Autostart checkbox (#3269)
This commit is contained in:
parent
d8eafa91b8
commit
b453ae1db2
@ -83,6 +83,10 @@ functionEnd
|
|||||||
section "install"
|
section "install"
|
||||||
# Files for the install directory - to build the installer, these should be in the same directory as the install script (this file)
|
# Files for the install directory - to build the installer, these should be in the same directory as the install script (this file)
|
||||||
setOutPath $INSTDIR
|
setOutPath $INSTDIR
|
||||||
|
|
||||||
|
# Close parity if running
|
||||||
|
!insertmacro TerminateApp
|
||||||
|
|
||||||
# Files added here should be removed by the uninstaller (see section "uninstall")
|
# Files added here should be removed by the uninstaller (see section "uninstall")
|
||||||
file /oname=parity.exe ..\target\release\parity.exe
|
file /oname=parity.exe ..\target\release\parity.exe
|
||||||
file /oname=ptray.exe ..\windows\ptray\x64\Release\ptray.exe
|
file /oname=ptray.exe ..\windows\ptray\x64\Release\ptray.exe
|
||||||
@ -99,6 +103,7 @@ section "install"
|
|||||||
|
|
||||||
# Start Menu
|
# Start Menu
|
||||||
createDirectory "$SMPROGRAMS\${COMPANYNAME}"
|
createDirectory "$SMPROGRAMS\${COMPANYNAME}"
|
||||||
|
delete "$SMPROGRAMS\${COMPANYNAME}\${APPNAME}.lnk"
|
||||||
createShortCut "$SMPROGRAMS\${COMPANYNAME}\${APPNAME} Ethereum.lnk" "$INSTDIR\ptray.exe" "ui" "$INSTDIR\logo.ico"
|
createShortCut "$SMPROGRAMS\${COMPANYNAME}\${APPNAME} Ethereum.lnk" "$INSTDIR\ptray.exe" "ui" "$INSTDIR\logo.ico"
|
||||||
createShortCut "$DESKTOP\${APPNAME} Ethereum.lnk" "$INSTDIR\ptray.exe" "ui" "$INSTDIR\logo.ico"
|
createShortCut "$DESKTOP\${APPNAME} Ethereum.lnk" "$INSTDIR\ptray.exe" "ui" "$INSTDIR\logo.ico"
|
||||||
|
|
||||||
@ -115,7 +120,7 @@ section "install"
|
|||||||
SimpleFC::AdvAddRule "Parity UDP discovery (UDP:30303)" "" 17 2 1 2147483647 1 "$INSTDIR\parity.exe" "" "" "Parity" "" 30303 "" ""
|
SimpleFC::AdvAddRule "Parity UDP discovery (UDP:30303)" "" 17 2 1 2147483647 1 "$INSTDIR\parity.exe" "" "" "Parity" "" 30303 "" ""
|
||||||
|
|
||||||
# Registry information for add/remove programs
|
# Registry information for add/remove programs
|
||||||
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "DisplayName" "${COMPANYNAME} - ${APPNAME} - ${DESCRIPTION}"
|
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "DisplayName" "${APPNAME} - ${DESCRIPTION}"
|
||||||
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "UninstallString" "$\"$INSTDIR\uninstall.exe$\""
|
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "UninstallString" "$\"$INSTDIR\uninstall.exe$\""
|
||||||
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "QuietUninstallString" "$\"$INSTDIR\uninstall.exe$\" /S"
|
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "QuietUninstallString" "$\"$INSTDIR\uninstall.exe$\" /S"
|
||||||
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "InstallLocation" "$\"$INSTDIR$\""
|
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "InstallLocation" "$\"$INSTDIR$\""
|
||||||
@ -133,7 +138,8 @@ section "install"
|
|||||||
# Set the INSTALLSIZE constant (!defined at the top of this script) so Add/Remove Programs can accurately report the size
|
# Set the INSTALLSIZE constant (!defined at the top of this script) so Add/Remove Programs can accurately report the size
|
||||||
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "EstimatedSize" ${INSTALLSIZE}
|
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "EstimatedSize" ${INSTALLSIZE}
|
||||||
|
|
||||||
WriteRegStr HKEY_LOCAL_MACHINE "Software\Microsoft\Windows\CurrentVersion\Run" ${APPNAME} "$INSTDIR\ptray.exe ${ARGS}"
|
WriteRegStr HKEY_CURRENT_USER "Software\Microsoft\Windows\CurrentVersion\Run" ${APPNAME} "$INSTDIR\ptray.exe ${ARGS}"
|
||||||
|
DeleteRegValue HKLM "Software\Microsoft\Windows\CurrentVersion\Run" "${APPNAME}"
|
||||||
ExecShell "" "$INSTDIR\ptray.exe" "${FIRST_START_ARGS}"
|
ExecShell "" "$INSTDIR\ptray.exe" "${FIRST_START_ARGS}"
|
||||||
sectionEnd
|
sectionEnd
|
||||||
|
|
||||||
@ -177,5 +183,6 @@ section "uninstall"
|
|||||||
# Remove uninstaller information from the registry
|
# Remove uninstaller information from the registry
|
||||||
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}"
|
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}"
|
||||||
DeleteRegValue HKLM "Software\Microsoft\Windows\CurrentVersion\Run" "${APPNAME}"
|
DeleteRegValue HKLM "Software\Microsoft\Windows\CurrentVersion\Run" "${APPNAME}"
|
||||||
|
DeleteRegValue HKCU "Software\Microsoft\Windows\CurrentVersion\Run" "${APPNAME}"
|
||||||
sectionEnd
|
sectionEnd
|
||||||
|
|
||||||
|
@ -33,6 +33,7 @@
|
|||||||
#define MAX_LOADSTRING 100
|
#define MAX_LOADSTRING 100
|
||||||
#define IDM_EXIT 100
|
#define IDM_EXIT 100
|
||||||
#define IDM_OPEN 101
|
#define IDM_OPEN 101
|
||||||
|
#define IDM_AUTOSTART 102
|
||||||
#define WM_USER_SHELLICON WM_USER + 1
|
#define WM_USER_SHELLICON WM_USER + 1
|
||||||
|
|
||||||
HANDLE parityHandle = INVALID_HANDLE_VALUE;
|
HANDLE parityHandle = INVALID_HANDLE_VALUE;
|
||||||
@ -49,12 +50,14 @@ LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
|
|||||||
void KillParity();
|
void KillParity();
|
||||||
void OpenUI();
|
void OpenUI();
|
||||||
bool ParityIsRunning();
|
bool ParityIsRunning();
|
||||||
|
bool AutostartEnabled();
|
||||||
|
void EnableAutostart(bool enable);
|
||||||
|
|
||||||
bool GetParityExePath(TCHAR* dest, size_t destSize)
|
bool GetParityExePath(TCHAR* dest, size_t destSize)
|
||||||
{
|
{
|
||||||
if (!dest || MAX_PATH > destSize)
|
if (!dest || MAX_PATH > destSize)
|
||||||
return false;
|
return false;
|
||||||
GetModuleFileName(NULL, dest, destSize);
|
GetModuleFileName(NULL, dest, (DWORD)destSize);
|
||||||
if (!PathRemoveFileSpec(dest))
|
if (!PathRemoveFileSpec(dest))
|
||||||
return false;
|
return false;
|
||||||
return PathAppend(dest, _T("parity.exe")) == TRUE;
|
return PathAppend(dest, _T("parity.exe")) == TRUE;
|
||||||
@ -201,7 +204,11 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|||||||
HMENU hPopMenu = CreatePopupMenu();
|
HMENU hPopMenu = CreatePopupMenu();
|
||||||
InsertMenu(hPopMenu, 0xFFFFFFFF, MF_BYPOSITION | MF_STRING, IDM_OPEN, _T("Open"));
|
InsertMenu(hPopMenu, 0xFFFFFFFF, MF_BYPOSITION | MF_STRING, IDM_OPEN, _T("Open"));
|
||||||
InsertMenu(hPopMenu, 0xFFFFFFFF, MF_SEPARATOR | MF_BYPOSITION, 0, nullptr);
|
InsertMenu(hPopMenu, 0xFFFFFFFF, MF_SEPARATOR | MF_BYPOSITION, 0, nullptr);
|
||||||
|
InsertMenu(hPopMenu, 0xFFFFFFFF, MF_BYPOSITION | MF_STRING, IDM_AUTOSTART, _T("Start at Login"));
|
||||||
|
InsertMenu(hPopMenu, 0xFFFFFFFF, MF_SEPARATOR | MF_BYPOSITION, 0, nullptr);
|
||||||
InsertMenu(hPopMenu, 0xFFFFFFFF, MF_BYPOSITION | MF_STRING, IDM_EXIT, _T("Exit"));
|
InsertMenu(hPopMenu, 0xFFFFFFFF, MF_BYPOSITION | MF_STRING, IDM_EXIT, _T("Exit"));
|
||||||
|
bool autoStart = AutostartEnabled();
|
||||||
|
CheckMenuItem(hPopMenu, IDM_AUTOSTART, autoStart ? MF_CHECKED : autoStart);
|
||||||
|
|
||||||
SetForegroundWindow(hWnd);
|
SetForegroundWindow(hWnd);
|
||||||
TrackPopupMenu(hPopMenu, TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_BOTTOMALIGN, lpClickPoint.x, lpClickPoint.y, 0, hWnd, NULL);
|
TrackPopupMenu(hPopMenu, TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_BOTTOMALIGN, lpClickPoint.x, lpClickPoint.y, 0, hWnd, NULL);
|
||||||
@ -221,6 +228,12 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|||||||
case IDM_OPEN:
|
case IDM_OPEN:
|
||||||
OpenUI();
|
OpenUI();
|
||||||
break;
|
break;
|
||||||
|
case IDM_AUTOSTART:
|
||||||
|
{
|
||||||
|
bool autoStart = AutostartEnabled();
|
||||||
|
EnableAutostart(!autoStart);
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
return DefWindowProc(hWnd, message, wParam, lParam);
|
return DefWindowProc(hWnd, message, wParam, lParam);
|
||||||
}
|
}
|
||||||
@ -276,3 +289,37 @@ void OpenUI()
|
|||||||
LPWSTR cmd = _T("parity.exe ui");
|
LPWSTR cmd = _T("parity.exe ui");
|
||||||
CreateProcess(path, cmd, nullptr, nullptr, false, CREATE_NO_WINDOW, nullptr, nullptr, &startupInfo, &procInfo);
|
CreateProcess(path, cmd, nullptr, nullptr, false, CREATE_NO_WINDOW, nullptr, nullptr, &startupInfo, &procInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool AutostartEnabled() {
|
||||||
|
HKEY hKey;
|
||||||
|
LONG lRes = RegOpenKeyExW(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Run", 0, KEY_READ, &hKey);
|
||||||
|
if (lRes != ERROR_SUCCESS)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
WCHAR szBuffer[512];
|
||||||
|
DWORD dwBufferSize = sizeof(szBuffer);
|
||||||
|
ULONG nError;
|
||||||
|
nError = RegQueryValueExW(hKey, L"Parity", 0, nullptr, (LPBYTE)szBuffer, &dwBufferSize);
|
||||||
|
if (ERROR_SUCCESS != nError)
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void EnableAutostart(bool enable) {
|
||||||
|
HKEY hKey;
|
||||||
|
LONG lRes = RegOpenKeyExW(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Run", 0, KEY_WRITE, &hKey);
|
||||||
|
if (lRes != ERROR_SUCCESS)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (enable) {
|
||||||
|
TCHAR path[MAX_PATH] = { 0 };
|
||||||
|
if (!GetParityExePath(path, MAX_PATH))
|
||||||
|
return;
|
||||||
|
RegSetValueEx(hKey, L"Parity", 0, REG_SZ, (LPBYTE)path, MAX_PATH);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
RegDeleteValue(hKey, L"Parity");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -95,7 +95,7 @@
|
|||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
<ClCompile>
|
<ClCompile>
|
||||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||||
<WarningLevel>Level3</WarningLevel>
|
<WarningLevel>Level3</WarningLevel>
|
||||||
<Optimization>Disabled</Optimization>
|
<Optimization>Disabled</Optimization>
|
||||||
<PreprocessorDefinitions>_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
Loading…
Reference in New Issue
Block a user