-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.cs
84 lines (68 loc) · 2.78 KB
/
Main.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
// requires nu-get package tlbimp-microsoft.search.interop
// references COM object ADODB (microsoft activex data object b691e011-1797-432e-907a-4d8c69339129)
//
// TODO
// configuralize SCOPE path
using System.Collections.Generic;
using Flow.Launcher.Plugin;
using ADODB;
using Flow.Launcher.Plugin.SharedCommands;
using System;
namespace HelloWorldCSharp
{
public class Main : IPlugin, IPluginI18n
{
internal PluginInitContext Context;
internal Microsoft.Search.Interop.CSearchCatalogManager searchCatalogManager;
public List<Result> Query(Query query)
{
var query_helper = searchCatalogManager.GetQueryHelper();
query_helper.QueryMaxResults = 10;
query_helper.QuerySelectColumns = "System.ItemUrl";
query_helper.QueryWhereRestrictions = "AND SCOPE = 'C:\\Users\\jesus\\backed-up\\plain\\Investigacion'";
if (query.Search.Trim().Length == 0) {
return new List<Result>();
}
var sql_query = query_helper.GenerateSQLFromUserQuery(query.Search.Trim());
var connection = new ADODB.Connection();
connection.Open("Provider=Search.CollatorDSO;Extended Properties='Application=Windows';");
var recordset = new ADODB.Recordset();
recordset.Open(sql_query, connection);
var results = new List<Result>();
while (!recordset.EOF) {
// just one column
var file_uri_string = recordset.Fields[0].Value;
var file_uri = new Uri(file_uri_string);
var file_path = file_uri.LocalPath;
var result = new Result
{
Title = System.IO.Path.GetFileName(file_path),
SubTitle = System.IO.Path.GetDirectoryName(file_path),
Action = c =>
{
FilesFolders.OpenPath(file_path);
return true;
},
IcoPath = "Images/app.png"
};
results.Add(result);
recordset.MoveNext();
}
return results;
}
public void Init(PluginInitContext context)
{
Context = context;
var searchManager = new Microsoft.Search.Interop.CSearchManagerClass();
searchCatalogManager = searchManager.GetCatalog("SystemIndex");
}
public string GetTranslatedPluginTitle()
{
return Context.API.GetTranslation("plugin_helloworldcsharp_plugin_name");
}
public string GetTranslatedPluginDescription()
{
return Context.API.GetTranslation("plugin_helloworldcsharp_plugin_description");
}
}
}