[Windows Mobile Software Development] RoryB:
@Noonski

I have not been working on my script for a while, but I have just finished dealing with the multiple config_???.txt files and also FILEOP: command.

Here are the portions of my script.

The part that develops the list of config files. First by looking in Config_operator.txt to see if it refers you to the next one with CFG: and then looks in that one for another CFG: and so on. Then it compares to a list of config files I know of and lastly checks the \windows\ folder for any others.

###############################
# Generate list of Config.txt files
###############################
cfglist[1]=ToLower("\extended_rom\config.txt")
cfglist[2]=ToLower("\windows\config_operator.txt")
If( FileExists("\windows\config_operator.txt"))
i=2
xDir1=ToLower("\windows\config_operator.txt")
zcount = "1"
While(zcount EQ "1")
xDir=xDir1
zcount = "0"
xcount = ReadLine( xDir )
While( IsEmpty( xcount ) = FALSE )
If( SubStr( xcount, 1, 5 ) EQ "CFG: " )
If( FileExists( SubStr( xcount, 6 ) ))
i=i+1
cfglist[I] = ToLower(SubStr( xcount, 6 ))[/I]
[I] xDir1 = SubStr( xcount, 6 )[/I]
[I] zcount = "1"[/I]
[I] EndIf[/I]
[I]EndIf[/I]
[I]xcount = ReadLine( xDir )[/I]
[I] EndWhile[/I]
[I]EndWhile[/I]
[I]EndIf[/I]
[I]cfglist=join( cfglist, ", ")[/I]
[I]ForEach ycfg in values( "\extended_rom\config.txt", "\windows\config_operator.txt", "\windows\config_pt.txt", "\windows\config_ap.txt", "\windows\config_end.txt", "\windows\config.txt", "\sp_rom\config_sp.txt" )[/I]
[I]If( NOT find( cfglist, ycfg ) )[/I]
[I] cfglist =replace( cfglist, cfglist, cfglist & ", " & ycfg )[/I]
[I]EndIf[/I]
[I]EndForEach[/I]
[I]ForEach zcfg in Files( "\windows\*config*.txt" )[/I]
[I]If( NOT find( cfglist, zcfg ) )[/I]
[I] cfglist =replace( cfglist, cfglist, cfglist & ", " & zcfg )[/I]
[I]EndIf[/I]
[I]EndForEach[/I]

After I generate my list, I run the parser.

[I]###############################[/I]
[I]# Config.txt without AutoRun or RunCC[/I]
[I]# and Extra Config.txt files of RunCC[/I]
[I]###############################[/I]
[I]ForEach xcfg in array (split(cfglist, ", "))[/I]
[I]If( FileExists( xcfg ) )[/I]
[I]xDir = xcfg[/I]
[I]Call( "CfgParser", xDir )[/I]
[I]EndIf[/I]
[I]EndForEach[/I]

After this I run a SDCard config parser. I allow one in SDAUTO to let people use my additional config parser features and keep one in root of SDCard so they can switch back and forth to other UC ROMs. If they do not have a config in SDAUTO, it runs the one in root of SDCard.

[I]###############################[/I]
[I]# SDConfig without SDAutoRun[/I]
[I]###############################[/I]
[I]If( FileExists( "\Storage Card\SDAUTO\Config.txt" ) )[/I]
[I] xDir = "\Storage Card\SDAUTO\Config.txt"[/I]
[I] Call( "CfgParser", xDir )[/I]
[I]ElseIf( FileExists( "\Storage Card\SDConfig.txt" ) )[/I]
[I] xDir = "\Storage Card\SDConfig.txt"[/I]
[I] Call( "CfgParser", xDir )[/I]
[I]EndIf[/I]

Here are the subroutines.

Parser for config files

###############################
# Subroutine CfgParser
###############################
Sub CfgParser
xcount = ReadLine( xDir )
While( IsEmpty( xcount ) = FALSE )
If( SubStr( xcount, 1, 5 ) EQ "CPY1:" )
xcopy1 = SubStr( xcount, 6 )
xcount = ReadLine( xDir )
If( SubStr( xcount, 1, 5 ) eq "CPY2:" )
xcopy2 = SubStr( xcount, 6 )
If( FileExists( xcopy1 ))
Copy( xcopy1, xcopy2, TRUE )
EndIf
EndIf
ElseIf( SubStr( xcount, 1, 5 ) EQ "SCT1:" )
xcopy1 = SubStr( xcount, 6 )
xcount = ReadLine( xDir )
If( SubStr( xcount, 1, 5 ) eq "SCT2:" )
xcopy2 = SubStr( xcount, 6 )
CreateShortcut( xcopy1, xcopy2, TRUE )
EndIf
ElseIf( SubStr( xcount, 1, 5 ) eq "ZIP: " )
If( FileExists( SubStr( xcount, 6 ) ))
UnZipAll( SubStr( xcount, 6 ), "" )
EndIf
ElseIf( SubStr( xcount, 1, 5 ) eq "CAB: " )
If( FileExists( SubStr( xcount, 6 ) ))
RunWait( "\windows\wceload.exe", "/nodelete /silent " & """" & SubStr( xcount, 6 ) & """" )
EndIf
ElseIf( SubStr( xcount, 1, 5 ) eq "XML: " )
If( SubStr( xcount, -4 ) ne "mscr" )
If( FileExists( SubStr( xcount, 6 ) ))
RunWait( "\windows\dfTaskMgr.exe", "/provxml " & SubStr( xcount, 6 ))
EndIf
EndIf
ElseIf( SubStr( xcount, 1, 5 ) eq "REG: " )
If( FileExists( SubStr( xcount, 6 ) ))
RunWait( "\windows\dfTaskMgr.exe", SubStr( xcount, 6 ) & " /silent" )
EndIf
ElseIf( SubStr( xcount, 1, 5 ) eq "TSK: " )
If( SubStr( xcount, -4 ) ne "mscr" )
If( FileExists( SubStr( xcount, 6 ) ))
xCopy( SubStr( xcount, 6 ), "\windows")
RunWait( "\Windows\custsk.exe", "\windows\" & filebase( SubStr( xcount, 6 ) ) & ".tsk" )
EndIf
EndIf
ElseIf( SubStr( xcount, 1, 5 ) eq "EXEC:" )
If( FileExists( SubStr( xcount, 6 ) ))
Run( SubStr( xcount, 6 ))
EndIf
ElseIf( SubStr( xcount, 1, 5 ) eq "MKDR:" )
MkDir( SubStr( xcount, 6 ))
ElseIf( SubStr( xcount, 1, 5 ) eq "MSCR:" )
If( FileExists( SubStr( xcount, 6 ) ))
CallScript( SubStr( xcount, 6 ) )
EndIf
ElseIf( SubStr( xcount, 1, 5 ) eq "MCAB:" )
If( FileExists( SubStr( xcount, 6 ) ))
RunWait( "\windows\wceload.exe", "/nodelete " & """" & SubStr( xcount, 6 ) & """" )
EndIf
ElseIf( SubStr( xcount, 1, 5 ) eq "SCAB:" )
If( FileExists( SubStr( xcount, 6 ) ))
Run( "\windows\wceload.exe", "/nodelete " & """" & SubStr( xcount, 6 ) & """" )
WaitFor( "Installation",3 )
SendDown( "Installation" )
SendSPACE( "Installation" )
SendLeftSoft
While( WndExists( "Installing" ) )
sleep( 500 )
EndWhile
SendOK( "Installation" )
While( ProcExists( "wceload.exe") )
sleep(500)
EndWhile
EndIf
ElseIf( SubStr( xcount, 1, 5 ) eq "FILEO" )
xDir2 = SubStr( xcount, 8 )
If( FileExists( xDir2 ))
Call( "FileOPer", xDir2 )
EndIf
Else
EndIf
xcount = ReadLine( xDir )
Sleep( 1000 )
Show( "Desktop" )
EndWhile
EndSub

and parser for FILEOP: to copy and then change attributes. I have seen very few of these files and only saw Removeattribute, but I have an addattribute feature too.

###############################
# Subroutine FileOP Parser
###############################
Sub FileOPer
ForEach destin, sorce in iniKeys ( xDir2, "" )
Call( "Dirconv", xDir2 )
If( FileExists( sorce ))
copy( sorce, destin, TRUE)
EndIf
EndForEach
ForEach destin, sorce in iniKeys ( xDir2, "" )
Call( "Dirconv", xDir2 )
If( Find( destin, ":" ))
destin1=substr( destin, Find( destin, ":" )+1 )
destin=substr( destin, "1", Find( destin, ":" )-1)
If( FileExists( destin ))
If( sorce EQ "addattribute" )
sorce="TRUE"
ElseIf( sorce EQ "removeattribute" )
sorce="FALSE"
Else
sorce=""
EndIf
If(sorce NE "" )
ForEach att in charsOf( destin1 )
If( att EQ "r")
att="readonly"
ElseIf( att EQ "h")
att="hidden"
ElseIf( att EQ "s")
att="system"
ElseIf( att EQ "a")
att="archive"
EndIf
SetFileAttribute( destin, att, sorce )
EndForEach
EndIf
EndIf
EndIf
EndForEach
EndSub

The FileOP.txt files I saw included %CE% macros for paths so I wrote a subroutine to fix those to regular paths for mortscript to use.

###############################
# Subroutine Dirconv
###############################
Sub Dirconv
DirMac=Array( "%ce1%", "\Program Files", "%ce2%", "\Windows", "%CE3%", "\My Documents", "%ce4%", "\Windows\StartUp", "%ce5%", "\My Documents", "%ce6%", "\Program Files\Accessories", "%ce7%", "\Program Files\Communications", "%ce8%", "\Program Files\Games", "%CE9%", "\Program Files\Pocket Outlook", "%CE10%", "\Program Files\Office", "%ce11%", "\Windows\Start Menu\Programs", "%ce12%", "\Windows\Start Menu\Programs\Accessories", "%ce13%", "\Windows\Start Menu\Programs\Communications", "%ce14%", "\Windows\Start Menu\Programs\Games", "%ce15%", "\Windows\Fonts", "%ce17%", "\Windows\Start Menu" )
sorce=ToLower( sorce )
destin=ToLower( destin )
destin=substr(destin, "2", length(destin)-2)
int = MaxIndex( DirMac )
i = 1
While (int GT 0)
destin=Replace( destin, DirMac[i], DirMac[i+1] )
sorce=Replace( sorce, DirMac[i], DirMac[i+1] )
i=i+2
int=int-2
EndWhile
EndSub