mirror of
https://github.com/MrUnknownDE/VRCX.git
synced 2026-05-07 14:56:06 +02:00
store cookies to sqlite
This commit is contained in:
+3
-3
@@ -3,7 +3,6 @@
|
|||||||
// This work is licensed under the terms of the MIT license.
|
// This work is licensed under the terms of the MIT license.
|
||||||
// For a copy, see <https://opensource.org/licenses/MIT>.
|
// For a copy, see <https://opensource.org/licenses/MIT>.
|
||||||
|
|
||||||
using CefSharp.DevTools.Runtime;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
@@ -37,10 +36,10 @@ namespace VRCX
|
|||||||
Application.EnableVisualStyles();
|
Application.EnableVisualStyles();
|
||||||
Application.SetCompatibleTextRenderingDefault(false);
|
Application.SetCompatibleTextRenderingDefault(false);
|
||||||
|
|
||||||
|
SQLite.Instance.Init();
|
||||||
VRCXStorage.Load();
|
VRCXStorage.Load();
|
||||||
CpuMonitor.Instance.Init();
|
CpuMonitor.Instance.Init();
|
||||||
Discord.Instance.Init();
|
Discord.Instance.Init();
|
||||||
SQLite.Instance.Init();
|
|
||||||
WebApi.Instance.Init();
|
WebApi.Instance.Init();
|
||||||
LogWatcher.Instance.Init();
|
LogWatcher.Instance.Init();
|
||||||
|
|
||||||
@@ -52,10 +51,11 @@ namespace VRCX
|
|||||||
|
|
||||||
LogWatcher.Instance.Exit();
|
LogWatcher.Instance.Exit();
|
||||||
WebApi.Instance.Exit();
|
WebApi.Instance.Exit();
|
||||||
SQLite.Instance.Exit();
|
|
||||||
Discord.Instance.Exit();
|
Discord.Instance.Exit();
|
||||||
CpuMonitor.Instance.Exit();
|
CpuMonitor.Instance.Exit();
|
||||||
VRCXStorage.Save();
|
VRCXStorage.Save();
|
||||||
|
SQLite.Instance.Exit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,6 +78,40 @@ namespace VRCX
|
|||||||
callback.Dispose();
|
callback.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Execute(Action<object[]> callback, string sql, IDictionary<string, object> args = null)
|
||||||
|
{
|
||||||
|
m_ConnectionLock.EnterReadLock();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (var command = new SQLiteCommand(sql, m_Connection))
|
||||||
|
{
|
||||||
|
if (args != null)
|
||||||
|
{
|
||||||
|
foreach (var arg in args)
|
||||||
|
{
|
||||||
|
command.Parameters.Add(new SQLiteParameter(arg.Key, arg.Value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
using (var reader = command.ExecuteReader())
|
||||||
|
{
|
||||||
|
while (reader.Read() == true)
|
||||||
|
{
|
||||||
|
var values = new object[reader.FieldCount];
|
||||||
|
reader.GetValues(values);
|
||||||
|
callback(values);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
m_ConnectionLock.ExitReadLock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public int ExecuteNonQuery(string sql, IDictionary<string, object> args = null)
|
public int ExecuteNonQuery(string sql, IDictionary<string, object> args = null)
|
||||||
{
|
{
|
||||||
int result = -1;
|
int result = -1;
|
||||||
@@ -97,9 +131,6 @@ namespace VRCX
|
|||||||
result = command.ExecuteNonQuery();
|
result = command.ExecuteNonQuery();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch
|
|
||||||
{
|
|
||||||
}
|
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
m_ConnectionLock.ExitWriteLock();
|
m_ConnectionLock.ExitWriteLock();
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ namespace VRCX
|
|||||||
public class WebApi
|
public class WebApi
|
||||||
{
|
{
|
||||||
public static readonly WebApi Instance;
|
public static readonly WebApi Instance;
|
||||||
private readonly string _cookieFilePath;
|
|
||||||
private CookieContainer _cookieContainer;
|
private CookieContainer _cookieContainer;
|
||||||
|
|
||||||
static WebApi()
|
static WebApi()
|
||||||
@@ -21,31 +20,46 @@ namespace VRCX
|
|||||||
|
|
||||||
public WebApi()
|
public WebApi()
|
||||||
{
|
{
|
||||||
_cookieFilePath = Path.Combine(Program.BaseDirectory, "cookies.dat");
|
|
||||||
_cookieContainer = new CookieContainer();
|
_cookieContainer = new CookieContainer();
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void Init()
|
internal void Init()
|
||||||
|
{
|
||||||
|
SQLite.Instance.ExecuteNonQuery("CREATE TABLE IF NOT EXISTS `cookies` (`key` TEXT PRIMARY KEY, `value` TEXT)");
|
||||||
|
SQLite.Instance.Execute((values) =>
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (var file = File.Open(_cookieFilePath, FileMode.Open, FileAccess.Read))
|
using (var stream = new MemoryStream(Convert.FromBase64String((string)values[0])))
|
||||||
{
|
{
|
||||||
_cookieContainer = (CookieContainer)new BinaryFormatter().Deserialize(file);
|
_cookieContainer = (CookieContainer)new BinaryFormatter().Deserialize(stream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"SELECT `value` FROM `cookies` WHERE `key` = @key",
|
||||||
|
new Dictionary<string, object>() {
|
||||||
|
{"@key", "default"}
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void Exit()
|
internal void Exit()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (var file = File.Open(_cookieFilePath, FileMode.Create, FileAccess.Write))
|
using (var memoryStream = new MemoryStream())
|
||||||
{
|
{
|
||||||
new BinaryFormatter().Serialize(file, _cookieContainer);
|
new BinaryFormatter().Serialize(memoryStream, _cookieContainer);
|
||||||
|
SQLite.Instance.ExecuteNonQuery(
|
||||||
|
"INSERT OR REPLACE INTO `cookies` (`key`, `value`) VALUES (@key, @value)",
|
||||||
|
new Dictionary<string, object>() {
|
||||||
|
{"@key", "default"},
|
||||||
|
{"@value", Convert.ToBase64String(memoryStream.ToArray())}
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
|
|||||||
Reference in New Issue
Block a user