mirror of
https://github.com/MrUnknownDE/VRCX.git
synced 2026-05-07 14:56:06 +02:00
more cleanup
This commit is contained in:
@@ -73,7 +73,7 @@ namespace VRCX
|
|||||||
/// <returns>The signature of the file as a base64-encoded string.</returns>
|
/// <returns>The signature of the file as a base64-encoded string.</returns>
|
||||||
public string SignFile(string Blob)
|
public string SignFile(string Blob)
|
||||||
{
|
{
|
||||||
var fileData = Convert.FromBase64CharArray(Blob.ToCharArray(), 0, Blob.Length);
|
var fileData = Convert.FromBase64String(Blob);
|
||||||
using (var sig = Librsync.ComputeSignature(new MemoryStream(fileData)))
|
using (var sig = Librsync.ComputeSignature(new MemoryStream(fileData)))
|
||||||
using (var memoryStream = new MemoryStream())
|
using (var memoryStream = new MemoryStream())
|
||||||
{
|
{
|
||||||
|
|||||||
+9
-16
@@ -34,7 +34,9 @@ namespace VRCX
|
|||||||
|
|
||||||
public string GetAssetId(string id)
|
public string GetAssetId(string id)
|
||||||
{
|
{
|
||||||
byte[] hash = SHA256.Create().ComputeHash(Encoding.UTF8.GetBytes(id));
|
using(var sha256 = SHA256.Create())
|
||||||
|
{
|
||||||
|
byte[] hash = sha256.ComputeHash(Encoding.UTF8.GetBytes(id));
|
||||||
StringBuilder idHex = new StringBuilder(hash.Length * 2);
|
StringBuilder idHex = new StringBuilder(hash.Length * 2);
|
||||||
foreach (byte b in hash)
|
foreach (byte b in hash)
|
||||||
{
|
{
|
||||||
@@ -42,6 +44,7 @@ namespace VRCX
|
|||||||
}
|
}
|
||||||
return idHex.ToString().ToUpper().Substring(0, 16);
|
return idHex.ToString().ToUpper().Substring(0, 16);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public string GetAssetVersion(int version)
|
public string GetAssetVersion(int version)
|
||||||
{
|
{
|
||||||
@@ -120,8 +123,7 @@ namespace VRCX
|
|||||||
DownloadCanceled = true;
|
DownloadCanceled = true;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (client != null)
|
client?.CancelAsync();
|
||||||
client.CancelAsync();
|
|
||||||
if (File.Exists(DownloadTempLocation))
|
if (File.Exists(DownloadTempLocation))
|
||||||
File.Delete(DownloadTempLocation);
|
File.Delete(DownloadTempLocation);
|
||||||
}
|
}
|
||||||
@@ -231,15 +233,11 @@ namespace VRCX
|
|||||||
public long GetCacheSize()
|
public long GetCacheSize()
|
||||||
{
|
{
|
||||||
var cachePath = GetVRChatCacheLocation();
|
var cachePath = GetVRChatCacheLocation();
|
||||||
if (Directory.Exists(cachePath))
|
|
||||||
{
|
if (!Directory.Exists(cachePath)) return 0;
|
||||||
|
|
||||||
return DirSize(new DirectoryInfo(cachePath));
|
return DirSize(new DirectoryInfo(cachePath));
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -250,16 +248,11 @@ namespace VRCX
|
|||||||
public long DirSize(DirectoryInfo d)
|
public long DirSize(DirectoryInfo d)
|
||||||
{
|
{
|
||||||
long size = 0;
|
long size = 0;
|
||||||
FileInfo[] files = d.GetFiles();
|
FileInfo[] files = d.GetFiles("*.*", SearchOption.AllDirectories);
|
||||||
foreach (FileInfo file in files)
|
foreach (FileInfo file in files)
|
||||||
{
|
{
|
||||||
size += file.Length;
|
size += file.Length;
|
||||||
}
|
}
|
||||||
DirectoryInfo[] directories = d.GetDirectories();
|
|
||||||
foreach (DirectoryInfo directory in directories)
|
|
||||||
{
|
|
||||||
size += DirSize(directory);
|
|
||||||
}
|
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -13,8 +13,8 @@ namespace VRCX
|
|||||||
{
|
{
|
||||||
public static readonly CpuMonitor Instance;
|
public static readonly CpuMonitor Instance;
|
||||||
public float CpuUsage;
|
public float CpuUsage;
|
||||||
private PerformanceCounter _performanceCounter;
|
private readonly PerformanceCounter _performanceCounter;
|
||||||
private Timer _timer;
|
private readonly Timer _timer;
|
||||||
|
|
||||||
static CpuMonitor()
|
static CpuMonitor()
|
||||||
{
|
{
|
||||||
|
|||||||
+1
-1
@@ -16,7 +16,7 @@ namespace VRCX
|
|||||||
private readonly ReaderWriterLockSlim m_Lock;
|
private readonly ReaderWriterLockSlim m_Lock;
|
||||||
private readonly RichPresence m_Presence;
|
private readonly RichPresence m_Presence;
|
||||||
private DiscordRpcClient m_Client;
|
private DiscordRpcClient m_Client;
|
||||||
private Timer m_Timer;
|
private readonly Timer m_Timer;
|
||||||
private bool m_Active;
|
private bool m_Active;
|
||||||
public static string DiscordAppId;
|
public static string DiscordAppId;
|
||||||
|
|
||||||
|
|||||||
+8
-10
@@ -9,11 +9,12 @@ namespace VRCX
|
|||||||
{
|
{
|
||||||
private static readonly string cacheLocation = Path.Combine(Program.AppDataDirectory, "ImageCache");
|
private static readonly string cacheLocation = Path.Combine(Program.AppDataDirectory, "ImageCache");
|
||||||
|
|
||||||
|
private const string IMAGE_HOST1 = "api.vrchat.cloud";
|
||||||
|
private const string IMAGE_HOST2 = "files.vrchat.cloud";
|
||||||
|
private const string IMAGE_HOST3 = "d348imysud55la.cloudfront.net";
|
||||||
|
|
||||||
public static string GetImage(string url, string fileId, string version)
|
public static string GetImage(string url, string fileId, string version)
|
||||||
{
|
{
|
||||||
var imageHost = "api.vrchat.cloud";
|
|
||||||
var imageHost1 = "files.vrchat.cloud";
|
|
||||||
var imageHost2 = "d348imysud55la.cloudfront.net";
|
|
||||||
var directoryLocation = Path.Combine(cacheLocation, fileId);
|
var directoryLocation = Path.Combine(cacheLocation, fileId);
|
||||||
var fileLocation = Path.Combine(directoryLocation, $"{version}.png");
|
var fileLocation = Path.Combine(directoryLocation, $"{version}.png");
|
||||||
|
|
||||||
@@ -28,7 +29,7 @@ namespace VRCX
|
|||||||
Directory.CreateDirectory(directoryLocation);
|
Directory.CreateDirectory(directoryLocation);
|
||||||
|
|
||||||
Uri uri = new Uri(url);
|
Uri uri = new Uri(url);
|
||||||
if (uri.Host != imageHost && uri.Host != imageHost1 && uri.Host != imageHost2)
|
if (uri.Host != IMAGE_HOST1 && uri.Host != IMAGE_HOST2 && uri.Host != IMAGE_HOST3)
|
||||||
throw new ArgumentException("Invalid image host", url);
|
throw new ArgumentException("Invalid image host", url);
|
||||||
|
|
||||||
using (var client = new WebClient())
|
using (var client = new WebClient())
|
||||||
@@ -36,7 +37,7 @@ namespace VRCX
|
|||||||
string cookieString = string.Empty;
|
string cookieString = string.Empty;
|
||||||
if (WebApi.Instance != null && WebApi.Instance._cookieContainer != null)
|
if (WebApi.Instance != null && WebApi.Instance._cookieContainer != null)
|
||||||
{
|
{
|
||||||
CookieCollection cookies = WebApi.Instance._cookieContainer.GetCookies(new Uri($"https://{imageHost}"));
|
CookieCollection cookies = WebApi.Instance._cookieContainer.GetCookies(new Uri($"https://{IMAGE_HOST1}"));
|
||||||
foreach (Cookie cookie in cookies)
|
foreach (Cookie cookie in cookies)
|
||||||
cookieString += $"{cookie.Name}={cookie.Value};";
|
cookieString += $"{cookie.Name}={cookie.Value};";
|
||||||
}
|
}
|
||||||
@@ -56,12 +57,9 @@ namespace VRCX
|
|||||||
private static void CleanImageCache()
|
private static void CleanImageCache()
|
||||||
{
|
{
|
||||||
DirectoryInfo dirInfo = new DirectoryInfo(cacheLocation);
|
DirectoryInfo dirInfo = new DirectoryInfo(cacheLocation);
|
||||||
var folders = dirInfo.GetDirectories().OrderBy(p => p.LastWriteTime);
|
var folders = dirInfo.GetDirectories().OrderByDescending(p => p.LastWriteTime).Skip(1000);
|
||||||
int i = 0;
|
foreach (DirectoryInfo folder in folders)
|
||||||
foreach (DirectoryInfo folder in folders.Reverse())
|
|
||||||
{
|
{
|
||||||
i++;
|
|
||||||
if (i > 1000)
|
|
||||||
folder.Delete(true);
|
folder.Delete(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -17,7 +17,7 @@ namespace VRCX
|
|||||||
{
|
{
|
||||||
public class OffScreenBrowser : ChromiumWebBrowser, IRenderHandler
|
public class OffScreenBrowser : ChromiumWebBrowser, IRenderHandler
|
||||||
{
|
{
|
||||||
private ReaderWriterLockSlim _paintBufferLock;
|
private readonly ReaderWriterLockSlim _paintBufferLock;
|
||||||
private GCHandle _paintBuffer;
|
private GCHandle _paintBuffer;
|
||||||
private int _width;
|
private int _width;
|
||||||
private int _height;
|
private int _height;
|
||||||
|
|||||||
+1
-1
@@ -21,7 +21,7 @@ namespace VRCX
|
|||||||
public static string Version { get; private set; }
|
public static string Version { get; private set; }
|
||||||
public static bool LaunchDebug;
|
public static bool LaunchDebug;
|
||||||
public static bool GPUFix;
|
public static bool GPUFix;
|
||||||
private static NLog.Logger logger = NLog.LogManager.GetLogger("VRCX");
|
private static readonly NLog.Logger logger = NLog.LogManager.GetLogger("VRCX");
|
||||||
static Program()
|
static Program()
|
||||||
{
|
{
|
||||||
BaseDirectory = AppDomain.CurrentDomain.BaseDirectory;
|
BaseDirectory = AppDomain.CurrentDomain.BaseDirectory;
|
||||||
|
|||||||
@@ -407,7 +407,7 @@ namespace SQLite
|
|||||||
|
|
||||||
Handle = handle;
|
Handle = handle;
|
||||||
if (r != SQLite3.Result.OK) {
|
if (r != SQLite3.Result.OK) {
|
||||||
throw SQLiteException.New (r, String.Format ("Could not open database file: {0} ({1})", DatabasePath, r));
|
throw SQLiteException.New (r, string.Format ("Could not open database file: {0} ({1})", DatabasePath, r));
|
||||||
}
|
}
|
||||||
_open = true;
|
_open = true;
|
||||||
|
|
||||||
@@ -505,7 +505,6 @@ namespace SQLite
|
|||||||
{
|
{
|
||||||
var utf8Length = System.Text.Encoding.UTF8.GetByteCount (s);
|
var utf8Length = System.Text.Encoding.UTF8.GetByteCount (s);
|
||||||
var bytes = new byte [utf8Length + 1];
|
var bytes = new byte [utf8Length + 1];
|
||||||
utf8Length = System.Text.Encoding.UTF8.GetBytes(s, 0, s.Length, bytes, 0);
|
|
||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -816,7 +815,7 @@ namespace SQLite
|
|||||||
public int CreateIndex (string indexName, string tableName, string[] columnNames, bool unique = false)
|
public int CreateIndex (string indexName, string tableName, string[] columnNames, bool unique = false)
|
||||||
{
|
{
|
||||||
const string sqlFormat = "create {2} index if not exists \"{3}\" on \"{0}\"(\"{1}\")";
|
const string sqlFormat = "create {2} index if not exists \"{3}\" on \"{0}\"(\"{1}\")";
|
||||||
var sql = String.Format (sqlFormat, tableName, string.Join ("\", \"", columnNames), unique ? "unique" : string.Empty, indexName);
|
var sql = string.Format (sqlFormat, tableName, string.Join ("\", \"", columnNames), unique ? "unique" : string.Empty, indexName);
|
||||||
return Execute (sql);
|
return Execute (sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1489,7 +1488,7 @@ namespace SQLite
|
|||||||
// Rolling back without a TO clause rolls backs all transactions
|
// Rolling back without a TO clause rolls backs all transactions
|
||||||
// and leaves the transaction stack empty.
|
// and leaves the transaction stack empty.
|
||||||
try {
|
try {
|
||||||
if (String.IsNullOrEmpty (savepoint)) {
|
if (string.IsNullOrEmpty (savepoint)) {
|
||||||
if (Interlocked.Exchange (ref _transactionDepth, 0) > 0) {
|
if (Interlocked.Exchange (ref _transactionDepth, 0) > 0) {
|
||||||
Execute ("rollback");
|
Execute ("rollback");
|
||||||
}
|
}
|
||||||
@@ -1541,18 +1540,19 @@ namespace SQLite
|
|||||||
// Validate the savepoint
|
// Validate the savepoint
|
||||||
int firstLen = savepoint.IndexOf ('D');
|
int firstLen = savepoint.IndexOf ('D');
|
||||||
if (firstLen >= 2 && savepoint.Length > firstLen + 1) {
|
if (firstLen >= 2 && savepoint.Length > firstLen + 1) {
|
||||||
int depth;
|
if (int.TryParse(savepoint.Substring(firstLen + 1), out int depth))
|
||||||
if (Int32.TryParse (savepoint.Substring (firstLen + 1), out depth)) {
|
{
|
||||||
// TODO: Mild race here, but inescapable without locking almost everywhere.
|
// TODO: Mild race here, but inescapable without locking almost everywhere.
|
||||||
if (0 <= depth && depth < _transactionDepth) {
|
if (0 <= depth && depth < _transactionDepth)
|
||||||
|
{
|
||||||
#if NETFX_CORE || USE_SQLITEPCL_RAW || NETCORE
|
#if NETFX_CORE || USE_SQLITEPCL_RAW || NETCORE
|
||||||
Volatile.Write (ref _transactionDepth, depth);
|
Volatile.Write (ref _transactionDepth, depth);
|
||||||
#elif SILVERLIGHT
|
#elif SILVERLIGHT
|
||||||
_transactionDepth = depth;
|
_transactionDepth = depth;
|
||||||
#else
|
#else
|
||||||
Thread.VolatileWrite (ref _transactionDepth, depth);
|
Thread.VolatileWrite(ref _transactionDepth, depth);
|
||||||
#endif
|
#endif
|
||||||
Execute (cmd + savepoint);
|
Execute(cmd + savepoint);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2231,9 +2231,7 @@ namespace SQLite
|
|||||||
|
|
||||||
void OnTableChanged (TableMapping table, NotifyTableChangedAction action)
|
void OnTableChanged (TableMapping table, NotifyTableChangedAction action)
|
||||||
{
|
{
|
||||||
var ev = TableChanged;
|
TableChanged?.Invoke(this, new NotifyTableChangedEventArgs(table, action));
|
||||||
if (ev != null)
|
|
||||||
ev (this, new NotifyTableChangedEventArgs (table, action));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public event EventHandler<NotifyTableChangedEventArgs> TableChanged;
|
public event EventHandler<NotifyTableChangedEventArgs> TableChanged;
|
||||||
@@ -2644,9 +2642,7 @@ namespace SQLite
|
|||||||
|
|
||||||
public void SetAutoIncPK (object obj, long id)
|
public void SetAutoIncPK (object obj, long id)
|
||||||
{
|
{
|
||||||
if (_autoPk != null) {
|
_autoPk?.SetValue (obj, Convert.ChangeType (id, _autoPk.ColumnType, null));
|
||||||
_autoPk.SetValue (obj, Convert.ChangeType (id, _autoPk.ColumnType, null));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Column[] InsertColumns {
|
public Column[] InsertColumns {
|
||||||
@@ -2678,7 +2674,7 @@ namespace SQLite
|
|||||||
|
|
||||||
public class Column
|
public class Column
|
||||||
{
|
{
|
||||||
MemberInfo _member;
|
private readonly MemberInfo _member;
|
||||||
|
|
||||||
public string Name { get; private set; }
|
public string Name { get; private set; }
|
||||||
|
|
||||||
@@ -2834,9 +2830,9 @@ namespace SQLite
|
|||||||
public static EnumCacheInfo GetInfo (Type type)
|
public static EnumCacheInfo GetInfo (Type type)
|
||||||
{
|
{
|
||||||
lock (Cache) {
|
lock (Cache) {
|
||||||
EnumCacheInfo info = null;
|
if (!Cache.TryGetValue(type, out EnumCacheInfo info))
|
||||||
if (!Cache.TryGetValue (type, out info)) {
|
{
|
||||||
info = new EnumCacheInfo (type);
|
info = new EnumCacheInfo(type);
|
||||||
Cache[type] = info;
|
Cache[type] = info;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2855,9 +2851,8 @@ namespace SQLite
|
|||||||
{
|
{
|
||||||
if (obj == null)
|
if (obj == null)
|
||||||
return typeof (object);
|
return typeof (object);
|
||||||
var rt = obj as IReflectableType;
|
if (obj is IReflectableType rt)
|
||||||
if (rt != null)
|
return rt.GetTypeInfo().AsType();
|
||||||
return rt.GetTypeInfo ().AsType ();
|
|
||||||
return obj.GetType ();
|
return obj.GetType ();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2884,13 +2879,13 @@ namespace SQLite
|
|||||||
public static string SqlType (TableMapping.Column p, bool storeDateTimeAsTicks, bool storeTimeSpanAsTicks)
|
public static string SqlType (TableMapping.Column p, bool storeDateTimeAsTicks, bool storeTimeSpanAsTicks)
|
||||||
{
|
{
|
||||||
var clrType = p.ColumnType;
|
var clrType = p.ColumnType;
|
||||||
if (clrType == typeof (Boolean) || clrType == typeof (Byte) || clrType == typeof (UInt16) || clrType == typeof (SByte) || clrType == typeof (Int16) || clrType == typeof (Int32) || clrType == typeof (UInt32) || clrType == typeof (Int64)) {
|
if (clrType == typeof (bool) || clrType == typeof (byte) || clrType == typeof (ushort) || clrType == typeof (sbyte) || clrType == typeof (short) || clrType == typeof (int) || clrType == typeof (uint) || clrType == typeof (long)) {
|
||||||
return "integer";
|
return "integer";
|
||||||
}
|
}
|
||||||
else if (clrType == typeof (Single) || clrType == typeof (Double) || clrType == typeof (Decimal)) {
|
else if (clrType == typeof (float) || clrType == typeof (double) || clrType == typeof (decimal)) {
|
||||||
return "float";
|
return "float";
|
||||||
}
|
}
|
||||||
else if (clrType == typeof (String) || clrType == typeof (StringBuilder) || clrType == typeof (Uri) || clrType == typeof (UriBuilder)) {
|
else if (clrType == typeof (string) || clrType == typeof (StringBuilder) || clrType == typeof (Uri) || clrType == typeof (UriBuilder)) {
|
||||||
int? len = p.MaxStringLength;
|
int? len = p.MaxStringLength;
|
||||||
|
|
||||||
if (len.HasValue)
|
if (len.HasValue)
|
||||||
@@ -3024,8 +3019,8 @@ namespace SQLite
|
|||||||
|
|
||||||
public partial class SQLiteCommand
|
public partial class SQLiteCommand
|
||||||
{
|
{
|
||||||
SQLiteConnection _conn;
|
private readonly SQLiteConnection _conn;
|
||||||
private List<Binding> _bindings;
|
private readonly List<Binding> _bindings;
|
||||||
|
|
||||||
public string CommandText { get; set; }
|
public string CommandText { get; set; }
|
||||||
|
|
||||||
@@ -3042,9 +3037,8 @@ namespace SQLite
|
|||||||
_conn.Tracer?.Invoke ("Executing: " + this);
|
_conn.Tracer?.Invoke ("Executing: " + this);
|
||||||
}
|
}
|
||||||
|
|
||||||
var r = SQLite3.Result.OK;
|
|
||||||
var stmt = Prepare ();
|
var stmt = Prepare ();
|
||||||
r = SQLite3.Step (stmt);
|
var r = SQLite3.Step(stmt);
|
||||||
Finalize (stmt);
|
Finalize (stmt);
|
||||||
if (r == SQLite3.Result.Done) {
|
if (r == SQLite3.Result.Done) {
|
||||||
int rowsAffected = SQLite3.Changes (_conn.Handle);
|
int rowsAffected = SQLite3.Changes (_conn.Handle);
|
||||||
@@ -3159,7 +3153,7 @@ namespace SQLite
|
|||||||
_conn.Tracer?.Invoke ("Executing Query: " + this);
|
_conn.Tracer?.Invoke ("Executing Query: " + this);
|
||||||
}
|
}
|
||||||
|
|
||||||
T val = default (T);
|
T val = default;
|
||||||
|
|
||||||
var stmt = Prepare ();
|
var stmt = Prepare ();
|
||||||
|
|
||||||
@@ -3199,7 +3193,7 @@ namespace SQLite
|
|||||||
var colType = SQLite3.ColumnType (stmt, 0);
|
var colType = SQLite3.ColumnType (stmt, 0);
|
||||||
var val = ReadCol (stmt, 0, colType, typeof (T));
|
var val = ReadCol (stmt, 0, colType, typeof (T));
|
||||||
if (val == null) {
|
if (val == null) {
|
||||||
yield return default (T);
|
yield return default;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
yield return (T)val;
|
yield return (T)val;
|
||||||
@@ -3271,57 +3265,57 @@ namespace SQLite
|
|||||||
SQLite3.BindNull (stmt, index);
|
SQLite3.BindNull (stmt, index);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (value is Int32) {
|
if (value is int) {
|
||||||
SQLite3.BindInt (stmt, index, (int)value);
|
SQLite3.BindInt (stmt, index, (int)value);
|
||||||
}
|
}
|
||||||
else if (value is String) {
|
else if (value is string) {
|
||||||
SQLite3.BindText (stmt, index, (string)value, -1, NegativePointer);
|
SQLite3.BindText (stmt, index, (string)value, -1, NegativePointer);
|
||||||
}
|
}
|
||||||
else if (value is Byte || value is UInt16 || value is SByte || value is Int16) {
|
else if (value is byte || value is ushort || value is sbyte || value is short) {
|
||||||
SQLite3.BindInt (stmt, index, Convert.ToInt32 (value));
|
SQLite3.BindInt (stmt, index, Convert.ToInt32 (value));
|
||||||
}
|
}
|
||||||
else if (value is Boolean) {
|
else if (value is bool) {
|
||||||
SQLite3.BindInt (stmt, index, (bool)value ? 1 : 0);
|
SQLite3.BindInt (stmt, index, (bool)value ? 1 : 0);
|
||||||
}
|
}
|
||||||
else if (value is UInt32 || value is Int64) {
|
else if (value is uint || value is long) {
|
||||||
SQLite3.BindInt64 (stmt, index, Convert.ToInt64 (value));
|
SQLite3.BindInt64 (stmt, index, Convert.ToInt64 (value));
|
||||||
}
|
}
|
||||||
else if (value is Single || value is Double || value is Decimal) {
|
else if (value is float || value is double || value is decimal) {
|
||||||
SQLite3.BindDouble (stmt, index, Convert.ToDouble (value));
|
SQLite3.BindDouble (stmt, index, Convert.ToDouble (value));
|
||||||
}
|
}
|
||||||
else if (value is TimeSpan) {
|
else if (value is TimeSpan span) {
|
||||||
if (storeTimeSpanAsTicks) {
|
if (storeTimeSpanAsTicks) {
|
||||||
SQLite3.BindInt64 (stmt, index, ((TimeSpan)value).Ticks);
|
SQLite3.BindInt64 (stmt, index, span.Ticks);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
SQLite3.BindText (stmt, index, ((TimeSpan)value).ToString (), -1, NegativePointer);
|
SQLite3.BindText (stmt, index, span.ToString (), -1, NegativePointer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (value is DateTime) {
|
else if (value is DateTime time) {
|
||||||
if (storeDateTimeAsTicks) {
|
if (storeDateTimeAsTicks) {
|
||||||
SQLite3.BindInt64 (stmt, index, ((DateTime)value).Ticks);
|
SQLite3.BindInt64 (stmt, index, time.Ticks);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
SQLite3.BindText (stmt, index, ((DateTime)value).ToString (dateTimeStringFormat, System.Globalization.CultureInfo.InvariantCulture), -1, NegativePointer);
|
SQLite3.BindText (stmt, index, time.ToString (dateTimeStringFormat, System.Globalization.CultureInfo.InvariantCulture), -1, NegativePointer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (value is DateTimeOffset) {
|
else if (value is DateTimeOffset offset) {
|
||||||
SQLite3.BindInt64 (stmt, index, ((DateTimeOffset)value).UtcTicks);
|
SQLite3.BindInt64 (stmt, index, offset.UtcTicks);
|
||||||
}
|
}
|
||||||
else if (value is byte[]) {
|
else if (value is byte[] v) {
|
||||||
SQLite3.BindBlob (stmt, index, (byte[])value, ((byte[])value).Length, NegativePointer);
|
SQLite3.BindBlob (stmt, index, v, v.Length, NegativePointer);
|
||||||
}
|
}
|
||||||
else if (value is Guid) {
|
else if (value is Guid guid) {
|
||||||
SQLite3.BindText (stmt, index, ((Guid)value).ToString (), 72, NegativePointer);
|
SQLite3.BindText (stmt, index, guid.ToString (), 72, NegativePointer);
|
||||||
}
|
}
|
||||||
else if (value is Uri) {
|
else if (value is Uri uri) {
|
||||||
SQLite3.BindText (stmt, index, ((Uri)value).ToString (), -1, NegativePointer);
|
SQLite3.BindText (stmt, index, uri.ToString (), -1, NegativePointer);
|
||||||
}
|
}
|
||||||
else if (value is StringBuilder) {
|
else if (value is StringBuilder builder) {
|
||||||
SQLite3.BindText (stmt, index, ((StringBuilder)value).ToString (), -1, NegativePointer);
|
SQLite3.BindText (stmt, index, builder.ToString (), -1, NegativePointer);
|
||||||
}
|
}
|
||||||
else if (value is UriBuilder) {
|
else if (value is UriBuilder builder1) {
|
||||||
SQLite3.BindText (stmt, index, ((UriBuilder)value).ToString (), -1, NegativePointer);
|
SQLite3.BindText (stmt, index, builder1.ToString (), -1, NegativePointer);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Now we could possibly get an enum, retrieve cached info
|
// Now we could possibly get an enum, retrieve cached info
|
||||||
@@ -3362,13 +3356,13 @@ namespace SQLite
|
|||||||
clrTypeInfo = clrType.GetTypeInfo ();
|
clrTypeInfo = clrType.GetTypeInfo ();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (clrType == typeof (String)) {
|
if (clrType == typeof (string)) {
|
||||||
return SQLite3.ColumnString (stmt, index);
|
return SQLite3.ColumnString (stmt, index);
|
||||||
}
|
}
|
||||||
else if (clrType == typeof (Int32)) {
|
else if (clrType == typeof (int)) {
|
||||||
return (int)SQLite3.ColumnInt (stmt, index);
|
return SQLite3.ColumnInt(stmt, index);
|
||||||
}
|
}
|
||||||
else if (clrType == typeof (Boolean)) {
|
else if (clrType == typeof (bool)) {
|
||||||
return SQLite3.ColumnInt (stmt, index) == 1;
|
return SQLite3.ColumnInt (stmt, index) == 1;
|
||||||
}
|
}
|
||||||
else if (clrType == typeof (double)) {
|
else if (clrType == typeof (double)) {
|
||||||
@@ -3414,22 +3408,22 @@ namespace SQLite
|
|||||||
else
|
else
|
||||||
return SQLite3.ColumnInt (stmt, index);
|
return SQLite3.ColumnInt (stmt, index);
|
||||||
}
|
}
|
||||||
else if (clrType == typeof (Int64)) {
|
else if (clrType == typeof (long)) {
|
||||||
return SQLite3.ColumnInt64 (stmt, index);
|
return SQLite3.ColumnInt64 (stmt, index);
|
||||||
}
|
}
|
||||||
else if (clrType == typeof (UInt32)) {
|
else if (clrType == typeof (uint)) {
|
||||||
return (uint)SQLite3.ColumnInt64 (stmt, index);
|
return (uint)SQLite3.ColumnInt64 (stmt, index);
|
||||||
}
|
}
|
||||||
else if (clrType == typeof (decimal)) {
|
else if (clrType == typeof (decimal)) {
|
||||||
return (decimal)SQLite3.ColumnDouble (stmt, index);
|
return (decimal)SQLite3.ColumnDouble (stmt, index);
|
||||||
}
|
}
|
||||||
else if (clrType == typeof (Byte)) {
|
else if (clrType == typeof (byte)) {
|
||||||
return (byte)SQLite3.ColumnInt (stmt, index);
|
return (byte)SQLite3.ColumnInt (stmt, index);
|
||||||
}
|
}
|
||||||
else if (clrType == typeof (UInt16)) {
|
else if (clrType == typeof (ushort)) {
|
||||||
return (ushort)SQLite3.ColumnInt (stmt, index);
|
return (ushort)SQLite3.ColumnInt (stmt, index);
|
||||||
}
|
}
|
||||||
else if (clrType == typeof (Int16)) {
|
else if (clrType == typeof (short)) {
|
||||||
return (short)SQLite3.ColumnInt (stmt, index);
|
return (short)SQLite3.ColumnInt (stmt, index);
|
||||||
}
|
}
|
||||||
else if (clrType == typeof (sbyte)) {
|
else if (clrType == typeof (sbyte)) {
|
||||||
@@ -3489,17 +3483,17 @@ namespace SQLite
|
|||||||
clrTypeInfo = clrType.GetTypeInfo ();
|
clrTypeInfo = clrType.GetTypeInfo ();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (clrType == typeof (String)) {
|
if (clrType == typeof (string)) {
|
||||||
fastSetter = CreateTypedSetterDelegate<T, string> (column, (stmt, index) => {
|
fastSetter = CreateTypedSetterDelegate<T, string> (column, (stmt, index) => {
|
||||||
return SQLite3.ColumnString (stmt, index);
|
return SQLite3.ColumnString (stmt, index);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else if (clrType == typeof (Int32)) {
|
else if (clrType == typeof (int)) {
|
||||||
fastSetter = CreateNullableTypedSetterDelegate<T, int> (column, (stmt, index)=>{
|
fastSetter = CreateNullableTypedSetterDelegate<T, int> (column, (stmt, index)=>{
|
||||||
return SQLite3.ColumnInt (stmt, index);
|
return SQLite3.ColumnInt (stmt, index);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else if (clrType == typeof (Boolean)) {
|
else if (clrType == typeof (bool)) {
|
||||||
fastSetter = CreateNullableTypedSetterDelegate<T, bool> (column, (stmt, index) => {
|
fastSetter = CreateNullableTypedSetterDelegate<T, bool> (column, (stmt, index) => {
|
||||||
return SQLite3.ColumnInt (stmt, index) == 1;
|
return SQLite3.ColumnInt (stmt, index) == 1;
|
||||||
});
|
});
|
||||||
@@ -3523,9 +3517,9 @@ namespace SQLite
|
|||||||
else {
|
else {
|
||||||
fastSetter = CreateNullableTypedSetterDelegate<T, TimeSpan> (column, (stmt, index) => {
|
fastSetter = CreateNullableTypedSetterDelegate<T, TimeSpan> (column, (stmt, index) => {
|
||||||
var text = SQLite3.ColumnString (stmt, index);
|
var text = SQLite3.ColumnString (stmt, index);
|
||||||
TimeSpan resultTime;
|
if (!TimeSpan.TryParseExact(text, "c", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.TimeSpanStyles.None, out TimeSpan resultTime))
|
||||||
if (!TimeSpan.TryParseExact (text, "c", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.TimeSpanStyles.None, out resultTime)) {
|
{
|
||||||
resultTime = TimeSpan.Parse (text);
|
resultTime = TimeSpan.Parse(text);
|
||||||
}
|
}
|
||||||
return resultTime;
|
return resultTime;
|
||||||
});
|
});
|
||||||
@@ -3540,9 +3534,9 @@ namespace SQLite
|
|||||||
else {
|
else {
|
||||||
fastSetter = CreateNullableTypedSetterDelegate<T, DateTime> (column, (stmt, index) => {
|
fastSetter = CreateNullableTypedSetterDelegate<T, DateTime> (column, (stmt, index) => {
|
||||||
var text = SQLite3.ColumnString (stmt, index);
|
var text = SQLite3.ColumnString (stmt, index);
|
||||||
DateTime resultDate;
|
if (!DateTime.TryParseExact(text, conn.DateTimeStringFormat, System.Globalization.CultureInfo.InvariantCulture, conn.DateTimeStyle, out DateTime resultDate))
|
||||||
if (!DateTime.TryParseExact (text, conn.DateTimeStringFormat, System.Globalization.CultureInfo.InvariantCulture, conn.DateTimeStyle, out resultDate)) {
|
{
|
||||||
resultDate = DateTime.Parse (text);
|
resultDate = DateTime.Parse(text);
|
||||||
}
|
}
|
||||||
return resultDate;
|
return resultDate;
|
||||||
});
|
});
|
||||||
@@ -3556,13 +3550,13 @@ namespace SQLite
|
|||||||
else if (clrTypeInfo.IsEnum) {
|
else if (clrTypeInfo.IsEnum) {
|
||||||
// NOTE: Not sure of a good way (if any?) to do a strongly-typed fast setter like this for enumerated types -- for now, return null and column sets will revert back to the safe (but slow) Reflection-based method of column prop.Set()
|
// NOTE: Not sure of a good way (if any?) to do a strongly-typed fast setter like this for enumerated types -- for now, return null and column sets will revert back to the safe (but slow) Reflection-based method of column prop.Set()
|
||||||
}
|
}
|
||||||
else if (clrType == typeof (Int64)) {
|
else if (clrType == typeof (long)) {
|
||||||
fastSetter = CreateNullableTypedSetterDelegate<T, Int64> (column, (stmt, index) => {
|
fastSetter = CreateNullableTypedSetterDelegate<T, long> (column, (stmt, index) => {
|
||||||
return SQLite3.ColumnInt64 (stmt, index);
|
return SQLite3.ColumnInt64 (stmt, index);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else if (clrType == typeof (UInt32)) {
|
else if (clrType == typeof (uint)) {
|
||||||
fastSetter = CreateNullableTypedSetterDelegate<T, UInt32> (column, (stmt, index) => {
|
fastSetter = CreateNullableTypedSetterDelegate<T, uint> (column, (stmt, index) => {
|
||||||
return (uint)SQLite3.ColumnInt64 (stmt, index);
|
return (uint)SQLite3.ColumnInt64 (stmt, index);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -3571,18 +3565,18 @@ namespace SQLite
|
|||||||
return (decimal)SQLite3.ColumnDouble (stmt, index);
|
return (decimal)SQLite3.ColumnDouble (stmt, index);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else if (clrType == typeof (Byte)) {
|
else if (clrType == typeof (byte)) {
|
||||||
fastSetter = CreateNullableTypedSetterDelegate<T, Byte> (column, (stmt, index) => {
|
fastSetter = CreateNullableTypedSetterDelegate<T, byte> (column, (stmt, index) => {
|
||||||
return (byte)SQLite3.ColumnInt (stmt, index);
|
return (byte)SQLite3.ColumnInt (stmt, index);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else if (clrType == typeof (UInt16)) {
|
else if (clrType == typeof (ushort)) {
|
||||||
fastSetter = CreateNullableTypedSetterDelegate<T, UInt16> (column, (stmt, index) => {
|
fastSetter = CreateNullableTypedSetterDelegate<T, ushort> (column, (stmt, index) => {
|
||||||
return (ushort)SQLite3.ColumnInt (stmt, index);
|
return (ushort)SQLite3.ColumnInt (stmt, index);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else if (clrType == typeof (Int16)) {
|
else if (clrType == typeof (short)) {
|
||||||
fastSetter = CreateNullableTypedSetterDelegate<T, Int16> (column, (stmt, index) => {
|
fastSetter = CreateNullableTypedSetterDelegate<T, short> (column, (stmt, index) => {
|
||||||
return (short)SQLite3.ColumnInt (stmt, index);
|
return (short)SQLite3.ColumnInt (stmt, index);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -3804,13 +3798,11 @@ namespace SQLite
|
|||||||
List<Ordering> _orderBys;
|
List<Ordering> _orderBys;
|
||||||
int? _limit;
|
int? _limit;
|
||||||
int? _offset;
|
int? _offset;
|
||||||
|
|
||||||
BaseTableQuery _joinInner;
|
BaseTableQuery _joinInner;
|
||||||
Expression _joinInnerKeySelector;
|
Expression _joinInnerKeySelector;
|
||||||
BaseTableQuery _joinOuter;
|
BaseTableQuery _joinOuter;
|
||||||
Expression _joinOuterKeySelector;
|
Expression _joinOuterKeySelector;
|
||||||
Expression _joinSelector;
|
Expression _joinSelector;
|
||||||
|
|
||||||
Expression _selector;
|
Expression _selector;
|
||||||
|
|
||||||
TableQuery (SQLiteConnection conn, TableMapping table)
|
TableQuery (SQLiteConnection conn, TableMapping table)
|
||||||
@@ -3939,7 +3931,7 @@ namespace SQLite
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public TableQuery<T> OrderBy<U> (Expression<Func<T, U>> orderExpr)
|
public TableQuery<T> OrderBy<U> (Expression<Func<T, U>> orderExpr)
|
||||||
{
|
{
|
||||||
return AddOrderBy<U> (orderExpr, true);
|
return AddOrderBy(orderExpr, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -3947,7 +3939,7 @@ namespace SQLite
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public TableQuery<T> OrderByDescending<U> (Expression<Func<T, U>> orderExpr)
|
public TableQuery<T> OrderByDescending<U> (Expression<Func<T, U>> orderExpr)
|
||||||
{
|
{
|
||||||
return AddOrderBy<U> (orderExpr, false);
|
return AddOrderBy(orderExpr, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -3955,7 +3947,7 @@ namespace SQLite
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public TableQuery<T> ThenBy<U> (Expression<Func<T, U>> orderExpr)
|
public TableQuery<T> ThenBy<U> (Expression<Func<T, U>> orderExpr)
|
||||||
{
|
{
|
||||||
return AddOrderBy<U> (orderExpr, true);
|
return AddOrderBy(orderExpr, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -3963,7 +3955,7 @@ namespace SQLite
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public TableQuery<T> ThenByDescending<U> (Expression<Func<T, U>> orderExpr)
|
public TableQuery<T> ThenByDescending<U> (Expression<Func<T, U>> orderExpr)
|
||||||
{
|
{
|
||||||
return AddOrderBy<U> (orderExpr, false);
|
return AddOrderBy(orderExpr, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
TableQuery<T> AddOrderBy<U> (Expression<Func<T, U>> orderExpr, bool asc)
|
TableQuery<T> AddOrderBy<U> (Expression<Func<T, U>> orderExpr, bool asc)
|
||||||
@@ -3971,7 +3963,7 @@ namespace SQLite
|
|||||||
if (orderExpr.NodeType == ExpressionType.Lambda) {
|
if (orderExpr.NodeType == ExpressionType.Lambda) {
|
||||||
var lambda = (LambdaExpression)orderExpr;
|
var lambda = (LambdaExpression)orderExpr;
|
||||||
|
|
||||||
MemberExpression mem = null;
|
MemberExpression mem;
|
||||||
|
|
||||||
var unary = lambda.Body as UnaryExpression;
|
var unary = lambda.Body as UnaryExpression;
|
||||||
if (unary != null && unary.NodeType == ExpressionType.Convert) {
|
if (unary != null && unary.NodeType == ExpressionType.Convert) {
|
||||||
@@ -4255,22 +4247,23 @@ namespace SQLite
|
|||||||
var m = (PropertyInfo)mem.Member;
|
var m = (PropertyInfo)mem.Member;
|
||||||
val = m.GetValue (obj, null);
|
val = m.GetValue (obj, null);
|
||||||
}
|
}
|
||||||
else if (mem.Member is FieldInfo) {
|
else if (mem.Member is FieldInfo m)
|
||||||
var m = (FieldInfo)mem.Member;
|
{
|
||||||
val = m.GetValue (obj);
|
val = m.GetValue(obj);
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
throw new NotSupportedException ("MemberExpr: " + mem.Member.GetType ());
|
{
|
||||||
|
throw new NotSupportedException("MemberExpr: " + mem.Member.GetType());
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Work special magic for enumerables
|
// Work special magic for enumerables
|
||||||
//
|
//
|
||||||
if (val != null && val is System.Collections.IEnumerable && !(val is string) && !(val is System.Collections.Generic.IEnumerable<byte>)) {
|
if (val != null && val is IEnumerable enumerable && !(val is string) && !(val is IEnumerable<byte>)) {
|
||||||
var sb = new System.Text.StringBuilder ();
|
var sb = new StringBuilder ();
|
||||||
sb.Append ("(");
|
sb.Append ("(");
|
||||||
var head = string.Empty;
|
var head = string.Empty;
|
||||||
foreach (var a in (System.Collections.IEnumerable)val) {
|
foreach (var a in enumerable) {
|
||||||
queryArgs.Add (a);
|
queryArgs.Add (a);
|
||||||
sb.Append (head);
|
sb.Append (head);
|
||||||
sb.Append ("?");
|
sb.Append ("?");
|
||||||
|
|||||||
+1
-1
@@ -16,7 +16,7 @@ namespace VRCX
|
|||||||
public static readonly VRCXStorage Instance;
|
public static readonly VRCXStorage Instance;
|
||||||
private static readonly ReaderWriterLockSlim m_Lock = new ReaderWriterLockSlim();
|
private static readonly ReaderWriterLockSlim m_Lock = new ReaderWriterLockSlim();
|
||||||
private static Dictionary<string, string> m_Storage = new Dictionary<string, string>();
|
private static Dictionary<string, string> m_Storage = new Dictionary<string, string>();
|
||||||
private static string m_JsonPath = Path.Combine(Program.AppDataDirectory, "VRCX.json");
|
private static readonly string m_JsonPath = Path.Combine(Program.AppDataDirectory, "VRCX.json");
|
||||||
private static bool m_Dirty;
|
private static bool m_Dirty;
|
||||||
|
|
||||||
static VRCXStorage()
|
static VRCXStorage()
|
||||||
|
|||||||
Reference in New Issue
Block a user