Skip to content

Commit

Permalink
Only download necessary patch data during configuration and updates.
Browse files Browse the repository at this point in the history
And that would be all of fast bootstrapping (#36) we can reasonably implement
without a GUI.

... except that it's not yet as fast as it could be, due to a slight flaw in
the current patch file structure: "<game>.js" and "<game>.<build>.js" are
stored in the root directory of a patch. The patches themselves don't include
a simple list of the games they support (and really, why should they), so
determining the global and game-specific parts of a patch becomes slightly
less trivial, as there is no way around building such a list internally by
parsing through files.js.

If we are about to break backwards compatibility anyway, we should move these
files into the subdirectories of the respective games (so that e.g.
"th14.v1.00b.js" becomes "th14/th14.v1.00b.js") for even faster bootstrapping.
Then, global files are easily identified by the lack of a slash in their
filename.

This implementation already pretends that this is the case. In a typical setup
where only a single game is to be patched, this would still download 40-ish
JSON files too many.
  • Loading branch information
nmlgc committed Nov 8, 2014
1 parent 085e03f commit add1b88
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 8 deletions.
12 changes: 9 additions & 3 deletions thcrap_configure/src/configure.c
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,9 @@ int __cdecl wmain(int argc, wchar_t *wargv[])
"The configuration process has two steps:\n"
"\n"
"\t\t1. Selecting patches\n"
"\t\t2. Locating game installations\n"
"\t\t2. Download game-independent data\n"
"\t\t3. Locating game installations\n"
"\t\t4. Download game-specific data\n"
"\n"
"\n"
"\n"
Expand Down Expand Up @@ -373,8 +375,8 @@ int __cdecl wmain(int argc, wchar_t *wargv[])
size_t i;
json_t *sel;

log_printf("Bootstrapping selected patches...\n");
stack_update(NULL, NULL);
log_printf("Downloading game-independent data...\n");
stack_update(update_filter_global, NULL);

/// Build the new run configuration
json_array_foreach(sel_stack, i, sel) {
Expand Down Expand Up @@ -404,6 +406,10 @@ int __cdecl wmain(int argc, wchar_t *wargv[])
games = ConfigureLocateGames(cur_dir);

if(json_object_size(games) > 0 && !CreateShortcuts(run_cfg_fn, games)) {
json_t *filter = json_object_get_keys_sorted(games);
log_printf("\nDownloading data specific to the located games...\n");
stack_update(update_filter_games, filter);
filter = json_decref_safe(filter);
log_printf(
"\n"
"\n"
Expand Down
8 changes: 4 additions & 4 deletions thcrap_configure/src/configure_search.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ json_t* ConfigureLocateGames(const char *games_js_path)
if(json_object_size(games) != 0) {
log_printf("You already have a %s with the following contents:\n\n", games_js_fn);
json_dump_log(games, JSON_INDENT(2) | JSON_SORT_KEYS);
log_printf("\n\n");
log_printf("\n\nPatch data will be downloaded or updated for all the games listed.\n\n");
if(Ask("Should the paths of these games be re-scanned?")) {
json_object_clear(games);
} else if(!Ask("Should new games be added to this list?")) {
Expand All @@ -88,13 +88,13 @@ json_t* ConfigureLocateGames(const char *games_js_path)
log_printf(
"You don't have a %s yet.\n"
"\n"
"Thus, I now need to search for all Touhou games installed on your system.\n"
"Thus, I now need to search for patchable games installed on your system.\n"
"This only has to be done once - unless, of course, you later move the games to\n"
"different directories.\n"
"\n"
"Depending on the number of drives and your directory structure,\n"
"this may take a while. You can speed up this process by giving me the\n"
"_common_ root path all of your Touhou games share.\n"
"this may take a while. You can speed up this process by giving me a\n"
"common root path shared by all games you want to patch.\n"
"\n"
"For example, if you have 'Double Dealing Character' in \n"
"\n"
Expand Down
2 changes: 1 addition & 1 deletion thcrap_update/src/thcrap_update.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ DWORD WINAPI UpdateThread(void *param)
if(!TryEnterCriticalSection(&cs_update)) {
return 1;
}
stack_update(NULL, NULL);
stack_update(update_filter_games, json_object_get(runconfig_get(), "game"));
LeaveCriticalSection(&cs_update);
return 0;
}
Expand Down
24 changes: 24 additions & 0 deletions thcrap_update/src/update.c
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,30 @@ int PatchFileRequiresUpdate(const json_t *patch_info, const char *fn, json_t *lo
return 0;
}

int update_filter_global(const char *fn, json_t *null)
{
return strchr(fn, '/') == NULL;
}

int update_filter_games(const char *fn, json_t *games)
{
STRLEN_DEC(fn);
size_t i = 0;
json_t *val;
json_flex_array_foreach(games, i, val) {
// We will need to match "th14", but not "th143".
size_t val_len = json_string_length(val);
if(
fn_len > val_len
&& !strnicmp(fn, json_string_value(val), val_len)
&& fn[val_len] == '/'
) {
return 1;
}
}
return update_filter_global(fn, NULL);
}

int patch_update(json_t *patch_info, update_filter_func_t filter_func, json_t *filter_data)
{
const char *files_fn = "files.js";
Expand Down
6 changes: 6 additions & 0 deletions thcrap_update/src/update.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ void* ServerDownloadFile(
// downloaded.
typedef int (*update_filter_func_t)(const char *fn, json_t *filter_data);

// Returns 1 for all global file names, i.e. those without a slash.
int update_filter_global(const char *fn, json_t *null);
// Returns 1 for all global file names and those that are specific to a game
// in the flexible JSON array [games].
int update_filter_games(const char *fn, json_t *games);

int patch_update(
json_t *patch_info, update_filter_func_t filter_func, json_t *filter_data
);
Expand Down
2 changes: 2 additions & 0 deletions thcrap_update/thcrap_update.def
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ EXPORTS

ServerDownloadFile

update_filter_global
update_filter_games
patch_update
stack_update

Expand Down

1 comment on commit add1b88

@nmlgc
Copy link
Contributor Author

@nmlgc nmlgc commented on add1b88 Nov 8, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@D--A: Contains new user-facing strings in need to be translated.

Please sign in to comment.