Skip to content

Commit 748a7dd

Browse files
committed
Use installation dir to install service
1 parent fbc309f commit 748a7dd

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

src/glpi-wince-agent-setup.c

+28-8
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ DECLSPEC_EXPORT APIENTRY BOOL
5252
DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved);
5353

5454
FILE *hFile = NULL;
55-
LPCSTR cstrInstallJournal = "\\Windows\\" APPNAME "-install.txt";
55+
LPCSTR cstrInstallJournal = APPNAME "-install.txt";
5656
DWORD keepFiles = 0;
5757

5858
#define SHORT_BUFFER_SIZE 16
@@ -281,6 +281,12 @@ Install_Init(HWND hwndparent, BOOL bFirstcall, BOOL IsInstalled,
281281
LPCTSTR pszinstalldir)
282282
{
283283
HKEY hKey = NULL;
284+
LPSTR logpath = NULL;
285+
286+
logpath = malloc(MAX_PATH);
287+
wcstombs(logpath, pszinstalldir, MAX_PATH);
288+
strcat(logpath, "\\");
289+
strcat(logpath, cstrInstallJournal);
284290

285291
// Initializes OS informations
286292
os.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
@@ -297,7 +303,7 @@ Install_Init(HWND hwndparent, BOOL bFirstcall, BOOL IsInstalled,
297303
if (hFile != NULL)
298304
{
299305
fclose(hFile);
300-
hFile = freopen( cstrInstallJournal, "w", stdout );
306+
hFile = freopen( logpath, "w", stdout );
301307
}
302308

303309
#ifdef TEST
@@ -362,6 +368,8 @@ Install_Init(HWND hwndparent, BOOL bFirstcall, BOOL IsInstalled,
362368
Log("Installing " APPNAME " v" VERSION "...");
363369
}
364370

371+
free(logpath);
372+
365373
return codeINSTALL_INIT_CONTINUE;
366374
}
367375

@@ -493,8 +501,6 @@ Install_Exit(HWND hwndparent, LPCTSTR pszinstalldir, WORD cfaileddirs,
493501
Log("Can't try to set VarDir in registry");
494502
DumpError();
495503
}
496-
free(wPath);
497-
free(path);
498504

499505
// TODO: Update DLLs file attributes as protected system file
500506

@@ -637,12 +643,13 @@ Install_Exit(HWND hwndparent, LPCTSTR pszinstalldir, WORD cfaileddirs,
637643

638644
// Set Dll in registry
639645
dwType = REG_SZ;
640-
wData = L"glpi-agent.dll";
641-
dwDataSize = sizeof(TCHAR)*(wcslen(wData)+1);
646+
swprintf(wPath, L"%s%hs", pszinstalldir, "\\glpi-agent.dll");
647+
dwDataSize = sizeof(TCHAR)*(wcslen(wPath)+1);
642648
if (RegSetValueEx(hKey, L"Dll", 0, dwType,
643-
(LPBYTE)wData, dwDataSize) == ERROR_SUCCESS)
649+
(LPBYTE)wPath, dwDataSize) == ERROR_SUCCESS)
644650
{
645-
Log("Service Dll set in registry");
651+
wcstombs(path, wPath, MAX_PATH);
652+
Log("Service Dll set in registry to '%s'", path);
646653
}
647654
else
648655
{
@@ -800,6 +807,9 @@ Install_Exit(HWND hwndparent, LPCTSTR pszinstalldir, WORD cfaileddirs,
800807
DebugRegistry();
801808
#endif
802809

810+
free(wPath);
811+
free(path);
812+
803813
return codeINSTALL_EXIT_DONE;
804814
}
805815

@@ -988,6 +998,9 @@ BOOL APIENTRY
988998
DllMain(HANDLE hModule, DWORD dwReason, LPVOID lpReserved)
989999
{
9901000
LPCSTR hdr = APPNAME "-Setup (Built: " __DATE__ ", " __TIME__ ")";
1001+
#ifndef TEST
1002+
LPTSTR wPath = NULL;
1003+
#endif
9911004

9921005
if (hFile == NULL)
9931006
{
@@ -1015,6 +1028,13 @@ DllMain(HANDLE hModule, DWORD dwReason, LPVOID lpReserved)
10151028
Log("%s: unloading", hdr);
10161029
if (hFile != NULL)
10171030
fclose(hFile);
1031+
#ifndef TEST
1032+
// Remove first cstrInstallJournal created file
1033+
wPath = malloc(2*MAX_PATH);
1034+
swprintf( wPath, L"\\%hs", cstrInstallJournal );
1035+
DeleteFile(wPath);
1036+
free(wPath);
1037+
#endif
10181038
break;
10191039
}
10201040

src/glpi-wince-agent.inf

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ CESetupDLL = setup.dll
3737
[DestinationDirs]
3838
; See https://msdn.microsoft.com/en-us/library/ee504636.aspx for %CEXY%
3939
; Or http://www.cabextract.org.uk/wince_cab_format/
40-
AgentService = 0, %CE2% ; \Windows
40+
AgentService = 0, %InstallDir%
4141
AgentFile = 0, %InstallDir%
4242
;CplAgentFile = 0, %CE2% ; \Windows
4343
Links = 0, %CE11% ; "\Windows\Start Menu" directory

0 commit comments

Comments
 (0)