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

Commit

Permalink
Bug fix for shortcut directory
Browse files Browse the repository at this point in the history
  • Loading branch information
caesay committed Dec 31, 2021
1 parent 0b8bcc1 commit c8927f2
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/Squirrel/Internal/Utility.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics.Contracts;
Expand Down Expand Up @@ -70,13 +70,17 @@ public static string RemoveByteOrderMarkerIfPresent(byte[] content)
return Encoding.UTF8.GetString(output);
}

public static string NormalizePath(string path)
{
return Path.GetFullPath(new Uri(path).LocalPath)
.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
}

public static bool IsFileInDirectory(string file, string directory)
{
if (!File.Exists(file)) return false;
if (!Directory.Exists(directory)) return false;
var fileDir = Path.GetDirectoryName(file).TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
var normalizedDir = directory.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
return fileDir.Equals(normalizedDir, StringComparison.OrdinalIgnoreCase);
var normalizedDir = NormalizePath(directory) + Path.DirectorySeparatorChar;
var normalizedFile = NormalizePath(file);
return normalizedFile.StartsWith(normalizedDir, StringComparison.OrdinalIgnoreCase);
}

public static IEnumerable<FileInfo> GetAllFilesRecursively(this DirectoryInfo rootPath)
Expand Down

0 comments on commit c8927f2

Please sign in to comment.