WinSparkle wrapper improvements.
- Make WinSparkleDllWrapper a real singleton. Make the constructor private and add a static `GetInstance()` method that constructs the single instance and/or returns it. Make it encapsulate the function pointers and the wxDynamicLibrary instance, with the API as friend functions. - Make winsparkle API completely self-contained. Make the instance of the WinSparkleDllWrapper a factory function local static. This way the calling program does not have to manage the life-cycle, the singleton is initialized when the API is first invoked, and destroyed during global destruction. The destructor is now also private, because the singleton object is destroyed during global destruction. Found the solution here: https://stackoverflow.com/a/46139631/262458 - Cmake improvements. Only enable the ENABLE_ONLINEUPDATES option by default if we are going to use winsparkle on 32 or 64 bit intel windows. Do not inlclude winsparkle if the option is off. - Disable for now. Currently ENABLE_ONLINEUPDATES defaults to OFF even on intel/windows, until we do more work on this feature. Signed-off-by: Rafael Kitover <rkitover@gmail.com>
This commit is contained in:
parent
76803caf5f
commit
e35d46254b
|
@ -141,7 +141,17 @@ endif()
|
|||
|
||||
option(ENABLE_FFMPEG "Enable ffmpeg A/V recording" ${FFMPEG_DEFAULT})
|
||||
|
||||
option(ENABLE_ONLINEUPDATES "Enable online update checks" ON)
|
||||
set(ONLINEUPDATES_DEFAULT OFF)
|
||||
|
||||
if(WIN32 AND (AMD64 OR X86_32))
|
||||
|
||||
# currently we do not turn this on until we do more work on this feature
|
||||
#
|
||||
# set(ONLINEUPDATES_DEFAULT ON) # use winsparkle
|
||||
|
||||
endif()
|
||||
|
||||
option(ENABLE_ONLINEUPDATES "Enable online update checks" ${ONLINEUPDATES_DEFAULT})
|
||||
|
||||
set(LTO_DEFAULT ON)
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit fa2265a8bedfbdc6169d9891c79320c76b7b0dd1
|
||||
Subproject commit fe50718d0e642c2c9c32b63abec510ced9f1ae0a
|
|
@ -696,12 +696,11 @@ set(
|
|||
# from external source with minor modifications
|
||||
widgets/wx/checkedlistctrl.h
|
||||
../common/version_cpp.h
|
||||
winsparkle-wrapper.h
|
||||
)
|
||||
|
||||
if(WIN32)
|
||||
if(WIN32 AND (AMD64 OR X86_32) AND ENABLE_ONLINEUPDATES)
|
||||
list(APPEND SRC_WX winsparkle-wrapper.cpp)
|
||||
list(APPEND HDR_WX winsparkle-wrapper.h)
|
||||
list(APPEND HDR_WX winsparkle-wrapper.h winsparkle-rc.h)
|
||||
endif()
|
||||
|
||||
set(
|
||||
|
@ -763,7 +762,7 @@ add_executable(
|
|||
${CM_STUFF}
|
||||
)
|
||||
|
||||
if(WIN32 AND (AMD64 OR X86_32))
|
||||
if(WIN32 AND (AMD64 OR X86_32) AND ENABLE_ONLINEUPDATES)
|
||||
if(NOT DEFINED WINSPARKLE_BIN_RELEASE_DIR)
|
||||
set(WINSPARKLE_BIN_RELEASE_DIR ${CMAKE_SOURCE_DIR}/dependencies/WinSparkle-0.6.0)
|
||||
endif()
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
#ifndef WINSPARKLE_RC_H
|
||||
#define WINSPARKLE_RC_H
|
||||
|
||||
#define WINSPARKLE_DLL_RC 300
|
||||
|
||||
#endif /* WINSPARKLE_RC_H */
|
|
@ -4,29 +4,17 @@
|
|||
#include "winsparkle-wrapper.h"
|
||||
#include "wx/msw/private.h"
|
||||
|
||||
wxDynamicLibrary *winsparkle_dll = nullptr;
|
||||
WinSparkleDllWrapper *WinSparkleDllWrapper::GetInstance()
|
||||
{
|
||||
static WinSparkleDllWrapper instance;
|
||||
|
||||
typedef void (*func_win_sparkle_init)();
|
||||
func_win_sparkle_init winsparkle_init = nullptr;
|
||||
|
||||
typedef void (*func_win_sparkle_check_update_with_ui)();
|
||||
func_win_sparkle_check_update_with_ui winsparkle_check_update_with_ui = nullptr;
|
||||
|
||||
typedef void (*func_win_sparkle_set_appcast_url)(const char *);
|
||||
func_win_sparkle_set_appcast_url winsparkle_set_appcast_url = nullptr;
|
||||
|
||||
typedef void (*func_win_sparkle_set_app_details)(const wchar_t*, const wchar_t*, const wchar_t*);
|
||||
func_win_sparkle_set_app_details winsparkle_set_app_details = nullptr;
|
||||
|
||||
typedef void (*func_win_sparkle_cleanup)();
|
||||
func_win_sparkle_cleanup winsparkle_cleanup = nullptr;
|
||||
|
||||
wxString *temp_file_name = nullptr;
|
||||
return &instance;
|
||||
}
|
||||
|
||||
WinSparkleDllWrapper::WinSparkleDllWrapper()
|
||||
{
|
||||
wxFile temp_file;
|
||||
temp_file_name = new wxString(wxFileName::CreateTempFileName("winsparkle", &temp_file));
|
||||
temp_file_name = wxFileName::CreateTempFileName("winsparkle", &temp_file);
|
||||
|
||||
HRSRC res = FindResource(wxGetInstance(), MAKEINTRESOURCE(WINSPARKLE_DLL_RC), RT_RCDATA);
|
||||
|
||||
|
@ -46,7 +34,7 @@ WinSparkleDllWrapper::WinSparkleDllWrapper()
|
|||
|
||||
temp_file.Close();
|
||||
|
||||
winsparkle_dll = new wxDynamicLibrary(*temp_file_name, wxDL_NOW | wxDL_VERBATIM);
|
||||
winsparkle_dll = new wxDynamicLibrary(temp_file_name, wxDL_NOW | wxDL_VERBATIM);
|
||||
|
||||
winsparkle_init = reinterpret_cast<func_win_sparkle_init>(winsparkle_dll->GetSymbol("win_sparkle_init"));
|
||||
winsparkle_check_update_with_ui = reinterpret_cast<func_win_sparkle_check_update_with_ui>(winsparkle_dll->GetSymbol("win_sparkle_check_update_with_ui"));
|
||||
|
@ -59,35 +47,33 @@ WinSparkleDllWrapper::~WinSparkleDllWrapper()
|
|||
{
|
||||
delete winsparkle_dll;
|
||||
|
||||
wxRemoveFile(*temp_file_name);
|
||||
|
||||
delete temp_file_name;
|
||||
wxRemoveFile(temp_file_name);
|
||||
}
|
||||
|
||||
void win_sparkle_init()
|
||||
{
|
||||
winsparkle_init();
|
||||
WinSparkleDllWrapper::GetInstance()->winsparkle_init();
|
||||
}
|
||||
|
||||
void win_sparkle_check_update_with_ui()
|
||||
{
|
||||
winsparkle_check_update_with_ui();
|
||||
WinSparkleDllWrapper::GetInstance()->winsparkle_check_update_with_ui();
|
||||
}
|
||||
|
||||
|
||||
void win_sparkle_set_appcast_url(const char *url)
|
||||
{
|
||||
winsparkle_set_appcast_url(url);
|
||||
WinSparkleDllWrapper::GetInstance()->winsparkle_set_appcast_url(url);
|
||||
}
|
||||
|
||||
|
||||
void win_sparkle_set_app_details(const wchar_t *company_name, const wchar_t *app_name, const wchar_t *app_version)
|
||||
{
|
||||
winsparkle_set_app_details(company_name, app_name, app_version);
|
||||
WinSparkleDllWrapper::GetInstance()->winsparkle_set_app_details(company_name, app_name, app_version);
|
||||
}
|
||||
|
||||
|
||||
void win_sparkle_cleanup()
|
||||
{
|
||||
winsparkle_cleanup();
|
||||
WinSparkleDllWrapper::GetInstance()->winsparkle_cleanup();
|
||||
}
|
||||
|
|
|
@ -1,11 +1,43 @@
|
|||
#ifndef WINSPARKLE_WRAPPER_H
|
||||
#define WINSPARKLE_WRAPPER_H
|
||||
|
||||
#define WINSPARKLE_DLL_RC 300
|
||||
#include <wx/string.h>
|
||||
#include <wx/dynlib.h>
|
||||
|
||||
struct WinSparkleDllWrapper {
|
||||
#include "winsparkle-rc.h"
|
||||
|
||||
class WinSparkleDllWrapper {
|
||||
public:
|
||||
static WinSparkleDllWrapper *GetInstance();
|
||||
private:
|
||||
WinSparkleDllWrapper();
|
||||
~WinSparkleDllWrapper();
|
||||
|
||||
wxDynamicLibrary *winsparkle_dll = nullptr;
|
||||
|
||||
typedef void (*func_win_sparkle_init)();
|
||||
func_win_sparkle_init winsparkle_init = nullptr;
|
||||
|
||||
typedef void (*func_win_sparkle_check_update_with_ui)();
|
||||
func_win_sparkle_check_update_with_ui winsparkle_check_update_with_ui = nullptr;
|
||||
|
||||
typedef void (*func_win_sparkle_set_appcast_url)(const char *);
|
||||
func_win_sparkle_set_appcast_url winsparkle_set_appcast_url = nullptr;
|
||||
|
||||
typedef void (*func_win_sparkle_set_app_details)(const wchar_t*, const wchar_t*, const wchar_t*);
|
||||
func_win_sparkle_set_app_details winsparkle_set_app_details = nullptr;
|
||||
|
||||
typedef void (*func_win_sparkle_cleanup)();
|
||||
func_win_sparkle_cleanup winsparkle_cleanup = nullptr;
|
||||
|
||||
wxString temp_file_name;
|
||||
|
||||
// the API needs to access the function pointers
|
||||
friend void win_sparkle_init();
|
||||
friend void win_sparkle_check_update_with_ui();
|
||||
friend void win_sparkle_set_appcast_url(const char *url);
|
||||
friend void win_sparkle_set_app_details(const wchar_t *company_name, const wchar_t *app_name, const wchar_t *app_version);
|
||||
friend void win_sparkle_cleanup();
|
||||
};
|
||||
|
||||
void win_sparkle_init();
|
||||
|
|
|
@ -198,7 +198,7 @@ static void init_check_for_updates()
|
|||
wxString version(vbam_version);
|
||||
//win_sparkle_set_appcast_url("https://github.com/visualboyadvance-m/visualboyadvance-m/data/appcast.xml");
|
||||
win_sparkle_set_appcast_url("https://raw.githubusercontent.com/visualboyadvance-m/visualboyadvance-m/update-checker/data/appcast.xml");
|
||||
win_sparkle_set_app_details(L"visualboyadvance-m", L"VisualBoyAdvance-M", version.c_str());
|
||||
win_sparkle_set_app_details(L"visualboyadvance-m", L"VisualBoyAdvance-M", version.wc_str());
|
||||
win_sparkle_init();
|
||||
#endif // __WXMSW__
|
||||
}
|
||||
|
@ -451,10 +451,6 @@ bool wxvbamApp::OnInit()
|
|||
frame->ShowFullScreen(isFullscreen);
|
||||
frame->Show(true);
|
||||
|
||||
#if defined(__WXMSW__) && !defined(NO_ONLINEUPDATES)
|
||||
winsparkle = new WinSparkleDllWrapper();
|
||||
#endif
|
||||
|
||||
#ifndef NO_ONLINEUPDATES
|
||||
init_check_for_updates();
|
||||
#endif
|
||||
|
@ -710,7 +706,6 @@ wxvbamApp::~wxvbamApp() {
|
|||
|
||||
#if defined(__WXMSW__) && !defined(NO_ONLINEUPDATES)
|
||||
win_sparkle_cleanup();
|
||||
delete winsparkle;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -73,7 +73,6 @@ inline std::string ToString(const wxChar* aString)
|
|||
}
|
||||
|
||||
class MainFrame;
|
||||
class WinSparkleDllWrapper;
|
||||
|
||||
class wxvbamApp : public wxApp {
|
||||
public:
|
||||
|
@ -158,7 +157,6 @@ protected:
|
|||
private:
|
||||
wxPathList config_path;
|
||||
char* home = nullptr;
|
||||
WinSparkleDllWrapper *winsparkle = nullptr;
|
||||
};
|
||||
|
||||
DECLARE_APP(wxvbamApp);
|
||||
|
|
|
@ -5,9 +5,6 @@ AAAAA_MAINICON ICON "icons/vbam.ico"
|
|||
|
||||
#include "version.h"
|
||||
|
||||
#include "winsparkle-wrapper.h"
|
||||
#include "winsparkle-path.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Version
|
||||
|
@ -16,8 +13,15 @@ AAAAA_MAINICON ICON "icons/vbam.ico"
|
|||
#define VER_PRODUCTVERSION VER_FILEVERSION
|
||||
#define VER_PRODUCTVERSION_STR VER_FILEVERSION_STR
|
||||
|
||||
#ifndef NO_ONLINEUPDATES
|
||||
|
||||
#include "winsparkle-rc.h"
|
||||
#include "winsparkle-path.h"
|
||||
|
||||
WINSPARKLE_DLL_RC RCDATA WINSPARKLE_DLL_PATH
|
||||
|
||||
#endif /* NO_ONLINEUPDATES */
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION VER_FILEVERSION
|
||||
PRODUCTVERSION VER_PRODUCTVERSION
|
||||
|
|
Loading…
Reference in New Issue