diff --git a/AppApi.cs b/AppApi.cs index 654648d3..fcb04491 100644 --- a/AppApi.cs +++ b/AppApi.cs @@ -59,8 +59,11 @@ namespace VRCX public string MD5File(string Blob) { var fileData = Convert.FromBase64CharArray(Blob.ToCharArray(), 0, Blob.Length); - var md5 = MD5.Create().ComputeHash(fileData); - return Convert.ToBase64String(md5); + using (var md5 = MD5.Create()) + { + var md5Hash = md5.ComputeHash(fileData); + return Convert.ToBase64String(md5Hash); + } } /// @@ -71,11 +74,13 @@ namespace VRCX public string SignFile(string Blob) { var fileData = Convert.FromBase64CharArray(Blob.ToCharArray(), 0, Blob.Length); - var sig = Librsync.ComputeSignature(new MemoryStream(fileData)); - var memoryStream = new MemoryStream(); - sig.CopyTo(memoryStream); - var sigBytes = memoryStream.ToArray(); - return Convert.ToBase64String(sigBytes); + using (var sig = Librsync.ComputeSignature(new MemoryStream(fileData))) + using (var memoryStream = new MemoryStream()) + { + sig.CopyTo(memoryStream); + var sigBytes = memoryStream.ToArray(); + return Convert.ToBase64String(sigBytes); + } } /// @@ -85,7 +90,7 @@ namespace VRCX /// The length of the file in bytes. public string FileLength(string Blob) { - var fileData = Convert.FromBase64CharArray(Blob.ToCharArray(), 0, Blob.Length); + var fileData = Convert.FromBase64String(Blob); return fileData.Length.ToString(); } @@ -99,7 +104,7 @@ namespace VRCX var configFile = Path.Combine(logPath, @"config.json"); if (!Directory.Exists(logPath) || !File.Exists(configFile)) { - return ""; + return string.Empty; } var json = File.ReadAllText(configFile); @@ -404,7 +409,7 @@ namespace VRCX Icon = Image; } - var broadcastIP = IPAddress.Parse("127.0.0.1"); + var broadcastIP = IPAddress.Loopback; var broadcastSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); var endPoint = new IPEndPoint(broadcastIP, 42069); @@ -415,7 +420,7 @@ namespace VRCX msg.height = 110f; msg.sourceApp = "VRCX"; msg.timeout = Timeout; - msg.audioPath = ""; + msg.audioPath = string.Empty; msg.useBase64Icon = UseBase64Icon; msg.icon = Icon; @@ -430,9 +435,11 @@ namespace VRCX public void DownloadVRCXUpdate(string url) { var Location = Path.Combine(Program.AppDataDirectory, "update.exe"); - var client = new WebClient(); - client.Headers.Add("user-agent", Program.Version); - client.DownloadFile(new Uri(url), Location); + using (var client = new WebClient()) + { + client.Headers.Add("user-agent", Program.Version); + client.DownloadFile(new Uri(url), Location); + } } /// diff --git a/AssetBundleCacher.cs b/AssetBundleCacher.cs index 6d845b79..28f2673f 100644 --- a/AssetBundleCacher.cs +++ b/AssetBundleCacher.cs @@ -46,7 +46,7 @@ namespace VRCX public string GetAssetVersion(int version) { byte[] bytes = BitConverter.GetBytes(version); - string versionHex = String.Empty; + string versionHex = string.Empty; foreach (byte b in bytes) { versionHex += b.ToString("X2"); diff --git a/AutoAppLaunchManager.cs b/AutoAppLaunchManager.cs index 10946a5d..8020dfab 100644 --- a/AutoAppLaunchManager.cs +++ b/AutoAppLaunchManager.cs @@ -162,9 +162,8 @@ namespace VRCX Process proc = Process.GetProcessById(pid); proc.Kill(); } - catch (Exception ex) + catch { - } } diff --git a/IPCClient.cs b/IPCClient.cs index dd9fac46..1de5b611 100644 --- a/IPCClient.cs +++ b/IPCClient.cs @@ -39,7 +39,7 @@ namespace VRCX _ipcServer.BeginRead(_recvBuffer, 0, _recvBuffer.Length, OnRead, _ipcServer); } - public async Task Send(IPCPacket ipcPacket) + public void Send(IPCPacket ipcPacket) { try { diff --git a/IPCServer.cs b/IPCServer.cs index bb9c0967..5a1a9c09 100644 --- a/IPCServer.cs +++ b/IPCServer.cs @@ -26,11 +26,11 @@ namespace VRCX new IPCServer().CreateIPCServer(); } - public static async Task Send(IPCPacket ipcPacket) + public static void Send(IPCPacket ipcPacket) { foreach (var client in Clients) { - await client.Send(ipcPacket); + client.Send(ipcPacket); } } diff --git a/ImageCache.cs b/ImageCache.cs index ab928396..b3df86b0 100644 --- a/ImageCache.cs +++ b/ImageCache.cs @@ -33,7 +33,7 @@ namespace VRCX using (var client = new WebClient()) { - string cookieString = String.Empty; + string cookieString = string.Empty; if (WebApi.Instance != null && WebApi.Instance._cookieContainer != null) { CookieCollection cookies = WebApi.Instance._cookieContainer.GetCookies(new Uri($"https://{imageHost}")); diff --git a/Program.cs b/Program.cs index 009adef5..13de48e5 100644 --- a/Program.cs +++ b/Program.cs @@ -16,7 +16,7 @@ namespace VRCX public static class Program { public static string BaseDirectory { get; private set; } - public static string AppDataDirectory { get; private set; } + public static readonly string AppDataDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "VRCX"); public static string ConfigLocation; public static string Version { get; private set; } public static bool LaunchDebug; @@ -25,7 +25,6 @@ namespace VRCX static Program() { BaseDirectory = AppDomain.CurrentDomain.BaseDirectory; - AppDataDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "VRCX"); ConfigLocation = Path.Combine(Program.AppDataDirectory, "VRCX.sqlite3"); if (!Directory.Exists(AppDataDirectory)) diff --git a/Properties/Resources.Designer.cs b/Properties/Resources.Designer.cs index ee915eda..ad62a905 100644 --- a/Properties/Resources.Designer.cs +++ b/Properties/Resources.Designer.cs @@ -19,7 +19,7 @@ namespace VRCX.Properties { // class via a tool like ResGen or Visual Studio. // To add or remove a member, edit your .ResX file then rerun ResGen // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class Resources { diff --git a/SQLite.cs b/SQLite.cs index 3bfd1fd7..93b78c97 100644 --- a/SQLite.cs +++ b/SQLite.cs @@ -484,7 +484,7 @@ namespace SQLite throw new ArgumentNullException (nameof (key)); if (key.Length != 32 && key.Length != 48) throw new ArgumentException ("Key must be 32 bytes (256-bit) or 48 bytes (384-bit)", nameof (key)); - var s = String.Join ("", key.Select (x => x.ToString ("X2"))); + var s = string.Join(string.Empty, key.Select (x => x.ToString ("X2"))); ExecuteScalar ("pragma key = \"x'" + s + "'\""); } @@ -816,7 +816,7 @@ namespace SQLite 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}\")"; - var sql = String.Format (sqlFormat, tableName, string.Join ("\", \"", columnNames), unique ? "unique" : "", indexName); + var sql = String.Format (sqlFormat, tableName, string.Join ("\", \"", columnNames), unique ? "unique" : string.Empty, indexName); return Execute (sql); } @@ -1720,7 +1720,7 @@ namespace SQLite if (obj == null) { return 0; } - return Insert (obj, "", Orm.GetType (obj)); + return Insert (obj, string.Empty, Orm.GetType (obj)); } /// @@ -1761,7 +1761,7 @@ namespace SQLite /// public int Insert (object obj, Type objType) { - return Insert (obj, "", objType); + return Insert (obj, string.Empty, objType); } /// @@ -2170,7 +2170,7 @@ namespace SQLite // Check for errors r = SQLite3.GetResult (destHandle); - string msg = ""; + string msg = string.Empty; if (r != SQLite3.Result.OK) { msg = SQLite3.GetErrmsg (destHandle); } @@ -2932,16 +2932,16 @@ namespace SQLite public static string Collation (MemberInfo p) { #if ENABLE_IL2CPP - return (p.GetCustomAttribute ()?.Value) ?? ""; + return (p.GetCustomAttribute ()?.Value) ?? string.Empty; #else return (p.CustomAttributes .Where (x => typeof (CollationAttribute) == x.AttributeType) .Select (x => { var args = x.ConstructorArguments; - return args.Count > 0 ? ((args[0].Value as string) ?? "") : ""; + return args.Count > 0 ? ((args[0].Value as string) ?? string.Empty) : string.Empty; }) - .FirstOrDefault ()) ?? ""; + .FirstOrDefault ()) ?? string.Empty; #endif } @@ -3033,7 +3033,7 @@ namespace SQLite { _conn = conn; _bindings = new List (); - CommandText = ""; + CommandText = string.Empty; } public int ExecuteNonQuery () @@ -4052,7 +4052,7 @@ namespace SQLite cmdText += " where " + w.CommandText; } if ((_orderBys != null) && (_orderBys.Count > 0)) { - var t = string.Join (", ", _orderBys.Select (o => "\"" + o.ColumnName + "\"" + (o.Ascending ? "" : " desc")).ToArray ()); + var t = string.Join (", ", _orderBys.Select (o => "\"" + o.ColumnName + "\"" + (o.Ascending ? string.Empty : " desc")).ToArray ()); cmdText += " order by " + t; } if (_limit.HasValue) { @@ -4127,7 +4127,7 @@ namespace SQLite args[i] = CompileExpr (call.Arguments[i], queryArgs); } - var sqlCall = ""; + var sqlCall = string.Empty; if (call.Method.Name == "Like" && args.Length == 2) { sqlCall = "(" + args[0].CommandText + " like " + args[1].CommandText + ")"; @@ -4269,7 +4269,7 @@ namespace SQLite if (val != null && val is System.Collections.IEnumerable && !(val is string) && !(val is System.Collections.Generic.IEnumerable)) { var sb = new System.Text.StringBuilder (); sb.Append ("("); - var head = ""; + var head = string.Empty; foreach (var a in (System.Collections.IEnumerable)val) { queryArgs.Add (a); sb.Append (head); @@ -4726,7 +4726,7 @@ namespace SQLite public static Result Open (string filename, out Sqlite3DatabaseHandle db, int flags, string vfsName) { #if USE_WP8_NATIVE_SQLITE - return (Result)Sqlite3.sqlite3_open_v2(filename, out db, flags, vfsName ?? ""); + return (Result)Sqlite3.sqlite3_open_v2(filename, out db, flags, vfsName ?? string.Empty); #else return (Result)Sqlite3.sqlite3_open_v2 (filename, out db, flags, vfsName); #endif diff --git a/ScreenshotHelper.cs b/ScreenshotHelper.cs index 6868d949..bf6e74d0 100644 --- a/ScreenshotHelper.cs +++ b/ScreenshotHelper.cs @@ -231,7 +231,7 @@ namespace VRCX { metadata.Add("author", new JObject { - { "id", "" }, + { "id", string.Empty }, { "displayName", $"{author[1]} ({author[0]})" } }); break; @@ -249,18 +249,18 @@ namespace VRCX var world = split[1].Split(','); metadata.Add("world", new JObject { - { "id", "" }, + { "id", string.Empty }, { "name", $"{world[2]} ({world[0]})" }, - { "instanceId", "" } + { "instanceId", string.Empty } }); } else if (version == 1) { metadata.Add("world", new JObject { - { "id", "" }, + { "id", string.Empty }, { "name", split[1] }, - { "instanceId", "" } + { "instanceId", string.Empty } }); } else @@ -297,7 +297,7 @@ namespace VRCX { playersArray.Add(new JObject { - { "id", "" }, + { "id", string.Empty }, { "x", playerSplit[1] }, { "y", playerSplit[2] }, { "z", playerSplit[3] }, @@ -342,7 +342,6 @@ namespace VRCX // init lookup table and store crc for iTXt private static readonly uint iTXtCrc = Crc32(new[] { (byte)'i', (byte)'T', (byte)'X', (byte)'t' }, 0, 4, 0); private readonly Encoding keywordEncoding = Encoding.GetEncoding("ISO-8859-1"); // ISO-8859-1/Latin1 is the encoding used for the keyword in text chunks. - public List ChunkBytes; public List ChunkDataBytes; public int ChunkDataLength; public string ChunkType; diff --git a/Update.cs b/Update.cs index 4bea6d36..ab4b6dbe 100644 --- a/Update.cs +++ b/Update.cs @@ -13,13 +13,16 @@ namespace VRCX { internal class Update { + private static readonly string VRCX_Setup_Executable = Path.Combine(Program.AppDataDirectory, "VRCX_Setup.exe"); + private static readonly string Update_Executable = Path.Combine(Program.AppDataDirectory, "update.exe"); + public static void Check() { if (Process.GetProcessesByName("VRCX_Setup").Length > 0) Environment.Exit(0); - if (File.Exists(Path.Combine(Program.AppDataDirectory, "VRCX_Setup.exe"))) - File.Delete(Path.Combine(Program.AppDataDirectory, "VRCX_Setup.exe")); - if (File.Exists(Path.Combine(Program.AppDataDirectory, "update.exe"))) + if (File.Exists(VRCX_Setup_Executable)) + File.Delete(VRCX_Setup_Executable); + if (File.Exists(Update_Executable)) Install(); } @@ -27,12 +30,12 @@ namespace VRCX { try { - File.Move(Path.Combine(Program.AppDataDirectory, "update.exe"), Path.Combine(Program.AppDataDirectory, "VRCX_Setup.exe")); + File.Move(Update_Executable, VRCX_Setup_Executable); var VRCXProcess = new Process { StartInfo = new ProcessStartInfo { - FileName = Path.Combine(Program.AppDataDirectory, "VRCX_Setup.exe"), + FileName = VRCX_Setup_Executable, Arguments = "/S" } }; diff --git a/VRCX.csproj b/VRCX.csproj index 683a3e7c..272225bc 100644 --- a/VRCX.csproj +++ b/VRCX.csproj @@ -134,9 +134,11 @@ VRForm.cs + Designer MainForm.cs + Designer ResXFileCodeGenerator diff --git a/WebApi.cs b/WebApi.cs index 12e658fd..4e3a5613 100644 --- a/WebApi.cs +++ b/WebApi.cs @@ -204,7 +204,7 @@ namespace VRCX string FormDataTemplate = "--{0}\r\nContent-Disposition: form-data; name=\"{1}\"\r\n\r\n{2}\r\n"; foreach (string key in postData.Keys) { - string item = String.Format(FormDataTemplate, boundary, key, postData[key]); + string item = string.Format(FormDataTemplate, boundary, key, postData[key]); byte[] itemBytes = System.Text.Encoding.UTF8.GetBytes(item); await requestStream.WriteAsync(itemBytes, 0, itemBytes.Length); } @@ -215,7 +215,7 @@ namespace VRCX string fileName = "image.png"; string fileMimeType = "image/png"; string HeaderTemplate = "--{0}\r\nContent-Disposition: form-data; name=\"{1}\"; filename=\"{2}\"\r\nContent-Type: {3}\r\n\r\n"; - string header = String.Format(HeaderTemplate, boundary, fileFormKey, fileName, fileMimeType); + string header = string.Format(HeaderTemplate, boundary, fileFormKey, fileName, fileMimeType); byte[] headerbytes = Encoding.UTF8.GetBytes(header); await requestStream.WriteAsync(headerbytes, 0, headerbytes.Length); using (MemoryStream fileStream = new MemoryStream(fileToUpload)) diff --git a/WorldDBManager.cs b/WorldDBManager.cs index 6536f85f..7cd327a2 100644 --- a/WorldDBManager.cs +++ b/WorldDBManager.cs @@ -363,7 +363,7 @@ namespace VRCX /// True if the world was successfully initialized, false otherwise. private bool TryInitializeWorld(string worldId, out string connectionKey) { - if (String.IsNullOrEmpty(worldId)) + if (string.IsNullOrEmpty(worldId)) { connectionKey = null; return false; @@ -421,7 +421,7 @@ namespace VRCX string worldId = funcResult?.Result?.ToString(); - if (String.IsNullOrEmpty(worldId)) + if (string.IsNullOrEmpty(worldId)) { // implement // wait what was i going to do here again @@ -484,7 +484,7 @@ namespace VRCX /// Processes a JSON request containing world data and logs it to the world database. /// /// The JSON request containing the world data. - public async void ProcessLogWorldDataRequest(string json) + public void ProcessLogWorldDataRequest(string json) { // Current format: // { @@ -519,7 +519,7 @@ namespace VRCX return; } - if (String.IsNullOrEmpty(request.RequestType)) + if (string.IsNullOrEmpty(request.RequestType)) { logger.Warn("World tried to store data with no request type provided. Request: ", json); this.lastError = "`requestType` is missing or null";