Merge branch 'feature/first-last-environment-path' into 'master'
Added: first and last environment path See merge request SympatheticFire/linear-app-launcher!10
This commit is contained in:
commit
3a779f91c5
@ -20,11 +20,81 @@ namespace AppLauncher.Models
|
|||||||
|
|
||||||
public override string ToString() => this.Title ?? string.Empty;
|
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