Skip to content

Commit 9f165b6

Browse files
committed
Fix scraper search requests erroring after repeat
1 parent 2a80a04 commit 9f165b6

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

scenes/popups/scraper/ScraperPopup.gd

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,9 @@ func thread_fetch_game_entries():
179179
else:
180180
game_entry.description = "Fetching media (by search)..."
181181
call_thread_safe("emit_signal", "scrape_step", game_entry)
182+
# FIXME: Refactor this code ASAP it's so bad
183+
if game_entry.data is Array:
184+
game_entry.data = game_data.name.get_basename()
182185
if not scraper.scrape_game_by_search(game_data, game_entry.data):
183186
pending_datas[game_data] = req
184187
Request.Type.MEDIA:
@@ -260,7 +263,6 @@ func t_on_game_scrape_not_found(game_data: RetroHubGameData):
260263
call_deferred("incr_num_games_error")
261264

262265

263-
264266
func t_on_game_scrape_error(game_data: RetroHubGameData, details: String):
265267
var req : Request = _ensure_valid_req(game_data)
266268
if not req:
@@ -466,7 +468,7 @@ func _on_Warning_search_completed(orig_game_data: RetroHubGameData, new_game_dat
466468
break
467469

468470
func cancel_scrape(game_entry: RetroHubScraperGameEntry):
469-
game_entry.data = ["Canceled", null]
471+
game_entry.data = ["Canceled", game_entry.data if game_entry.data is String else null]
470472
game_entry.state = RetroHubScraperGameEntry.State.ERROR
471473
num_games_pending = num_games_pending - 1
472474
num_games_error = num_games_error + 1
@@ -523,7 +525,7 @@ func cancel_entry(game_entry: RetroHubScraperGameEntry):
523525
#warning-ignore:return_value_discarded
524526
requests_semaphore.wait()
525527
requests_mutex.unlock()
526-
game_entry.data = ["Canceled", null]
528+
game_entry.data = ["Canceled", game_entry.data if game_entry.data is String else null]
527529
game_entry.state = RetroHubScraperGameEntry.State.ERROR
528530
num_games_pending -= 1
529531
num_games_error += 1
@@ -562,11 +564,14 @@ func _on_StopScraperDialog_confirmed():
562564
finish_scraping()
563565

564566

565-
func _on_Error_retry_entry(game_entry: RetroHubScraperGameEntry, req: Request):
567+
func _on_Error_retry_entry(game_entry: RetroHubScraperGameEntry, req):
566568
requests_mutex.lock()
567569
if req == null:
568570
# No request, so start by scratch
569571
add_data_request(game_entry, Request.Type.DATA_HASH if scrape_by_hash else Request.Type.DATA_SEARCH, true)
572+
elif req is String:
573+
game_entry.data = req
574+
add_data_request(game_entry, Request.Type.DATA_SEARCH, true)
570575
else:
571576
requests_queue.push_front(req)
572577
#warning-ignore:return_value_discarded

source/emulators/GenericEmulator.gd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ static func find_path(emulator_def: Dictionary, key: String, substitutes: Dictio
3030
static func substitute_str(path, substitutes: Dictionary) -> String:
3131
return JSONUtils.format_string_with_substitutes(path, substitutes)
3232

33-
static func load_icon(name: String) -> Texture2D:
34-
var path := "res://assets/emulators/%s.png" % name
33+
static func load_icon(_name: String) -> Texture2D:
34+
var path := "res://assets/emulators/%s.png" % _name
3535
if ResourceLoader.exists(path, "Image"):
3636
return load(path)
3737
return null

source/utils/JSONUtils.gd

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@ func load_json_file(filepath: String):
66
push_error("Error when opening " + filepath)
77
return {}
88
var json = load_json_buffer(file.get_as_text())
9-
if not json:
9+
if not (json is Dictionary or json is Array):
1010
push_error("Error when parsing JSON for " + filepath)
11+
return {}
1112
return json
1213

1314
func load_json_buffer(data: String):
1415
var json = JSON.new()
1516
if json.parse(data):
1617
push_error("Error when parsing JSON buffer")
17-
return {}
18+
return ERR_FILE_CORRUPT
1819
return json.get_data()
1920

2021
func save_json_file(json, file_path: String):

0 commit comments

Comments
 (0)