Lanzador de aplicaciones portables

Todas los scripts relacionados con AMS.
Con este código crea fácilmente lanzadores de aplicaciones, es decir crea una lista de apps y ejecutalas =)

Incluye soporte de línea de comandos, por ejemplo como en este caso, permite enviar ROMs de distintas consolas y mandarlos al emulador adecuado.

self: contiene el nombre, version, acceso a los parámetros de la línea de comandos, carpeta root, carpeta de 'apps' donde guardamos los ejecutables. El procedimiento init() inicializa las apps, las tags o categorías y demás.

incluye algunas funciones como forEach para recorrer las tablas.
además incluye los mensajes comunes de JavaScript: alert, confirm, prompt y un adicional select.

esta sin terminar, así que es para trabajar en el.

--------------------------------------------------
--------------------------------------------------
self = {}
self.name = 'Lanzador de aplicaciones portables'
self.version = '1.0.0.0'
self.parameters = _CommandLineArgs
self.rootFolder = _SourceFolder
self.appsFolder = self.rootFolder .. '\\emu\\'
--------------------------------------------------
self.init = function()
--------------------------------------------------
-- apps table
newApp('No$gba mod','2.7a',self.appsFolder .. 'no$gba_','no$gba.exe',{'Game Boy Advance', 'Nintendo DS'})
--newApp('No$gba mod Noise Reducer','1.0',self.appsFolder .. 'no$gba_','no$gba noise reducer.exe',{''})
newApp('No$gba','2.6a',self.appsFolder .. 'no$gba','no$gba.exe',{'Game Boy Advance', 'Nintendo DS'})
--newApp('No$gba Run Tool','1.0',self.appsFolder,'autoit.exe',{''})
--newApp('No$pmp','0.40',self.appsFolder .. 'no$gba','no$pmp.exe',{''})
--newApp('No$wtt','0.36',self.appsFolder .. 'no$gba','no$wtt.exe',{''})
newApp('No$Zoomer','2.3.0.2',self.appsFolder .. 'no$gba','no$zoomer.exe',{'Game Boy Advance', 'Nintendo DS'})
newApp('MyZoom','1.8.36',self.appsFolder .. 'no$gba','myzoom.exe',{'Nintendo DS'})
newApp('NgZoom','1.0',self.appsFolder .. 'no$gba','ngzoom.exe',{'Nintendo DS'})
newApp('No$Mooz','1.0',self.appsFolder .. 'no$gba','no$mooz.exe',{'Nintendo DS'})
newApp('Noz','2.3',self.appsFolder .. 'no$gba','noz.exe',{'Nintendo DS'})
newApp('No$gba 2x','2.6a',self.appsFolder .. 'no$gba','no$gba2x.exe',{'Nintendo DS'})
newApp('DeSmuME','0.9.10 r4831',self.appsFolder .. 'desmume','desmume.exe',{'Nintendo DS'})
newApp('VBA-Link','1.8.0',self.appsFolder .. 'vbalink','vbalink.exe',{'Game Boy', 'Game Boy Color', 'Game Boy Advance'})
newApp('VBA-M','1.8.0 r1226',self.appsFolder .. 'vbam','vbam.exe',{'Game Boy', 'Game Boy Color', 'Game Boy Advance'})
--------------------------------------------------
-- tags table
tags = {}
tags['Game Boy'] = {'.gb','.gmb','.sgb'}
tags['Game Boy Color'] = {'.cgb','.gbc'}
tags['Game Boy Advance'] = {'.agb','.bin','.elf','.gba','.mb'}
tags['Nintendo DS'] = {'.dsi','.nds','.pme','.srl'}
--------------------------------------------------
-- files table
files.init()
--------------------------------------------------
-- parameters
if Table.Count(self.parameters) > 0 then
files.changeFile(self.parameters[1])
files.openWith()
else
if files.open() then
files.openWith()
end
end
--Application.Exit(0)
os.exit()
--------------------------------------------------
end
--------------------------------------------------
--------------------------------------------------
-- table iterator

function forEach(pairsTable,fun)
for index,element in pairs(pairsTable) do
fun(element,index,array)
end
end

--------------------------------------------------
-- dialogs

function alert(message)
Dialog.Message(self.name, message, MB_OK, MB_ICONNONE, MB_DEFBUTTON1)
end

function confirm(message)
if Dialog.Message(self.name, message, MB_YESNO, MB_ICONNONE, MB_DEFBUTTON1) == 6 then
return true
end
return false
end

function prompt(message,value)
Dialog.Input(self.name, message, value, MB_ICONNONE)
end

function select(message,items)
local selected = Dialog.ComboBox(self.name, message, items, '', true, false, MB_ICONNONE)

if (selected == 'CANCEL') or (selected == '') then
return ''
else
return selected
end
end

--------------------------------------------------
-- apps table

apps = {}

function createApp(name,version,folder,executable,tags)
local self = {}

self.name = name
self.version = version
self.folder = folder .. '\\'
self.executable = executable
self.tags = tags
Table.Sort(self.tags)

self.run = function(args)
return File.Run(self.folder .. self.executable, args, self.folder, SW_SHOWNORMAL, false)
end

return self
end

function newApp(name,version,folder,executable,tags)
apps[name] = createApp(name,version,folder,executable,tags)
end

--------------------------------------------------
-- files table

files = {}
files.filter = "All Files (*.*)|*.*|"
files.generateFilter = function()
local filter = ''
local all_filters = self.name .. '|'

-- file extension in tags
forEach(tags,function(element,index,array)
local y = Table.Count(element)
filter = filter .. index .. '|'
for x = 1,y do
filter = filter .. '*' .. element[x] .. ';'
all_filters = all_filters .. '*' .. element[x] .. ';'
end
filter = filter .. '|'
end)

all_filters = all_filters .. '|'
files.filter = all_filters .. filter
end
files.lastFolder = _DesktopFolder
files.lastFilePath = {}
files.lastFileTag = ''
files.history = {}
files.historyLastFile = function()
return files.history[Table.Count(files.history)-1]
end
files.open = function()
local file = Dialog.FileBrowse(true, self.name, files.lastFolder, files.filter, "", "", false, true);

if (file[1] == 'CANCEL') or (file == nil) then
return false
else
files.changeFile(file[1])
return true
end
end
files.changeFile = function(file)
Table.Insert(files.history, Table.Count(files.history), '\"' .. file .. '\"')
files.lastFilePath = String.SplitPath(file)
files.lastFolder = files.lastFilePath.Drive .. files.lastFilePath.Folder
end
files.openWith = function()
-- tag: check file extension in tags
forEach(tags,function(element,index,array)
local y = Table.Count(element)

for x = 1,y do
if String.CompareNoCase(element[x],files.lastFilePath.Extension) == 0 then
files.LastFileTag = index
end
end
end)

local match_apps = {}

-- apps: check tag in apps tags
forEach(apps,function(element,index,array)
local y = Table.Count(element.tags)

for x = 1,y do
if element.tags[x] == files.LastFileTag then
Table.Insert(match_apps,Table.Count(match_apps),element.name)
end
end
end)

-- apps: select app from list
if Table.Count(match_apps) > 0 then
local selected = select(files.LastFileTag,match_apps)
if selected ~= '' then
apps[selected].run(files.historyLastFile())
end
else
alert('Unknown file extension ' .. files.lastFilePath.Extension)
end
end
files.init = function()
files.generateFilter()
end

--------------------------------------------------
-- init

self.init()

--------------------------------------------------


Como usar:

- Se inicia automáticamente al final del script con self.init(), en el apartado --parameters hay una se evalua si hay archivos enviados por línea de comandos, lo evalua con files.openWith y de otra forma cierra el programa.
- Agrega tus aplicaciones dentro del método self.init() con newApp(), se agregarán a la tabla 'apps'
- newApp(nombre,version,carpeta,exe,{categorías})
- Agrega las categorías o tags como ves en el script junto con las extensiones de archivo. Por ejemplo podría agregar tags['Música'] = {'.mp3','.wma','.ogg'}
- files maneja los archivos, con files.open() muestra el cuadro de diálogo con las categorías agregadas en las tags (el filtro de extensiones de archivo del cuadro de diálogo se genera con files.generateFilter al llamar files.init() o cuando necesites llamarlo si has cambiado en otro lugar de la aplicacion las tags, el filtro puede ser accedido desde files.filter)
- files.openWith() muestra una lista de apps compatibles con el archivo abierto. En el ejemplo del script si el archivo es .nds se podrá abrir con las apps no$gba y desmume entre otras. Por defecto usa el último archivo abierto con files.open()
- files.history guarda una lista de todos los archivos abiertos en la ejecución del programa. files.historyLastFile obtiene el último archivo del historial de archivos. files.historyLastFolder obtene la última carpeta abierta desde files.open().
- files.changeFile(archivo) agrega un nuevo archivo al historial.

Lista de tablas y funciones
self = {}
self.name
self.version
self.parameters
self.rootFolder
self.appsFolder
self.init

tags = {}

forEach(parsTable,fun)
alert(message)
confirm(message)
prompt(message,value)
select(message,items)

apps = {}
createApp(name,version,folder,executable,tags) -> retorna una tabla
newApp(name,version,folder,executable,tags) -> agrega la app en 'apps'

files = {}
files.filter
files.generateFilter
files.lastFolder
files.lastFilePath
files.lastFileTag
files.history
files.historyLastFile()
files.open()
files.changeFile(file)
files.openWith()
files.init()

Flujo de eventos:
self
->self.init
-> newApp
-> tags
-> files.init
-> --parameters / exit

curioso. :hypno: