Skip to content

Commit

Permalink
Added path cleanup to DisplayIcon;
Browse files Browse the repository at this point in the history
Fixed bugs in path cleanup of InstallLocation, InstallSource and ModifyPath. Some valid paths were treated as invalid and removed or modified;
Improved speed of path cleanup slightly.
  • Loading branch information
Klocman committed Feb 5, 2017
1 parent 30f66f0 commit 7e5289b
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions UninstallTools/ApplicationUninstallerEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public class ApplicationUninstallerEntry
private string _installLocation;
private string _installSource;
private string _modifyPath;
private string _displayIcon;

internal ApplicationUninstallerEntry()
{
Expand Down Expand Up @@ -102,7 +103,11 @@ public string DisplayName
public string Comment { get; set; }

[LocalisedName(typeof (Localisation), "DisplayIcon")]
public string DisplayIcon { get; set; }
public string DisplayIcon
{
get { return _displayIcon; }
set { _displayIcon = CleanupPath(value, true); }
}

[ComparisonTarget, LocalisedName(typeof (Localisation), "DisplayVersion")]
public string DisplayVersion { get; set; }
Expand Down Expand Up @@ -358,25 +363,31 @@ public override string ToString()
return sb.ToString();
}

private static string CleanupPath(string path)
private static readonly char[] InvalidPathChars = Path.GetInvalidPathChars();
private static string CleanupPath(string path, bool isFilename = false)
{
if (string.IsNullOrEmpty(path)) return null;

path = path.Trim('"', ' ', '\'', '\\', '/'); // Get rid of the quotation marks
if (!isFilename)
{
// Try the fast method first for directories
var trimmed = path.Trim('"', ' ', '\'', '\\', '/');

if (!trimmed.ContainsAny(InvalidPathChars))
return trimmed;
}

try
{
var i = path.LastIndexOf('\\');
// TODO unnecessary?
if (i > 0 && path.Substring(i).Contains('.') && !Directory.Exists(path))
{
path = Path.GetDirectoryName(ProcessTools.SeparateArgsFromCommand(path).FileName);
}
path = ProcessTools.SeparateArgsFromCommand(path).FileName;
if (!isFilename && path.Contains('.') && !Directory.Exists(path))
return Path.GetDirectoryName(path);
}
catch
{
// If sanitization failed just leave it be, it will be handled afterwards
}
return path;
return path.TrimEnd('\\');
}
}
}

0 comments on commit 7e5289b

Please sign in to comment.