Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;UPDATE 2016-05-24 this script is now obsolete, as the launcher has fixed these issues. 1303 hits
- ;I leave, however, the last version below
- ;-----------------------------------------------------------------------
- ;-----------------------------------------------------------------------
- ; 2014-10-17
- ;mc_stat_save.ahk
- ;Minecraft stats and achievements rescuing script by Mgis
- ;It saves stats for cracked versions of Minecraft
- ;[longer description near the end of the file]
- ; updates at http://pastebin.com/u/mgis90
- ;--- Screenshot --- (both the same)
- ;http://imgur.com/4AFvhtN
- ;http://pl.tinypic.com/r/2mgupty/8
- ;--- Video ---
- ;http://youtu.be/LxVBwUBYKK0
- ;-----------------------------------------------------------------------
- ;thanks for the solution suggested by HiArashi on 2014-08-24 00:33 (at tpb)
- ;and @Antaishi asked that question bothering me!
- ;[AutoHotkey Version v1.1.13.00 but on older may work anyways]
- ;for "TryAgain" [v1.0.44.08+]
- ;-----------------------------------------------------------------------
- #SingleInstance force
- #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases they said.
- #LTrim ; Allows continuation sections to be indented. Positional. May be turned off via #LTrim Off
- #KeyHistory 0 ; Disable keyboard and mouse event history.
- ;#Warn ;debug mode, not needed for typical user
- GoSub,settings
- GoSub,TrayIcon ;it will exit itself regarding to settings
- GoSub,java_check
- ;save the stats
- worlds_saved=0
- Loop, % dir_saves . "\*",2,0 ;walk through the dir, retrieve folders only
- {
- ;here we get world1 world2 ... folders
- worlds_num:=A_Index
- filelist:=Object() ;list of all stat json files PER WORLD
- max=0 ;max FileTimeModified for the next WorldFolder
- Loop, % A_LoopFileFullPath . "\*.json",0,1 ;only files, recurse
- {
- if not InStr(A_LoopFileName,nick) ;do not list files already named with correct nickname
- filelist.Insert(A_LoopFileLongPath)
- if (A_LoopFileTimeModified > max)
- {
- max:=A_LoopFileTimeModified
- max_path:=A_LoopFileLongPath
- StringTrimRight,max_folder,max_path, % StrLen(A_LoopFileName) ;warning! contains last backslash
- }
- } ;after this we have now the freshest file of this world
- ;we change the freshest filename to nick
- ;if filelist contains >=1 entries AND inString of (freshest fileNAME only) there is NO nick
- if (filelist.MaxIndex()>=1) AND ( NOT InStr(max_path,nick,false,StrLen(max_folder)))
- {
- if dbg
- Msgbox,,Moving - %ScriptName%, % "Moving file:`n" . max_path . "`nto`n" . max_folder . nick . ".json"
- FileMove,%max_path%, % max_folder . nick . ".json",1
- worlds_saved+=1
- } else { ;there is less than one file OR freshest filename contains nick (that means its ok)
- if dbg
- MsgBox,64,Skipping World - %ScriptName%,Skipping World:`n%A_LoopFileName%`nbecause it seems to not have been played recently
- Continue ;we really skip the rest of this worlds loop
- }
- if (cleanup_recycle>0)
- { ;we remove other old files
- if (cleanup_recycle=2)
- {
- if dbg
- MsgBox,64,Cleanup - %ScriptName%, % "Deleting " . (filelist.MaxIndex()-1) . " files."
- for k, v in filelist
- FileDelete,%v%
- }
- else if (cleanup_recycle=1)
- {
- if dbg
- MsgBox,64,Cleanup - %ScriptName%, % "Recycling " . (filelist.MaxIndex()-1) . " files."
- for k, v in filelist
- FileRecycle,%v%
- }
- }
- if dbg
- MsgBox,64,World stats saved - %ScriptName%,World finished:`n%A_LoopFileName%,4
- } ;done world
- if (worlds_saved=0)
- TrayTip,%ScriptName%,Nothing to save.,5,1
- else
- TrayTip,Saved - %ScriptName%,Saved %worlds_saved% out of %worlds_num% worlds.,3,1
- Sleep 3000
- if dbg
- MsgBox,64,Saved,All worlds finished! Bye!,2
- ExitApp
- return ;autoexec
- java_check:
- ;protects the script from working and possibly arguing with Minecraft for files
- if (WaitForJava=2)
- {
- ;wait and wake when Minecraft closed, then show a little dialog informing that we save
- Process,WaitClose,javaw.exe ;wait indefinitely
- if silent
- return
- ;so the user doesnt get the dialog so quickly (missclicks happened to me)
- TrayTip,%ScriptName%,Saving statistics in a few seconds...
- Loop, 15
- {
- ToolTip, % (16-A_Index)
- Sleep 200 ;total sleep =3000
- }
- TrayTip
- ToolTip
- SetTimer, ChangeButtonNames,50
- ;msgbox cancel/try again/continue + 3rd button default
- MsgBox,518,Mc stat save,Script will save stats for %nick%.,6 ;window title here must be unchanged!
- IfMsgBox,Timeout
- return
- IfMsgBox,Continue
- return
- else
- IfMsgBox,TryAgain
- {
- Sleep 180000 ;wait 180 seconds
- Reload
- }
- else ;(Cancel,closing) ;escape or closing the window is the same as pressing cancel
- ExitApp
- } else if (WaitForJava=1) {
- ;wait one second, if Minecraft process exists then exit script
- Process,WaitClose,javaw.exe,1
- if ErrorLevel
- {
- 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.
- ExitApp
- }
- }
- return ;java_check
- ChangeButtonNames:
- IfWinExist,Mc stat save
- {
- WinActivate,Mc stat save
- ControlSetText, Button1,&Exit
- ControlSetText, Button2,&Wait 3min
- ControlSetText, Button3,&Save now
- SetTimer, ChangeButtonNames, off
- }
- return
- TrayIcon:
- if not trayicon_change
- return
- StringTrimRight,iconpath,A_ScriptFullPath,3
- iconpath.="ico"
- if trayicon_download ;retrieve it
- {
- if not FileExist(iconpath) ;download only if it does not exist
- {
- ;ask user first, 35= 32->?icon + 3->yes/no/cancel
- MsgBox,35,Download icon - %ScriptName%,Do you want to download tray icon from:`n%trayicon_source%`n`n(you may disable this in settings, just edit the line with "trayicon_download=1")
- IfMsgBox,Yes
- {
- MsgBox,,,Ok. Will download now.,5
- UrlDownloadToFile,%trayicon_source%,%iconpath%
- if ErrorLevel
- MsgBox,48,,There was an error while downloading the icon.`n%ErrorLevel%
- else
- {
- FileGetSize,iconsize,%iconpath%
- if (iconsize=trayicon_size)
- MsgBox,64,Finished downloading - %ScriptName%,Downloaded file size:`n%iconsize% = %trayicon_size%,5
- else
- MsgBox,64,Finished downloading - %ScriptName%,Downloaded file size: %iconsize%`nSuggested file size: %trayicon_size%
- }
- }
- IfMsgBox,No
- {
- MsgBox,36,%ScriptName%,Do you want to edit configuration?
- IfMsgBox,Yes
- Edit
- }
- } ;else does exist
- } ;else do not retrieve
- if FileExist(iconpath)
- Menu,Tray,Icon,%iconpath%
- return ;TrayIcon
- settings:
- if A_AhkVersion < 1.1.0.0
- {
- MsgBox,% 16+3+256,You have old ahk!,You have old AutoHotkey!`nYou need to have Ahk_L for this script to work properly.`nPlease visit ahkscript.org`n`nOpen website now?,10
- IfMsgBox,Yes
- Run,www.ahkscript.org
- }
- ScriptName=Mc stat save
- StringTrimRight,file_ini,A_ScriptFullPath, 3
- file_ini.="ini"
- IniRead,dir_saves,%file_ini%,Settings,dir_saves, % A_AppData . "\.minecraft\saves"
- IniRead,nick,%file_ini%,Settings,nick,ERROR
- IniRead,AlwaysAskForNick,%file_ini%,Settings,AlwaysAskForNick,0
- IniRead,cleanup_recycle,%file_ini%,Settings,cleanup_recycle,0
- IniRead,WaitForJava,%file_ini%,Settings,WaitForJava,2
- IniRead,silent,%file_ini%,Settings,silent,0
- IniRead,dbg,%file_ini%,Settings,dbg,0
- IniRead,trayicon_change,%file_ini%,Settings,trayicon_change,1
- IniRead,trayicon_download,%file_ini%,Settings,trayicon_download,0
- IniRead,trayicon_source,%file_ini%,Settings,trayicon_source,%A_Space%
- IniRead,trayicon_size,%file_ini%,Settings,trayicon_size,%A_Space%
- if (nick="ERROR") or (StrLen(nick)<2) or AlwaysAskForNick
- {
- ;please enter your nick
- ;InputBox, OutputVar [, Title, Prompt, HIDE, Width, Height, X, Y, Font, Timeout, Default]
- InputBox,nick,Your Minecraft nick,Please enter Your Minecraft nick:,,250,120,,,,,Player
- if ErrorLevel ;dismissed nick input
- ExitApp
- }
- IfNotExist, %file_ini%
- {
- ;FileAppend,`;`n, %file_ini%
- FileAppend,`;Descriptions and default values. Delete this Ini to regenerate it.`n, %file_ini%
- FileAppend,`;-----------------------------------------------------------------------`n, %file_ini%
- FileAppend,`;dir_saves=`%AppData`%\.minecraft\saves`n`;`tThis is the directory of your saves folder. No longer you have to configure this! (It will set itself) But you may. Right here. In case you need.`n, %file_ini%
- FileAppend,`;nick=`n`;`tYour Minecraft nickname [text string]`n, %file_ini%
- FileAppend,`;AlwaysAskForNick=0`n`;`tfor multi-nickname situations [0/1]`n, %file_ini%
- FileAppend,`;cleanup_recycle=1`n`;`tAffect other json files beyond the freshest? What to do with files? [0-dont do cleanup 1-recycles 2-deletes]`n, %file_ini%
- 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%
- FileAppend,`;silent=0`n`;`tSaves without asking. Decreases dialogs. [0/1]`n, %file_ini%
- FileAppend,`;dbg=0`n`;`tdebug mode (displays more dialogs you may use it to get familiar with the script)`n, %file_ini%
- FileAppend,`;-----------------------------------------------------------------------`n, %file_ini%
- FileAppend,`;trayicon_change=true`n`;`tchange the tray icon to more minecrafty one? (only if it exists. you may use any icon you want)`n, %file_ini%
- FileAppend,`;uncomment these three lines to download tray icon (and place them under settings, at end of this file) I TAKE NO RESPONSIBILITY FOR ANYTHING (but it works nice for me)`n, %file_ini%
- FileAppend,`;trayicon_download=true`t`;download the tray icon? (will save as ScriptName.ico in the directory of the script) this is DISABLED by default so it does not download anything`n, %file_ini%
- FileAppend,`;trayicon_source=http://www.iconarchive.com/download/i78543/chrisl21/minecraft/Chest.ico`n, %file_ini%
- FileAppend,`;trayicon_size=233286`t`;this is only indicative size`n, %file_ini%
- FileAppend,`;-----------------------------------------------------------------------, %file_ini%
- Sleep 100
- IniWrite, % A_AppData . "\.minecraft\saves",%file_ini%,Settings,dir_saves
- IniWrite,%nick%,%file_ini%,Settings,nick
- IniWrite,%AlwaysAskForNick%,%file_ini%,Settings,AlwaysAskForNick
- Iniwrite,%cleanup_recycle%,%file_ini%,Settings,cleanup_recycle
- IniWrite,%WaitForJava%,%file_ini%,Settings,WaitForJava
- IniWrite,%silent%,%file_ini%,Settings,silent
- IniWrite,%dbg%,%file_ini%,Settings,dbg
- IniWrite,%trayicon_change%,%file_ini%,Settings,trayicon_change
- IniWrite,%trayicon_download%,%file_ini%,Settings,trayicon_download
- IniWrite,%A_Space%,%file_ini%,Settings,trayicon_source
- IniWrite,%A_Space%,%file_ini%,Settings,trayicon_size
- MsgBox,3,Ini not found - %ScriptName%,Default values restored. Script will exit. You can launch me again.`n`nDo you want to edit settings now?
- IfMsgBox,Yes
- Run,%file_ini%
- ExitApp
- }
- Menu,Tray,NoStandard
- Menu,Tray,Add,Edit settings,edit_ini
- Menu,Tray,Add
- Menu,Tray,Standard
- return ;settings
- edit_ini:
- Run,*edit "%file_ini%"
- return ;edit_ini
- /*
- HiArashi on 2014-08-24 00:33 CET:
- @Antaishi and everyone else who experience lost achievements and stats problem.
- After you quit the game go to .minecraftsaves[your_world_name]stats and change the name of
- the file you see there (or the most recent file if you have many of those) to the nick, that you use.
- Unfortunately, you have to do it every time you quit the game.
- */
- /* --- longer description ---
- After you play in a World, the freshest file in stats folder (the one
- you just played, or are still playing) becomes some kind of long ID number [UUID?],
- like this: \stats\0fa4e30e-80a8-43b4-8186-270f8af78b03.json
- What this script does: it renames that file to Nick.json
- And that file is found by Minecraft the next time you load that World
- (it says downloading stats ooooOoo)
- Unfortunately this may be only some kind of backward-compatibility of Mc
- NOTE: we assume that in \saves\ and its subfolders (worlds) there are no other json files other than stat files in \world\stats\123.json
- */
- ;---------------------
- ;----- changelog -----
- ;---------------------
- ;times are in CET/CEST, UTC/GMT +2 hours
- /*
- 15:56 2014-10-01
- fixed deletion of stats of a world which wasnt played in a mc session
- added overwrite flag when moving stats
- 23:26 2014-10-01
- note: multi-user players don't have support. Guess they can play on one profile in launcher. I may add a question to select Nickname when script starts. I had this around here... somewhere. Blast that little! Where did she get to?
- reenabled changing button names in dialog
- changed all settings to use true/false instead of 1/0 style
- removed old unused code
- changed stuff
- linked to pastebin
- added minecrafty tray icon support!
- 13:17 2014-10-03
- done todo: add some checks that will protect unplayed worlds from getting "Rename Mgis.json --> Mgis.json" because it is an unneeded FileSystem operation!
- it will increase script size but it should be done
- 16:26 2014-10-03
- oh no my cat came to me and stepped on Insert and Backspace keys. Luckily I had it saved.
- added skipping world (checking if Mgis.json is the only filename, and if the freshest filename contains Mgis)
- changed one var name to WaitForJava
- 01:11 2014-10-04
- moved configuration to Ini
- added WaitForJava=0 which now skips the check entirely
- changed dialogs, added timeout to the save dialog
- added AlwaysAskForNick (see note above at 2014-10-01)
- added world save summary (num/saved)
- added silent mode setting
- 2014-10-04
- uploaded a video! http://youtu.be/LxVBwUBYKK0
- 2014-10-13
- disabled warn debug mode
- added check for version in settings, added run website
- 2014-10-15
- added edit settings to tray menu
- 22:15 2014-10-17
- changed conditions of skipping world
- 14:21 2016-05-24
- found out that the launcher fixed these issues
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement