Last active
October 4, 2022 02:21
-
-
Save Specnr/f7a5450d932a1277fdcd6c141ad7bf6a to your computer and use it in GitHub Desktop.
Moves worlds of all open Minecrafts to a given directory (Read comment for instructions)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#SingleInstance, Force | |
SendMode Input | |
SetWorkingDir, %A_ScriptDir% | |
; Will move all New World/Speedrun # worlds from all open Minecrafts to oldWorldsFolder | |
global oldWorldsFolder := "C:\MultiInstanceMC\oldWorlds\" ; Old Worlds folder, make it whatever you want | |
IfNotExist, %oldWorldsFolder% | |
FileCreateDir %oldWorldsFolder% | |
; Dont edit | |
global McDirectories := [] | |
global rawPIDs := [] | |
global instances := 0 | |
sleep, 500 | |
RunHide(Command) | |
{ | |
dhw := A_DetectHiddenWindows | |
DetectHiddenWindows, On | |
Run, %ComSpec%,, Hide, cPid | |
WinWait, ahk_pid %cPid% | |
DetectHiddenWindows, %dhw% | |
DllCall("AttachConsole", "uint", cPid) | |
Shell := ComObjCreate("WScript.Shell") | |
Exec := Shell.Exec(Command) | |
Result := Exec.StdOut.ReadAll() | |
DllCall("FreeConsole") | |
Process, Close, %cPid% | |
Return Result | |
} | |
GetMcDir(pid) | |
{ | |
command := Format("powershell.exe $x = Get-WmiObject Win32_Process -Filter \""ProcessId = {1}\""; $x.CommandLine", pid) | |
rawOut := RunHide(command) | |
if (InStr(rawOut, "--gameDir")) { | |
strStart := RegExMatch(rawOut, "P)--gameDir (?:""(.+?)""|([^\s]+))", strLen, 1) | |
return SubStr(rawOut, strStart+10, strLen-10) . "\" | |
} else { | |
strStart := RegExMatch(rawOut, "P)(?:-Djava\.library\.path=(.+?) )|(?:\""-Djava\.library.path=(.+?)\"")", strLen, 1) | |
if (SubStr(rawOut, strStart+20, 1) == "=") { | |
strLen -= 1 | |
strStart += 1 | |
} | |
return StrReplace(SubStr(rawOut, strStart+20, strLen-28) . ".minecraft\", "/", "\") | |
} | |
} | |
GetInstanceTotal() { | |
idx := 1 | |
global rawPIDs | |
WinGet, all, list | |
Loop, %all% | |
{ | |
WinGet, pid, PID, % "ahk_id " all%A_Index% | |
WinGetTitle, title, ahk_pid %pid% | |
if (InStr(title, "Minecraft*")) { | |
rawPIDs[idx] := pid | |
idx += 1 | |
} | |
} | |
return rawPIDs.MaxIndex() | |
} | |
GetAllPIDs() | |
{ | |
global McDirectories | |
global instances := GetInstanceTotal() | |
; Generate mcdir and order PIDs | |
Loop, %instances% { | |
mcdir := GetMcDir(rawPIDs[A_Index]) | |
McDirectories[A_Index] := mcdir | |
} | |
} | |
GetAllPIDs() | |
for i, mcdir in McDirectories { | |
saves := mcdir . "saves\" | |
OutputDebug, Starting instance %i% | |
Loop, Files, %saves%*, D | |
{ | |
If (InStr(A_LoopFileName, "New World") || InStr(A_LoopFileName, "Speedrun #")) { | |
tmp := A_NowUTC | |
FileMoveDir, %saves%%A_LoopFileName%, %saves%%A_LoopFileName%%tmp%Instance %i%, R | |
FileMoveDir, %saves%%A_LoopFileName%%tmp%Instance %i%, %oldWorldsFolder%%A_LoopFileName%%tmp%Instance %i% | |
} | |
} | |
} | |
ComObjCreate("SAPI.SpVoice").Speak("Done") | |
ExitApp |
very cool
If youre feeling like installing python, try this https://gist.github.com/Specnr/8a572ac5c5cfdb54eb0dc7d1eb2906a3 for a faster solution that deletes everything instead of moving things
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
very cool