rfancella

User Functions.ahk (Full)

Mar 11th, 2015
595
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.72 KB | None | 0 0
  1. ; Use this function to define any code you want to run in every module on start
  2. StartGlobalUserFeatures(){
  3. Global systemName, romName, WinIPACPath, WinIPACProfileDir, changedIPacProfile, 3rdPartyToolsSettingsFile, IdleVolPath, IdleVolUse
  4. Log("StartGlobalUserFeatures - Starting")
  5. 3rdPartyToolsSettingsFile := A_ScriptDir . "\Lib\3rdPartyToolsPaths.ini"
  6. Log("3rdPartyTools - Ini file location " . 3rdPartyToolsSettingsFile, 5)
  7. Log("WinIPAC - Start IPac System Profile Test")
  8. WinIPACPath := IniReadCheck(3rdPartyToolsSettingsFile, "WinIPAC", "WinIPACPath",A_ScriptDir . "\WinIPAC\WinIPAC.exe",,1)
  9. WinIPACProfileDir := IniReadCheck(3rdPartyToolsSettingsFile, "WinIPAC", "WinIPACProfileDir",A_ScriptDir . "\IPACProfiles",,1)
  10.  
  11. If !(FileExist(WinIPACPath)) {
  12. Log("WinIPAC - The file WinIPAC.exe does not exist at " . WinIPACPath . ". Please check your paths!",3)
  13. } else {
  14. If !(FileExist(WinIPACProfileDir . "\" . "default.ipc")){
  15. Log("WinIPAC - IPac required Default Profile not found at " . WinIPACProfileDir . "\" . "default.ipc",5)
  16. } else {
  17. Log("WinIPAC - Default profile found: " . WinIPACProfileDir . "\" . "default.ipc",5)
  18. changedIPacProfile := LoadIPacProfile()
  19. }
  20. }
  21. Log("WinIPAC - Stop IPac System Profile Test")
  22. Log("IdleVolAdjust - Start IdleVolAdjust Section")
  23.  
  24. IdleVolPath := IniReadCheck(3rdPartyToolsSettingsFile, "IdleVolAdjust", "IdleVolPath",A_ScriptDir . "\IdleVolumeAdjuster.exe",,1)
  25. IdleVolUse := IniReadCheck(3rdPartyToolsSettingsFile, "IdleVolAdjust", "IdleVolUse","No",,1)
  26. IdleVolSystems := IniReadCheck(3rdPartyToolsSettingsFile, "IdleVolAdjust", "IdleVolSystems","",,1)
  27.  
  28. If !(FileExist(IdleVolPath)) {
  29. Log("IdleVolAdjust - Exe NOT located at " . IdleVolPath . ". Please check your paths", 5)
  30. IdleVolUse := "No"
  31. } else {
  32. IfInString, IdleVolSystems, %systemName%
  33. {
  34. Log("IdleVolAdjust - " . systemName . " System found in IdleVolSystems list", 5)
  35. If (IdleVolUse = "Yes") {
  36. Log("IdleVolAdjust - Running IdleVolumeAdjuster pause with """ . IdleVolPath . " pause""", 5)
  37. Run, % IdleVolPath . " pause",,UseErrorLevel,OutputVarPID
  38. } else If (IdleVolUse = "Kill") {
  39. Log("IdleVolAdjust - Running IdleVolumeAdjuster Kill with """ . IdleVolPath . " Kill""", 5)
  40. Log("IdleVolAdjust - Trying to detect if program is running.",5)
  41. Process, Exist, IdleVolumeAdjuster.exe
  42. IdleVolPID = %ErrorLevel%
  43. Log("IdleVolAdjust - IdleVolPID = " . IdleVolPID,5)
  44. If IdleVolPID = 0
  45. {
  46. Log("IdleVolAdjust - Process does not exist. Not stopping the process and it will not be restarted.", 5)
  47. IdleVolUse := "No"
  48. } else {
  49. Log("IdleVolAdjust - Attempting to stop Idle Volume Adjuster with a PID of " . IdleVolPID,5)
  50. Process, Close, %IdleVolPID%
  51. CloseIdleVolPID = %ErrorLevel%
  52. Log("IdleVolAdjust - Close process ErrorLevel - " . CloseIdleVolPID,5)
  53. If (IdleVolPID = CloseIdleVolPID)
  54. {
  55. Log("IdleVolAdjust - Process closed OK.",5)
  56. } else {
  57. Log("IdleVolAdjust - Process not closed. Will not restart.",5)
  58. IdleVolUse := "No"
  59. }
  60. }
  61. }
  62. } else {
  63. Log("IdleVolAdjust - " . systemName . " System Not found in IdleVolSystems list :" . IdleVolSystems, 5)
  64. IdleVolUse := "No"
  65. }
  66. }
  67. Log("IdleVolAdjust - Stop IdleVolAdjust Section")
  68. Log("StartGlobalUserFeatures - Ending")
  69. }
  70.  
  71.  
  72. LoadIPacProfile(){
  73. Global systemName, romName, WinIPACPath, WinIPACProfileDir
  74. IPacPath1 := WinIPACProfileDir . "\" . systemName . "\" . romName . ".ipc"
  75. IPacPath2 := WinIPACProfileDir . "\" . systemName . ".ipc"
  76. Loop, 2 {
  77. if FileExist(IPacPath%a_index%) {
  78. Log("WinIPAC - Loading IPAC profile: " . IPacPath%a_index%, 5)
  79. Run, % WinIPACPath . " " . IPacPath%a_index%,,UseErrorLevel,OutputVarPID
  80. Process, WaitClose, %OutputVarPID%, 5
  81. IPacPID = ErrorLevel
  82. Log("WinIPAC - WinIPAC PID: " . OutputVarPID . " Error Level: " . ErrorLevel, 5)
  83. ;11:55:54 AM | Title/Class: WinIPAC - Downloading ahk_class ThunderRT6FormDC is now active
  84. If (ErrorLevel > 0){
  85. ScriptError("Your IPac failed to program. Make sure the IPac is connected and try again. You may need to reboot your computer and try again.")
  86. } else {
  87. Log("WinIPAC - IPAC profile was loaded.",5)
  88. Return true
  89. }
  90. } else {
  91. Log("WinIPAC - IPac profile " . IPacPath%a_index% . " not found.",5)
  92. }
  93. }
  94. }
  95.  
  96. ; Use this function to define any code you may need to stop or clean up in every module on exit
  97. StopGlobalUserFeatures(){
  98. Global WinIPACPath, WinIPACProfileDir, changedIPacProfile, IdleVolPath, IdleVolUse
  99. Log("StopGlobalUserFeatures - Starting")
  100. Log("WinIPAC - Start IPac Profile Restore")
  101. If (changedIPacProfile){
  102. RunWait, % WinIPACPath . " " . WinIPACProfileDir . "\" . "default.ipc",,UseErrorLevel,OutputVarPID
  103. If (ErrorLevel > 0){
  104. ScriptError("Your IPac failed to restore. Your default IPac profile was not programmed.")
  105. } else {
  106. Log("WinIPAC - Default IPac profile has been restored.",5)
  107. Return
  108. }
  109. } else {
  110. Log("WinIPAC - Alternative IPac profile not used. No need to restore.")
  111. }
  112. Log("WinIPAC - Stop IPac Profile Restore")
  113.  
  114. Log("IdleVolAdjust - Start IdleVolAdjust resume section")
  115. If (IdleVolUse = "Yes") {
  116. Log("IdleVolAdjust - Running IdleVolumeAdjuster resume with """ . IdleVolPath . " resume""", 5)
  117. Run, % IdleVolPath . " resume",,UseErrorLevel,OutputVarPID
  118. } else If (IdleVolUse = "Kill") {
  119. Log("IdleVolAdjust - Running IdleVolumeAdjuster restart from Kill with """ . IdleVolPath . """", 5)
  120. Run, % IdleVolPath,,UseErrorLevel,OutputVarPID
  121. } else {
  122. Log("IdleVolAdjust - Not adjusting volume. IdleVolUse set to: " . IdleVolUse, 5)
  123. }
  124.  
  125. Log("IdleVolAdjust - Stop IdleVolAdjust resume section")
  126. Log("StopGlobalUserFeatures - Ending")
  127. }
Advertisement
Add Comment
Please, Sign In to add comment