Add source file directory in the game list. So the front end knows the original directory
Insert those changes into a new %LogDir% game list system
Now the script writes the %LogDir% system in the systems.cfg, writes bat files into %LogDir% directory, reads the %LogDir% game list, extracts the desired game info, makes necessary changes to that info and then adds it to the %LogDir% game list.
Code: Select all
SetWorkingDir %A_ScriptDir%
LogDir := "allgames"
IfNotExist, %CLogDir%
FileCreateDir, %LogDir%
IfNotExist, ..\gamelists\%LogDir%
FileCreateDir, ..\gamelists\%LogDir%
FileRead, systemsconfig, ..\systems.cfg
IfInString, systemsconfig, %LogDir%
{
MsgBox, ,Please proceed, The %LogDir% system already exists
goto FileSetAttrib
}
IfNotInString, systemsconfig, %LogDir%
{
ROM_RAW := "%ROM_RAW%"
%LogDir%node =
(join`r`n
<system>
<name>%LogDir%</name>
<fullname>%LogDir%</fullname>
<path>%LogDir%</path>
<extension>.bat .BAT</extension>
<command>"%ROM_RAW%"</command>
<theme>%LogDir%</theme>
</system>
</systemList>
)
systemsconfig := StrReplace(systemsconfig, "</systemList>", %LogDir%node)
FileDelete, ..\systems.cfg
FileAppend, %systemsconfig%, ..\systems.cfg
MsgBox, ,Please proceed, The %LogDir% system was created in the systems.cfg
}
FileSetAttrib:
{
MsgBox, 4,Please select, Would you like to hide unwanted files?
IfMsgBox, No, goto Loop
}
FileSetAttrib, +H, %A_WorkingDir%\nullDC\*.*
FileSetAttrib, -H, %A_WorkingDir%\nullDC\*.iso
FileSetAttrib, +H, %A_WorkingDir%\Dolphin\*.*
FileSetAttrib, -H, %A_WorkingDir%\Dolphin\*.bin
FileSetAttrib, +H, %A_WorkingDir%\PPSSPP\*.*
FileSetAttrib, -H, %A_WorkingDir%\PPSSPP\*.cso
FileSetAttrib, +H, %A_WorkingDir%\pcsx-2\*.*
FileSetAttrib, -H, %A_WorkingDir%\pcsx-2\*.bin
FileSetAttrib, -H, %A_WorkingDir%\pcsx-2\*.iso
MsgBox, ,Please proceed, Unwanted files have been hidden
Loop:
FileList =
Loop, Files, *.*, R
IfNotInString, A_LoopFileAttrib, H
FileList = %FileList%%A_LoopFileFullPath%`n
Sort, FileList
Loop, Parse, FileList, `n
{
Array := StrSplit(A_LoopField, "\")
SourceFileName := Array.2
SourceFileDir := Array.1
Aray := StrSplit(SourceFileName, ".")
Needle := Aray.MaxIndex()
if Needle = 2
SourceFileExt := Aray.2
if Needle = 3
SourceFileExt := Aray.3
if Needle = 4
SourceFileExt := Aray.4
if Needle = 5
SourceFileExt := Aray.5
if Needle = 6
SourceFileExt := Aray.6
if Needle = 7
SourceFileExt := Aray.7
if Needle = 8
SourceFileExt := Aray.8
if Needle = 9
SourceFileExt := Aray.9
if Needle = 10
SourceFileExt := Aray.10
SourceFileExtensions = .%SourceFileExt%
SourceFileNoExt := StrReplace(SourceFileName, SourceFileExtensions)
;MsgBox, 4, Please select,%SourceFileNoExt%
;IfMsgBox, No, break
nullDC = %HOME%\nullDC.exe -config nullDC_GUI:Fullscreen=1 -config nullDC:Emulator.Autostart=1 -config ImageReader:LoadDefaultImage=1 -config ImageReader:DefaultImage="%SourceFileName%"
Dolphin = %HOME%\Dolphin.exe -e "%SourceFileName%"
PPSSPP = %HOME%\PPSSPPWindows.exe "%SourceFileName%"
pcsx2 = %HOME%\pcsx2.exe "%SourceFileName%"
if A_LoopField contains pcsx-2
{
FileDelete, %A_WorkingDir%\%LogDir%\%SourceFileNoExt% - pcsx-2.bat
FileAppend, % pcsx2, %A_WorkingDir%\%LogDir%\%SourceFileNoExt% - pcsx-2.bat
;MsgBox, , Congratulations!, %SourceFileNoExt% - pcsx-2.bat`n`n Was successfully created in the %LogDir% directory
FileRead, gamelist, ..\gamelists\pcsx-2\gamelist.xml
doc := ComObjCreate("MSXML2.DOMDocument.6.0")
doc.async := false
doc.loadXML(gamelist)
try {
docNode := doc.selectSingleNode("//game[path='./" SourceFileName "']")
}catch e {
;ignore
}
if !docNode
;Msgbox, ,Please scrape from the front end, The %SourceFileName%`n was not found in the pcsx-2 gamelist
continue
{
Haystack := docNode.xml
Loop, Parse, Haystack, `n
if A_index = 2
{
Needle = <path>./%SourceFileNoExt% - pcsx-2.bat</path>
Haystack1 := StrReplace(Haystack, A_LoopField, Needle)
}
else
{
Ndle = - pcsx-2</name>
Haystack2 := StrReplace(Haystack1, "</name>", Ndle)
Haystack3 := StrReplace(Haystack2, "</game>", "</game>`n</gameList>")
}
FileRead, LogDirGameList, ..\gamelists\%LogDir%\gamelist.xml
if ErrorLevel = 0
{
;if LogDirGameList contains %SourceFileNoExt% - pcsx-2.bat
;continue
;{
;MsgBox, ,Please proceed, %SourceFileNoExt% - pcsx-2.bat`n`n Already exists in the`n`n %LogDir%\gamelist.xml
;}
;else
;{
LogDirGameList := StrReplace(LogDirGameList, "</gamelist>", Haystack3)
FileDelete, ..\gamelists\%LogDir%\gamelist.xml
FileAppend, %LogDirGameList%, ..\gamelists\%LogDir%\gamelist.xml
;MsgBox, , Congratulations!, %SourceFileNoExt% - pcsx-2.bat`n`n Was successfully created in the`n`n ..\gamelists\%LogDir%\gamelist.xml
;return
;}
}
if ErrorLevel = 1
{
NewXmlLogDir =
(join`r`n
<?xml version="1.0"?>
<gameList>
<game>
<path></path>
<name></name>
</game>
</gameList>
)
Haystack4 := StrReplace(NewXmlLogDir, "</gameList>", Haystack3)
FileAppend, %Haystack4%, ..\gamelists\%LogDir%\gamelist.xml
;MsgBox, , Congratulations!, %SourceFileNoExt% - pcsx-2.bat`n`n Was successfully created in the`n`n ..\gamelists\%LogDir%\gamelist.xml
;return
}
}
}
else
{
try {
BatchF := %SourceFileDir%
}
catch e {
;ignore
}
if !BatchF, goto FileSetAttribReturn
FileDelete, %A_WorkingDir%\%LogDir%\%SourceFileNoExt% - %SourceFileDir%.bat
FileAppend, %BatchF%, %A_WorkingDir%\%LogDir%\%SourceFileNoExt% - %SourceFileDir%.bat
;MsgBox, , Congratulations!, %SourceFileNoExt% - %SourceFileDir%.bat`n`n Was successfully created in the %LogDir% directory
FileRead, gamelist, ..\gamelists\%SourceFileDir%\gamelist.xml
doc := ComObjCreate("MSXML2.DOMDocument.6.0")
doc.async := false
doc.loadXML(gamelist)
try {
docNode := doc.selectSingleNode("//game[path='./" SourceFileName "']")
}catch e {
;ignore
}
if !docNode
;Msgbox, ,Please scrape from the front end, The %SourceFileName%`n was not found in the %SourceFileDir% gamelist
continue
else
{
Haystack := docNode.xml
Loop, Parse, Haystack, `n
if A_index = 2
{
Needle = <path>./%SourceFileNoExt% - %SourceFileDir%.bat</path>
Haystack1 := StrReplace(Haystack, A_LoopField, Needle)
}
else
{
Ndle = - %SourceFileDir%</name>
Haystack2 := StrReplace(Haystack1, "</name>", Ndle)
Haystack3 := StrReplace(Haystack2, "</game>", "</game>`n</gameList>")
}
FileRead, LogDirGameList, ..\gamelists\%LogDir%\gamelist.xml
if ErrorLevel = 0
{
;if LogDirGameList contains %SourceFileNoExt% - %SourceFileDir%.bat
;continue
;{
;MsgBox, ,Please proceed, %SourceFileNoExt% - %SourceFileDir%.bat`n`n Already exists in the`n`n ..\gamelists\%LogDir%\gamelist.xml
;}
;else
;{
LogDirGameList := StrReplace(LogDirGameList, "</gamelist>", Haystack3)
FileDelete, ..\gamelists\%LogDir%\gamelist.xml
FileAppend, %LogDirGameList%, ..\gamelists\%LogDir%\gamelist.xml
;MsgBox, , Congratulations!, %SourceFileNoExt% - %SourceFileDir%.bat`n`n Was successfully created in the`n`n ..\gamelists\%LogDir%\gamelist.xml
;return
;}
}
if ErrorLevel = 1
{
NewXmlLogDir =
(join`r`n
<?xml version="1.0"?>
<gameList>
<game>
<path></path>
<name></name>
</game>
</gameList>
)
Haystack4 := StrReplace(NewXmlLogDir, "</gameList>", Haystack3)
FileAppend, %Haystack4%, ..\gamelists\%LogDir%\gamelist.xml
;MsgBox, , Congratulations!, %SourceFileNoExt% - %SourceFileDir%.bat`n`n Was successfully created in the`n`n ..\gamelists\%LogDir%\gamelist.xml
;return
}
}
}
}
FileSetAttribReturn:
{
MsgBox, 4,Please select, Would you like to return the hidden files?
IfMsgBox, No, goto Congratulations
}
FileSetAttrib, -H, %A_WorkingDir%\nullDC\*.*
FileSetAttrib, -H, %A_WorkingDir%\Dolphin\*.*
FileSetAttrib, -H, %A_WorkingDir%\PPSSPP\*.*
FileSetAttrib, -H, %A_WorkingDir%\pcsx-2\*.*
MsgBox, ,Please proceed, Hidden files have been returned
Congratulations:
MsgBox, ,Congratulations!, All your batch files were successfully created in the %LogDir% directory.`n`n You are ready to test!
ExitApp