It turned out that I had the brackets in the wrong place. I've added a lot more script to it. It all works now!
Code: Select all
SetWorkingDir %A_ScriptDir%
LogDir := "favorites"
IfNotExist, %CLogDir%
FileCreateDir, %LogDir%
IfNotExist, ..\gamelists\%LogDir%
FileCreateDir, ..\gamelists\%LogDir%
;MsgBox, , Please proceed, Your batch files will be saved in the %LogDir% directory
FileRead, systemsconfig, ..\systems.cfg
;MsgBox, ,Please wait, Checking if the %LogDir% system exists in the systems.cfg
IfInString, systemsconfig, %LogDir%
{
MsgBox, ,Please proceed, The %LogDir% system already exists
goto FileSetAttrib
}
IfNotInString, systemsconfig, %LogDir%
{
;MsgBox, ,Please wait, The %LogDir% system needs to be created
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 FileSelectFile
}
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
FileSelectFile:
FileSelectFile, SourceFiles, M3, %A_WorkingDir%, Please select Roms you wish to add to the %LogDir%
{
MsgBox, 4,Please select, Would you like to return the hidden files?
IfMsgBox, No, goto Next
}
FileSetAttrib, -H, %A_WorkingDir%\nullDC\*.*
FileSetAttrib, -H, %A_WorkingDir%\Dolphin\*.*
FileSetAttrib, -H, %A_WorkingDir%\PPSSPP\*.*
FileSetAttrib, -H, %A_WorkingDir%\pcsx-2\*.*
Next:
if SourceFiles =
{
MsgBox, ,Thank you!, You chose not to create the batch file.`n`n Goodbye!
return
}
Loop, parse, SourceFiles, `n
if A_Index = 1
{
Array := StrSplit(A_LoopField, "\")
SrcFileFolder := StrReplace(Array[6], "-")
;MsgBox, ,Please proceed, The selected files come from`n %SrcFileFolder%`n Folder.
}
else
{
SplitPath, A_LoopField, SourceFileName, SourceFileDir, SourceFileExt, SourceFileNoExt
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 SourceFileDir 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='./" SourceFileNoExt "']") ;will select the first game with the SourceFileNoExt
}catch e {
;ignore
}
if !docNode
Msgbox, ,Please scrape from the front end, The %SourceFileName%`n was not found in the pcsx-2 gamelist
{
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%
{
MsgBox, ,Please proceed, %SourceFileNoExt% - pcsx-2.bat`n`n Was found 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% - 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
{
BatchF := %SrcFileFolder%
FileDelete, %A_WorkingDir%\%LogDir%\%SourceFileNoExt% - %SrcFileFolder%.bat
FileAppend, %BatchF%, %A_WorkingDir%\%LogDir%\%SourceFileNoExt% - %SrcFileFolder%.bat
MsgBox, , Congratulations!, %SourceFileNoExt% - %SrcFileFolder%.bat`n`n Was successfully created in the %LogDir% directory
FileRead, gamelist, ..\gamelists\%SrcFileFolder%\gamelist.xml
doc := ComObjCreate("MSXML2.DOMDocument.6.0")
doc.async := false
doc.loadXML(gamelist)
try {
docNode := doc.selectSingleNode("//game[path='./" SourceFileName "']") ;will select the first game with the SourceFileName
}catch e {
;ignore
}
if !docNode
Msgbox, ,Please scrape from the front end, The %SourceFileName%`n was not found in the %SrcFileFolder% gamelist
else
{
Haystack := docNode.xml
Loop, Parse, Haystack, `n
if A_index = 2
{
Needle = <path>./%SourceFileNoExt% - %SrcFileFolder%.bat</path>
Haystack1 := StrReplace(Haystack, A_LoopField, Needle)
}
else
{
Ndle = - %SrcFileFolder%</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%
{
MsgBox, ,Please proceed, %SourceFileNoExt% - %SrcFileFolder%.bat`n`n Was found 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% - %SrcFileFolder%.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% - %SrcFileFolder%.bat`n`n Was successfully created in the`n`n ..\gamelists\%LogDir%\gamelist.xml
return
}
}
}
}
ExitApp
/*
;;;;;;;;;;;;;;;;;;;;;;; gamelist.xml format ;;;;;;;;;
<?xml version="1.0"?>
<gameList>
<game>
<path></path>
<name></name>
<desc></desc>
<image></image>
<rating></rating>
<releasedate></releasedate>
<developer></developer>
<publisher></publisher>
<genre></genre>
<playcount></playcount>
<lastplayed></lastplayed>
</game>
<game>
<path></path>
<name></name>
<desc></desc>
<image></image>
<rating></rating>
<releasedate></releasedate>
<developer></developer>
<publisher></publisher>
<genre></genre>
<playcount></playcount>
<lastplayed></lastplayed>
</game>
</gameList>
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;##################### systems.cfg format ################
<systemList>
<system>
<name></name>
<fullname></fullname>
<path></path>
<extension></extension>
<command></command>
<theme></theme>
</system>
<system>
<name></name>
<fullname></fullname>
<path></path>
<extension></extension>
<command></command>
<theme></theme>
</system>
</systemList>
;##########################################################
*/