Fix System.ArgumentException

Fix System.ArgumentException("Illegal characters in path") when parsing
path string
This commit is contained in:
bao-qian 2015-10-31 22:40:11 +00:00
parent cfeb637685
commit f3038e4fef

View File

@ -1,21 +1,21 @@
using System;
using System.Collections.Generic;
using Wox.Infrastructure.Logger;
namespace Wox.Plugin.Program.ProgramSources
{
[Serializable]
[global::System.ComponentModel.Browsable(false)]
public class AppPathsProgramSource: AbstractProgramSource
[System.ComponentModel.Browsable(false)]
public class AppPathsProgramSource : AbstractProgramSource
{
public AppPathsProgramSource()
{
this.BonusPoints = -10;
BonusPoints = -10;
}
public AppPathsProgramSource(ProgramSource source)
: this()
public AppPathsProgramSource(ProgramSource source) : this()
{
this.BonusPoints = source.BonusPoints;
BonusPoints = source.BonusPoints;
}
public override List<Program> LoadPrograms()
@ -33,17 +33,31 @@ namespace Wox.Plugin.Program.ProgramSources
if (root == null) return;
foreach (var item in root.GetSubKeyNames())
{
using (var key = root.OpenSubKey(item))
try
{
object path = key.GetValue("");
if (path is string && global::System.IO.File.Exists((string)path))
using (var key = root.OpenSubKey(item))
{
var entry = CreateEntry((string)path);
string path = key.GetValue("") as string;
if (path == null) continue;
// fix path like this ""\"C:\\folder\\executable.exe\"""
const int begin = 0;
int end = path.Length - 1;
const char quotationMark = '"';
if (path[begin] == quotationMark && path[end] == quotationMark)
{
path = path.Substring(begin + 1, path.Length - 2);
}
if (!System.IO.File.Exists(path)) continue;
var entry = CreateEntry(path);
entry.ExecuteName = item;
list.Add(entry);
}
key.Close();
}
catch (Exception e)
{
Log.Error(e.StackTrace);
}
}
}