diff --git a/src/wx/CMakeLists.txt b/src/wx/CMakeLists.txt index b66d42ec..76bda3c6 100644 --- a/src/wx/CMakeLists.txt +++ b/src/wx/CMakeLists.txt @@ -793,7 +793,7 @@ if(WIN32 AND (X86_64 OR ARM64 OR X86_32) AND ENABLE_ONLINEUPDATES) endif() target_sources(visualboyadvance-m PRIVATE - autoupdater/wxmsw/autoupdater.cpp@ + autoupdater/wxmsw/autoupdater.cpp autoupdater/wxmsw/winsparkle-rc.h autoupdater/wxmsw/winsparkle-wrapper.cpp autoupdater/wxmsw/winsparkle-wrapper.h) diff --git a/src/wx/autoupdater/wxmsw/winsparkle-wrapper.cpp b/src/wx/autoupdater/wxmsw/winsparkle-wrapper.cpp index 3eb5696a..58af07c0 100644 --- a/src/wx/autoupdater/wxmsw/winsparkle-wrapper.cpp +++ b/src/wx/autoupdater/wxmsw/winsparkle-wrapper.cpp @@ -19,37 +19,10 @@ WinSparkleDllWrapper *WinSparkleDllWrapper::GetInstance() return &instance; } -extern "C" { - func_win_sparkle_init ws_init; - func_win_sparkle_check_update_with_ui ws_cu_wui; - func_win_sparkle_set_appcast_url ws_saurl; - func_win_sparkle_set_app_details ws_sad; - func_win_sparkle_cleanup ws_cu; - HMODULE winsparkle_dll = nullptr; - - void winsparkle_load_symbols(wxString path) - { - winsparkle_dll = LoadLibraryW(path.wc_str()); - - if (winsparkle_dll != nullptr) { - ws_init = reinterpret_cast(GetProcAddress(winsparkle_dll, "win_sparkle_init")); - ws_cu_wui = reinterpret_cast(GetProcAddress(winsparkle_dll, "win_sparkle_check_update_with_ui")); - ws_saurl = reinterpret_cast(GetProcAddress(winsparkle_dll, "win_sparkle_set_appcast_url")); - ws_sad = reinterpret_cast(GetProcAddress(winsparkle_dll, "win_sparkle_set_app_details")); - ws_cu = reinterpret_cast(GetProcAddress(winsparkle_dll, "win_sparkle_cleanup")); - } - } -} - WinSparkleDllWrapper::WinSparkleDllWrapper() { - wchar_t temp_file_path_w[MAX_PATH + 1]; - GetTempPathW(MAX_PATH, temp_file_path_w); - wxString temp_file_path = wxString(temp_file_path_w); - wchar_t temp_file_name_w[MAX_PATH + 1]; - GetLongPathNameW(temp_file_path.wc_str(), temp_file_name_w, MAX_PATH + 1); - temp_file_name = wxString(temp_file_name_w) + "WinSparkle.dll"; - wxFile temp_file = wxFile(temp_file_name, wxFile::write); + wxFile temp_file; + temp_file_name = wxFileName::CreateTempFileName("winsparkle", &temp_file); HRSRC res = FindResource(wxGetInstance(), MAKEINTRESOURCE(WINSPARKLE_DLL_RC), RT_RCDATA); if (!res) @@ -67,13 +40,15 @@ WinSparkleDllWrapper::WinSparkleDllWrapper() temp_file.Write((void *)res_data, res_size); temp_file.Close(); - winsparkle_load_symbols(temp_file_name); + winsparkle_dll = LoadLibraryW(temp_file_name.wc_str()); - winsparkle_init = ws_init; - winsparkle_check_update_with_ui = ws_cu_wui; - winsparkle_set_appcast_url = ws_saurl; - winsparkle_set_app_details = ws_sad; - winsparkle_cleanup = ws_cu; + if (winsparkle_dll != nullptr) { + winsparkle_init = reinterpret_cast(GetProcAddress(winsparkle_dll, "win_sparkle_init")); + winsparkle_check_update_with_ui = reinterpret_cast(GetProcAddress(winsparkle_dll, "win_sparkle_check_update_with_ui")); + winsparkle_set_appcast_url = reinterpret_cast(GetProcAddress(winsparkle_dll, "win_sparkle_set_appcast_url")); + winsparkle_set_app_details = reinterpret_cast(GetProcAddress(winsparkle_dll, "win_sparkle_set_app_details")); + winsparkle_cleanup = reinterpret_cast(GetProcAddress(winsparkle_dll, "win_sparkle_cleanup")); + } } diff --git a/src/wx/autoupdater/wxmsw/winsparkle-wrapper.h b/src/wx/autoupdater/wxmsw/winsparkle-wrapper.h index 9dbcb6ca..39021538 100644 --- a/src/wx/autoupdater/wxmsw/winsparkle-wrapper.h +++ b/src/wx/autoupdater/wxmsw/winsparkle-wrapper.h @@ -11,8 +11,6 @@ extern "C" { typedef void (__cdecl *func_win_sparkle_set_appcast_url)(const char*); typedef void (__cdecl *func_win_sparkle_set_app_details)(const wchar_t*, const wchar_t*, const wchar_t*); typedef void (__cdecl *func_win_sparkle_cleanup)(); - - extern HMODULE winsparkle_dll; } class WinSparkleDllWrapper { @@ -22,6 +20,8 @@ private: WinSparkleDllWrapper(); ~WinSparkleDllWrapper(); + HMODULE winsparkle_dll; + func_win_sparkle_init winsparkle_init = nullptr; func_win_sparkle_check_update_with_ui winsparkle_check_update_with_ui = nullptr; func_win_sparkle_set_appcast_url winsparkle_set_appcast_url = nullptr;