Merge pull request #2335 from ktos/bookmarks-newsqlite

Switch Bookmarks plugin to use Microsoft.Data.Sqlite
This commit is contained in:
Jeremy Wu 2023-10-24 21:34:13 +11:00 committed by GitHub
commit 026e5f5b09
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 24 deletions

View file

@ -34,6 +34,17 @@ namespace Flow.Launcher.Core.Plugin
return existAssembly ?? (assemblyPath == null ? null : LoadFromAssemblyPath(assemblyPath));
}
protected override IntPtr LoadUnmanagedDll(string unmanagedDllName)
{
var path = dependencyResolver.ResolveUnmanagedDllToPath(unmanagedDllName);
if (!string.IsNullOrEmpty(path))
{
return LoadUnmanagedDllFromPath(path);
}
return IntPtr.Zero;
}
internal Type FromAssemblyGetTypeOfInterface(Assembly assembly, Type type)
{
@ -41,4 +52,4 @@ namespace Flow.Launcher.Core.Plugin
return allTypes.First(o => o.IsClass && !o.IsAbstract && o.GetInterfaces().Any(t => t == type));
}
}
}
}

View file

@ -1,7 +1,7 @@
using Flow.Launcher.Plugin.BrowserBookmark.Models;
using Microsoft.Data.Sqlite;
using System;
using System.Collections.Generic;
using System.Data.SQLite;
using System.IO;
using System.Linq;
@ -19,7 +19,7 @@ namespace Flow.Launcher.Plugin.BrowserBookmark
ORDER BY moz_places.visit_count DESC
";
private const string dbPathFormat = "Data Source ={0};Version=3;New=False;Compress=True;";
private const string dbPathFormat = "Data Source ={0}";
protected static List<Bookmark> GetBookmarksFromPath(string placesPath)
{
@ -33,11 +33,11 @@ namespace Flow.Launcher.Plugin.BrowserBookmark
// create the connection string and init the connection
string dbPath = string.Format(dbPathFormat, placesPath);
using var dbConnection = new SQLiteConnection(dbPath);
using var dbConnection = new SqliteConnection(dbPath);
// Open connection to the database file and execute the query
dbConnection.Open();
var reader = new SQLiteCommand(queryAllBookmarks, dbConnection).ExecuteReader();
var reader = new SqliteCommand(queryAllBookmarks, dbConnection).ExecuteReader();
// return results in List<Bookmark> format
bookmarkList = reader.Select(
x => new Bookmark(x["title"] is DBNull ? string.Empty : x["title"].ToString(),
@ -133,7 +133,7 @@ namespace Flow.Launcher.Plugin.BrowserBookmark
public static class Extensions
{
public static IEnumerable<T> Select<T>(this SQLiteDataReader reader, Func<SQLiteDataReader, T> projection)
public static IEnumerable<T> Select<T>(this SqliteDataReader reader, Func<SqliteDataReader, T> projection)
{
while (reader.Read())
{

View file

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Library</OutputType>
@ -56,22 +56,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="System.Data.SQLite" Version="1.0.118" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="7.0.10" />
</ItemGroup>
<ItemGroup>
<Compile Remove="Bookmark.cs" />
</ItemGroup>
<Target Name="CopyDLLs" AfterTargets="Build">
<Message Text="Executing CopyDLLs task" Importance="High" />
<Copy SourceFiles="$(TargetDir)\runtimes\win-x64\native\SQLite.Interop.dll" DestinationFolder="$(TargetDir)\x64" />
<Copy SourceFiles="$(TargetDir)\runtimes\win-x86\native\SQLite.Interop.dll" DestinationFolder="$(TargetDir)\x86" />
</Target>
<Target Name="DeleteRuntimesFolder" AfterTargets="CopyDLLs">
<Message Text="Deleting runtimes folder" Importance="High" />
<RemoveDir Directories="$(TargetDir)\runtimes" />
</Target>
</Project>