Auto-start
This commit is contained in:
@@ -24,7 +24,7 @@ public:
|
||||
JProperty(std::uint8_t, MaxUploadCount, public, public, _configDocument)
|
||||
JProperty(std::string, HostNameOrIp, public, public, _configDocument)
|
||||
JProperty(bool, LockWalletOnExit, public, public, _configDocument)
|
||||
JProperty(bool, AutoStartOnLogon, public, public, _configDocument)
|
||||
JPropertyCb(bool, AutoStartOnLogon, public, public, _configDocument, OnAutoStartOnLogonChanged)
|
||||
JProperty(bool, LaunchBundledSiad, public, public, _configDocument)
|
||||
JProperty(bool, LaunchFileMgrOnMount, public, public, _configDocument)
|
||||
JProperty(std::string, EventLevel, public, public, _configDocument)
|
||||
@@ -37,6 +37,8 @@ private:
|
||||
|
||||
void Load( );
|
||||
|
||||
void OnAutoStartOnLogonChanged(const bool& value);
|
||||
|
||||
void Save() const;
|
||||
};
|
||||
|
||||
|
@@ -22,6 +22,8 @@ int APIENTRY wWinMain(HINSTANCE hInstance,
|
||||
{
|
||||
UNREFERENCED_PARAMETER(hPrevInstance);
|
||||
UNREFERENCED_PARAMETER(lpCmdLine);
|
||||
::CoInitializeEx(nullptr, COINIT_MULTITHREADED);
|
||||
|
||||
std::shared_ptr<CSiaDriveConfig> siaDriveConfig(new CSiaDriveConfig);
|
||||
const EventLevel eventLevel = EventLevelFromString(siaDriveConfig->GetEventLevel());
|
||||
#ifdef _DEBUG
|
||||
@@ -70,5 +72,7 @@ int APIENTRY wWinMain(HINSTANCE hInstance,
|
||||
CefRunMessageLoop();
|
||||
CefShutdown();
|
||||
|
||||
::CoUninitialize();
|
||||
|
||||
return 0;;
|
||||
}
|
||||
|
@@ -5,6 +5,8 @@
|
||||
#include <bitset>
|
||||
#include <filepath.h>
|
||||
#include <siadriveconfig.h>
|
||||
#include <shlguid.h>
|
||||
#include <Shlobj.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <Wincrypt.h>
|
||||
@@ -231,6 +233,29 @@ bool ExecuteProcess(CSiaDriveConfig* siaDriveConfig, FilePath process, FilePath
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
HRESULT CreateShortcut(const SString& execPath, const SString& description, const SString& shortcutPath)
|
||||
{
|
||||
IShellLink* shellLink(nullptr);
|
||||
HRESULT hr = ::CoCreateInstance(CLSID_ShellLink, nullptr, CLSCTX_INPROC_SERVER, IID_IShellLink, reinterpret_cast<LPVOID*>(&shellLink));
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
shellLink->SetPath(&execPath[0]);
|
||||
shellLink->SetWorkingDirectory(&FilePath(execPath).RemoveFileName()[0]);
|
||||
shellLink->SetDescription(&description[0]);
|
||||
|
||||
IPersistFile* persistFile(nullptr);
|
||||
hr = shellLink->QueryInterface(IID_IPersistFile, reinterpret_cast<LPVOID*>(&persistFile));
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
hr = persistFile->Save(&shortcutPath[0], TRUE);
|
||||
persistFile->Release();
|
||||
}
|
||||
shellLink->Release();
|
||||
}
|
||||
|
||||
return hr;
|
||||
}
|
||||
#endif
|
||||
|
||||
NS_END(2)
|
@@ -2,6 +2,7 @@
|
||||
#include <fstream>
|
||||
#include <filepath.h>
|
||||
#include <siacommon.h>
|
||||
#include <Shlobj.h>
|
||||
using namespace Sia::Api;
|
||||
|
||||
CSiaDriveConfig::CSiaDriveConfig() :
|
||||
@@ -20,6 +21,36 @@ CSiaDriveConfig::~CSiaDriveConfig()
|
||||
Save();
|
||||
}
|
||||
|
||||
void CSiaDriveConfig::OnAutoStartOnLogonChanged(const bool& value)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
PWSTR startupPath;
|
||||
if (SUCCEEDED(::SHGetKnownFolderPath(FOLDERID_Startup, 0, nullptr, &startupPath)))
|
||||
{
|
||||
FilePath shortcutPath(startupPath, "SiaDrive.lnk");
|
||||
|
||||
const BOOL exists = ::PathFileExists(&shortcutPath[0]);
|
||||
if (value)
|
||||
{
|
||||
if (!exists)
|
||||
{
|
||||
SString execPath;
|
||||
execPath.Resize(MAX_PATH + 1);
|
||||
GetModuleFileName(::GetModuleHandle(nullptr), &execPath[0], MAX_PATH);
|
||||
CreateShortcut(execPath, "SiaDrive", shortcutPath);
|
||||
}
|
||||
}
|
||||
else if (exists)
|
||||
{
|
||||
::DeleteFile(&shortcutPath[0]);
|
||||
}
|
||||
::CoTaskMemFree(startupPath);
|
||||
}
|
||||
#else
|
||||
a
|
||||
#endif
|
||||
}
|
||||
|
||||
bool CSiaDriveConfig::LoadDefaults()
|
||||
{
|
||||
bool changed = false;
|
||||
|
Reference in New Issue
Block a user