From 6b90c9f76a3402614c259a699ea18ac51425979e Mon Sep 17 00:00:00 2001 From: Jordon Brooks Date: Mon, 27 May 2024 13:18:50 +0100 Subject: [PATCH] More work --- .gitignore | 3 +- CMakeLists.txt | 3 +- HarmonyLinkLib/src/HarmonyLinkLib.c | 28 --- HarmonyLinkLib/src/dllmain.c | 0 HarmonyLinkTest/CMakeLists.txt | 10 +- HarmonyLinkTest_CPP/CMakeLists.txt | 58 ++++++ HarmonyLinkTest_CPP/src/main.cpp | 170 ++++++++++++++++++ .../CMakeLists.txt | 33 ++-- .../Resources/Version.rc.in | 0 .../include/Core.h | 10 +- .../include/Enums/Device.h | 27 ++- LibHarmonyLink/include/Enums/Platform.h | 46 +++++ .../include/Enums/SteamDeck.h | 25 ++- .../include/HarmonyLinkLib.h | 12 +- .../include/Structs/Battery.h | 17 +- .../include/Structs/CPUInfo.h | 25 ++- LibHarmonyLink/include/Structs/Device.h | 47 +++++ LibHarmonyLink/include/Structs/OSInfo.h | 49 +++++ .../include/Structs/StringArray.h | 26 ++- .../include/Utilities.h | 12 +- .../include/Version.h | 26 ++- .../include/Version.h.in | 10 +- .../src/HarmonyLinkLib.c | 18 +- .../src/Structs/Battery.c | 17 ++ .../src/Structs/CPUInfo.c | 7 +- LibHarmonyLink/src/Structs/Device.c | 58 ++++++ LibHarmonyLink/src/Structs/OSInfo.c | 40 +++++ .../src/Structs/StringArray.c | 4 + .../src/Utilities.c | 19 +- .../src/Version.c | 19 +- 30 files changed, 710 insertions(+), 109 deletions(-) delete mode 100644 HarmonyLinkLib/src/HarmonyLinkLib.c delete mode 100644 HarmonyLinkLib/src/dllmain.c create mode 100644 HarmonyLinkTest_CPP/CMakeLists.txt create mode 100644 HarmonyLinkTest_CPP/src/main.cpp rename {HarmonyLinkLib => LibHarmonyLink}/CMakeLists.txt (83%) rename {HarmonyLinkLib => LibHarmonyLink}/Resources/Version.rc.in (100%) rename {HarmonyLinkLib => LibHarmonyLink}/include/Core.h (77%) rename {HarmonyLinkLib => LibHarmonyLink}/include/Enums/Device.h (65%) create mode 100644 LibHarmonyLink/include/Enums/Platform.h rename {HarmonyLinkLib => LibHarmonyLink}/include/Enums/SteamDeck.h (62%) rename {HarmonyLinkLib => LibHarmonyLink}/include/HarmonyLinkLib.h (81%) rename {HarmonyLinkLib => LibHarmonyLink}/include/Structs/Battery.h (71%) rename {HarmonyLinkLib => LibHarmonyLink}/include/Structs/CPUInfo.h (62%) create mode 100644 LibHarmonyLink/include/Structs/Device.h create mode 100644 LibHarmonyLink/include/Structs/OSInfo.h rename {HarmonyLinkLib => LibHarmonyLink}/include/Structs/StringArray.h (62%) rename {HarmonyLinkLib => LibHarmonyLink}/include/Utilities.h (82%) rename {HarmonyLinkLib => LibHarmonyLink}/include/Version.h (62%) rename {HarmonyLinkLib => LibHarmonyLink}/include/Version.h.in (69%) rename HarmonyLinkLib/include/Enums/Platform.h => LibHarmonyLink/src/HarmonyLinkLib.c (75%) rename {HarmonyLinkLib => LibHarmonyLink}/src/Structs/Battery.c (65%) rename {HarmonyLinkLib => LibHarmonyLink}/src/Structs/CPUInfo.c (94%) create mode 100644 LibHarmonyLink/src/Structs/Device.c create mode 100644 LibHarmonyLink/src/Structs/OSInfo.c rename {HarmonyLinkLib => LibHarmonyLink}/src/Structs/StringArray.c (97%) rename {HarmonyLinkLib => LibHarmonyLink}/src/Utilities.c (71%) rename {HarmonyLinkLib => LibHarmonyLink}/src/Version.c (60%) diff --git a/.gitignore b/.gitignore index 2e489f4..81e8788 100644 --- a/.gitignore +++ b/.gitignore @@ -15,8 +15,9 @@ build/** !Images/* !.github/** -!HarmonyLinkLib/** +!LibHarmonyLink/** !HarmonyLinkTest/** +!HarmonyLinkTest_CPP/** # Blacklist specific build directories linuxbuild/ diff --git a/CMakeLists.txt b/CMakeLists.txt index 02296e9..3a0e4c8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,8 +53,9 @@ endforeach() # Add the library and executable directories -add_subdirectory(HarmonyLinkLib) +add_subdirectory(LibHarmonyLink) add_subdirectory(HarmonyLinkTest) +add_subdirectory(HarmonyLinkTest_CPP) # Add Google Test as a subdirectory #add_subdirectory(ThirdParty/googletest) diff --git a/HarmonyLinkLib/src/HarmonyLinkLib.c b/HarmonyLinkLib/src/HarmonyLinkLib.c deleted file mode 100644 index 9d1f950..0000000 --- a/HarmonyLinkLib/src/HarmonyLinkLib.c +++ /dev/null @@ -1,28 +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 "HarmonyLinkLib.h" - -#include -#include "Version.h" - -bool HarmonyLink_Init(void) -{ - wprintf(L"HarmonyLink V%hs Copyright (C) 2023 Jordon Brooks\n", get_version_string()); - wprintf(L"Build Timestamp: %hs\n", get_version_build_timestamp()); - wprintf(L"Git Branch: %hs\n", get_git_branch()); - wprintf(L"Git Commit Timestamp: %hs\n", get_git_commit_timestamp()); - wprintf(L"Build type: %ls\n", get_is_debug() ? L"True" : L"False"); - return 1; -} diff --git a/HarmonyLinkLib/src/dllmain.c b/HarmonyLinkLib/src/dllmain.c deleted file mode 100644 index e69de29..0000000 diff --git a/HarmonyLinkTest/CMakeLists.txt b/HarmonyLinkTest/CMakeLists.txt index 31dd770..a821500 100644 --- a/HarmonyLinkTest/CMakeLists.txt +++ b/HarmonyLinkTest/CMakeLists.txt @@ -24,13 +24,13 @@ file(GLOB_RECURSE TEST_HEADERS "src/*.h" "src/*.hpp") # Add executable for static library add_executable(HarmonyLinkTestStatic ${TEST_SOURCES} ${TEST_HEADERS}) -target_link_libraries(HarmonyLinkTestStatic PRIVATE HarmonyLinkLibStatic) -target_compile_definitions(HarmonyLinkTestStatic PRIVATE HARMONYLINKLIB_STATIC) +target_link_libraries(HarmonyLinkTestStatic PRIVATE LibHarmonyLinkStatic) +target_compile_definitions(HarmonyLinkTestStatic PRIVATE HARMONYLINK_STATIC) # Add executable for shared library add_executable(HarmonyLinkTestShared ${TEST_SOURCES} ${TEST_HEADERS}) -target_link_libraries(HarmonyLinkTestShared PRIVATE HarmonyLinkLibShared) -target_compile_definitions(HarmonyLinkTestShared PRIVATE HARMONYLINKLIB_SHARED) +target_link_libraries(HarmonyLinkTestShared PRIVATE LibHarmonyLinkShared) +target_compile_definitions(HarmonyLinkTestShared PRIVATE HARMONYLINK_SHARED) # Set output directories for all build types foreach(TYPE IN ITEMS DEBUG RELEASE) @@ -54,5 +54,5 @@ endforeach() # Copy the DLL to the executable directory after building the shared test executable add_custom_command(TARGET HarmonyLinkTestShared POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different - "$" + "$" "$") diff --git a/HarmonyLinkTest_CPP/CMakeLists.txt b/HarmonyLinkTest_CPP/CMakeLists.txt new file mode 100644 index 0000000..9c18edd --- /dev/null +++ b/HarmonyLinkTest_CPP/CMakeLists.txt @@ -0,0 +1,58 @@ +# 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. + +cmake_minimum_required(VERSION 3.22.1) +project(HarmonyLinkTest) + +# Specify the C++ standard +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED True) + +# Automatically add all .cpp and .h/.hpp files in the src directory +file(GLOB_RECURSE TEST_SOURCES "src/*.cpp") +file(GLOB_RECURSE TEST_HEADERS "src/*.h" "src/*.hpp") + +# Add executable for static library +add_executable(HarmonyLinkTestStatic_CPP ${TEST_SOURCES} ${TEST_HEADERS}) +target_link_libraries(HarmonyLinkTestStatic_CPP PRIVATE LibHarmonyLinkStatic) +target_compile_definitions(HarmonyLinkTestStatic_CPP PRIVATE HARMONYLINK_STATIC) + +# Add executable for shared library +add_executable(HarmonyLinkTestShared_CPP ${TEST_SOURCES} ${TEST_HEADERS}) +target_link_libraries(HarmonyLinkTestShared_CPP PRIVATE LibHarmonyLinkShared) +target_compile_definitions(HarmonyLinkTestShared_CPP PRIVATE HARMONYLINK_SHARED) + +# Set output directories for all build types +foreach(TYPE IN ITEMS DEBUG RELEASE) + string(TOUPPER ${TYPE} TYPE_UPPER) + + # Static test executable properties + set_target_properties(HarmonyLinkTestStatic_CPP PROPERTIES + RUNTIME_OUTPUT_DIRECTORY_${TYPE_UPPER} "${CMAKE_BINARY_DIR}/bin/${TYPE}/HarmonyLinkTestStatic_CPP" + LIBRARY_OUTPUT_DIRECTORY_${TYPE_UPPER} "${CMAKE_BINARY_DIR}/lib/${TYPE}/HarmonyLinkTestStatic_CPP" + ARCHIVE_OUTPUT_DIRECTORY_${TYPE_UPPER} "${CMAKE_BINARY_DIR}/archive/${TYPE}/HarmonyLinkTestStatic_CPP" + ) + + # Shared test executable properties + set_target_properties(HarmonyLinkTestShared_CPP PROPERTIES + RUNTIME_OUTPUT_DIRECTORY_${TYPE_UPPER} "${CMAKE_BINARY_DIR}/bin/${TYPE}/HarmonyLinkTestShared_CPP" + LIBRARY_OUTPUT_DIRECTORY_${TYPE_UPPER} "${CMAKE_BINARY_DIR}/lib/${TYPE}/HarmonyLinkTestShared_CPP" + ARCHIVE_OUTPUT_DIRECTORY_${TYPE_UPPER} "${CMAKE_BINARY_DIR}/archive/${TYPE}/HarmonyLinkTestShared_CPP" + ) +endforeach() + +# Copy the DLL to the executable directory after building the shared test executable +add_custom_command(TARGET HarmonyLinkTestShared_CPP POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different + "$" + "$") diff --git a/HarmonyLinkTest_CPP/src/main.cpp b/HarmonyLinkTest_CPP/src/main.cpp new file mode 100644 index 0000000..7d9a93f --- /dev/null +++ b/HarmonyLinkTest_CPP/src/main.cpp @@ -0,0 +1,170 @@ +// 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 +#include +#include + +#include "HarmonyLinkLib.h" + +// Include necessary headers for platform-specific functionality +#ifdef BUILD_WINDOWS +#include // For _kbhit() and _getch() +#include // For system("cls") +#else +#include // For read() +#include // For termios +#include // For getchar() +#include // For F_GETFL, F_SETFL and O_NONBLOCK +#endif + +std::atomic quitFlag(false); + +// Function to clear the screen cross-platform +void clearScreen() { +#ifdef BUILD_WINDOWS + system("cls"); +#else + std::cout << "\x1B[2J\x1B[H"; +#endif +} + + +// Function to check if 'q' or 'Q' is pressed in Windows +void checkForQuit() { + while (!quitFlag) { +#ifdef BUILD_WINDOWS + if (_kbhit()) { + const char c = static_cast(_getch()); + if (c == 'q' || c == 'Q') { + quitFlag = true; + break; + } + } +#else + struct termios oldt, newt; + int ch; + int oldf; + + tcgetattr(STDIN_FILENO, &oldt); + newt = oldt; + newt.c_lflag &= ~(ICANON | ECHO); + tcsetattr(STDIN_FILENO, TCSANOW, &newt); + oldf = fcntl(STDIN_FILENO, F_GETFL, 0); + fcntl(STDIN_FILENO, F_SETFL, oldf | O_NONBLOCK); + + ch = getchar(); + + tcsetattr(STDIN_FILENO, TCSANOW, &oldt); + fcntl(STDIN_FILENO, F_SETFL, oldf); + + if (ch != EOF) { + ungetc(ch, stdin); + if (ch == 'q' || ch == 'Q') { + quitFlag = true; + break; + } + } +#endif + // Checks for input every roughly 60 frames + std::this_thread::sleep_for(std::chrono::milliseconds(16)); + } +} + +int main() +{ + std::cout << "Hello, World!" << '\n'; + + std::thread inputThread(checkForQuit); + + if (!LibHarmonyLink::HarmonyLink_Init()) + { + printf("Failed to Initialize HarmonyLink!"); + } + + printf("HarmonyLink Initialized!"); + + std::this_thread::sleep_for(std::chrono::milliseconds(5000)); + + //const bool isWine = LibHarmonyLink::get_is_wine(); + //const char* test = isWine ? "is" : "isn't"; + + //const HarmonyLinkLib::FOSVerInfo* os_info = HarmonyLinkLib::get_os_version(); + + //const HarmonyLinkLib::FDevice* device_info = HarmonyLinkLib::get_device_info(); + + //const HarmonyLinkLib::FCPUInfo* cpu_info = HarmonyLinkLib::get_cpu_info(); + + // This loop is to test how stable & expensive these functions are + while (!quitFlag) + { + // Clear the screen + clearScreen(); + + //std::wcout << "This program " << test << " running under wine.\n"; + + //if (cpu_info) + //{ + // cpu_info->print(); + //} + + //if (os_info) + //{ + // os_info->print(); + //} + + //if (device_info) + //{ + // wprintf(L"Is SteamDeck: %s\n", device_info->device == HarmonyLinkLib::EDevice::STEAM_DECK ? L"true" : L"false"); + //} + + // we can't do this before the loop because we need updated values + //if (const HarmonyLinkLib::FBattery* battery = HarmonyLinkLib::get_battery_status()) + //{ + // battery->print(); + // battery->free(); + //} + + //const bool is_docked = HarmonyLinkLib::get_is_docked(); + + //const char* dock_check_string = is_docked ? "is" : "isn't"; + + //wprintf(L"Device %hs docked\n", dock_check_string); + + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + } + + if (inputThread.joinable()) + { + inputThread.join(); + } + + //if (os_info) + //{ + // os_info->free(); + //} + + //if (device_info) + //{ + // device_info->free(); + //} + + //if (cpu_info) + //{ + // cpu_info->free(); + //} + + return 0; +} diff --git a/HarmonyLinkLib/CMakeLists.txt b/LibHarmonyLink/CMakeLists.txt similarity index 83% rename from HarmonyLinkLib/CMakeLists.txt rename to LibHarmonyLink/CMakeLists.txt index b794608..b250121 100644 --- a/HarmonyLinkLib/CMakeLists.txt +++ b/LibHarmonyLink/CMakeLists.txt @@ -12,7 +12,7 @@ # limitations under the License. cmake_minimum_required(VERSION 3.10) -project(HarmonyLinkLib VERSION 2.1.1) +project(LibHarmonyLink VERSION 2.1.1) # Specify the C++ standard set(CMAKE_C_STANDARD 11) @@ -42,9 +42,9 @@ configure_file(include/Version.h.in Version.generated.h) # Define metadata variables set(FILE_DESCRIPTION "Enhances handheld gaming with intelligent hardware recognition, dynamic adaptability, and robust API access for Windows and Linux, including Steam Deck and Wine support.") -set(INTERNAL_NAME "HarmonyLinkLib") -set(ORIGINAL_FILENAME "HarmonyLinkLib.dll") -set(PRODUCT_NAME "HarmonyLinkLib") +set(INTERNAL_NAME "LibHarmonyLink") +set(ORIGINAL_FILENAME "LibHarmonyLink.dll") +set(PRODUCT_NAME "LibHarmonyLink") set(COMMENTS "") # Configure version.rc file for shared library @@ -52,7 +52,6 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Resources/Version.rc.in ${CMAKE_CURRE # Explicitly list source files set(COMMON_SOURCES - src/dllmain.c src/HarmonyLinkLib.c src/Version.c src/Utilities.c @@ -60,6 +59,8 @@ set(COMMON_SOURCES src/Structs/Battery.c src/Structs/CPUInfo.c src/Structs/StringArray.c + src/Structs/Device.c + src/Structs/OSInfo.C ) # Explicitly list include files @@ -76,6 +77,8 @@ set(COMMON_INCLUDES include/Structs/Battery.h include/Structs/CPUInfo.h include/Structs/StringArray.h + include/Structs/Device.h + include/Structs/OSInfo.h ) set(WINDOWS_SOURCES @@ -117,40 +120,36 @@ elseif(UNIX) endif() # Create the shared library -add_library(HarmonyLinkLibShared SHARED ${LIB_SOURCES} ${SHARED_SOURCES}) -target_include_directories(HarmonyLinkLibShared +add_library(LibHarmonyLinkShared SHARED ${LIB_SOURCES} ${LIB_INCLUDES} ${SHARED_SOURCES}) +target_include_directories(LibHarmonyLinkShared PRIVATE "${PROJECT_SOURCE_DIR}/src" PUBLIC "${PROJECT_BINARY_DIR}" "${PROJECT_SOURCE_DIR}/include" ) -target_compile_definitions(HarmonyLinkLibShared PRIVATE HARMONYLINKLIB_SHARED) +target_compile_definitions(LibHarmonyLinkShared PRIVATE HARMONYLINK_SHARED) # Create the static library -add_library(HarmonyLinkLibStatic STATIC ${LIB_SOURCES}) -target_include_directories(HarmonyLinkLibStatic +add_library(LibHarmonyLinkStatic STATIC ${LIB_SOURCES} ${LIB_INCLUDES}) +target_include_directories(LibHarmonyLinkStatic PRIVATE "${PROJECT_SOURCE_DIR}/src" PUBLIC "${PROJECT_BINARY_DIR}" "${PROJECT_SOURCE_DIR}/include" ) -target_compile_definitions(HarmonyLinkLibStatic PRIVATE HARMONYLINKLIB_STATIC) +target_compile_definitions(LibHarmonyLinkStatic PRIVATE HARMONYLINK_STATIC) # Set output directories for all build types foreach(TYPE IN ITEMS DEBUG RELEASE) string(TOUPPER ${TYPE} TYPE_UPPER) - set_target_properties(HarmonyLinkLibShared PROPERTIES + set_target_properties(LibHarmonyLinkShared 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 + set_target_properties(LibHarmonyLinkStatic PROPERTIES ARCHIVE_OUTPUT_DIRECTORY_${TYPE_UPPER} "${CMAKE_BINARY_DIR}/archive/${TYPE}/HarmonyLinkLibStatic" ) endforeach() - - -if (UNIX) -endif() diff --git a/HarmonyLinkLib/Resources/Version.rc.in b/LibHarmonyLink/Resources/Version.rc.in similarity index 100% rename from HarmonyLinkLib/Resources/Version.rc.in rename to LibHarmonyLink/Resources/Version.rc.in diff --git a/HarmonyLinkLib/include/Core.h b/LibHarmonyLink/include/Core.h similarity index 77% rename from HarmonyLinkLib/include/Core.h rename to LibHarmonyLink/include/Core.h index 94a32d2..49ea871 100644 --- a/HarmonyLinkLib/include/Core.h +++ b/LibHarmonyLink/include/Core.h @@ -16,13 +16,13 @@ // Use a preprocessor definition to switch between export and import declarations #ifdef _WIN32 - #ifdef HARMONYLINKLIB_STATIC - #define HARMONYLINKLIB_API + #ifdef HARMONYLINK_STATIC + #define HARMONYLINK_API #else - #ifdef HARMONYLINKLIB_SHARED - #define HARMONYLINKLIB_API __declspec(dllexport) + #ifdef HARMONYLINK_SHARED + #define HARMONYLINK_API __declspec(dllexport) #else - #define HARMONYLINKLIB_API __declspec(dllimport) + #define HARMONYLINK_API __declspec(dllimport) #endif #endif #else diff --git a/HarmonyLinkLib/include/Enums/Device.h b/LibHarmonyLink/include/Enums/Device.h similarity index 65% rename from HarmonyLinkLib/include/Enums/Device.h rename to LibHarmonyLink/include/Enums/Device.h index 8ee0946..66e749c 100644 --- a/HarmonyLinkLib/include/Enums/Device.h +++ b/LibHarmonyLink/include/Enums/Device.h @@ -14,18 +14,39 @@ #pragma once +#include "Core.h" + // Undefine the LINUX macro to avoid conflicts with the enum definition. #undef LINUX -typedef enum -{ +#ifdef __cplusplus +namespace LibHarmonyLink { +extern "C" { +#endif + +typedef enum { EDevice_UNKNOWN, EDevice_DESKTOP, EDevice_LAPTOP, EDevice_HANDHELD, - + EDevice_STEAM_DECK, // EDevice_ROG_ALLY // EDevice_AYONEO_SLIDE // etc... } EDevice; + +HARMONYLINK_API const char* Device_ToString(EDevice device) { + switch (device) { + case EDevice_DESKTOP: return "DESKTOP"; + case EDevice_LAPTOP: return "LAPTOP"; + case EDevice_HANDHELD: return "HANDHELD"; + case EDevice_STEAM_DECK: return "STEAM_DECK"; + default: return "UNKNOWN"; + } +} + +#ifdef __cplusplus +} +} +#endif diff --git a/LibHarmonyLink/include/Enums/Platform.h b/LibHarmonyLink/include/Enums/Platform.h new file mode 100644 index 0000000..247eff9 --- /dev/null +++ b/LibHarmonyLink/include/Enums/Platform.h @@ -0,0 +1,46 @@ +// 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. + +#pragma once + +#include "Core.h" + +#ifdef __cplusplus +namespace LibHarmonyLink { +extern "C" { +#endif + +typedef enum { + EPlatform_UNKNOWN, + EPlatform_WINDOWS, + EPlatform_LINUX, + EPlatform_MAC, + EPlatform_UNIX, +} EPlatform; + +// Helper functions to convert enums to strings (must be implemented somewhere in your code) +HARMONYLINK_API const char* Platform_ToString(EPlatform platform) { + switch (platform) { + case EPlatform_WINDOWS: return "WINDOWS"; + case EPlatform_LINUX: return "LINUX"; + case EPlatform_MAC: return "MAC"; + case EPlatform_UNIX: return "UNIX"; + default: return "UNKNOWN"; + } +} + +#ifdef __cplusplus +} +} +#endif diff --git a/HarmonyLinkLib/include/Enums/SteamDeck.h b/LibHarmonyLink/include/Enums/SteamDeck.h similarity index 62% rename from HarmonyLinkLib/include/Enums/SteamDeck.h rename to LibHarmonyLink/include/Enums/SteamDeck.h index 142504e..b6fe09e 100644 --- a/HarmonyLinkLib/include/Enums/SteamDeck.h +++ b/LibHarmonyLink/include/Enums/SteamDeck.h @@ -14,10 +14,31 @@ #pragma once -typedef enum -{ +#include "Core.h" + +#ifdef __cplusplus +namespace LibHarmonyLink { +extern "C" { +#endif + +typedef enum { ESteamDeck_NONE, // Device is not a steam deck ESteamDeck_UNKNOWN, // Device is a steam deck but model cannot be determined ESteamDeck_LCD, ESteamDeck_OLED, } ESteamDeck; + +HARMONYLINK_API const char* SteamDeck_ToString(ESteamDeck steam_deck_model) { + switch (steam_deck_model) { + case ESteamDeck_NONE: return "NONE"; + case ESteamDeck_LCD: return "STEAMDECK_LCD"; + case ESteamDeck_OLED: return "STEAMDECK_OLED"; + // Add other cases as needed + default: return "UNKNOWN"; + } +} + +#ifdef __cplusplus +} +} +#endif diff --git a/HarmonyLinkLib/include/HarmonyLinkLib.h b/LibHarmonyLink/include/HarmonyLinkLib.h similarity index 81% rename from HarmonyLinkLib/include/HarmonyLinkLib.h rename to LibHarmonyLink/include/HarmonyLinkLib.h index 9930ffd..a6a45ed 100644 --- a/HarmonyLinkLib/include/HarmonyLinkLib.h +++ b/LibHarmonyLink/include/HarmonyLinkLib.h @@ -17,4 +17,14 @@ #include #include "Core.h" -HARMONYLINKLIB_API bool HarmonyLink_Init(void); +#ifdef __cplusplus +namespace LibHarmonyLink { +extern "C" { +#endif + +HARMONYLINK_API bool HarmonyLink_Init(void); + +#ifdef __cplusplus +} +} +#endif diff --git a/HarmonyLinkLib/include/Structs/Battery.h b/LibHarmonyLink/include/Structs/Battery.h similarity index 71% rename from HarmonyLinkLib/include/Structs/Battery.h rename to LibHarmonyLink/include/Structs/Battery.h index af566e7..0fe6614 100644 --- a/HarmonyLinkLib/include/Structs/Battery.h +++ b/LibHarmonyLink/include/Structs/Battery.h @@ -18,14 +18,23 @@ #include "Core.h" -typedef struct -{ +#ifdef __cplusplus +namespace LibHarmonyLink { +extern "C" { +#endif + +typedef struct { bool has_battery; bool is_connected_to_ac; unsigned char battery_percent; } FBattery; -HARMONYLINKLIB_API FBattery* FBattery_Init(const FBattery* self); +HARMONYLINK_API FBattery* HL_FBattery_Init(bool has_battery, bool is_connected_to_ac, unsigned char battery_percent); -HARMONYLINKLIB_API void FBattery_print(const FBattery* self); +HARMONYLINK_API void HL_FBattery_print(const FBattery *self); + +#ifdef __cplusplus +} +} +#endif diff --git a/HarmonyLinkLib/include/Structs/CPUInfo.h b/LibHarmonyLink/include/Structs/CPUInfo.h similarity index 62% rename from HarmonyLinkLib/include/Structs/CPUInfo.h rename to LibHarmonyLink/include/Structs/CPUInfo.h index f9daddb..044adb9 100644 --- a/HarmonyLinkLib/include/Structs/CPUInfo.h +++ b/LibHarmonyLink/include/Structs/CPUInfo.h @@ -22,25 +22,36 @@ #include "Core.h" #include "Structs/StringArray.h" +#ifdef __cplusplus +namespace LibHarmonyLink { +extern "C" { +#endif + typedef struct { - char* VendorID; - char* Model_Name; + char *VendorID; + char *Model_Name; unsigned int Physical_Cores; unsigned int Logical_Cores; StringArray flagsInfo; } FCPUInfo; // Initialize FCPUInfo -FCPUInfo* FCPUInfo_Init(const char* vendorID, const char* modelName, unsigned int physicalCores, unsigned int logicalCores, size_t flagsCount); +FCPUInfo* FCPUInfo_Init(const char *vendorID, const char *modelName, unsigned int physicalCores, unsigned int logicalCores, + size_t flagsCount); // Print FlagsInfo -HARMONYLINKLIB_API void HL_FlagsInfo_Print(const FCPUInfo* cpuInfo); +HARMONYLINK_API void HL_FlagsInfo_Print(const FCPUInfo *cpuInfo); // Print FCPUInfo -HARMONYLINKLIB_API void HL_FCPUInfo_Print(const FCPUInfo* cpuInfo); +HARMONYLINK_API void HL_FCPUInfo_Print(const FCPUInfo *cpuInfo); // Free FCPUInfo -HARMONYLINKLIB_API void HL_FCPUInfo_Free(FCPUInfo* cpuInfo); +HARMONYLINK_API void HL_FCPUInfo_Free(FCPUInfo *cpuInfo); // Check if a flag exists in FlagsInfo -HARMONYLINKLIB_API bool HL_FlagsInfo_Contains(const FCPUInfo* cpuInfo, const char* flag); +HARMONYLINK_API bool HL_FlagsInfo_Contains(const FCPUInfo *cpuInfo, const char *flag); + +#ifdef __cplusplus +} +} +#endif diff --git a/LibHarmonyLink/include/Structs/Device.h b/LibHarmonyLink/include/Structs/Device.h new file mode 100644 index 0000000..546f936 --- /dev/null +++ b/LibHarmonyLink/include/Structs/Device.h @@ -0,0 +1,47 @@ +// 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. + +#pragma once + +#include "Core.h" +#include "Enums/Platform.h" +#include "Enums/Device.h" +#include "Enums/SteamDeck.h" + +#define DEFAULT_INITIAL_FLAGS_SIZE 4 + +#ifdef __cplusplus +namespace LibHarmonyLink { +extern "C" { +#endif + +typedef struct { + EPlatform platform; + EDevice device; + ESteamDeck steam_deck_model; +} FDevice; + +// Initialize FlagsInfo +FDevice* Device_Init(EPlatform platform, EDevice device, ESteamDeck steam_deck_model); + +// Print FlagsInfo +HARMONYLINK_API void HL_Device_Print(const FDevice* Device); + +// Free FlagsInfo +HARMONYLINK_API void HL_Device_Free(FDevice* Device); + +#ifdef __cplusplus +} +} +#endif diff --git a/LibHarmonyLink/include/Structs/OSInfo.h b/LibHarmonyLink/include/Structs/OSInfo.h new file mode 100644 index 0000000..e160a6a --- /dev/null +++ b/LibHarmonyLink/include/Structs/OSInfo.h @@ -0,0 +1,49 @@ +// 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. + +#pragma once + +#include +#include + +#include "Core.h" + +#ifdef __cplusplus +namespace LibHarmonyLink { +extern "C" { +#endif + +typedef struct { + char* name; + char* version; + unsigned int id; + char* version_id; + char* version_codename; + char* pretty_name; + char* variant_id; +} FOSVerInfo; + +// Initialize FCPUInfo +FOSVerInfo* FOSVerInfo_Init(char* name, char* version, unsigned int id, char* version_id, char* version_codename, char* pretty_name, char* variant_id); + +// Print FlagsInfo +HARMONYLINK_API void HL_FOSVerInfo_Print(const FOSVerInfo* OSVerInfo); + +// Free FCPUInfo +HARMONYLINK_API void HL_FOSVerInfo_Free(FOSVerInfo* OSVerInfo); + +#ifdef __cplusplus +} +} +#endif diff --git a/HarmonyLinkLib/include/Structs/StringArray.h b/LibHarmonyLink/include/Structs/StringArray.h similarity index 62% rename from HarmonyLinkLib/include/Structs/StringArray.h rename to LibHarmonyLink/include/Structs/StringArray.h index ff7b433..1b87569 100644 --- a/HarmonyLinkLib/include/Structs/StringArray.h +++ b/LibHarmonyLink/include/Structs/StringArray.h @@ -23,29 +23,39 @@ #define DEFAULT_INITIAL_FLAGS_SIZE 4 +#ifdef __cplusplus +namespace LibHarmonyLink { +extern "C" { +#endif + typedef struct { - char** data; // Array of strings (flags) + char **data; // Array of strings (flags) size_t FlagsCount; // Number of flags size_t AllocatedSize; // Number of allocated slots } StringArray; // Initialize FlagsInfo -void StringArray_Init(StringArray* flagsInfo, size_t overrideInitialSize); +void StringArray_Init(StringArray *flagsInfo, size_t overrideInitialSize); // Print FlagsInfo -HARMONYLINKLIB_API void HL_StringArray_Print(const StringArray* flagsInfo); +HARMONYLINK_API void HL_StringArray_Print(const StringArray *flagsInfo); // Free FlagsInfo -HARMONYLINKLIB_API void HL_StringArray_Free(StringArray* flagsInfo); +HARMONYLINK_API void HL_StringArray_Free(StringArray *flagsInfo); // Check if a flag exists in FlagsInfo -HARMONYLINKLIB_API bool HL_StringArray_Contains(const StringArray* flagsInfo, const char* flag); +HARMONYLINK_API bool HL_StringArray_Contains(const StringArray *flagsInfo, const char *flag); // Add a flag to FlagsInfo -void StringArray_AddFlag(StringArray* flagsInfo, const char* flag); +void StringArray_AddFlag(StringArray *flagsInfo, const char *flag); // Remove a flag from FlagsInfo by value -void StringArray_Remove(StringArray* flagsInfo, const char* flag); +void StringArray_Remove(StringArray *flagsInfo, const char *flag); // Resize FlagsInfo array -void StringArray_Resize(StringArray* flagsInfo, size_t newSize); +void StringArray_Resize(StringArray *flagsInfo, size_t newSize); + +#ifdef __cplusplus +} +} +#endif diff --git a/HarmonyLinkLib/include/Utilities.h b/LibHarmonyLink/include/Utilities.h similarity index 82% rename from HarmonyLinkLib/include/Utilities.h rename to LibHarmonyLink/include/Utilities.h index f50ad6a..4aa6856 100644 --- a/HarmonyLinkLib/include/Utilities.h +++ b/LibHarmonyLink/include/Utilities.h @@ -14,5 +14,15 @@ #include +#ifdef __cplusplus +namespace LibHarmonyLink { +extern "C" { +#endif + // Utility function to convert char* to wchar_t* -wchar_t* convertToWideChar(const char* str); \ No newline at end of file +wchar_t *convertToWideChar(const char *str); + +#ifdef __cplusplus +} +} +#endif \ No newline at end of file diff --git a/HarmonyLinkLib/include/Version.h b/LibHarmonyLink/include/Version.h similarity index 62% rename from HarmonyLinkLib/include/Version.h rename to LibHarmonyLink/include/Version.h index 74f6179..d238e47 100644 --- a/HarmonyLinkLib/include/Version.h +++ b/LibHarmonyLink/include/Version.h @@ -17,8 +17,24 @@ #include #include "Core.h" -HARMONYLINKLIB_API char* get_version_string(void); -HARMONYLINKLIB_API char* get_version_build_timestamp(void); -HARMONYLINKLIB_API char* get_git_branch(void); -HARMONYLINKLIB_API char* get_git_commit_timestamp(void); -HARMONYLINKLIB_API bool get_is_debug(void); +#ifdef __cplusplus +namespace LibHarmonyLink { +extern "C" { +#endif + +HARMONYLINK_API char* HL_version_get_string(void); + +HARMONYLINK_API char* HL_version_build_timestamp(void); + +HARMONYLINK_API char* HL_git_branch(void); + +HARMONYLINK_API char* HL_git_commit_timestamp(void); + +HARMONYLINK_API bool HL_is_debug(void); + +HARMONYLINK_API void HL_version_print(void); + +#ifdef __cplusplus +} +} +#endif diff --git a/HarmonyLinkLib/include/Version.h.in b/LibHarmonyLink/include/Version.h.in similarity index 69% rename from HarmonyLinkLib/include/Version.h.in rename to LibHarmonyLink/include/Version.h.in index 08881c5..9b03890 100644 --- a/HarmonyLinkLib/include/Version.h.in +++ b/LibHarmonyLink/include/Version.h.in @@ -15,11 +15,11 @@ // Version.h.in #pragma once -#define HARMONYLINK_VERSION_MAJOR @HarmonyLinkLib_VERSION_MAJOR@ -#define HARMONYLINK_VERSION_MINOR @HarmonyLinkLib_VERSION_MINOR@ -#define HARMONYLINK_VERSION_PATCH @HarmonyLinkLib_VERSION_PATCH@ -#define HARMONYLINK_VERSION_TWEAK @HarmonyLinkLib_VERSION_TWEAK@ -#define HARMONYLINK_VERSION "@HarmonyLinkLib_VERSION@" +#define HARMONYLINK_VERSION_MAJOR @LibHarmonyLink_VERSION_MAJOR@ +#define HARMONYLINK_VERSION_MINOR @LibHarmonyLink_VERSION_MINOR@ +#define HARMONYLINK_VERSION_PATCH @LibHarmonyLink_VERSION_PATCH@ +#define HARMONYLINK_VERSION_TWEAK @LibHarmonyLink_VERSION_TWEAK@ +#define HARMONYLINK_VERSION "@LibHarmonyLink_VERSION@" #define GIT_BRANCH_NAME "@GIT_BRANCH_NAME@" #define GIT_COMMIT_TIMESTAMP "@GIT_COMMIT_TIMESTAMP@" diff --git a/HarmonyLinkLib/include/Enums/Platform.h b/LibHarmonyLink/src/HarmonyLinkLib.c similarity index 75% rename from HarmonyLinkLib/include/Enums/Platform.h rename to LibHarmonyLink/src/HarmonyLinkLib.c index c077d8c..ab45b0a 100644 --- a/HarmonyLinkLib/include/Enums/Platform.h +++ b/LibHarmonyLink/src/HarmonyLinkLib.c @@ -1,4 +1,4 @@ -// Copyright (c) 2024 Jordon Brooks +// 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. @@ -12,13 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. -#pragma once +#include +#include "HarmonyLinkLib.h" -typedef enum +#include "Version.h" + +bool HarmonyLink_Init(void) { - EPlatform_UNKNOWN, - EPlatform_WINDOWS, - EPlatform_LINUX, - EPlatform_MAC, - EPlatform_UNIX, -} EPlatform; + HL_version_print(); + return 1; +} diff --git a/HarmonyLinkLib/src/Structs/Battery.c b/LibHarmonyLink/src/Structs/Battery.c similarity index 65% rename from HarmonyLinkLib/src/Structs/Battery.c rename to LibHarmonyLink/src/Structs/Battery.c index 020a0d7..dbd0bba 100644 --- a/HarmonyLinkLib/src/Structs/Battery.c +++ b/LibHarmonyLink/src/Structs/Battery.c @@ -15,6 +15,23 @@ #include "Structs/Battery.h" #include +#include +#include + +FBattery* HL_FBattery_Init(bool has_battery, bool is_connected_to_ac, unsigned char battery_percent) { + FBattery* battery = (FBattery*)malloc(sizeof(FBattery)); + + if (battery == NULL) { + fprintf(stderr, "Memory allocation failed for FCPUInfo.\n"); + exit(EXIT_FAILURE); + } + + battery->has_battery = has_battery; + battery->battery_percent = is_connected_to_ac; + battery->is_connected_to_ac = battery_percent; + + return battery; +} void FBattery_print(const FBattery* self) { diff --git a/HarmonyLinkLib/src/Structs/CPUInfo.c b/LibHarmonyLink/src/Structs/CPUInfo.c similarity index 94% rename from HarmonyLinkLib/src/Structs/CPUInfo.c rename to LibHarmonyLink/src/Structs/CPUInfo.c index 1c169e9..c88e999 100644 --- a/HarmonyLinkLib/src/Structs/CPUInfo.c +++ b/LibHarmonyLink/src/Structs/CPUInfo.c @@ -26,9 +26,14 @@ FCPUInfo* FCPUInfo_Init(const char *vendorID, const char *modelName, unsigned in fprintf(stderr, "Memory allocation failed for FCPUInfo.\n"); exit(EXIT_FAILURE); } - +#if defined(BUILD_WINDOWS) cpuInfo->VendorID = _strdup(vendorID); cpuInfo->Model_Name = _strdup(modelName); +#else + cpuInfo->VendorID = strdup(vendorID); + cpuInfo->Model_Name = strdup(modelName); +#endif + cpuInfo->Physical_Cores = physicalCores; cpuInfo->Logical_Cores = logicalCores; StringArray_Init(&cpuInfo->flagsInfo, flagsCount); diff --git a/LibHarmonyLink/src/Structs/Device.c b/LibHarmonyLink/src/Structs/Device.c new file mode 100644 index 0000000..082218b --- /dev/null +++ b/LibHarmonyLink/src/Structs/Device.c @@ -0,0 +1,58 @@ +// 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 "Structs/Device.h" +#include "Utilities.h" + +#include +#include + +FDevice* Device_Init(EPlatform platform, EDevice device, ESteamDeck steam_deck_model) { + FDevice* newDevice = (FDevice*)malloc(sizeof(FDevice)); + if (newDevice != NULL) { + newDevice->platform = platform; + newDevice->device = device; + newDevice->steam_deck_model = steam_deck_model; + } + return newDevice; +} + +void HL_Device_Print(const FDevice *Device) { + if (Device == NULL) { + wprintf(L"Device is NULL\n"); + return; + } + + // Assuming that EPlatform, EDevice, and ESteamDeck have corresponding string representations + // which should be implemented for a proper print function + + wchar_t* platformStr = convertToWideChar(Platform_ToString(Device->platform)); + wchar_t* deviceStr = convertToWideChar(Device_ToString(Device->device)); + wchar_t* steamDeckStr = convertToWideChar(SteamDeck_ToString(Device->steam_deck_model)); + + wprintf(L"Device Information:\n"); + wprintf(L"Platform: %ls\n", platformStr); + wprintf(L"Device: %ls\n", deviceStr); + wprintf(L"Steam Deck Model: %ls\n", steamDeckStr); + + free(platformStr); + free(deviceStr); + free(steamDeckStr); +} + +void HL_Device_Free(FDevice *Device) { + if (Device != NULL) { + free(Device); + } +} diff --git a/LibHarmonyLink/src/Structs/OSInfo.c b/LibHarmonyLink/src/Structs/OSInfo.c new file mode 100644 index 0000000..5116ba4 --- /dev/null +++ b/LibHarmonyLink/src/Structs/OSInfo.c @@ -0,0 +1,40 @@ +// 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 "Structs/OSInfo.h" + +FOSVerInfo* FOSVerInfo_Init(char* name, char* version, unsigned int id, char* version_id, char* version_codename, char* pretty_name, + char* variant_id) { + FOSVerInfo* OSVerInfo = (FOSVerInfo*)malloc(sizeof(FOSVerInfo)); + + if (OSVerInfo == NULL) { + fprintf(stderr, "Memory allocation failed for FOSVerInfo.\n"); + exit(EXIT_FAILURE); + } + + OSVerInfo->name = name; + OSVerInfo->version = version; + OSVerInfo->id = id; + OSVerInfo->variant_id = version_id; + OSVerInfo->version_codename = version_codename; + OSVerInfo->pretty_name = pretty_name; + OSVerInfo->version_id = variant_id; + + return OSVerInfo; +} + +void HL_FOSVerInfo_Free(FOSVerInfo *OSVerInfo) { + +} diff --git a/HarmonyLinkLib/src/Structs/StringArray.c b/LibHarmonyLink/src/Structs/StringArray.c similarity index 97% rename from HarmonyLinkLib/src/Structs/StringArray.c rename to LibHarmonyLink/src/Structs/StringArray.c index aa2187f..5165193 100644 --- a/HarmonyLinkLib/src/Structs/StringArray.c +++ b/LibHarmonyLink/src/Structs/StringArray.c @@ -39,7 +39,11 @@ void StringArray_AddFlag(StringArray *flagsInfo, const char *flag) { if (flagsInfo->FlagsCount >= flagsInfo->AllocatedSize) { StringArray_Resize(flagsInfo, flagsInfo->AllocatedSize * 2); } +#if defined(BUILD_WINDOWS) flagsInfo->data[flagsInfo->FlagsCount] = _strdup(flag); +#else + flagsInfo->data[flagsInfo->FlagsCount] = strdup(flag); +#endif flagsInfo->FlagsCount++; } diff --git a/HarmonyLinkLib/src/Utilities.c b/LibHarmonyLink/src/Utilities.c similarity index 71% rename from HarmonyLinkLib/src/Utilities.c rename to LibHarmonyLink/src/Utilities.c index 25d0bf7..6aa8b51 100644 --- a/HarmonyLinkLib/src/Utilities.c +++ b/LibHarmonyLink/src/Utilities.c @@ -17,11 +17,28 @@ wchar_t* convertToWideChar(const char* str) { size_t len = 0; - mbstowcs_s(&len, NULL, 0, str, 0); // Get the length of the wide string (including null terminator) + +#if defined(BUILD_WINDOWS) + // Use mbstowcs_s on Windows + mbstowcs_s(&len, NULL, 0, str, 0); +#else + // Use mbstowcs on Linux + len = mbstowcs(NULL, str, 0) + 1; +#endif + + // Allocate memory for the wide string wchar_t* wstr = (wchar_t*)malloc(len * sizeof(wchar_t)); if (wstr == NULL) { return NULL; // Handle memory allocation failure } + +#if defined(BUILD_WINDOWS) + // Use mbstowcs_s on Windows mbstowcs_s(&len, wstr, len, str, len - 1); +#else + // Use mbstowcs on Linux + mbstowcs(wstr, str, len); +#endif + return wstr; } \ No newline at end of file diff --git a/HarmonyLinkLib/src/Version.c b/LibHarmonyLink/src/Version.c similarity index 60% rename from HarmonyLinkLib/src/Version.c rename to LibHarmonyLink/src/Version.c index b844b0c..fd34e33 100644 --- a/HarmonyLinkLib/src/Version.c +++ b/LibHarmonyLink/src/Version.c @@ -15,28 +15,29 @@ #include "Version.h" #include +#include -char* get_version_string(void) +char* HL_version_get_string(void) { return HARMONYLINK_VERSION; } -char* get_version_build_timestamp(void) +char* HL_version_build_timestamp(void) { return __TIMESTAMP__; } -char* get_git_branch(void) +char* HL_git_branch(void) { return GIT_BRANCH_NAME; } -char* get_git_commit_timestamp(void) +char* HL_git_commit_timestamp(void) { return GIT_COMMIT_TIMESTAMP; } -bool get_is_debug(void) +bool HL_is_debug(void) { #ifdef DEBUG_MODE return true; @@ -44,3 +45,11 @@ bool get_is_debug(void) return false; #endif } + +void HL_version_print(void) { + wprintf(L"HarmonyLink V%hs Copyright (C) 2023 Jordon Brooks\n", HL_version_get_string()); + wprintf(L"Build Timestamp: %hs\n", HL_version_build_timestamp()); + wprintf(L"Git Branch: %hs\n", HL_git_branch()); + wprintf(L"Git Commit Timestamp: %hs\n", HL_git_commit_timestamp()); + wprintf(L"Build type: %ls\n", HL_is_debug() ? L"True" : L"False"); +}