1
0

Lock wallet on exit and event level

This commit is contained in:
Scott E. Graves
2017-04-24 14:10:11 -05:00
parent fce3e669e0
commit 52141a3227
13 changed files with 66 additions and 84 deletions

3
.gitignore vendored
View File

@@ -253,3 +253,6 @@ ModelManifest.xml
/3rd_party/Sia-v1.2.0-windows-amd64.zip
/3rd_party/Sia
/Output
/SiaDrive_Packager_Debug.iss
/include/siadrive_api/siacommon.h
/SiaDrive_Packager_Release.iss

View File

@@ -4,6 +4,7 @@ cmake_minimum_required(VERSION 3.3)
#Common Configuration Pre-setup
set(SIADRIVE_VERSION 0.1_Alpha1)
string(REPLACE "\\" "/" SIADRIVE_INSTALL_FOLDER ${SIADRIVE_INSTALL_FOLDER})
set(EXTERNAL_BUILD_ROOT ${CMAKE_BINARY_DIR}/external)
set(EXTERNAL_BUILD_TYPE ${CMAKE_BUILD_TYPE})
@@ -13,6 +14,7 @@ add_definitions(-DTTMATH_NOASM)
#SiaDrive API Library
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include/siadrive_api/siacommon.h.in ${CMAKE_CURRENT_SOURCE_DIR}/include/siadrive_api/siacommon.h @ONLY)
file(GLOB_RECURSE SIADRIVE_API_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/siadrive_api/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/siadrive_api/*.cxx
@@ -24,6 +26,7 @@ set_target_properties(siadrive.api
)
if (MSVC)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/SiaDrive_Packager.iss.in ${CMAKE_CURRENT_SOURCE_DIR}/SiaDrive_Packager_${CMAKE_BUILD_TYPE}.iss @ONLY)
set(DOKANY_VERSION dokany-1.0.3)
ExternalProject_Add(curl_project
URL https://github.com/curl/curl/archive/curl-7_53_1.tar.gz

View File

@@ -1,57 +0,0 @@
; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
#define MyAppName "SiaDrive [DEBUG]"
#define MyAppVersion "0.0.1_PRE_RELEASE"
#define MyAppPublisher "SiaExtensions"
#define MyAppURL "https://github.com/SiaExtensions/SiaDrive"
#define MyAppExeName "siadrive.exe"
[Setup]
; NOTE: The value of AppId uniquely identifies this application.
; Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{C783A865-35A2-4740-A075-48F61C126505}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={pf}\{#MyAppName}
DisableProgramGroupPage=yes
LicenseFile=.\LICENSE
OutputBaseFilename=SiaDrive_{#MyAppVersion}_Debug_x64
Compression=lzma
SolidCompression=yes
ArchitecturesAllowed=x64
ArchitecturesInstallIn64BitMode=x64
[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"
[Components]
Name: "main"; Description: "SiaDrive Files"; Types: full compact custom; Flags: fixed
Name: "vc_runtime"; Description: "Visual C++ 2015 Redistributable"; Types: full custom
Name: "dokany"; Description: "Dokany v1.0.3"; Types: full custom
Name: "sia"; Description: "Sia v1.2.0"; Types: full custom
[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked; Components: main
[Files]
Source: ".\dist\Debug\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs; Components: main
Source: ".\3rd_party\Dokan_x64.msi"; Destdir: "{tmp}"; Flags: deleteafterinstall overwritereadonly; Components: dokany
Source: ".\3rd_party\vc_redist.x64.exe"; Destdir: "{tmp}"; Flags: deleteafterinstall overwritereadonly; Components: vc_runtime
Source: ".\3rd_party\Sia\*"; Destdir: "{app}\sia"; Flags: recursesubdirs createallsubdirs overwritereadonly; Components: sia
; NOTE: Don't use "Flags: ignoreversion" on any shared system files
[Icons]
Name: "{commonprograms}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Components: main
Name: "{commondesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon; Components: main
[Run]
Filename: "{tmp}\vc_redist.x64.exe"; Parameters: "/install /passive /norestart"; Flags: 64bit waituntilterminated; Components: vc_runtime
Filename: "msiexec.exe"; Parameters: "/i {tmp}\Dokan_x64.msi /passive /norestart"; Flags: 64bit waituntilterminated; Components: dokany
Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent; Components: main

View File

@@ -2,7 +2,7 @@
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
#define MyAppName "SiaDrive"
#define MyAppVersion "0.0.1_PRE_RELEASE"
#define MyAppVersion "@SIADRIVE_VERSION@"
#define MyAppPublisher "SiaExtensions"
#define MyAppURL "https://github.com/SiaExtensions/SiaDrive"
#define MyAppExeName "siadrive.exe"
@@ -22,9 +22,9 @@ AppUpdatesURL={#MyAppURL}
DefaultDirName={pf}\{#MyAppName}
DisableProgramGroupPage=yes
LicenseFile=.\LICENSE
OutputBaseFilename=SiaDrive_{#MyAppVersion}_x64
OutputBaseFilename=SiaDrive_{#MyAppVersion}_@CMAKE_BUILD_TYPE@_x64
Compression=lzma
SolidCompression=yes
SolidCompression=yes
ArchitecturesAllowed=x64
ArchitecturesInstallIn64BitMode=x64
@@ -41,7 +41,7 @@ Name: "sia"; Description: "Sia v1.2.0"; Types: full custom
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked; Components: main
[Files]
Source: ".\dist\Release\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs; Components: main
Source: ".\dist\@CMAKE_BUILD_TYPE@\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs; Components: main
Source: ".\3rd_party\Dokan_x64.msi"; Destdir: "{tmp}"; Flags: deleteafterinstall overwritereadonly; Components: dokany
Source: ".\3rd_party\vc_redist.x64.exe"; Destdir: "{tmp}"; Flags: deleteafterinstall overwritereadonly; Components: vc_runtime
Source: ".\3rd_party\Sia\*"; Destdir: "{app}\sia"; Flags: recursesubdirs createallsubdirs overwritereadonly; Components: sia
@@ -55,4 +55,3 @@ Name: "{commondesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks:
Filename: "{tmp}\vc_redist.x64.exe"; Parameters: "/install /passive /norestart"; Flags: 64bit waituntilterminated; Components: vc_runtime
Filename: "msiexec.exe"; Parameters: "/i {tmp}\Dokan_x64.msi /passive /norestart"; Flags: 64bit waituntilterminated; Components: dokany
Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent; Components: main

View File

@@ -63,7 +63,7 @@ public:
private:
static void ExecuteSetter(CefRefPtr<CefV8Context> context, CefRefPtr<CefV8Value> obj, const SString& method, const SString& value);
static void ExecuteSetter(CefRefPtr<CefV8Context> context, CefRefPtr<CefV8Value> obj, const SString& method, CefRefPtr<CefV8Value> value);
void ShutdownServices();
void ShutdownServices(const bool& closing = false);
void SiaApiRefreshCallback(CefRefPtr<CefV8Context> context, const Api::CSiaCurl& siaCurl, Api::CSiaDriveConfig* siaDriveConfig);
private:

View File

@@ -12,6 +12,8 @@ enum class EventLevel
Debug
};
EventLevel SIADRIVE_EXPORTABLE EventLevelFromString(const SString& eventLevel);
class SIADRIVE_EXPORTABLE CEvent
{
public:

View File

@@ -2,7 +2,7 @@
#define _SIACOMMON_H
#include <cstdint>
#define SIDRIVE_VERSION_STRING "0.0.1"
#define SIADRIVE_VERSION_STRING "@SIADRIVE_VERSION@"
#define COMPAT_SIAD_VERSION "1.2.0"
#ifdef _WIN32

View File

@@ -26,6 +26,7 @@ public:
JProperty(bool, LockWalletOnExit, public, public, _configDocument)
JProperty(bool, AutoStartOnLogon, public, public, _configDocument)
JProperty(bool, LaunchBundledSiad, public, public, _configDocument)
JProperty(std::string, EventLevel, public, public, _configDocument)
private:
json _configDocument;

View File

@@ -22,17 +22,16 @@ int APIENTRY wWinMain(HINSTANCE hInstance,
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
std::shared_ptr<CSiaDriveConfig> siaDriveConfig(new CSiaDriveConfig);
const EventLevel eventLevel = EventLevelFromString(siaDriveConfig->GetEventLevel());
#ifdef _DEBUG
CDebugConsumer debugConsumer;
CLoggingConsumer loggingConsumer(EventLevel::Debug);
#else
CLoggingConsumer loggingConsumer(EventLevel::Normal);
#endif
CLoggingConsumer loggingConsumer(eventLevel);
CEventSystem::EventSystem.Start();
CefEnableHighDPISupport();
CefMainArgs mainArgs(hInstance);
std::shared_ptr<CSiaDriveConfig> siaDriveConfig(new CSiaDriveConfig);
CefRefPtr<CSiaDriveApp> app(new CSiaDriveApp(siaDriveConfig));
int exitCode = CefExecuteProcess(mainArgs, app, nullptr);
if (exitCode >= 0)
@@ -70,7 +69,6 @@ int APIENTRY wWinMain(HINSTANCE hInstance,
CefRunMessageLoop();
CefShutdown();
CEventSystem::EventSystem.Stop();
return 0;;
}

View File

@@ -288,14 +288,6 @@ CSiaDriveApp::CSiaDriveApp(std::shared_ptr<Api::CSiaDriveConfig> siaDriveConfig)
CSiaDriveApp::~CSiaDriveApp()
{
if (_siaApi)
{
_siaApi->StopBackgroundRefresh();
}
ShutdownServices();
_siaDrive.reset(nullptr);
_siaApi.reset(nullptr);
_siaCurl.reset(nullptr);
}
void CSiaDriveApp::ExecuteSetter(CefRefPtr<CefV8Context> context, CefRefPtr<CefV8Value> obj, const SString& method, const SString& value)
@@ -328,10 +320,10 @@ void CSiaDriveApp::OnContextCreated(
CefRefPtr<CefV8Value> global = context->GetGlobal();
CefRefPtr<FunctionHandler> handler(new FunctionHandler(*_siaApi, _appStarted, _siaDriveConfig, _siaDrive, [this]() {this->ShutdownServices(); }, [this](CefRefPtr<CefV8Context> context) {this->SiaApiRefreshCallback(context, *_siaCurl, _siaDriveConfig.get()); }));
CefRefPtr<FunctionHandler> handler(new FunctionHandler(*_siaApi, _appStarted, _siaDriveConfig, _siaDrive, [this]() {this->ShutdownServices(true); }, [this](CefRefPtr<CefV8Context> context) {this->SiaApiRefreshCallback(context, *_siaCurl, _siaDriveConfig.get()); }));
CefRefPtr<CefV8Value> obj = CefV8Value::CreateObject(nullptr, nullptr);
obj->SetValue("clientVersion", CefV8Value::CreateString(SIDRIVE_VERSION_STRING), V8_PROPERTY_ATTRIBUTE_NONE);
obj->SetValue("clientVersion", CefV8Value::CreateString(SIADRIVE_VERSION_STRING), V8_PROPERTY_ATTRIBUTE_NONE);
obj->SetValue("isOnline", CefV8Value::CreateBool(_siaApi->GetWallet()->GetConnected()), V8_PROPERTY_ATTRIBUTE_NONE);
CefRefPtr<CefV8Value> defaultFunds = CefV8Value::CreateObject(nullptr, nullptr);
defaultFunds->SetValue("Funds", CefV8Value::CreateString(SIA_DEFAULT_MINIMUM_FUNDS.ToString()), V8_PROPERTY_ATTRIBUTE_NONE);
@@ -395,7 +387,7 @@ void CSiaDriveApp::OnContextInitialized()
}
}
void CSiaDriveApp::ShutdownServices()
void CSiaDriveApp::ShutdownServices(const bool& closing)
{
if (_refreshThread)
{
@@ -408,6 +400,23 @@ void CSiaDriveApp::ShutdownServices()
{
_siaDrive->Unmount();
}
if (closing)
{
if (_siaDriveConfig->GetLockWalletOnExit())
{
_siaApi->GetWallet()->Lock();
}
if (_siaApi)
{
_siaApi->StopBackgroundRefresh();
}
_siaDrive.reset(nullptr);
_siaApi.reset(nullptr);
_siaCurl.reset(nullptr);
CEventSystem::EventSystem.Stop();
}
}
void CSiaDriveApp::SiaApiRefreshCallback(CefRefPtr<CefV8Context> context, const CSiaCurl& siaCurl, CSiaDriveConfig* siaDriveConfig)

View File

@@ -4,6 +4,24 @@ using namespace Sia::Api;
CEventSystem CEventSystem::EventSystem;
EventLevel Sia::Api::EventLevelFromString(const SString& eventLevel)
{
if (eventLevel == "Debug" || eventLevel == "EventLevel::Debug")
{
return EventLevel::Debug;
}
else if (eventLevel == "Normal" || eventLevel == "EventLevel::Normal")
{
return EventLevel::Normal;
}
else if (eventLevel == "Error" || eventLevel == "EventLevel::Error")
{
return EventLevel::Error;
}
return EventLevel::Normal;
}
CEventSystem::CEventSystem() :
#ifdef _WIN32
_stopEvent(INVALID_HANDLE_VALUE)

View File

@@ -18,10 +18,6 @@ CSiaApi::CSiaApi(const SiaHostConfig& hostConfig, CSiaDriveConfig* siaDriveConfi
CSiaApi::~CSiaApi()
{
if (_siaDriveConfig->GetLockWalletOnExit())
{
_wallet->Lock();
}
_refreshThread->StopAutoThread();
}

View File

@@ -92,6 +92,16 @@ bool CSiaDriveConfig::LoadDefaults()
changed = true;
}
if (!CheckEventLevel())
{
#ifdef _DEBUG
SetEventLevel("Debug");
#else
SetEventLevel("Normal");
#endif
changed = true;
}
return changed;
}