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

Commit

Permalink
Replace all 'StartsWith(rootdir)' with IsFileInDirectory
Browse files Browse the repository at this point in the history
  • Loading branch information
caesay committed Jan 1, 2022
1 parent b564861 commit b1ec154
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/Squirrel/UpdateManager.ApplyReleases.cs
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ internal void unshimOurselves()
if (regKey == null) return;

var toDelete = regKey.GetValueNames()
.Where(x => x.StartsWith(rootAppDirectory, StringComparison.OrdinalIgnoreCase))
.Where(x => Utility.IsFileInDirectory(x, rootAppDirectory))
.ToList();

toDelete.ForEach(x =>
Expand Down
2 changes: 1 addition & 1 deletion src/Squirrel/UpdateManager.InstallHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public void KillAllProcessesBelongingToPackage()
if (String.IsNullOrWhiteSpace(x.Item1)) return false;

// Files that aren't in our root app directory are untouched
if (!x.Item1.StartsWith(rootAppDirectory, StringComparison.OrdinalIgnoreCase)) return false;
if (!Utility.IsFileInDirectory(x.ProcessExePath, rootAppDirectory)) return false;

// Never kill our own EXE
if (ourExePath != null && x.Item1.Equals(ourExePath, StringComparison.OrdinalIgnoreCase)) return false;
Expand Down
15 changes: 4 additions & 11 deletions src/Squirrel/UpdateManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,8 @@ public SemanticVersion CurrentlyInstalledVersion(string executable = null)
{
executable = executable ?? AssemblyRuntimeInfo.EntryExePath;

if (!executable.StartsWith(rootAppDirectory, StringComparison.OrdinalIgnoreCase)) {
if (!Utility.IsFileInDirectory(executable, RootAppDirectory))
return null;
}

var appDirName = executable.Split(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar)
.FirstOrDefault(x => x.StartsWith("app-", StringComparison.OrdinalIgnoreCase));
Expand Down Expand Up @@ -180,17 +179,11 @@ public void KillAllExecutablesBelongingToPackage()
installHelpers.KillAllProcessesBelongingToPackage();
}

public string ApplicationName {
get { return applicationName; }
}
public string ApplicationName => applicationName;

public string RootAppDirectory {
get { return rootAppDirectory; }
}
public string RootAppDirectory => rootAppDirectory;

public bool IsInstalledApp {
get { return Process.GetCurrentProcess().MainModule.FileName.StartsWith(RootAppDirectory, StringComparison.OrdinalIgnoreCase); }
}
public bool IsInstalledApp => Utility.IsFileInDirectory(AssemblyRuntimeInfo.EntryExePath, RootAppDirectory);

/// <inheritdoc/>
public void Dispose()
Expand Down

0 comments on commit b1ec154

Please sign in to comment.