Use WorkingDirectory when strat process

As proposed in #569
This commit is contained in:
bao-qian
2016-04-24 13:35:21 +01:00
parent 04a4833c6e
commit bed65745cc
5 changed files with 24 additions and 18 deletions

View File

@@ -24,13 +24,14 @@ namespace Wox.Plugin.Program
{
Title = Path.GetFileNameWithoutExtension(file),
IcoPath = file,
ExecutePath = file
Path = file,
Directory = Directory.GetParent(file).FullName
};
switch (Path.GetExtension(file).ToLower())
{
case ".exe":
p.ExecuteName = Path.GetFileName(file);
p.ExecutableName = Path.GetFileName(file);
try
{
FileVersionInfo versionInfo = FileVersionInfo.GetVersionInfo(file);

View File

@@ -8,11 +8,11 @@ namespace Wox.Plugin.Program
[Serializable]
public class Program
{
private static readonly Regex AbbrRegexp = new Regex("[^A-Z0-9]", RegexOptions.Compiled);
public string Title { get; set; }
public string IcoPath { get; set; }
public string ExecutePath { get; set; }
public string ExecuteName { get; set; }
public string Path { get; set; }
public string Directory { get; set; }
public string ExecutableName { get; set; }
public int Score { get; set; }
public IProgramSource Source { get; set; }
}

View File

@@ -54,7 +54,7 @@ namespace Wox.Plugin.Program.ProgramSources
if (!File.Exists(path)) continue;
var entry = CreateEntry(path);
entry.ExecuteName = item;
entry.ExecutableName = item;
entry.Source = this;
list.Add(entry);
}

View File

@@ -57,13 +57,18 @@ namespace Wox.Plugin.Program
.Select(p => new Result
{
Title = p.Title,
SubTitle = p.ExecutePath,
SubTitle = p.Path,
IcoPath = p.IcoPath,
Score = p.Score,
ContextData = p,
Action = e =>
{
var hide = StartProcess(new ProcessStartInfo(p.ExecutePath));
var info = new ProcessStartInfo
{
FileName = p.Path,
WorkingDirectory = p.Directory
};
var hide = StartProcess(info);
return hide;
}
}).ToList();
@@ -74,8 +79,8 @@ namespace Wox.Plugin.Program
{
var score1 = StringMatcher.Score(program.Title, query);
var score2 = StringMatcher.ScoreForPinyin(program.Title, query);
var score3 = StringMatcher.Score(program.ExecuteName, query);
var score = new[] {score1, score2, score3}.Max();
var score3 = StringMatcher.Score(program.ExecutableName, query);
var score = new[] { score1, score2, score3 }.Max();
program.Score = score;
return score;
}
@@ -119,7 +124,7 @@ namespace Wox.Plugin.Program
_programs = _sources.AsParallel()
.SelectMany(s => s.LoadPrograms())
// filter duplicate program
.GroupBy(x => new { x.ExecutePath, x.ExecuteName })
.GroupBy(x => new { ExecutePath = x.Path, ExecuteName = x.ExecutableName })
.Select(g => g.First())
.ToList();
@@ -200,11 +205,13 @@ namespace Wox.Plugin.Program
Title = _context.API.GetTranslation("wox_plugin_program_run_as_administrator"),
Action = _ =>
{
var hide = StartProcess(new ProcessStartInfo
var info = new ProcessStartInfo
{
FileName = p.ExecutePath,
FileName = p.Path,
WorkingDirectory = p.Directory,
Verb = "runas"
});
};
var hide = StartProcess(info);
return hide;
},
IcoPath = "Images/cmd.png"
@@ -214,10 +221,7 @@ namespace Wox.Plugin.Program
Title = _context.API.GetTranslation("wox_plugin_program_open_containing_folder"),
Action = _ =>
{
//get parent folder
var folderPath = Directory.GetParent(p.ExecutePath).FullName;
//open the folder
var hide = StartProcess(new ProcessStartInfo(folderPath));
var hide = StartProcess(new ProcessStartInfo(p.Directory));
return hide;
},
IcoPath = "Images/folder.png"