diff --git a/lib/api.rb b/lib/api.rb index a5e8d54..918cb44 100644 --- a/lib/api.rb +++ b/lib/api.rb @@ -222,6 +222,7 @@ class W3DHub if response.status == 200 hash = JSON.parse(response.body, symbolize_names: true) + hash[:packages].map { |pkg| Package.new(pkg) } else logger.error(LOG_TAG) { "Failed to fetch package details for:" } diff --git a/lib/application_manager/manifest.rb b/lib/application_manager/manifest.rb index 389d658..d02e4ea 100644 --- a/lib/application_manager/manifest.rb +++ b/lib/application_manager/manifest.rb @@ -30,7 +30,7 @@ class W3DHub def parse_files @document.root.elements.each("//File") do |element| - @files.push(ManifestFile.new(element)) + @files.push(ManifestFile.new(element, @version)) end end @@ -42,9 +42,9 @@ class W3DHub # TODO: Support patches class ManifestFile - attr_reader :name, :checksum, :package, :removed_since, :from + attr_reader :name, :checksum, :package, :removed_since, :from, :version - def initialize(xml) + def initialize(xml, version) @data = xml @name = @data["name"] @@ -58,6 +58,8 @@ class W3DHub @from = patch["from"] @package = patch["package"] end + + @version = version end def removed? diff --git a/lib/application_manager/task.rb b/lib/application_manager/task.rb index be73e7f..539f44c 100644 --- a/lib/application_manager/task.rb +++ b/lib/application_manager/task.rb @@ -224,7 +224,9 @@ class W3DHub @status.step = :build_package_list + files = [] packages = [] + deleted_files = [] # TODO: remove removed files manifests.reverse.each do |manifest| logger.info(LOG_TAG) { "#{manifest.game}-#{manifest.type}: #{manifest.version} (#{manifest.base_version})" } @@ -232,32 +234,36 @@ class W3DHub manifest.files.each do |file| @files["#{file.name}:#{manifest.version}"] = file - next if file.removed? # No package data - - # if file.patch? - # fail!("#{@application.name} requires patches. Patching is not yet supported.") - # break - # end - - next if packages.detect do |pkg| - pkg.category == "games" && - pkg.subcategory == @app_id && - pkg.name == file.package && - pkg.version == manifest.version + if file.removed? # No package data + files.delete_if { |f| f.name == file.name } + deleted_files.push(file) + next end - packages.push( - Api::Package.new( - { category: "games", subcategory: @app_id, name: file.package, version: manifest.version } - ) - ) + files.delete_if { |f| f.name == file.name } unless file.patch? - packages.last.is_patch = file if file.patch? + files.push(file) end # TODO: Dependencies end + files.each do |file| + next if packages.detect do |pkg| + pkg.category == "games" && + pkg.subcategory == @app_id && + pkg.name == file.package && + pkg.version == file.version + end + + package = Api::Package.new({ category: "games", subcategory: @app_id, name: file.package, version: file.version }) + + package.is_patch = file if file.patch? + + packages.push(package) + end + + packages end @@ -326,6 +332,7 @@ class W3DHub selected_packages = [] selected_packages_hash = {} + # FIXME: Refactoring `build_package_list` has broken this bit since we no longer fetch EVERYTHING and actually DON'T download REMOVED files rejected_files.each do |hash| next if selected_packages_hash["#{hash[:file].package}_#{hash[:manifest_version]}"]