Skip to content

Commit

Permalink
Show warning message box when JSON parsing fails (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kimjio committed Feb 27, 2023
1 parent 5da67f6 commit 42847d9
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
12 changes: 6 additions & 6 deletions src/VERSIONINFO.rc
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
//

VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,17,0,0
PRODUCTVERSION 1,17,0,0
FILEVERSION 1,17,1,0
PRODUCTVERSION 1,17,1,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
Expand All @@ -25,19 +25,19 @@ BEGIN
BEGIN
VALUE "LegalCopyright", "Copyright © Ji O Kim\0"
VALUE "FileDescription", "우마무스메 현지화 패치\0"
VALUE "FileVersion", "1.17.0.0\0"
VALUE "FileVersion", "1.17.1.0\0"
VALUE "InternalName", "umamusume-localify\0"
VALUE "ProductName", "Umamusume Localify\0"
VALUE "ProductVersion", "1.17.0\0"
VALUE "ProductVersion", "1.17.1\0"
END
BLOCK "000004b0"
BEGIN
VALUE "LegalCopyright", "Copyright © Ji O Kim\0"
VALUE "FileDescription", "Localization patch for Umamusume\0"
VALUE "FileVersion", "1.17.0.0\0"
VALUE "FileVersion", "1.17.1.0\0"
VALUE "InternalName", "umamusume-localify\0"
VALUE "ProductName", "Umamusume Localify\0"
VALUE "ProductVersion", "1.17.0\0"
VALUE "ProductVersion", "1.17.1\0"
END
END
BLOCK "VarFileInfo"
Expand Down
12 changes: 10 additions & 2 deletions src/hook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,17 @@ namespace
MH_DisableHook(LoadLibraryW);
MH_RemoveHook(LoadLibraryW);

if (!g_custom_title_name.empty())
auto hWnd = FindWindowW(L"UnityWndClass", L"umamusume");
if (hWnd)
{
SetWindowText(GetActiveWindow(), local::wide_acp(local::u8_wide(g_custom_title_name)).data());
if (!g_custom_title_name.empty())
{
SetWindowText(hWnd, local::wide_acp(local::u8_wide(g_custom_title_name)).data());
}
if (has_json_parse_error)
{
MessageBox(hWnd, json_parse_error_msg.data(), "Umamusume Localify", MB_OK | MB_ICONWARNING);
}
}

// use original function beacuse we have unhooked that
Expand Down
9 changes: 9 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <stdinclude.hpp>
#include <rapidjson/error/en.h>

extern bool init_hook();
extern void uninit_hook();
Expand Down Expand Up @@ -36,6 +37,9 @@ int g_cyspring_update_mode = -1;
bool g_hide_now_loading = false;
std::string text_id_dict;

bool has_json_parse_error = false;
std::string json_parse_error_msg;

namespace
{
void create_debug_console()
Expand Down Expand Up @@ -255,6 +259,11 @@ namespace
dicts.emplace_back(dict);
}
}
} else {
has_json_parse_error = true;
std::stringstream str_stream;
str_stream << "JSON parse error: " << GetParseError_En(document.GetParseError()) << " (" << document.GetErrorOffset() << ")";
json_parse_error_msg = str_stream.str();
}

config_stream.close();
Expand Down
3 changes: 3 additions & 0 deletions src/stdinclude.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ extern bool g_character_system_text_caption;
extern int g_cyspring_update_mode;
extern bool g_hide_now_loading;

extern bool has_json_parse_error;
extern std::string json_parse_error_msg;

namespace {
// copy-pasted from https://stackoverflow.com/questions/3418231/replace-part-of-a-string-with-another-string
void replaceAll(std::string& str, const std::string& from, const std::string& to)
Expand Down

0 comments on commit 42847d9

Please sign in to comment.