From 11a71a28381201c2e49d182f00fb91f4c02fc755 Mon Sep 17 00:00:00 2001 From: MistEO Date: Sat, 7 Dec 2024 23:44:50 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20current=5Fzone=20?= =?UTF-8?q?=E5=B4=A9=E6=BA=83=E9=97=AE=E9=A2=98=EF=BC=8Cci=20=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=20win-dbg=20=E5=8C=85=20(#451)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build.yml | 140 ++++++++++++++---- .github/workflows/test.yml | 4 +- .../Controller/ControllerAgent.cpp | 5 +- .../MaaProjectInterface/Impl/Configurator.cpp | 13 +- .../MaaToolkit/Config/GlobalOptionConfig.cpp | 6 +- source/MaaUtils/Logger/Logger.cpp | 4 +- source/include/Utils/ImageIo.h | 3 +- source/include/Utils/Time.hpp | 32 ++-- 8 files changed, 154 insertions(+), 53 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6d560a985..b2391adcf 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -3,27 +3,27 @@ name: build on: push: tags: - - 'v*' + - "v*" branches: - - '**' + - "**" paths: - - '.github/workflows/build.yml' - - '3rdparty/**' - - 'cmake/**' - - 'include/**' - - 'source/**' - - 'CMakeLists.txt' + - ".github/workflows/build.yml" + - "3rdparty/**" + - "cmake/**" + - "include/**" + - "source/**" + - "CMakeLists.txt" pull_request: branches: - - '**' + - "**" paths: - - '.github/workflows/build.yml' - - '3rdparty/**' - - 'cmake/**' - - 'include/**' - - 'source/**' - - 'CMakeLists.txt' + - ".github/workflows/build.yml" + - "3rdparty/**" + - "cmake/**" + - "include/**" + - "source/**" + - "CMakeLists.txt" workflow_dispatch: jobs: @@ -55,7 +55,7 @@ jobs: with: minimum-size: 16GB maximum-size: 16GB - disk-root: 'D:' + disk-root: "D:" - uses: actions/checkout@v4 with: @@ -64,7 +64,7 @@ jobs: - name: Setup Windows 10 SDK uses: GuillaumeFalourd/setup-windows10-sdk-action@v2.2 with: - sdk-version: 22621 + sdk-version: 26100 - name: Bootstrap MaaDeps env: @@ -89,7 +89,7 @@ jobs: - name: Build MAA run: | - cmake --preset "${{ matrix.arch == 'x86_64' && 'MSVC 2022' || 'MSVC 2022 ARM' }}" -DCMAKE_SYSTEM_VERSION="10.0.22621.0" -DMAADEPS_TRIPLET="maa-${{ matrix.arch == 'x86_64' && 'x64' || 'arm64' }}-windows" -DMAA_HASH_VERSION='${{ needs.meta.outputs.tag }}' -DBUILD_NODEJS_BINDING=ON + cmake --preset "${{ matrix.arch == 'x86_64' && 'MSVC 2022' || 'MSVC 2022 ARM' }}" -DCMAKE_SYSTEM_VERSION="10.0.26100.0" -DMAADEPS_TRIPLET="maa-${{ matrix.arch == 'x86_64' && 'x64' || 'arm64' }}-windows" -DMAA_HASH_VERSION='${{ needs.meta.outputs.tag }}' -DBUILD_NODEJS_BINDING=ON cmake --build build --preset "${{ matrix.arch == 'x86_64' && 'MSVC 2022' || 'MSVC 2022 ARM' }} - Release" -j 16 @@ -111,7 +111,74 @@ jobs: if: always() with: name: MAA-win-${{ matrix.arch }} - path: 'install' + path: "install" + + windows_debug: + needs: meta + runs-on: windows-latest + strategy: + matrix: + arch: [x86_64] + fail-fast: false + + steps: + - name: Windows runner hack + shell: cmd + run: | + dir d:\a + cd .. + mkdir C:\MaaFramework + rmdir MaaFramework + mklink /j MaaFramework C:\MaaFramework + dism /Online /Disable-Feature /FeatureName:Windows-Defender /Remove /NoRestart /Quiet + cd . + + - name: Windows runner hack (2) + uses: al-cheb/configure-pagefile-action@v1.4 + with: + minimum-size: 16GB + maximum-size: 16GB + disk-root: "D:" + + - uses: actions/checkout@v4 + with: + submodules: true + + - name: Setup Windows 10 SDK + uses: GuillaumeFalourd/setup-windows10-sdk-action@v2.2 + with: + sdk-version: 26100 + + - name: Bootstrap MaaDeps + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + python3 tools/maadeps-download.py x64-windows + + - name: Build MAA + run: | + cmake --preset 'MSVC 2022' -DCMAKE_SYSTEM_VERSION="10.0.26100.0" -DMAADEPS_TRIPLET="maa-x64-windows" -DMAA_HASH_VERSION='${{ needs.meta.outputs.tag }}-dbg' + + cmake --build build --preset 'MSVC 2022 - Debug' -j 16 --config Debug + + - name: Install + shell: bash + if: always() + run: | + cmake --install build --prefix install --config Debug + + cp -r docs install + cp README*.md install + + cp -r sample install + + cp -r LICENSE.md install + + - uses: actions/upload-artifact@v4 + if: always() + with: + name: MAA-win-dbg-${{ matrix.arch }} + path: "install" ubuntu: needs: meta @@ -199,7 +266,7 @@ jobs: if: always() with: name: MAA-linux-${{ matrix.arch }} - path: 'install' + path: "install" macos: needs: meta @@ -281,7 +348,7 @@ jobs: if: always() with: name: MAA-macos-${{ matrix.arch }} - path: 'install' + path: "install" android: needs: meta @@ -347,7 +414,7 @@ jobs: if: always() with: name: MAA-android-${{ matrix.arch }} - path: 'install' + path: "install" nuget_pack: needs: [meta, windows, ubuntu, macos, android] @@ -377,7 +444,7 @@ jobs: if: always() with: name: MAA-nupkgs - path: 'tools/nupkgs/*.nupkg' + path: "tools/nupkgs/*.nupkg" pip_pack: needs: [meta, windows, ubuntu, macos, android] @@ -399,7 +466,7 @@ jobs: if: always() with: name: MAA-pip-pkgs - path: 'tools/pip_pack/wheel/*.whl' + path: "tools/pip_pack/wheel/*.whl" nodejs_pack: needs: [meta, windows, ubuntu, macos, android] @@ -436,11 +503,21 @@ jobs: - uses: actions/upload-artifact@v4 with: name: MAA-nodejs-package - path: 'source/binding/NodeJS/release' + path: "source/binding/NodeJS/release" release: if: ${{ needs.meta.outputs.is_release == 'true' && github.repository_id == '632024122' }} - needs: [meta, windows, ubuntu, macos, android, nuget_pack, pip_pack, nodejs_pack] + needs: + [ + meta, + windows, + ubuntu, + macos, + android, + nuget_pack, + pip_pack, + nodejs_pack, + ] runs-on: ubuntu-latest env: OUTPUT_PUBLISH_FAILED: 'echo "failed=true" >> $GITHUB_OUTPUT && echo "::error::Failed to publish packages"' @@ -518,6 +595,10 @@ jobs: run: | rm -r assets/MAA-nodejs-package + - name: Remove win-dbg package + run: | + rm -r assets/MAA-win-dbg* + - run: | cd assets for f in *; do @@ -531,13 +612,12 @@ jobs: prerelease: ${{ needs.meta.outputs.is_pre_release == 'true' }} - name: Create issue if failed to publish packages - if: steps.nuget.outputs.failed || steps.pip.outputs.failed || steps.nodejs.outputs.failed + if: steps.nuget.outputs.failed || steps.pip.outputs.failed uses: actions-cool/issues-helper@v3 with: - actions: 'create-issue' - title: '${{ needs.meta.outputs.tag }} failed to publish packages' + actions: "create-issue" + title: "${{ needs.meta.outputs.tag }} failed to publish packages" body: | Please manually publish the following packages: ${{ steps.nuget.outputs.failed && '- nuget @moomiji' || '' }} ${{ steps.pip.outputs.failed && '- pip @MistEO' || '' }} - ${{ steps.nodejs.outputs.failed && '- nodejs @neko-para' || '' }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b76933258..f004bda58 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -64,7 +64,7 @@ jobs: - name: Setup Windows 10 SDK uses: GuillaumeFalourd/setup-windows10-sdk-action@v2.2 with: - sdk-version: 22621 + sdk-version: 26100 - name: Setup Python uses: actions/setup-python@v5.2.0 @@ -97,7 +97,7 @@ jobs: - name: Build MAA run: | - cmake --preset "${{ matrix.arch == 'x86_64' && 'MSVC 2022' || 'MSVC 2022 ARM' }}" -DMAADEPS_TRIPLET="maa-${{ matrix.arch == 'x86_64' && 'x64' || 'arm64' }}-windows" -DCMAKE_SYSTEM_VERSION="10.0.22621.0" -DMAA_HASH_VERSION='${{ needs.meta.outputs.tag }}' -DBUILD_NODEJS_BINDING=ON -DBUILD_PIPELINE_TESTING=ON -DBUILD_DLOPEN_TESTING=ON + cmake --preset "${{ matrix.arch == 'x86_64' && 'MSVC 2022' || 'MSVC 2022 ARM' }}" -DMAADEPS_TRIPLET="maa-${{ matrix.arch == 'x86_64' && 'x64' || 'arm64' }}-windows" -DCMAKE_SYSTEM_VERSION="10.0.26100.0" -DMAA_HASH_VERSION='${{ needs.meta.outputs.tag }}' -DBUILD_NODEJS_BINDING=ON -DBUILD_PIPELINE_TESTING=ON -DBUILD_DLOPEN_TESTING=ON cmake --build build --preset "${{ matrix.arch == 'x86_64' && 'MSVC 2022' || 'MSVC 2022 ARM' }} - Release" -j 16 diff --git a/source/MaaFramework/Controller/ControllerAgent.cpp b/source/MaaFramework/Controller/ControllerAgent.cpp index fea4bf6b2..053703ec7 100644 --- a/source/MaaFramework/Controller/ControllerAgent.cpp +++ b/source/MaaFramework/Controller/ControllerAgent.cpp @@ -601,7 +601,10 @@ bool ControllerAgent::recording() const void ControllerAgent::init_recording() { auto recording_dir = GlobalOptionMgr::get_instance().log_dir() / "recording"; - std::filesystem::create_directories(recording_dir); + if (std::error_code ec; !std::filesystem::create_directories(recording_dir, ec)) { + LogError << "failed to create_directories" << VAR(recording_dir) << VAR(ec.message()); + return; + } recording_path_ = recording_dir / std::format("maa_recording_{}.txt", format_now_for_filename()); } diff --git a/source/MaaProjectInterface/Impl/Configurator.cpp b/source/MaaProjectInterface/Impl/Configurator.cpp index 12c695f65..cf876ec3e 100644 --- a/source/MaaProjectInterface/Impl/Configurator.cpp +++ b/source/MaaProjectInterface/Impl/Configurator.cpp @@ -51,9 +51,18 @@ void Configurator::save(const std::filesystem::path& user_dir) { LogInfo << VAR(user_dir); - std::filesystem::create_directories((user_dir / kConfigFilename).parent_path()); + const auto config_path = user_dir / kConfigFilename; + if (std::error_code ec; config_path.has_parent_path() && !std::filesystem::create_directories(config_path.parent_path(), ec)) { + LogError << "failed to create_directories" << VAR(config_path.parent_path()) << VAR(ec.message()); + return; + } + + std::ofstream ofs(config_path); + if (!ofs.is_open()) { + LogError << "failed to open" << VAR(config_path); + return; + } - std::ofstream ofs(user_dir / kConfigFilename); ofs << config_.to_json(); } diff --git a/source/MaaToolkit/Config/GlobalOptionConfig.cpp b/source/MaaToolkit/Config/GlobalOptionConfig.cpp index 3a637c12a..a953148bd 100644 --- a/source/MaaToolkit/Config/GlobalOptionConfig.cpp +++ b/source/MaaToolkit/Config/GlobalOptionConfig.cpp @@ -88,7 +88,11 @@ bool GlobalOptionConfig::save() const { LogInfo; - std::filesystem::create_directories(config_path_.parent_path()); + if (std::error_code ec; config_path_.has_parent_path() && !std::filesystem::create_directories(config_path_.parent_path(), ec)) { + LogError << "failed to create_directories" << VAR(config_path_.parent_path()) << VAR(ec.message()); + return false; + } + std::ofstream ofs(config_path_, std::ios::out); if (!ofs.is_open()) { LogError << "Failed to open config file" << config_path_; diff --git a/source/MaaUtils/Logger/Logger.cpp b/source/MaaUtils/Logger/Logger.cpp index 937551364..b59867e41 100644 --- a/source/MaaUtils/Logger/Logger.cpp +++ b/source/MaaUtils/Logger/Logger.cpp @@ -155,7 +155,9 @@ void Logger::open() return; } - std::filesystem::create_directories(log_dir_); + if (std::error_code ec; !std::filesystem::create_directories(log_dir_, ec)) { + return; + } std::unique_lock trace_lock(trace_mutex_); if (ofs_.is_open()) { diff --git a/source/include/Utils/ImageIo.h b/source/include/Utils/ImageIo.h index 3496357c2..0d0a3284a 100644 --- a/source/include/Utils/ImageIo.h +++ b/source/include/Utils/ImageIo.h @@ -28,8 +28,7 @@ inline cv::Mat imread(const std::string& utf8_path, int flags = cv::IMREAD_COLOR inline bool imwrite(const std::filesystem::path& path, cv::InputArray img) { - if (path.has_parent_path() && !std::filesystem::exists(path.parent_path()) - && !std::filesystem::create_directories(path.parent_path())) { + if (std::error_code ec; path.has_parent_path() && !std::filesystem::create_directories(path.parent_path(), ec)) { return false; } diff --git a/source/include/Utils/Time.hpp b/source/include/Utils/Time.hpp index 253eff4f4..eceb3de37 100644 --- a/source/include/Utils/Time.hpp +++ b/source/include/Utils/Time.hpp @@ -1,10 +1,8 @@ #pragma once -#if defined(__APPLE__) || defined(__ANDROID__) -#define MAA_USE_POSIX_TIME -#endif - -#ifdef MAA_USE_POSIX_TIME +#ifdef _WIN32 +#include "SafeWindows.hpp" +#else #include #include #include @@ -22,17 +20,19 @@ MAA_NS_BEGIN inline std::string format_now() { -#ifndef MAA_USE_POSIX_TIME - return std::format( - "{}", - std::chrono::current_zone()->to_local(std::chrono::floor(std::chrono::system_clock::now()))); + constexpr std::string_view kFormat = "{:0>4}-{:0>2}-{:0>2} {:0>2}:{:0>2}:{:0>2}.{:0>3}"; + +#ifdef _WIN32 + SYSTEMTIME sys {}; + GetLocalTime(&sys); + return std::format(kFormat, sys.wYear, sys.wMonth, sys.wDay, sys.wHour, sys.wMinute, sys.wSecond, sys.wMilliseconds); #else timeval tv = {}; gettimeofday(&tv, nullptr); time_t nowtime = tv.tv_sec; tm* tm_info = localtime(&nowtime); return std::format( - "{:0>4}-{:0>2}-{:0>2} {:0>2}:{:0>2}:{:0>2}.{:0>3}", + kFormat, tm_info->tm_year + 1900, tm_info->tm_mon, tm_info->tm_mday, @@ -45,22 +45,26 @@ inline std::string format_now() inline std::string format_now_for_filename() { -#ifndef MAA_USE_POSIX_TIME - return std::format("{:%Y.%m.%d-%H.%M.%S}", std::chrono::current_zone()->to_local(std::chrono::system_clock::now())); + constexpr std::string_view kFormat = "{:0>4}.{:0>2}.{:0>2}-{:0>2}.{:0>2}.{:0>2}.{}"; + +#ifdef _WIN32 + SYSTEMTIME sys {}; + GetLocalTime(&sys); + return std::format(kFormat, sys.wYear, sys.wMonth, sys.wDay, sys.wHour, sys.wMinute, sys.wSecond, sys.wMilliseconds); #else timeval tv = {}; gettimeofday(&tv, nullptr); time_t nowtime = tv.tv_sec; tm* tm_info = localtime(&nowtime); return std::format( - "{:0>4}.{:0>2}.{:0>2}-{:0>2}.{:0>2}.{:0>2}.{}", + kFormat, tm_info->tm_year + 1900, tm_info->tm_mon, tm_info->tm_mday, tm_info->tm_hour, tm_info->tm_min, tm_info->tm_sec, - tv.tv_usec); + tv.tv_usec / 1000); #endif }