Stuff
This commit is contained in:
Binary file not shown.
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 27 KiB |
@@ -545,8 +545,4 @@
|
||||
console.log('Main window load');
|
||||
reloadApplication();
|
||||
});
|
||||
|
||||
window.onunload = ()=> {
|
||||
AppActions.shutdown();
|
||||
};
|
||||
})();
|
@@ -27,7 +27,7 @@ class CSiaDriveApp :
|
||||
public CefBrowserProcessHandler
|
||||
{
|
||||
public:
|
||||
CSiaDriveApp(std::shared_ptr<Api::CSiaDriveConfig> siaDriveConfig);
|
||||
CSiaDriveApp();
|
||||
|
||||
virtual ~CSiaDriveApp();
|
||||
|
||||
@@ -59,11 +59,12 @@ public:
|
||||
// CefBrowserProcessHandler methods:
|
||||
virtual void OnContextInitialized() OVERRIDE;
|
||||
virtual void OnContextCreated(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefV8Context> context) OVERRIDE;
|
||||
|
||||
virtual bool OnProcessMessageReceived(CefRefPtr<CefBrowser> browser, CefProcessId source_process, CefRefPtr<CefProcessMessage> message) OVERRIDE;
|
||||
|
||||
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(const bool& closing = false);
|
||||
void ShutdownServices(CefRefPtr<CefBrowser> browser, const bool& closing = false);
|
||||
void SiaApiRefreshCallback(CefRefPtr<CefV8Context> context, const Api::CSiaCurl& siaCurl, Api::CSiaDriveConfig* siaDriveConfig);
|
||||
|
||||
private:
|
||||
|
@@ -46,20 +46,22 @@ public:
|
||||
virtual bool DoClose(CefRefPtr<CefBrowser> browser) OVERRIDE;
|
||||
virtual void OnBeforeClose(CefRefPtr<CefBrowser> browser) OVERRIDE;
|
||||
virtual void OnLoadError(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, ErrorCode errorCode, const CefString& errorText, const CefString& failedUrl) OVERRIDE;
|
||||
|
||||
virtual bool OnProcessMessageReceived(CefRefPtr<CefBrowser> browser, CefProcessId source_process, CefRefPtr<CefProcessMessage> message) OVERRIDE;
|
||||
void CloseAllBrowsers(bool forceClose);
|
||||
|
||||
bool IsClosing() const { return _isClosing; }
|
||||
|
||||
bool GetUseViews() const { return _useViews; }
|
||||
|
||||
private:
|
||||
void PlatformTitleChange(CefRefPtr<CefBrowser> browser, const CefString& title);
|
||||
private:
|
||||
const bool _useViews;
|
||||
bool _isClosing;
|
||||
bool _active;
|
||||
typedef std::list<CefRefPtr<CefBrowser> > BrowserList;
|
||||
BrowserList _browserList;
|
||||
|
||||
bool _isClosing;
|
||||
|
||||
IMPLEMENT_REFCOUNTING(CSiaDriveHandler);
|
||||
};
|
||||
NS_END(1)
|
||||
|
@@ -17,6 +17,9 @@ public:
|
||||
FilePath(const SString& path1, const SString& path2);
|
||||
FilePath(FilePath&& filePath);
|
||||
|
||||
public:
|
||||
~FilePath();
|
||||
|
||||
public:
|
||||
static const SString DirSep;
|
||||
|
||||
@@ -26,6 +29,9 @@ public:
|
||||
static SString GetAppDataDirectory();
|
||||
|
||||
private:
|
||||
#ifdef _WIN32
|
||||
const BOOL _uninit;
|
||||
#endif
|
||||
SString _path;
|
||||
|
||||
public:
|
||||
|
@@ -7,9 +7,9 @@ NS_BEGIN(Api)
|
||||
class SIADRIVE_EXPORTABLE CSiaDriveConfig
|
||||
{
|
||||
public:
|
||||
CSiaDriveConfig();
|
||||
CSiaDriveConfig(const bool& autoSave);
|
||||
|
||||
CSiaDriveConfig(const SString& filePath);
|
||||
CSiaDriveConfig(const bool& autoSave, const SString& filePath);
|
||||
|
||||
public:
|
||||
~CSiaDriveConfig();
|
||||
@@ -30,6 +30,7 @@ public:
|
||||
JProperty(std::string, EventLevel, public, public, _configDocument)
|
||||
|
||||
private:
|
||||
const bool _autoSave;
|
||||
json _configDocument;
|
||||
|
||||
private:
|
||||
|
@@ -23,52 +23,54 @@ int APIENTRY wWinMain(HINSTANCE hInstance,
|
||||
UNREFERENCED_PARAMETER(hPrevInstance);
|
||||
UNREFERENCED_PARAMETER(lpCmdLine);
|
||||
|
||||
std::shared_ptr<CSiaDriveConfig> siaDriveConfig(new CSiaDriveConfig);
|
||||
const EventLevel eventLevel = EventLevelFromString(siaDriveConfig->GetEventLevel());
|
||||
{
|
||||
std::shared_ptr<CSiaDriveConfig> siaDriveConfig(new CSiaDriveConfig(false));
|
||||
const EventLevel eventLevel = EventLevelFromString(siaDriveConfig->GetEventLevel());
|
||||
#ifdef _DEBUG
|
||||
CDebugConsumer debugConsumer;
|
||||
CDebugConsumer debugConsumer;
|
||||
#endif
|
||||
CLoggingConsumer loggingConsumer(eventLevel);
|
||||
CEventSystem::EventSystem.Start();
|
||||
CefEnableHighDPISupport();
|
||||
CLoggingConsumer loggingConsumer(eventLevel);
|
||||
CEventSystem::EventSystem.Start();
|
||||
CefEnableHighDPISupport();
|
||||
|
||||
CefMainArgs mainArgs(hInstance);
|
||||
CefRefPtr<CSiaDriveApp> app(new CSiaDriveApp(siaDriveConfig));
|
||||
int exitCode = CefExecuteProcess(mainArgs, app, nullptr);
|
||||
if (exitCode >= 0)
|
||||
{
|
||||
return exitCode;
|
||||
}
|
||||
|
||||
if (siaDriveConfig->GetLaunchBundledSiad())
|
||||
{
|
||||
SiaHostConfig hostConfig;
|
||||
hostConfig.HostName = siaDriveConfig->GetHostNameOrIp();
|
||||
hostConfig.HostPort = siaDriveConfig->GetApiPort();
|
||||
hostConfig.RequiredVersion = COMPAT_SIAD_VERSION;
|
||||
|
||||
CSiaApi api(hostConfig, siaDriveConfig.get());
|
||||
if (api.GetServerVersion().IsNullOrEmpty())
|
||||
CefMainArgs mainArgs(hInstance);
|
||||
CefRefPtr<CSiaDriveApp> app(new CSiaDriveApp);
|
||||
int exitCode = CefExecuteProcess(mainArgs, app, nullptr);
|
||||
if (exitCode >= 0)
|
||||
{
|
||||
FilePath dataPath(FilePath::GetAppDataDirectory(), "siadrive");
|
||||
dataPath.Append("data");
|
||||
dataPath.CreateDirectory();
|
||||
ExecuteProcess(siaDriveConfig.get(), FilePath("./sia/siad"), dataPath, false);
|
||||
return exitCode;
|
||||
}
|
||||
}
|
||||
|
||||
CefSettings settings;
|
||||
settings.no_sandbox = true;
|
||||
if (siaDriveConfig->GetLaunchBundledSiad())
|
||||
{
|
||||
SiaHostConfig hostConfig;
|
||||
hostConfig.HostName = siaDriveConfig->GetHostNameOrIp();
|
||||
hostConfig.HostPort = siaDriveConfig->GetApiPort();
|
||||
hostConfig.RequiredVersion = COMPAT_SIAD_VERSION;
|
||||
|
||||
CSiaApi api(hostConfig, siaDriveConfig.get());
|
||||
if (api.GetServerVersion().IsNullOrEmpty())
|
||||
{
|
||||
FilePath dataPath(FilePath::GetAppDataDirectory(), "siadrive");
|
||||
dataPath.Append("data");
|
||||
dataPath.CreateDirectory();
|
||||
ExecuteProcess(siaDriveConfig.get(), FilePath("./sia/siad"), dataPath, false);
|
||||
}
|
||||
}
|
||||
|
||||
CefSettings settings;
|
||||
settings.no_sandbox = true;
|
||||
#ifdef _DEBUG
|
||||
settings.remote_debugging_port = 8080;
|
||||
settings.single_process = true;
|
||||
settings.log_severity = LOGSEVERITY_VERBOSE;
|
||||
settings.remote_debugging_port = 8080;
|
||||
settings.single_process = true;
|
||||
settings.log_severity = LOGSEVERITY_VERBOSE;
|
||||
#else
|
||||
settings.log_severity = LOGSEVERITY_DISABLE;
|
||||
settings.log_severity = LOGSEVERITY_DISABLE;
|
||||
#endif
|
||||
CefInitialize(mainArgs, settings, app, nullptr);
|
||||
|
||||
CefRunMessageLoop();
|
||||
CefInitialize(mainArgs, settings, app, nullptr);
|
||||
|
||||
CefRunMessageLoop();
|
||||
}
|
||||
CefShutdown();
|
||||
|
||||
return 0;;
|
||||
|
@@ -7,9 +7,9 @@
|
||||
#include <siaapi.h>
|
||||
#include <siacurl.h>
|
||||
#include <siadriveconfig.h>
|
||||
#include "siadrivehandler.h"
|
||||
#include <siadokandrive.h>
|
||||
#include <eventsystem.h>
|
||||
#include <siadrivehandler.h>
|
||||
|
||||
using namespace Sia;
|
||||
using namespace Sia::Api;
|
||||
@@ -22,23 +22,20 @@ public:
|
||||
bool& appStarted,
|
||||
std::shared_ptr<CSiaDriveConfig>& siaDriveConfig,
|
||||
std::unique_ptr<Api::Dokan::CSiaDokanDrive>& siaDrive,
|
||||
std::function<void()> shutdownCallback,
|
||||
std::function<void(CefRefPtr<CefV8Context> context)> refreshCallback) :
|
||||
_siaApi(siaApi),
|
||||
_siaDriveConfig(siaDriveConfig),
|
||||
_siaDriveConfig(siaDriveConfig.get()),
|
||||
_siaDrive(siaDrive),
|
||||
_appStarted(appStarted),
|
||||
_shutdownCallback(shutdownCallback),
|
||||
_refreshCallback(refreshCallback)
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
const CSiaApi& _siaApi;
|
||||
std::shared_ptr<CSiaDriveConfig> _siaDriveConfig;
|
||||
CSiaDriveConfig* _siaDriveConfig;
|
||||
std::unique_ptr<Api::Dokan::CSiaDokanDrive>& _siaDrive;
|
||||
bool& _appStarted;
|
||||
std::function<void()> _shutdownCallback;
|
||||
std::function<void(CefRefPtr<CefV8Context> context)> _refreshCallback;
|
||||
|
||||
private:
|
||||
@@ -186,7 +183,6 @@ public:
|
||||
}
|
||||
else if (name == "shutdown")
|
||||
{
|
||||
_shutdownCallback();
|
||||
return true;
|
||||
}
|
||||
else if (name == "setRenterSettings")
|
||||
@@ -282,8 +278,7 @@ private:
|
||||
DISALLOW_COPY_AND_ASSIGN(SimpleWindowDelegate);
|
||||
};
|
||||
|
||||
CSiaDriveApp::CSiaDriveApp(std::shared_ptr<Api::CSiaDriveConfig> siaDriveConfig) :
|
||||
_siaDriveConfig(siaDriveConfig)
|
||||
CSiaDriveApp::CSiaDriveApp()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -304,6 +299,19 @@ void CSiaDriveApp::ExecuteSetter(CefRefPtr<CefV8Context> context, CefRefPtr<CefV
|
||||
setConfirmed->ExecuteFunctionWithContext(context, nullptr, args);
|
||||
}
|
||||
|
||||
bool CSiaDriveApp::OnProcessMessageReceived(CefRefPtr<CefBrowser> browser, CefProcessId source_process, CefRefPtr<CefProcessMessage> message)
|
||||
{
|
||||
CEF_REQUIRE_RENDERER_THREAD();
|
||||
const std::string& messageName = message->GetName();
|
||||
if (messageName == "shutdownServices")
|
||||
{
|
||||
this->ShutdownServices(browser, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void CSiaDriveApp::OnContextCreated(
|
||||
CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
@@ -311,6 +319,8 @@ void CSiaDriveApp::OnContextCreated(
|
||||
{
|
||||
CEF_REQUIRE_RENDERER_THREAD();
|
||||
|
||||
_siaDriveConfig.reset(new CSiaDriveConfig(true));
|
||||
|
||||
SiaHostConfig hostConfig;
|
||||
hostConfig.HostName = _siaDriveConfig->GetHostNameOrIp();
|
||||
hostConfig.HostPort = _siaDriveConfig->GetApiPort();
|
||||
@@ -321,7 +331,7 @@ void CSiaDriveApp::OnContextCreated(
|
||||
|
||||
CefRefPtr<CefV8Value> global = context->GetGlobal();
|
||||
|
||||
CefRefPtr<FunctionHandler> handler(new FunctionHandler(*_siaApi, _appStarted, _siaDriveConfig, _siaDrive, [this]() {this->ShutdownServices(true); }, [this](CefRefPtr<CefV8Context> context) {this->SiaApiRefreshCallback(context, *_siaCurl, _siaDriveConfig.get()); }));
|
||||
CefRefPtr<FunctionHandler> handler(new FunctionHandler(*_siaApi, _appStarted, _siaDriveConfig, _siaDrive, [this](CefRefPtr<CefV8Context> context) {this->SiaApiRefreshCallback(context, *_siaCurl, _siaDriveConfig.get()); }));
|
||||
|
||||
CefRefPtr<CefV8Value> obj = CefV8Value::CreateObject(nullptr, nullptr);
|
||||
obj->SetValue("clientVersion", CefV8Value::CreateString(SIADRIVE_VERSION_STRING), V8_PROPERTY_ATTRIBUTE_NONE);
|
||||
@@ -358,21 +368,21 @@ void CSiaDriveApp::OnContextInitialized()
|
||||
{
|
||||
CEF_REQUIRE_UI_THREAD();
|
||||
|
||||
CefRefPtr<CefCommandLine> commandLine = CefCommandLine::GetGlobalCommandLine();
|
||||
|
||||
#if defined(OS_WIN) || defined(OS_LINUX)
|
||||
const bool useViews = commandLine->HasSwitch("use-views");
|
||||
#else
|
||||
const bool useViews = false;
|
||||
#endif
|
||||
|
||||
CefRefPtr<CSiaDriveHandler> handler(new CSiaDriveHandler(useViews));
|
||||
CefBrowserSettings browserSettings;
|
||||
|
||||
SString url = "file:///./htdocs/index.html";
|
||||
if (useViews)
|
||||
CefRefPtr<CefCommandLine> commandLine = CefCommandLine::GetGlobalCommandLine();
|
||||
|
||||
#if defined(OS_WIN) || defined(OS_LINUX)
|
||||
const bool useViews = commandLine->HasSwitch("use-views");
|
||||
#else
|
||||
const bool useViews = false;
|
||||
#endif
|
||||
|
||||
CefRefPtr<CSiaDriveHandler> _handler(new CSiaDriveHandler(useViews));
|
||||
if (_handler->GetUseViews())
|
||||
{
|
||||
CefRefPtr<CefBrowserView> browserView = CefBrowserView::CreateBrowserView(handler, url.str(), browserSettings, nullptr, nullptr);
|
||||
CefRefPtr<CefBrowserView> browserView = CefBrowserView::CreateBrowserView(_handler, url.str(), browserSettings, nullptr, nullptr);
|
||||
CefWindow::CreateTopLevelWindow(new SimpleWindowDelegate(browserView));
|
||||
}
|
||||
else
|
||||
@@ -384,11 +394,11 @@ void CSiaDriveApp::OnContextInitialized()
|
||||
windowInfo.width = 800;
|
||||
windowInfo.height = 675;
|
||||
|
||||
CefBrowserHost::CreateBrowser(windowInfo, handler, url.str(), browserSettings, nullptr);
|
||||
CefBrowserHost::CreateBrowser(windowInfo, _handler, url.str(), browserSettings, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
void CSiaDriveApp::ShutdownServices(const bool& closing)
|
||||
void CSiaDriveApp::ShutdownServices(CefRefPtr<CefBrowser> browser, const bool& closing)
|
||||
{
|
||||
if (_refreshThread)
|
||||
{
|
||||
@@ -404,7 +414,7 @@ void CSiaDriveApp::ShutdownServices(const bool& closing)
|
||||
|
||||
if (closing)
|
||||
{
|
||||
if (_siaDriveConfig->GetLockWalletOnExit())
|
||||
if (_siaDriveConfig && _siaDriveConfig->GetLockWalletOnExit())
|
||||
{
|
||||
_siaApi->GetWallet()->Lock();
|
||||
}
|
||||
@@ -417,6 +427,10 @@ void CSiaDriveApp::ShutdownServices(const bool& closing)
|
||||
_siaApi.reset(nullptr);
|
||||
_siaCurl.reset(nullptr);
|
||||
CEventSystem::EventSystem.Stop();
|
||||
_siaDriveConfig.reset();
|
||||
|
||||
CefRefPtr<CefProcessMessage> msg = CefProcessMessage::Create("shutdownServicesComplete");
|
||||
browser->SendProcessMessage(PID_BROWSER, msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -17,7 +17,8 @@ static NOTIFYICONDATA g_notifyIcon = { 0 };
|
||||
|
||||
CSiaDriveHandler::CSiaDriveHandler(const bool& useViews) :
|
||||
_useViews(useViews),
|
||||
_isClosing(false)
|
||||
_isClosing(false),
|
||||
_active(true)
|
||||
{
|
||||
DCHECK(!g_instance);
|
||||
g_instance = this;
|
||||
@@ -53,6 +54,18 @@ void CSiaDriveHandler::OnTitleChange(CefRefPtr<CefBrowser> browser, const CefStr
|
||||
}
|
||||
}
|
||||
|
||||
bool CSiaDriveHandler::OnProcessMessageReceived(CefRefPtr<CefBrowser> browser, CefProcessId source_process, CefRefPtr<CefProcessMessage> message)
|
||||
{
|
||||
if (message->GetName() == "shutdownServicesComplete")
|
||||
{
|
||||
_active = false;
|
||||
browser->GetHost()->CloseBrowser(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void CSiaDriveHandler::OnAfterCreated(CefRefPtr<CefBrowser> browser)
|
||||
{
|
||||
CEF_REQUIRE_UI_THREAD();
|
||||
@@ -87,15 +100,18 @@ bool CSiaDriveHandler::DoClose(CefRefPtr<CefBrowser> browser)
|
||||
{
|
||||
CEF_REQUIRE_UI_THREAD();
|
||||
|
||||
if (_browserList.size() == 1)
|
||||
if (!_isClosing && (_browserList.size() == 1))
|
||||
{
|
||||
// Set a flag to indicate that the window close should be allowed.
|
||||
_isClosing = true;
|
||||
CefRefPtr<CefProcessMessage> msg = CefProcessMessage::Create("shutdownServices");
|
||||
browser->SendProcessMessage(PID_RENDERER, msg);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Allow the close. For windowed browsers this will result in the OS close
|
||||
// event being sent.
|
||||
return false;
|
||||
return _active;
|
||||
}
|
||||
|
||||
void CSiaDriveHandler::OnBeforeClose(CefRefPtr<CefBrowser> browser)
|
||||
@@ -112,10 +128,10 @@ void CSiaDriveHandler::OnBeforeClose(CefRefPtr<CefBrowser> browser)
|
||||
}
|
||||
}
|
||||
|
||||
if (_browserList.empty())
|
||||
if (_browserList.size() == 0)
|
||||
{
|
||||
CefQuitMessageLoop();
|
||||
::Shell_NotifyIcon(NIM_DELETE, &g_notifyIcon);
|
||||
CefQuitMessageLoop();
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -32,10 +32,17 @@ SString FilePath::GetTempDirectory()
|
||||
SString FilePath::GetAppDataDirectory()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
BOOL uninit = SUCCEEDED(::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED));
|
||||
|
||||
PWSTR localAppData = nullptr;
|
||||
::SHGetKnownFolderPath(FOLDERID_LocalAppData, 0, nullptr, &localAppData);
|
||||
SString ret = localAppData;
|
||||
::CoTaskMemFree(localAppData);
|
||||
|
||||
if (uninit)
|
||||
{
|
||||
::CoUninitialize();
|
||||
}
|
||||
return ret;
|
||||
#else
|
||||
a
|
||||
@@ -43,48 +50,83 @@ SString FilePath::GetAppDataDirectory()
|
||||
}
|
||||
|
||||
FilePath::FilePath()
|
||||
#ifdef _WIN32
|
||||
: _uninit(SUCCEEDED(::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED)))
|
||||
#endif
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
FilePath::FilePath(const FilePath& filePath) :
|
||||
#ifdef _WIN32
|
||||
_uninit(SUCCEEDED(::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED))),
|
||||
#endif
|
||||
_path(filePath)
|
||||
{
|
||||
}
|
||||
|
||||
FilePath::FilePath(const SString& path)
|
||||
#ifdef _WIN32
|
||||
: _uninit(SUCCEEDED(::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED)))
|
||||
#endif
|
||||
{
|
||||
_path = FinalizePath(path);
|
||||
}
|
||||
|
||||
FilePath::FilePath(const FilePath& filePath1, const FilePath& filePath2)
|
||||
#ifdef _WIN32
|
||||
: _uninit(SUCCEEDED(::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED)))
|
||||
#endif
|
||||
{
|
||||
_path = filePath1;
|
||||
Append(filePath2);
|
||||
}
|
||||
|
||||
FilePath::FilePath(const FilePath& filePath1, const SString& path2)
|
||||
#ifdef _WIN32
|
||||
: _uninit(SUCCEEDED(::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED)))
|
||||
#endif
|
||||
{
|
||||
_path = filePath1;
|
||||
Append(FinalizePath(path2));
|
||||
}
|
||||
|
||||
FilePath::FilePath(const SString& path1, const FilePath& filePath2)
|
||||
#ifdef _WIN32
|
||||
: _uninit(SUCCEEDED(::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED)))
|
||||
#endif
|
||||
{
|
||||
_path = FinalizePath(path1);
|
||||
Append(filePath2);
|
||||
}
|
||||
|
||||
FilePath::FilePath(const SString& path1, const SString& path2)
|
||||
FilePath::FilePath(const SString& path1, const SString& path2)
|
||||
#ifdef _WIN32
|
||||
: _uninit(SUCCEEDED(::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED)))
|
||||
#endif
|
||||
{
|
||||
_path = FinalizePath(path1);
|
||||
Append(FinalizePath(path2));
|
||||
}
|
||||
|
||||
FilePath::FilePath(FilePath&& filePath) :
|
||||
#ifdef _WIN32
|
||||
_uninit(SUCCEEDED(::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED))),
|
||||
#endif
|
||||
_path(std::move(filePath._path))
|
||||
{
|
||||
}
|
||||
|
||||
FilePath::~FilePath()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
if (_uninit)
|
||||
{
|
||||
::CoUninitialize();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
const SString FilePath::DirSep = "\\";
|
||||
#else
|
||||
|
@@ -236,6 +236,8 @@ bool ExecuteProcess(CSiaDriveConfig* siaDriveConfig, FilePath process, FilePath
|
||||
|
||||
HRESULT CreateShortcut(const SString& execPath, const SString& description, const SString& shortcutPath, const bool& minimized)
|
||||
{
|
||||
BOOL uninit = SUCCEEDED(::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED));
|
||||
|
||||
IShellLink* shellLink(nullptr);
|
||||
HRESULT hr = ::CoCreateInstance(CLSID_ShellLink, nullptr, CLSCTX_INPROC_SERVER, IID_IShellLink, reinterpret_cast<LPVOID*>(&shellLink));
|
||||
if (SUCCEEDED(hr))
|
||||
@@ -250,11 +252,16 @@ HRESULT CreateShortcut(const SString& execPath, const SString& description, cons
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
hr = persistFile->Save(&shortcutPath[0], TRUE);
|
||||
|
||||
persistFile->Release();
|
||||
}
|
||||
shellLink->Release();
|
||||
}
|
||||
|
||||
if (uninit)
|
||||
{
|
||||
::CoUninitialize();
|
||||
}
|
||||
return hr;
|
||||
}
|
||||
#endif
|
||||
|
@@ -5,12 +5,13 @@
|
||||
#include <Shlobj.h>
|
||||
using namespace Sia::Api;
|
||||
|
||||
CSiaDriveConfig::CSiaDriveConfig() :
|
||||
CSiaDriveConfig(DEFAULT_CONFIG_FILE_PATH)
|
||||
CSiaDriveConfig::CSiaDriveConfig(const bool& autoSave) :
|
||||
CSiaDriveConfig(autoSave, DEFAULT_CONFIG_FILE_PATH)
|
||||
{
|
||||
}
|
||||
|
||||
CSiaDriveConfig::CSiaDriveConfig(const SString& filePath) :
|
||||
CSiaDriveConfig::CSiaDriveConfig(const bool& autoSave, const SString& filePath) :
|
||||
_autoSave(autoSave),
|
||||
_FilePath(FilePath(filePath).Resolve())
|
||||
{
|
||||
Load();
|
||||
@@ -18,19 +19,28 @@ CSiaDriveConfig::CSiaDriveConfig(const SString& filePath) :
|
||||
|
||||
CSiaDriveConfig::~CSiaDriveConfig()
|
||||
{
|
||||
Save();
|
||||
if (_autoSave)
|
||||
{
|
||||
Save();
|
||||
}
|
||||
}
|
||||
|
||||
void CSiaDriveConfig::OnAutoStartOnLogonChanged(const bool& value)
|
||||
{
|
||||
#ifndef _DEBUG
|
||||
#ifdef _WIN32
|
||||
#if defined(_WIN32) && !defined(_DEBUG)
|
||||
BOOL uninit = SUCCEEDED(::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED));
|
||||
|
||||
PWSTR startupPath = nullptr;
|
||||
if (SUCCEEDED(::SHGetKnownFolderPath(FOLDERID_Startup, 0, nullptr, &startupPath)))
|
||||
{
|
||||
FilePath shortcutPath(startupPath, "SiaDrive.lnk");
|
||||
|
||||
const BOOL exists = ::PathFileExists(&shortcutPath[0]);
|
||||
const BOOL exists = ::PathFileExists(&shortcutPath[0]);
|
||||
if (exists)
|
||||
{
|
||||
::DeleteFile(&shortcutPath[0]);
|
||||
}
|
||||
|
||||
if (value)
|
||||
{
|
||||
if (!exists)
|
||||
@@ -38,19 +48,22 @@ void CSiaDriveConfig::OnAutoStartOnLogonChanged(const bool& value)
|
||||
SString execPath;
|
||||
execPath.Resize(MAX_PATH + 1);
|
||||
GetModuleFileName(::GetModuleHandle(nullptr), &execPath[0], MAX_PATH);
|
||||
execPath.Fit();
|
||||
CreateShortcut(execPath, "SiaDrive", shortcutPath, true);
|
||||
}
|
||||
}
|
||||
else if (exists)
|
||||
{
|
||||
::DeleteFile(&shortcutPath[0]);
|
||||
}
|
||||
|
||||
::CoTaskMemFree(startupPath);
|
||||
}
|
||||
#else
|
||||
|
||||
if (uninit)
|
||||
{
|
||||
::CoUninitialize();
|
||||
}
|
||||
#endif
|
||||
#if !defined(_WIN32)
|
||||
a
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
bool CSiaDriveConfig::LoadDefaults()
|
||||
@@ -153,9 +166,6 @@ bool CSiaDriveConfig::LoadDefaults()
|
||||
changed = true;
|
||||
}
|
||||
|
||||
// Do this to add/remove shortcut on start-up
|
||||
OnAutoStartOnLogonChanged(GetAutoStartOnLogon());
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
@@ -177,6 +187,9 @@ void CSiaDriveConfig::Load( )
|
||||
Save();
|
||||
}
|
||||
|
||||
// Do this to add/remove shortcut on start-up
|
||||
OnAutoStartOnLogonChanged(GetAutoStartOnLogon());
|
||||
|
||||
FilePath cacheFolder(GetCacheFolder());
|
||||
if (!cacheFolder.IsDirectory())
|
||||
{
|
||||
|
Reference in New Issue
Block a user