Added: first and last environment path
This commit is contained in:
parent
093d2b5dfe
commit
5e4eb97121
@ -20,11 +20,81 @@ namespace AppLauncher.Models
|
||||
|
||||
public override string ToString() => this.Title ?? string.Empty;
|
||||
|
||||
public string CleanProcessFilename => (string.IsNullOrWhiteSpace(this.ProcessFilename) ? string.Empty : Environment.ExpandEnvironmentVariables(this.ProcessFilename));
|
||||
public string CleanProcessFilename => (string.IsNullOrWhiteSpace(this.ProcessFilename) ? string.Empty : resolvePath(this.ProcessFilename));
|
||||
|
||||
public string CleanProcessArgument => (string.IsNullOrWhiteSpace(this.ProcessArgument) ? string.Empty : Environment.ExpandEnvironmentVariables(this.ProcessArgument));
|
||||
public string CleanProcessArgument => (string.IsNullOrWhiteSpace(this.ProcessArgument) ? string.Empty : resolvePath(this.ProcessArgument));
|
||||
|
||||
public string CleanProcessWorkingDirectory => (string.IsNullOrWhiteSpace(this.ProcessWorkingDirectory) ? string.Empty : Environment.ExpandEnvironmentVariables(this.ProcessWorkingDirectory));
|
||||
public string CleanProcessWorkingDirectory => (string.IsNullOrWhiteSpace(this.ProcessWorkingDirectory) ? string.Empty : resolvePath(this.ProcessWorkingDirectory));
|
||||
|
||||
protected string resolvePath(string value)
|
||||
{
|
||||
string rv = Environment.ExpandEnvironmentVariables(value);
|
||||
|
||||
rv = resolveFirstPath(rv);
|
||||
rv = resolveLastPath(rv);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
protected string resolveFirstPath(string value)
|
||||
{
|
||||
const string last = "%FIRST%";
|
||||
if (!value.Contains(last))
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
string head = value.Substring(0, value.IndexOf(last));
|
||||
string tail = value.Substring(value.IndexOf(last) + last.Length);
|
||||
|
||||
string[] dirList = new string[0];
|
||||
|
||||
try
|
||||
{
|
||||
dirList = System.IO.Directory.GetDirectories(head, "*", System.IO.SearchOption.TopDirectoryOnly);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
if (dirList.Length <= 0)
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
return dirList[0] + tail;
|
||||
}
|
||||
|
||||
protected string resolveLastPath(string value)
|
||||
{
|
||||
const string last = "%LAST%";
|
||||
if (!value.Contains(last))
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
string head = value.Substring(0, value.IndexOf(last));
|
||||
string tail = value.Substring(value.IndexOf(last) + last.Length);
|
||||
|
||||
string[] dirList = new string[0];
|
||||
|
||||
try
|
||||
{
|
||||
dirList = System.IO.Directory.GetDirectories(head, "*", System.IO.SearchOption.TopDirectoryOnly);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
if (dirList.Length <= 0)
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
return dirList[(dirList.Length - 1)] + tail;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user