From 52f896f7276e050bc88b961df9506d72ef50c835 Mon Sep 17 00:00:00 2001 From: Stephen Hodgson Date: Sun, 27 Jun 2021 09:55:05 -0400 Subject: [PATCH] fixed some edge cases when generating symbolic links --- .../com.xrtk.core/Editor/AssemblyInfo.cs | 2 +- .../Utilities/SymbolicLinks/SymbolicLink.cs | 16 ++++++------- .../Utilities/SymbolicLinks/SymbolicLinker.cs | 8 +++---- .../com.xrtk.core/Runtime/AssemblyInfo.cs | 2 +- .../Runtime/Extensions/StringExtensions.cs | 24 +++++-------------- XRTK-Core/Packages/com.xrtk.core/package.json | 2 +- 6 files changed, 20 insertions(+), 34 deletions(-) diff --git a/XRTK-Core/Packages/com.xrtk.core/Editor/AssemblyInfo.cs b/XRTK-Core/Packages/com.xrtk.core/Editor/AssemblyInfo.cs index bba49b376..7b73abce1 100644 --- a/XRTK-Core/Packages/com.xrtk.core/Editor/AssemblyInfo.cs +++ b/XRTK-Core/Packages/com.xrtk.core/Editor/AssemblyInfo.cs @@ -5,7 +5,7 @@ using System.Reflection; -[assembly: AssemblyVersion("0.2.17")] +[assembly: AssemblyVersion("0.2.18")] [assembly: AssemblyTitle("com.xrtk.core.editor")] [assembly: AssemblyCompany("XRTK")] [assembly: AssemblyCopyright("Copyright (c) XRTK. All rights reserved.")] diff --git a/XRTK-Core/Packages/com.xrtk.core/Editor/Utilities/SymbolicLinks/SymbolicLink.cs b/XRTK-Core/Packages/com.xrtk.core/Editor/Utilities/SymbolicLinks/SymbolicLink.cs index c5289f05c..8ca432f5e 100644 --- a/XRTK-Core/Packages/com.xrtk.core/Editor/Utilities/SymbolicLinks/SymbolicLink.cs +++ b/XRTK-Core/Packages/com.xrtk.core/Editor/Utilities/SymbolicLinks/SymbolicLink.cs @@ -14,8 +14,8 @@ public SymbolicLink() { } public SymbolicLink(string sourceRelativePath, string targetRelativePath) { - this.sourceRelativePath = sourceRelativePath; - this.targetRelativePath = targetRelativePath; + SourceRelativePath = sourceRelativePath; + TargetRelativePath = targetRelativePath; } [SerializeField] @@ -23,14 +23,14 @@ public SymbolicLink(string sourceRelativePath, string targetRelativePath) public string SourceRelativePath { - get => sourceRelativePath.ForwardSlashes(); - internal set => sourceRelativePath = value.ForwardSlashes(); + get => sourceRelativePath; + internal set => sourceRelativePath = value.ForwardSlashes().Replace(SymbolicLinker.ProjectRoot, string.Empty); } public string SourceAbsolutePath { get => $"{SymbolicLinker.ProjectRoot}{sourceRelativePath}".ForwardSlashes(); - internal set => sourceRelativePath = value.ForwardSlashes().Replace(SymbolicLinker.ProjectRoot, string.Empty); + internal set => sourceRelativePath = value; } [SerializeField] @@ -38,13 +38,13 @@ public string SourceAbsolutePath public string TargetRelativePath { - get => targetRelativePath.ForwardSlashes(); - internal set => targetRelativePath = value.ForwardSlashes(); + get => targetRelativePath; + internal set => targetRelativePath = value.ForwardSlashes().Replace(SymbolicLinker.ProjectRoot, string.Empty); } public string TargetAbsolutePath { get => $"{SymbolicLinker.ProjectRoot}{targetRelativePath}".ForwardSlashes(); - internal set => targetRelativePath = value.ForwardSlashes().Replace(SymbolicLinker.ProjectRoot, string.Empty); + internal set => targetRelativePath = value; } [SerializeField] diff --git a/XRTK-Core/Packages/com.xrtk.core/Editor/Utilities/SymbolicLinks/SymbolicLinker.cs b/XRTK-Core/Packages/com.xrtk.core/Editor/Utilities/SymbolicLinks/SymbolicLinker.cs index a433de045..e079d76b3 100644 --- a/XRTK-Core/Packages/com.xrtk.core/Editor/Utilities/SymbolicLinks/SymbolicLinker.cs +++ b/XRTK-Core/Packages/com.xrtk.core/Editor/Utilities/SymbolicLinks/SymbolicLinker.cs @@ -37,7 +37,7 @@ static SymbolicLinker() private static GUIStyle symbolicLinkMarkerStyle; - internal static string ProjectRoot => GitUtilities.RepositoryRootDir; + internal static string ProjectRoot => GitUtilities.RepositoryRootDir.ForwardSlashes(); /// /// Is the sync task running? @@ -211,7 +211,7 @@ internal static bool Add(this SymbolicLink newLink) return false; } - newLink.TargetAbsolutePath = AddSubfolderPathToTarget(newLink.SourceAbsolutePath, newLink.TargetAbsolutePath); + newLink.TargetRelativePath = AddSubfolderPathToTarget(newLink.SourceRelativePath, newLink.TargetRelativePath); if (!CreateSymbolicLink(newLink)) { @@ -349,9 +349,7 @@ private static bool IsSymbolicPath(string path) } internal static bool Validate(this SymbolicLink link) - { - return ValidateSymbolicPath(link.TargetAbsolutePath, link.SourceAbsolutePath); - } + => ValidateSymbolicPath(link.TargetAbsolutePath, link.SourceAbsolutePath); private static bool ValidateSymbolicPath(string targetAbsolutePath, string sourceAbsolutePath = null) { diff --git a/XRTK-Core/Packages/com.xrtk.core/Runtime/AssemblyInfo.cs b/XRTK-Core/Packages/com.xrtk.core/Runtime/AssemblyInfo.cs index 50ef59ad0..59ae68dca 100644 --- a/XRTK-Core/Packages/com.xrtk.core/Runtime/AssemblyInfo.cs +++ b/XRTK-Core/Packages/com.xrtk.core/Runtime/AssemblyInfo.cs @@ -6,7 +6,7 @@ using System.Reflection; using System.Runtime.CompilerServices; -[assembly: AssemblyVersion("0.2.17")] +[assembly: AssemblyVersion("0.2.18")] [assembly: AssemblyTitle("com.xrtk.core")] [assembly: AssemblyCompany("XRTK")] [assembly: AssemblyCopyright("Copyright (c) XRTK. All rights reserved.")] diff --git a/XRTK-Core/Packages/com.xrtk.core/Runtime/Extensions/StringExtensions.cs b/XRTK-Core/Packages/com.xrtk.core/Runtime/Extensions/StringExtensions.cs index 41c189b8e..26908df40 100644 --- a/XRTK-Core/Packages/com.xrtk.core/Runtime/Extensions/StringExtensions.cs +++ b/XRTK-Core/Packages/com.xrtk.core/Runtime/Extensions/StringExtensions.cs @@ -21,9 +21,7 @@ public static class StringExtensions /// String to encode. /// Encoded string. public static string EncodeTo64(this string toEncode) - { - return Convert.ToBase64String(Encoding.ASCII.GetBytes(toEncode)); - } + => Convert.ToBase64String(Encoding.ASCII.GetBytes(toEncode)); /// /// Decodes string from base 64 ASCII. @@ -31,9 +29,7 @@ public static string EncodeTo64(this string toEncode) /// String to decode. /// Decoded string. public static string DecodeFrom64(this string encodedData) - { - return Encoding.ASCII.GetString(Convert.FromBase64String(encodedData)); - } + => Encoding.ASCII.GetString(Convert.FromBase64String(encodedData)); /// /// Capitalize the first character and add a space before @@ -78,33 +74,25 @@ public static string ToProperCase(this string value) /// Replaces all back slashes in the string with forward slashes. /// public static string ForwardSlashes(this string value) - { - return value.Replace(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); - } + => value.Replace(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); /// /// Replaces all forward slashes in the string with back slashes. /// public static string BackSlashes(this string value) - { - return value.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar); - } + => value.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar); /// /// Returns the URI path, excluding the filename /// public static string PathFromURI(this string value) - { - return value.Substring(0, value.LastIndexOf("/", StringComparison.Ordinal) + 1); - } + => value.Substring(0, value.LastIndexOf("/", StringComparison.Ordinal) + 1); /// /// Returns the filename from a URI path /// public static string FilenameFromURI(this string value) - { - return value.Substring(value.LastIndexOf("/", StringComparison.Ordinal) + 1, value.Length - value.LastIndexOf("/", StringComparison.Ordinal) - 1); - } + => value.Substring(value.LastIndexOf("/", StringComparison.Ordinal) + 1, value.Length - value.LastIndexOf("/", StringComparison.Ordinal) - 1); /// /// Creates a relative path from one file or folder to another. diff --git a/XRTK-Core/Packages/com.xrtk.core/package.json b/XRTK-Core/Packages/com.xrtk.core/package.json index bd1a79336..995674a4b 100644 --- a/XRTK-Core/Packages/com.xrtk.core/package.json +++ b/XRTK-Core/Packages/com.xrtk.core/package.json @@ -10,7 +10,7 @@ "Mixed Reality", "DI" ], - "version": "0.2.17", + "version": "0.2.18", "unity": "2019.4", "license": "MIT", "repository": {