Advertisement
Glurmo

Doom Save Restore AHK

Jul 31st, 2019
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #NoEnv
  2. #Warn
  3. #UseHook on
  4. #SingleInstance force
  5.  
  6. EnvGet, UserProfile, USERPROFILE
  7. global BackupPath := UserProfile . "\Desktop\DoomSaves\Any%"
  8.  
  9. global SteamId := 0
  10. global DoomBasePath := UserProfile . "\Saved Games\id Software\DOOM\base\savegame.user"
  11. Loop, Files, %DoomBasePath%\*, D
  12. {
  13.     SteamId := A_LoopFileName
  14.     break
  15. }
  16. if (SteamId)
  17. {
  18.     global SavePath := DoomBasePath . "\" . SteamId . "\GAME-AUTOSAVE0"
  19. }
  20. else
  21. {
  22.     MsgBox, Unable to find Doom save folder, exiting...
  23.     Exit
  24. }
  25.  
  26. Gui, Font, s14
  27. Gui, Add, DropDownList, Readonly x5 y5 w550 h300 vDebug
  28. Gui, Show, x0 y0 w560 h40, Current Save
  29. LoadSaveList()
  30.  
  31. ; ^Numpad5 = Copy Save
  32. ; ^Numpad7 = Backup Save
  33. ; ^Numpad8 = Previous Save
  34. ; ^Numpad2 = Next Save
  35. ^Numpad5::CopySave()
  36. ^Numpad7::CreateNewSave()
  37. ^Numpad8::MovePosition(-1)
  38. ^Numpad2::MovePosition(1)
  39.  
  40. LoadSaveList()
  41. {
  42.     GuiControl,, Debug, |
  43.     Loop, Files, %BackupPath%\*, D
  44.     {
  45.         GuiControlGet, Debug
  46.         GuiControl,, Debug, %A_LoopFileName%
  47.     }
  48.     MovePosition(1, false)
  49.     Return
  50. }
  51.  
  52. CopySave()
  53. {
  54.     GuiControlGet, SelectedFile, , Debug, text
  55.     SelectedFilePath := BackupPath . "\" . SelectedFile
  56.  
  57.     ; Sanity Checks
  58.     if (InStr(SavePath, "GAME-AUTOSAVE")) and (StrLen(SelectedFile) > 1) and (FileExist(SavePath)) and (FileExist(SelectedFilePath))
  59.     {
  60.         FileDelete, %SavePath%\*.*
  61.         FileCopy, %SelectedFilePath%\*, %SavePath%, 1
  62.     }
  63.     return
  64. }
  65.  
  66. MovePosition(newPos, relative := true)
  67. {
  68.     GuiControl, +AltSubmit, Debug
  69.     GuiControlGet, CurrentPosition, , Debug
  70.     GuiControl, -AltSubmit, Debug
  71.     if (relative)
  72.     {
  73.         newPos := CurrentPosition + newPos
  74.     }
  75.     if (newPos > 0) and (newPos <= SaveCount())
  76.     {
  77.         GuiControl, Choose, Debug, %newPos%
  78.     }
  79. }
  80.  
  81. SaveCount()
  82. {
  83.     count := 0
  84.     Loop, Files, %BackupPath%\*, D
  85.         count++
  86.     return count
  87. }
  88.  
  89. CreateNewSave()
  90. {
  91.     InputBox, name, Enter Save Name
  92.     if ErrorLevel = 0
  93.     {
  94.         nextFolderNumber := SubStr("000" . SaveCount() + 1, -2)
  95.         fullPath := BackupPath . "\" . nextFolderNumber . " - " . name
  96.         FileCreateDir, %fullPath%
  97.         FileCopy, %SavePath%\*, %fullPath%, 1
  98.         LoadSaveList()
  99.         MovePosition(SaveCount(), false)
  100.     }
  101.     return
  102. }
  103.  
  104. GuiClose:
  105. {
  106.     Gui, Destroy
  107.     ExitApp
  108.     Return
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement