forked from davidtrautmann/Wox.Plugin.AxLauncher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAxLauncher.cs
121 lines (112 loc) · 3.72 KB
/
AxLauncher.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Management;
using System.IO;
using Newtonsoft.Json;
namespace Wox.Plugin.AxLauncher
{
/// <summary>
/// Launcher class for axc files.
/// </summary>
public class AxLauncher : IPlugin, ISettingProvider
{
/// <summary>
/// Settings store object.
/// </summary>
public static Settings settings;
/// <summary>
/// Process the query.
/// </summary>
/// <param name="query"></param>
/// <returns></returns>
public List<Result> Query(Query query)
{
string[] axcFiles;
string searchPattern;
List<Result> results = new List<Result>();
// check if search parameter is given
if (query.ActionParameters.Count == 0)
{
// no search parameter
// show all .axc files
searchPattern = "*.axc";
}
else
{
// search for files *parameters*.axc
searchPattern = "*";
foreach (string parameter in query.ActionParameters)
{
searchPattern += parameter + "*";
}
searchPattern += ".axc";
}
if (String.Empty.Equals(settings.axcPath.Trim()))
{
axcFiles = new string[] { "Define the axc path in settings" };
}
else
{
axcFiles = Directory.GetFiles(settings.axcPath, searchPattern, SearchOption.AllDirectories);
}
foreach (string axcFile in axcFiles)
{
results.Add(new Result()
{
Title = axcFile.Substring(axcFile.LastIndexOf("\\") + 1),
SubTitle = axcFile,
IcoPath = "Images\\app.png",
Action = e =>
{
try
{
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = axcFile;
Process.Start(startInfo);
}
catch
{
return false;
}
return true;
}
});
}
return results;
}
/// <summary>
/// Init method. Loads the settings from the settings.json file.
/// </summary>
/// <param name="context"></param>
public void Init(PluginInitContext context)
{
string settingsPath = System.IO.Path.Combine(context.CurrentPluginMetadata.PluginDirectory, "settings.json");
try
{
settings = JsonConvert.DeserializeObject<Settings>(System.IO.File.ReadAllText(settingsPath));
}
catch
{
settings = new Settings();
settings.settingsPath = settingsPath;
}
}
/// <summary>
/// Create the settings panel for ax launcher.
/// </summary>
public System.Windows.Controls.Control CreateSettingPanel()
{
return new Setting();
}
/// <summary>
/// Save the settings object into the settings.json file.
/// </summary>
public static void saveSettings()
{
settings.saveSettings();
}
}
}