2014-03-19 02:06:51 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2014-03-19 03:24:15 +08:00
|
|
|
|
using System.Diagnostics;
|
2014-08-10 22:22:54 +08:00
|
|
|
|
using System.IO;
|
2014-03-19 02:06:51 +08:00
|
|
|
|
|
2014-03-30 11:16:44 +08:00
|
|
|
|
namespace Wox.Plugin.SystemPlugins.Program
|
2014-03-19 02:06:51 +08:00
|
|
|
|
{
|
|
|
|
|
public interface IProgramSource
|
|
|
|
|
{
|
|
|
|
|
List<Program> LoadPrograms();
|
|
|
|
|
int BonusPoints { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public abstract class AbstractProgramSource : IProgramSource
|
|
|
|
|
{
|
|
|
|
|
public abstract List<Program> LoadPrograms();
|
|
|
|
|
|
|
|
|
|
public int BonusPoints
|
|
|
|
|
{
|
|
|
|
|
get; set;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-10 22:22:54 +08:00
|
|
|
|
protected Program CreateEntry(string file)
|
2014-03-19 02:06:51 +08:00
|
|
|
|
{
|
2014-08-10 22:22:54 +08:00
|
|
|
|
var p = new Program()
|
2014-03-19 02:06:51 +08:00
|
|
|
|
{
|
2014-08-10 22:22:54 +08:00
|
|
|
|
Title = Path.GetFileNameWithoutExtension(file),
|
2014-03-19 02:06:51 +08:00
|
|
|
|
IcoPath = file,
|
|
|
|
|
ExecutePath = file
|
|
|
|
|
};
|
|
|
|
|
|
2014-08-10 22:22:54 +08:00
|
|
|
|
switch (Path.GetExtension(file).ToLower())
|
2014-03-19 03:24:15 +08:00
|
|
|
|
{
|
|
|
|
|
case ".exe":
|
2014-03-20 04:15:05 +08:00
|
|
|
|
p.ExecuteName = global::System.IO.Path.GetFileName(file);
|
2014-03-19 03:24:15 +08:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
FileVersionInfo versionInfo = FileVersionInfo.GetVersionInfo(file);
|
2014-08-10 22:22:54 +08:00
|
|
|
|
if (!string.IsNullOrEmpty(versionInfo.FileDescription))
|
|
|
|
|
{
|
|
|
|
|
p.Title = versionInfo.FileDescription;
|
|
|
|
|
}
|
2014-03-19 03:24:15 +08:00
|
|
|
|
}
|
|
|
|
|
catch (Exception) { }
|
|
|
|
|
break;
|
|
|
|
|
}
|
2014-03-19 02:06:51 +08:00
|
|
|
|
return p;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|