From 696bbcca4f986cd59b032628bfe38c1010c6498d Mon Sep 17 00:00:00 2001 From: Nelonn <42481486+Nelonn@users.noreply.github.com> Date: Sun, 28 Jul 2024 15:20:21 +0300 Subject: [PATCH 1/3] Packing macOS executable into application --- .github/workflows/automatic_release.yml | 4 ++-- .github/workflows/sniffcraft_build.yml | 13 +++++++++++++ .gitignore | 10 +++++++++- sniffcraft/CMakeLists.txt | 9 +++++++++ sniffcraft/src/conf.cpp | 8 ++++++++ 5 files changed, 41 insertions(+), 3 deletions(-) diff --git a/.github/workflows/automatic_release.yml b/.github/workflows/automatic_release.yml index 24e3ad6..3065363 100644 --- a/.github/workflows/automatic_release.yml +++ b/.github/workflows/automatic_release.yml @@ -88,7 +88,7 @@ jobs: run: | mv linux/sniffcraft sniffcraft-linux-${{ steps.mc-version.outputs.version }} mv windows/sniffcraft.exe sniffcraft-windows-${{ steps.mc-version.outputs.version }}.exe - mv macos/sniffcraft sniffcraft-macos-${{ steps.mc-version.outputs.version }} + mv macos/sniffcraft.zip sniffcraft-macos-universal-${{ steps.mc-version.outputs.version }}.zip - name: Remove old latest release run: gh release delete latest --repo ${{ github.repository }} --cleanup-tag -y @@ -100,7 +100,7 @@ jobs: gh release create latest sniffcraft-linux-${{ steps.mc-version.outputs.version }} sniffcraft-windows-${{ steps.mc-version.outputs.version }}.exe - sniffcraft-macos-${{ steps.mc-version.outputs.version }} + sniffcraft-macos-universal-${{ steps.mc-version.outputs.version }}.zip --repo ${{ github.repository }} --latest -F release_note.txt diff --git a/.github/workflows/sniffcraft_build.yml b/.github/workflows/sniffcraft_build.yml index 953c672..d90283e 100644 --- a/.github/workflows/sniffcraft_build.yml +++ b/.github/workflows/sniffcraft_build.yml @@ -87,8 +87,21 @@ jobs: GH_TOKEN: ${{ github.token }} - name: Upload artifact + if: ${{ inputs.os != 'macos-latest' }} uses: actions/upload-artifact@v4 with: name: sniffcraft-${{ runner.os }} path: ${{ github.workspace }}/bin/sniffcraft* retention-days: 1 + + - name: Archive macOS application + if: ${{ inputs.os == 'macos-latest' }} + run: zip -r ${{ github.workspace }}/bin/sniffcraft.zip ${{ github.workspace }}/bin/SniffCraft.app + + - name: Upload macOS artifact + if: ${{ inputs.os == 'macos-latest' }} + uses: actions/upload-artifact@v4 + with: + name: sniffcraft-${{ runner.os }} + path: ${{ github.workspace }}/bin/sniffcraft.zip + retention-days: 1 diff --git a/.gitignore b/.gitignore index 0948008..954e577 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,11 @@ bin/ build/ -lib/ \ No newline at end of file +lib/ + +.vscode/ +.idea/ + +# CLion build directory +/cmake-** + +.DS_Store diff --git a/sniffcraft/CMakeLists.txt b/sniffcraft/CMakeLists.txt index a2632e1..28c43b1 100644 --- a/sniffcraft/CMakeLists.txt +++ b/sniffcraft/CMakeLists.txt @@ -108,6 +108,15 @@ if (MSVC) set_target_properties(${PROJECT_NAME} PROPERTIES MSVC_RUNTIME_LIBRARY "MultiThreaded") endif(MSVC) +if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin") + set_target_properties(${PROJECT_NAME} PROPERTIES MACOSX_BUNDLE TRUE) + set_target_properties(${PROJECT_NAME} PROPERTIES + OUTPUT_NAME "SniffCraft" + XCODE_ATTRIBUTE_ENABLE_HARDENED_RUNTIME YES + XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY libc++ + ) +endif() + # Add Asio target_link_libraries(${PROJECT_NAME} PUBLIC asio) target_compile_definitions(${PROJECT_NAME} PUBLIC ASIO_STANDALONE) diff --git a/sniffcraft/src/conf.cpp b/sniffcraft/src/conf.cpp index 52ca976..21c287f 100644 --- a/sniffcraft/src/conf.cpp +++ b/sniffcraft/src/conf.cpp @@ -45,12 +45,20 @@ ProtocolCraft::Json::Value Conf::LoadConf() { if (conf_path.empty()) { +#if defined(__APPLE__) + conf_path = "/Users/" + std::string(std::getenv("USER")) + "/Library/Application Support/SniffCraft/conf.json"; +#else conf_path = "conf.json"; +#endif } // Create file if it doesn't exist if (!std::filesystem::exists(conf_path)) { + std::filesystem::path parent_directory = std::filesystem::path(conf_path).parent_path(); + if (!parent_directory.empty()) { + std::filesystem::create_directories(parent_directory); + } std::ofstream outfile(conf_path, std::ios::out); outfile << ProtocolCraft::Json::Value().Dump(4); } From 7dea38a5cd22955714547b1e24d8144ce79fd994 Mon Sep 17 00:00:00 2001 From: Nelonn <42481486+Nelonn@users.noreply.github.com> Date: Sun, 28 Jul 2024 15:21:17 +0300 Subject: [PATCH 2/3] Trigger workflow --- sniffcraft/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sniffcraft/CMakeLists.txt b/sniffcraft/CMakeLists.txt index 28c43b1..c43b109 100644 --- a/sniffcraft/CMakeLists.txt +++ b/sniffcraft/CMakeLists.txt @@ -108,7 +108,7 @@ if (MSVC) set_target_properties(${PROJECT_NAME} PROPERTIES MSVC_RUNTIME_LIBRARY "MultiThreaded") endif(MSVC) -if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin") +if (CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin") set_target_properties(${PROJECT_NAME} PROPERTIES MACOSX_BUNDLE TRUE) set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME "SniffCraft" From 1f3302bba0368017a7aa5f7c5dfc41e7f1fdd96d Mon Sep 17 00:00:00 2001 From: Nelonn <42481486+Nelonn@users.noreply.github.com> Date: Sun, 28 Jul 2024 15:26:16 +0300 Subject: [PATCH 3/3] Fixed macOS application archive --- .github/workflows/sniffcraft_build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sniffcraft_build.yml b/.github/workflows/sniffcraft_build.yml index d90283e..8f2c887 100644 --- a/.github/workflows/sniffcraft_build.yml +++ b/.github/workflows/sniffcraft_build.yml @@ -96,7 +96,7 @@ jobs: - name: Archive macOS application if: ${{ inputs.os == 'macos-latest' }} - run: zip -r ${{ github.workspace }}/bin/sniffcraft.zip ${{ github.workspace }}/bin/SniffCraft.app + run: cd ${{ github.workspace }}/bin && zip -r sniffcraft.zip SniffCraft.app - name: Upload macOS artifact if: ${{ inputs.os == 'macos-latest' }}