2014-03-19 04:05:27 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2016-07-22 02:51:47 +08:00
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.IO;
|
2014-03-19 04:05:27 +08:00
|
|
|
|
|
2016-07-22 02:51:47 +08:00
|
|
|
|
namespace Wox.Plugin.Program.ProgramSources
|
2014-03-19 04:05:27 +08:00
|
|
|
|
{
|
|
|
|
|
[Serializable]
|
2016-07-22 02:51:47 +08:00
|
|
|
|
public abstract class ProgramSource
|
2014-03-19 04:05:27 +08:00
|
|
|
|
{
|
2016-07-22 02:51:47 +08:00
|
|
|
|
public const char SuffixSeperator = ';';
|
|
|
|
|
|
|
|
|
|
public int BonusPoints { get; set; } = 0;
|
|
|
|
|
public bool Enabled { get; set; } = true;
|
2016-04-25 01:34:49 +08:00
|
|
|
|
// happlebao todo: temp hack for program suffixes
|
|
|
|
|
public string[] Suffixes { get; set; } = {"bat", "appref-ms", "exe", "lnk"};
|
2016-07-22 02:51:47 +08:00
|
|
|
|
public int MaxDepth { get; set; } = -1;
|
2014-03-19 20:16:20 +08:00
|
|
|
|
|
2016-07-22 02:51:47 +08:00
|
|
|
|
public abstract List<Program> LoadPrograms();
|
|
|
|
|
|
|
|
|
|
protected Program CreateEntry(string file)
|
2014-03-19 20:16:20 +08:00
|
|
|
|
{
|
2016-07-22 02:51:47 +08:00
|
|
|
|
var p = new Program
|
|
|
|
|
{
|
|
|
|
|
Title = Path.GetFileNameWithoutExtension(file),
|
|
|
|
|
IcoPath = file,
|
|
|
|
|
Path = file,
|
|
|
|
|
Directory = Directory.GetParent(file).FullName
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
switch (Path.GetExtension(file).ToLower())
|
|
|
|
|
{
|
|
|
|
|
case ".exe":
|
|
|
|
|
p.ExecutableName = Path.GetFileName(file);
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var versionInfo = FileVersionInfo.GetVersionInfo(file);
|
|
|
|
|
if (!string.IsNullOrEmpty(versionInfo.FileDescription))
|
|
|
|
|
{
|
|
|
|
|
p.Title = versionInfo.FileDescription;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return p;
|
2014-03-19 20:16:20 +08:00
|
|
|
|
}
|
2014-03-19 04:05:27 +08:00
|
|
|
|
}
|
2016-07-22 02:51:47 +08:00
|
|
|
|
}
|