From 779d3269622f0c213cebe1a0e2c76f3407321c32 Mon Sep 17 00:00:00 2001 From: Anairkoen Schno Date: Sun, 5 Aug 2018 19:36:25 -0500 Subject: [PATCH] Did some cleanup, moved a utility function to LoneFunctions --- IllusionInjector/PluginManager.cs | 14 +---------- .../Updating/Backup/BackupUnit.cs | 23 +++++++------------ .../Updating/ModsaberML/Updater.cs | 1 - IllusionInjector/Utilities/LoneFunctions.cs | 13 +++++++++++ 4 files changed, 22 insertions(+), 29 deletions(-) diff --git a/IllusionInjector/PluginManager.cs b/IllusionInjector/PluginManager.cs index ee98192e..0868fee6 100644 --- a/IllusionInjector/PluginManager.cs +++ b/IllusionInjector/PluginManager.cs @@ -124,7 +124,7 @@ namespace IllusionInjector Logger.log.Info($"Running on Unity {UnityEngine.Application.unityVersion}"); Logger.log.Info($"Game version {UnityEngine.Application.version}"); Logger.log.Info("-----------------------------"); - Logger.log.Info($"Loading plugins from {GetRelativePath(pluginDirectory, Environment.CurrentDirectory)} and found {_bsPlugins.Count + _ipaPlugins.Count}"); + Logger.log.Info($"Loading plugins from {LoneFunctions.GetRelativePath(pluginDirectory, Environment.CurrentDirectory)} and found {_bsPlugins.Count + _ipaPlugins.Count}"); Logger.log.Info("-----------------------------"); foreach (var plugin in _bsPlugins) { @@ -138,18 +138,6 @@ namespace IllusionInjector Logger.log.Info("-----------------------------"); } - private static string GetRelativePath(string filespec, string folder) - { - Uri pathUri = new Uri(filespec); - // Folders must end in a slash - if (!folder.EndsWith(Path.DirectorySeparatorChar.ToString())) - { - folder += Path.DirectorySeparatorChar; - } - Uri folderUri = new Uri(folder); - return Uri.UnescapeDataString(folderUri.MakeRelativeUri(pathUri).ToString().Replace('/', Path.DirectorySeparatorChar)); - } - private static Tuple, IEnumerable> LoadPluginsFromFile(string file, string exeName) { List bsPlugins = new List(); diff --git a/IllusionInjector/Updating/Backup/BackupUnit.cs b/IllusionInjector/Updating/Backup/BackupUnit.cs index 32f78eff..547540d6 100644 --- a/IllusionInjector/Updating/Backup/BackupUnit.cs +++ b/IllusionInjector/Updating/Backup/BackupUnit.cs @@ -1,4 +1,5 @@ -using System; +using IllusionInjector.Utilities; +using System; using System.Collections.Generic; using System.Collections.Specialized; using System.IO; @@ -16,9 +17,7 @@ namespace IllusionInjector.Updating.Backup private DirectoryInfo _BackupPath; private List _Files = new List(); - - - + public BackupUnit(string backupPath) : this(backupPath, DateTime.Now.ToString("yyyy-MM-dd_h-mm-ss")) { } @@ -58,13 +57,7 @@ namespace IllusionInjector.Updating.Backup /// public void Add(FileInfo file) { - /*if(!file.FullName.StartsWith(_Context.ProjectRoot)) - { - Console.Error.WriteLine("Invalid file path for backup! {0}", file); - return; - }*/ - - var relativePath = new Uri(Environment.CurrentDirectory, UriKind.Absolute).MakeRelativeUri(new Uri(file.FullName)).ToString();//file.FullName.Substring(_Context.ProjectRoot.Length + 1); + var relativePath = LoneFunctions.GetRelativePath(Environment.CurrentDirectory, file.FullName); var backupPath = new FileInfo(Path.Combine(_BackupPath.FullName, relativePath)); if(_Files.Contains(relativePath)) @@ -96,7 +89,7 @@ namespace IllusionInjector.Updating.Backup { foreach(var relativePath in _Files) { - Console.WriteLine("Restoring {0}", relativePath); + //Console.WriteLine("Restoring {0}", relativePath); // Original version var backupFile = new FileInfo(Path.Combine(_BackupPath.FullName, relativePath)); var target = new FileInfo(Path.Combine(Environment.CurrentDirectory, relativePath)); @@ -105,19 +98,19 @@ namespace IllusionInjector.Updating.Backup { if (backupFile.Length > 0) { - Console.WriteLine(" {0} => {1}", backupFile.FullName, target.FullName); + //Console.WriteLine(" {0} => {1}", backupFile.FullName, target.FullName); target.Directory.Create(); backupFile.CopyTo(target.FullName, true); } else { - Console.WriteLine(" x {0}", target.FullName); + //Console.WriteLine(" x {0}", target.FullName); if(target.Exists) { target.Delete(); } } } else { - Console.Error.WriteLine("Backup not found!"); + //Console.Error.WriteLine("Backup not found!"); } } } diff --git a/IllusionInjector/Updating/ModsaberML/Updater.cs b/IllusionInjector/Updating/ModsaberML/Updater.cs index 6982322e..062dafb9 100644 --- a/IllusionInjector/Updating/ModsaberML/Updater.cs +++ b/IllusionInjector/Updating/ModsaberML/Updater.cs @@ -202,7 +202,6 @@ namespace IllusionInjector.Updating.ModsaberML private void ExtractPluginAsync(MemoryStream stream, UpdateStruct item, ApiEndpoint.Mod.PlatformFile fileInfo, string tempDirectory) { Logger.log.Debug($"Extracting ZIP file for {item.plugin.Plugin.Name}"); - //var stream = await httpClient.GetStreamAsync(url); var data = stream.GetBuffer(); SHA1 sha = new SHA1CryptoServiceProvider(); diff --git a/IllusionInjector/Utilities/LoneFunctions.cs b/IllusionInjector/Utilities/LoneFunctions.cs index 1dad987f..3077e13e 100644 --- a/IllusionInjector/Utilities/LoneFunctions.cs +++ b/IllusionInjector/Utilities/LoneFunctions.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -38,5 +39,17 @@ namespace IllusionInjector.Utilities return true; } } + + public static string GetRelativePath(string filespec, string folder) + { + Uri pathUri = new Uri(filespec); + // Folders must end in a slash + if (!folder.EndsWith(Path.DirectorySeparatorChar.ToString())) + { + folder += Path.DirectorySeparatorChar; + } + Uri folderUri = new Uri(folder); + return Uri.UnescapeDataString(folderUri.MakeRelativeUri(pathUri).ToString().Replace('/', Path.DirectorySeparatorChar)); + } } }