romloader 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/README.md +2 -0
 - data/lib/romloader/archive_extractor.rb +44 -42
 - data/lib/romloader/romloader_cli.rb +33 -14
 - metadata +1 -1
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: ad9d09bd1aafb62ad873edd616512de5e887d4bd
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 827d0debcc137eb05ac9dfc3c5d8dfa4358c2323
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: ad01221bb446839ee8caa995a8c03514fde47d4ca01fb4a697226a50b0acb1fa9334ebc35d94e5a3047ab81e2620b04b1b09cdbfe06f7c8def80a9dca60f6bc0
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 5f40abfdf5c3aa19f243f63a58181415d17d25394074173e5fc2e4d1c72aff5668654d9c87c84b875313e077266aa738210195a7d06b9d09b28c4df48d9b2429
         
     | 
    
        data/README.md
    CHANGED
    
    | 
         @@ -27,6 +27,8 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/jinstr 
     | 
|
| 
       27 
27 
     | 
    
         | 
| 
       28 
28 
     | 
    
         
             
            ## Version Changes
         
     | 
| 
       29 
29 
     | 
    
         | 
| 
      
 30 
     | 
    
         
            +
            v. 1.2: Added basic file managment capability for Windows (requires Powershell v 3.0 or higher). Also updated UI slightly.
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
       30 
32 
     | 
    
         
             
            v. 1.1: Added basic rom download capability for Windows (requires Powershell v 3.0 or higher)
         
     | 
| 
       31 
33 
     | 
    
         | 
| 
       32 
34 
     | 
    
         
             
            v. 1.0: Changed the namespacing of classes, added zip/7-zip extraction and rom download directory management. Also, added the ability to open the newly downloaded game from the command line (requires a emulator)
         
     | 
| 
         @@ -2,59 +2,61 @@ 
     | 
|
| 
       2 
2 
     | 
    
         
             
            class RomLoader::ArchiveExtractor
         
     | 
| 
       3 
3 
     | 
    
         | 
| 
       4 
4 
     | 
    
         
             
              #Extracts zip or 7-zip rom files, manages the extracted dirs, then deletes archive files
         
     | 
| 
       5 
     | 
    
         
            -
              def self.extract( 
     | 
| 
      
 5 
     | 
    
         
            +
              def self.extract(archive_dir,extract_dir,game_obj)
         
     | 
| 
       6 
6 
     | 
    
         
             
                file_or_dir_to_open = nil
         
     | 
| 
       7 
     | 
    
         
            -
                /(?<=\().+(?=\))/.match(game_obj.system.name) ? system_name = /(?<=\().+(?=\))/.match(game_obj.system.name)[0] : system_name = nil
         
     | 
| 
       8 
     | 
    
         
            -
                system_name ||= game_obj.system.name
         
     | 
| 
       9 
     | 
    
         
            -
                system_name = system_name.rstrip.gsub(/[[[:space:]]\/]/, "_").downcase
         
     | 
| 
       10 
     | 
    
         
            -
                dir_w_system = File.join(Dir.home,"videogame_roms",system_name)
         
     | 
| 
       11 
7 
     | 
    
         
             
                dir_game_name = game_obj.filename.split(game_obj.file_ext)[0]
         
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
     | 
    
         
            -
                 
     | 
| 
       14 
     | 
    
         
            -
                
         
     | 
| 
       15 
     | 
    
         
            -
                if game_obj.system.name != "MAME"
         
     | 
| 
      
 8 
     | 
    
         
            +
                  
         
     | 
| 
      
 9 
     | 
    
         
            +
                if game_obj.file_ext == ".zip"
         
     | 
| 
       16 
10 
     | 
    
         
             
                  puts "Extracting #{game_obj.filename}"
         
     | 
| 
       17 
     | 
    
         
            -
                   
     | 
| 
       18 
     | 
    
         
            -
                     
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
                       
     | 
| 
       22 
     | 
    
         
            -
                         
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
                         
     | 
| 
       25 
     | 
    
         
            -
                          rom.extract(File.join(dir_w_system,rom.name)) unless File.exist?(File.join(dir_w_system,rom.name))
         
     | 
| 
       26 
     | 
    
         
            -
                        end
         
     | 
| 
       27 
     | 
    
         
            -
                        zip_archive.size == 1 ? file_or_dir_to_open = File.join(dir_w_system,"\"#{rom.name}\"") : file_or_dir_to_open = File.join(dir_w_system,dir_game_name)
         
     | 
| 
      
 11 
     | 
    
         
            +
                  Zip::File.open(archive_dir) do |zip_archive|
         
     | 
| 
      
 12 
     | 
    
         
            +
                    zip_archive.glob("*htm").each { |entry| zip_archive.remove(entry) }
         
     | 
| 
      
 13 
     | 
    
         
            +
                    Dir.mkdir(File.join(extract_dir,dir_game_name)) if zip_archive.size > 1 && !Dir.exist?(File.join(extract_dir,dir_game_name))
         
     | 
| 
      
 14 
     | 
    
         
            +
                    zip_archive.each_entry do |rom|
         
     | 
| 
      
 15 
     | 
    
         
            +
                      if Dir.exist?(File.join(extract_dir,dir_game_name))
         
     | 
| 
      
 16 
     | 
    
         
            +
                        rom.extract(File.join(extract_dir,dir_game_name,rom.name)) unless File.exist?(File.join(extract_dir,dir_game_name,rom.name))
         
     | 
| 
      
 17 
     | 
    
         
            +
                      else
         
     | 
| 
      
 18 
     | 
    
         
            +
                        rom.extract(File.join(extract_dir,rom.name)) unless File.exist?(File.join(extract_dir,rom.name))
         
     | 
| 
       28 
19 
     | 
    
         
             
                      end
         
     | 
| 
      
 20 
     | 
    
         
            +
                      zip_archive.size == 1 ? file_or_dir_to_open = File.join(extract_dir,"\"#{rom.name}\"") : file_or_dir_to_open = File.join(extract_dir,dir_game_name)
         
     | 
| 
       29 
21 
     | 
    
         
             
                    end
         
     | 
| 
       30 
     | 
    
         
            -
                   
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
     | 
    
         
            -
             
     | 
| 
       36 
     | 
    
         
            -
             
     | 
| 
       37 
     | 
    
         
            -
                         
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
       41 
     | 
    
         
            -
                           
     | 
| 
       42 
     | 
    
         
            -
                           
     | 
| 
      
 22 
     | 
    
         
            +
                  end
         
     | 
| 
      
 23 
     | 
    
         
            +
                elsif game_obj.file_ext == ".7z"
         
     | 
| 
      
 24 
     | 
    
         
            +
                  puts "Extracting #{game_obj.filename}"
         
     | 
| 
      
 25 
     | 
    
         
            +
                  File.open(archive_dir, "rb") do |seven_zip_archive|
         
     | 
| 
      
 26 
     | 
    
         
            +
                    SevenZipRuby::Reader.open(seven_zip_archive) do |szr|
         
     | 
| 
      
 27 
     | 
    
         
            +
                      if szr.entries.size > 2
         
     | 
| 
      
 28 
     | 
    
         
            +
                        Dir.mkdir(File.join(extract_dir,dir_game_name)) unless Dir.exist?(File.join(extract_dir,dir_game_name))
         
     | 
| 
      
 29 
     | 
    
         
            +
                        szr.extract_if(File.join(extract_dir,dir_game_name)) { |entry| !/\.htm/.match(entry.inspect) }
         
     | 
| 
      
 30 
     | 
    
         
            +
                        file_or_dir_to_open = File.join(extract_dir,dir_game_name)
         
     | 
| 
      
 31 
     | 
    
         
            +
                      else
         
     | 
| 
      
 32 
     | 
    
         
            +
                        szr.extract_if(extract_dir) do |entry|
         
     | 
| 
      
 33 
     | 
    
         
            +
                          game_name = /(?<=file, |dir, |anti, )[.[^\.]]+\..+(?=>)/.match(entry.inspect)[0] unless /\.htm/.match(entry.inspect)
         
     | 
| 
      
 34 
     | 
    
         
            +
                          !/\.htm/.match(entry.inspect)
         
     | 
| 
       43 
35 
     | 
    
         
             
                        end
         
     | 
| 
      
 36 
     | 
    
         
            +
                        file_or_dir_to_open = File.join(extract_dir,"\"#{game_name}\"")
         
     | 
| 
       44 
37 
     | 
    
         
             
                      end
         
     | 
| 
       45 
38 
     | 
    
         
             
                    end
         
     | 
| 
       46 
39 
     | 
    
         
             
                  end
         
     | 
| 
       47 
     | 
    
         
            -
                  File.delete(dir)
         
     | 
| 
       48 
     | 
    
         
            -
                  file_or_dir_to_open
         
     | 
| 
       49 
40 
     | 
    
         
             
                else
         
     | 
| 
       50 
     | 
    
         
            -
                   
     | 
| 
       51 
     | 
    
         
            -
             
     | 
| 
       52 
     | 
    
         
            -
                  else
         
     | 
| 
       53 
     | 
    
         
            -
                    puts "NOTE: No archive extraction. Only Zip and 7-Zip extraction is supported."
         
     | 
| 
       54 
     | 
    
         
            -
                  end
         
     | 
| 
       55 
     | 
    
         
            -
                  FileUtils.move dir, dir_w_system
         
     | 
| 
       56 
     | 
    
         
            -
                  file_or_dir_to_open = dir_w_system
         
     | 
| 
      
 41 
     | 
    
         
            +
                  puts "NOTE: No archive extraction. Only Zip and 7-Zip extraction is supported."
         
     | 
| 
      
 42 
     | 
    
         
            +
                  file_or_dir_to_open = extract_dir
         
     | 
| 
       57 
43 
     | 
    
         
             
                end
         
     | 
| 
      
 44 
     | 
    
         
            +
                file_or_dir_to_open
         
     | 
| 
      
 45 
     | 
    
         
            +
              end
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
              def self.create_extract_dir(game_obj)
         
     | 
| 
      
 48 
     | 
    
         
            +
                /(?<=\().+(?=\))/.match(game_obj.system.name) ? system_name = /(?<=\().+(?=\))/.match(game_obj.system.name)[0].downcase : system_name = game_obj.system.name.rstrip.gsub(/[[[:space:]]\/]/, "_").downcase
         
     | 
| 
      
 49 
     | 
    
         
            +
                dir_w_system = File.join(Dir.home,"videogame_roms",system_name)
         
     | 
| 
      
 50 
     | 
    
         
            +
                Dir.mkdir(dir_w_system) unless Dir.exist?(dir_w_system)
         
     | 
| 
      
 51 
     | 
    
         
            +
                dir_w_system
         
     | 
| 
      
 52 
     | 
    
         
            +
              end
         
     | 
| 
      
 53 
     | 
    
         
            +
             
     | 
| 
      
 54 
     | 
    
         
            +
              def self.move_archive(src,dest)
         
     | 
| 
      
 55 
     | 
    
         
            +
                FileUtils.move src, dest
         
     | 
| 
      
 56 
     | 
    
         
            +
              end
         
     | 
| 
      
 57 
     | 
    
         
            +
             
     | 
| 
      
 58 
     | 
    
         
            +
              def self.delete_archive(dir)
         
     | 
| 
      
 59 
     | 
    
         
            +
                File.delete(dir)
         
     | 
| 
       58 
60 
     | 
    
         
             
              end
         
     | 
| 
       59 
61 
     | 
    
         | 
| 
       60 
62 
     | 
    
         
             
            end
         
     | 
| 
         @@ -70,11 +70,16 @@ class RomLoader::RomLoaderCli 
     | 
|
| 
       70 
70 
     | 
    
         
             
                        if file_or_dir_to_open
         
     | 
| 
       71 
71 
     | 
    
         
             
                          if /\".+\"/.match(file_or_dir_to_open)
         
     | 
| 
       72 
72 
     | 
    
         
             
                            game_file = /\".+\"/.match(file_or_dir_to_open)[0]
         
     | 
| 
       73 
     | 
    
         
            -
                            input = input_prompt("Play #{game_file}? ( 
     | 
| 
      
 73 
     | 
    
         
            +
                            input = input_prompt("Play #{game_file}? (y/N) [exit]:", /[yn]/,control_flow_level)
         
     | 
| 
       74 
74 
     | 
    
         
             
                          else
         
     | 
| 
       75 
     | 
    
         
            -
                            input = input_prompt("Open #{file_or_dir_to_open}? ( 
     | 
| 
      
 75 
     | 
    
         
            +
                            input = input_prompt("Open #{file_or_dir_to_open}? (y/N) [exit]:", /[yn]/,control_flow_level)
         
     | 
| 
      
 76 
     | 
    
         
            +
                          end
         
     | 
| 
      
 77 
     | 
    
         
            +
                          
         
     | 
| 
      
 78 
     | 
    
         
            +
                          if !isWindows?
         
     | 
| 
      
 79 
     | 
    
         
            +
                            system("open #{file_or_dir_to_open}") if input == 'y'
         
     | 
| 
      
 80 
     | 
    
         
            +
                          else
         
     | 
| 
      
 81 
     | 
    
         
            +
                            system("powershell -command \"& { Invoke-Item '#{file_or_dir_to_open}' }\"") if input == 'y'
         
     | 
| 
       76 
82 
     | 
    
         
             
                          end
         
     | 
| 
       77 
     | 
    
         
            -
                            system("open #{file_or_dir_to_open}") if input == 'y' || input == ""
         
     | 
| 
       78 
83 
     | 
    
         
             
                        end 
         
     | 
| 
       79 
84 
     | 
    
         
             
                      end
         
     | 
| 
       80 
85 
     | 
    
         
             
                      input_stack.shift
         
     | 
| 
         @@ -181,19 +186,33 @@ class RomLoader::RomLoaderCli 
     | 
|
| 
       181 
186 
     | 
    
         
             
              # Downloads the selected game to the local directory (~/videogame_roms)
         
     | 
| 
       182 
187 
     | 
    
         
             
              def download_rom(game)
         
     | 
| 
       183 
188 
     | 
    
         
             
                file_or_dir_to_open = nil
         
     | 
| 
       184 
     | 
    
         
            -
                 
     | 
| 
       185 
     | 
    
         
            -
                if  
     | 
| 
       186 
     | 
    
         
            -
                   
     | 
| 
       187 
     | 
    
         
            -
             
     | 
| 
       188 
     | 
    
         
            -
             
     | 
| 
       189 
     | 
    
         
            -
             
     | 
| 
       190 
     | 
    
         
            -
             
     | 
| 
       191 
     | 
    
         
            -
             
     | 
| 
       192 
     | 
    
         
            -
             
     | 
| 
       193 
     | 
    
         
            -
                   
     | 
| 
      
 189 
     | 
    
         
            +
                extract_dir = RomLoader::ArchiveExtractor.create_extract_dir(game)
         
     | 
| 
      
 190 
     | 
    
         
            +
                if !File.exist?(File.join(extract_dir,game.filename))
         
     | 
| 
      
 191 
     | 
    
         
            +
                  puts "Downloading #{game.name} (#{game.size})..."
         
     | 
| 
      
 192 
     | 
    
         
            +
                  if isWindows?
         
     | 
| 
      
 193 
     | 
    
         
            +
                    result = Dir.chdir(extract_dir) { system("powershell -command \"& { Invoke-WebRequest '#{game.download_url}' -OutFile '#{game.filename}' }\"") }
         
     | 
| 
      
 194 
     | 
    
         
            +
                  else
         
     | 
| 
      
 195 
     | 
    
         
            +
                    result = Dir.chdir(extract_dir) { system("curl -Og# \"#{game.download_url}\"") }
         
     | 
| 
      
 196 
     | 
    
         
            +
                  end
         
     | 
| 
      
 197 
     | 
    
         
            +
             
     | 
| 
      
 198 
     | 
    
         
            +
                  if result && !isWindows? && game.system.name != "MAME"
         
     | 
| 
      
 199 
     | 
    
         
            +
                    puts "Finished downloading #{game.filename} to #{extract_dir}. Extracting..."
         
     | 
| 
      
 200 
     | 
    
         
            +
                    file_or_dir_to_open = RomLoader::ArchiveExtractor.extract(File.join(extract_dir,game.filename),extract_dir,game)
         
     | 
| 
      
 201 
     | 
    
         
            +
                    RomLoader::ArchiveExtractor.delete_archive(File.join(extract_dir,game.filename))
         
     | 
| 
      
 202 
     | 
    
         
            +
                  elsif result && !isWindows? && game.system.name == "MAME"
         
     | 
| 
      
 203 
     | 
    
         
            +
                    puts "Finished downloading #{game.filename} to #{extract_dir}."
         
     | 
| 
      
 204 
     | 
    
         
            +
                    puts "NOTE: No archive extraction. MAME roms must remain zipped to play."
         
     | 
| 
      
 205 
     | 
    
         
            +
                    file_or_dir_to_open = extract_dir
         
     | 
| 
      
 206 
     | 
    
         
            +
                  elsif result && isWindows?
         
     | 
| 
      
 207 
     | 
    
         
            +
                    puts "Finished downloading #{game.filename} to #{extract_dir}."
         
     | 
| 
      
 208 
     | 
    
         
            +
                    file_or_dir_to_open = extract_dir
         
     | 
| 
      
 209 
     | 
    
         
            +
                  else
         
     | 
| 
      
 210 
     | 
    
         
            +
                    puts "An error occured, the rom couldn't be downloaded.\n\n"
         
     | 
| 
      
 211 
     | 
    
         
            +
                  end
         
     | 
| 
       194 
212 
     | 
    
         
             
                else
         
     | 
| 
       195 
     | 
    
         
            -
                  puts " 
     | 
| 
      
 213 
     | 
    
         
            +
                  puts "File already exists.\n\n"
         
     | 
| 
       196 
214 
     | 
    
         
             
                end
         
     | 
| 
      
 215 
     | 
    
         
            +
             
     | 
| 
       197 
216 
     | 
    
         
             
                sleep 2
         
     | 
| 
       198 
217 
     | 
    
         
             
                file_or_dir_to_open
         
     | 
| 
       199 
218 
     | 
    
         
             
              end
         
     |