2016-08-20 06:05:59 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using Wox.Infrastructure.Exception;
|
|
|
|
|
using Wox.Infrastructure.Logger;
|
|
|
|
|
|
2016-08-20 08:17:28 +08:00
|
|
|
|
namespace Wox.Plugin.Program.Programs
|
2016-08-20 06:05:59 +08:00
|
|
|
|
{
|
|
|
|
|
[Serializable]
|
2016-08-20 08:17:28 +08:00
|
|
|
|
public class Win32
|
2016-08-20 06:05:59 +08:00
|
|
|
|
{
|
2016-08-20 08:17:28 +08:00
|
|
|
|
public string Title { get; set; }
|
|
|
|
|
public string IcoPath { get; set; }
|
|
|
|
|
public string ExecutablePath { get; set; }
|
|
|
|
|
public string Directory { get; set; }
|
|
|
|
|
public string ExecutableName { get; set; }
|
|
|
|
|
public int Score { get; set; }
|
2016-08-20 06:05:59 +08:00
|
|
|
|
|
2016-08-20 08:17:28 +08:00
|
|
|
|
protected static Win32 CreateEntry(string file)
|
2016-08-20 06:05:59 +08:00
|
|
|
|
{
|
2016-08-20 08:17:28 +08:00
|
|
|
|
var p = new Win32
|
2016-08-20 06:05:59 +08:00
|
|
|
|
{
|
|
|
|
|
Title = Path.GetFileNameWithoutExtension(file),
|
|
|
|
|
IcoPath = file,
|
2016-08-20 08:17:28 +08:00
|
|
|
|
ExecutablePath = file,
|
|
|
|
|
Directory = System.IO.Directory.GetParent(file).FullName
|
2016-08-20 06:05:59 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-20 08:17:28 +08:00
|
|
|
|
protected static void GetAppFromDirectory(List<Win32> apps, string directory, int depth, string[] suffixes)
|
2016-08-20 06:05:59 +08:00
|
|
|
|
{
|
2016-08-20 08:17:28 +08:00
|
|
|
|
if (depth == -1)
|
2016-08-20 06:05:59 +08:00
|
|
|
|
{
|
2016-08-20 08:17:28 +08:00
|
|
|
|
}
|
|
|
|
|
else if (depth > 0)
|
|
|
|
|
{
|
|
|
|
|
depth = depth - 1;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var f in System.IO.Directory.GetFiles(directory))
|
|
|
|
|
{
|
|
|
|
|
if (suffixes.Any(o => f.EndsWith("." + o)))
|
2016-08-20 06:05:59 +08:00
|
|
|
|
{
|
2016-08-20 08:17:28 +08:00
|
|
|
|
Win32 p;
|
|
|
|
|
try
|
2016-08-20 06:05:59 +08:00
|
|
|
|
{
|
2016-08-20 08:17:28 +08:00
|
|
|
|
p = CreateEntry(f);
|
2016-08-20 06:05:59 +08:00
|
|
|
|
}
|
2016-08-20 08:17:28 +08:00
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
var woxPluginException = new WoxPluginException("Program",
|
|
|
|
|
$"GetAppFromDirectory failed: {directory}", e);
|
|
|
|
|
Log.Exception(woxPluginException);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
apps.Add(p);
|
2016-08-20 06:05:59 +08:00
|
|
|
|
}
|
2016-08-20 08:17:28 +08:00
|
|
|
|
}
|
|
|
|
|
foreach (var d in System.IO.Directory.GetDirectories(directory))
|
|
|
|
|
{
|
|
|
|
|
GetAppFromDirectory(apps, d, depth, suffixes);
|
2016-08-20 06:05:59 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|