Advertisement
mgis90

mc_stat_save_lite.ahk [OBSOLETE]

Oct 3rd, 2014
901
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;UPDATE     2016-05-24  this script is now obsolete, as the launcher has fixed these issues. 708 hits
  2. ;I leave, however, the last version below
  3. ;-----------------------------------------------------------------------
  4. ;-----------------------------------------------------------------------
  5. ;                                           2014-10-17
  6. ;mc_stat_save_lite.ahk
  7. ;Minecraft stats and achievements rescuing script by Mgis
  8. ;It saves stats for cracked versions of Minecraft
  9. ;not the fancy version
  10. ;                           updates at      http://pastebin.com/u/mgis90
  11. ;-----------------------------------------------------------------------
  12. #SingleInstance force
  13. #KeyHistory 0  ; Disable keyboard and mouse event history.
  14. ;#Warn  ;enables variable checks, debug mode
  15. GoSub,settings
  16. GoSub,java_check
  17. Loop, % dir_saves . "\*",2,0    ;walk through the dir, retrieve folders only
  18. {
  19.     ;here we get world1 world2 ... folders
  20.     max=0                                           ;max FileTimeModified for the next WorldFolder
  21.     Loop, % A_LoopFileFullPath . "\*.json",0,1      ;only files, recurse
  22.     {
  23.         if (A_LoopFileTimeModified > max)
  24.         {
  25.             max:=A_LoopFileTimeModified
  26.             max_path:=A_LoopFileLongPath
  27.             StringTrimRight,max_folder,max_path, % StrLen(A_LoopFileName)   ;warning! contains last backslash
  28.         }
  29.     }   ;after this we have now the freshest file of this world. we change that filename to nick
  30.     ;if not [ inString of (freshest fileNAME only) there is nick ]
  31.     if NOT (InStr(max_path,nick,false,StrLen(max_folder)))
  32.     {
  33.         FileMove,%max_path%, % max_folder . nick . ".json",1
  34.         worlds_saved+=1
  35.     }   ;cleanup removed in this version
  36. worlds_num:=A_Index
  37. }   ;done world
  38. if not silent
  39. {
  40.     if (worlds_saved=0)
  41.         TrayTip,%ScriptName%,Nothing to save.,5,1
  42.     else
  43.         TrayTip,Saved - %ScriptName%,Saved %worlds_saved% out of %worlds_num% worlds.,3,1
  44.     Sleep 3000
  45. } else Sleep 1000
  46. ExitApp
  47. return  ;autoexec
  48.  
  49. java_check:                 ;protects the script from working and possibly arguing with Minecraft for files
  50. if (WaitForJava=2)
  51. {       ;wait and wake when Minecraft closed, then show a little dialog informing that we save
  52.     Process,WaitClose,javaw.exe     ;wait indefinitely
  53.     if silent
  54.         return
  55.     ;so the user doesnt get the dialog so quickly (missclicks happened to me)
  56.     TrayTip,%ScriptName%,Saving statistics in a few seconds...
  57.     Sleep 2000
  58.     TrayTip
  59.     MsgBox,3,%ScriptName%,Script will save stats for %nick%.
  60.     IfMsgBox,Yes
  61.         return
  62.     else
  63.         ExitApp
  64. } else if (WaitForJava=1) {     ;wait one second, if Minecraft process exists then exit script
  65.     Process,WaitClose,javaw.exe,1
  66.     if ErrorLevel
  67.     {
  68.         MsgBox,48,Java found! - %ScriptName%,Whew! I saved you!`nIt seems that there is an instance of JAVAW.EXE running.`nTo prevent damage the script will exit after this message.`n`nMake sure you close Minecraft before running this script.
  69.         ExitApp
  70.     }
  71. }
  72. return ;java_check
  73.  
  74. settings:
  75. worlds_saved=0
  76. ScriptName=Mc stat save lite
  77. StringTrimRight,file_ini,A_ScriptFullPath, 3
  78. file_ini.="ini"
  79. IniRead,dir_saves,%file_ini%,Settings,dir_saves, % A_AppData . "\.minecraft\saves"
  80. IniRead,nick,%file_ini%,Settings,nick,ERROR
  81. IniRead,AlwaysAskForNick,%file_ini%,Settings,AlwaysAskForNick,0
  82. IniRead,WaitForJava,%file_ini%,Settings,WaitForJava,2
  83. IniRead,silent,%file_ini%,Settings,silent,0
  84. if (nick="ERROR") or (StrLen(nick)<2) or AlwaysAskForNick
  85. {   ;please enter your nick
  86.     InputBox,nick,Your Minecraft nick,Please enter Your Minecraft nick:,,250,120,,,,,Player
  87.     if ErrorLevel   ;dismissed nick input
  88.         ExitApp
  89. }
  90. IfNotExist, %file_ini%
  91. {
  92.     FileAppend,`;Descriptions and default values. Delete this Ini to regenerate it.`n, %file_ini%
  93.     FileAppend,`;-----------------------------------------------------------------------`n, %file_ini%
  94.     FileAppend,`;dir_saves=`%AppData`%\.minecraft\saves`n`;`tThis is the directory of your saves folder. No longer you have to configure this! But you may. Right here. In case you need.`n, %file_ini%
  95.     FileAppend,`;nick=`n`;`tYour Minecraft nickname`n, %file_ini%
  96.     FileAppend,`;AlwaysAskForNick=0`n`;`tfor multi-nickname situations`n, %file_ini%
  97.     FileAppend,`;WaitForJava=2`n`;`tMethod of protection javaw.exe check handling [0-disable check 1-SINGLE CHECK-abort script when java found running 2-wait for java to close and then ask you]`n, %file_ini%
  98.     FileAppend,`;silent=0`n`;`tSaves without asking. Decreases dialogs.`n, %file_ini%
  99.     FileAppend,`;-----------------------------------------------------------------------, %file_ini%
  100.     Sleep 100
  101.     IniWrite, % A_AppData . "\.minecraft\saves",%file_ini%,Settings,dir_saves
  102.     IniWrite,%nick%,%file_ini%,Settings,nick
  103.     IniWrite,%AlwaysAskForNick%,%file_ini%,Settings,AlwaysAskForNick
  104.     IniWrite,%WaitForJava%,%file_ini%,Settings,WaitForJava
  105.     IniWrite,%silent%,%file_ini%,Settings,silent
  106.     MsgBox,,Ini not found - %ScriptName%,Default values restored.,1
  107. }
  108. return  ;settings
  109. ;----- changelog -----      times are in CET/CEST, UTC/GMT +2 hours
  110. /*
  111. 03:47 2014-10-04
  112.     lite version
  113. 22:11 2014-10-17
  114.     disabled #warn
  115. 14:21 2016-05-24
  116.     found out that the launcher fixed these issues
  117. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement