Advertisement
BizzKeryear

grab_system_data.ahk

Dec 26th, 2014
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;Copyright by BiZZ Keryear under CC by-sa 3.0 http://creativecommons.org/licenses/by-sa/3.0/
  2. ;BiZZ Keryear aka MrMegaPussyPlayer
  3. ;each copy must contain these three credits lines
  4. if A_AhkVersion < 1.1.16.05
  5. {
  6.     msgbox ,16,! ! ! ! ! ! ! ! ! Error: Wrong Version of AHK ! ! ! ! ! ! ! ! !, You are using an outdated version of AHK!`n`n`nPlease grab the correct one:`t`tv1.1.16.05 (or later but before 2.x)`n`n`tfrom:`thttp://ahkscript.org/download/`n`nScript will exit after you click ok.
  7.     ExitApp
  8. }
  9. else if A_AhkVersion => 2.
  10. {
  11.     msgbox ,16,! ! ! ! ! ! ! ! ! Error: Wrong Version of AHK ! ! ! ! ! ! ! ! !, You are using a wrong version of AHK!`nThis script is not compatible with the experimental 2.x or later`n`nPlease grab the correct one:`t`tv1.1.16.05 (or later but before 2.x)`n`n`tfrom:`thttp://ahkscript.org/download/`n`nScript will exit after you click ok.
  12.     ExitApp
  13. }
  14. defaultBasePath = %USERPROFILE%\AppData\Local\Frontier_Developments\Products\FORC-FDEV-D-1002
  15. defaultLogpath = %defaultBasePath%\Logs
  16. #SingleInstance force
  17. DetectHiddenWindows , On
  18. Menu, TRAY, Tip , Elite Dangerous System Data Grabber V1
  19. Menu, TRAY, NoStandard
  20. Menu, TRAY, Add , Exit Script , ExitSub
  21. Menu, TRAY, Add , Reload Script , ReloadSub
  22. Menu, TRAY, Add
  23. Menu, TRAY, Add , Test ED Settings, testini
  24. Menu, TRAY, Add
  25. Menu, TRAY, Add , Change Settings, SettingsGui
  26. Menu, TRAY, Add
  27. Menu, TRAY, Add , Grab System, GrabSystem
  28. Menu, TRAY, Default , Grab System
  29.  
  30. IfNotExist datagrab.ini
  31. {
  32.     gosub reset
  33.     sleep 100
  34.     gosub settingsgui
  35.     /*
  36.     to do:
  37.     write errorhandler
  38.     */
  39. }
  40. else
  41. {
  42.     ;IniRead, OutputVar, Filename [, Section, Key, Default]
  43.     IniRead, BasePath, datagrab.ini , PathSettings , BasePath
  44.     IniRead, Logpath, datagrab.ini , PathSettings , Logpath
  45. }
  46.  
  47. dummy:
  48. return
  49.  
  50. ;-----------functions------------
  51. SettingsGui:
  52.     Gui, 1:Add, Text, x36 y7 w786 h130 , ED System Data Grabber:`tCopies the current System the user is in to the clipboard.`n`t`t`t`tOnce the ini is written it will do so from the start `tas well as if choosen from the tray menu`t or if the tray icon is double clicked`n`n`t`t`t`tThis app is controled by its taskicon...`n`t`t`t`t`tClicking OK as well as choosing "Test ED Settings" will edit the ED settings.`n`t`t`t`t`t"Change Settings" will bring up this menu`n`t`t`t`t`tThe rest of Menu should be selfexplaining`n`nTo Do: implementing changeable hotkeys for more comfort. `t Writing Errorhandlers for more stability`nCopyright by BiZZ Keryear under CC by-sa 3.0 http://creativecommons.org/licenses/by-sa/3.0/
  53.     Gui, 1:Add, Text, x6 y157 w90 h20 , Path to logs:
  54.     Gui, 1:Add, Text, x106 y157 w690 h20 , %LogPath%
  55.     Gui, 1:Add, Button, x806 y157 w60 h20 gChangeLog, Change
  56.     Gui, 1:Add, Text, x6 y187 w690 h20 , Path to settings
  57.     Gui, 1:Add, Text, x106 y187 w690 h20 , %BasePath%
  58.     Gui, 1:Add, Button, x806 y187 w60 h20 gChangeSetting, Change
  59.     Gui, 1:Add, Button, x290 y217 w100 h30 Default ,&OK
  60.     Gui, 1:Add, Button, x510 y217 w100 h30 gResetd ,&Reset to default
  61.     Gui, 1:Show, x323 y203 h252 w880, ED System Data Grabber V1.1 -- Settings:
  62. Return
  63.  
  64. GrabSystem:
  65.     gosub FindNewestLog
  66.     gosub Parselog
  67. return
  68.  
  69. WriteSettings:
  70.     IniWrite, 1.0 , datagrab.ini, Version , Version
  71.     ;IniWrite, Value, Filename, Section [, Key]
  72.     IniWrite, %BasePath% , datagrab.ini, PathSettings , BasePath
  73.     IniWrite, %Logpath%, datagrab.ini, PathSettings , Logpath
  74. return
  75.  
  76. ExitSub:
  77.     ExitApp
  78. return
  79.  
  80. ReloadSub:
  81.     reload
  82. return
  83.  
  84. testini:
  85.     AppConfig = %BasePath%\AppConfig.xml
  86.     ifnotexist %AppConfig%
  87.     {
  88.         msgbox ,16,! ! ! ! ! ! ! ! ! Error: Path to ED Settings File Wrong ! ! ! ! ! ! ! ! !, Try to find the file AppConfig.xml from Elite Dangerous and change the path accordenly`n`nP.S.: The path to the logfiles might be wrong as well.
  89.         gosub ChangeSetting
  90.     }
  91.     else
  92.     {
  93.         file := FileOpen(AppConfig, "r")
  94.         line := file.Read()
  95.         if file
  96.             file.Close()   
  97.  
  98.         NeedleRegEx := "mi)<Network\s*VerboseLogging=""([0|1])"""
  99.         out := RegExMatch(line, NeedleRegEx, verboseone)
  100.         if !out
  101.         {
  102.             NeedleRegExReplace := "mi)(<Network\s)"
  103.             line := RegExReplace(line, NeedleRegExReplace , "<Network`n`t  VerboseLogging=""1""")
  104.             verboseone1 := 1
  105.         }
  106.         NeedleRegEx2 := "mi)</Network>\s*VerboseLogging=""([0|1])"""
  107.         out2 := RegExMatch(line, NeedleRegEx2, verbosetwo)
  108.         if !out2
  109.         {
  110.             NeedleRegExReplace := "mi)</Network>$"
  111.             line := RegExReplace(line, NeedleRegExReplace , "</Network>`n`tVerboseLogging=""1""")
  112.             verbosetwo1 := 1
  113.         }
  114.         if verboseone1 != 1
  115.         {
  116.             NeedleRegExReplace := "mi)<Network\s*VerboseLogging=""0"""
  117.             line := RegExReplace(line, NeedleRegExReplace , "<Network`n`t  VerboseLogging=""1""")
  118.         }
  119.         if verbosetwo1 != 1
  120.         {
  121.             NeedleRegExReplace := "mi)</Network>\s*VerboseLogging=""0"""
  122.             line := RegExReplace(line, NeedleRegExReplace , "</Network>`n`tVerboseLogging=""1""")
  123.         }
  124.         if (verboseone1 = 0 OR verbosetwo1 = 0 OR !out OR !out2)
  125.         {
  126.             FileCopy, %AppConfig%, %BasePath%/AppConfig.xml.bak
  127.             file := FileOpen(AppConfig, "w")
  128.             if !IsObject(file)
  129.                 msgbox error, failed to change Elite Dangerous settings! If you see this error something is off
  130.             else
  131.                 File.Write(line)
  132.             if file
  133.                 file.Close()
  134.             ifwinexist Elite Dangerous Launcher
  135.                 msgbox This app has dectected that Elite Dangerous is currently running.`n`nSince it made changes to the Elite Dangerous Setting file`nElite Dangerous needs to be restarted.`nAn copy of the previous version of the config file is made: AppConfig.xml.bak
  136.         }          
  137.     }
  138. return
  139.  
  140.  
  141. ChangeLog:
  142.     inputbox , nLogPath , Change Path to log files, Type or Paste in here the path to EliteDangerous log files:,,800,120,,,,,%LogPath%
  143.     if Errorlevel
  144.         Errorlevel =
  145.     else
  146.     {
  147.         LogPath := nLogPath
  148.         nLogPath =
  149.     }
  150.     gui , 1:destroy
  151.     gosub SettingsGui
  152. return
  153.  
  154. ChangeSetting:
  155.     inputbox , nBasePath , Change Path to settings, Type or Paste in here the path to EliteDangerous settings file:,,800,120,,,,,%BasePath%
  156.     if Errorlevel
  157.         Errorlevel =
  158.     else
  159.     {
  160.         BasePath := nBasePath
  161.         nBasePath =
  162.     }
  163.     gui , 1:destroy
  164.     gosub SettingsGui
  165. return
  166.  
  167. resetd:
  168.     gosub reset
  169.     gui , 1:destroy
  170.     gosub SettingsGui
  171. return
  172.    
  173. reset:
  174.     BasePath := defaultBasePath
  175.     Logpath := defaultLogpath
  176. return
  177.  
  178. ButtonOK:
  179.     gui , 1:destroy
  180.     gosub testini
  181.     gosub WriteSettings
  182. return
  183.  
  184. Parselog:
  185.     target=%Logpath%\%LastFileName%
  186.     file := FileOpen(target, "r")
  187.     while !file.AtEOF ; This loop will run until it finds the end of the file
  188.     {
  189.         ;Read the next line of the script
  190.         line := file.ReadLine()
  191.        
  192.         ;Check if the line starts with a timestamp
  193.         NeedleRegEx := "^\{(\d{2}:\d{2}:\d{2})\} System:\d*\((.*?)\)"
  194.         out := RegExMatch(line, NeedleRegEx, System)
  195.  
  196.         ;If the line started with a timestamp, do more stuff...
  197.         if (out > 0)
  198.         {
  199.             LastSystem := System2
  200.             LastTime := System1
  201.         }
  202.     }
  203.     if file
  204.         file.Close()
  205.     clipboard := LastSystem
  206. return
  207.  
  208. FindNewestLog:
  209.     frun :=0
  210.     Loop, %Logpath%\netLog.*.log
  211.     {
  212.         if frun = 0
  213.         {
  214.             LastFileDate:= A_LoopFileTimeModified
  215.             LastFileName := A_LoopFileName
  216.             frun:=1
  217.         }
  218.         diff := A_LoopFileTimeModified - LastFileDate
  219.         if diff > 0
  220.         {
  221.             LastFileName := A_LoopFileName
  222.             LastFileDate:= A_LoopFileTimeModified
  223.         }
  224.     }
  225. return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement