Update SQLite, remove unneeded libraries

This commit is contained in:
Natsumi
2025-08-31 13:38:38 +12:00
parent d854f3f009
commit 9e08758157
13 changed files with 122 additions and 83 deletions

View File

@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputPath>..\build\Cef\</OutputPath>
</PropertyGroup>
@@ -37,13 +37,6 @@
<SelfContained Condition="'$(SelfContained)' == ''">false</SelfContained>
</PropertyGroup>
<PropertyGroup>
<ContentSQLiteInteropFiles>true</ContentSQLiteInteropFiles>
<CopySQLiteInteropFiles>true</CopySQLiteInteropFiles>
<CleanSQLiteInteropFiles>false</CleanSQLiteInteropFiles>
<CollectSQLiteInteropFiles>false</CollectSQLiteInteropFiles>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NLog" Version="6.0.3" />
<PackageReference Include="sqlite-net-pcl" Version="1.9.172" />

View File

@@ -89,11 +89,18 @@ namespace VRCX
if (File.Exists(vueDevtoolsCrxPath))
{
var vueDevtoolsPath = Path.Join(extensionsPath, "Vue-js-devtools");
if (!Directory.Exists(vueDevtoolsPath))
try
{
if (Directory.Exists(vueDevtoolsPath))
Directory.Delete(vueDevtoolsPath, true);
Directory.CreateDirectory(vueDevtoolsPath);
ZipFile.ExtractToDirectory(vueDevtoolsCrxPath, vueDevtoolsPath);
}
catch (Exception ex)
{
logger.Error(ex, "Failed to extract Vue Devtools");
}
}
// load extensions

View File

@@ -10,7 +10,7 @@ namespace VRCX
repository.Register("AppApi", Program.AppApiInstance);
repository.Register("WebApi", WebApi.Instance);
repository.Register("VRCXStorage", VRCXStorage.Instance);
repository.Register("SQLite", SQLiteLegacy.Instance);
repository.Register("SQLite", SQLite.Instance);
repository.Register("LogWatcher", LogWatcher.Instance);
repository.Register("Discord", Discord.Instance);
repository.Register("AssetBundleManager", AssetBundleManager.Instance);

View File

@@ -230,7 +230,7 @@ namespace VRCX
logger.Info("Launch Command: {0}", StartupArgs.LaunchArguments.LaunchCommand);
logger.Debug("Wine detection: {0}", Wine.GetIfWine());
SQLiteLegacy.Instance.Init();
SQLite.Instance.Init();
AppApiInstance = new AppApiCef();
AppApiVrInstance = new AppApiVrCef();
@@ -262,7 +262,7 @@ namespace VRCX
Discord.Instance.Exit();
SystemMonitorCef.Instance.Exit();
VRCXStorage.Instance.Save();
SQLiteLegacy.Instance.Exit();
SQLite.Instance.Exit();
ProcessMonitor.Instance.Exit();
}
#else

View File

@@ -8,18 +8,18 @@ using System.Text.Json;
namespace VRCX
{
public class SQLiteLegacy
public class SQLite
{
public static SQLiteLegacy Instance;
public static SQLite Instance;
private readonly ReaderWriterLockSlim m_ConnectionLock;
private SQLiteConnection m_Connection;
static SQLiteLegacy()
static SQLite()
{
Instance = new SQLiteLegacy();
Instance = new SQLite();
}
public SQLiteLegacy()
public SQLite()
{
m_ConnectionLock = new ReaderWriterLockSlim();
}

View File

@@ -1,23 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SQLite;
using System.Data.SQLite;
namespace VRCX
{
[Table("cache")]
public class MetadataCache
{
[PrimaryKey, AutoIncrement]
[Column("id")]
public int Id { get; set; }
[Column("file_path"), NotNull, Indexed]
public string FilePath { get; set; }
[Column("metadata")]
public string Metadata { get; set; }
[Column("cached_at"), NotNull]
public string? Metadata { get; set; }
public DateTimeOffset CachedAt { get; set; }
}
@@ -25,61 +16,135 @@ namespace VRCX
// Couldn't be me... oh wait
internal class ScreenshotMetadataDatabase
{
private SQLiteConnection sqlite;
private readonly SQLiteConnection _sqlite;
public ScreenshotMetadataDatabase(string databaseLocation)
{
var options = new SQLiteConnectionString(databaseLocation, true);
sqlite = new SQLiteConnection(options);
sqlite.CreateTable<MetadataCache>();
_sqlite = new SQLiteConnection($"Data Source=\"{databaseLocation}\";Version=3;PRAGMA locking_mode=NORMAL;PRAGMA busy_timeout=5000;PRAGMA journal_mode=WAL;PRAGMA optimize=0x10002;", true);
_sqlite.Open();
using var cmd = new SQLiteCommand(_sqlite);
cmd.CommandText = @"CREATE TABLE IF NOT EXISTS cache (
id INTEGER PRIMARY KEY AUTOINCREMENT,
file_path TEXT NOT NULL UNIQUE,
metadata TEXT,
cached_at INTEGER NOT NULL
);";
cmd.ExecuteNonQuery();
}
public void AddMetadataCache(string filePath, string metadata)
{
// old table schema didn't have filePath as unique
var isFileCached = IsFileCached(filePath);
if (isFileCached != -1)
return;
var cache = new MetadataCache()
{
FilePath = filePath,
Metadata = metadata,
CachedAt = DateTimeOffset.Now
};
sqlite.Insert(cache);
const string sql = "INSERT OR REPLACE INTO cache (file_path, metadata, cached_at) VALUES (@FilePath, @Metadata, @CachedAt);";
using var command = new SQLiteCommand(sql, _sqlite);
command.Parameters.AddWithValue("@FilePath", cache.FilePath);
command.Parameters.AddWithValue("@Metadata", cache.Metadata);
command.Parameters.AddWithValue("@CachedAt", cache.CachedAt.Ticks);
command.ExecuteNonQuery();
}
public void BulkAddMetadataCache(IEnumerable<MetadataCache> cache)
{
sqlite.InsertAll(cache, runInTransaction: true);
using var transaction = _sqlite.BeginTransaction();
using var command = new SQLiteCommand(_sqlite);
const string sql = "INSERT OR REPLACE INTO cache (file_path, metadata, cached_at) VALUES (@FilePath, @Metadata, @CachedAt);";
command.CommandText = sql;
var filePathParam = command.Parameters.Add("@FilePath", System.Data.DbType.String);
var metadataParam = command.Parameters.Add("@Metadata", System.Data.DbType.String);
var cachedAtParam = command.Parameters.Add("@CachedAt", System.Data.DbType.Int64);
foreach (var item in cache)
{
var isFileCached = IsFileCached(item.FilePath);
if (isFileCached != -1)
continue;
filePathParam.Value = item.FilePath;
metadataParam.Value = item.Metadata;
cachedAtParam.Value = item.CachedAt.Ticks;
command.ExecuteNonQuery();
}
transaction.Commit();
}
public int IsFileCached(string filePath)
{
var query = sqlite.Table<MetadataCache>().Where(c => c.FilePath == filePath).Select(c => c.Id);
if (query.Any())
const string sql = "SELECT id FROM cache WHERE file_path = @FilePath;";
using var command = new SQLiteCommand(sql, _sqlite);
command.Parameters.AddWithValue("@FilePath", filePath);
using var reader = command.ExecuteReader();
var result = new List<int>();
while (reader.Read())
{
return query.First();
result.Add(reader.GetInt32(0));
}
else
if (result.Count > 0)
{
return -1;
return result[0];
}
return -1;
}
public string GetMetadata(string filePath)
public string? GetMetadata(string filePath)
{
var query = sqlite.Table<MetadataCache>().Where(c => c.FilePath == filePath).Select(c => c.Metadata);
return query.FirstOrDefault();
const string sql = "SELECT id, file_path, metadata, cached_at FROM cache WHERE file_path = @FilePath;";
using var command = new SQLiteCommand(sql, _sqlite);
command.Parameters.AddWithValue("@FilePath", filePath);
using var reader = command.ExecuteReader();
var result = new List<MetadataCache>();
while (reader.Read())
{
result.Add(new MetadataCache()
{
Id = reader.GetInt32(0),
FilePath = reader.GetString(1),
Metadata = reader.IsDBNull(2) ? null : reader.GetString(2),
CachedAt = new DateTime(reader.GetInt64(3))
});
}
if (result.Count > 0)
{
return result[0].Metadata;
}
return null;
}
public string GetMetadataById(int id)
public string? GetMetadataById(int id)
{
var query = sqlite.Table<MetadataCache>().Where(c => c.Id == id).Select(c => c.Metadata);
return query.FirstOrDefault();
const string sql = "SELECT id, file_path, metadata, cached_at FROM cache WHERE id = @Id;";
using var command = new SQLiteCommand(sql, _sqlite);
command.Parameters.AddWithValue("@Id", id);
using var reader = command.ExecuteReader();
var result = new List<MetadataCache>();
while (reader.Read())
{
result.Add(new MetadataCache()
{
Id = reader.GetInt32(0),
FilePath = reader.GetString(1),
Metadata = reader.IsDBNull(2) ? null : reader.GetString(2),
CachedAt = new DateTime(reader.GetInt64(3))
});
}
if (result.Count > 0)
{
return result[0].Metadata;
}
return null;
}
public void Close()
{
sqlite.Close();
_sqlite.Close();
}
}
}

View File

@@ -55,12 +55,7 @@
<PropertyGroup>
<ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>
<PropertyGroup>
<ContentSQLiteInteropFiles>true</ContentSQLiteInteropFiles>
<CopySQLiteInteropFiles>true</CopySQLiteInteropFiles>
<CleanSQLiteInteropFiles>false</CleanSQLiteInteropFiles>
<CollectSQLiteInteropFiles>false</CollectSQLiteInteropFiles>
</PropertyGroup>
<ItemGroup>
<Compile Remove="DBMerger\**" />
<EmbeddedResource Remove="DBMerger\**" />
@@ -103,12 +98,10 @@
<PackageReference Include="SharpDX.Mathematics" Version="4.2.0" />
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.11" />
<PackageReference Include="SixLabors.ImageSharp.Drawing" Version="2.1.7" />
<PackageReference Include="sqlite-net-pcl" Version="1.9.172" />
<PackageReference Include="System.Data.SQLite" Version="1.0.119" />
<PackageReference Include="System.Data.SQLite" Version="2.0.1" />
<PackageReference Include="System.Data.SQLite.Core" Version="1.0.119" />
<PackageReference Include="System.Drawing.Common" Version="9.0.8" />
<PackageReference Include="System.Management" Version="9.0.8" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
<PackageReference Include="System.Text.Json" Version="9.0.8" />
<PackageReference Include="System.Text.RegularExpressions" Version="4.3.1" />
<PackageReference Include="Websocket.Client" Version="5.2.0" />

View File

@@ -54,12 +54,6 @@
<SelfContained Condition="'$(SelfContained)' == ''">false</SelfContained>
</PropertyGroup>
<PropertyGroup>
<ContentSQLiteInteropFiles>true</ContentSQLiteInteropFiles>
<CopySQLiteInteropFiles>true</CopySQLiteInteropFiles>
<CleanSQLiteInteropFiles>false</CleanSQLiteInteropFiles>
<CollectSQLiteInteropFiles>false</CollectSQLiteInteropFiles>
</PropertyGroup>
<ItemGroup>
<Reference Include="Blake2Sharp">
<HintPath>libs\Blake2Sharp.dll</HintPath>
@@ -79,14 +73,6 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<TargetPath>openvr_api.dll</TargetPath>
</None>
<None Include="libs\linux\SQLite.Interop.dll" Condition="$([MSBuild]::IsOSPlatform('Linux'))">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<TargetPath>SQLite.Interop.dll</TargetPath>
</None>
<None Include="libs\macos\SQLite.Interop.dll" Condition="$([MSBuild]::IsOSPlatform('OSX'))">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<TargetPath>SQLite.Interop.dll</TargetPath>
</None>
<Content Include="..\VRCX.ico">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
@@ -98,19 +84,14 @@
<PackageReference Include="Microsoft.JavaScript.NodeApi" Version="0.9.15" />
<PackageReference Include="Microsoft.JavaScript.NodeApi.Generator" Version="0.9.15" />
<PackageReference Include="DiscordRichPresence" Version="1.6.1.70" />
<PackageReference Include="Microsoft.Toolkit.Uwp.Notifications" Version="7.1.3" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="NLog" Version="6.0.3" />
<PackageReference Include="SharpDX.Direct3D11" Version="4.2.0" />
<PackageReference Include="SharpDX.Mathematics" Version="4.2.0" />
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.11" />
<PackageReference Include="SixLabors.ImageSharp.Drawing" Version="2.1.7" />
<PackageReference Include="sqlite-net-pcl" Version="1.9.172" />
<PackageReference Include="System.Data.SQLite" Version="1.0.119" />
<PackageReference Include="System.Data.SQLite" Version="2.0.1" />
<PackageReference Include="System.Data.SQLite.Core" Version="1.0.119" />
<PackageReference Include="System.Drawing.Common" Version="9.0.8" />
<PackageReference Include="System.Management" Version="9.0.8" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
<PackageReference Include="System.Text.Json" Version="9.0.8" />
<PackageReference Include="System.Text.RegularExpressions" Version="4.3.1" />
<PackageReference Include="Websocket.Client" Version="5.2.0" />

View File

@@ -121,8 +121,8 @@ namespace VRCX
private void LoadCookies()
{
SQLiteLegacy.Instance.ExecuteNonQuery("CREATE TABLE IF NOT EXISTS `cookies` (`key` TEXT PRIMARY KEY, `value` TEXT)");
var values = SQLiteLegacy.Instance.Execute("SELECT `value` FROM `cookies` WHERE `key` = @key",
SQLite.Instance.ExecuteNonQuery("CREATE TABLE IF NOT EXISTS `cookies` (`key` TEXT PRIMARY KEY, `value` TEXT)");
var values = SQLite.Instance.Execute("SELECT `value` FROM `cookies` WHERE `key` = @key",
new Dictionary<string, object>
{
{ "@key", "default" }
@@ -190,7 +190,7 @@ namespace VRCX
var cookies = GetAllCookies();
using var memoryStream = new MemoryStream();
System.Text.Json.JsonSerializer.Serialize(memoryStream, cookies);
SQLiteLegacy.Instance.ExecuteNonQuery(
SQLite.Instance.ExecuteNonQuery(
"INSERT OR REPLACE INTO `cookies` (`key`, `value`) VALUES (@key, @value)",
new Dictionary<string, object>() {
{"@key", "default"},

Binary file not shown.

Binary file not shown.

View File

@@ -101,7 +101,7 @@ const version = getVersion();
interopApi.getDotNetObject('ProgramElectron').PreInit(version, args);
interopApi.getDotNetObject('VRCXStorage').Load();
interopApi.getDotNetObject('ProgramElectron').Init();
interopApi.getDotNetObject('SQLiteLegacy').Init();
interopApi.getDotNetObject('SQLite').Init();
interopApi.getDotNetObject('AppApiElectron').Init();
interopApi.getDotNetObject('Discord').Init();
interopApi.getDotNetObject('WebApi').Init();

View File

@@ -16,9 +16,9 @@ if (WINDOWS) {
window.AppApi = InteropApi.AppApiElectron;
window.WebApi = InteropApi.WebApi;
window.VRCXStorage = InteropApi.VRCXStorage;
window.SQLite = InteropApi.SQLiteLegacy;
window.SQLite = InteropApi.SQLite;
window.LogWatcher = InteropApi.LogWatcher;
window.Discord = InteropApi.Discord;
window.AssetBundleManager = InteropApi.AssetBundleManager;
window.AppApiVrElectron = InteropApi.AppApiVrElectron;
}
}