Skip to content

Commit ed0bf84

Browse files
committed
Update migrator to remove old BepInEx installs
1 parent f78c0a3 commit ed0bf84

1 file changed

Lines changed: 40 additions & 2 deletions

File tree

SybarisMigrator/SybarisMigrator/Program.cs

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Diagnostics;
34
using System.IO;
45

56
namespace SybarisMigrator
@@ -105,13 +106,23 @@ private static void DoMigrate()
105106
filesToDelete.Add(file);
106107
}
107108

109+
bool deleteBepInExFolder = false;
110+
if (File.Exists("BepInEx/core/BepInEx.dll"))
111+
{
112+
var fileInfo = FileVersionInfo.GetVersionInfo("BepInEx/core/BepInEx.dll");
113+
if (int.Parse(fileInfo.FileVersion.Substring(0, 1)) < 5)
114+
deleteBepInExFolder = true;
115+
fileInfo = null;
116+
GC.Collect();
117+
}
118+
108119
Console.Clear();
109120
WriteLine(ConsoleColor.Green, new string('=', Console.WindowWidth - 2));
110121
WriteLine(ConsoleColor.Green, "Step 2: Moving the files");
111122
WriteLine(ConsoleColor.Green, new string('=', Console.WindowWidth - 2));
112123
Console.WriteLine();
113124

114-
if (filesToDelete.Count == 0)
125+
if (filesToDelete.Count == 0 && !deleteBepInExFolder)
115126
{
116127
Console.WriteLine("No conflicting files found! Your game is clean!");
117128
Console.WriteLine();
@@ -127,6 +138,11 @@ private static void DoMigrate()
127138
Console.WriteLine($"* {s}");
128139
Console.WriteLine();
129140

141+
if (deleteBepInExFolder)
142+
{
143+
Console.WriteLine("The migrator also found an incompatible installation of BepInEx.");
144+
}
145+
130146
Console.Write("Migrator will now move these files to ");
131147
Write(ConsoleColor.Cyan, "sybaris_old");
132148
Console.WriteLine(" folder.");
@@ -160,7 +176,29 @@ private static void DoMigrate()
160176
File.Move(Path.GetFullPath(file), dest);
161177
}
162178

163-
File.WriteAllText("sybaris_migrator.lock", "REMOVE ME IF YOU WANT TO RE-RUN SYBARIS MIGRATOR");
179+
if (deleteBepInExFolder)
180+
{
181+
foreach (string file in Directory.EnumerateFiles("BepInEx", "*", SearchOption.AllDirectories))
182+
{
183+
string dest = Path.GetFullPath(Path.Combine("sybaris_old", file));
184+
Directory.CreateDirectory(Path.GetDirectoryName(dest));
185+
if(File.Exists(dest))
186+
File.Delete(dest);
187+
File.Move(Path.GetFullPath(file), dest);
188+
}
189+
190+
try
191+
{
192+
Directory.Delete(Path.GetFullPath("BepInEx"), true);
193+
}
194+
catch (Exception) { }
195+
196+
try
197+
{
198+
Directory.Delete(Path.GetFullPath("BepInEx"));
199+
}
200+
catch (Exception) { }
201+
}
164202

165203
PrintMigrated();
166204
}

0 commit comments

Comments
 (0)