From 053e85047e985cfd2f14bfac9de090859f14e156 Mon Sep 17 00:00:00 2001 From: Natsumi Date: Tue, 4 Oct 2022 01:54:38 +1300 Subject: [PATCH] Version file --- AppApi.cs | 5 ++++ CefService.cs | 2 +- MainForm.Designer.cs | 2 +- Program.cs | 15 ++++++++++++ VRCX.csproj | 5 +++- Version | 1 + WebApi.cs | 5 +--- html/src/app.js | 54 +++++++++++++++++++++++-------------------- html/src/constants.js | 1 - 9 files changed, 57 insertions(+), 33 deletions(-) create mode 100644 Version delete mode 100644 html/src/constants.js diff --git a/AppApi.cs b/AppApi.cs index 73500129..30a9c342 100644 --- a/AppApi.cs +++ b/AppApi.cs @@ -370,6 +370,11 @@ namespace VRCX return System.Globalization.CultureInfo.CurrentCulture.ToString(); } + public string GetVersion() + { + return Program.Version; + } + public void ChangeTheme(int value) { WinformThemer.SetGlobalTheme(value); diff --git a/CefService.cs b/CefService.cs index 300cfbb7..8d4511b3 100644 --- a/CefService.cs +++ b/CefService.cs @@ -50,7 +50,7 @@ namespace VRCX // Enable High-DPI support on Windows 7 or newer Cef.EnableHighDPISupport(); - cefSettings.UserAgent = "VRCX Cef Browser"; + cefSettings.UserAgent = Program.Version; if (Cef.Initialize(cefSettings) == false) { diff --git a/MainForm.Designer.cs b/MainForm.Designer.cs index 39db5823..b0eb6f9a 100644 --- a/MainForm.Designer.cs +++ b/MainForm.Designer.cs @@ -94,7 +94,7 @@ namespace VRCX this.MinimumSize = new System.Drawing.Size(320, 240); this.Name = "MainForm"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; - this.Text = "VRCX"; + this.Text = Program.Version; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.MainForm_FormClosing); this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.MainForm_FormClosed); this.Load += new System.EventHandler(this.MainForm_Load); diff --git a/Program.cs b/Program.cs index c440fca9..1b24b010 100644 --- a/Program.cs +++ b/Program.cs @@ -15,6 +15,7 @@ namespace VRCX public static string BaseDirectory { get; private set; } public static string AppDataDirectory { get; private set; } public static string ConfigLocation; + public static string Version { get; private set; } public static bool LaunchDebug; static Program() @@ -55,10 +56,24 @@ namespace VRCX } } + private static void GetVersion() + { + var buildName = "VRCX"; + try + { + Version = $"{buildName} {File.ReadAllText(Path.Combine(BaseDirectory, "Version"))}"; + } + catch (Exception) + { + Version = $"{buildName} Build"; + } + } + private static void Run() { Update.Check(); StartupArgs.ArgsCheck(); + GetVersion(); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); diff --git a/VRCX.csproj b/VRCX.csproj index 24c50a4f..79ea8c4f 100644 --- a/VRCX.csproj +++ b/VRCX.csproj @@ -1,4 +1,4 @@ - + @@ -154,6 +154,9 @@ Settings.settings True + + Always + diff --git a/Version b/Version new file mode 100644 index 00000000..2d82e850 --- /dev/null +++ b/Version @@ -0,0 +1 @@ +Build \ No newline at end of file diff --git a/WebApi.cs b/WebApi.cs index 2c9ebca9..1c2cd61b 100644 --- a/WebApi.cs +++ b/WebApi.cs @@ -131,6 +131,7 @@ namespace VRCX var request = WebRequest.CreateHttp((string)options["url"]); request.CookieContainer = _cookieContainer; request.KeepAlive = true; + request.UserAgent = Program.Version; if (options.TryGetValue("headers", out object headers) == true) { @@ -143,10 +144,6 @@ namespace VRCX { request.ContentType = value; } - else if (string.Compare(key, "User-Agent", StringComparison.OrdinalIgnoreCase) == 0) - { - request.UserAgent = value; - } else if (string.Compare(key, "Referer", StringComparison.OrdinalIgnoreCase) == 0) { request.Referer = value; diff --git a/html/src/app.js b/html/src/app.js index 7f95574a..53f2feb2 100644 --- a/html/src/app.js +++ b/html/src/app.js @@ -16,7 +16,6 @@ import {v4 as uuidv4} from 'uuid'; import * as workerTimers from 'worker-timers'; import 'default-passive-events'; -import {appVersion} from './constants.js'; import configRepository from './repository/config.js'; import webApiService from './service/webapi.js'; import gameLogService from './service/gamelog.js'; @@ -383,10 +382,6 @@ speechSynthesis.getVoices(); init.body = params === Object(params) ? JSON.stringify(params) : '{}'; } - init.headers = { - 'User-Agent': appVersion, - ...init.headers - }; var req = webApiService .execute(init) .catch((err) => { @@ -4328,7 +4323,7 @@ speechSynthesis.getVoices(); isGameRunning: false, isGameNoVR: configRepository.getBool('isGameNoVR'), isSteamVRRunning: false, - appVersion, + appVersion: '', latestAppVersion: '', ossDialog: false, exportFriendsListDialog: false, @@ -4339,6 +4334,9 @@ speechSynthesis.getVoices(); watch: {}, el: '#x-app', mounted() { + AppApi.GetVersion().then((version) => { + this.appVersion = version; + }); API.$on('SHOW_WORLD_DIALOG', (tag) => this.showWorldDialog(tag)); API.$on('SHOW_LAUNCH_DIALOG', (tag) => this.showLaunchDialog(tag)); this.updateLoop(); @@ -5247,8 +5245,7 @@ speechSynthesis.getVoices(); imageLocation = await AppApi.GetImage( imageUrl, fileId, - fileVersion, - appVersion + fileVersion ); } else if (imageUrl) { fileVersion = imageUrl.split('/').pop(); // 1416226261.thumbnail-500.png @@ -5256,8 +5253,7 @@ speechSynthesis.getVoices(); imageLocation = await AppApi.GetImage( imageUrl, fileId, - fileVersion, - appVersion + fileVersion ); } } catch (err) { @@ -10351,7 +10347,6 @@ speechSynthesis.getVoices(); )}&part=snippet,contentDetails&key=${apiKey}`, method: 'GET', headers: { - 'User-Agent': appVersion, Referer: 'https://vrcx.pypy.moe' } }); @@ -12427,11 +12422,20 @@ speechSynthesis.getVoices(); configRepository.setString('VRCX_branch', $app.data.branch); } if (configRepository.getString('VRCX_lastVRCXVersion')) { - if (configRepository.getString('VRCX_lastVRCXVersion') < appVersion) { - configRepository.setString('VRCX_lastVRCXVersion', appVersion); + if ( + configRepository.getString('VRCX_lastVRCXVersion') < + $app.data.appVersion + ) { + configRepository.setString( + 'VRCX_lastVRCXVersion', + $app.data.appVersion + ); } } else { - configRepository.setString('VRCX_lastVRCXVersion', appVersion); + configRepository.setString( + 'VRCX_lastVRCXVersion', + $app.data.appVersion + ); } if (!configRepository.getInt('VRCX_maxTableSize')) { $app.data.maxTableSize = 1000; @@ -14283,7 +14287,6 @@ speechSynthesis.getVoices(); }?${type}=${encodeURIComponent(search)}&n=5000`, method: 'GET', headers: { - 'User-Agent': appVersion, Referer: 'https://vrcx.pypy.moe' } }); @@ -14346,7 +14349,6 @@ speechSynthesis.getVoices(); url: `${url}?authorId=${encodeURIComponent(authorId)}`, method: 'GET', headers: { - 'User-Agent': appVersion, Referer: 'https://vrcx.pypy.moe' } }); @@ -18966,7 +18968,7 @@ speechSynthesis.getVoices(); var url = this.downloadCurrent.updateZipUrl; var size = this.downloadCurrent.size; - await AssetBundleCacher.DownloadFile(url, size, appVersion); + await AssetBundleCacher.DownloadFile(url, size); this.downloadFileProgress(); }; @@ -19649,10 +19651,7 @@ speechSynthesis.getVoices(); this.checkingForVRCXUpdate = true; var response = await webApiService.execute({ url, - method: 'GET', - headers: { - 'User-Agent': appVersion - } + method: 'GET' }); this.checkingForVRCXUpdate = false; var json = JSON.parse(response.data); @@ -19702,6 +19701,14 @@ speechSynthesis.getVoices(); }; $app.methods.checkForVRCXUpdate = async function () { + if ( + !this.appVersion || + this.appVersion === 'VRCX Nightly Build' || + this.appVersion === 'VRCX Stable' + ) { + console.log('Skipping VRCX update check, version is null'); + return; + } if (this.branch === 'Beta') { // move Beta users to stable this.branch = 'Stable'; @@ -19711,10 +19718,7 @@ speechSynthesis.getVoices(); this.checkingForVRCXUpdate = true; var response = await webApiService.execute({ url, - method: 'GET', - headers: { - 'User-Agent': appVersion - } + method: 'GET' }); this.checkingForVRCXUpdate = false; var json = JSON.parse(response.data); diff --git a/html/src/constants.js b/html/src/constants.js deleted file mode 100644 index cd990e12..00000000 --- a/html/src/constants.js +++ /dev/null @@ -1 +0,0 @@ -export var appVersion = 'VRCX 2022.09.09';