Changeset 206 in Main for trunk/Server/main.c


Ignore:
Timestamp:
Oct 2, 2024, 11:33:40 AM (6 weeks ago)
Author:
Nishi
Message:

[release 2.03C] read registry

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Server/main.c

    r200 r206  
    7272int startup(int argc, char** argv);
    7373
     74#ifdef __MINGW32__
     75char* get_registry(const char* main, const char* sub) {
     76        DWORD bufsize = 255;
     77        char* value = malloc(256);
     78        int err = RegGetValue(HKEY_LOCAL_MACHINE, main, sub, RRF_RT_ANY, NULL, (void*)value, &bufsize);
     79        if(err == ERROR_SUCCESS) {
     80                return value;
     81        } else {
     82                free(value);
     83                return NULL;
     84        }
     85}
     86#endif
     87
    7488#ifdef SERVICE
    7589SERVICE_STATUS status;
     
    87101
    88102void WINAPI servmain(DWORD argc, LPSTR* argv) {
    89         logfile = fopen(PREFIX "/logs/tewi.log", "a");
     103        char* path = get_registry("Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Tewi HTTPd", "InstallDir");
     104        if(path != NULL) {
     105                char* lpath = cm_strcat(path, "/logs/tewi.log");
     106                logfile = fopen(lpath, "a");
     107                free(lpath);
     108                free(path);
     109        } else {
     110                logfile = fopen(PREFIX "/logs/tewi.log", "a");
     111        }
    90112        if(logfile == NULL) logfile = stderr;
    91113        status.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
     
    662684int startup(int argc, char** argv) {
    663685        int i;
     686#ifdef __MINGW32__
     687        char* confpath = cm_strdup(PREFIX "/etc/tewi.conf");
     688        char* regpath = get_registry("Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Tewi HTTPd", "InstallDir");
     689        if(regpath != NULL) {
     690                free(confpath);
     691                confpath = cm_strcat(regpath, "/etc/tewi.conf");
     692                free(regpath);
     693        }
     694#else
    664695        const char* confpath = PREFIX "/etc/tewi.conf";
     696#endif
    665697        if(argv != NULL) {
    666698                for(i = 1; i < argc; i++) {
Note: See TracChangeset for help on using the changeset viewer.