From 016e11e81fbba9197b203957f1d1132e572ff679 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Holger=20B=C3=B6rchers?= Date: Thu, 22 Mar 2018 07:58:39 +0100 Subject: [PATCH] Moved PathFragments from SetupTmplCode to extra class. --- Creator/AssemblyFileInfo.cs | 1 - Creator/Helper/Utils.cs | 2 -- Creator/KattekerCreator.csproj | 1 + Creator/PathFragments.cs | 25 ++++++++++++++++++++ Creator/PhysicalFile.cs | 10 ++++---- Creator/SetupTmplCode.cs | 42 ++++------------------------------ Katteker.Gui/Wrapper.cs | 3 +-- 7 files changed, 36 insertions(+), 48 deletions(-) create mode 100644 Creator/PathFragments.cs diff --git a/Creator/AssemblyFileInfo.cs b/Creator/AssemblyFileInfo.cs index b706521..94cacfc 100644 --- a/Creator/AssemblyFileInfo.cs +++ b/Creator/AssemblyFileInfo.cs @@ -89,7 +89,6 @@ namespace KattekerCreator return semanticVersion?.Change(build: string.Empty); Version.TryParse(productVersion, out var version); return SemanticVersion.Parse(version.ToString(3)); - } } } \ No newline at end of file diff --git a/Creator/Helper/Utils.cs b/Creator/Helper/Utils.cs index 9a986ef..6279542 100644 --- a/Creator/Helper/Utils.cs +++ b/Creator/Helper/Utils.cs @@ -2,8 +2,6 @@ using System.Collections.Generic; using System.IO; using System.Linq; -using System.Runtime.CompilerServices; -using System.Security.Cryptography.X509Certificates; using Vestris.ResourceLib; namespace KattekerCreator.Helper diff --git a/Creator/KattekerCreator.csproj b/Creator/KattekerCreator.csproj index e81ba0b..1000c2d 100644 --- a/Creator/KattekerCreator.csproj +++ b/Creator/KattekerCreator.csproj @@ -54,6 +54,7 @@ + diff --git a/Creator/PathFragments.cs b/Creator/PathFragments.cs new file mode 100644 index 0000000..2d48011 --- /dev/null +++ b/Creator/PathFragments.cs @@ -0,0 +1,25 @@ +using System.IO; +using System.Linq; + +namespace KattekerCreator +{ + public class PathFragments + { + private readonly string[] _fragments; + + public PathFragments(string path) + { + _fragments = path.Split(Path.PathSeparator); + } + + public int FragmentLength => _fragments.Length; + + public override bool Equals(object obj) => string.Equals(ToString(), obj?.ToString()); + + public override int GetHashCode() => (_fragments != null ? _fragments.GetHashCode() : 0); + + public override string ToString() => string.Join(Path.PathSeparator.ToString(), _fragments.Take(_fragments.Length - 1)); + + protected bool Equals(PathFragments other) => Equals(_fragments, other._fragments); + } +} \ No newline at end of file diff --git a/Creator/PhysicalFile.cs b/Creator/PhysicalFile.cs index ff99905..2d6b43e 100644 --- a/Creator/PhysicalFile.cs +++ b/Creator/PhysicalFile.cs @@ -2,13 +2,13 @@ { public class PhysicalFile { - public PhysicalFile(string sourcePath, string targetPath) + public PhysicalFile(string source, string target) { - SourcePath = sourcePath; - TargetPath = targetPath; + Source = source; + Target = target; } - public string SourcePath { get; } - public string TargetPath { get; } + public string Source { get; } + public string Target { get; } } } \ No newline at end of file diff --git a/Creator/SetupTmplCode.cs b/Creator/SetupTmplCode.cs index a72118b..bdda482 100644 --- a/Creator/SetupTmplCode.cs +++ b/Creator/SetupTmplCode.cs @@ -30,55 +30,21 @@ namespace KattekerCreator public string UninstallIcon { get; set; } public string ReleaseChannel { get; set; } - private readonly List _directoriesList = new List(); + private readonly List _directoriesList = new List(); private string _appName; private IEnumerable DirectoriesToCreate() { foreach (var physicalFile in Files) { - var dirSplit = new DirSplit(physicalFile.TargetPath); - if (dirSplit.SplitCount > 1 && !_directoriesList.Contains(dirSplit)) + var dirSplit = new PathFragments(physicalFile.Target); + if (dirSplit.FragmentLength > 1 && !_directoriesList.Contains(dirSplit)) { _directoriesList.Add(dirSplit); } } - return _directoriesList.Select(x=> x.ToString()); - } - - private class DirSplit - { - private const char SplitChar = '\\'; - - private readonly string[] _splits; - - public int SplitCount => _splits.Length; - - public DirSplit(string path) - { - _splits = path.Split(SplitChar); - } - - public override string ToString() - { - return string.Join(SplitChar.ToString(), _splits.Take(_splits.Length - 1)); - } - - public override bool Equals(object obj) - { - return string.Equals(ToString(), obj?.ToString()); - } - - protected bool Equals(DirSplit other) - { - return Equals(_splits, other._splits); - } - - public override int GetHashCode() - { - return (_splits != null ? _splits.GetHashCode() : 0); - } + return _directoriesList.Select(x => x.ToString()); } } } \ No newline at end of file diff --git a/Katteker.Gui/Wrapper.cs b/Katteker.Gui/Wrapper.cs index b999286..b5eee77 100644 --- a/Katteker.Gui/Wrapper.cs +++ b/Katteker.Gui/Wrapper.cs @@ -1,5 +1,4 @@ -using System; -using System.Linq; +using System.Linq; using System.Threading.Tasks; using System.Windows.Forms; using Katteker.Gui.Properties;