From b7dfef869c1302a9a05e062e0d37d4107039d8e4 Mon Sep 17 00:00:00 2001 From: DaNike Date: Tue, 29 Jan 2019 00:35:38 -0600 Subject: [PATCH] Renamed LoneFunctions to Utils Added Ref utility function --- IPA.Injector/Backups/BackupUnit.cs | 2 +- IPA.Injector/Updates.cs | 4 ++-- IPA.Loader/Loader/PluginManager.cs | 2 +- IPA.Loader/Updating/ModSaber/ApiEndpoint.cs | 6 +++--- IPA.Loader/Updating/ModSaber/Updater.cs | 12 ++++++------ IPA.Loader/Utilities/Ref.cs | 17 +++++++++++++++++ .../Utilities/{LoneFunctions.cs => Utils.cs} | 2 +- 7 files changed, 31 insertions(+), 14 deletions(-) rename IPA.Loader/Utilities/{LoneFunctions.cs => Utils.cs} (99%) diff --git a/IPA.Injector/Backups/BackupUnit.cs b/IPA.Injector/Backups/BackupUnit.cs index 4a0a78d8..d168ffe1 100644 --- a/IPA.Injector/Backups/BackupUnit.cs +++ b/IPA.Injector/Backups/BackupUnit.cs @@ -67,7 +67,7 @@ namespace IPA.Injector.Backups /// public void Add(FileInfo file) { - var relativePath = Utilities.LoneFunctions.GetRelativePath(file.FullName, Environment.CurrentDirectory); + var relativePath = Utilities.Utils.GetRelativePath(file.FullName, Environment.CurrentDirectory); var backupPath = new FileInfo(Path.Combine(_backupPath.FullName, relativePath)); // Copy over diff --git a/IPA.Injector/Updates.cs b/IPA.Injector/Updates.cs index 5c09f427..94522478 100644 --- a/IPA.Injector/Updates.cs +++ b/IPA.Injector/Updates.cs @@ -73,7 +73,7 @@ namespace IPA.Injector { try { - if (!LoneFunctions.GetRelativePath(file, path).Split(Path.PathSeparator).Contains("Pending")) + if (!Utils.GetRelativePath(file, path).Split(Path.PathSeparator).Contains("Pending")) File.Delete(file); } catch (FileNotFoundException e) @@ -97,7 +97,7 @@ namespace IPA.Injector try { - LoneFunctions.CopyAll(new DirectoryInfo(pendingDir), new DirectoryInfo(BeatSaber.InstallPath)); + Utils.CopyAll(new DirectoryInfo(pendingDir), new DirectoryInfo(BeatSaber.InstallPath)); } catch (Exception e) { diff --git a/IPA.Loader/Loader/PluginManager.cs b/IPA.Loader/Loader/PluginManager.cs index 0dce9e15..4d76a875 100644 --- a/IPA.Loader/Loader/PluginManager.cs +++ b/IPA.Loader/Loader/PluginManager.cs @@ -196,7 +196,7 @@ namespace IPA.Loader Logger.log.Info($"Running on Unity {Application.unityVersion}"); Logger.log.Info($"Game version {BeatSaber.GameVersion}"); Logger.log.Info("-----------------------------"); - Logger.log.Info($"Loading plugins from {LoneFunctions.GetRelativePath(pluginDirectory, Environment.CurrentDirectory)} and found {_bsPlugins.Count + _ipaPlugins.Count}"); + Logger.log.Info($"Loading plugins from {Utils.GetRelativePath(pluginDirectory, Environment.CurrentDirectory)} and found {_bsPlugins.Count + _ipaPlugins.Count}"); Logger.log.Info("-----------------------------"); foreach (var plugin in _bsPlugins) { diff --git a/IPA.Loader/Updating/ModSaber/ApiEndpoint.cs b/IPA.Loader/Updating/ModSaber/ApiEndpoint.cs index 2516da6a..72d51825 100644 --- a/IPA.Loader/Updating/ModSaber/ApiEndpoint.cs +++ b/IPA.Loader/Updating/ModSaber/ApiEndpoint.cs @@ -32,7 +32,7 @@ namespace IPA.Updating.ModSaber { try { - return LoneFunctions.StringToByteArray((string)reader.Value); + return Utils.StringToByteArray((string)reader.Value); } catch (Exception ex) { @@ -55,7 +55,7 @@ namespace IPA.Updating.ModSaber { throw new JsonSerializationException("Expected byte[] object value"); } - writer.WriteValue(LoneFunctions.ByteArrayToString((byte[]) value)); + writer.WriteValue(Utils.ByteArrayToString((byte[]) value)); } } } @@ -138,7 +138,7 @@ namespace IPA.Updating.ModSaber public string DownloadPath; public override string ToString() => - $"{LoneFunctions.ByteArrayToString(Hash)}@{DownloadPath}({string.Join(",", FileHashes.Select(o => $"\"{o.Key}\":\"{LoneFunctions.ByteArrayToString(o.Value)}\""))})"; + $"{Utils.ByteArrayToString(Hash)}@{DownloadPath}({string.Join(",", FileHashes.Select(o => $"\"{o.Key}\":\"{Utils.ByteArrayToString(o.Value)}\""))})"; } [Serializable] diff --git a/IPA.Loader/Updating/ModSaber/Updater.cs b/IPA.Loader/Updating/ModSaber/Updater.cs index 6a279ecf..6a026494 100644 --- a/IPA.Loader/Updating/ModSaber/Updater.cs +++ b/IPA.Loader/Updating/ModSaber/Updater.cs @@ -463,7 +463,7 @@ namespace IPA.Updating.ModSaber var data = stream.GetBuffer(); SHA1 sha = new SHA1CryptoServiceProvider(); var hash = sha.ComputeHash(data); - if (!LoneFunctions.UnsafeCompare(hash, fileInfo.Hash)) + if (!Utils.UnsafeCompare(hash, fileInfo.Hash)) throw new Exception("The hash for the file doesn't match what is defined"); var targetDir = Path.Combine(BeatSaber.InstallPath, "IPA", Path.GetRandomFileName() + "_Pending"); @@ -499,7 +499,7 @@ namespace IPA.Updating.ModSaber try { - if (!LoneFunctions.UnsafeCompare(fileHash, fileInfo.FileHashes[entry.FileName])) + if (!Utils.UnsafeCompare(fileHash, fileInfo.FileHashes[entry.FileName])) throw new Exception("The hash for the file doesn't match what is defined"); } catch (KeyNotFoundException) @@ -511,7 +511,7 @@ namespace IPA.Updating.ModSaber FileInfo targetFile = new FileInfo(Path.Combine(targetDir, entry.FileName)); Directory.CreateDirectory(targetFile.DirectoryName ?? throw new InvalidOperationException()); - if (LoneFunctions.GetRelativePath(targetFile.FullName, targetDir) == LoneFunctions.GetRelativePath(item.LocalPluginMeta?.Metadata.File.FullName, BeatSaber.InstallPath)) + if (Utils.GetRelativePath(targetFile.FullName, targetDir) == Utils.GetRelativePath(item.LocalPluginMeta?.Metadata.File.FullName, BeatSaber.InstallPath)) shouldDeleteOldFile = false; // overwriting old file, no need to delete /*if (targetFile.Exists) @@ -530,7 +530,7 @@ namespace IPA.Updating.ModSaber } if (shouldDeleteOldFile && item.LocalPluginMeta != null) - File.AppendAllLines(Path.Combine(targetDir, SpecialDeletionsFile), new[] { LoneFunctions.GetRelativePath(item.LocalPluginMeta?.Metadata.File.FullName, BeatSaber.InstallPath) }); + File.AppendAllLines(Path.Combine(targetDir, SpecialDeletionsFile), new[] { Utils.GetRelativePath(item.LocalPluginMeta?.Metadata.File.FullName, BeatSaber.InstallPath) }); } catch (Exception) { // something failed; restore @@ -545,7 +545,7 @@ namespace IPA.Updating.ModSaber if (item.LocalPluginMeta?.Plugin is SelfPlugin) { // currently updating self, so copy to working dir and update - LoneFunctions.CopyAll(new DirectoryInfo(targetDir), new DirectoryInfo(BeatSaber.InstallPath)); + Utils.CopyAll(new DirectoryInfo(targetDir), new DirectoryInfo(BeatSaber.InstallPath)); if (File.Exists(Path.Combine(BeatSaber.InstallPath, SpecialDeletionsFile))) File.Delete(Path.Combine(BeatSaber.InstallPath, SpecialDeletionsFile)); Process.Start(new ProcessStartInfo { @@ -555,7 +555,7 @@ namespace IPA.Updating.ModSaber }); } else - LoneFunctions.CopyAll(new DirectoryInfo(targetDir), new DirectoryInfo(eventualOutput), SpecialDeletionsFile); + Utils.CopyAll(new DirectoryInfo(targetDir), new DirectoryInfo(eventualOutput), SpecialDeletionsFile); Directory.Delete(targetDir, true); // delete extraction site Logger.updater.Debug("Extractor exited"); diff --git a/IPA.Loader/Utilities/Ref.cs b/IPA.Loader/Utilities/Ref.cs index 9f68a2a5..bcb1ff62 100644 --- a/IPA.Loader/Utilities/Ref.cs +++ b/IPA.Loader/Utilities/Ref.cs @@ -4,6 +4,23 @@ using System.Reflection; namespace IPA.Utilities { + /// + /// Utilities to create using type inference. + /// + public static class Ref + { + /// + /// Creates a . + /// + /// the type to reference. + /// the default value. + /// the new . + public static Ref Create(T val) + { + return new Ref(val); + } + } + /// /// A class to store a reference for passing to methods which cannot take ref parameters. /// diff --git a/IPA.Loader/Utilities/LoneFunctions.cs b/IPA.Loader/Utilities/Utils.cs similarity index 99% rename from IPA.Loader/Utilities/LoneFunctions.cs rename to IPA.Loader/Utilities/Utils.cs index 10df9a53..a702f5b3 100644 --- a/IPA.Loader/Utilities/LoneFunctions.cs +++ b/IPA.Loader/Utilities/Utils.cs @@ -7,7 +7,7 @@ namespace IPA.Utilities /// /// A class providing static utility functions that in any other language would just *exist*. /// - public static class LoneFunctions + public static class Utils { /// /// Converts a hex string to a byte array.