diff --git a/Dotnet/ImageCache.cs b/Dotnet/ImageCache.cs index f4972122..7e327451 100644 --- a/Dotnet/ImageCache.cs +++ b/Dotnet/ImageCache.cs @@ -11,7 +11,7 @@ namespace VRCX class ImageCache { private static readonly string cacheLocation = Path.Combine(Program.AppDataDirectory, "ImageCache"); - private static readonly HttpClientHandler httpClientHandler = new HttpClientHandler(){ Proxy = StartupArgs.Proxy }; + private static readonly HttpClientHandler httpClientHandler = new HttpClientHandler(){ Proxy = WebApi.Proxy }; private static readonly HttpClient httpClient = new HttpClient(httpClientHandler); private static readonly List _imageHosts = [ diff --git a/Dotnet/MainForm.cs b/Dotnet/MainForm.cs index bed4bb06..e762953e 100644 --- a/Dotnet/MainForm.cs +++ b/Dotnet/MainForm.cs @@ -6,6 +6,7 @@ using System; using System.Drawing; +using System.Net; using System.Reflection; using System.Windows.Forms; using CefSharp; @@ -57,6 +58,12 @@ namespace VRCX Dock = DockStyle.Fill }; + string? proxyUrl = VRCXStorage.Instance.Get("VRCX_ProxyServer"); + if (!string.IsNullOrEmpty(proxyUrl)) + { + WebApi.Proxy = new WebProxy(proxyUrl); + } + Browser.IsBrowserInitializedChanged += (A, B) => { if (Program.LaunchDebug) diff --git a/Dotnet/Program.cs b/Dotnet/Program.cs index 3ac8bf21..b82513fd 100644 --- a/Dotnet/Program.cs +++ b/Dotnet/Program.cs @@ -155,9 +155,10 @@ namespace VRCX private static void Run() { - BrowserSubprocess.Start(); StartupArgs.ArgsCheck(); SetProgramDirectories(); + VRCXStorage.Load(); + BrowserSubprocess.Start(); ConfigureLogger(); Update.Check(); GetVersion(); @@ -169,7 +170,6 @@ namespace VRCX ProcessMonitor.Instance.Init(); - VRCXStorage.Load(); SQLiteLegacy.Instance.Init(); AppApi.Instance.Init(); AppApiVr.Instance.Init(); diff --git a/Dotnet/StartupArgs.cs b/Dotnet/StartupArgs.cs index 272c4083..601647fe 100644 --- a/Dotnet/StartupArgs.cs +++ b/Dotnet/StartupArgs.cs @@ -5,6 +5,7 @@ // For a copy, see . using CefSharp; +using CefSharp.Internals; using System; using System.Diagnostics; using System.IO; @@ -17,7 +18,6 @@ namespace VRCX { internal class StartupArgs { - public static IWebProxy? Proxy = WebRequest.DefaultWebProxy; public static string LaunchCommand; public static Process[] processList; @@ -54,10 +54,14 @@ namespace VRCX if (arg.Length >= 16 && arg.Substring(0, 14) == "--proxy-server") { string proxyUrl = arg.Substring(15).Replace("'", string.Empty).Replace("\"", string.Empty); - Proxy = new WebProxy(proxyUrl); + WebApi.Proxy = new WebProxy(proxyUrl); } } + var type = CommandLineArgsParser.GetArgumentValue(args, CefSharpArguments.SubProcessTypeArgument); + if (!string.IsNullOrEmpty(type)) + disableClosing = true; // we're launching a subprocess, allow it + if (!string.IsNullOrEmpty(Program.AppDataDirectory)) disableClosing = true; // we're launching with a custom config path, allow it diff --git a/Dotnet/WebApi.cs b/Dotnet/WebApi.cs index 38cc4bf5..f22b339b 100644 --- a/Dotnet/WebApi.cs +++ b/Dotnet/WebApi.cs @@ -19,6 +19,7 @@ namespace VRCX public CookieContainer _cookieContainer; private bool _cookieDirty; private Timer _timer; + public static IWebProxy? Proxy = WebRequest.DefaultWebProxy; static WebApi() { @@ -144,7 +145,7 @@ namespace VRCX private static async Task LegacyImageUpload(HttpWebRequest request, IDictionary options) { - request.Proxy = StartupArgs.Proxy; + request.Proxy = Proxy; request.Method = "POST"; string boundary = "---------------------------" + DateTime.Now.Ticks.ToString("x"); request.ContentType = "multipart/form-data; boundary=" + boundary; @@ -189,7 +190,7 @@ namespace VRCX private static async Task UploadFilePut(HttpWebRequest request, IDictionary options) { - request.Proxy = StartupArgs.Proxy; + request.Proxy = Proxy; request.Method = "PUT"; request.ContentType = options["fileMIME"] as string; var fileData = options["fileData"] as string; @@ -204,7 +205,7 @@ namespace VRCX private static async Task ImageUpload(HttpWebRequest request, IDictionary options) { - request.Proxy = StartupArgs.Proxy; + request.Proxy = Proxy; request.Method = "POST"; string boundary = "---------------------------" + DateTime.Now.Ticks.ToString("x"); request.ContentType = "multipart/form-data; boundary=" + boundary; @@ -258,7 +259,7 @@ namespace VRCX try { var request = WebRequest.CreateHttp((string)options["url"]); - request.Proxy = StartupArgs.Proxy; + request.Proxy = Proxy; request.CookieContainer = _cookieContainer; request.KeepAlive = true; request.UserAgent = Program.Version;