Skip to content
This repository has been archived by the owner on Aug 11, 2024. It is now read-only.

Commit

Permalink
fixed some edge cases when generating symbolic links (#855)
Browse files Browse the repository at this point in the history
# XRTK - Mixed Reality Toolkit Pull Request

## Overview
<!-- Please provide a clear and concise description of the pull request. -->
fixed some edge cases when generating symbolic links
  • Loading branch information
StephenHodgson authored Jun 27, 2021
1 parent c65f27a commit b0589c2
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 34 deletions.
2 changes: 1 addition & 1 deletion Editor/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.")]
16 changes: 8 additions & 8 deletions Editor/Utilities/SymbolicLinks/SymbolicLink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,37 @@ public SymbolicLink() { }

public SymbolicLink(string sourceRelativePath, string targetRelativePath)
{
this.sourceRelativePath = sourceRelativePath;
this.targetRelativePath = targetRelativePath;
SourceRelativePath = sourceRelativePath;
TargetRelativePath = targetRelativePath;
}

[SerializeField]
private string sourceRelativePath;

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]
private string targetRelativePath;

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]
Expand Down
8 changes: 3 additions & 5 deletions Editor/Utilities/SymbolicLinks/SymbolicLinker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ static SymbolicLinker()

private static GUIStyle symbolicLinkMarkerStyle;

internal static string ProjectRoot => GitUtilities.RepositoryRootDir;
internal static string ProjectRoot => GitUtilities.RepositoryRootDir.ForwardSlashes();

/// <summary>
/// Is the sync task running?
Expand Down Expand Up @@ -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))
{
Expand Down Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion Runtime/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.")]
Expand Down
24 changes: 6 additions & 18 deletions Runtime/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,15 @@ public static class StringExtensions
/// <param name="toEncode">String to encode.</param>
/// <returns>Encoded string.</returns>
public static string EncodeTo64(this string toEncode)
{
return Convert.ToBase64String(Encoding.ASCII.GetBytes(toEncode));
}
=> Convert.ToBase64String(Encoding.ASCII.GetBytes(toEncode));

/// <summary>
/// Decodes string from base 64 ASCII.
/// </summary>
/// <param name="encodedData">String to decode.</param>
/// <returns>Decoded string.</returns>
public static string DecodeFrom64(this string encodedData)
{
return Encoding.ASCII.GetString(Convert.FromBase64String(encodedData));
}
=> Encoding.ASCII.GetString(Convert.FromBase64String(encodedData));

/// <summary>
/// Capitalize the first character and add a space before
Expand Down Expand Up @@ -78,33 +74,25 @@ public static string ToProperCase(this string value)
/// Replaces all back slashes in the string with forward slashes.
/// </summary>
public static string ForwardSlashes(this string value)
{
return value.Replace(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
}
=> value.Replace(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);

/// <summary>
/// Replaces all forward slashes in the string with back slashes.
/// </summary>
public static string BackSlashes(this string value)
{
return value.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);
}
=> value.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);

/// <summary>
/// Returns the URI path, excluding the filename
/// </summary>
public static string PathFromURI(this string value)
{
return value.Substring(0, value.LastIndexOf("/", StringComparison.Ordinal) + 1);
}
=> value.Substring(0, value.LastIndexOf("/", StringComparison.Ordinal) + 1);

/// <summary>
/// Returns the filename from a URI path
/// </summary>
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);

/// <summary>
/// Creates a relative path from one file or folder to another.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"Mixed Reality",
"DI"
],
"version": "0.2.17",
"version": "0.2.18",
"unity": "2019.4",
"license": "MIT",
"repository": {
Expand Down

0 comments on commit b0589c2

Please sign in to comment.