mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Update Searcher class to handle result creation
This commit is contained in:
parent
dd319c61b3
commit
be524cb6ea
1 changed files with 59 additions and 15 deletions
|
|
@ -1,6 +1,9 @@
|
|||
using System;
|
||||
using Flow.Launcher.Infrastructure.Logger;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data.OleDb;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Flow.Launcher.Plugin.Explorer.Search.WindowsIndex
|
||||
{
|
||||
|
|
@ -11,44 +14,85 @@ namespace Flow.Launcher.Plugin.Explorer.Search.WindowsIndex
|
|||
public OleDbCommand command;
|
||||
|
||||
public OleDbDataReader dataReaderResults;
|
||||
|
||||
private PluginInitContext _context;
|
||||
|
||||
private readonly object _lock = new object();
|
||||
|
||||
public Searcher(PluginInitContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
internal List<Result> ExecuteWindowsIndexSearch(string query, string connectionString)
|
||||
{
|
||||
var results = new List<Result>();
|
||||
|
||||
using (conn = new OleDbConnection(connectionString))
|
||||
try
|
||||
{
|
||||
conn.Open();
|
||||
|
||||
using (command = new OleDbCommand(query, conn))
|
||||
using (conn = new OleDbConnection(connectionString))
|
||||
{
|
||||
// Results return as an OleDbDataReader.
|
||||
using (dataReaderResults = command.ExecuteReader())
|
||||
conn.Open();
|
||||
|
||||
using (command = new OleDbCommand(query, conn))
|
||||
{
|
||||
if (dataReaderResults.HasRows)
|
||||
// Results return as an OleDbDataReader.
|
||||
using (dataReaderResults = command.ExecuteReader())
|
||||
{
|
||||
while (dataReaderResults.Read())
|
||||
if (dataReaderResults.HasRows)
|
||||
{
|
||||
if (dataReaderResults.GetValue(0) != DBNull.Value && dataReaderResults.GetValue(1) != DBNull.Value)
|
||||
while (dataReaderResults.Read())
|
||||
{
|
||||
var result = new Result
|
||||
if (dataReaderResults.GetValue(0) != DBNull.Value && dataReaderResults.GetValue(1) != DBNull.Value)
|
||||
{
|
||||
Title = dataReaderResults.GetString(0),
|
||||
SubTitle = dataReaderResults.GetString(1)
|
||||
};
|
||||
results.Add(result);
|
||||
results.Add(CreateResult(dataReaderResults));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (InvalidOperationException)
|
||||
{
|
||||
// Internal error from ExecuteReader(): Connection closed.
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Info(ex.ToString());//UPDATE THIS LOGGING
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
private Result CreateResult(OleDbDataReader dataReaderResults)
|
||||
{
|
||||
return new Result
|
||||
{
|
||||
Title = dataReaderResults.GetString(0),
|
||||
SubTitle = dataReaderResults.GetString(1),
|
||||
IcoPath = "Images\\Explorer.png",//<------CHANGE
|
||||
Action = c =>
|
||||
{
|
||||
try
|
||||
{
|
||||
Process.Start(new ProcessStartInfo
|
||||
{
|
||||
FileName = dataReaderResults.GetString(1),
|
||||
UseShellExecute = true,
|
||||
//WorkingDirectory = workingDir <----??
|
||||
});
|
||||
}
|
||||
catch (Win32Exception)
|
||||
{
|
||||
_context.API.ShowMsg("Explorer plugin: ", "Unable to open the selected file", string.Empty); //<=========
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
internal List<Result> WindowsIndexSearch(string query, string connectionString, Func<string, string> constructQuery)
|
||||
{
|
||||
lock (_lock)
|
||||
|
|
|
|||
Loading…
Reference in a new issue