Browse Source

Did some cleanup, moved a utility function to LoneFunctions

refactor
Anairkoen Schno 6 years ago
parent
commit
60fcb7bb62
4 changed files with 22 additions and 29 deletions
  1. +1
    -13
      IllusionInjector/PluginManager.cs
  2. +8
    -15
      IllusionInjector/Updating/Backup/BackupUnit.cs
  3. +0
    -1
      IllusionInjector/Updating/ModsaberML/Updater.cs
  4. +13
    -0
      IllusionInjector/Utilities/LoneFunctions.cs

+ 1
- 13
IllusionInjector/PluginManager.cs View File

@ -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<BSPluginMeta>, IEnumerable<IPlugin>> LoadPluginsFromFile(string file, string exeName)
{
List<BSPluginMeta> bsPlugins = new List<BSPluginMeta>();


+ 8
- 15
IllusionInjector/Updating/Backup/BackupUnit.cs View File

@ -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<string> _Files = new List<string>();
public BackupUnit(string backupPath) : this(backupPath, DateTime.Now.ToString("yyyy-MM-dd_h-mm-ss"))
{
}
@ -58,13 +57,7 @@ namespace IllusionInjector.Updating.Backup
/// <param name="path"></param>
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!");
}
}
}


+ 0
- 1
IllusionInjector/Updating/ModsaberML/Updater.cs View File

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


+ 13
- 0
IllusionInjector/Utilities/LoneFunctions.cs View File

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

Loading…
Cancel
Save