From 748a7dda1a37a00c342c2b98684cbac27fb0598a Mon Sep 17 00:00:00 2001 From: Guillaume Bougard Date: Thu, 29 Nov 2018 14:27:19 +0100 Subject: [PATCH] Use installation dir to install service --- src/glpi-wince-agent-setup.c | 36 ++++++++++++++++++++++++++++-------- src/glpi-wince-agent.inf | 2 +- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/src/glpi-wince-agent-setup.c b/src/glpi-wince-agent-setup.c index 3664f01..0d467c7 100644 --- a/src/glpi-wince-agent-setup.c +++ b/src/glpi-wince-agent-setup.c @@ -52,7 +52,7 @@ DECLSPEC_EXPORT APIENTRY BOOL DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved); FILE *hFile = NULL; -LPCSTR cstrInstallJournal = "\\Windows\\" APPNAME "-install.txt"; +LPCSTR cstrInstallJournal = APPNAME "-install.txt"; DWORD keepFiles = 0; #define SHORT_BUFFER_SIZE 16 @@ -281,6 +281,12 @@ Install_Init(HWND hwndparent, BOOL bFirstcall, BOOL IsInstalled, LPCTSTR pszinstalldir) { HKEY hKey = NULL; + LPSTR logpath = NULL; + + logpath = malloc(MAX_PATH); + wcstombs(logpath, pszinstalldir, MAX_PATH); + strcat(logpath, "\\"); + strcat(logpath, cstrInstallJournal); // Initializes OS informations os.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); @@ -297,7 +303,7 @@ Install_Init(HWND hwndparent, BOOL bFirstcall, BOOL IsInstalled, if (hFile != NULL) { fclose(hFile); - hFile = freopen( cstrInstallJournal, "w", stdout ); + hFile = freopen( logpath, "w", stdout ); } #ifdef TEST @@ -362,6 +368,8 @@ Install_Init(HWND hwndparent, BOOL bFirstcall, BOOL IsInstalled, Log("Installing " APPNAME " v" VERSION "..."); } + free(logpath); + return codeINSTALL_INIT_CONTINUE; } @@ -493,8 +501,6 @@ Install_Exit(HWND hwndparent, LPCTSTR pszinstalldir, WORD cfaileddirs, Log("Can't try to set VarDir in registry"); DumpError(); } - free(wPath); - free(path); // TODO: Update DLLs file attributes as protected system file @@ -637,12 +643,13 @@ Install_Exit(HWND hwndparent, LPCTSTR pszinstalldir, WORD cfaileddirs, // Set Dll in registry dwType = REG_SZ; - wData = L"glpi-agent.dll"; - dwDataSize = sizeof(TCHAR)*(wcslen(wData)+1); + swprintf(wPath, L"%s%hs", pszinstalldir, "\\glpi-agent.dll"); + dwDataSize = sizeof(TCHAR)*(wcslen(wPath)+1); if (RegSetValueEx(hKey, L"Dll", 0, dwType, - (LPBYTE)wData, dwDataSize) == ERROR_SUCCESS) + (LPBYTE)wPath, dwDataSize) == ERROR_SUCCESS) { - Log("Service Dll set in registry"); + wcstombs(path, wPath, MAX_PATH); + Log("Service Dll set in registry to '%s'", path); } else { @@ -800,6 +807,9 @@ Install_Exit(HWND hwndparent, LPCTSTR pszinstalldir, WORD cfaileddirs, DebugRegistry(); #endif + free(wPath); + free(path); + return codeINSTALL_EXIT_DONE; } @@ -988,6 +998,9 @@ BOOL APIENTRY DllMain(HANDLE hModule, DWORD dwReason, LPVOID lpReserved) { LPCSTR hdr = APPNAME "-Setup (Built: " __DATE__ ", " __TIME__ ")"; +#ifndef TEST + LPTSTR wPath = NULL; +#endif if (hFile == NULL) { @@ -1015,6 +1028,13 @@ DllMain(HANDLE hModule, DWORD dwReason, LPVOID lpReserved) Log("%s: unloading", hdr); if (hFile != NULL) fclose(hFile); +#ifndef TEST + // Remove first cstrInstallJournal created file + wPath = malloc(2*MAX_PATH); + swprintf( wPath, L"\\%hs", cstrInstallJournal ); + DeleteFile(wPath); + free(wPath); +#endif break; } diff --git a/src/glpi-wince-agent.inf b/src/glpi-wince-agent.inf index 6fecc8d..24248f7 100644 --- a/src/glpi-wince-agent.inf +++ b/src/glpi-wince-agent.inf @@ -37,7 +37,7 @@ CESetupDLL = setup.dll [DestinationDirs] ; See https://msdn.microsoft.com/en-us/library/ee504636.aspx for %CEXY% ; Or http://www.cabextract.org.uk/wince_cab_format/ -AgentService = 0, %CE2% ; \Windows +AgentService = 0, %InstallDir% AgentFile = 0, %InstallDir% ;CplAgentFile = 0, %CE2% ; \Windows Links = 0, %CE11% ; "\Windows\Start Menu" directory