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

Commit

Permalink
Fixed string extensions (backslahses and forward slashes were inverte…
Browse files Browse the repository at this point in the history
…d) (#844)

# XRTK - Mixed Reality Toolkit Pull Request

## Overview
<!-- Please provide a clear and concise description of the pull request. -->
Back slash and forward slash string extensions were inverted, needed to be fixed.

## Submodule Changes

- XRTK/com.xrtk.lumin#112
- XRTK/com.xrtk.oculus#118
- XRTK/com.xrtk.sdk#240
- XRTK/com.xrtk.wmr#140
  • Loading branch information
StephenHodgson committed May 19, 2021
1 parent 262fa99 commit 75e6ab8
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 41 deletions.
2 changes: 1 addition & 1 deletion Editor/MixedRealityPreferences.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public static string ProfileGenerationPath
set
{
var newPath = value;
var root = Path.GetFullPath(Application.dataPath).ToBackSlashes();
var root = Path.GetFullPath(Application.dataPath).ForwardSlashes();

if (!newPath.Contains(root))
{
Expand Down
14 changes: 7 additions & 7 deletions Editor/PackageInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace XRTK.Editor
{
public static class PackageInstaller
{
private static string ProjectRootPath => Directory.GetParent(Application.dataPath).FullName.ToForwardSlashes();
private static string ProjectRootPath => Directory.GetParent(Application.dataPath).FullName.BackSlashes();

/// <summary>
/// Attempt to copy any assets found in the source path into the project.
Expand Down Expand Up @@ -56,8 +56,8 @@ public static bool TryInstallAssets(Dictionary<string, string> installationPaths

foreach (var installationPath in installationPaths)
{
var sourcePath = installationPath.Key.ToForwardSlashes();
var destinationPath = installationPath.Value.ToForwardSlashes();
var sourcePath = installationPath.Key.BackSlashes();
var destinationPath = installationPath.Value.BackSlashes();
installedDirectories.Add(destinationPath);

if (Directory.Exists(destinationPath))
Expand All @@ -70,7 +70,7 @@ public static bool TryInstallAssets(Dictionary<string, string> installationPaths
for (int i = 0; i < installedAssets.Count; i++)
{
EditorUtility.DisplayProgressBar("Verifying assets...", Path.GetFileNameWithoutExtension(installedAssets[i]), i / (float)installedAssets.Count);
installedAssets[i] = installedAssets[i].Replace($"{ProjectRootPath}\\", string.Empty).ToForwardSlashes();
installedAssets[i] = installedAssets[i].Replace($"{ProjectRootPath}\\", string.Empty).BackSlashes();
}

EditorUtility.ClearProgressBar();
Expand Down Expand Up @@ -187,9 +187,9 @@ private static void AddConfigurations(List<string> profiles)

private static string CopyAsset(this string rootPath, string sourceAssetPath, string destinationPath)
{
sourceAssetPath = sourceAssetPath.ToForwardSlashes();
destinationPath = $"{destinationPath}{sourceAssetPath.Replace(Path.GetFullPath(rootPath), string.Empty)}".ToForwardSlashes();
destinationPath = Path.Combine(ProjectRootPath, destinationPath).ToForwardSlashes();
sourceAssetPath = sourceAssetPath.BackSlashes();
destinationPath = $"{destinationPath}{sourceAssetPath.Replace(Path.GetFullPath(rootPath), string.Empty)}".BackSlashes();
destinationPath = Path.Combine(ProjectRootPath, destinationPath).BackSlashes();

if (!File.Exists(destinationPath))
{
Expand Down
4 changes: 2 additions & 2 deletions Editor/Utilities/GitUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static string RepositoryRootDir
{
if (new Process().Run($@"cd ""{Application.dataPath}"" && git rev-parse --show-toplevel", out var rootDir))
{
projectRootDir = rootDir.ToBackSlashes().Replace("\n", string.Empty);
projectRootDir = rootDir.ForwardSlashes().Replace("\n", string.Empty);
}
}

Expand Down Expand Up @@ -99,7 +99,7 @@ public static void WritePathToGitIgnore(string ignoredPath)
}

var rootDir = RepositoryRootDir;
ignoredPath = ignoredPath.Replace($"{rootDir.ToBackSlashes()}/", string.Empty);
ignoredPath = ignoredPath.Replace($"{rootDir.ForwardSlashes()}/", string.Empty);
var directory = ignoredPath.Replace(Path.GetFileName(ignoredPath), Path.GetFileNameWithoutExtension(ignoredPath));
directory = directory.Substring(0, directory.LastIndexOf("/", StringComparison.Ordinal));
var gitIgnoreFilePath = $"{rootDir}\\.gitignore";
Expand Down
2 changes: 1 addition & 1 deletion Editor/Utilities/MixedRealityServiceWizard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ private void OnGUI()
outputPath = EditorUtility.OpenFolderPanel("Generation Location", outputPath, string.Empty);
var namespaceRoot = $"{Application.productName.Replace("-Core", string.Empty)}";

@namespace = outputPath.Replace($"{Directory.GetParent(Application.dataPath).FullName.ToBackSlashes()}/", string.Empty);
@namespace = outputPath.Replace($"{Directory.GetParent(Application.dataPath).FullName.ForwardSlashes()}/", string.Empty);

if (@namespace.StartsWith("Assets/"))
{
Expand Down
16 changes: 8 additions & 8 deletions Editor/Utilities/SymbolicLinks/SymbolicLink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,28 @@ public SymbolicLink(string sourceRelativePath, string targetRelativePath)

public string SourceRelativePath
{
get => sourceRelativePath.ToBackSlashes();
internal set => sourceRelativePath = value.ToBackSlashes();
get => sourceRelativePath.ForwardSlashes();
internal set => sourceRelativePath = value.ForwardSlashes();
}

public string SourceAbsolutePath
{
get => $"{SymbolicLinker.ProjectRoot}{sourceRelativePath}".ToBackSlashes();
internal set => sourceRelativePath = value.ToBackSlashes().Replace(SymbolicLinker.ProjectRoot, string.Empty);
get => $"{SymbolicLinker.ProjectRoot}{sourceRelativePath}".ForwardSlashes();
internal set => sourceRelativePath = value.ForwardSlashes().Replace(SymbolicLinker.ProjectRoot, string.Empty);
}

[SerializeField]
private string targetRelativePath;

public string TargetRelativePath
{
get => targetRelativePath.ToBackSlashes();
internal set => targetRelativePath = value.ToBackSlashes();
get => targetRelativePath.ForwardSlashes();
internal set => targetRelativePath = value.ForwardSlashes();
}
public string TargetAbsolutePath
{
get => $"{SymbolicLinker.ProjectRoot}{targetRelativePath}".ToBackSlashes();
internal set => targetRelativePath = value.ToBackSlashes().Replace(SymbolicLinker.ProjectRoot, string.Empty);
get => $"{SymbolicLinker.ProjectRoot}{targetRelativePath}".ForwardSlashes();
internal set => targetRelativePath = value.ForwardSlashes().Replace(SymbolicLinker.ProjectRoot, string.Empty);
}

[SerializeField]
Expand Down
2 changes: 1 addition & 1 deletion Editor/Utilities/SymbolicLinks/SymbolicLinker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ private static void OnProjectWindowItemGui(string guid, Rect rect)
var path = AssetDatabase.GUIDToAssetPath(guid);

if (!string.IsNullOrEmpty(path) &&
ValidateSymbolicPath(Path.GetFullPath(path).ToBackSlashes()))
ValidateSymbolicPath(Path.GetFullPath(path).ForwardSlashes()))
{
GUI.Label(rect, LINK_ICON_TEXT, SymlinkMarkerStyle);
}
Expand Down
12 changes: 6 additions & 6 deletions Editor/Utilities/SymbolicLinks/SymbolicLinkerWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ private static void CreateSymbolicLink()

if (string.IsNullOrEmpty(path) || !Directory.Exists(path))
{
targetPath = $"{Application.dataPath}/ThirdParty".ToBackSlashes();
targetPath = $"{Application.dataPath}/ThirdParty".ForwardSlashes();
}
else
{
targetPath = Path.GetFullPath(path).ToBackSlashes();
targetPath = Path.GetFullPath(path).ForwardSlashes();
}

window.titleContent = new GUIContent("Import Module");
Expand All @@ -79,7 +79,7 @@ private static bool DisableSymbolicLinkValidation()
return false;
}

path = Path.GetFullPath(path).ToBackSlashes();
path = Path.GetFullPath(path).ForwardSlashes();

if (SymbolicLinker.Settings == null) { return false; }

Expand All @@ -97,7 +97,7 @@ private static void DisableSymbolicLink()

var path = AssetDatabase.GUIDToAssetPath(guids[0]);

path = Path.GetFullPath(path).ToBackSlashes();
path = Path.GetFullPath(path).ForwardSlashes();
var symbolicLink = SymbolicLinker.Settings.SymbolicLinks.Find(link => link.TargetAbsolutePath == path);

if (symbolicLink == null) { return; }
Expand Down Expand Up @@ -133,15 +133,15 @@ private void OnGUI()

if (GUILayout.Button("Choose Source Path"))
{
sourcePath = EditorUtility.OpenFolderPanel("Source Path", Application.dataPath, string.Empty).ToBackSlashes();
sourcePath = EditorUtility.OpenFolderPanel("Source Path", Application.dataPath, string.Empty).ForwardSlashes();
}

GUILayout.Space(10);
GUILayout.TextField(targetPath, textFieldGUIStyle);

if (GUILayout.Button("Choose Target Path"))
{
targetPath = EditorUtility.OpenFolderPanel("Target Path", targetPath, string.Empty).ToBackSlashes();
targetPath = EditorUtility.OpenFolderPanel("Target Path", targetPath, string.Empty).ForwardSlashes();
}

GUILayout.Space(8);
Expand Down
21 changes: 6 additions & 15 deletions Runtime/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ public static class StringExtensions
{
public const string WhiteSpace = " ";

public const string BackSlash = "\\";

public const string ForwardSlash = "/";

/// <summary>
/// Encodes the string to base 64 ASCII.
/// </summary>
Expand Down Expand Up @@ -79,28 +75,24 @@ public static string ToProperCase(this string value)
}

/// <summary>
/// Replaces all forward slashes in the string with back slashes.
/// Replaces all back slashes in the string with forward slashes.
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static string ToBackSlashes(this string value) // TODO FIX -> ToForwardSlashes
public static string ForwardSlashes(this string value)
{
return value.Replace(BackSlash, ForwardSlash);
return value.Replace(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
}

/// <summary>
/// Replaces all back slashes in the string with forward slashes.
/// Replaces all forward slashes in the string with back slashes.
/// </summary>
/// <param name="value"></param>
public static string ToForwardSlashes(this string value) // TODO FIX -> ToBackSlashes
public static string BackSlashes(this string value)
{
return value.Replace(ForwardSlash, BackSlash);
return value.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);
}

/// <summary>
/// Returns the URI path, excluding the filename
/// </summary>
/// <param name="value"></param>
public static string PathFromURI(this string value)
{
return value.Substring(0, value.LastIndexOf("/", StringComparison.Ordinal) + 1);
Expand All @@ -109,7 +101,6 @@ public static string PathFromURI(this string value)
/// <summary>
/// Returns the filename from a URI path
/// </summary>
/// <param name="value"></param>
public static string FilenameFromURI(this string value)
{
return value.Substring(value.LastIndexOf("/", StringComparison.Ordinal) + 1, value.Length - value.LastIndexOf("/", StringComparison.Ordinal) - 1);
Expand Down

0 comments on commit 75e6ab8

Please sign in to comment.