---- LUA XMB Theme Cycler v0.2
---- Author: LuizLizard
-----------------------------------------------
---- Some code grabbed from SG57 flash example.

green = Color.new(0,255,0)
magenta = Color.new(255,0,255)
white = Color.new(255,255,255)
red = Color.new(255,0,0)
blue = Color.new(0,0,255)
yellow = Color.new(255,255,0)
control = 0

-- Load number of themes
max = 0
dirlist = System.listDirectory("ms0:/themecycler")
for index,file in ipairs(dirlist) do
if dirlist[index].directory then
max = max + 1
end
end
max = max - 2

-- Open and check wich theme to flash and increase count by 1 and reset to 0 if count = maximum
file = io.open("control.txt", "r")
if file then
control = file:read("*n")
file:close()
end
theme = control
control = control + 1
if control > max then
control = 1
end
file = io.open("control.txt", "w")
file:write(control)
file:close()
--

-- Flash specified theme
-- Unassing flash0
System.Unassign("flash0:")
-- Reassing flash0 with writing rights
System.Assign("flash0:", "lflash0:0,0", "flashfat0:")
-- Set Phats
topmenu_plugin = "ms0:/themecycler/"..theme.."/topmenu_plugin.rco"
opening_plugin = "ms0:/themecycler/"..theme.."/opening_plugin.rco"
savedata_plugin = "ms0:/themecycler/"..theme.."/savedata_plugin.rco"
gameboot = "ms0:/themecycler/"..theme.."/gameboot.pmf"
system_plugin = "ms0:/themecycler/"..theme.."/system_plugin.rco"
background = "ms0:/themecycler/"..theme.."/01-12.bmp"
impose_plugin = "ms0:/themecycler/"..theme.."/impose_plugin.rco"
premo_plugin = "ms0:/themecycler/"..theme.."/premo_plugin.rco"
system_plugin_fg = "ms0:/themecycler/"..theme.."/system_plugin_fg.rco"
system_plugin_bg = "ms0:/themecycler/"..theme.."/system_plugin_bg.rco"
photo_plugin = "ms0:/themecycler/"..theme.."/photo_plugin.rco"
game_plugin = "ms0:/themecycler/"..theme.."/game_plugin.rco"
sysconf_plugin = "ms0:/themecycler/"..theme.."/sysconf_plugin.rco"
ltn0 = "ms0:/themecycler/"..theme.."/ltn0.pgf"
-- Start flashing
file = io.open(topmenu_plugin, "r")
if file then
		System.writeFile(topmenu_plugin,"flash0:/vsh/resource/topmenu_plugin.rco","no")
file:close()
end

file = io.open(opening_plugin, "r")
if file then
		System.writeFile(opening_plugin,"flash0:/vsh/resource/opening_plugin.rco","no")
file:close()
end

file = io.open(savedata_plugin, "r")
if file then
		System.writeFile(savedata_plugin,"flash0:/vsh/resource/savedata_plugin.rco","no")
		file:close()
end

file = io.open(gameboot, "r")
if file then		
		System.writeFile(gameboot,"flash0:/vsh/resource/gameboot.pmf","no")
		file:close()
end

file = io.open(system_plugin, "r")
if file then		
		System.writeFile(system_plugin,"flash0:/vsh/resource/system_plugin.rco","no")
		file:close()
end

file = io.open(background, "r")
if file then
		System.writeFile(background,"flash0:/vsh/resource/01-12.bmp","no")
		file:close()
end

file = io.open(impose_plugin, "r")
if file then
		System.writeFile(impose_plugin,"flash0:/vsh/resource/impose_plugin.rco","no")
		file:close()
end

file = io.open(premo_plugin, "r")
if file then
        System.writeFile(premo_plugin,"flash0:/vsh/resource/premo_plugin.rco","no")
		file:close()
end

file = io.open(system_plugin_fg, "r")
if file then
		System.writeFile(system_plugin_fg,"flash0:/vsh/resource/system_plugin_fg.rco","no")
		file:close()
end

file = io.open(system_plugin_bg, "r")
if file then
		System.writeFile(system_plugin_bg,"flash0:/vsh/resource/system_plugin_bg.rco","no")
		file:close()
end

file = io.open(photo_plugin, "r")
if file then	
		System.writeFile(photo_plugin,"flash0:/vsh/resource/photo_plugin.rco","no")
		file:close()
end

file = io.open(game_plugin, "r")
if file then
		System.writeFile(game_plugin,"flash0:/vsh/resource/game_plugin.rco","no")
		file:close()
end

file = io.open(sysconf_plugin, "r")
if file then
		System.writeFile(sysconf_plugin,"flash0:/vsh/resource/sysconf_plugin.rco","no")
		file:close()
end

file = io.open(ltn0, "r")
if file then
		System.writeFile(ltn0,"flash0:/font/ltn0.pgf","no")
		file:close()
end

-- End Program (Return to XMB)
System.Quit()
















