Skip to content

Commit

Permalink
threads in GUI, fixed level pack, added cache clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
N1ghtTheF0x committed Jan 6, 2025
1 parent bcd46f8 commit 286455e
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 11 deletions.
22 changes: 16 additions & 6 deletions GUI/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,20 +99,30 @@ private Menu CreateContextMenu(Mod mod)
contextmenu.ShowAll();
return contextmenu;
}
private void ApplyModsThread()
{
Sensitive = false;
ModDB.Apply();
Sensitive = true;
//this.ShowMessageBox("Enabled mods have been applied, you can now start the game with mods!");
}
public void ApplyMods()
{
if(ModDB.EnabledMods.Count == 0) return;
Thread thread = new(ApplyModsThread);
thread.Start();
}
private void RevertThread()
{
Sensitive = false;
Utils.JoinThread(ModDB.Apply);
this.ShowMessageBox("Enabled mods have been applied, you can now start the game with mods!");
BackupManager.Revert();
Sensitive = true;
//this.ShowMessageBox("Reverted all the game files back to their orignal!");
}
public void Revert()
{
Sensitive = false;
Utils.JoinThread(BackupManager.Revert);
this.ShowMessageBox("Reverted all the game files back to their orignal!");
Sensitive = true;
Thread thread = new(RevertThread);
thread.Start();
}
public void Launch()
{
Expand Down
9 changes: 5 additions & 4 deletions VelvetBeautifier/Levels/Manager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,16 @@ public static void Apply(Game game)
pack.Add(modpack);
}
pack.Save(tempLevels);
Velvet.Info($"applying levels modifications with {pack.Levels.Count} levels and {pack.Worlds.Entries.Count} to {FILENAME}");
Velvet.Info($"applying levels modifications with {pack.Levels.Count} levels and {pack.Worlds.Entries.Count} entries to {FILENAME}");
string gfs = GetFilePath(game);
RevergePackage levels = RevergePackage.Open(gfs);
levels.Merge(RevergePackage.Create(tempLevels));
RevergePackage newLevels = RevergePackage.Create(temp);
RevergePackage modded = RevergePackage.Merge(levels.Header,levels,newLevels);
if(File.Exists(gfs))
File.Delete(gfs);
using Writer writer = new(gfs);
writer.Write(levels);
writer.Write(modded);
if(Directory.Exists(temp))
Directory.Delete(temp);
Directory.Delete(temp,true);
}
}
2 changes: 2 additions & 0 deletions VelvetBeautifier/ModLoaderTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ private static bool SetupRequired()
}
public static void Init()
{
// clear cache on startup
FileSystem.ClearTempFolders();
// create main directory for storing things
Directory.CreateDirectory(Velvet.AppDataFolder);
Migrate();
Expand Down
13 changes: 12 additions & 1 deletion VelvetBeautifier/Utilities/FileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace ThemModdingHerds.VelvetBeautifier.Utilities;
/// </summary>
public static class FileSystem
{
public const string TEMP_PREFIX = $"{Velvet.ALTNAME}-";
/// <summary>
/// Safe method of getting all the files in <c>folder</c>
/// </summary>
Expand Down Expand Up @@ -63,7 +64,7 @@ public static string CreateTempFile()
/// Create a empty folder in the temporal folder of the Operating System
/// </summary>
/// <returns>A valid folderpath in the temporal folder</returns>
public static string CreateTempFolder() => Directory.CreateTempSubdirectory($"{Velvet.ALTNAME}-").FullName; // very easy as you can see
public static string CreateTempFolder() => Directory.CreateTempSubdirectory(TEMP_PREFIX).FullName; // very easy as you can see
/// <summary>
/// Remove invalid characters from <c>path</c>
/// </summary>
Expand Down Expand Up @@ -91,4 +92,14 @@ public static bool OpenFolder(string folderpath)
Verb = "open"
}) != null;
}
/// <summary>
/// Clears all the temporal folders created
/// </summary>
public static void ClearTempFolders()
{
string tempFolder = Path.GetTempPath();
string[] folders = Directory.GetDirectories(tempFolder,$"{TEMP_PREFIX}*");
foreach(string folder in folders)
Directory.Delete(folder,true);
}
}

0 comments on commit 286455e

Please sign in to comment.