oblivioncth

ScummVM Shortname Polling For LB

May 18th, 2020
147
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. %% Generate scummvm files
  2. clear all
  3.  
  4. iniPath = 'D:\LaunchBox\Emulators\ScummVM\scummvm.ini';
  5. launcherPath = 'R:\Finalized\Retro PC\[Various] ScummVM (Various)\Launch Files';
  6.  
  7. confirm = input('This will erase all current launcher files and regenerate from .ini, are you sure? (''y'' to confirm)','s');
  8.  
  9. if(~strcmp(confirm,'y'))
  10.     error('Generation canceled by user');
  11. end
  12.  
  13. if exist(launcherPath, 'dir')
  14.    rmdir(launcherPath, 's')
  15. end
  16.  
  17. % Load ini
  18. iniFile = fopen(iniPath);
  19. iniData = textscan(iniFile,'%s','Delimiter','\n');
  20. fclose(iniFile);
  21. iniData = iniData{1};
  22.  
  23. % Find game entries
  24. entries = find(cellfun(@(x) (~isempty(x) && strcmp(x(1),'[')) ,iniData));
  25. entries = entries(2:end); % Remove scummvm section
  26.  
  27. % Initialize data containers
  28. fullNames = cell.empty;
  29. shortNames = cell.empty;
  30. paths = cell.empty;
  31. kosherNames = cell.empty;
  32. folderNames = cell.empty;
  33.  
  34. % Go through each entry
  35. for e = 1:length(entries)
  36.    
  37.     % % Gather info
  38.     if(e == length(entries))
  39.         fullEntry = iniData(entries(e):end);
  40.     else
  41.         fullEntry = iniData(entries(e):entries(e + 1) - 1);
  42.     end
  43.    
  44.     shortNames{e} = iniData{entries(e)}(2:end - 1);
  45.    
  46.     for f = 1:length(fullEntry)
  47.         if(length(fullEntry{f}) > 12 && strcmp(fullEntry{f}(1:11),'description'))
  48.             fullNames{e} = fullEntry{f}(strfind(iniData{entries(1) + 1},'=') + 1:end);
  49.         elseif(length(fullEntry{f}) > 4 && strcmp(fullEntry{f}(1:4),'path'))
  50.             paths{e} = fullEntry{f}(strfind(iniData{entries(1) + 2},'=') + 1:end);
  51.             backSlashes = strfind(paths{e},'\');
  52.             folderNames{e} = paths{e}(backSlashes(end - 1) + 1:end - 1);
  53.         end
  54.     end
  55.    
  56.     % Make valid filename
  57.     kosherNames{e} = strrep(fullNames{e},'\',' ');
  58.     kosherNames{e} = strrep(kosherNames{e},'/',' ');
  59.     kosherNames{e} = strrep(kosherNames{e},':',' -');
  60.     kosherNames{e} = strrep(kosherNames{e},'*','');
  61.     kosherNames{e} = strrep(kosherNames{e},'?','');
  62.     kosherNames{e} = strrep(kosherNames{e},'"','''');
  63.     kosherNames{e} = strrep(kosherNames{e},'<','[');
  64.     kosherNames{e} = strrep(kosherNames{e},'>',']');
  65.     kosherNames{e} = strrep(kosherNames{e},'|',';');
  66.    
  67.     % Create launcher file
  68.     launcherDir = [launcherPath '\' kosherNames{e}];
  69.     if ~exist(launcherDir, 'dir')
  70.        mkdir(launcherDir)
  71.     end
  72.    
  73.     launcherFile = fopen([launcherDir '\' shortNames{e} '.scummvm'],'w');
  74.     fprintf(launcherFile,'%s',shortNames{e});
  75.     fclose(launcherFile);
  76. end
RAW Paste Data Copied