public static void RestoreBackupGameDir(SettingsManager SBBuildSettings) { Debug.LogLine("[SB_Build] Promoting SB_Build Game Directory", Debug.LogLevel.Basic); if (!Directory.Exists(GameDirBackup_Build)) { Debug.LogLine($"[SB_Build] Directory not found: {GameDirBackup_Build}", Debug.LogLevel.Basic); return; } List<string> fileEntryDirs = new List<string>(); foreach (string externalBuildFiles in SBBuildSettings.GetModExternalFiles()) { string fileModPath = Tools.ToWinPath(externalBuildFiles); string sourceFullPath = Path.Combine(GameDir, fileModPath); string sourceDir = Path.GetDirectoryName(sourceFullPath); if (!fileEntryDirs.Contains(sourceDir)) fileEntryDirs.Add(sourceDir); if (File.Exists(sourceFullPath)) File.Delete(sourceFullPath); // deletes all of the new snakebite.xml's managed files else Debug.LogLine(string.Format("[SB_Build] File not found: {0}", sourceFullPath), Debug.LogLevel.Basic); } Tools.DirectoryCopy(GameDirBackup_Build, GameDir, true); // moves all gamedir_backup_build files over foreach (string fileEntryDir in fileEntryDirs) //all the directories that have had files deleted within them { if (Directory.Exists(fileEntryDir) && Directory.GetFiles(fileEntryDir).Length == 0) // if the directory has not yet been deleted and there are no more files inside the directory { Debug.LogLine(String.Format("[SB_Build] deleting empty folder: {0}", fileEntryDir), Debug.LogLevel.All); try { Directory.Delete(fileEntryDir); } catch { Console.WriteLine("[Uninstall] Could not delete: " + fileEntryDir); } } } }
public static void PromoteGameDirFiles() // call this method BEFORE snakebite.xml.SB_Build is promoted, so it will reference the old snakebite.xml { Debug.LogLine("[SB_Build] Promoting SB_Build Game Directory", Debug.LogLevel.Basic); if (!Directory.Exists(GameDirSB_Build)) { Debug.LogLine($"[SB_Build] Directory not found: {GameDirSB_Build}", Debug.LogLevel.Basic); return; } List<string> fileEntryDirs = new List<string>(); foreach (string externalFile in new SettingsManager(SnakeBiteSettings).GetModExternalFiles()) { string fileModPath = Tools.ToWinPath(externalFile); string sourceFullPath = Path.Combine(GameDir, fileModPath); string sourceDir = Path.GetDirectoryName(sourceFullPath); if (!fileEntryDirs.Contains(sourceDir)) fileEntryDirs.Add(sourceDir); if (File.Exists(sourceFullPath)) File.Delete(sourceFullPath); // deletes all of the old snakebite.xml's managed files (unmanaged files will be overwritten later or left alone) else Debug.LogLine(string.Format("[SB_Build] File not found: {0}", sourceFullPath), Debug.LogLevel.Basic); } Tools.DirectoryCopy(GameDirSB_Build, GameDir, true); // moves all gamedir_sb_build files over foreach (string fileEntryDir in fileEntryDirs) { if (Directory.Exists(fileEntryDir) && Directory.GetFiles(fileEntryDir).Length == 0) { Debug.LogLine(String.Format("[SB_Build] deleting empty folder: {0}", fileEntryDir), Debug.LogLevel.All); try { Directory.Delete(fileEntryDir); } catch { Console.WriteLine("[Uninstall] Could not delete: " + fileEntryDir); } } } }