Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %% Generate scummvm files
- clear all
- iniPath = 'D:\LaunchBox\Emulators\ScummVM\scummvm.ini';
- launcherPath = 'R:\Finalized\Retro PC\[Various] ScummVM (Various)\Launch Files';
- confirm = input('This will erase all current launcher files and regenerate from .ini, are you sure? (''y'' to confirm)','s');
- if(~strcmp(confirm,'y'))
- error('Generation canceled by user');
- end
- if exist(launcherPath, 'dir')
- rmdir(launcherPath, 's')
- end
- % Load ini
- iniFile = fopen(iniPath);
- iniData = textscan(iniFile,'%s','Delimiter','\n');
- fclose(iniFile);
- iniData = iniData{1};
- % Find game entries
- entries = find(cellfun(@(x) (~isempty(x) && strcmp(x(1),'[')) ,iniData));
- entries = entries(2:end); % Remove scummvm section
- % Initialize data containers
- fullNames = cell.empty;
- shortNames = cell.empty;
- paths = cell.empty;
- kosherNames = cell.empty;
- folderNames = cell.empty;
- % Go through each entry
- for e = 1:length(entries)
- % % Gather info
- if(e == length(entries))
- fullEntry = iniData(entries(e):end);
- else
- fullEntry = iniData(entries(e):entries(e + 1) - 1);
- end
- shortNames{e} = iniData{entries(e)}(2:end - 1);
- for f = 1:length(fullEntry)
- if(length(fullEntry{f}) > 12 && strcmp(fullEntry{f}(1:11),'description'))
- fullNames{e} = fullEntry{f}(strfind(iniData{entries(1) + 1},'=') + 1:end);
- elseif(length(fullEntry{f}) > 4 && strcmp(fullEntry{f}(1:4),'path'))
- paths{e} = fullEntry{f}(strfind(iniData{entries(1) + 2},'=') + 1:end);
- backSlashes = strfind(paths{e},'\');
- folderNames{e} = paths{e}(backSlashes(end - 1) + 1:end - 1);
- end
- end
- % Make valid filename
- kosherNames{e} = strrep(fullNames{e},'\',' ');
- kosherNames{e} = strrep(kosherNames{e},'/',' ');
- kosherNames{e} = strrep(kosherNames{e},':',' -');
- kosherNames{e} = strrep(kosherNames{e},'*','');
- kosherNames{e} = strrep(kosherNames{e},'?','');
- kosherNames{e} = strrep(kosherNames{e},'"','''');
- kosherNames{e} = strrep(kosherNames{e},'<','[');
- kosherNames{e} = strrep(kosherNames{e},'>',']');
- kosherNames{e} = strrep(kosherNames{e},'|',';');
- % Create launcher file
- launcherDir = [launcherPath '\' kosherNames{e}];
- if ~exist(launcherDir, 'dir')
- mkdir(launcherDir)
- end
- launcherFile = fopen([launcherDir '\' shortNames{e} '.scummvm'],'w');
- fprintf(launcherFile,'%s',shortNames{e});
- fclose(launcherFile);
- end
Add Comment
Please, Sign In to add comment