From 0628761a9f98714d7ae79c4b35462492ab87c4b4 Mon Sep 17 00:00:00 2001 From: Nishi Date: Wed, 2 Oct 2024 02:33:40 +0000 Subject: [PATCH] [release 2.03C] read registry git-svn-id: file:///raid/svn-personal/tewi/trunk@206 8739d7e6-ffea-ec47-b151-bdff447c6205 --- Server/install.nsi | 2 ++ Server/main.c | 34 +++++++++++++++++++++++++++++++++- Server/tw_version.h | 2 +- installer.sh | 12 ++++++------ 4 files changed, 42 insertions(+), 8 deletions(-) diff --git a/Server/install.nsi b/Server/install.nsi index d98f24b..e3c7bc4 100644 --- a/Server/install.nsi +++ b/Server/install.nsi @@ -26,6 +26,7 @@ LangString WAIT_STOP ${LANG_JAPANESE} "サービスが止まるのを待って !include "Sections.nsh" Page license +Page directory Page components Page instfiles UninstPage uninstConfirm @@ -57,6 +58,7 @@ Section CreateShortcut "$SMPROGRAMS\Tewi HTTPd\Uninstall Tewi HTTPd.lnk" "$INSTDIR\uninstall.exe" "" WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Tewi HTTPd" "DisplayName" "Tewi HTTPd" + WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Tewi HTTPd" "InstallDir" '"$INSTDIR"' WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Tewi HTTPd" "UninstallString" '"$INSTDIR\uninstall.exe"' WriteUninstaller "$INSTDIR\uninstall.exe" diff --git a/Server/main.c b/Server/main.c index 2e81f71..4b3c832 100644 --- a/Server/main.c +++ b/Server/main.c @@ -71,6 +71,20 @@ char tw_server[2048]; int startup(int argc, char** argv); +#ifdef __MINGW32__ +char* get_registry(const char* main, const char* sub) { + DWORD bufsize = 255; + char* value = malloc(256); + int err = RegGetValue(HKEY_LOCAL_MACHINE, main, sub, RRF_RT_ANY, NULL, (void*)value, &bufsize); + if(err == ERROR_SUCCESS) { + return value; + } else { + free(value); + return NULL; + } +} +#endif + #ifdef SERVICE SERVICE_STATUS status; SERVICE_STATUS_HANDLE status_handle; @@ -86,7 +100,15 @@ void WINAPI servhandler(DWORD control) { } void WINAPI servmain(DWORD argc, LPSTR* argv) { - logfile = fopen(PREFIX "/logs/tewi.log", "a"); + char* path = get_registry("Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Tewi HTTPd", "InstallDir"); + if(path != NULL) { + char* lpath = cm_strcat(path, "/logs/tewi.log"); + logfile = fopen(lpath, "a"); + free(lpath); + free(path); + } else { + logfile = fopen(PREFIX "/logs/tewi.log", "a"); + } if(logfile == NULL) logfile = stderr; status.dwServiceType = SERVICE_WIN32_OWN_PROCESS; status.dwCurrentState = SERVICE_START_PENDING; @@ -661,7 +683,17 @@ int main(int argc, char** argv) { int startup(int argc, char** argv) { int i; +#ifdef __MINGW32__ + char* confpath = cm_strdup(PREFIX "/etc/tewi.conf"); + char* regpath = get_registry("Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Tewi HTTPd", "InstallDir"); + if(regpath != NULL) { + free(confpath); + confpath = cm_strcat(regpath, "/etc/tewi.conf"); + free(regpath); + } +#else const char* confpath = PREFIX "/etc/tewi.conf"; +#endif if(argv != NULL) { for(i = 1; i < argc; i++) { if(argv[i][0] == '-') { diff --git a/Server/tw_version.h b/Server/tw_version.h index c138d35..9f40e32 100644 --- a/Server/tw_version.h +++ b/Server/tw_version.h @@ -7,7 +7,7 @@ extern "C" { #endif -#define TW_VERSION "2.03B\0" +#define TW_VERSION "2.03C\0" const char* tw_get_version(void); const char* tw_get_platform(void); diff --git a/installer.sh b/installer.sh index 6dfc91d..768855a 100755 --- a/installer.sh +++ b/installer.sh @@ -22,13 +22,13 @@ VERSION=`make get-version` sed "s/undef NO_SSL/define NO_SSL/g" config.h.tmpl > config.h make clean || fail -make PLATFORM=$1 -j4 || fail +make PLATFORM=$1 PREFIX=C:/srv/Tewi -j4 || fail cp Server/tewi.exe tewi.exe make clean || fail -make PLATFORM=$1-service -j4 || fail +make PLATFORM=$1-service -j4 PREFIX=C:/srv/Tewi || fail cp Server/tewi.exe tewi-service.exe cd Server -../Tool/genconf "C:/Tewi" modules dll > ../generated.conf +../Tool/genconf "C:/srv/Tewi" modules dll > ../generated.conf ../Tool/itworks > ../itworks.html makensis -DVERSION=$VERSION install.nsi cp install.exe ../install-nossl.exe @@ -38,13 +38,13 @@ cd .. sed "s/define NO_SSL/undef NO_SSL/g" config.h.tmpl > config.h make clean || fail -make PLATFORM=$1 -j4 || fail +make PLATFORM=$1 -j4 PREFIX=C:/srv/Tewi|| fail cp Server/tewi.exe tewi.exe make clean || fail -make PLATFORM=$1-service -j4 || fail +make PLATFORM=$1-service -j4 PREFIX=C:/srv/Tewi || fail cp Server/tewi.exe tewi-service.exe cd Server -../Tool/genconf "C:/Tewi" modules dll > ../generated.conf +../Tool/genconf "C:/srv/Tewi" modules dll > ../generated.conf ../Tool/itworks > ../itworks.html makensis -DVERSION=$VERSION install.nsi cp install.exe ../install-ssl.exe -- 2.43.0