Commit c1131e15 authored by jan.koester's avatar jan.koester
Browse files

test

parent 3a39f996
Loading
Loading
Loading
Loading
+1
Changes for src/CMakeLists.txt: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -57,6 +57,7 @@ if(${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Windows")
    target_link_libraries(blogi PUBLIC
        blogidev
        kernel32.lib
        shlwapi.lib
    )
else()
    target_link_libraries(blogi PUBLIC
+34 −1
Changes for src/blogi.cpp: 34 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -51,6 +51,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <Windows.h>
#include <tchar.h>
#include <stdio.h>
#include <Shlwapi.h>
#else
#include <unistd.h>
#include <fcntl.h>
@@ -741,9 +742,29 @@ VOID WINAPI ServiceMain(DWORD argc, LPTSTR* argv);
VOID WINAPI ServiceCtrlHandler(DWORD);

#define SERVICE_NAME _T(LPSTR("BlogiService"))
#define CFGPATH "yaml:.\\..\\config.yaml"
#define CFGPATH "yaml:C:\blogi\config.yaml"

int _tmain(int argc, TCHAR* argv[]) {
    try {

        auto getexecdir = [](){
            wchar_t path[MAX_PATH];
            GetModuleFileNameW(NULL, path, MAX_PATH);
            PathRemoveFileSpecW(path);
            return std::wstring(path);
        };

        std::wstring exe_dir = getexecdir();

        if (!SetCurrentDirectoryW( exe_dir.c_str() ) ) {
            std::wcerr << L"Failed to set current directory to: " << exe_dir << std::endl;
            return -1;
        }
    } catch (const std::exception& ex) {
        std::cerr << "Exception while setting current directory: " << ex.what() << std::endl;
        return -1;
    }

    SERVICE_TABLE_ENTRY ServiceTable[] = {
        {SERVICE_NAME, (LPSERVICE_MAIN_FUNCTION)ServiceMain},
        {NULL, NULL}
@@ -850,12 +871,24 @@ VOID WINAPI ServiceMain(DWORD dwArgc, LPTSTR* lpszArgv) {
    }

    // 3. Service initialization and configuration
    try {

        try {
            blogi::Blogi::Config = std::make_shared<blogi::Config>(CFGPATH);
        } catch (const std::exception& ex) {
            std::cerr << "Failed to load config: " << ex.what() << std::endl;
            ReportSvcStatus(SERVICE_STOPPED, ERROR_INVALID_DATA, 0);
            CloseHandle(g_ServiceStopEvent);
            return;
        }

        ReportSvcStatus(SERVICE_RUNNING, NO_ERROR, 0);

        // Run the server and wait for the stop event to be signaled
        HttpConD blogiD(false);

        CloseHandle(g_ServiceStopEvent);
        ReportSvcStatus(SERVICE_STOPPED, NO_ERROR, 0);
    }
    catch (const libhttppp::HTTPException& ex) {
        // Log the exception message to the event log