diff --git a/.github/workflows/build.ps1 b/.github/workflows/build.ps1 index c10723e4..c097ebd0 100644 --- a/.github/workflows/build.ps1 +++ b/.github/workflows/build.ps1 @@ -37,7 +37,7 @@ $vcpkgTagName = &"git" -C $vcpkgRoot describe --exact-match --tags $releasePath = [string](jq -r '.configurePresets[0].binaryDir' CMakePresets.json).Replace('${sourceDir}/', '') Write-Output "--------------------------------------------------" -Write-Output "BUILD CONFIGURATION: $env:_RELEASE_CONFIGURATION" +Write-Output "BUILD CONFIGURATION: $env:_RELEASE_CONFIGURATION_PRESET" Write-Output "RELEASE VERSION: $env:_RELEASE_VERSION" Write-Output "VCPKG ORIGIN: $vcpkgOriginUrl" Write-Output "VCPKG TAG: $vcpkgTagName" @@ -113,9 +113,9 @@ cmd.exe /c "call $vcpkgRoot\bootstrap-vcpkg.bat" vcpkg integrate install # Start the build -cmake --preset "${env:_RELEASE_CONFIGURATION}" -cmake --build --preset "${env:_RELEASE_CONFIGURATION}" +cmake --preset "${env:_RELEASE_CONFIGURATION_PRESET}" +cmake --build --preset "${env:_RELEASE_CONFIGURATION_PRESET}" # Start the packaging -7z a ".\.dist\${env:_RELEASE_NAME}-${env:_RELEASE_VERSION}.zip" ".\$releasePath\bin\${env:_RELEASE_CONFIGURATION}\*" +7z a ".\.dist\${env:_RELEASE_NAME}-${env:_RELEASE_VERSION}.zip" ".\$releasePath\bin\${env:_RELEASE_CONFIGURATION_RAW}\*" diff --git a/.github/workflows/main-1.0.0.yaml b/.github/workflows/main-1.0.0.yaml index 1d535175..70898945 100644 --- a/.github/workflows/main-1.0.0.yaml +++ b/.github/workflows/main-1.0.0.yaml @@ -26,7 +26,8 @@ env: _IS_GITHUB_RELEASE: false _RELEASE_NAME: Field-Map-Editor _RELEASE_VERSION: v0 - _RELEASE_CONFIGURATION: Release + _RELEASE_CONFIGURATION_PRESET: Release-windows + _RELEASE_CONFIGURATION_RAW: Release _BUILD_BRANCH: "${{ github.ref }}" _CHANGELOG_VERSION: "0" # GIT: Fix reporting from stderr to stdout diff --git a/.github/workflows/ubuntu.yaml b/.github/workflows/ubuntu.yaml index a660fc0f..c876cb8e 100644 --- a/.github/workflows/ubuntu.yaml +++ b/.github/workflows/ubuntu.yaml @@ -28,7 +28,8 @@ env: _IS_GITHUB_RELEASE: false _RELEASE_NAME: Field-Map-Editor _RELEASE_VERSION: v0 - _RELEASE_CONFIGURATION: Release + _RELEASE_CONFIGURATION_PRESET: Release-linux + _RELEASE_CONFIGURATION_RAW: Release _BUILD_BRANCH: "${{ github.ref }}" _CHANGELOG_VERSION: "0" # GIT: Fix reporting from stderr to stdout @@ -56,7 +57,8 @@ jobs: sudo apt-get update sudo add-apt-repository universe -y sudo apt-get update - sudo apt-get install -y ninja-build libxmu-dev libxi-dev libgl-dev libxrandr-dev libxinerama-dev libxcursor-dev gcc-14 g++-14 + sudo apt-get install -y ninja-build libxmu-dev libxi-dev libgl-dev libxrandr-dev libxinerama-dev libxcursor-dev gcc-14 g++-14 \ + mono-complete # GCC 14 sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-14 100 sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-14 100 @@ -78,18 +80,14 @@ jobs: restore-keys: | vcpkg-${{ runner.os }}- + - name: Integrate vcpkg + run: ${{ github.workspace }}/vcpkg/vcpkg integrate install + - name: Configure CMake - # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. - # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type - run: cmake -B ${{github.workspace}}/build -G Ninja -DCMAKE_TOOLCHAIN_FILE=${{github.workspace}}/vcpkg/scripts/buildsystems/vcpkg.cmake -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} + run: cmake --preset "${{ env._RELEASE_CONFIGURATION_PRESET }}" - name: Build - # Build your program with the given configuration - run: cmake --build ${{github.workspace}}/build --parallel + run: cmake --build --preset "${{ env._RELEASE_CONFIGURATION_PRESET }}" - name: Test - working-directory: ${{github.workspace}}/build - # Execute tests defined by the CMake configuration. - # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail - run: ctest --output-on-failure - + run: cmake --build --preset "${{ env._RELEASE_CONFIGURATION_PRESET }}" --target test \ No newline at end of file diff --git a/CMakePresets.json b/CMakePresets.json index f72e5384..30941964 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -133,19 +133,23 @@ { "name": "Release-windows", - "configurePreset": "Release-windows" + "configurePreset": "Release-windows", + "configuration": "Release" }, { "name": "Debug-windows", - "configurePreset": "Debug-windows" + "configurePreset": "Debug-windows", + "configuration": "Debug" }, { "name": "RelWithDebInfo-windows", - "configurePreset": "RelWithDebInfo-windows" + "configurePreset": "RelWithDebInfo-windows", + "configuration": "RelWithDebInfo" }, { "name": "MinSizeRel-windows", - "configurePreset": "MinSizeRel-windows" + "configurePreset": "MinSizeRel-windows", + "configuration": "MinSizeRel" } ] } \ No newline at end of file diff --git a/src/opengl/main/Configuration.cpp b/src/opengl/main/Configuration.cpp index 2ecfb525..c6d20450 100644 --- a/src/opengl/main/Configuration.cpp +++ b/src/opengl/main/Configuration.cpp @@ -3,11 +3,14 @@ // #include "Configuration.hpp" +#include "Paths.hpp" #include "safedir.hpp" #include #include +#include #include + fme::Configuration::Configuration(std::filesystem::path in_path) : m_path(std::move(in_path)) , m_table( @@ -45,19 +48,23 @@ fme::Configuration::Configuration() if (!initialized) { - std::error_code error_code{}; - path = std::filesystem::current_path(error_code) / "res" - / "field-map-editor.toml"; - if (error_code) - { - spdlog::warn( - "{}:{} - {}: {} path: \"{}\"", - __FILE__, - __LINE__, - error_code.value(), - error_code.message(), - path.string()); - } + path = getAppConfigDir() / "config.toml"; + auto console_logger = spdlog::get(""); + spdlog::info("Config path: \"{}\"", path.string()); + console_logger->info("Config path: \"{}\"", path.string()); + // std::error_code error_code{}; + // path = std::filesystem::current_path(error_code) / "res" + // / "field-map-editor.toml"; + // if (error_code) + // { + // spdlog::warn( + // "{}:{} - {}: {} path: \"{}\"", + // __FILE__, + // __LINE__, + // error_code.value(), + // error_code.message(), + // path.string()); + // } initialized = true; } diff --git a/src/opengl/main/Paths.hpp b/src/opengl/main/Paths.hpp new file mode 100644 index 00000000..57b513f2 --- /dev/null +++ b/src/opengl/main/Paths.hpp @@ -0,0 +1,49 @@ +#include "open_viii/paths/Paths.hpp" +#include +#include + +namespace fme +{ +inline static const std::filesystem::path app_name = "Field-Map-Editor"; + + +// Example: Config path (inside dataHome or configHome) +inline std::filesystem::path getAppDataDir() +{ + return open_viii::Paths::dataHome() / app_name; +} + +inline std::filesystem::path getAppConfigDir() +{ + return open_viii::Paths::configHome() / app_name; +} + +// Logs path (inside stateHome) +inline std::filesystem::path getAppLogsDir() +{ + return open_viii::Paths::stateHome() / app_name / "Logs"; +} + +inline void createDirs() +{ + const auto create_log + = []( + const spdlog::format_string_t format, + const std::filesystem::path &path) + { + std::error_code ec; + std::filesystem::create_directories(path, ec); + + if (ec) + { + spdlog::error("create_directories failed: {}", ec.message()); + } + + spdlog::info(format, path.string()); + }; + create_log("Data Dir: \"{}\"", getAppDataDir()); + create_log("Config Dir: \"{}\"", getAppConfigDir()); + create_log("Logs Dir: \"{}\"", getAppLogsDir()); +} + +}// namespace fme diff --git a/src/opengl/main/gui/gui.cpp b/src/opengl/main/gui/gui.cpp index f543970c..8a8774de 100644 --- a/src/opengl/main/gui/gui.cpp +++ b/src/opengl/main/gui/gui.cpp @@ -10,6 +10,7 @@ #include "main_menu_paths.hpp" #include "open_file_explorer.hpp" #include "path_search.hpp" +#include "Paths.hpp" #include "push_pop_id.hpp" #include "safedir.hpp" #include "tool_tip.hpp" @@ -4151,9 +4152,15 @@ gui::gui(GLFWwindow *const window) // 2. Configure ImGui (optional but common) ImGuiIO &imgui_io = ImGui::GetIO(); std::error_code error_code = {}; - static const auto path = (std::filesystem::current_path(error_code) / "res" - / "field-map-editor_imgui.ini") - .string(); + + + // static const auto path = (std::filesystem::current_path(error_code) / "res" + // / "field-map-editor_imgui.ini") + // .string(); + auto console_logger = spdlog::get(""); + static const auto path = (getAppConfigDir() / "imgui.ini").string(); + spdlog::info("Imgui Confg: \"{}\"", path); + console_logger->info("Imgui Confg: \"{}\"", path); imgui_io.ConfigFlags = bitwise_or(imgui_io.ConfigFlags, ImGuiConfigFlags_DockingEnable); imgui_io.ConfigFlags diff --git a/src/opengl/main/main.cpp b/src/opengl/main/main.cpp index 8c64bc4f..28a43194 100644 --- a/src/opengl/main/main.cpp +++ b/src/opengl/main/main.cpp @@ -4,6 +4,9 @@ #include // clang-format on #include "gui/gui.hpp" +#include "Paths.hpp" +#include +#include #include #include @@ -117,11 +120,70 @@ int main( [[maybe_unused]] int argc, [[maybe_unused]] char **argv) { + fme::createDirs();// create paths first + const auto local_now = []() -> std::chrono::system_clock::time_point + { + try + { + // get current local time + const std::chrono::zoned_time cur_time{ + std::chrono::current_zone(), + std::chrono::system_clock::now() + }; + + // get local_time rounded to seconds + auto local_sec + = std::chrono::time_point_cast( + cur_time.get_local_time()); + + // reinterpret local_time as system_clock by measuring duration + // since epoch + auto local_duration = local_sec.time_since_epoch(); + + // NOTE: this just treats the underlying duration as system_clock + // time + return std::chrono::time_point_cast( + std::chrono::system_clock::time_point{ local_duration }); + } + catch (const std::runtime_error &ex) + { + spdlog::error("Failed to get time zone: {}", ex.what()); + return std::chrono::time_point_cast( + std::chrono::system_clock::now()); + } + }; try { + + const auto now = local_now(); + + // YYYY_MM_DD_HH_MM_SS.log + const auto filename = [&]() + { + // format as usual + std::string tmp = fmt::format("{:%Y%m%d_%H%M%S}", now); + + // find '.' and truncate if present + auto pos = tmp.find('.'); + if (pos != std::string::npos) + { + tmp.resize(pos); + } + + // append extension + tmp += ".log"; + return tmp; + }(); // Create file logger and set as default + const auto file_logger_path = fme::getAppLogsDir() / filename; + spdlog::info("Created Log File: \"{}\"", file_logger_path); +#if defined(_WIN32) && defined(SPDLOG_WCHAR_FILENAMES) auto file_logger = spdlog::basic_logger_mt( - "file_logger", "res/field_map_editor.log", true); + "file_logger", file_logger_path.wstring(), true); +#else + auto file_logger = spdlog::basic_logger_mt( + "file_logger", file_logger_path.string(), true); +#endif // Remove logger name from output pattern file_logger->set_pattern(R"([%Y-%m-%d %H:%M:%S.%e] [%^%l%$] %v)"); @@ -140,6 +202,7 @@ int main( // Now log anywhere spdlog::info("App started"); + fme::createDirs();// rerun to log paths in log file. } catch (const spdlog::spdlog_ex &ex) {