diff --git a/.gitattributes b/.gitattributes index 970e13f..92bbb8f 100644 --- a/.gitattributes +++ b/.gitattributes @@ -36,4 +36,7 @@ # Executables *.exe binary *.out binary -*.app binary \ No newline at end of file +*.app binary + +# Linux shell files must always be LF +*.sh text eol=lf \ No newline at end of file diff --git a/.github/workflows/cmake-multi-platform.yml b/.github/workflows/cmake-multi-platform.yml index 95ddb78..6c5b9f7 100644 --- a/.github/workflows/cmake-multi-platform.yml +++ b/.github/workflows/cmake-multi-platform.yml @@ -24,7 +24,7 @@ jobs: # # To add more build types (Release, Debug, RelWithDebInfo, etc.) customize the build_type list. matrix: - os: [ubuntu-latest, windows-latest, macos-latest] + os: [ubuntu-latest, windows-latest] # macos-latest build_type: [Release] c_compiler: [gcc, clang, cl] cpp_compiler: [g++, clang++, cl] @@ -38,9 +38,9 @@ jobs: - os: ubuntu-latest c_compiler: clang cpp_compiler: clang++ - - os: macos-latest - c_compiler: clang - cpp_compiler: clang++ + #- os: macos-latest + # c_compiler: clang + # cpp_compiler: clang++ exclude: - os: windows-latest c_compiler: gcc @@ -50,14 +50,14 @@ jobs: c_compiler: cl - os: ubuntu-latest cpp_compiler: cl - - os: macos-latest - c_compiler: gcc - - os: macos-latest - cpp_compiler: g++ - - os: macos-latest - c_compiler: cl - - os: macos-latest - cpp_compiler: cl + #- os: macos-latest + # c_compiler: gcc + #- os: macos-latest + # cpp_compiler: g++ + #- os: macos-latest + # c_compiler: cl + #- os: macos-latest + # cpp_compiler: cl steps: - uses: actions/checkout@v4 with: diff --git a/.gitignore b/.gitignore index 0839667..2e552b2 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,9 @@ build/** # Blacklist specific build directories linuxbuild/ build/ +.idea/ +winbuild/ + +!Compile.sh +!Compile.bat +HarmonyLinkLib/.vscode/ diff --git a/CMakeLists.txt b/CMakeLists.txt index 02296e9..a394d22 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,12 +44,12 @@ elseif(UNIX) endif() # Set global output directories for all build types -foreach(TYPE IN ITEMS DEBUG RELEASE) - string(TOUPPER ${TYPE} TYPE_UPPER) - set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${TYPE_UPPER} "${CMAKE_BINARY_DIR}/bin/${TYPE}") - set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_${TYPE_UPPER} "${CMAKE_BINARY_DIR}/lib/${TYPE}") - set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${TYPE_UPPER} "${CMAKE_BINARY_DIR}/archive/${TYPE}") -endforeach() +#foreach(TYPE IN ITEMS DEBUG RELEASE) +# string(TOUPPER ${TYPE} TYPE_UPPER) +# set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${TYPE_UPPER} "${CMAKE_BINARY_DIR}/bin/${TYPE}") +# set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_${TYPE_UPPER} "${CMAKE_BINARY_DIR}/lib/${TYPE}") +# set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${TYPE_UPPER} "${CMAKE_BINARY_DIR}/archive/${TYPE}") +#endforeach() # Add the library and executable directories diff --git a/Compile.bat b/Compile.bat new file mode 100644 index 0000000..ccad60c --- /dev/null +++ b/Compile.bat @@ -0,0 +1,68 @@ +@echo off +setlocal enabledelayedexpansion + +REM Clear the screen +cls + +REM Define the color codes +set GREEN= +set NC= + +REM Prompt the user to choose a compiler +echo %GREEN%Select the compiler to use:%NC% +echo 1^ ) MSBuild (default) +echo 2^ ) MinGW +echo 3^ ) Ninja +set /p choice=Enter the number of your choice: + +REM Set the generator and compiler based on the user's choice +if "%choice%"=="2" ( + set "GENERATOR=MinGW Makefiles" + set "COMPILER_OPTION=-DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++" +) else if "%choice%"=="3" ( + set "GENERATOR=Ninja" + set "COMPILER_OPTION=" +) else ( + set "GENERATOR=Visual Studio 17 2022" + set "COMPILER_OPTION=-A x64" + set "choice=1" +) + +echo Using generator: %GENERATOR% + +REM Prompt the user to choose a build type +echo %GREEN%Select the build type:%NC% +echo 1^ ) Release (default) +echo 2^ ) Debug +set /p build_choice=Enter the number of your choice: + +REM Set the build type based on the user's choice +if "%build_choice%"=="2" ( + set "BUILD_TYPE=Debug" +) else ( + set "BUILD_TYPE=Release" +) + +echo Build type: %BUILD_TYPE% + +REM Create the build directory if it doesn't exist +if not exist "winbuild" ( + mkdir winbuild +) + +cd winbuild + +REM Get the number of processors +for /f "tokens=2 delims==" %%a in ('wmic cpu get NumberOfLogicalProcessors /value') do set "NUM_PROCESSORS=%%a" + +REM Run CMake with the selected generator and build type +cmake -G "%GENERATOR%" %COMPILER_OPTION% -DCMAKE_BUILD_TYPE=%BUILD_TYPE% .. + +REM Build the project +if "%choice%"=="1" ( + cmake --build . --config %BUILD_TYPE% -- /m:%NUM_PROCESSORS% +) else ( + cmake --build . --config %BUILD_TYPE% -- -j %NUM_PROCESSORS% +) + +cd .. diff --git a/Compile.sh b/Compile.sh new file mode 100644 index 0000000..63ea1c3 --- /dev/null +++ b/Compile.sh @@ -0,0 +1,127 @@ +#!/bin/bash + +set -e + +clear + +# Define color codes +GREEN='\033[0;32m' +NC='\033[0m' # No Color +PURPLE='\033[0;35m' +GRAY='\033[1;30m' + +# Ensure dialog is installed +if ! command -v dialog &> /dev/null +then + echo "dialog could not be found. Please install it to use this script." + exit +fi + +# Function to check if a compiler is installed +check_compiler() { + if command -v $1 &> /dev/null + then + COMPILER_OPTIONS+=("$2" "$3" "$4") + fi +} + +# Array to store the menu options +COMPILER_OPTIONS=() + +# Add available compilers to the options array +check_compiler g++ "1" "g++ (default)" "on" +check_compiler clang++ "2" "clang++" "off" +check_compiler clang++-15 "3" "clang++ 15" "off" +check_compiler clang++-16 "4" "clang++ 16" "off" +check_compiler clang++-17 "5" "clang++ 17" "off" + +# Debug: print the compiler options +echo "Compiler options: ${COMPILER_OPTIONS[@]}" + +# Check if any compilers are available +if [ ${#COMPILER_OPTIONS[@]} -eq 0 ]; then + dialog --msgbox "No compilers found. Please install a compiler to use this script." 10 40 + exit +fi + +# Prompt the user to choose one or more compilers +compiler_choices=$(dialog --colors --title "\Zb\Z5Select Compiler\Zn" --checklist "\nChoose one or more compilers:" 15 60 ${#COMPILER_OPTIONS[@]} "${COMPILER_OPTIONS[@]}" 3>&1 1>&2 2>&3) + +# Process the selected compilers +C_COMPILERS=() +CXX_COMPILERS=() + +# Debug: print the compiler choices +echo "Compiler choices: $compiler_choices" + +for choice in $compiler_choices; do + case $choice in + 1) + C_COMPILERS+=("gcc") + CXX_COMPILERS+=("g++") + ;; + 2) + C_COMPILERS+=("clang") + CXX_COMPILERS+=("clang++") + ;; + 3) + C_COMPILERS+=("clang-15") + CXX_COMPILERS+=("clang++-15") + ;; + 4) + C_COMPILERS+=("clang-16") + CXX_COMPILERS+=("clang++-16") + ;; + 5) + C_COMPILERS+=("clang-17") + CXX_COMPILERS+=("clang++-17") + ;; + esac +done + +# Output the chosen compilers +msg="Chosen compilers:\n" +for i in "${!C_COMPILERS[@]}"; do + msg+="C compiler: ${C_COMPILERS[$i]}, C++ compiler: ${CXX_COMPILERS[$i]}\n" +done + +dialog --colors --msgbox "\Zb\Z5$msg\Zn" 20 60 + +# Prompt the user to choose a build type +build_choice=$(dialog --colors --title "\Zb\Z5Select Build Type\Zn" --menu "\nChoose a build type:" 10 40 2 \ +1 "Release (default)" \ +2 "Debug" 3>&1 1>&2 2>&3) + +# Set the build type based on the user's choice +case $build_choice in + 2) + BUILD_TYPE=Debug + ;; + *) + BUILD_TYPE=Release + ;; +esac + +# Output the chosen build type +dialog --colors --msgbox "\Zb\Z5Build type:\Zn $BUILD_TYPE" 10 40 + +clear + +# Create the build directory if it doesn't exist +if [ ! -d "linuxbuild" ]; then + mkdir linuxbuild +fi + +cd linuxbuild + +# Run CMake with the selected compilers and build type +for i in "${!C_COMPILERS[@]}"; do + cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_C_COMPILER=${C_COMPILERS[$i]} -DCMAKE_CXX_COMPILER=${CXX_COMPILERS[$i]} .. + # Build the project + cmake --build . --config $BUILD_TYPE -j 15 #--clean-first #--verbose +done + +cd .. + +# End with a success message +dialog --colors --msgbox "\Zb\Z5Build(s) completed successfully!\Zn" 10 40 diff --git a/HarmonyLinkLib/CMakeLists.txt b/HarmonyLinkLib/CMakeLists.txt index 6727506..de087b6 100644 --- a/HarmonyLinkLib/CMakeLists.txt +++ b/HarmonyLinkLib/CMakeLists.txt @@ -12,10 +12,11 @@ # limitations under the License. cmake_minimum_required(VERSION 3.10) -project(HarmonyLinkLib VERSION 2.1.0) +project(HarmonyLinkLib VERSION 2.1.2 LANGUAGES CXX) include(FetchContent) +# Fetch fmt library FetchContent_Declare( fmt GIT_REPOSITORY https://github.com/fmtlib/fmt.git @@ -23,15 +24,22 @@ FetchContent_Declare( ) FetchContent_MakeAvailable(fmt) -if(NOT fmt_POPULATED) - FetchContent_Populate(fmt) - # Add fmt but exclude it from the ALL target, reducing IDE clutter - add_subdirectory(${fmt_SOURCE_DIR} ${fmt_BINARY_DIR} EXCLUDE_FROM_ALL) -endif() set_target_properties(fmt PROPERTIES FOLDER External) set_target_properties(fmt PROPERTIES POSITION_INDEPENDENT_CODE TRUE) +# Fetch ghc library +FetchContent_Declare( + ghc_filesystem + GIT_REPOSITORY https://github.com/gulrak/filesystem.git + GIT_TAG v1.5.14 # Specify the desired version of ghc +) + +FetchContent_MakeAvailable(ghc_filesystem) + +set_target_properties(ghc_filesystem PROPERTIES FOLDER External) +set_target_properties(ghc_filesystem PROPERTIES POSITION_INDEPENDENT_CODE TRUE) + # Find the current Git branch and the last commit timestamp find_package(Git QUIET) if(GIT_FOUND) @@ -73,7 +81,6 @@ set(COMMON_SOURCES "src/Platform/IPlatformUtilities.cpp" "src/HarmonyLinkLib.cpp" "src/Version.cpp" - "src/dllmain.cpp" "src/Platform/WineUtilities.cpp" "src/Utilities.cpp" ) @@ -124,6 +131,18 @@ set(MAC_INCLUDES "src/Platform/Unix/UnixUtilities.h" ) +# Platform-specific definitions +if(WIN32) + add_definitions(-DBUILD_WINDOWS) +elseif(UNIX) + if(APPLE) + add_definitions(-DBUILD_MACOS) + else() + add_definitions(-DBUILD_LINUX) + endif() + add_definitions(-DBUILD_UNIX) +endif() + # Platform-specific definitions if(WIN32) message(STATUS "Compiling for Windows...") @@ -143,8 +162,16 @@ elseif(UNIX) endif() endif() +# Detect the compiler name +get_filename_component(COMPILER_NAME ${CMAKE_CXX_COMPILER} NAME) + +# Replace forbidden characters in file names (optional, if needed) +string(REPLACE "." "_" COMPILER_NAME ${COMPILER_NAME}) +string(REPLACE "/" "_" COMPILER_NAME ${COMPILER_NAME}) +string(REPLACE "\\" "_" COMPILER_NAME ${COMPILER_NAME}) + # Create the shared library -add_library(HarmonyLinkLibShared SHARED ${LIB_SOURCES} ${SHARED_SOURCES}) +add_library(HarmonyLinkLibShared SHARED ${LIB_SOURCES} ${SHARED_SOURCES} ${LIB_INCLUDES}) target_include_directories(HarmonyLinkLibShared PRIVATE "${PROJECT_SOURCE_DIR}/src" @@ -153,9 +180,10 @@ target_include_directories(HarmonyLinkLibShared "${PROJECT_SOURCE_DIR}/include" ) target_compile_definitions(HarmonyLinkLibShared PRIVATE HARMONYLINKLIB_SHARED) +set_target_properties(HarmonyLinkLibShared PROPERTIES OUTPUT_NAME "HarmonyLinkLibShared_${COMPILER_NAME}") # Create the static library -add_library(HarmonyLinkLibStatic STATIC ${LIB_SOURCES}) +add_library(HarmonyLinkLibStatic STATIC ${LIB_SOURCES} ${LIB_INCLUDES}) target_include_directories(HarmonyLinkLibStatic PRIVATE "${PROJECT_SOURCE_DIR}/src" @@ -164,20 +192,46 @@ target_include_directories(HarmonyLinkLibStatic "${PROJECT_SOURCE_DIR}/include" ) target_compile_definitions(HarmonyLinkLibStatic PRIVATE HARMONYLINKLIB_STATIC) +set_target_properties(HarmonyLinkLibStatic PROPERTIES OUTPUT_NAME "HarmonyLinkLibStatic_${COMPILER_NAME}") # Set output directories for all build types -foreach(TYPE IN ITEMS DEBUG RELEASE) - string(TOUPPER ${TYPE} TYPE_UPPER) - set_target_properties(HarmonyLinkLibShared PROPERTIES - RUNTIME_OUTPUT_DIRECTORY_${TYPE_UPPER} "${CMAKE_BINARY_DIR}/bin/${TYPE}/HarmonyLinkLib" - LIBRARY_OUTPUT_DIRECTORY_${TYPE_UPPER} "${CMAKE_BINARY_DIR}/lib/${TYPE}/HarmonyLinkLib" - ARCHIVE_OUTPUT_DIRECTORY_${TYPE_UPPER} "${CMAKE_BINARY_DIR}/archive/${TYPE}/HarmonyLinkLib" - ) - set_target_properties(HarmonyLinkLibStatic PROPERTIES - ARCHIVE_OUTPUT_DIRECTORY_${TYPE_UPPER} "${CMAKE_BINARY_DIR}/archive/${TYPE}/HarmonyLinkLibStatic" - ) -endforeach() +#foreach(TYPE IN ITEMS DEBUG RELEASE) +# string(TOUPPER ${TYPE} TYPE_UPPER) +# set_target_properties(HarmonyLinkLibShared PROPERTIES +# RUNTIME_OUTPUT_DIRECTORY_${TYPE_UPPER} "${CMAKE_BINARY_DIR}/bin/${TYPE}/HarmonyLinkLib" +# LIBRARY_OUTPUT_DIRECTORY_${TYPE_UPPER} "${CMAKE_BINARY_DIR}/lib/${TYPE}/HarmonyLinkLib" +# ARCHIVE_OUTPUT_DIRECTORY_${TYPE_UPPER} "${CMAKE_BINARY_DIR}/archive/${TYPE}/HarmonyLinkLib" +# ) +# set_target_properties(HarmonyLinkLibStatic PROPERTIES +# ARCHIVE_OUTPUT_DIRECTORY_${TYPE_UPPER} "${CMAKE_BINARY_DIR}/archive/${TYPE}/HarmonyLinkLibStatic" +# ) +#endforeach() -# Link fmt library to both shared and static libraries -target_link_libraries(HarmonyLinkLibShared PRIVATE fmt::fmt) -target_link_libraries(HarmonyLinkLibStatic PRIVATE fmt::fmt) +# Link fmt to HarmonyLinkLib +target_link_libraries(HarmonyLinkLibStatic PRIVATE fmt::fmt-header-only) +target_link_libraries(HarmonyLinkLibShared PRIVATE fmt::fmt-header-only) + +# Link ghc to HarmonyLinkLib +target_link_libraries(HarmonyLinkLibStatic PRIVATE ghc_filesystem) +target_link_libraries(HarmonyLinkLibShared PRIVATE ghc_filesystem) + +# Determine the compiler and set appropriate flags for libc++ +if (UNIX AND CMAKE_CXX_COMPILER_ID MATCHES "Clang") + # Use libc++ instead of libstdc++ with Clang + target_compile_options(HarmonyLinkLibStatic PRIVATE -stdlib=libc++) + target_compile_options(HarmonyLinkLibShared PRIVATE -stdlib=libc++) + target_link_options(HarmonyLinkLibStatic PRIVATE -stdlib=libc++) + target_link_options(HarmonyLinkLibShared PRIVATE -stdlib=libc++) + + # Link against the libc++ library and the filesystem library + target_link_libraries(HarmonyLinkLibStatic PRIVATE c++ c++abi c++experimental) + target_link_libraries(HarmonyLinkLibShared PRIVATE c++ c++abi c++experimental) +elseif (UNIX AND CMAKE_CXX_COMPILER_ID MATCHES "GNU") + # Use libstdc++ with GCC + target_link_options(HarmonyLinkLibStatic PRIVATE -static-libgcc -static-libstdc++) + target_link_options(HarmonyLinkLibShared PRIVATE -static-libgcc -static-libstdc++) + + # Link against the libstdc++ filesystem library if necessary + #target_link_libraries(HarmonyLinkLibStatic PRIVATE stdc++fs) + #target_link_libraries(HarmonyLinkLibShared PRIVATE stdc++fs) +endif() diff --git a/HarmonyLinkLib/include/Core.h b/HarmonyLinkLib/include/Core.h index 94a32d2..90babed 100644 --- a/HarmonyLinkLib/include/Core.h +++ b/HarmonyLinkLib/include/Core.h @@ -15,7 +15,7 @@ #pragma once // Use a preprocessor definition to switch between export and import declarations -#ifdef _WIN32 +#ifdef BUILD_WINDOWS #ifdef HARMONYLINKLIB_STATIC #define HARMONYLINKLIB_API #else @@ -26,5 +26,13 @@ #endif #endif #else - #define HARMONYLINKLIB_API + #ifdef HARMONYLINKLIB_SHARED + #ifdef __clang__ + #define HARMONYLINKLIB_API __attribute__((visibility("default"))) + #else + #define HARMONYLINKLIB_API + #endif + #else + #define HARMONYLINKLIB_API + #endif #endif diff --git a/HarmonyLinkLib/include/Enums/EDevice.h b/HarmonyLinkLib/include/Enums/EDevice.h index f49c7ec..c11919d 100644 --- a/HarmonyLinkLib/include/Enums/EDevice.h +++ b/HarmonyLinkLib/include/Enums/EDevice.h @@ -14,6 +14,9 @@ #pragma once +// Undefine the LINUX macro to avoid conflicts with the enum definition. +#undef LINUX + #include // Enum class for representing different types of devices diff --git a/HarmonyLinkLib/include/HarmonyLinkLib.h b/HarmonyLinkLib/include/HarmonyLinkLib.h index d6575a5..0298e2d 100644 --- a/HarmonyLinkLib/include/HarmonyLinkLib.h +++ b/HarmonyLinkLib/include/HarmonyLinkLib.h @@ -44,17 +44,19 @@ class IPlatformUtilities; namespace HarmonyLinkLib { - extern "C" HARMONYLINKLIB_API bool get_is_wine(); + HARMONYLINKLIB_API bool HL_Init(); - extern "C" HARMONYLINKLIB_API bool get_is_linux(); + HARMONYLINKLIB_API bool get_is_wine(); - extern "C" HARMONYLINKLIB_API bool get_is_docked(); + HARMONYLINKLIB_API bool get_is_linux(); - extern "C" HARMONYLINKLIB_API FCPUInfo* get_cpu_info(); + HARMONYLINKLIB_API bool get_is_docked(); - extern "C" HARMONYLINKLIB_API FDevice* get_device_info(); + HARMONYLINKLIB_API FCPUInfo* get_cpu_info(); - extern "C" HARMONYLINKLIB_API FOSVerInfo* get_os_version(); + HARMONYLINKLIB_API FDevice* get_device_info(); + + HARMONYLINKLIB_API FOSVerInfo* get_os_version(); - extern "C" HARMONYLINKLIB_API FBattery* get_battery_status(); + HARMONYLINKLIB_API FBattery* get_battery_status(); } diff --git a/HarmonyLinkLib/src/HarmonyLinkLib.cpp b/HarmonyLinkLib/src/HarmonyLinkLib.cpp index 91ccc2c..f57feac 100644 --- a/HarmonyLinkLib/src/HarmonyLinkLib.cpp +++ b/HarmonyLinkLib/src/HarmonyLinkLib.cpp @@ -16,10 +16,19 @@ #include #include "Platform/IPlatformUtilities.h" +#include "Version.h" namespace HarmonyLinkLib { - std::shared_ptr PlatformUtilities = IPlatformUtilities::GetInstance(); + std::shared_ptr PlatformUtilities = nullptr; + + bool HL_Init() + { + std::wcout << "HarmonyLink V" << version::ToString().c_str() << " Copyright (C) 2023 Jordon Brooks\n"; + PlatformUtilities = IPlatformUtilities::GetInstance(); + + return PlatformUtilities != nullptr; + } bool get_is_wine() { @@ -92,8 +101,6 @@ namespace HarmonyLinkLib FOSVerInfo* get_os_version() { - - if (!PlatformUtilities) { std::wcout << "Failed to get platform utilities!\n"; diff --git a/HarmonyLinkLib/src/Platform/IPlatformUtilities.cpp b/HarmonyLinkLib/src/Platform/IPlatformUtilities.cpp index 735eeab..555cc10 100644 --- a/HarmonyLinkLib/src/Platform/IPlatformUtilities.cpp +++ b/HarmonyLinkLib/src/Platform/IPlatformUtilities.cpp @@ -49,7 +49,7 @@ namespace HarmonyLinkLib INSTANCE = std::make_shared(); // ... other platform checks #else - std::wcout << "Platform is not supported.\n" + std::wcout << "Platform is not supported.\n"; #endif } diff --git a/HarmonyLinkLib/src/Platform/WineUtilities.cpp b/HarmonyLinkLib/src/Platform/WineUtilities.cpp index efe48a3..fca7352 100644 --- a/HarmonyLinkLib/src/Platform/WineUtilities.cpp +++ b/HarmonyLinkLib/src/Platform/WineUtilities.cpp @@ -18,12 +18,14 @@ #include #include #include -#include +#include #ifdef BUILD_WINDOWS #include #endif +namespace fs = ghc::filesystem; + namespace HarmonyLinkLib { bool force_detect_wine = false; @@ -38,7 +40,7 @@ namespace HarmonyLinkLib FBattery result = {}; for (int i = 0; i <= 9; ++i) { - if (std::string bat_path = append + "/sys/class/power_supply/BAT" + std::to_string(i); std::filesystem::exists(bat_path)) { + if (std::string bat_path = append + "/sys/class/power_supply/BAT" + std::to_string(i); fs::exists(bat_path)) { result.has_battery = true; std::ifstream status_file(bat_path + "/status"); diff --git a/HarmonyLinkLib/src/dllmain.cpp b/HarmonyLinkLib/src/dllmain.cpp deleted file mode 100644 index 5e6df48..0000000 --- a/HarmonyLinkLib/src/dllmain.cpp +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright (c) 2024 Jordon Brooks -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 - -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include -#include "Version.h" - -namespace HarmonyLinkLib -{ - void HarmonyLinkInit() - { - std::wcout << "HarmonyLink V" << version::ToString().c_str() << " Copyright (C) 2023 Jordon Brooks\n"; - } -} - - -#if BUILD_WINDOWS -#include - -// Standard DLL entry point -BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) { - switch (fdwReason) { - case DLL_PROCESS_ATTACH: - // Code to run when the DLL is loaded - HarmonyLinkLib::HarmonyLinkInit(); - break; - case DLL_THREAD_ATTACH: - // Code to run when a thread is created during the DLL's lifetime - case DLL_THREAD_DETACH: - // Code to run when a thread ends normally. - case DLL_PROCESS_DETACH: - // Code to run when the DLL is unloaded - default: - break; - } - return TRUE; // Successful DLL_PROCESS_ATTACH. -} -#endif - -#if BUILD_UNIX -__attribute__((constructor)) -static void onLibraryLoad() { - // Code to run when the library is loaded - HarmonyLinkLib::HarmonyLinkInit(); -} - -__attribute__((destructor)) -static void onLibraryUnload() { - // Code to run when the library is unloaded -} -#endif diff --git a/HarmonyLinkTest/src/main.cpp b/HarmonyLinkTest/src/main.cpp index e9eaf87..d4d2d29 100644 --- a/HarmonyLinkTest/src/main.cpp +++ b/HarmonyLinkTest/src/main.cpp @@ -85,10 +85,18 @@ void checkForQuit() { int main() { - std::cout << "Hello, World!" << '\n'; + std::cout << "Hello, World!\n"; std::thread inputThread(checkForQuit); + if (!HarmonyLinkLib::HL_Init()) + { + std::cout << "Failed to init HarmonyLinkLib\n"; + return 1; + } + + std::cout << "HarmonyLinkLib successfully initialised!\n"; + const bool isWine = HarmonyLinkLib::get_is_wine(); const char* test = isWine ? "is" : "isn't"; diff --git a/README.md b/README.md index 81a55f2..f8a5b5e 100644 --- a/README.md +++ b/README.md @@ -61,22 +61,22 @@ As you can see, Even though it's running on Proton, we can still detect the unde Integrate HarmonyLink 2.0 into your game project with ease: -1. Download the latest version of HarmonyLink 2.0 from the [releases page](https://github.com/Jordonbc/HarmonyLink/releases/latest). +1. Download the latest version of HarmonyLink 2.0 from the [releases page](https://git.bbgames.dev/jordon/HarmonyLink/releases/latest). 2. Add the HarmonyLink DLL to your project according to your development environment's specifications. 3. Utilize the provided API to access device-specific metrics and enhance your game's performance on handheld devices. -Refer to the [integration documentation](https://github.com/Jordonbc/HarmonyLink/wiki/Integration-Guide) for detailed instructions. +Refer to the [integration documentation](https://git.bbgames.dev/jordon/HarmonyLink/wiki) for detailed instructions. ### Unreal Engine 5 Plugin For developers leveraging Unreal Engine 5.3 or newer*, HarmonyLink 2.0 is readily accessible as a plugin: -1. Clone or download the HarmonyLink UE5 Plugin from the [Unreal Engine Plugin repository](https://github.com/Jordonbc/HarmonyLinkUE). +1. Clone or download the HarmonyLink UE5 Plugin from the [Unreal Engine Plugin repository](https://git.bbgames.dev/jordon/HarmonyLinkUE). 2. Place the HarmonyLink plugin folder into the `Plugins` directory of your Unreal Engine 5 project. 3. Enable the HarmonyLink plugin from the Edit > Plugins menu within Unreal Engine 5. 4. Access HarmonyLink functionalities via Blueprints or C++ within your project. -For a step-by-step guide, visit the [Unreal Engine 5 Plugin instructions](https://github.com/Jordonbc/HarmonyLinkUE/wiki/Integration-Guide) on our wiki. +For a step-by-step guide, visit the [Unreal Engine 5 Plugin instructions](https://git.bbgames.dev/jordon/HarmonyLinkUE/wiki) on our wiki. *With potential backward compatibility, not verified. @@ -91,7 +91,7 @@ If you prefer to build HarmonyLink 2.0 from the source code, follow these steps: 5. Compile the code by running `cmake --build build --config Release`. 6. The built DLL will be located in the `build/bin/HarmonyLinkLib` directory. -For additional building options and troubleshooting, refer to the [building from source documentation](https://github.com/Jordonbc/HarmonyLink/wiki/Building-From-Source). +For additional building options and troubleshooting, refer to the [building from source documentation](https://git.bbgames.dev/jordon/HarmonyLink/wiki). ## How It Works