Fixed unable to download ECW due to spaces in the file names, added checksum caching for Task to make updating much faster for most games (IA with its mostly loose files doesn't gain anything and might even be slower... Consider not performing any verification for non-repair tasks?)

This commit is contained in:
2026-10-08 14:12:18 -05:00
parent c6de24bf34
commit f6fbd1bce1
6 changed files with 164 additions and 9 deletions

View File

@@ -19,6 +19,12 @@ module W3DHubLauncher
@sha256_checksum = hash["checksum"]
@checksum_chunks = hash["checksum-chunks"]
@download_url = hash["download_url"]
# Fix crashing on spaces
if @download_url
uri_path = @download_url.split("/").last
@download_url = @download_url.sub(uri_path, URI.encode_uri_component(uri_path))
end
end
def error?

View File

@@ -0,0 +1,107 @@
module W3DHubLauncher
class Worker
class Api
# Cached verifcation data for application and pending package files
class VerificationData
SCHEMA = 0
def initialize(path)
@path = path
data = {}
if File.exist?(@path)
begin
data = JSON.parse(File.read(@path))
rescue JSON::ParserError
data = {}
end
end
data = {} unless data.is_a?(Hash)
@schema = data["schema"] || SCHEMA
@data = {}
data["data"]&.each do |key, value|
@data[key] = Data.new(value)
end
end
def key(file_name, file_version: "", package: false)
file_name = file_name.gsub("\\", "/").downcase
if package
"package:{file_name}:#{file_version}"
else
file_name
end
end
def data(key)
@data[key]
end
def unchanged?(key, checksum:, file_path:)
data = data(key)
return nil unless data
return data if data.checksum.upcase.strip == checksum.upcase.strip &&
data.modification_time == File.mtime(file_path).to_i &&
data.file_size == File.size(file_path)
nil
end
def set(key, checksum:, file_path:)
data = Data.new(
{
"checksum" => checksum.upcase.strip,
"modification_time" => File.mtime(file_path).to_i,
"file_size" => File.size(file_path)
}
)
@data[key] = data
save
data
end
def delete(key)
data = @data.delete(key)
save
data
end
def save
File.write(@path, JSON.pretty_generate(self))
end
def to_json(options = {})
{
schema: SCHEMA,
data: @data
}.to_json(options)
end
class Data
attr_reader :checksum, :modification_time, :file_size
def initialize(data)
@checksum = data["checksum"]
@modification_time = data["modification_time"]
@file_size = data["file_size"]
end
def to_json(options = {})
{
checksum: @checksum,
modification_time: @modification_time,
file_size: @file_size
}.to_json(options)
end
end
end
end
end
end