|
| 1 | +#SingleInstance Force |
| 2 | +#Warn |
| 3 | +#NoEnv |
| 4 | +SetWorkingDir %A_ScriptDir% |
| 5 | +ListLines Off |
| 6 | +DetectHiddenWindows, Off |
| 7 | +DetectHiddenText, Off |
| 8 | + |
| 9 | +;----------------- Paths ----------------- |
| 10 | +EnvGet, OneDriveDir, OneDrive |
| 11 | +if (!OneDriveDir) |
| 12 | + OneDriveDir := A_ScriptDir ; fallback if OneDrive not set |
| 13 | + |
| 14 | +BaseDir := OneDriveDir "\Backup\Game\Emul\Citra\nightly-mingw" |
| 15 | +ModRoot := BaseDir "\Mods" |
| 16 | +ModTarget := BaseDir "\user\load\mods" |
| 17 | +ConfigFile := BaseDir "\user\config\qt-config.ini" |
| 18 | +DestCsv := A_ScriptDir "\Destination.csv" |
| 19 | + |
| 20 | +;----------------- Data ----------------- |
| 21 | +global DestMap := {} |
| 22 | +global Mods := [] ; each: {game, mod, title, src} |
| 23 | + |
| 24 | +LoadDestinations(){ |
| 25 | + global DestMap, DestCsv |
| 26 | + DestMap := {} |
| 27 | + if !FileExist(DestCsv) |
| 28 | + return |
| 29 | + Loop, Read, %DestCsv% |
| 30 | + { |
| 31 | + line := Trim(A_LoopReadLine) |
| 32 | + if (line = "" || !InStr(line, ",")) |
| 33 | + continue |
| 34 | + StringSplit, p, line, `, |
| 35 | + g := Trim(p1), t := Trim(p2) |
| 36 | + if (g != "" && t != "") |
| 37 | + DestMap[g] := t |
| 38 | + } |
| 39 | +} |
| 40 | + |
| 41 | +ScanMods(){ |
| 42 | + global Mods, ModRoot, DestMap |
| 43 | + Mods := [] |
| 44 | + if !FileExist(ModRoot) |
| 45 | + return |
| 46 | + Loop, Files, %ModRoot%\*.*, D |
| 47 | + { |
| 48 | + game := A_LoopFileName |
| 49 | + title := DestMap.HasKey(game) ? DestMap[game] : "" |
| 50 | + Loop, Files, %A_LoopFileFullPath%\*.*, D |
| 51 | + Mods.Push({game: game, mod: A_LoopFileName, title: title, src: A_LoopFileFullPath}) |
| 52 | + } |
| 53 | +} |
| 54 | + |
| 55 | +;----------------- Config Helpers ----------------- |
| 56 | +RegExEscape(str){ |
| 57 | + static specials := "()[]{}?*+|^$.\" |
| 58 | + out := "" |
| 59 | + Loop, Parse, str |
| 60 | + out .= InStr(specials, A_LoopField) ? "\" A_LoopField : A_LoopField |
| 61 | + return out |
| 62 | +} |
| 63 | + |
| 64 | +SetKey(content, key, value){ |
| 65 | + pat := "m)^(" . RegExEscape(key) . ")\s*=.*$" |
| 66 | + if (RegExMatch(content, pat)) |
| 67 | + return RegExReplace(content, pat, "$1=" value, , 1) |
| 68 | + else |
| 69 | + return content "`n" key "=" value |
| 70 | +} |
| 71 | + |
| 72 | +LoadConfig(){ |
| 73 | + global ConfigFile |
| 74 | + cfg := "" |
| 75 | + if FileExist(ConfigFile) |
| 76 | + FileRead, cfg, %ConfigFile% |
| 77 | + return cfg |
| 78 | +} |
| 79 | + |
| 80 | +SaveConfig(cfg){ |
| 81 | + global ConfigFile |
| 82 | + if FileExist(ConfigFile) |
| 83 | + FileCopy, %ConfigFile%, %ConfigFile%.bak, 1 |
| 84 | + f := FileOpen(ConfigFile, "w") |
| 85 | + if (!IsObject(f)) |
| 86 | + return false |
| 87 | + f.Write(cfg) |
| 88 | + f.Close() |
| 89 | + return true |
| 90 | +} |
| 91 | + |
| 92 | +ApplyPreset(game){ |
| 93 | + cfg := LoadConfig() |
| 94 | + if (cfg = "") |
| 95 | + return "Config missing" |
| 96 | + |
| 97 | + norm := NormKey(game) |
| 98 | + ; defaults |
| 99 | + cfg := SetKey(cfg, "resolution_factor", "10") |
| 100 | + cfg := SetKey(cfg, "texture_filter_name", "xBRZ freescale") |
| 101 | + cfg := SetKey(cfg, "texture_filter_name\\default", "false") |
| 102 | + cfg := SetKey(cfg, "pp_shader_name", "Bump_Mapping_AA_optimize") |
| 103 | + cfg := SetKey(cfg, "pp_shader_name\\default", "false") |
| 104 | + cfg := SetKey(cfg, "preload_textures\\default", "false") |
| 105 | + cfg := SetKey(cfg, "preload_textures", "true") |
| 106 | + cfg := SetKey(cfg, "cpu_clock_percentage", "125") |
| 107 | + cfg := SetKey(cfg, "layout_option", "2") |
| 108 | + |
| 109 | + if (norm = "3d_land"){ |
| 110 | + cfg := SetKey(cfg, "resolution_factor", "8") |
| 111 | + cfg := SetKey(cfg, "texture_filter_name", "none") |
| 112 | + cfg := SetKey(cfg, "texture_filter_name\\default", "true") |
| 113 | + cfg := SetKey(cfg, "pp_shader_name", "none (builtin)") |
| 114 | + cfg := SetKey(cfg, "pp_shader_name\\default", "false") |
| 115 | + cfg := SetKey(cfg, "preload_textures", "false") |
| 116 | + cfg := SetKey(cfg, "preload_textures\\default", "true") |
| 117 | + } else if (norm = "hd_texture_pack"){ |
| 118 | + cfg := SetKey(cfg, "resolution_factor", "4") |
| 119 | + cfg := SetKey(cfg, "texture_filter_name", "none") |
| 120 | + cfg := SetKey(cfg, "texture_filter_name\\default", "true") |
| 121 | + cfg := SetKey(cfg, "pp_shader_name", "none (builtin)") |
| 122 | + cfg := SetKey(cfg, "pp_shader_name\\default", "false") |
| 123 | + cfg := SetKey(cfg, "preload_textures", "false") |
| 124 | + cfg := SetKey(cfg, "preload_textures\\default", "true") |
| 125 | + } else if (norm = "luigi_s_mansion_2"){ |
| 126 | + cfg := SetKey(cfg, "resolution_factor", "6") |
| 127 | + cfg := SetKey(cfg, "cpu_clock_percentage", "25") |
| 128 | + } else if (norm = "mario_kart_7"){ |
| 129 | + cfg := SetKey(cfg, "resolution_factor", "5") |
| 130 | + cfg := SetKey(cfg, "texture_filter_name", "none") |
| 131 | + cfg := SetKey(cfg, "texture_filter_name\\default", "true") |
| 132 | + cfg := SetKey(cfg, "preload_textures", "false") |
| 133 | + cfg := SetKey(cfg, "preload_textures\\default", "true") |
| 134 | + } else if (norm = "mario_luigi_bowser_s_inside_story"){ |
| 135 | + cfg := SetKey(cfg, "layout_option", "0") |
| 136 | + cfg := SetKey(cfg, "texture_filter_name", "none") |
| 137 | + cfg := SetKey(cfg, "texture_filter_name\\default", "true") |
| 138 | + cfg := SetKey(cfg, "pp_shader_name", "none (builtin)") |
| 139 | + cfg := SetKey(cfg, "pp_shader_name\\default", "false") |
| 140 | + cfg := SetKey(cfg, "preload_textures", "false") |
| 141 | + cfg := SetKey(cfg, "preload_textures\\default", "true") |
| 142 | + } else if (norm = "mario_luigi"){ |
| 143 | + cfg := SetKey(cfg, "layout_option", "0") |
| 144 | + } else if (norm = "no_preloading"){ |
| 145 | + cfg := SetKey(cfg, "preload_textures", "false") |
| 146 | + cfg := SetKey(cfg, "preload_textures\\default", "true") |
| 147 | + } else if (norm = "nsmb2"){ |
| 148 | + cfg := SetKey(cfg, "resolution_factor", "10") |
| 149 | + cfg := SetKey(cfg, "texture_filter_name", "none") |
| 150 | + cfg := SetKey(cfg, "texture_filter_name\\default", "true") |
| 151 | + cfg := SetKey(cfg, "pp_shader_name", "none (builtin)") |
| 152 | + cfg := SetKey(cfg, "pp_shader_name\\default", "false") |
| 153 | + cfg := SetKey(cfg, "preload_textures", "false") |
| 154 | + cfg := SetKey(cfg, "preload_textures\\default", "true") |
| 155 | + } |
| 156 | + |
| 157 | + if (!SaveConfig(cfg)) |
| 158 | + return "Failed to write config" |
| 159 | + return "" |
| 160 | +} |
| 161 | + |
| 162 | +NormKey(k){ |
| 163 | + StringLower, k, k |
| 164 | + StringReplace, k, k, %A_Space%, _, All |
| 165 | + StringReplace, k, k, -, _, All |
| 166 | + StringReplace, k, k, ', , All |
| 167 | + return k |
| 168 | +} |
| 169 | + |
| 170 | +;----------------- Mod Copy ----------------- |
| 171 | +CopyMod(idx){ |
| 172 | + global Mods, ModTarget |
| 173 | + if (idx < 1 || idx > Mods.Length()) |
| 174 | + return "Select a mod" |
| 175 | + m := Mods[idx] |
| 176 | + if (m.title = "") |
| 177 | + return "Destination.csv missing title for " m.game |
| 178 | + |
| 179 | + target := ModTarget "\" m.title "\" m.mod |
| 180 | + src := m.src |
| 181 | + |
| 182 | + ; ensure target parent exists |
| 183 | + SplitPath, target, , tgtDir |
| 184 | + FileCreateDir, %tgtDir% |
| 185 | + |
| 186 | + ; check emptiness of target parent dir |
| 187 | + vCount := 0 |
| 188 | + Loop, Files, %tgtDir%\*, DF |
| 189 | + vCount++ |
| 190 | + if (vCount) |
| 191 | + return "Dir has " vCount " item(s). Can't copy" |
| 192 | + |
| 193 | + FileCopyDir, %src%, %target%, 1 |
| 194 | + if (ErrorLevel) |
| 195 | + return "Copy failed" |
| 196 | + return "" |
| 197 | +} |
| 198 | + |
| 199 | +;----------------- GUI ----------------- |
| 200 | +Gui, New, -MinimizeBox, Citra 3DS Manager |
| 201 | +Gui, Add, Text, xm ym, Base: %BaseDir% |
| 202 | +Gui, Add, ListView, xm w700 h280 vLVMods gOnPick AltSubmit, Game|Mod|TitleID|Source |
| 203 | +Gui, Add, Button, xm w100 gDoMod, Apply Mod |
| 204 | +Gui, Add, Button, x+10 w110 gDoConfig, Apply Config |
| 205 | +Gui, Add, Button, x+10 w110 gDoBoth, Apply Both |
| 206 | +Gui, Add, Button, x+10 w80 gDoRefresh, Refresh |
| 207 | +Gui, Add, Button, x+10 w120 gOpenSrc, Open Mods |
| 208 | +Gui, Add, Button, x+10 w130 gOpenDst, Open Target |
| 209 | +Gui, Show, , Citra 3DS Manager |
| 210 | + |
| 211 | +ReloadData(){ |
| 212 | + global Mods |
| 213 | + LV_Delete() |
| 214 | + LoadDestinations() |
| 215 | + ScanMods() |
| 216 | + For idx, m in Mods |
| 217 | + LV_Add("", m.game, m.mod, m.title, m.src) |
| 218 | + LV_ModifyCol() |
| 219 | +} |
| 220 | +ReloadData() |
| 221 | + |
| 222 | +OnPick: |
| 223 | +return |
| 224 | + |
| 225 | +DoRefresh: |
| 226 | + ReloadData() |
| 227 | +return |
| 228 | + |
| 229 | +DoMod: |
| 230 | + Row := LV_GetNext() |
| 231 | + msg := CopyMod(Row) |
| 232 | + MsgBox % (msg="") ? "Mod copied." : msg |
| 233 | +return |
| 234 | + |
| 235 | +DoConfig: |
| 236 | + Row := LV_GetNext() |
| 237 | + if (!Row){ |
| 238 | + MsgBox Select a row first. |
| 239 | + return |
| 240 | + } |
| 241 | + LV_GetText(g, Row, 1) |
| 242 | + msg := ApplyPreset(g) |
| 243 | + MsgBox % (msg="") ? "Config applied." : msg |
| 244 | +return |
| 245 | + |
| 246 | +DoBoth: |
| 247 | + Row := LV_GetNext() |
| 248 | + if (!Row){ |
| 249 | + MsgBox Select a row first. |
| 250 | + return |
| 251 | + } |
| 252 | + LV_GetText(g, Row, 1) |
| 253 | + msg := CopyMod(Row) |
| 254 | + if (msg=""){ |
| 255 | + msg := ApplyPreset(g) |
| 256 | + if (msg="") |
| 257 | + MsgBox Done: Mod + Config applied. |
| 258 | + else |
| 259 | + MsgBox Mod copied, but config error: %msg% |
| 260 | + } else { |
| 261 | + MsgBox %msg% |
| 262 | + } |
| 263 | +return |
| 264 | + |
| 265 | +OpenSrc: |
| 266 | + Run, %ModRoot% |
| 267 | +return |
| 268 | + |
| 269 | +OpenDst: |
| 270 | + Run, %ModTarget% |
| 271 | +return |
| 272 | + |
| 273 | +GuiClose: |
| 274 | +GuiEscape: |
| 275 | +ExitApp |
0 commit comments