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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 87a10ca23bd4fc1e499ef4240027008cc2a4d911
4
- data.tar.gz: 953fe06a0b401c28467d65a00acbb7818f84c6ae
3
+ metadata.gz: ad9d09bd1aafb62ad873edd616512de5e887d4bd
4
+ data.tar.gz: 827d0debcc137eb05ac9dfc3c5d8dfa4358c2323
5
5
  SHA512:
6
- metadata.gz: 0c3b71b8b3319c7d2f5a8ec434b87981d7307a36c4e968188f373b66ca1543b1b8fcb47012a13cb4ed38f3f5ffdfd48d159aab3800ea524490d4ff8b47571c1d
7
- data.tar.gz: ac72b823b59ca07ac9677116f02264ce8343dc03cefc2aa11765be4e936f73bd2900459d4bf21d27eac81fd97344ce4c2a7a228d5fdc4a87ca758a67dc92da22
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(dir,game_obj)
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
- Dir.mkdir(dir_w_system) unless Dir.exist?(dir_w_system)
14
-
15
- if game_obj.system.name != "MAME"
8
+
9
+ if game_obj.file_ext == ".zip"
16
10
  puts "Extracting #{game_obj.filename}"
17
- if game_obj.file_ext == ".zip"
18
- Zip::File.open(dir) do |zip_archive|
19
- zip_archive.glob("*htm").each { |entry| zip_archive.remove(entry) }
20
- Dir.mkdir(File.join(dir_w_system,dir_game_name)) if zip_archive.size > 1 && !Dir.exist?(File.join(dir_w_system,dir_game_name))
21
- zip_archive.each_entry do |rom|
22
- if Dir.exist?(File.join(dir_w_system,dir_game_name))
23
- rom.extract(File.join(dir_w_system,dir_game_name,rom.name)) unless File.exist?(File.join(dir_w_system,dir_game_name,rom.name))
24
- else
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
- elsif game_obj.file_ext == ".7z"
31
- File.open(dir, "rb") do |seven_zip_archive|
32
- SevenZipRuby::Reader.open(seven_zip_archive) do |szr|
33
- if szr.entries.size > 2
34
- Dir.mkdir(File.join(dir_w_system,dir_game_name)) unless Dir.exist?(File.join(dir_w_system,dir_game_name))
35
- szr.extract_if(File.join(dir_w_system,dir_game_name)) { |entry| !/\.htm/.match(entry.inspect) }
36
- file_or_dir_to_open = File.join(dir_w_system,dir_game_name)
37
- else
38
- szr.extract_if(dir_w_system) do |entry|
39
- game_name = /(?<=file, |dir, |anti, )[.[^\.]]+\..+(?=>)/.match(entry.inspect)[0] unless /\.htm/.match(entry.inspect)
40
- !/\.htm/.match(entry.inspect)
41
- end
42
- file_or_dir_to_open = File.join(dir_w_system,"\"#{game_name}\"")
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
- if game_obj.system.name == "MAME"
51
- puts "NOTE: No archive extraction. MAME roms must remain zipped to play."
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}? (Y/n) [exit]:", /[yn]/,control_flow_level)
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}? (Y/n) [exit]:", /[yn]/,control_flow_level)
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
- puts "Downloading #{game.name} (#{game.size})..."
185
- if isWindows?
186
- result = Dir.chdir(File.join(Dir.home,"videogame_roms")) { system("powershell -command \"& { Invoke-WebRequest '#{game.download_url}' -OutFile '#{game.filename}' }\"") }
187
- else
188
- result = Dir.chdir(File.join(Dir.home,"videogame_roms")) { system("curl -Og# \"#{game.download_url}\"") }
189
- end
190
-
191
- if result == true
192
- puts "Finished downloading #{game.filename} to #{File.join(Dir.home,"videogame_roms")}.\n"
193
- file_or_dir_to_open = RomLoader::ArchiveExtractor.extract(File.join(Dir.home,"videogame_roms",game.filename),game) unless isWindows?
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 "An error occured, the rom couldn't be downloaded.\n"
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: romloader
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Efrain Perez Jr