mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-01-18 06:29:44 +08:00
Fix System.ArgumentException
Fix System.ArgumentException("Illegal characters in path") when parsing path string
This commit is contained in:
parent
cfeb637685
commit
f3038e4fef
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user