Move config to AppData

This commit is contained in:
Natsumi
2021-08-03 01:45:44 +12:00
parent d0c520e678
commit a66ff77fce
5 changed files with 28 additions and 8 deletions

View File

@@ -231,7 +231,7 @@ namespace VRCX
public void CacheImage(string Base64File) public void CacheImage(string Base64File)
{ {
String Icon = Path.Combine(Program.BaseDirectory, "cache\\toast"); String Icon = Path.Combine(Program.AppDataDirectory, "cache\\toast");
File.WriteAllBytes(Icon, Convert.FromBase64String(Base64File)); File.WriteAllBytes(Icon, Convert.FromBase64String(Base64File));
} }
@@ -242,7 +242,7 @@ namespace VRCX
String imagePath = Path.Combine(Program.BaseDirectory, "VRCX.ico"); String imagePath = Path.Combine(Program.BaseDirectory, "VRCX.ico");
if (Image) if (Image)
{ {
imagePath = Path.Combine(Program.BaseDirectory, "cache\\toast"); imagePath = Path.Combine(Program.AppDataDirectory, "cache\\toast");
} }
stringElements[0].AppendChild(toastXml.CreateTextNode(BoldText)); stringElements[0].AppendChild(toastXml.CreateTextNode(BoldText));
stringElements[1].AppendChild(toastXml.CreateTextNode(Text)); stringElements[1].AppendChild(toastXml.CreateTextNode(Text));
@@ -275,7 +275,7 @@ namespace VRCX
if (Image) if (Image)
{ {
UseBase64Icon = false; UseBase64Icon = false;
Icon = Path.Combine(Program.BaseDirectory, "cache\\toast"); Icon = Path.Combine(Program.AppDataDirectory, "cache\\toast");
} }
IPAddress broadcastIP = IPAddress.Parse("127.0.0.1"); IPAddress broadcastIP = IPAddress.Parse("127.0.0.1");

View File

@@ -18,8 +18,8 @@ namespace VRCX
{ {
var cefSettings = new CefSettings var cefSettings = new CefSettings
{ {
CachePath = Path.Combine(Program.BaseDirectory, "cache"), CachePath = Path.Combine(Program.AppDataDirectory, "cache"),
UserDataPath = Path.Combine(Program.BaseDirectory, "userdata"), UserDataPath = Path.Combine(Program.AppDataDirectory, "userdata"),
IgnoreCertificateErrors = true, IgnoreCertificateErrors = true,
LogSeverity = LogSeverity.Disable, LogSeverity = LogSeverity.Disable,
WindowlessRenderingEnabled = true, WindowlessRenderingEnabled = true,

View File

@@ -4,6 +4,7 @@
// For a copy, see <https://opensource.org/licenses/MIT>. // For a copy, see <https://opensource.org/licenses/MIT>.
using System; using System;
using System.IO;
using System.Windows.Forms; using System.Windows.Forms;
namespace VRCX namespace VRCX
@@ -11,10 +12,29 @@ namespace VRCX
public class Program public class Program
{ {
public static string BaseDirectory { get; private set; } public static string BaseDirectory { get; private set; }
public static string AppDataDirectory { get; private set; }
static Program() static Program()
{ {
BaseDirectory = AppDomain.CurrentDomain.BaseDirectory; BaseDirectory = AppDomain.CurrentDomain.BaseDirectory;
AppDataDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "VRCX");
if (!Directory.Exists(AppDataDirectory))
{
Directory.CreateDirectory(AppDataDirectory);
// Migrate config to AppData
if (File.Exists(Path.Combine(BaseDirectory, "VRCX.json")))
{
File.Move(Path.Combine(BaseDirectory, "VRCX.json"), Path.Combine(AppDataDirectory, "VRCX.json"));
File.Copy(Path.Combine(AppDataDirectory, "VRCX.json"), Path.Combine(AppDataDirectory, "VRCX-backup.json"));
}
if (File.Exists(Path.Combine(BaseDirectory, "VRCX.sqlite3")))
{
File.Move(Path.Combine(BaseDirectory, "VRCX.sqlite3"), Path.Combine(AppDataDirectory, "VRCX.sqlite3"));
File.Copy(Path.Combine(AppDataDirectory, "VRCX.sqlite3"), Path.Combine(AppDataDirectory, "VRCX-backup.sqlite3"));
}
}
} }
[STAThread] [STAThread]

View File

@@ -1,4 +1,4 @@
using CefSharp; using CefSharp;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Data.SQLite; using System.Data.SQLite;
@@ -22,7 +22,7 @@ namespace VRCX
{ {
m_ConnectionLock = new ReaderWriterLockSlim(); m_ConnectionLock = new ReaderWriterLockSlim();
var dataSource = Path.Combine(Program.BaseDirectory, "VRCX.sqlite3"); var dataSource = Path.Combine(Program.AppDataDirectory, "VRCX.sqlite3");
m_Connection = new SQLiteConnection($"Data Source=\"{dataSource}\";Version=3;PRAGMA locking_mode=NORMAL;PRAGMA busy_timeout=5000", true); m_Connection = new SQLiteConnection($"Data Source=\"{dataSource}\";Version=3;PRAGMA locking_mode=NORMAL;PRAGMA busy_timeout=5000", true);
} }

View File

@@ -15,7 +15,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.BaseDirectory, "VRCX.json"); private static string m_JsonPath = Path.Combine(Program.AppDataDirectory, "VRCX.json");
private static bool m_Dirty; private static bool m_Dirty;
static VRCXStorage() static VRCXStorage()