mirror of
https://github.com/tnodir/fort
synced 2024-11-15 05:25:56 +00:00
UI: StartupUtil: Add default language to auto-run command.
This commit is contained in:
parent
c37e7d61ed
commit
90a6c5d5c1
@ -53,7 +53,7 @@ void OptionsPage::onSaved()
|
||||
const bool wasServiceMode = StartupUtil::isServiceMode(m_currentStartMode);
|
||||
|
||||
m_currentStartMode = m_comboStartMode->currentIndex();
|
||||
StartupUtil::setStartupMode(m_currentStartMode);
|
||||
StartupUtil::setStartupMode(m_currentStartMode, settings()->defaultLanguage());
|
||||
|
||||
const bool isServiceMode = StartupUtil::isServiceMode(m_currentStartMode);
|
||||
if (isServiceMode != wasServiceMode) {
|
||||
|
@ -46,20 +46,20 @@ bool isAutorunForAllUsers()
|
||||
return isAutorunForUser(regAllUsersRun);
|
||||
}
|
||||
|
||||
void setAutorunForUser(const char *key)
|
||||
void setAutorunForUser(const char *key, const QString &command)
|
||||
{
|
||||
QSettings reg(key, QSettings::Registry64Format);
|
||||
reg.setValue(APP_NAME, wrappedAppFilePath());
|
||||
reg.setValue(APP_NAME, command);
|
||||
}
|
||||
|
||||
void setAutorunForCurrentUser()
|
||||
void setAutorunForCurrentUser(const QString &command)
|
||||
{
|
||||
setAutorunForUser(regCurUserRun);
|
||||
setAutorunForUser(regCurUserRun, command);
|
||||
}
|
||||
|
||||
void setAutorunForAllUsers()
|
||||
void setAutorunForAllUsers(const QString &command)
|
||||
{
|
||||
setAutorunForUser(regAllUsersRun);
|
||||
setAutorunForUser(regAllUsersRun, command);
|
||||
}
|
||||
|
||||
void removeAutorunForUser(const char *key)
|
||||
@ -78,17 +78,12 @@ void removeAutorunForAllUsers()
|
||||
removeAutorunForUser(regAllUsersRun);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const wchar_t *const StartupUtil::serviceName = L"" APP_BASE "Svc";
|
||||
const wchar_t *const StartupUtil::serviceDisplay = L"" APP_NAME;
|
||||
|
||||
bool StartupUtil::installService()
|
||||
bool installService(
|
||||
const wchar_t *serviceName, const wchar_t *serviceDisplay, const QString &command)
|
||||
{
|
||||
bool res = false;
|
||||
const SC_HANDLE mngr = OpenSCManager(NULL, NULL, SC_MANAGER_CREATE_SERVICE);
|
||||
if (mngr) {
|
||||
const auto command = wrappedAppFilePath() + " --service";
|
||||
const SC_HANDLE svc = CreateServiceW(mngr, serviceName, serviceDisplay, SERVICE_ALL_ACCESS,
|
||||
SERVICE_WIN32_OWN_PROCESS, SERVICE_AUTO_START, SERVICE_ERROR_NORMAL,
|
||||
(LPCWSTR) command.utf16(), 0, 0, 0, 0, 0);
|
||||
@ -101,7 +96,7 @@ bool StartupUtil::installService()
|
||||
return res;
|
||||
}
|
||||
|
||||
bool StartupUtil::uninstallService()
|
||||
bool uninstallService(const wchar_t *serviceName)
|
||||
{
|
||||
bool res = false;
|
||||
const SC_HANDLE mngr = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
|
||||
@ -124,6 +119,11 @@ bool StartupUtil::uninstallService()
|
||||
return res;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const wchar_t *const StartupUtil::serviceName = L"" APP_BASE "Svc";
|
||||
const wchar_t *const StartupUtil::serviceDisplay = L"" APP_NAME;
|
||||
|
||||
bool StartupUtil::isServiceInstalled()
|
||||
{
|
||||
bool res = false;
|
||||
@ -161,7 +161,7 @@ StartupUtil::StartupMode StartupUtil::getStartupMode()
|
||||
: (isAutorunForCurrentUser() ? StartupCurrentUser : StartupDisabled);
|
||||
}
|
||||
|
||||
void StartupUtil::setStartupMode(int mode)
|
||||
void StartupUtil::setStartupMode(int mode, const QString &defaultLanguage)
|
||||
{
|
||||
// COMPAT: Remove link from Programs -> Startup
|
||||
// TODO: Remove after v4.1.0 (via v4.0.0)
|
||||
@ -169,19 +169,23 @@ void StartupUtil::setStartupMode(int mode)
|
||||
|
||||
removeAutorunForCurrentUser();
|
||||
removeAutorunForAllUsers();
|
||||
uninstallService();
|
||||
uninstallService(serviceName);
|
||||
|
||||
if (mode == StartupDisabled)
|
||||
return;
|
||||
|
||||
const QString command = wrappedAppFilePath()
|
||||
+ (defaultLanguage.isEmpty() ? QString() : " --lang " + defaultLanguage);
|
||||
|
||||
switch (mode) {
|
||||
case StartupDisabled:
|
||||
break;
|
||||
case StartupCurrentUser:
|
||||
setAutorunForCurrentUser();
|
||||
setAutorunForCurrentUser(command);
|
||||
break;
|
||||
case StartupAllUsers:
|
||||
setAutorunForAllUsers();
|
||||
setAutorunForAllUsers(command);
|
||||
Q_FALLTHROUGH();
|
||||
case StartupAllUsersBackground:
|
||||
installService();
|
||||
installService(serviceName, serviceDisplay, command + " --service");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -16,14 +16,11 @@ public:
|
||||
static const wchar_t *const serviceName;
|
||||
static const wchar_t *const serviceDisplay;
|
||||
|
||||
static bool installService();
|
||||
static bool uninstallService();
|
||||
|
||||
static bool isServiceInstalled();
|
||||
static bool startService();
|
||||
|
||||
static StartupMode getStartupMode();
|
||||
static void setStartupMode(int mode);
|
||||
static void setStartupMode(int mode, const QString &defaultLanguage = QString());
|
||||
|
||||
static bool isServiceMode(int mode);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user