|
| 1 | +namespace FileCleaner.Games |
| 2 | +{ |
| 3 | + public class IW6 : Base |
| 4 | + { |
| 5 | + public override string WELCOME_MESSAGE => "COD: Ghosts Cleaner"; |
| 6 | + public override string[] GAME_EXECUTABLES { get; } = { "iw6mp64_ship.exe", "iw6sp64_ship.exe" }; |
| 7 | + |
| 8 | + public override async Task Process() |
| 9 | + { |
| 10 | + RUNNING = true; |
| 11 | + while (RUNNING) |
| 12 | + { |
| 13 | + Helpers.WriteColor(WELCOME_MESSAGE); |
| 14 | + Helpers.WriteColor("[1] Clean Game Files"); |
| 15 | + Helpers.WriteColor("[2] Revert Cleaning"); |
| 16 | + Helpers.WriteColor("[Q] Quit", ConsoleColor.DarkGray); |
| 17 | + |
| 18 | + var choice = Console.ReadLine()?.ToUpperInvariant(); |
| 19 | + |
| 20 | + switch (choice) |
| 21 | + { |
| 22 | + case "1": |
| 23 | + await CleanGameFiles(); |
| 24 | + break; |
| 25 | + case "2": |
| 26 | + await RevertCleaning(); |
| 27 | + break; |
| 28 | + case "Q": |
| 29 | + RUNNING = false; |
| 30 | + break; |
| 31 | + default: |
| 32 | + Helpers.WriteColor("Not a Valid Choice!\n", ConsoleColor.Red); |
| 33 | + break; |
| 34 | + } |
| 35 | + } |
| 36 | + } |
| 37 | + |
| 38 | + private async Task CleanGameFiles() |
| 39 | + { |
| 40 | + if (!File.Exists(COMMON_MP_FASTFILE) || !File.Exists(COMMON_FASTFILE)) |
| 41 | + { |
| 42 | + Helpers.WriteColor("Your game is already clean!\nIf not, make sure you have put the file in the correct game folder.\n", ConsoleColor.Yellow); |
| 43 | + return; |
| 44 | + } |
| 45 | + |
| 46 | + Helpers.EnsureDirectoriesExist([ZONE_FOLDER, |
| 47 | + RAW_FOLDER, |
| 48 | + RAW_VIDEO_FOLDER, |
| 49 | + CLEAN_ZONE_FOLDER, |
| 50 | + CLEAN_RAW_VIDEO_FOLDER]); |
| 51 | + |
| 52 | + var fileTypeMap = new Dictionary<string, string> |
| 53 | + { |
| 54 | + { FASTFILE_EXTENSION, CLEAN_ZONE_FOLDER }, |
| 55 | + { PAK_EXTENSION, CLEAN_ZONE_FOLDER }, |
| 56 | + { SABL_EXTENSION, CLEAN_ZONE_FOLDER }, |
| 57 | + { SABS_EXTENSION, CLEAN_ZONE_FOLDER }, |
| 58 | + { BIK_EXTENSION, CLEAN_RAW_VIDEO_FOLDER } |
| 59 | + }; |
| 60 | + |
| 61 | + foreach (var entry in fileTypeMap) |
| 62 | + { |
| 63 | + string[] files = Directory.GetFiles("./", entry.Key); |
| 64 | + if (files.Length > 0) |
| 65 | + { |
| 66 | + Helpers.MoveFileTo(files, entry.Value); |
| 67 | + } |
| 68 | + } |
| 69 | + |
| 70 | + MoveLanguageFolders(isReverting: false); |
| 71 | + Helpers.WriteColor("Finished Processing Files\n", ConsoleColor.Green); |
| 72 | + } |
| 73 | + |
| 74 | + private void MoveLanguageFolders(bool isReverting) |
| 75 | + { |
| 76 | + var folderMap = new Dictionary<string, string> |
| 77 | + { |
| 78 | + { ENGLISH_FOLDER, ENGLISH_ZONE_FOLDER }, |
| 79 | + { ENGLISH_SAFE_FOLDER, ENGLISH_SAFE_ZONE_FOLDER }, |
| 80 | + { FRENCH_FOLDER, FRENCH_ZONE_FOLDER }, |
| 81 | + { GERMAN_FOLDER, GERMAN_ZONE_FOLDER }, |
| 82 | + { RUSSIAN_FOLDER, RUSSIAN_ZONE_FOLDER }, |
| 83 | + { POLISH_FOLDER, POLISH_ZONE_FOLDER }, |
| 84 | + { JAPAN_FOLDER, JAPAN_ZONE_FOLDER }, |
| 85 | + { KOREAN_FOLDER, KOREAN_ZONE_FOLDER }, |
| 86 | + { PORTUGUESE_FOLDER, PORTUGUESE_ZONE_FOLDER }, |
| 87 | + { SPANISH_FOLDER, SPANISH_ZONE_FOLDER }, |
| 88 | + { ITALIAN_FOLDER, ITALIAN_ZONE_FOLDER }, |
| 89 | + { SCHINA_FOLDER, SCHINA_ZONE_FOLDER }, |
| 90 | + { TCHINA_FOLDER, TCHINA_ZONE_FOLDER } |
| 91 | + }; |
| 92 | + |
| 93 | + foreach (var entry in folderMap) |
| 94 | + { |
| 95 | + try |
| 96 | + { |
| 97 | + if (isReverting) |
| 98 | + { |
| 99 | + Helpers.MoveDirectoryTo(entry.Value, entry.Key); |
| 100 | + string langName = Path.GetFileName(entry.Key); |
| 101 | + string langVideoFolder = Path.Combine(RAW_VIDEO_FOLDER, langName); |
| 102 | + |
| 103 | + Helpers.MoveSpecificFiles(langVideoFolder, entry.Key, "*.bik"); |
| 104 | + Helpers.TryCleanupDirectory(langVideoFolder); |
| 105 | + } |
| 106 | + else |
| 107 | + { |
| 108 | + if (Directory.Exists(entry.Key)) |
| 109 | + { |
| 110 | + string langName = Path.GetFileName(entry.Key); |
| 111 | + string langVideoTarget = Path.Combine(RAW_VIDEO_FOLDER, langName); |
| 112 | + Helpers.MoveSpecificFiles(entry.Key, langVideoTarget, "*.bik"); |
| 113 | + Helpers.MoveDirectoryTo(entry.Key, entry.Value); |
| 114 | + } |
| 115 | + } |
| 116 | + } |
| 117 | + catch (Exception ex) |
| 118 | + { |
| 119 | + Helpers.WriteColor($"Error processing {entry.Key}: {ex.Message}", ConsoleColor.Red); |
| 120 | + } |
| 121 | + } |
| 122 | + } |
| 123 | + |
| 124 | + private async Task RevertCleaning() |
| 125 | + { |
| 126 | + Helpers.WriteColor("Reverting Game Files...", ConsoleColor.Cyan); |
| 127 | + |
| 128 | + string[] sourceFolders = { CLEAN_ZONE_FOLDER, CLEAN_RAW_VIDEO_FOLDER }; |
| 129 | + |
| 130 | + foreach (var folder in sourceFolders) |
| 131 | + { |
| 132 | + if (Directory.Exists(folder)) |
| 133 | + { |
| 134 | + var files = Directory.GetFiles(folder, "*.*"); |
| 135 | + if (files.Length > 0) |
| 136 | + { |
| 137 | + Helpers.MoveFileTo(files, "./"); |
| 138 | + } |
| 139 | + } |
| 140 | + } |
| 141 | + |
| 142 | + MoveLanguageFolders(isReverting: true); |
| 143 | + |
| 144 | + Helpers.TryCleanupDirectory(CLEAN_RAW_VIDEO_FOLDER); |
| 145 | + Helpers.TryCleanupDirectory(RAW_VIDEO_FOLDER); |
| 146 | + Helpers.TryCleanupDirectory(RAW_FOLDER); |
| 147 | + Helpers.TryCleanupDirectory(CLEAN_ZONE_FOLDER); |
| 148 | + Helpers.TryCleanupDirectory(ZONE_FOLDER); |
| 149 | + |
| 150 | + Helpers.WriteColor("Done Reverting Files\n", ConsoleColor.Green); |
| 151 | + } |
| 152 | + } |
| 153 | +} |
0 commit comments