Skip to content

Commit

Permalink
update: Delete files that shouldn't exist according to the local file…
Browse files Browse the repository at this point in the history
…s.js. [V]
  • Loading branch information
nmlgc committed Jun 18, 2017
1 parent b839a93 commit cef2cfe
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions thcrap_update/src/update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,13 @@ int patch_update(json_t *patch_info, update_filter_func_t filter_func, json_t *f
const char *key;
const char *patch_name = json_object_get_string(patch_info, "id");

auto update_delete = [&patch_info, &local_files] (const char *fn) {
log_printf("Deleting %s...\n", fn);
if(!patch_file_delete(patch_info, fn)) {
json_object_del(local_files, fn);
}
};

if(!patch_info) {
return -1;
}
Expand Down Expand Up @@ -568,7 +575,7 @@ int patch_update(json_t *patch_info, update_filter_func_t filter_func, json_t *f

i = 0;
json_object_foreach(remote_files_to_get, key, remote_val) {
void *file_buffer;
void *file_buffer = nullptr;
DWORD file_size;
json_t *local_val;

Expand All @@ -587,15 +594,18 @@ int patch_update(json_t *patch_info, update_filter_func_t filter_func, json_t *f
if(file_buffer && file_size) {
DWORD local_crc = crc32(0, (Bytef*)file_buffer, file_size);
if(local_crc == json_integer_value(local_val)) {
log_printf("Deleting %s...\n", key);
if(!patch_file_delete(patch_info, key)) {
json_object_del(local_files, key);
}
update_delete(key);
} else {
log_printf("%s (locally changed, skipping deletion)\n", key);
}
}
SAFE_FREE(file_buffer);
} else if(json_is_null(local_val)) {
// Delete files that shouldn't exist, according to files.js.
// Mainly intended to work around broken third-party patch
// downloaders, since we don't even write JSON nulls to the
// local files.js ourselves.
update_delete(key);
} else if(json_is_integer(remote_val)) {
DWORD remote_crc = json_integer_value(remote_val);
file_buffer = servers.download(&file_size, key, &remote_crc);
Expand Down

0 comments on commit cef2cfe

Please sign in to comment.