Browse Source

Renamed LoneFunctions to Utils

Added Ref utility function
pull/46/head
DaNike 5 years ago
parent
commit
33492cc9e3
7 changed files with 31 additions and 14 deletions
  1. +1
    -1
      IPA.Injector/Backups/BackupUnit.cs
  2. +2
    -2
      IPA.Injector/Updates.cs
  3. +1
    -1
      IPA.Loader/Loader/PluginManager.cs
  4. +3
    -3
      IPA.Loader/Updating/ModSaber/ApiEndpoint.cs
  5. +6
    -6
      IPA.Loader/Updating/ModSaber/Updater.cs
  6. +17
    -0
      IPA.Loader/Utilities/Ref.cs
  7. +1
    -1
      IPA.Loader/Utilities/Utils.cs

+ 1
- 1
IPA.Injector/Backups/BackupUnit.cs View File

@ -67,7 +67,7 @@ namespace IPA.Injector.Backups
/// <param name="file"></param>
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


+ 2
- 2
IPA.Injector/Updates.cs View File

@ -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)
{


+ 1
- 1
IPA.Loader/Loader/PluginManager.cs View File

@ -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)
{


+ 3
- 3
IPA.Loader/Updating/ModSaber/ApiEndpoint.cs View File

@ -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]


+ 6
- 6
IPA.Loader/Updating/ModSaber/Updater.cs View File

@ -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");


+ 17
- 0
IPA.Loader/Utilities/Ref.cs View File

@ -4,6 +4,23 @@ using System.Reflection;
namespace IPA.Utilities
{
/// <summary>
/// Utilities to create <see cref="Ref{T}"/> using type inference.
/// </summary>
public static class Ref
{
/// <summary>
/// Creates a <see cref="Ref{T}"/>.
/// </summary>
/// <typeparam name="T">the type to reference.</typeparam>
/// <param name="val">the default value.</param>
/// <returns>the new <see cref="Ref{T}"/>.</returns>
public static Ref<T> Create<T>(T val)
{
return new Ref<T>(val);
}
}
/// <summary>
/// A class to store a reference for passing to methods which cannot take ref parameters.
/// </summary>


IPA.Loader/Utilities/LoneFunctions.cs → IPA.Loader/Utilities/Utils.cs View File

@ -7,7 +7,7 @@ namespace IPA.Utilities
/// <summary>
/// A class providing static utility functions that in any other language would just *exist*.
/// </summary>
public static class LoneFunctions
public static class Utils
{
/// <summary>
/// Converts a hex string to a byte array.

Loading…
Cancel
Save