Skip to content

Commit

Permalink
Removed NSSM and implemented custom service #16
Browse files Browse the repository at this point in the history
Backwards compatible upgrade support for the installer, if you experience issues please uninstall RETC first and then install the new version.
  • Loading branch information
MartB committed Jan 25, 2018
1 parent a4ccec6 commit 5484111
Show file tree
Hide file tree
Showing 7 changed files with 294 additions and 43 deletions.
22 changes: 21 additions & 1 deletion RETC.sln
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26430.16
VisualStudioVersion = 15.0.27130.2010
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RPC", "rpc-midl\midl.vcxproj", "{6536EBEC-014E-4D6B-97BE-223137694CA8}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Server", "server-exe\server.vcxproj", "{758DB128-9123-4E1B-A6C3-47323714123A}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ShimDLL", "shim-dll\shim.vcxproj", "{758DB129-9123-4E1B-A6C3-47323714123A}"
EndProject
Project("{911E67C6-3D85-4FCE-B560-20A9C3E3FF48}") = "retc-rpc-server-32", "out\x86\Debug\Server\retc-rpc-server-32.exe", "{99C1CD65-766B-4E30-AFA5-F5FFF092F5CF}"
ProjectSection(DebuggerProjectSystem) = preProject
PortSupplier = 00000000-0000-0000-0000-000000000000
Executable = D:\projects\Privat\RETC\out\x86\Debug\Server\retc-rpc-server-32.exe
RemoteMachine = DESKTOP-6T3SGUV
StartingDirectory = D:\projects\Privat\RETC\out\x86\Debug\Server
Environment = Standard
LaunchingEngine = 00000000-0000-0000-0000-000000000000
UseLegacyDebugEngines = No
LaunchSQLEngine = No
AttachLaunchAction = No
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Expand Down Expand Up @@ -40,8 +53,15 @@ Global
{758DB129-9123-4E1B-A6C3-47323714123A}.Release|Win32.Build.0 = Release|Win32
{758DB129-9123-4E1B-A6C3-47323714123A}.Release|x64.ActiveCfg = Release|x64
{758DB129-9123-4E1B-A6C3-47323714123A}.Release|x64.Build.0 = Release|x64
{99C1CD65-766B-4E30-AFA5-F5FFF092F5CF}.Debug|Win32.ActiveCfg = Release|x86
{99C1CD65-766B-4E30-AFA5-F5FFF092F5CF}.Debug|x64.ActiveCfg = Release|x86
{99C1CD65-766B-4E30-AFA5-F5FFF092F5CF}.Release|Win32.ActiveCfg = Release|x86
{99C1CD65-766B-4E30-AFA5-F5FFF092F5CF}.Release|x64.ActiveCfg = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {BF942D65-D62B-456A-8EB0-358C83FAFEB5}
EndGlobalSection
EndGlobal
38 changes: 18 additions & 20 deletions retc-installer/RETC_Installer.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,14 @@ Section "RETC (required)" Sec_RETC
; Set output path to the installation directory.
SetOutPath $INSTDIR

;If nssm is already installed, attempt to stop before installing
;Keep backwards compatibility
${If} ${FileExists} "$INSTDIR\nssm.exe"
nsExec::ExecToLog /OEM '"$INSTDIR\nssm.exe" stop RETC'
Delete "$INSTDIR\nssm.exe"
${ElseIf} ${FileExists} "$INSTDIR\retc-rpc-server-64.exe"
nsExec::ExecToLog /OEM /TIMEOUT=10000 '"$INSTDIR\retc-rpc-server-64.exe" remove_service'
${ElseIf} ${FileExists} "$INSTDIR\retc-rpc-server-32.exe"
nsExec::ExecToLog /OEM /TIMEOUT=10000 '"$INSTDIR\retc-rpc-server-32.exe" remove_service'
${EndIf}

${If} ${FileExists} "$SYSDIR\RzChromaSDK.dll"
Expand Down Expand Up @@ -218,8 +223,6 @@ Section "RETC (required)" Sec_RETC
File "${FILES}\win32\CUESDK_2015.dll"
${EndIf}

File "${FILES}\win32\nssm.exe"
File "${FILES}\win64\nssm.exe"
File "${FILES}\LICENSE"
File "${FILES}\SIMPLEINI_LICENSE"
File "${FILES}\SPDLOG_LICENSE"
Expand All @@ -240,23 +243,10 @@ Section "RETC (required)" Sec_RETC
WriteINIStr "$INSTDIR\RETC Github Repo.URL" "InternetShortcut" "URL" "https://github.com/MartB/RETC"

${If} ${RunningX64}
nsExec::ExecToLog /OEM '"$INSTDIR\nssm.exe" install RETC "$INSTDIR\retc-rpc-server-64.exe"'
nsExec::ExecToLog /OEM /TIMEOUT=10000 '"$INSTDIR\retc-rpc-server-64.exe" install_service'
${Else}
nsExec::ExecToLog /OEM '"$INSTDIR\nssm.exe" install RETC "$INSTDIR\retc-rpc-server-32.exe"'
nsExec::ExecToLog /OEM /TIMEOUT=10000 '"$INSTDIR\retc-rpc-server-32.exe" install_service'
${EndIf}
nsExec::ExecToLog /OEM '"$INSTDIR\nssm.exe" set RETC AppDirectory "$INSTDIR"'
nsExec::ExecToLog /OEM '"$INSTDIR\nssm.exe" set RETC AppExit Default Restart'
nsExec::ExecToLog /OEM '"$INSTDIR\nssm.exe" set RETC AppStdout "$INSTDIR\retc-server-nssm.log"'
nsExec::ExecToLog /OEM '"$INSTDIR\nssm.exe" set RETC AppStdoutCreationDisposition 2'
nsExec::ExecToLog /OEM '"$INSTDIR\nssm.exe" set RETC AppStderr "$INSTDIR\retc-server-nssm.log"'
nsExec::ExecToLog /OEM '"$INSTDIR\nssm.exe" set RETC AppStderrCreationDisposition 2'
nsExec::ExecToLog /OEM '"$INSTDIR\nssm.exe" set RETC Description "Allows programs that support the Razer Chroma SDK to use Corsair RGB devices. Visit https://github.com/MartB/RETC for more info."'
nsExec::ExecToLog /OEM '"$INSTDIR\nssm.exe" set RETC DisplayName "RETC Service"'
nsExec::ExecToLog /OEM '"$INSTDIR\nssm.exe" set RETC ObjectName LocalSystem'
nsExec::ExecToLog /OEM '"$INSTDIR\nssm.exe" set RETC Start SERVICE_AUTO_START'
nsExec::ExecToLog /OEM '"$INSTDIR\nssm.exe" set RETC Type SERVICE_WIN32_OWN_PROCESS'

nsExec::ExecToLog /OEM '"$INSTDIR\nssm.exe" start RETC'

; Write the installation path into the registry
WriteRegStr HKLM SOFTWARE\RETC "Install_Dir" "$INSTDIR"
Expand Down Expand Up @@ -337,8 +327,16 @@ Section "Uninstall"
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\RETC"
DeleteRegKey HKLM "SOFTWARE\RETC"

nsExec::ExecToLog /OEM '"$INSTDIR\nssm.exe" stop RETC'
nsExec::ExecToLog /OEM '"$INSTDIR\nssm.exe" remove RETC confirm'
; Keep backwards compatibility
${If} ${FileExists} "$INSTDIR\nssm.exe"
nsExec::ExecToLog /OEM '"$INSTDIR\nssm.exe" stop RETC'
nsExec::ExecToLog /OEM '"$INSTDIR\nssm.exe" remove RETC confirm'
Delete "$INSTDIR\nssm.exe"
${ElseIf} ${FileExists} "$INSTDIR\retc-rpc-server-64.exe"
nsExec::ExecToLog /OEM /TIMEOUT=10000 '"$INSTDIR\retc-rpc-server-64.exe" remove_service'
${ElseIf} ${FileExists} "$INSTDIR\retc-rpc-server-32.exe"
nsExec::ExecToLog /OEM /TIMEOUT=10000 '"$INSTDIR\retc-rpc-server-32.exe" remove_service'
${EndIf}

; Remove files and uninstaller
Delete "$INSTDIR\*.*"
Expand Down
13 changes: 0 additions & 13 deletions retc-installer/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
CUE_SDK_DLL_NAME_32 = "CUESDK_2015.dll"
CUE_SDK_DLL_NAME_64 = "CUESDK.x64_2015.dll"

# NSSM Binary
NSSM_BIN_NAME = "nssm.exe"

SERVER_BUILD_PATH_32 = '../out/x86/Release/Server/'
SERVER_BUILD_PATH_64 = '../out/x64/Release/Server/'

Expand Down Expand Up @@ -144,20 +141,10 @@ def main(argv):
cleanBuildFiles()
return

nssmExists = checkFiles([
FILE_PATH_32 + NSSM_BIN_NAME,
FILE_PATH_64 + NSSM_BIN_NAME
])

cueSDKExists = checkFiles([
FILE_PATH_32 + CUE_SDK_DLL_NAME_32,
FILE_PATH_64 + CUE_SDK_DLL_NAME_64
])

if not nssmExists:
print("Could not find nssm (please compile it yourself)")
return

if not cueSDKExists and not downloadCueSdk():
print("Could not download cue sdk")
return
Expand Down
25 changes: 16 additions & 9 deletions server-exe/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,34 @@ bool userCancelled = false;
std::condition_variable cv;

void cleanup() {
if (rpcReceiver) { //-V547
if (rpcReceiver) {
//-V547
rpcReceiver->shutdown();
rpcReceiver.reset();
}

if (sdkManager) { //-V547
if (sdkManager) {
//-V547
sdkManager.reset();
}

if (CONFIG) { //-V547
if (CONFIG) {
//-V547
if (!CONFIG->SaveConfig()) {
LOG->error("Failed to save config file.");
}
}
}

extern void requestTermination() {
userCancelled = true;
cv.notify_all();
}

BOOL WINAPI consoleHandler(DWORD signal) {
switch (signal) {
case CTRL_C_EVENT:
userCancelled = true;
cv.notify_all();
requestTermination();
return TRUE;
case CTRL_CLOSE_EVENT:
cleanup();
Expand All @@ -54,7 +61,7 @@ BOOL WINAPI consoleHandler(DWORD signal) {
#define DEF_FLUSH_LEVEL spdlog::level::err
#endif

int main() {
DWORD WINAPI SVCWorkerThread(LPVOID) {
CONFIG.reset(new ConfigManager());

try {
Expand All @@ -75,12 +82,12 @@ int main() {
}
catch (const spdlog::spdlog_ex& ex) {
std::cout << "Log init failed: " << ex.what() << std::endl;
return EXIT_FAILURE;
return ERROR_CANTOPEN;
}

if (!SetConsoleCtrlHandler(consoleHandler, TRUE)) {
LOG_E("Setting the console handler failed");
return EXIT_FAILURE;
return ERROR_INVALID_HANDLE;
}

sdkManager.reset(new SDKManager());
Expand All @@ -96,5 +103,5 @@ int main() {

// Dont put code below this just add all your exit code to cleanup()
cleanup();
return EXIT_SUCCESS;
return ERROR_SUCCESS;
}
1 change: 1 addition & 0 deletions server-exe/server.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@
<ClCompile Include="SDKLoader.cpp" />
<ClCompile Include="SDKManager.cpp" />
<ClCompile Include="server.cpp" />
<ClCompile Include="service.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\rpc-midl\rpc_retc.h" />
Expand Down
6 changes: 6 additions & 0 deletions server-exe/server.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
<ClCompile Include="RazerSDK.cpp">
<Filter>src\SDKS\Razer</Filter>
</ClCompile>
<ClCompile Include="service.cpp">
<Filter>src\Service</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="utils.h">
Expand Down Expand Up @@ -90,6 +93,9 @@
<Filter Include="src\SDKS\Razer">
<UniqueIdentifier>{ff229edb-146c-4197-b65d-6bbacf6acd32}</UniqueIdentifier>
</Filter>
<Filter Include="src\Service">
<UniqueIdentifier>{df5eb91d-a00f-447a-ad13-7f730bd8ac7e}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="Server.rc" />
Expand Down
Loading

0 comments on commit 5484111

Please sign in to comment.