mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-01-18 22:43:31 +08:00
Add PortableApps.com program source support. #42
This commit is contained in:
parent
07c13d84be
commit
aab0bf369d
119
Wox.Plugin.System/PortableAppsProgramSource.cs
Normal file
119
Wox.Plugin.System/PortableAppsProgramSource.cs
Normal file
@ -0,0 +1,119 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using IniParser;
|
||||
namespace Wox.Plugin.System
|
||||
{
|
||||
public class PortableAppsProgramSource : AbstractProgramSource
|
||||
{
|
||||
public string BaseDirectory;
|
||||
|
||||
public PortableAppsProgramSource(string baseDirectory)
|
||||
{
|
||||
BaseDirectory = baseDirectory;
|
||||
}
|
||||
|
||||
public override List<Program> LoadPrograms()
|
||||
{
|
||||
List<Program> list = new List<Program>();
|
||||
var ini = new IniParser.Parser.IniDataParser();
|
||||
ini.Configuration.AllowDuplicateKeys = true;
|
||||
|
||||
string menuSettingsPath = Path.Combine(BaseDirectory, @"PortableApps.com\Data\PortableAppsMenu.ini");
|
||||
|
||||
IniParser.Model.KeyDataCollection appsRenamed = null, appsRecategorized = null, appsHidden = null;
|
||||
if (File.Exists(menuSettingsPath))
|
||||
{
|
||||
var menuSettings = ini.Parse(File.ReadAllText(menuSettingsPath, Encoding.Default));
|
||||
appsRenamed = menuSettings["AppsRenamed"];
|
||||
appsRecategorized = menuSettings["AppsRecategorized"];
|
||||
appsHidden = menuSettings["AppsHidden"];
|
||||
}
|
||||
if (appsRenamed == null) appsRenamed = new IniParser.Model.KeyDataCollection();
|
||||
if (appsRecategorized == null) appsRecategorized = new IniParser.Model.KeyDataCollection();
|
||||
if (appsHidden == null) appsHidden = new IniParser.Model.KeyDataCollection();
|
||||
|
||||
foreach (var appDir in Directory.GetDirectories(BaseDirectory))
|
||||
{
|
||||
var appDirName = Path.GetDirectoryName(appDir);
|
||||
var appInfoPath = Path.Combine(appDir, @"App\AppInfo\appinfo.ini");
|
||||
var appInfoValid = false;
|
||||
|
||||
if (File.Exists(appInfoPath))
|
||||
{
|
||||
var appInfo = ini.Parse(File.ReadAllText(appInfoPath, Encoding.Default));
|
||||
var appName = appInfo["Details"]["Name"] ?? appDirName;
|
||||
var control = appInfo["Control"];
|
||||
int count;
|
||||
if (Int32.TryParse(control["Icons"], out count))
|
||||
{
|
||||
appInfoValid = true;
|
||||
for (int i = 1; i <= count; i++)
|
||||
{
|
||||
string cmdline, name, icon;
|
||||
cmdline = control[String.Format("Start{0}", i)];
|
||||
name = control[String.Format("Name{0}", i)];
|
||||
icon = control[String.Format("ExtractIcon{0}", i)];
|
||||
|
||||
if (i == 1)
|
||||
{
|
||||
if (cmdline == null) cmdline = control["Start"];
|
||||
if (cmdline == null) continue;
|
||||
|
||||
if (name == null) name = appName;
|
||||
if (icon == null) icon = control["ExtractIcon"];
|
||||
if (icon == null && !File.Exists(icon = Path.Combine(appDir, @"App\AppInfo\appicon.ico"))) icon = null;
|
||||
}
|
||||
|
||||
if (cmdline == null) continue;
|
||||
if (name == null) name = String.Format("{0} #{1}", appName, i);
|
||||
if (icon == null) icon = Path.Combine(appDir, String.Format(@"App\AppInfo\appicon{0}.ico", i));
|
||||
|
||||
cmdline = Path.Combine(appDir, cmdline);
|
||||
var menuKey = (appDirName + @"\" + cmdline).ToLower();
|
||||
|
||||
var renamed = appsRenamed[menuKey];
|
||||
if (renamed != null)
|
||||
name = renamed;
|
||||
|
||||
var hidden = appsHidden[menuKey] == "true";
|
||||
|
||||
if (!hidden)
|
||||
{
|
||||
Program p = new Program()
|
||||
{
|
||||
Title = name,
|
||||
IcoPath = icon,
|
||||
ExecutePath = cmdline
|
||||
};
|
||||
list.Add(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!appInfoValid)
|
||||
{
|
||||
foreach (var item in Directory.GetFiles(appDir, "*.exe", SearchOption.TopDirectoryOnly))
|
||||
{
|
||||
var menuKey = Path.GetFullPath(item).Substring(Path.GetFullPath(BaseDirectory).Length + 1).ToLower();
|
||||
|
||||
if (appsHidden[menuKey] != "true")
|
||||
{
|
||||
var p = CreateEntry(item);
|
||||
var renamed = appsRenamed[menuKey];
|
||||
if (renamed != null)
|
||||
p.Title = renamed;
|
||||
|
||||
list.Add(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
}
|
||||
}
|
@ -32,6 +32,9 @@
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="INIFileParser">
|
||||
<HintPath>..\packages\ini-parser.2.0.2\lib\INIFileParser.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json">
|
||||
<HintPath>..\packages\Newtonsoft.Json.5.0.8\lib\net35\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
@ -49,6 +52,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="AppPathsProgramSource.cs" />
|
||||
<Compile Include="PortableAppsProgramSource.cs" />
|
||||
<Compile Include="IProgramSource.cs" />
|
||||
<Compile Include="BaseSystemPlugin.cs" />
|
||||
<Compile Include="BrowserBookmarks.cs" />
|
||||
|
@ -1,5 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="ini-parser" version="2.0.2" targetFramework="net35" />
|
||||
<package id="Newtonsoft.Json" version="5.0.8" targetFramework="net35" />
|
||||
<package id="YAMP" version="1.3.0" targetFramework="net35" />
|
||||
</packages>
|
Loading…
Reference in New Issue
Block a user