Advertisement
djvj

7z,ahk

Apr 25th, 2016
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 30.65 KB | None | 0 0
  1. MCRC=80039582
  2. MVersion=1.0.7
  3.  
  4. 7z(ByRef _7zP, ByRef _7zN, ByRef _7zE, ByRef _7zExP,call="", AttachRomName=true, AllowLargerFolders=false){
  5. Global sevenZEnabled,sevenZFormats,sevenZFormatsNoP,sevenZFormatsRegEx,sevenZPath,sevenZAttachSystemName,sevenZTimedOut,sevenZTimerRunning,romExtensions,skipchecks,romMatchExt,systemName,dbName,MEmu,logLevel
  6. Global fadeIn,fadeLyr37zAnimation,fadeLyr3Animation,fadeLyr3Type,RLObject,RLLog,sevenZTempRomExists,use7zAnimation,romExSize,sevenZ1stRomPath,sevenZRomPath,sevenZPID,sevenZStatus
  7. Global romMapTable,romMappingFirstMatchingExt,romMenuRomName ;,romMappingEnabled
  8. Global altArchiveNameOnly,altRomNameOnly,altArchiveAndRomName,altArchiveAndManyRomNames,altRomNamesOnly
  9. Global fade7zProgressMode,fadeAnimationTimeElapsed,progressBarTimeToMax,FadeInExitDelay
  10. Static sevenZ1stUse
  11. If (sevenZEnabled = "true")
  12. { old7zP:=_7zP,old7zN:=_7zN,old7zE:=_7zE ; store values sent to 7z for logging
  13. ;If ( romMapTable.MaxIndex() && !_7zN ) ; if romMapTable contains a rom and romName not passed
  14. ; msgbox Rom map table exists`nNo rom name passed to 7z`nrom must be in map table so parse all archive types in table and check contents for the alt archive name or for the alt rom named if defined
  15. ; Else If ( romMapTable.MaxIndex() && _7zN ) ; if romMapTable contains a rom and romName passed
  16. ; msgbox Rom map table exists`nRom name passed to 7z`nignore map table as rom was passed`, but if archive type`, handle it`, otherwise run rom as is`nNO CHANGES NEEDED TO HANDLE THIS SCENARIO
  17. ; Else If ( !romMapTable.MaxIndex() && _7zN ) ; if romMapTable does not contain a rom and romName passed
  18. ; msgbox Rom map table does not exist`nRom name passed to 7z`nHandle rom`, if archive type pass further into 7z else if not`, skip 7z and run rom as is`nNO CHANGES NEEDED TO HANDLE THIS SCENARIO
  19. ; Else If ( !romMapTable.MaxIndex() && !_7zN ) ; if romMapTable does not contain a rom and romName not passed
  20. ; msgbox Rom map table does not exist`nNo rom name passed to 7z`nShould never see this error because no rom exists else if we are going to have to error out
  21. RLLog.Info("7z - Started, " . (If _7zN ? "received " . _7zP . "\" . _7zN . _7zE . ". If rom is an archive, it will extract to " . _7zExP : "but no romName was received"))
  22. sevenZ1stUse ++ ; increasing var each time 7z is used
  23. sevenZStatus := "" ; this var keeps track of where 7z is inside this function. This is needed so other parts of RocketLauncher stay in sync and don't rush through their own routines
  24. sevenZRunning := ""
  25. sevenZFinished := ""
  26.  
  27. Loop, Parse, romExtensions, | ; parse out 7zFormat extensions from romExtensions so the dll doesn't have to parse as many
  28. { If !RegExMatch(A_LoopField,"i)" . sevenZFormatsNoP)
  29. { extIndex ++ ; index only increases on valid rom type extensions
  30. romExtFound := 1
  31. romTypeExtensions .= (If extIndex > 1 ? "|":"") . A_LoopField
  32. }
  33. }
  34. If (!romExtFound and skipChecks = "false")
  35. ScriptError("You did not supply any valid rom extensions to search for in your compressed roms. Please turn off 7z support or add at least one rom extension to Rom_Extension: """ . romExtensions . """. If this archive has no roms with a standard romName inside, you may need to set Skip Checks to ""Rom Extension.""",10)
  36. ; msgbox romMenuRomName: %romMenuRomName%`nromFromDLL: %romFromDLL%`ndllRomPath: %dllRomPath%`ndllName: %dllName%`ndllExt: %dllExt%`n7zExP: %_7zExP%`nsevenZAttachSystemName: %sevenZAttachSystemName%`n_7zP: %_7zP%`n7zN: %_7zN%`n7zE: %_7zE%`nsevenZExPCheck: %sevenZExPCheck%`nromExSize: %romExSize%`nsevenZExPCheckSize: %sevenZExPCheckSize%`nromFound: %romFound%
  37. ; ExitApp
  38. If (romMapTable.MaxIndex() && !_7zN) { ; if romMapTable contains a rom and romName not passed, we must search the rom map table for known roms (defined from map ini or same as archive name) and stop on first found. This method is from a mapped rom not from the Rom Launch Menu.
  39. RLLog.Debug("7z - Using romTable method because a romTable exists and no romName provided")
  40. sevenZUsed := 1 ; flag that we used 7z for this launch
  41. Loop % romMapTable.MaxIndex() ; Loop through all found rom map inis
  42. { altArchiveFullPath := romMapTable[A_Index,"romPath"] . "\" . romMapTable[A_Index,"romName"] . "." . romMapTable[A_Index,"romExtension"], romMapIni := romMapTable[A_Index,1] ;, romMapKey := "Alternate_Rom_Name"
  43. firstAltArchiveFullPath := altArchiveFullPath ; storing this so it can be used if skipchecks is enabled and there are multiple paths found, we only want to send the first in this scenario
  44. RLLog.Debug("7z - Found a path to a previously found rom in romMapTable: """ . altArchiveFullPath . """")
  45. IniRead, altRomName, %romMapIni%, %dbName%, Alternate_Rom_Name
  46. If (altRomName = "" || altRomName = "ERROR") ; if multiple alt roms were defined, do a check if user defined the key with "_1"
  47. IniRead, altRomName, %romMapIni%, %dbName%, Alternate_Rom_Name_1
  48. If !(altRomName = "" || altRomName = "ERROR")
  49. RLLog.Debug("7z - Mapping ini contains an Alternate_Rom_Name of """ . altRomName . """")
  50. SplitPath, altArchiveFullPath,, _7zP, _7zE, _7zN ; assign vars to what is needed for the rest of 7z. This is where we define romPath, romName, and romExtension when none were provided to 7z because we used a map table instead.
  51. _7zE := "." . _7zE
  52. If romFromDLL := RLObject.findFileInZip(altArchiveFullPath, If (altRomName != "" && altRomName != "ERROR") ? altRomName : _7zN, romTypeExtensions) ; if altRomName is a valid name, search for it, otherwise search for the 7zN
  53. { RLLog.Debug("7z - DLL found rom inside archive using ""findFileInZip"": """ . romFromDLL . """")
  54. foundRom := 1
  55. Break
  56. } Else If (romMappingFirstMatchingExt = "true") ; if we didn't find an exact romName, settle on finding one that at least matches the first matching extension
  57. { If romFromDLL := RLObject.findByExtension(altArchiveFullPath, romTypeExtensions)
  58. { foundRom := 1
  59. Break ; break on first found rom and move on
  60. }
  61. }
  62. }
  63. If foundRom {
  64. RLLog.Info("7z - Loading Mapped Rom: """ . romFromDLL . """ found inside """ . _7zP . "\" . _7zN . _7zE . """")
  65. romFromRomMap := 1
  66. romIn7z := "true" ; avoid a duplicate check later
  67. } Else If (skipChecks != "false") ; this scenario is when a rom map is used to load an archive with no valid rom name or extension, like scummvm compressed roms, and relinking those roms to a different name
  68. { SplitPath, firstAltArchiveFullPath,, _7zP, _7zE, _7zN ; assign vars to what is needed for the rest of 7z. This is where we define romPath, romName, and romExtension when none were provided to 7z because we used a map table instead.
  69. _7zE := "." . _7zE
  70. RLLog.Debug("7z - A matching rom was not found inside the archive, but skipChecks is set to " . skipChecks . ", so continuing with extraction of the first found rom in the table: " . firstAltArchiveFullPath)
  71. } Else
  72. ScriptError("Scanned all defined ""Alternate_Archive_Name"" and no defined ""Alternate_Rom_Name"" found in any provided Rom Map ini files for """ . dbName . """")
  73.  
  74. } Else If romMenuRomName { ; if rom came from the rom map menu
  75. RLLog.Debug("7z - Using Rom Map Menu method because the Launch Menu was used for this rom: """ . romMenuRomName . """")
  76. sevenZUsed := 1 ; flag that we used 7z for this launch
  77. SplitPath, romMenuRomName,,,rmExt, rmName ; roms in map table do not always have an extension, like when showing roms from the map ini instead of all in the archive. If it does, use it to find the rom in the archive faster, if it doesn't, search all defined romExtensions
  78. IfNotInString, romTypeExtensions, %rmExt%
  79. { RLLog.Debug("7z - The rom Ext """ . rmExt . """ was not found in """ . romTypeExtensions . """")
  80. rmName := rmName . "." . rmExt ; If rom "extension" don't match romTypeExtension, this is probably not an extension but part of the romname
  81. rmExt := ""
  82. }
  83. ; msgbox % _7zP . "\" . _7zN . _7zE
  84. If romFromDLL := RLObject.findFileInZip(_7zP . "\" . _7zN . _7zE, rmName, If rmExt ? rmExt : romTypeExtensions) ; If rmExt exists, search for it, otherwise search for the all romTypeExtensions. Only searching for rmExt will speed up finding our rom
  85. { RLLog.Debug("7z - DLL found rom inside archive using ""findFileInZip"": """ . romFromDLL . """")
  86. romFromRomMap := 1
  87. romIn7z := "true" ; avoid a duplicate check later
  88. } Else ; if rom was not found in archive
  89. ScriptError("Scanned all defined ""Alternate_Archive_Name"" and could not find the selected game " . romMenuRomName . " in any provided Rom Map ini files for " . dbName)
  90.  
  91. } Else If RegExMatch(_7zE,"i)" . sevenZFormatsRegEx) ; Not using Rom Mapping and if provided extension is an archive type
  92. { RLLog.Debug("7z - Using Standard method to extract this rom")
  93. sevenZUsed := 1 ; flag that we used 7z for this launch
  94. RLLog.Debug("7z - """ . _7zE . """ found in " . sevenZFormats)
  95. If !romFromRomMap { ; do not need to check for rom extensions if alt rom was already scanned in the above dll "findFileInZip"
  96. ; msgbox
  97. CheckFile(_7zP . "\" . _7zN . _7zE,"7z could not find this file, please check it exists:`n" . _7zP . "\" . _7zN . _7zE)
  98. ; If skipChecks = false ; the following extension checks are bypassed with setting skipChecks to any option that will skip Rom Extensions (all of them except when skipchecks is disabled)
  99. ; {
  100. If romFromDLL := RLObject.findFileInZip(_7zP . "\" . _7zN . _7zE, _7zN, romTypeExtensions) ; check for _7zN inside the archive
  101. { romIn7z := "true" ; avoid a duplicate check later
  102. RLLog.Info("7z - Archive name matches rom name`; DLL found rom inside archive using ""findFileInZip"": """ . romFromDLL . """")
  103. } Else If (romMatchExt != "true" && skipChecks = "false") ; do not error if skip checks is set
  104. ScriptError("Could not find """ . _7zN . """ inside the archive with any defined Rom Extensions. Check if you are missing the correct Rom Extension for this rom for " . MEmu . "'s Extensions`, enable Rom_Match_Extension`, or correct the file name inside the archive.")
  105. If !romIn7z { ; if we didn't find an exact romName, settle on finding one that at least matches the first matching extension
  106. If romFromDLL := RLObject.findByExtension(_7zP . "\" . _7zN . _7zE, romTypeExtensions)
  107. { romIn7z := "true" ; avoid a duplicate check later
  108. RLLog.Warning("7z - Archive name DOES NOT MATCH rom name`; DLL found rom inside archive using ""findByExtension"": " . romFromDLL)
  109. }
  110. }
  111. ; }
  112. }
  113. } Else
  114. RLLog.Warning("7z - Unhandled scenario, please report this and post your troubleshooting log")
  115.  
  116. If (romIn7z = "true" || (skipchecks != "false" && sevenZUsed))
  117. { SplitPath, romFromDLL,,dllRomPath,dllExt,dllName
  118. If (sevenZAttachSystemName = "true")
  119. RLLog.Debug("7z - Attaching the system name """ . systemName . """ to the extracted path")
  120. sevenZRomPath := _7zExP . (If sevenZAttachSystemName = "true" ? "\" . systemName : "") . (If AttachRomName ? "\" . _7zN : "") ; sevenZRomPath reflects the sevenZExtractPath + the rom folder our rom will be extracted into. This is used for cleanup later so RocketLauncher knows what folder to remove
  121. sevenZExPCheck := sevenZRomPath . (If dllRomPath ? "\" . dllRomPath : "") ; If the archive contains a path/subfolder to the rom we are looking for, add that to the path to check
  122. romExSize := RLObject.getZipExtractedSize(_7zP . "\" . _7zN . _7zE) ; Get extracted Size of rom for Fade so we know when it's done being extracted or so we can verify the rom size of extracted folders with multiple roms
  123. RLLog.Debug("7z - Invoked COM Object, ROM extracted size: " . romExSize . " bytes")
  124.  
  125. If (skipchecks != "false")
  126. RLLog.Warning("7z - Following paths in log entries may not be accurate because SkipChecks is enabled! Do not be alarmed if you see invalid looking paths when Skip Checks is required for this system.")
  127.  
  128. If (AttachRomName || dllRomPath) {
  129. sevenZExSizeCheck := sevenZExPCheck
  130. } Else { ; AttachRomName=false AND dllRomPath is empty (rom not found inside the archive)
  131. RLLog.Debug("7z - Checking for root folder in archive " . _7zP . "\" . _7zN . _7zE)
  132. rootFolder := RLObject.getZipRootFolder(_7zP . "\" . _7zN . _7zE) ; Check if compressed archive only contains a single folder as the root and if so use that for checking the extraction size, if we don't do this size of the whole 7z_Extract_Path folder will be calculated which means the file will always be extracted as the next loop will produce the wrong file size
  133. RLLog.Debug("7z - Root folder checking returned """ . rootFolder . """")
  134. sevenZExSizeCheck := If rootFolder ? sevenZExPCheck . "\" . rootFolder : sevenZExPCheck
  135. ; msgbox sevenZRomPath: %sevenZRomPath%`n7zExP: %_7zExP%`nsevenZExPCheck: %sevenZExPCheck%`nrootFolder: %rootFolder%`n7zExSizeCheck: %sevenZExSizeCheck%`n7zExSizeCheck: %sevenZExSizeCheck%`nromFromDLL: %dllRomPath%`ndllName: %dllName%`ndllExt: %dllExt%`ndllRomPath: %dllRomPath%`nAttachRomName: %AttachRomName%`nsevenZAttachSystemName: %sevenZAttachSystemName%
  136. }
  137.  
  138. RLLog.Debug("7z - Checking if this archive has already been extracted in " . sevenZExSizeCheck)
  139. If FileExist(sevenZExSizeCheck) ; Check if the rom has already been extracted and break out to launch it
  140. { Loop % sevenZExSizeCheck . "\*.*",,1
  141. sevenZExPCheckSize += %A_LoopFileSize%
  142. RLLog.Debug("7z - File already exists in " . sevenZExSizeCheck . " with a size of: " . sevenZExPCheckSize . " bytes")
  143. } Else
  144. RLLog.Debug("7z - File does not already exist in " . sevenZExSizeCheck . "`, proceeding to extract it.")
  145.  
  146. ; msgbox romMenuRomName: %romMenuRomName%`nromFromDLL: %romFromDLL%`ndllRomPath: %dllRomPath%`ndllName: %dllName%`ndllExt: %dllExt%`n7zExP: %_7zExP%`nsevenZAttachSystemName: %sevenZAttachSystemName%`n7zP: %_7zP%`n7zN: %_7zN%`n7zE: %_7zE%`nsevenZExPCheck: %sevenZExPCheck%`nromExSize: %romExSize%`nsevenZExPCheckSize: %sevenZExPCheckSize%`nromFound: %romFound%
  147. ; difference:=sevenZExPCheckSize-romExSize
  148. ; msgbox, rom: %_7zP%\%_7zN%%_7zE%`nrom size from dll getZipExtractedSize: %romExSize%`nrom size alread on disk: %sevenZExPCheckSize%`ndifference: %difference%
  149. If (romExSize && sevenZExPCheckSize && (If AllowLargerFolders ? (romExSize <= sevenZExPCheckSize) : (romExSize = sevenZExPCheckSize))) ; If total size of rom in archive matches the size on disk, good guess the extracted rom is complete and we don't need to re-extract it again. If the system allows for larger extract path than the currently extracting game, like in dos games where there may be saved info made in the folder, allow the already extracted game to be larger than the archived game. AllowLargerFolders must be set to allow this behavior.
  150. { _7zP := sevenZExPCheck
  151. _7zE := "." . dllExt
  152. If romMenuRomName ; only need this when rom map launch menu was used
  153. _7zN := dllName ; set romName to the found rom from the dll
  154. romFound := "true" ; telling rest of function rom found so it exists successfully and to skip to end
  155. sevenZTempRomExists := "true" ; telling the animation that the rom already exists so it doesn't try to show a 7z animation
  156. ; RLLog.Debug("7z - TESTING 1 -- _7zP: " . _7zP)
  157. ; RLLog.Debug("7z - TESTING 1 -- _7zN: " . _7zN)
  158. ; RLLog.Debug("7z - TESTING 1 -- _7zE: " . _7zE)
  159. RLLog.Debug("7z - Breaking out of 7z to load existing file")
  160. If (fadeIn = "true")
  161. { RLLog.Debug("7z - FadeIn is true, but no extraction needed as it already exists in 7z_Extract_Path. Using Fade_Layer_3_Animation instead.")
  162. useNon7zAnimation := 1
  163. }
  164. } Else {
  165. Clipboard := sevenZExPCheckSize
  166. sizeDiff := If (romExSize > sevenZExPCheckSize) ? romExSize - sevenZExPCheckSize : sevenZExPCheckSize - romExSize
  167. RLLog.Debug("7z - Calculated a difference of " . sizeDiff . " bytes, so this file will be extracted")
  168. }
  169. } Else If RegExMatch(_7zE,"i)" . sevenZFormatsRegEx) ; only need this condition if using the standard 7z method and provided rom doesnt need 7z to load
  170. { RLLog.Info("7z - Provided rom extension """ . _7zE . """ is not an archive type, turning off 7z and running rom directly.")
  171. sevenZEnabled := "false" ; need to tell the animation to load a non-7z animation
  172. If (fadeIn = "true")
  173. { RLLog.Debug("7z - FadeIn is true, but no extraction needed for this rom. Using Fade_Layer_3_Animation instead.")
  174. useNon7zAnimation := 1
  175. }
  176. }
  177.  
  178. ; This section is seperate because I use a couple unique conditions in the above block of code, where the below code would be duplicated if it was moved up.
  179. ; If ((romIn7z = "true" || skipchecks != "false") && !romFound) { ; we found the rom in the archive or we are skipping looking alltogether
  180. If ((romIn7z = "true" || (skipchecks != "false" && sevenZUsed)) && romFound != "true") {
  181. RLLog.Debug("7z - " . (If romIn7z = "true" ? "File found in archive" : "Skipchecks is enabled`, and set to " . skipChecks . " continuing to extract rom."))
  182. ; _7zExP := _7zExP . "\" . (If sevenZAttachSystemName = "true" ? systemName . "\" : "") . _7zN ; unsure what this was for but its causing sevenZExPCheck to keep adding on path names on each loop
  183.  
  184. pathLength := StrLen(sevenZExPCheck . "\" . dllName . "." . dllExt) ; check length and error if there will be a problem.
  185. If pathLength > 255
  186. ScriptError("If you extract this rom, the path length will be " . pathLength . "`, exceeding 255 characters`, a Windows limitation. Please choose a shorter 7z_Extract_Path or shorten the name of your rom.")
  187. Else
  188. RLLog.Debug("7z - Extracted path of rom will be " . pathLength . " in length and within the 255 character limit.")
  189.  
  190. If !InStr(sevenZRomPath,"\\") {
  191. SplitPath, sevenZRomPath,,outDir,,,outDrive ; grabbing the outDrive because sometimes supplying just the sevenZRomPath or outDir to check for space doesn't always return a number
  192. If !FileExist(sevenZRomPath) {
  193. FileCreateDir, %sevenZRomPath%
  194. If ErrorLevel
  195. ScriptError("There was a problem creating this folder to extract your archive to. Please make sure the drive " . outDrive . " exists and can be written to: """ . sevenZRomPath . """")
  196. }
  197. DriveSpaceFree, sevenZFreeSpace, %outDrive% ; get free space in MB of this drive/folder
  198. If ((sevenZFreeSpace * 1000000) < romExSize) ; if the free space on the drive is less than the extracted game's size, error out
  199. ScriptError("You do not have enough free space in """ . outdir . """ to extract this game. Please choose a different folder or free up space on the drive. Free: " . sevenZFreeSpace . " MB / Need: " . (romExSize // 1000000) . " MB")
  200. Else
  201. RLLog.Info("7z - The sevenZExtractPath has " . sevenZFreeSpace . " MB of free space which is enough to extract this game: " . (romExSize // 1000000) . " MB")
  202. } Else
  203. RLLog.Warning("7z - The sevenZExtractPath is a network folder and free space cannot be determined: " . sevenZRomPath)
  204.  
  205. If (fadeIn = "true" && !call)
  206. { RLLog.Debug("7z - FadeIn is true, starting timer to update Layer 3 animation with 7z.exe statistics")
  207. use7zAnimation := "true" ; this will tell the Fade animation (so progress bar is shown) that 7z is being used to extract a rom
  208. ;SetTimer, UpdateFadeFor7z%zz%, -1 ; Create a new timer to start updating Layer 3 of fade. This needs to be a settimer otherwise progress bar gets stuck at 0 during extraction because the thread is waiting for that loop to finish and 7z never starts.
  209. Gosub, UpdateFadeFor7z%zz% ; Create a new timer to start updating Layer 3 of fade
  210. } Else If (call = "mg") { ; If 7z was called from MG, we need start updating its progress bar
  211. RLLog.Info("7z - MG triggered 7z, starting the MG Progress Bar")
  212. SetTimer, UpdateMGFor7z%zz%, -1
  213. } Else If (call = "pause") { ; If 7z was called from Pause, we need start updating its progress bar
  214. RLLog.Info("7z - Pause triggered 7z, starting the Pause Progress Bar")
  215. SetTimer, Pause_UpdateFor7z%zz%, -1
  216. }
  217. If (logLevel >= 4) { ; all debug levels will dump extraction info to log
  218. RLLog.Debug("7z - Logging is debug or higher, dumping 7z Extraction info to log")
  219. SetTimer, DumpExtractionToLog, -1
  220. }
  221. RLLog.Info("7z - Starting 7z extraction of " . _7zP . "\" . _7zN . _7zE . " to " . sevenZExSizeCheck)
  222. sevenZRunning := 1
  223. 7zTimeStart := A_Now
  224. RunWait, %sevenZPath% x "%_7zP%\%_7zN%%_7zE%" -aoa -o"%sevenZRomPath%", sevenZPID,Hide ; perform the extraction and overwrite all
  225. If ErrorLevel
  226. { If ErrorLevel = 1
  227. Error := "Non fatal error, file may be in use by another application"
  228. Else If ErrorLevel = 2
  229. Error := "Fatal Error. Possibly out of space on drive."
  230. Else If ErrorLevel = 7
  231. Error := "Command line error"
  232. Else If ErrorLevel = 8
  233. Error := "Not enough memory for operation"
  234. Else If ErrorLevel = 255
  235. Error := "User stopped the process"
  236. Else
  237. Error := "Unknown 7zip Error"
  238. ScriptError("7zip.exe Error: " . Error)
  239. }
  240. sevenZRunning := ""
  241. sevenZTimeEnd := A_Now - 7zTimeStart
  242. sevenZFinished := 1
  243. RLLog.Info("7z - Finished 7z extraction which took " . sevenZTimeEnd . " seconds")
  244. sevenZPID := "" ; clear the PID because 7z is not running anymore
  245. If (FileExist(sevenZExPCheck . "\" . dllName . "." . dllExt) || skipchecks != "false") { ; after extracting, if the rom now exists in our temp dir, or we are skipping looking, update 7zE, and break out
  246. _7zP := sevenZExPCheck
  247. _7zE := "." . dllExt
  248. If (skipChecks != "Rom Extension")
  249. _7zN := dllName ; update the romName just in case it was different from the name supplied to 7z, never update _7zN if skipChecks is set to Rom Extension
  250. romFound := "true"
  251. ; _7zN := dllName
  252. If !RegExMatch(skipChecks,"i)Rom Only|Rom and Emu")
  253. RLLog.Debug("7z - Found file in " . sevenZExPCheck . "\" . dllName . "." . dllExt)
  254. } Else { ; after extraction, rom was not found in the temp dir, something went wrong...
  255. romFound := "false"
  256. foundExt := "." . dllExt
  257. }
  258. }
  259. If sevenZUsed {
  260. If !romFound ; no need to error that a rom is not found if we are not supplying a rom to 7z
  261. ScriptError("No valid roms found in the archive " . _7zN . _7zE . "`nPlease make sure Rom_Extension contains a rom extension inside the archive: """ . romExtensions . """`nIf this is an arcade rom archive with no single definable extension, please try setting Settings->Skip Checks to Rom Only for this system.",10)
  262. Else If (romFound = "false") ; no need to error that a rom is not found if we are not supplying a rom to 7z
  263. ScriptError("No extracted files found in " . _7zExP . "`nCheck that you are not exceeding the 255 character limit and this file is in the root of your archive:`n" . _7zN . foundExt,10)
  264. If sevenZ1stUse = 1 ; If this is the first time 7z was used (rom launched from FE), set this var so that 7zCleanup knows where to find it for deletion. MultiGame extractions will be stored in the romTable for deletion.
  265. sevenZ1stRomPath := sevenZExSizeCheck
  266. } Else {
  267. RLLog.Info("7z - This rom type does not need 7z: """ . _7zE . """")
  268. useNon7zAnimation := 1
  269. }
  270. If (useNon7zAnimation && !mg) ; this got flagged above if 7z is on, but 7z was not used or needed for the current rom. Since the 7z call is after FadeInStart in the module, we need to start call the animation here now.
  271. { RLLog.Info("7z - Starting non-7z FadeIn animation.")
  272. ; SetTimer, UpdateFadeForNon7z%zz%, -1 ; Create a new timer to start fade non-7z animation because jumping out of a function via gosub does not work
  273. Gosub, UpdateFadeForNon7z%zz% ; Create a new timer to start fade non-7z animation because jumping out of a function via gosub does not work
  274. ; GoSub, %fadeLyr3Animation% ; still need to provide an animation because the 7z animation won't trigger above
  275. }
  276. RLLog.Warning("7z - romPath changed from """ . old7zP . """ to """ . _7zP . """")
  277. RLLog.Warning("7z - romName changed from """ . old7zN . """ to """ . _7zN . """")
  278. RLLog.Warning("7z - romExtension changed from """ . old7zE . """ to """ . _7zE . """")
  279. RLLog.Info("7z - Ended")
  280. }
  281. ;assuring that fade delays the emulator launch if the user choose a custom progress time higher than what is needed to launch the game
  282. If (fadeIn = "true" and fade7zProgressMode="custom" and sevenZUsed){
  283. While (fadeAnimationTimeElapsed < progressBarTimeToMax - FadeInExitDelay) {
  284. Sleep, 100
  285. Continue
  286. }
  287. }
  288. Return
  289.  
  290. DumpExtractionToLog:
  291. Process("Wait", "7z.exe", 2)
  292. If !sevenZTimerRunning { ; if the fade animation did not start the timer, let's start it here
  293. sevenZTimerRunning := 1
  294. sevenZTimedOut := ; reset counter
  295. SetTimer, SevenZTimeout, 100 ; poll 7z.exe every 100ms to see if it's still running
  296. RLLog.Debug("7z - Starting SevenZTimeout Timer")
  297. }
  298. Loop {
  299. ; Updating 7z extraction info
  300. SetFormat, Float, 3 ; don't want to show decimal places in the percentage
  301. romExPercentageAndFile := RLObject.getExtractionSize(sevenZExSizeCheck, 0) ; Get the current file being extracted and size of the 7z Extract Path - (Extraction Progress (Accurate Method))
  302. Loop, Parse, romExPercentageAndFile, | ; StringSplit oddly doesn't work for some unknown reason, must resort to a parsing Loop instead
  303. {
  304. If A_Index = 1
  305. {
  306. romExCurSize := A_LoopField ; Store bytes extracted
  307. romExPercentage := (A_LoopField / romExSize) * 100 ; Calculate percentage extracted
  308. ; tooltip % romExPercentage
  309. } Else If A_Index = 2
  310. romExFile := A_LoopField
  311. }
  312.  
  313. ; Defining text to be shown
  314. outputDebugPercentage := % "Extracting file:`t" . romExFile . "`t|`tPercentage Extracted: " . romExPercentage . "%"
  315. If (logLevel = 10) ; if logging is set to troubleshooting
  316. ToolTip % "Percentage Extracted: " . romExPercentage . "%"
  317. RLLog.Debug(outputDebugPercentage)
  318.  
  319. ; Breaking Loop
  320. ; Process, Exist, 7z.exe ; This breaks out of 7z.exe If it's no longer running. Sometimes an extraction was very quick or there was an error and we don't want to be stuck in an infinite Loop
  321. ; If !ErrorLevel {
  322. If (sevenZTimedOut >= 200) { ; bar is at 100% or 7z is already closed, so break out
  323. RLLog.Debug("7z - " . (If romExPercentage >= 100 ? "7z.exe returned a percentage >= 100":"7z.exe is no longer running") . ", assuming extraction is complete")
  324. Break
  325. }
  326. Sleep, 100
  327. }
  328. ToolTip
  329. Return
  330. }
  331.  
  332. SevenZTimeout:
  333. Process, Exist, 7z.exe ; This breaks out of 7z.exe If it's no longer running. Sometimes an extraction was very quick or there was an error and we don't want to be stuck in an infinite Loop
  334. 7zerrlvl := ErrorLevel
  335. If !ErrorLevel
  336. sevenZTimedOut += 100
  337. If sevenZTimedOut >= 200
  338. { RLLog.Debug("SevenZTimeout - 7z.exe is no longer running")
  339. sevenZTimerRunning := ""
  340. SetTimer, SevenZTimeout, Off
  341. }
  342. Return
  343.  
  344. 7zCleanUp(ExtractedFolder="") {
  345. Global romTable,dbName,mgEnabled,pauseEnabled,RLLog
  346. Global sevenZEnabled,sevenZDelTemp,sevenZCanceled,sevenZ1stRomPath,sevenZCleanUpTriggered
  347. sevenZDeleteFolder := If ExtractedFolder = "" ? sevenZ1stRomPath : ExtractedFolder
  348. If (sevenZEnabled = "true" && !sevenZCleanUpTriggered && (sevenZDelTemp = "true" or sevenZCanceled)) ; if user wants to delete temp files or user canceled a 7z extraction
  349. { RLLog.Info("7zCleanUp - Started")
  350. sevenZCleanUpTriggered := 1
  351. romTableExists := IsObject(romTable) ; if romTable was ever created, it would be an object, which is what this checks for
  352. If ((mgEnabled = "true" || pauseEnabled = "true") && romTableExists)
  353. { RLLog.Debug("7zCleanUp - romTable exists and MG or Pause is enabled. Parsing the table to delete any roms that were extracted")
  354. for index, element in romTable
  355. If % romTable[A_Index, 19]
  356. { FileRemoveDir, % romTable[A_Index, 19], 1 ; remove each game that was extracted with 7z
  357. RLLog.Info("7zCleanUp - Deleted " . romTable[A_Index, 19])
  358. }
  359. FileRemoveDir, %sevenZDeleteFolder%, 1 ; still have to remove the rom we launched from HS
  360. RLLog.Info("7zCleanUp - Deleted " . sevenZDeleteFolder)
  361. } Else {
  362. FileRemoveDir, %sevenZDeleteFolder%, 1
  363. RLLog.Info("7zCleanUp - Deleted " . sevenZDeleteFolder)
  364. }
  365. RLLog.Info("7zCleanUp - Ended")
  366. }
  367. }
  368.  
  369. ; http://www.autohotkey.com/forum/post-509873.html#509873
  370. StdoutToVar_CreateProcess(sCmd, bStream = False, sDir = "", sInput = "")
  371. {
  372. DllCall("CreatePipe", "UintP", hStdInRd , "UintP", hStdInWr , "Uint", 0, "Uint", 0)
  373. DllCall("CreatePipe", "UintP", hStdOutRd, "UintP", hStdOutWr, "Uint", 0, "Uint", 0)
  374. DllCall("SetHandleInformation", "Uint", hStdInRd , "Uint", 1, "Uint", 1)
  375. DllCall("SetHandleInformation", "Uint", hStdOutWr, "Uint", 1, "Uint", 1)
  376. VarSetCapacity(pi, 16, 0)
  377. NumPut(VarSetCapacity(si, 68, 0), si) ; size of si
  378. NumPut(0x100 , si, 44) ; STARTF_USESTDHANDLES
  379. NumPut(hStdInRd , si, 56) ; hStdInput
  380. NumPut(hStdOutWr, si, 60) ; hStdOutput
  381. NumPut(hStdOutWr, si, 64) ; hStdError
  382. If Not DllCall("CreateProcess", "Uint", 0, "Uint", &sCmd, "Uint", 0, "Uint", 0, "int", True, "Uint", 0x08000000, "Uint", 0, "Uint", sDir ? &sDir : 0, "Uint", &si, "Uint", &pi) ; bInheritHandles and CREATE_NO_WINDOW
  383. ExitApp
  384. DllCall("CloseHandle", "Uint", NumGet(pi,0))
  385. DllCall("CloseHandle", "Uint", NumGet(pi,4))
  386. DllCall("CloseHandle", "Uint", hStdOutWr)
  387. DllCall("CloseHandle", "Uint", hStdInRd)
  388. If sInput <>
  389. DllCall("WriteFile", "Uint", hStdInWr, "Uint", &sInput, "Uint", StrLen(sInput), "UintP", nSize, "Uint", 0)
  390. DllCall("CloseHandle", "Uint", hStdInWr)
  391. bStream ? (bAlloc:=DllCall("AllocConsole"),hCon:=DllCall("CreateFile","str","CON","Uint",0x40000000,"Uint",bAlloc ? 0 : 3,"Uint",0,"Uint",3,"Uint",0,"Uint",0)) : ""
  392. VarSetCapacity(sTemp, nTemp:=bStream ? 64-nTrim:=1 : 4095)
  393. Loop
  394. If DllCall("ReadFile", "Uint", hStdOutRd, "Uint", &sTemp, "Uint", nTemp, "UintP", nSize:=0, "Uint", 0)&&nSize
  395. {
  396. NumPut(0,sTemp,nSize,"Uchar"), VarSetCapacity(sTemp,-1), sOutput.=sTemp
  397. If bStream&&hCon+1
  398. Loop
  399. If RegExMatch(sOutput, "[^\n]*\n", sTrim, nTrim)
  400. DllCall("WriteFile", "Uint", hCon, "Uint", &sTrim, "Uint", StrLen(sTrim), "UintP", nSize:=0, "Uint", 0)&&nSize ? nTrim+=nSize : ""
  401. Else Break
  402. }
  403. Else Break
  404. DllCall("CloseHandle", "Uint", hStdOutRd)
  405. bStream ? (DllCall("Sleep","Uint",1000),hCon+1 ? DllCall("CloseHandle","Uint",hCon) : "",bAlloc ? DllCall("FreeConsole") : "") : ""
  406. Return sOutput
  407. }
  408.  
  409. ; CheckForRomExt() {
  410. ; Global romExtensions,sevenZFormatsNoP,skipChecks,RLLog
  411. ; If !RegExMatch(skipChecks,"i)Rom Only|Rom and Emu")
  412. ; { RLLog.Info("CheckForRomExt - Started")
  413. ; Loop, Parse, romExtensions, |
  414. ; { If A_LoopField in %sevenZFormatsNoP%
  415. ; { notFound = 1
  416. ; Continue
  417. ; } Else {
  418. ; RLLog.Info("CheckForRomExt - Ended - Rom extensions found in " . romExtensions)
  419. ; Return
  420. ; }
  421. ; }
  422. ; If notFound = 1
  423. ; ScriptError("You did not supply any valid rom extensions to search for in your compressed roms. Please turn off 7z support or add at least one rom extension to Rom_Extension: " . romExtensions)
  424. ; }
  425. ; }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement