Browse Source

Moved Assembly-CSharp and UnityEngine backup to the loader, updates the backup on game update

piracy-check 3.10.3
Anairkoen Schno 6 years ago
parent
commit
68db01ef97
5 changed files with 144 additions and 3 deletions
  1. +27
    -0
      IPA.Injector/Backups/BackupManager.cs
  2. +104
    -0
      IPA.Injector/Backups/BackupUnit.cs
  3. +2
    -0
      IPA.Injector/IPA.Injector.csproj
  4. +9
    -1
      IPA.Injector/Injector.cs
  5. +2
    -2
      IPA/Program.cs

+ 27
- 0
IPA.Injector/Backups/BackupManager.cs View File

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace IPA.Injector.Backups
{
public class BackupManager
{
public static BackupUnit FindLatestBackup(string dir)
{
new DirectoryInfo(dir).Create();
return new DirectoryInfo(dir)
.GetDirectories()
.OrderByDescending(p => p.Name)
.Select(p => BackupUnit.FromDirectory(p, dir))
.FirstOrDefault();
}
public static bool HasBackup(string dir)
{
return FindLatestBackup(dir) != null;
}
}
}

+ 104
- 0
IPA.Injector/Backups/BackupUnit.cs View File

@ -0,0 +1,104 @@
using IPA.Logging;
using IPA.Utilities;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO;
using System.Linq;
using System.Text;
namespace IPA.Injector.Backups
{
/// <summary>
/// A unit for backup. WIP.
/// </summary>
public class BackupUnit
{
public string Name { get; private set; }
private DirectoryInfo _BackupPath;
private HashSet<string> _Files = new HashSet<string>();
private FileInfo _ManifestFile;
private static string _ManifestFileName = "$manifest$.txt";
public BackupUnit(string dir) : this(dir, DateTime.Now.ToString("yyyy-MM-dd_h-mm-ss"))
{
}
private BackupUnit(string dir, string name)
{
Name = name;
_BackupPath = new DirectoryInfo(Path.Combine(dir, Name));
_ManifestFile = new FileInfo(Path.Combine(_BackupPath.FullName, _ManifestFileName));
}
public static BackupUnit FromDirectory(DirectoryInfo directory, string dir)
{
var unit = new BackupUnit(dir, directory.Name);
// Read Manifest
if (unit._ManifestFile.Exists)
{
string manifest = File.ReadAllText(unit._ManifestFile.FullName);
foreach (var line in manifest.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries))
unit._Files.Add(line);
}
else
{
foreach (var file in directory.GetFiles("*", SearchOption.AllDirectories))
{
if (file.Name == _ManifestFileName) continue;
var relativePath = file.FullName.Substring(directory.FullName.Length + 1);
unit._Files.Add(relativePath);
}
}
return unit;
}
public void Add(string file)
{
Add(new FileInfo(file));
}
internal void Delete()
{
_BackupPath.Delete(true);
}
/// <summary>
/// Adds a file to the list of changed files and backups it.
/// </summary>
/// <param name="path"></param>
public void Add(FileInfo file)
{
var relativePath = LoneFunctions.GetRelativePath(file.FullName, Environment.CurrentDirectory);
var backupPath = new FileInfo(Path.Combine(_BackupPath.FullName, relativePath));
// Copy over
backupPath.Directory.Create();
if (file.Exists)
{
file.CopyTo(backupPath.FullName);
}
else
{
// Make empty file
backupPath.Create().Close();
}
if (!_Files.Contains(relativePath))
{
if (!File.Exists(_ManifestFile.FullName))
_ManifestFile.Create().Close();
var stream = _ManifestFile.AppendText();
stream.WriteLine(relativePath);
stream.Close();
// Add to list
_Files.Add(relativePath);
}
}
}
}

+ 2
- 0
IPA.Injector/IPA.Injector.csproj View File

@ -52,6 +52,8 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Backups\BackupManager.cs" />
<Compile Include="Backups\BackupUnit.cs" />
<Compile Include="Bootstrapper.cs" />
<Compile Include="ConsoleWindow.cs" />
<Compile Include="Injector.cs" />


+ 9
- 1
IPA.Injector/Injector.cs View File

@ -1,4 +1,5 @@
using Harmony;
using IPA.Injector.Backups;
using IPA.Loader;
using IPA.Logging;
using Mono.Cecil;
@ -50,6 +51,12 @@ namespace IPA.Injector
{
var cAsmName = Assembly.GetExecutingAssembly().GetName();
loader.Debug("Finding backup");
var backupPath = Path.Combine(Environment.CurrentDirectory, "IPA","Backups","Beat Saber");
var bkp = BackupManager.FindLatestBackup(backupPath);
if (bkp == null)
loader.Warn("No backup found! Was BSIPA installed using the installer?");
loader.Debug("Ensuring patch on UnityEngine.CoreModule exists");
#region Insert patch into UnityEngine.CoreModule.dll
var unityPath = Path.Combine(Environment.CurrentDirectory, "Beat Saber_Data", "Managed", "UnityEngine.CoreModule.dll");
@ -110,6 +117,7 @@ namespace IPA.Injector
if (modified)
{
bkp?.Add(unityPath);
unityAsmDef.Write(unityPath);
}
#endregion
@ -119,7 +127,7 @@ namespace IPA.Injector
var ascPath = Path.Combine(Environment.CurrentDirectory, "Beat Saber_Data", "Managed", "Assembly-CSharp.dll");
var ascModule = VirtualizedModule.Load(ascPath);
ascModule.Virtualize(cAsmName);
ascModule.Virtualize(cAsmName, () => bkp?.Add(ascPath));
#endregion
}


+ 2
- 2
IPA/Program.cs View File

@ -255,8 +255,8 @@ namespace IPA
backup,
null, false);
backup.Add(context.AssemblyFile);
backup.Add(context.EngineFile);
//backup.Add(context.AssemblyFile);
//backup.Add(context.EngineFile);
}
#region Create Plugin Folder


Loading…
Cancel
Save