diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..8336a63 --- /dev/null +++ b/.clang-format @@ -0,0 +1 @@ +BasedOnStyle: "llvm" \ No newline at end of file diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000..b9c7ff0 --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,3 @@ +Checks: 'llvm-*' +ExtraArgs: + - '-Iout/x64-Debug/vcpkg_installed/x64-windows/include' diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..0d169d8 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,73 @@ +name: CinnamonToast Tests + +on: + push: + branches: + - dev + pull_request: + branches: + - dev + - main + +jobs: + build: + runs-on: windows-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Set up JDK + uses: actions/setup-java@v2 + with: + java-version: '11' # You can specify other versions like '8', '17', etc. + distribution: 'zulu' + + # Optional: Verify Java installation + - name: Verify JDK installation + run: java -version + - name: Set up MSVC and CMake + uses: microsoft/setup-msbuild@v1 + with: + vs-version: 'latest' + + + # - name: Install Ninja + # run: | + # choco install ninja + - name: Set up vcpkg + run: | + # Install required tools and dependencies + echo "Setting up vcpkg" + + # Clone the vcpkg repository + git clone https://github.com/Microsoft/vcpkg.git + cd vcpkg + + # Bootstrap vcpkg to build it + ./bootstrap-vcpkg.bat + cd.. + + ./vcpkg/vcpkg install + + - name: Configure with CMake + run: | + mkdir build + cd build + $VCPKG_PATH="$PWD/../vcpkg/scripts/buildsystems/vcpkg.cmake" + echo $VCPKG_PATH + + cmake .. -G "Visual Studio 17 2022" -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE="$VCPKG_PATH" -DPKG_CONFIG_EXECUTABLE="$PWD/../vcpkg/packages/pkgconf_x64-windows/tools/pkgconf/pkgconf.exe" + + # Step 5: Build the project with MSBuild + - name: Build with MSBuild + run: | + cd build + cmake --build . --config Release + + # Step 6: Run tests with CTest + - name: Run tests with CTest + run: | + cd build + dir + ctest -N + ctest -C Release --output-on-failure # Run tests and output on failure diff --git a/.gitignore b/.gitignore index 5fd0403..8e22c83 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,7 @@ # Mono auto generated files mono_crash.* +RC*20616 # Build results [Dd]ebug/ @@ -145,7 +146,7 @@ _TeamCity* # Coverlet is a free, cross platform Code Coverage Tool coverage*.json coverage*.xml -coverage*.info +coverage*.ctoastInfo # Visual Studio code coverage results *.coverage @@ -188,7 +189,7 @@ publish/ *.publishproj # Microsoft Azure Web App publish settings. Comment the next line if you want to -# checkin your Azure Web App publish settings, but sensitive information contained +# checkin your Azure Web App publish settings, but sensitive ctoastInformation contained # in these scripts will be unencrypted PublishScripts/ @@ -218,7 +219,7 @@ rcf/ AppPackages/ BundleArtifacts/ Package.StoreAssociation.xml -_pkginfo.txt +_pkgctoastInfo.txt *.appx *.appxbundle *.appxupload @@ -252,8 +253,8 @@ orleans.codegen.cs Generated_Code/ main.dll main.xml +CMakeSettings.json lib -vcpkg.json # Backup & report files from converting an old project file # to a newer Visual Studio version. Backup files are not needed, # because we have git ;-) @@ -344,7 +345,7 @@ ASALocalRun/ # MSBuild Binary and Structured Log *.binlog -# NVidia Nsight GPU debugger configuration file +# NVidia Nsight GPU ctoastDebugger configuration file *.nvuser # MFractors (Xamarin productivity tool) working folder @@ -366,4 +367,7 @@ MigrationBackup/ FodyWeavers.xsd # 32067 -secret/ \ No newline at end of file +secret/ +/.vscode +build +/.github/workflows/nightly.yml diff --git a/CHANGELOG.md b/CHANGELOG.md index c9a14a3..70e6bff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,21 @@ +# v1.4.0 (2025-03-30) +- Added C and Java bindings +- Use LLVM coding convention +- Used clang-tidy and clang-format +- Fixed bugs + +# v1.3.0 (2025-03-26) +- Added notifications +- Added tests +- Fixed bugs + +# v1.2.1 (2025-03-24) +- Fixed a bug where the window controls disappear + # v1.2.0 (2025-03-24) - Added support for Lua scripting - Fixed some bugs -- Added some error codes +- Added some ctoastError codes - Added a whole new Lua API for interfacing with the C++ code - Added a new module (lua) for handling Lua instances @@ -9,7 +23,7 @@ - Added shared library APIs (rudimentary) - Added support for DLL loading (for code injection) - Revamped .xml format to support shared libraries -- Added some error codes +- Added some ctoastError codes # v1.0.0 (unknown date) - Initial release diff --git a/CMakeLists.txt b/CMakeLists.txt index e824a48..cec0d7d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,71 +1,215 @@ # Set the minimum required CMake version cmake_minimum_required (VERSION 3.8) - +#set(CTOAST_BUNDLE 1) +message(STATUS "Generating files...") +message(STATUS "vcpkg toolchain location: ${CMAKE_TOOLCHAIN_FILE}") # Enable Hot Reload for MSVC compilers if supported. if (POLICY CMP0141) cmake_policy(SET CMP0141 NEW) - set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "$,$>,$<$:EditAndContinue>,$<$:ProgramDatabase>>") + if (CMAKE_C_COMPILER_ID STREQUAL "MSVC" AND CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "$,$>,$<$:EditAndContinue>,$<$:ProgramDatabase>>") + endif() + endif() # Define the project -project ("cinnamontoast") +set(TRIPLET "x64-windows") +project("cinnamontoast") +enable_testing() + +file(GLOB_RECURSE CTOAST_CORE "src/core/*.cpp" "src/core/*.h") +file(GLOB_RECURSE CTOAST_NET "src/net/*.cpp" "src/net/*.h" ) +file(GLOB_RECURSE CTOAST_CRASHHANDLER "src/crash/*.cpp" "src/crash/*.h") +file(GLOB_RECURSE CTOAST_CLI + "src/cli/*.cpp" "src/cli/*.h" "src/windows/ti.rc" +) +file(GLOB_RECURSE CTOAST_TEST + "test/*.cpp" +) +file(GLOB_RECURSE CTOAST_CSTYLE "src/api/cstyle/*.cpp" "src/api/cstyle/*.h") +file(GLOB_RECURSE CTOAST_LUA "src/api/lua/*.cpp" "src/api/lua/*.h") +file(GLOB_RECURSE CTOAST_JAVA "src/api/java/*.c" "src/api/java/*.h") +if(UNIX) + file(GLOB_RECURSE CTOAST_CORE "src/core/*.cpp" "src/core/*.h") + file(GLOB_RECURSE CTOAST_CRASHHANDLER "src/crash/*.cpp" "src/crash/*.h") + file(GLOB_RECURSE CTOAST_CLI + "src/cli/*.cpp" "src/cli/*.h" "src/windows/ctoasti.rc" + ) + file(GLOB_RECURSE CTOAST_TEST + "test/*.cpp" + ) + file(GLOB_RECURSE CTOAST_CSTYLE "src/api/cstyle/*.cpp" "src/api/cstyle/*.h") + file(GLOB_RECURSE CTOAST_LUA "src/api/lua/*.cpp" "src/api/lua/*.h") + file(GLOB_RECURSE CTOAST_JAVA "src/api/java/*.c" "src/api/java/*.h") +endif() # Collect .cpp and .h files from specific directories -file(GLOB_RECURSE CTOAST_CORE "src/*.cpp" "src/*.h") -file(GLOB_RECURSE CTOAST_CRASHHANDLER "crash/*.cpp" "crash/*.h") -file(GLOB_RECURSE CTOAST_CLI "cli/*.cpp" "cli/*.h") -file(GLOB_RECURSE CTOAST_LUA "lua/*.cpp" "lua/*.h") -file(GLOB_RECURSE TINYXML2 "lib/tinyxml2/*.cpp" "lib/tinyxml2/*.h") +get_filename_component(VCPKG_DIR "${CMAKE_TOOLCHAIN_FILE}" DIRECTORY) +set(VCPKG_DIR "${VCPKG_DIR}/../../") +set(PKG_CONFIG_EXECUTABLE "${VCPKG_DIR}/installed/${TRIPLET}/tools/pkgconf/pkgconf.exe") +set(LIB_FILE_DIR "${CMAKE_BINARY_DIR}/vcpkg_installed/${TRIPLET}/lib") +set(JAVA_VERSION "21") +set(JNI_INCLUDE_DIR "$ENV{JAVA_HOME}/include/win32" "$ENV{JAVA_HOME}/include") +if(UNIX) + set(JNI_INCLUDE_DIR "$ENV{JAVA_HOME}/include/linux" "$ENV{JAVA_HOME}/include") +endif(UNIX) +if(DEFINED CTOAST_BUNDLE) + file(GLOB_RECURSE CTOAST_COMMONS "src/common/*.cpp" "src/common/*.h") + + add_library(CinnamonToast SHARED ${CTOAST_CSTYLE} + ${CTOAST_CRASHHANDLER} + ${CTOAST_LUA} + ${CTOAST_JAVA} + ${CTOAST_NET} ${CTOAST_CORE} ${CTOAST_COMMONS} + ) + target_compile_definitions(CinnamonToast PRIVATE CTOAST_SHARED_LIBRARY=1) + target_compile_definitions(CinnamonToast PRIVATE CTOAST_LUA=1) + target_compile_definitions(CinnamonToast PRIVATE CTOAST_BUILDING=1) + target_compile_definitions(CinnamonToast PRIVATE CTOAST_BUNDLED=1) +else() + # Add the source files for the specific DLLs + add_library(CinnamonToast.CStyleAPI SHARED ${CTOAST_CSTYLE} "src/windows/CinnamonToast.CStyleAPI.rc") + add_library(CinnamonToast.CrashHandler SHARED ${CTOAST_CRASHHANDLER} "src/windows/CinnamonToast.CrashHandler.rc") + add_library(CinnamonToast.LuaAPI SHARED ${CTOAST_LUA} "src/windows/CinnamonToast.LuaAPI.rc") + add_library(CinnamonToast.JavaAPI SHARED ${CTOAST_JAVA} "src/windows/CinnamonToast.JavaAPI.rc") + add_library(CinnamonToast.Networking SHARED ${CTOAST_NET}) + add_library(CinnamonToast.Core SHARED ${CTOAST_CORE} "src/windows/CinnamonToast.Core.rc") + target_compile_definitions(CinnamonToast.Core PRIVATE CTOAST_SHARED_LIBRARY=1) + target_compile_definitions(CinnamonToast.Core PRIVATE CTOAST_EXT_NETWORKING=1) + target_compile_definitions(CinnamonToast.CrashHandler PRIVATE CTOAST_SHARED_LIBRARY=1) -# Add the source files for the specific DLLs -add_library(CinnamonToast.CrashHandler SHARED ${CTOAST_CRASHHANDLER} ) -add_library(CinnamonToast.LuaAPI SHARED ${CTOAST_LUA} ) -add_library(tinyxml2 SHARED ${TINYXML2} ) + target_compile_definitions(CinnamonToast.Core PRIVATE CTOAST_LUA=1) + target_compile_definitions(CinnamonToast.LuaAPI PRIVATE CTOAST_SHARED_LIBRARY=1) + target_compile_definitions(CinnamonToast.CStyleAPI PRIVATE CTOAST_BUILDING=1) +endif() +#link_directories("${CMAKE_BINARY_DIR}/vcpkg_installed/${TRIPLET}/lib") -# use precompiled binaries as it is too hard to compile luajit -add_library(CinnamonToast.Core SHARED ${CTOAST_CORE} ) +set(CMAKE_CXX_CLANG_TIDY "clang-tidy") +file(GLOB_RECURSE CTOAST_FILES "src/*.cpp" "src/*.c" "src/*.h") -target_compile_definitions(CinnamonToast.CrashHandler PRIVATE CTOAST_SHARED_LIBRARY=1) -target_compile_definitions(CinnamonToast.Core PRIVATE CTOAST_SHARED_LIBRARY=1) -target_compile_definitions(CinnamonToast.Core PRIVATE CTOAST_LUA=1) -target_compile_definitions(CinnamonToast.LuaAPI PRIVATE CTOAST_SHARED_LIBRARY=1) -target_compile_definitions(tinyxml2 PRIVATE TINYXML2_EXPORT=1) +# Define a custom target to run clang-format +add_custom_target( + format + COMMAND clang-format -i ${CTOAST_FILES} # -i option applies changes to the files + COMMENT "Running clang-format on source files" +) + +# Optionally, make the "format" target depend on the "all" target so that it runs by default +if(DEFINED CTOAST_BUNDLE) + add_dependencies(CinnamonToast format) +else() + add_dependencies(CinnamonToast.Core format) +endif() # Add source files for the executable (cli) -add_executable(ctoasti ${CTOAST_CLI} ) - -# Link CinnamonToast.Core with CinnamonToast.CrashHandler (making the dependency) - -target_link_libraries(CinnamonToast.LuaAPI PRIVATE "${CMAKE_SOURCE_DIR}/lib/luajit/lua51.lib") -target_link_libraries(CinnamonToast.Core PRIVATE CinnamonToast.CrashHandler) -target_link_libraries(CinnamonToast.Core PRIVATE tinyxml2) -target_link_libraries(CinnamonToast.Core PRIVATE "${CMAKE_SOURCE_DIR}/lib/luajit/lua51.lib") -target_link_libraries(CinnamonToast.Core PRIVATE CinnamonToast.LuaAPI) -target_include_directories(CinnamonToast.LuaAPI PRIVATE "${CMAKE_SOURCE_DIR}/common") -target_include_directories(CinnamonToast.CrashHandler PRIVATE "${CMAKE_SOURCE_DIR}/common") -target_include_directories(CinnamonToast.Core PRIVATE "${CMAKE_SOURCE_DIR}/common") -target_include_directories(ctoasti PRIVATE "${CMAKE_SOURCE_DIR}/common") +add_executable(ctoasti ${CTOAST_CLI}) +add_executable(ctoastt ${CTOAST_TEST}) +find_package(tinyxml2 CONFIG REQUIRED) +find_package(GTest REQUIRED) +set(OPENSSL_USE_STATIC_LIBS OFF) +find_package(OpenSSL REQUIRED) +find_package(PkgConfig REQUIRED) +pkg_check_modules(LUAJIT REQUIRED luajit) + +set(LUAJIT_LIBRARIES "${LIB_FILE_DIR}/${LUAJIT_LIBRARIES}.lib") +message(STATUS "LuaJIT binaries: ${LUAJIT_LIBRARIES}") +file(GLOB DLL_FILE_DIR "${CMAKE_BINARY_DIR}/vcpkg_installed/${TRIPLET}/bin/*") + +#foreach(file ${DLL_FILE_DIR}) +# if(NOT IS_DIRECTORY ${file}) +# # Copy the file if it is not a directory +# message(STATUS "Copying file ${file}...") +# file(COPY ${file} DESTINATION ".") +# endif() +#endforeach() +if(UNIX) + set(LUAJIT_LIBRARIES "${CMAKE_BINARY_DIR}/vcpkg_installed/${TRIPLET}/lib/libluajit-5.1.so") + +endif() +if(DEFINED CTOAST_BUNDLE) + target_link_libraries(CinnamonToast PRIVATE tinyxml2::tinyxml2) + target_link_libraries(CinnamonToast PRIVATE ${LUAJIT_LIBRARIES}) + target_link_libraries(CinnamonToast PRIVATE OpenSSL::SSL ws2_32) +else() + target_link_libraries(CinnamonToast.CStyleAPI PRIVATE CinnamonToast.Core) + target_link_libraries(CinnamonToast.JavaAPI PRIVATE CinnamonToast.CStyleAPI) + target_link_libraries(CinnamonToast.LuaAPI PRIVATE ${LUAJIT_LIBRARIES}) + target_link_libraries(CinnamonToast.Core PRIVATE CinnamonToast.CrashHandler) + target_link_libraries(CinnamonToast.Core PRIVATE tinyxml2::tinyxml2) + target_link_libraries(CinnamonToast.Core PRIVATE ${LUAJIT_LIBRARIES}) + target_link_libraries(CinnamonToast.Core PRIVATE CinnamonToast.LuaAPI) + target_link_libraries(CinnamonToast.Networking PRIVATE OpenSSL::SSL ws2_32) +endif() +# do not let main() of program conflict with main() of gtest +target_compile_definitions(ctoastt PRIVATE CTOAST_TESTS=1) +# add tests +target_link_libraries(ctoastt PRIVATE GTest::gtest GTest::gtest_main) + +if(DEFINED CTOAST_BUNDLE) + target_include_directories(CinnamonToast PRIVATE ${JNI_INCLUDE_DIR}) + target_include_directories(CinnamonToast PRIVATE "${CMAKE_SOURCE_DIR}/src/common") + target_include_directories(CinnamonToast PRIVATE ${LUAJIT_INCLUDE_DIRS}) + target_include_directories(CinnamonToast PRIVATE ${LUAJIT_INCLUDE_DIRS}) + target_include_directories(CinnamonToast PRIVATE "${CMAKE_SOURCE_DIR}/src/common") + target_include_directories(CinnamonToast PRIVATE "${CMAKE_SOURCE_DIR}/src/common") + target_include_directories(CinnamonToast PRIVATE "${CMAKE_SOURCE_DIR}/src/common") + target_include_directories(CinnamonToast PRIVATE "${CMAKE_SOURCE_DIR}/src/common") + target_include_directories(CinnamonToast PRIVATE "${CMAKE_SOURCE_DIR}/src/") + target_include_directories(CinnamonToast PRIVATE "${CMAKE_SOURCE_DIR}/src/common" ) +else() + target_include_directories(CinnamonToast.JavaAPI PRIVATE ${JNI_INCLUDE_DIR}) + target_include_directories(CinnamonToast.JavaAPI PRIVATE "${CMAKE_SOURCE_DIR}/src/common") + target_include_directories(CinnamonToast.LuaAPI PRIVATE ${LUAJIT_INCLUDE_DIRS}) + target_include_directories(CinnamonToast.Core PRIVATE ${LUAJIT_INCLUDE_DIRS}) + target_include_directories(CinnamonToast.LuaAPI PRIVATE "${CMAKE_SOURCE_DIR}/src/common") + target_include_directories(CinnamonToast.CrashHandler PRIVATE "${CMAKE_SOURCE_DIR}/src/common") + target_include_directories(CinnamonToast.Core PRIVATE "${CMAKE_SOURCE_DIR}/src/common") + target_include_directories(CinnamonToast.CStyleAPI PRIVATE "${CMAKE_SOURCE_DIR}/src/common") + target_include_directories(CinnamonToast.CStyleAPI PRIVATE "${CMAKE_SOURCE_DIR}/src/") + + target_include_directories(CinnamonToast.Networking PRIVATE "${CMAKE_SOURCE_DIR}/src/common" ) + +endif() +target_include_directories(ctoasti PRIVATE "${CMAKE_SOURCE_DIR}/src/common") +target_include_directories(ctoastt PRIVATE "${CMAKE_SOURCE_DIR}/src/common") + # Add the target executable (cli) - linking the core library -target_link_libraries(ctoasti PRIVATE CinnamonToast.Core) -target_compile_options(ctoasti PRIVATE /MT) -if(MSVC) - target_link_libraries(CinnamonToast.Core PRIVATE d2d1 gdi32 comctl32) + +if(DEFINED CTOAST_BUNDLE) + target_link_libraries(ctoasti PRIVATE CinnamonToast) + target_link_libraries(ctoastt PRIVATE CinnamonToast) +else() + target_link_libraries(ctoasti PRIVATE CinnamonToast.Core) + target_link_libraries(ctoastt PRIVATE CinnamonToast.Core) + target_link_libraries(ctoastt PRIVATE CinnamonToast.Networking) + target_link_libraries(ctoastt PRIVATE CinnamonToast.CrashHandler) +endif() + +if(WIN32) + if(DEFINED CTOAST_BUNDLE) + target_link_libraries(CinnamonToast PRIVATE d2d1 gdi32 comctl32 opengl32 ws2_32) + else() + target_link_libraries(CinnamonToast.Core PRIVATE d2d1 gdi32 comctl32 opengl32) + endif() + endif() # Set C++20 standard if (CMAKE_VERSION VERSION_GREATER 3.12) - set_property(TARGET CinnamonToast.Core PROPERTY CXX_STANDARD 20) - set_property(TARGET CinnamonToast.CrashHandler PROPERTY CXX_STANDARD 20) - set_property(TARGET ctoasti PROPERTY CXX_STANDARD 20) - set_property(TARGET CinnamonToast.LuaAPI PROPERTY CXX_STANDARD 20) + if(DEFINED CTOAST_BUNDLE) + set_property(TARGET CinnamonToast PROPERTY CXX_STANDARD 20) + set_property(TARGET CinnamonToast PROPERTY C_STANDARD 99) + else() + set_property(TARGET CinnamonToast.Core PROPERTY CXX_STANDARD 20) + set_property(TARGET CinnamonToast.CrashHandler PROPERTY CXX_STANDARD 20) + set_property(TARGET ctoasti PROPERTY CXX_STANDARD 20) + set_property(TARGET ctoastt PROPERTY CXX_STANDARD 20) + set_property(TARGET CinnamonToast.LuaAPI PROPERTY CXX_STANDARD 20) + set_property(TARGET CinnamonToast.JavaAPI PROPERTY C_STANDARD 99) + endif(DEFINED CTOAST_BUNDLE) + endif() -# TODO: Add tests and install targets if needed. -add_custom_command( - OUTPUT ${CMAKE_BINARY_DIR}/lua51.dll # The new renamed file - COMMAND ${CMAKE_COMMAND} -E copy_if_different - ${CMAKE_SOURCE_DIR}/lib/luajit/lua51.dll # Source DLL - ${CMAKE_BINARY_DIR}/lua51.dll # Destination with new name - DEPENDS ${CMAKE_SOURCE_DIR}/lib/luajit/lua51.dll # Ensure it runs when the source changes -) + +add_test(NAME CToastTest COMMAND ctoastt) \ No newline at end of file diff --git a/CMakeSettings.json b/CMakeSettings.json new file mode 100644 index 0000000..23fd37a --- /dev/null +++ b/CMakeSettings.json @@ -0,0 +1,28 @@ +{ + "configurations": [ + { + "name": "x64-Debug", + "generator": "Ninja", + "configurationType": "Debug", + "inheritEnvironments": [ "msvc_x64_x64" ], + "buildRoot": "${projectDir}\\out\\build\\${name}", + "installRoot": "${projectDir}\\out\\install\\${name}", + "cmakeToolchain": "C:\\Users\\client\\Downloads\\vcpkg-master\\vcpkg-master2\\scripts\\buildsystems\\vcpkg.cmake", + "buildCommandArgs": "", + "cmakeCommandArgs": "", + "ctestCommandArgs": "" + }, + { + "name": "x64-Release", + "generator": "Ninja", + "configurationType": "Release", + "buildRoot": "${projectDir}\\out\\build\\${name}", + "installRoot": "${projectDir}\\out\\install\\${name}", + "cmakeToolchain": "C:\\Users\\client\\Downloads\\vcpkg-master\\vcpkg-master2\\scripts\\buildsystems\\vcpkg.cmake", + "cmakeCommandArgs": "", + "buildCommandArgs": "", + "ctestCommandArgs": "", + "inheritEnvironments": [ "msvc_x64_x64" ] + } + ] +} \ No newline at end of file diff --git a/README.md b/README.md index 5d4f0d2..cec7ead 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,7 @@ cmake -G "Visual Studio xx xxxx" -A x64 ``` If you're using Ninja, run ```cmd -cmake -G "Ninja" +cmake -G "Ninja -DCMAKE_TOOLCHAIN_FILE=path/to/vcpkg/cmake" ``` 5. Now, build the project ```cmd @@ -80,7 +80,6 @@ cmake --build . --config Release 1. Open a terminal 2. Install CMake, g++ and Python if you haven't already: `sudo apt install cmake g++ python3` 3. Navigate to the project directory -4. Run `python3 DownloadLibraries.py` to download the libraries source (like tinyxml2) 5. Run `cmake .` 6. Run `make` diff --git a/TODO.md b/TODO.md index a31bd8d..55aa22f 100644 --- a/TODO.md +++ b/TODO.md @@ -1,8 +1,8 @@ # Todo - Fix a ton of bugs and issues as well as memory leaks (since its not inherently fast as expected, its still not fully developed) - Add more features and make it more user-friendly -- Optimize API as well and more error handling (again, its not fully developed) -- Add more documentation and examples +- Optimize API as well and more ctoastError handling (again, its not fully developed) +- Add more documentation and examples (partial) - Add OpenGL support for rendering (currently uses Direct2D/Win32 APIs as well as X11 for Linux) - Figure out a way to make it work on Linux again (since well, the code has been largely changed and the code has to be partially rewritten for Linux) - Add more controls and features \ No newline at end of file diff --git a/cli/Main.cpp b/cli/Main.cpp deleted file mode 100644 index c216ea7..0000000 --- a/cli/Main.cpp +++ /dev/null @@ -1,27 +0,0 @@ -/** -* Copyright (c) 2025 thebest12lines -* Permission is hereby granted, free of charge, to any person obtaining a copy of this software -* and associated documentation files (the "Software"), to deal in the Software without restriction, -* including without limitation the rights to use, copy, modify, merge, publish, distribute, -* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING -* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ -typedef unsigned char byte; -#ifdef _WIN32 - #include - // Visual styles - #pragma comment(linker,"\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version = '6.0.0.0' processorArchitecture = '*' publicKeyToken = '6595b64144ccf1df' language = '*'\"") -#endif -#include "Main.h" -#include "Utilities.h" - -int main(int argc, char const *argv[]) { - return CinnamonToast::CLIMain(argc, CinnamonToast::Utilities::CstrArrToVector(argv)); -} diff --git a/cli/Main.h b/cli/Main.h deleted file mode 100644 index 49f1c38..0000000 --- a/cli/Main.h +++ /dev/null @@ -1,26 +0,0 @@ -/** -* Copyright (c) 2025 thebest12lines -* Permission is hereby granted, free of charge, to any person obtaining a copy of this software -* and associated documentation files (the "Software"), to deal in the Software without restriction, -* including without limitation the rights to use, copy, modify, merge, publish, distribute, -* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING -* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ -#include -#include -#include -#include "TypeDefinitions.h" -#pragma once - -namespace CinnamonToast { - CTOAST_API int InvokeExecutable(string xmlFile); - CTOAST_API int CLIMain(const uint8_t argc, const vector argv); -} -int main(const int argc, const char* argv[]); \ No newline at end of file diff --git a/cli/Utilities.h b/cli/Utilities.h deleted file mode 100644 index e4a856e..0000000 --- a/cli/Utilities.h +++ /dev/null @@ -1,39 +0,0 @@ -/** -* Copyright (c) 2025 thebest12lines -* Permission is hereby granted, free of charge, to any person obtaining a copy of this software -* and associated documentation files (the "Software"), to deal in the Software without restriction, -* including without limitation the rights to use, copy, modify, merge, publish, distribute, -* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING -* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ -#pragma once - -#ifdef _WIN32 - #include // or any other conflicting headers -#endif -#include -#include "TypeDefinitions.h" -#include "Definitions.h" -#include - - -namespace CinnamonToast { - namespace Utilities { - CTOAST_API vector CstrArrToVector(const char* arr[]); - CTOAST_API vector SplitString(std::string str, char delimiter); - - #ifdef _WIN32 - CTOAST_API HFONT GetFont(string fontName = DEFAULT_FONT, int size = 16, int fontWeight = 400, bool italic = false, bool underline = false, bool strikeout = false); - CTOAST_API string GetLastErrorAsString(); - #endif - CTOAST_API string GetOSPlatformAndVersion(); - } -} - diff --git a/common/Console.h b/common/Console.h deleted file mode 100644 index 86fc580..0000000 --- a/common/Console.h +++ /dev/null @@ -1,53 +0,0 @@ -/** -* Copyright (c) 2025 thebest12lines -* Permission is hereby granted, free of charge, to any person obtaining a copy of this software -* and associated documentation files (the "Software"), to deal in the Software without restriction, -* including without limitation the rights to use, copy, modify, merge, publish, distribute, -* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING -* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ -#pragma once - -#include "TypeDefinitions.h" -#include -#include -using namespace std; - -namespace CinnamonToast { - namespace Console { - - // std:: part is omitted because of `using namespace std;`. - template - CTOAST_API void print(const T& obj) { - cout << obj; - }; - template - CTOAST_API void println(const T& obj) { - cout << obj << endl; - }; - template - CTOAST_API void error(const T& obj, string ctx = "default") { - cerr << "[ERROR] " << "[" << ctx << "]: " << obj << endl; - }; - template - CTOAST_API void info(const T& obj, string ctx = "default") { - cout << "[INFO] " << "[" << ctx << "]: " << obj << endl; - }; - template - CTOAST_API void warn(const T& obj, string ctx = "default") { - cout << "[WARN] " << "[" << ctx << "]: " << obj << endl; - }; - template - CTOAST_API void debug(const T& obj, string ctx = "default") { - cout << "[DEBUG] " << "[" << ctx << "]: " << obj << endl; - }; - } -} - diff --git a/common/Definitions.h b/common/Definitions.h deleted file mode 100644 index eb2e252..0000000 --- a/common/Definitions.h +++ /dev/null @@ -1,77 +0,0 @@ -/** -* Copyright (c) 2025 thebest12lines -* Permission is hereby granted, free of charge, to any person obtaining a copy of this software -* and associated documentation files (the "Software"), to deal in the Software without restriction, -* including without limitation the rights to use, copy, modify, merge, publish, distribute, -* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING -* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ -#pragma once -#define DEFAULT_FONT "Segoe UI" - -/** - * External app name to be shown to the end user. -*/ -#define APP_NAME "Project CinnamonToast" - -/** - * Internal app version for compatibility checks. - */ -#define APP_INTERNAL_VERSION 0000003L - -/** - * External app version to be shown to the end user. - */ -#define APP_VERSION "1.2.0" - -/** - * Error code specification - * - * These error codes should be used to indicate a specific error. Some errors - * are platform-specific, and this is indicated by the second leftmost digit of the - * error code. The valid values are: - * 0x0 - Cross-platform - * 0x1 - Windows - * 0x2 - macOS - * 0x3 - Linux - * - * Examples are: 0x01000000 (an "error" code for a successful execution on Windows, though this is only - * for demonstation purposes and SHOULD NOT be used in code), 0x03badf00 (Linux), etc. - * - * - * There are some reserved return codes like 0x0000002 which is ALWAYS the "file not found" error. 0x00000000 - * is also another one of these codes. It's not necessarily an "error" code, though it is a return code for success. - */ - -/** - * Comment/uncomment this to toggle Win32 errors. - */ -#ifdef _WIN32 - #define WIN32_ERROR_CODES -#endif - -// Internal error codes and other things -#define ERROR_NO_FILES_SPECIFIED 0x000003f0L -#define ERROR_GENERIC_XML_ERROR 0x000003f1L -#define ERROR_XML_NO_ROOT 0x000003f2L -#define ERROR_XML_NO_WINDOW 0x000003f3L -#define ERROR_FILE_NOT_FOUND 0x0000002L -#define ERROR_FONT_NOT_FOUND 0x0000003L -#define ERROR_HEX_COLOR_MALFORMED 0x000003f4L -#define ERROR_LINUX_X11_NOT_INITIALIZED 0x030003f5L -#define ERROR_CANNOT_LOAD_SHARED_LIBRARY 0x000003f9L -#define ERROR_CANNOT_LOAD_LIBRARY_FUNCTION 0x000003faL -#define ERROR_XML_NOT_COMPATIBLE 0x000003fbL -#define ERROR_UNHANDLED_EXCEPTION 0x000003fcL -// Win32 specific errors -#if defined(_WIN32) && defined(WIN32_ERROR_CODES) - #define ERROR_WIN_PARENT_HWND_INVALID 0x010003f5L - // more errors go here -#endif \ No newline at end of file diff --git a/common/TypeDefinitions.h b/common/TypeDefinitions.h deleted file mode 100644 index 7dc7149..0000000 --- a/common/TypeDefinitions.h +++ /dev/null @@ -1,34 +0,0 @@ -/** -* Copyright (c) 2025 thebest12lines -* Permission is hereby granted, free of charge, to any person obtaining a copy of this software -* and associated documentation files (the "Software"), to deal in the Software without restriction, -* including without limitation the rights to use, copy, modify, merge, publish, distribute, -* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING -* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ -#pragma once -typedef unsigned char byte; -#include "Definitions.h" -#if !defined(CTOAST_API) && !defined(CTOAST_BUILDING) - #define CTOAST_API __declspec(dllimport); -#endif -#define ctoast CinnamonToast:: -namespace CinnamonToast { }; - -#ifdef CTOAST_SHARED_LIBRARY - #ifdef _WIN32 - #define CTOAST_API __declspec(dllexport) - #elif __linux__ - #define CTOAST_API __attribute__((visibility("default"))) - #endif -#endif - -using namespace std; -using namespace CinnamonToast; \ No newline at end of file diff --git a/crash/CrashHandler.cpp b/crash/CrashHandler.cpp deleted file mode 100644 index 7ded6e8..0000000 --- a/crash/CrashHandler.cpp +++ /dev/null @@ -1,107 +0,0 @@ -/** -* Copyright (c) 2025 thebest12lines -* Permission is hereby granted, free of charge, to any person obtaining a copy of this software -* and associated documentation files (the "Software"), to deal in the Software without restriction, -* including without limitation the rights to use, copy, modify, merge, publish, distribute, -* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING -* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ -#include "TypeDefinitions.h" -#include "CrashHandler.h" -#include -#include -using namespace CinnamonToast; - -// Internal functions -namespace { - void NoCrashFunction() {}; - LONG WINAPI SignalHandler(EXCEPTION_POINTERS* ExceptionInfo) { - if (ExceptionInfo->ExceptionRecord->ExceptionCode == EXCEPTION_ACCESS_VIOLATION) { - std::cout << "[FATAL] [SignalHandler]: Program crashed! Segmentation fault!" << std::endl; - std::cout << "[FATAL] [SignalHandler]: Showing message! " << std::endl; - MessageBox(NULL, "The program crashed due to a segmentation fault. Reinstalling the app may fix the issue.", "Program crashed!", MB_ICONERROR); - exit(0x000003f7); - } - return EXCEPTION_CONTINUE_SEARCH; // Continue searching for another handler (if any) - }; -} - -namespace CinnamonToast { - CrashHandler* CrashManager::handler = nullptr; - void CrashManager::SetActiveCrashHandler(CrashHandler* handler_){ - if (handler != nullptr) { - handler->Deactivate(); - } - handler = handler_; - handler_->Activate(); - - }; - - CrashHandler* CrashManager::GetActiveCrashHandler() { - return handler; - }; - void CrashHandler::InvokeCrash(string crashMessage) { - if (throwCrash) { - std::cout << "[FATAL] [InvokeUnhandledExceptionCrash]: Program crashed! " << std::endl; - std::cout << "[FATAL] [InvokeUnhandledExceptionCrash]: Showing message! " << std::endl; - MessageBox(NULL, "The program crashed due to an unspecified reason. Restarting the app may fix this issue.", "Program crashed!", MB_ICONERROR); - exit(0x000003f8); - } - } - bool Utilities::CheckBit(unsigned int num, int n) { - unsigned int mask = 1 << n; // Create a mask with 1 at the nth position - return num & mask; // If the nth bit is 1, the result will be non-zero - } - - CrashHandler::CrashHandler(CrashConfig cf) : customCrash(NoCrashFunction), throwHandle(false), throwCrash(false), config(cf) { - } - void CrashHandler::InvokeUnhandledExceptionCrash(exception& ex) { - if (throwHandle) { - if (customCrash != NoCrashFunction) { - customCrash(); - } - std::cout << "[FATAL] [InvokeUnhandledExceptionCrash]: Program crashed! " << std::endl; - std::cout << "[FATAL] [InvokeUnhandledExceptionCrash]: Printing error and showing message! " << std::endl; - std::cout << "[FATAL] []: " << ex.what() << std::endl; - MessageBox(NULL, "The program crashed due to an unhandled exception. Reinstalling the app may fix this issue.", "Program crashed!", MB_ICONERROR); - exit(0x000003f6); - } - }; - void CrashHandler::Activate() { - active = true; - if (Utilities::CheckBit(config.CrashType, 0)) { - SetUnhandledExceptionFilter(SignalHandler); - } - if (Utilities::CheckBit(config.CrashType, 4)) { - throwHandle = true; - } - if (Utilities::CheckBit(config.CrashType, 8)) { - throwCrash = true; - } - - } - void CrashHandler::Deactivate() { - active = false; - if (Utilities::CheckBit(config.CrashType, 0)) { - SetUnhandledExceptionFilter(NULL); - } - if (Utilities::CheckBit(config.CrashType, 4)) { - throwHandle = false; - } - if (Utilities::CheckBit(config.CrashType, 8)) { - throwCrash = false; - } - - } - void CrashHandler::SetUnhandledExceptionCrashFunction(CrashFunction function) { - customCrash = function; - } -} - diff --git a/crash/CrashHandler.h b/crash/CrashHandler.h deleted file mode 100644 index d134740..0000000 --- a/crash/CrashHandler.h +++ /dev/null @@ -1,64 +0,0 @@ -/** -* Copyright (c) 2025 thebest12lines -* Permission is hereby granted, free of charge, to any person obtaining a copy of this software -* and associated documentation files (the "Software"), to deal in the Software without restriction, -* including without limitation the rights to use, copy, modify, merge, publish, distribute, -* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING -* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ -#pragma once -#include -#include "TypeDefinitions.h" -#include -#include - -#define CRASH_UNHANDLED_EXCEPTION 0x10 -#define CRASH_INVOKE 0x100 -#define CRASH_SEGFAULT 0x1 -typedef void (*CrashFunction)(); - -namespace CinnamonToast { - struct CrashConfig { - uint32_t MessageType; - uint32_t CrashType; - }; - class CrashHandler { - private: - CrashFunction customCrash; - bool active; - bool throwHandle; - bool throwCrash; - CrashConfig config; - CTOAST_API void Activate(); - CTOAST_API void Deactivate(); - - public: - CTOAST_API CrashHandler(CrashConfig cf); - CTOAST_API void SetCustomCrashHandler(CrashFunction func); - CTOAST_API void InvokeCrash(string crashMessage); - - // Note: explicitly need to define try-catch block and to call this method - CTOAST_API void InvokeUnhandledExceptionCrash(exception& ex); - CTOAST_API void SetUnhandledExceptionCrashFunction(CrashFunction function); - - friend class CrashManager; - - }; - class CrashManager { - private: - static CrashHandler* handler; - public: - CTOAST_API static void SetActiveCrashHandler(CrashHandler* handler_); - CTOAST_API static CrashHandler* GetActiveCrashHandler(); - }; - namespace Utilities { - bool CheckBit(unsigned int num, int n); - } -} \ No newline at end of file diff --git a/lua/CToastLua.h b/lua/CToastLua.h deleted file mode 100644 index f7cc22c..0000000 --- a/lua/CToastLua.h +++ /dev/null @@ -1,87 +0,0 @@ -#pragma once -/** -* Copyright (c) 2025 thebest12lines -* Permission is hereby granted, free of charge, to any person obtaining a copy of this software -* and associated documentation files (the "Software"), to deal in the Software without restriction, -* including without limitation the rights to use, copy, modify, merge, publish, distribute, -* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING -* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ -#undef byte -typedef unsigned char byte ; -#include -extern "C" { - #include "../lib/luajit/lua.h" - #include "../lib/luajit/lauxlib.h" - #include "../lib/luajit/lualib.h" -} -#include "TypeDefinitions.h" -#include -#include -#include -#include - - -extern "C++" { - namespace CinnamonToast { - template - concept ValidLuaType = std::is_same_v || std::is_same_v || std::is_same_v; - template - struct IsValidLuaTypeOrVectorTrait : std::false_type {}; - - template - struct IsValidLuaTypeOrVectorTrait> : std::conditional_t< - ValidLuaType || IsValidLuaTypeOrVectorTrait::value, - std::true_type, - std::false_type - > { - }; - - template - constexpr bool IsValidLuaTypeOrVector = IsValidLuaTypeOrVectorTrait::value; - - template - concept ValidLuaVector = requires(T t) { - typename T::value_type; - requires IsValidLuaTypeOrVector; - }; - - template - concept LuaType = ValidLuaType || ValidLuaVector; - - class LuaInstance { - private: - lua_State* L; - template - __declspec(dllimport) void SetValue(int index, T value); - public: - __declspec(dllimport) void Execute(std::string code); - __declspec(dllimport) void ExecuteFile(std::string filePath); - __declspec(dllimport) void RegisterFunction(std::string name, lua_CFunction func); - - template - __declspec(dllimport) void SetValue(std::string name, T value); - template - __declspec(dllimport) void SetValue(string hierarchy, string key, T value); - __declspec(dllimport) void CreateTable(std::string name); - - // Note: hierarchy corresponds to the table hierarchy (not including the table itself), e.g. "table1.table2.table3" or "foo" (if foo.bar will be initialized). - __declspec(dllimport) void CreateTable(std::string hierarchy, std::string name); - //__declspec(dllimport) void SetValue(std::string tableName, std::string key, int value); - //__declspec(dllimport) void SetValue(std::string tableName, std::string key, double value); - __declspec(dllimport) void SetValue(std::string tableName, std::string key, std::string value); - __declspec(dllimport) void RegisterFunction(std::string tableName, std::string name, lua_CFunction func); - __declspec(dllimport) void InitializeLuaApis(void (*customInitializer)(LuaInstance* self)); - __declspec(dllimport) LuaInstance(); - }; - - } - -} diff --git a/lua/Console.h b/lua/Console.h deleted file mode 100644 index 86fc580..0000000 --- a/lua/Console.h +++ /dev/null @@ -1,53 +0,0 @@ -/** -* Copyright (c) 2025 thebest12lines -* Permission is hereby granted, free of charge, to any person obtaining a copy of this software -* and associated documentation files (the "Software"), to deal in the Software without restriction, -* including without limitation the rights to use, copy, modify, merge, publish, distribute, -* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING -* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ -#pragma once - -#include "TypeDefinitions.h" -#include -#include -using namespace std; - -namespace CinnamonToast { - namespace Console { - - // std:: part is omitted because of `using namespace std;`. - template - CTOAST_API void print(const T& obj) { - cout << obj; - }; - template - CTOAST_API void println(const T& obj) { - cout << obj << endl; - }; - template - CTOAST_API void error(const T& obj, string ctx = "default") { - cerr << "[ERROR] " << "[" << ctx << "]: " << obj << endl; - }; - template - CTOAST_API void info(const T& obj, string ctx = "default") { - cout << "[INFO] " << "[" << ctx << "]: " << obj << endl; - }; - template - CTOAST_API void warn(const T& obj, string ctx = "default") { - cout << "[WARN] " << "[" << ctx << "]: " << obj << endl; - }; - template - CTOAST_API void debug(const T& obj, string ctx = "default") { - cout << "[DEBUG] " << "[" << ctx << "]: " << obj << endl; - }; - } -} - diff --git a/lua/LuaInstance.h b/lua/LuaInstance.h deleted file mode 100644 index dd65db7..0000000 --- a/lua/LuaInstance.h +++ /dev/null @@ -1,231 +0,0 @@ -#pragma once -/** -* Copyright (c) 2025 thebest12lines -* Permission is hereby granted, free of charge, to any person obtaining a copy of this software -* and associated documentation files (the "Software"), to deal in the Software without restriction, -* including without limitation the rights to use, copy, modify, merge, publish, distribute, -* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING -* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -#include "../lib/luajit/lua.hpp" -#include "TypeDefinitions.h" -#include -#include "Console.h" -#include -#include -#include - -#define CTOAST_LUA_API "CinnamonToast" - -namespace CinnamonToast { - template - concept ValidLuaType = std::is_same_v || std::is_same_v || std::is_same_v; - template - struct IsValidLuaTypeOrVectorTrait : std::false_type {}; - - template - struct IsValidLuaTypeOrVectorTrait> : std::conditional_t< - ValidLuaType || IsValidLuaTypeOrVectorTrait::value, - std::true_type, - std::false_type - > { - }; - - template - constexpr bool IsValidLuaTypeOrVector = IsValidLuaTypeOrVectorTrait::value; - - template - concept ValidLuaVector = requires(T t) { - typename T::value_type; - requires IsValidLuaTypeOrVector; - }; - - template - concept LuaType = ValidLuaType || ValidLuaVector; - - class LuaInstance { - private: - lua_State* L; - template - CTOAST_API void SetValue(int index, T value) { - // push to stack - if constexpr (std::is_same_v) { - lua_pushinteger(L, value); - } - else if constexpr (std::is_same_v) { - lua_pushnumber(L, value); - } - else if constexpr (std::is_same_v) { - lua_pushstring(L, value.c_str()); - } - else if constexpr (ValidLuaVector) { - lua_newtable(L); - for (int i = 0; i < value.size(); i++) { - if constexpr (ValidLuaType) { - SetValue(i + 1, value[i]); - } - else if constexpr (ValidLuaVector) { - SetValue(i + 1, value[i]); - } - } - } - } - public: - CTOAST_API void Execute(std::string code) { - luaL_dostring(L, code.c_str()); - }; - CTOAST_API void ExecuteFile(std::string filePath) { - luaL_dofile(L, filePath.c_str()); - }; - CTOAST_API void RegisterFunction(std::string name, lua_CFunction func) { - lua_register(L, name.c_str(), func); - }; - - template - CTOAST_API void SetValue(std::string name, T value) { - if constexpr (ValidLuaType) { - if constexpr (std::is_same_v) { - lua_pushinteger(L, value); - } - else if constexpr (std::is_same_v) { - lua_pushnumber(L, value); - } - else if constexpr (std::is_same_v) { - lua_pushstring(L, value.c_str()); - } - } else if constexpr (ValidLuaVector) { - lua_newtable(L); - for (int i = 0; i < value.size(); i++) { - SetValue(i + 1, value[i]); - } - } - lua_setglobal(L, name.c_str()); - }; - template - CTOAST_API void SetValue(string hierarchy, string key, T value) { - std::vector tables; - std::string currentTable = ""; - for (int i = 0; i < hierarchy.size(); i++) { - if (hierarchy[i] == '.') { - tables.push_back(currentTable); - currentTable = ""; - } - else { - currentTable += hierarchy[i]; - } - } - tables.push_back(currentTable); - lua_getglobal(L, tables[0].c_str()); - for (int i = 1; i < tables.size(); i++) { - lua_pushstring(L, tables[i].c_str()); - lua_gettable(L, -2); - } - if constexpr (ValidLuaType) { - if constexpr (std::is_same_v) { - lua_pushinteger(L, value); - } - else if constexpr (std::is_same_v) { - lua_pushnumber(L, value); - } - else if constexpr (std::is_same_v) { - lua_pushstring(L, value.c_str()); - } - } - else if constexpr (ValidLuaVector) { - lua_newtable(L); - for (int i = 0; i < value.size(); i++) { - SetValue(i + 1, value[i]); - } - } - lua_setfield(L, -2, key.c_str()); - }; - CTOAST_API void SetValue(string hierarchy, string key, string value) { - std::vector tables; - std::string currentTable = ""; - for (int i = 0; i < hierarchy.size(); i++) { - if (hierarchy[i] == '.') { - tables.push_back(currentTable); - currentTable = ""; - } - else { - currentTable += hierarchy[i]; - } - } - tables.push_back(currentTable); - lua_getglobal(L, tables[0].c_str()); - for (int i = 1; i < tables.size(); i++) { - lua_pushstring(L, tables[i].c_str()); - lua_gettable(L, -2); - } - lua_pushstring(L, value.c_str()); - lua_setfield(L, -2, key.c_str()); - } - CTOAST_API void CreateTable(std::string name) { - lua_newtable(L); - lua_setglobal(L, name.c_str()); - }; - - // Note: hierarchy corresponds to the table hierarchy (not including the table itself), e.g. "table1.table2.table3" or "foo" (if foo.bar will be initialized). - CTOAST_API void CreateTable(std::string hierarchy, std::string name) { - std::vector tables; - std::string currentTable = ""; - for (int i = 0; i < hierarchy.size(); i++) { - if (hierarchy[i] == '.') { - tables.push_back(currentTable); - currentTable = ""; - } - else { - currentTable += hierarchy[i]; - } - } - tables.push_back(currentTable); - lua_getglobal(L, tables[0].c_str()); - for (int i = 1; i < tables.size(); i++) { - lua_pushstring(L, tables[i].c_str()); - lua_gettable(L, -2); - } - lua_newtable(L); - lua_setglobal(L, name.c_str()); - }; - /*void SetValue(std::string tableName, std::string key, int value); - void SetValue(std::string tableName, std::string key, double value); - void SetValue(std::string tableName, std::string key, std::string value);*/ - CTOAST_API void RegisterFunction(std::string tableName, std::string name, lua_CFunction func) { - lua_getglobal(L, tableName.c_str()); - lua_pushcfunction(L, func); - lua_setfield(L, -2, name.c_str()); - }; - - CTOAST_API void InitializeLuaApis(void (*customInitializer)(LuaInstance* self)) { - CreateTable(CTOAST_LUA_API); - if (customInitializer != nullptr) { - customInitializer(this); - } - }; - CTOAST_API LuaInstance() { - L = luaL_newstate(); - luaopen_base(L); // Opens basic functions (_G) - luaopen_table(L); // Opens table library - luaopen_string(L); // Opens string library - luaopen_math(L); // Opens math library - lua_pushnil(L); - lua_setglobal(L, "dofile"); // Remove dofile (prevents running files) - lua_pushnil(L); - lua_setglobal(L, "loadfile"); // Remove loadfile (prevents loading scripts) - lua_pushnil(L); - lua_setglobal(L, "load"); // Remove load (prevents running arbitrary Lua code) - lua_pushnil(L); - lua_setglobal(L, "require"); // Remove require (prevents loading additional modules) - - } - }; - -} diff --git a/main.xml b/main.xml index d6fc764..65b258b 100644 --- a/main.xml +++ b/main.xml @@ -1,6 +1,11 @@ + - - + + + hi + + \ No newline at end of file diff --git a/src/CToastAPI.cpp b/src/CToastAPI.cpp deleted file mode 100644 index 5e7b70d..0000000 --- a/src/CToastAPI.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/** -* Copyright (c) 2025 thebest12lines -* Permission is hereby granted, free of charge, to any person obtaining a copy of this software -* and associated documentation files (the "Software"), to deal in the Software without restriction, -* including without limitation the rights to use, copy, modify, merge, publish, distribute, -* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING -* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ -typedef unsigned char byte; -#include -#include "ui/Label.h" -#include "CToastAPI.h" -#include "ui/Component.h" -#include "ui/Components.h" -#include "Console.h" -#include -#include "ui/TextComponent.h" -#include -using namespace CinnamonToast; -namespace { - vector cull = {}; -} - -ComponentId ExternalAPI::GetComponentById(const char* id) { - - cull.push_back(id); - return cull.size(); -}; -const char* ExternalAPI::GetComponentText(ComponentId ref) { - // Ensure the ref is within bounds - if (ref - 1 < 0 || ref - 1 >= cull.size()) { - - return nullptr; // Return null if invalid - } - - // Attempt dynamic_cast to TextComponent* - TextComponent* comp = (TextComponent*) (Components::GetComponentById(cull[ref - 1])); - Label* label = dynamic_cast(comp); - if (label) { - - string* text = new string(label->GetText()); - const char* textc = text->c_str(); - - return textc; - } else { - Console::warn("cast for component failed! (nullptr)", "GetComponentText"); - return nullptr; // Return null if the cast fails - } -} diff --git a/src/CToastAPI.h b/src/CToastAPI.h deleted file mode 100644 index eaca40c..0000000 --- a/src/CToastAPI.h +++ /dev/null @@ -1,33 +0,0 @@ -/** -* Copyright (c) 2025 thebest12lines -* Permission is hereby granted, free of charge, to any person obtaining a copy of this software -* and associated documentation files (the "Software"), to deal in the Software without restriction, -* including without limitation the rights to use, copy, modify, merge, publish, distribute, -* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING -* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ -#pragma once -typedef unsigned char byte; -#include -#include "TypeDefinitions.h" -#include "ui/Colors.h" -#include -namespace CinnamonToast { - typedef unsigned long long ComponentId; - struct CToastAPI { - ComponentId(*GetComponentById)(const char* id); - const char* (*GetComponentText)(ComponentId ref); - }; - namespace ExternalAPI { - CTOAST_API ComponentId GetComponentById(const char* id); - CTOAST_API const char* GetComponentText(ComponentId ref); - } - typedef void (*SharedLibraryMain)(CToastAPI* api); -} \ No newline at end of file diff --git a/src/Console.h b/src/Console.h deleted file mode 100644 index 86fc580..0000000 --- a/src/Console.h +++ /dev/null @@ -1,53 +0,0 @@ -/** -* Copyright (c) 2025 thebest12lines -* Permission is hereby granted, free of charge, to any person obtaining a copy of this software -* and associated documentation files (the "Software"), to deal in the Software without restriction, -* including without limitation the rights to use, copy, modify, merge, publish, distribute, -* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING -* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ -#pragma once - -#include "TypeDefinitions.h" -#include -#include -using namespace std; - -namespace CinnamonToast { - namespace Console { - - // std:: part is omitted because of `using namespace std;`. - template - CTOAST_API void print(const T& obj) { - cout << obj; - }; - template - CTOAST_API void println(const T& obj) { - cout << obj << endl; - }; - template - CTOAST_API void error(const T& obj, string ctx = "default") { - cerr << "[ERROR] " << "[" << ctx << "]: " << obj << endl; - }; - template - CTOAST_API void info(const T& obj, string ctx = "default") { - cout << "[INFO] " << "[" << ctx << "]: " << obj << endl; - }; - template - CTOAST_API void warn(const T& obj, string ctx = "default") { - cout << "[WARN] " << "[" << ctx << "]: " << obj << endl; - }; - template - CTOAST_API void debug(const T& obj, string ctx = "default") { - cout << "[DEBUG] " << "[" << ctx << "]: " << obj << endl; - }; - } -} - diff --git a/src/CrashHandler.h b/src/CrashHandler.h deleted file mode 100644 index 777c3b7..0000000 --- a/src/CrashHandler.h +++ /dev/null @@ -1,64 +0,0 @@ -/** -* Copyright (c) 2025 thebest12lines -* Permission is hereby granted, free of charge, to any person obtaining a copy of this software -* and associated documentation files (the "Software"), to deal in the Software without restriction, -* including without limitation the rights to use, copy, modify, merge, publish, distribute, -* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING -* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ -#pragma once -#include -#include "TypeDefinitions.h" -#include -#include - -#define CRASH_UNHANDLED_EXCEPTION 0x10 -#define CRASH_INVOKE 0x100 -#define CRASH_SEGFAULT 0x1 -typedef void (*CrashFunction)(); - -namespace CinnamonToast { - struct CrashConfig { - uint32_t MessageType; - uint32_t CrashType; - }; - class CrashHandler { - private: - CrashFunction customCrash; - bool active; - bool throwHandle; - bool throwCrash; - CrashConfig config; - __declspec(dllimport) void Activate(); - __declspec(dllimport) void Deactivate(); - - public: - __declspec(dllimport) CrashHandler(CrashConfig cf); - __declspec(dllimport) void SetCustomCrashHandler(CrashFunction func); - __declspec(dllimport) void InvokeCrash(string crashMessage); - - // Note: explicitly need to define try-catch block and to call this method - __declspec(dllimport) void InvokeUnhandledExceptionCrash(exception& ex); - __declspec(dllimport) void SetUnhandledExceptionCrashFunction(CrashFunction function); - - friend class CrashManager; - - }; - class CrashManager { - private: - static CrashHandler* handler; - public: - __declspec(dllimport) static void SetActiveCrashHandler(CrashHandler* handler_); - __declspec(dllimport) static CrashHandler* GetActiveCrashHandler(); - }; - namespace Utilities { - bool CheckBit(unsigned int num, int n); - } -} \ No newline at end of file diff --git a/src/Definitions.h b/src/Definitions.h deleted file mode 100644 index eb2e252..0000000 --- a/src/Definitions.h +++ /dev/null @@ -1,77 +0,0 @@ -/** -* Copyright (c) 2025 thebest12lines -* Permission is hereby granted, free of charge, to any person obtaining a copy of this software -* and associated documentation files (the "Software"), to deal in the Software without restriction, -* including without limitation the rights to use, copy, modify, merge, publish, distribute, -* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING -* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ -#pragma once -#define DEFAULT_FONT "Segoe UI" - -/** - * External app name to be shown to the end user. -*/ -#define APP_NAME "Project CinnamonToast" - -/** - * Internal app version for compatibility checks. - */ -#define APP_INTERNAL_VERSION 0000003L - -/** - * External app version to be shown to the end user. - */ -#define APP_VERSION "1.2.0" - -/** - * Error code specification - * - * These error codes should be used to indicate a specific error. Some errors - * are platform-specific, and this is indicated by the second leftmost digit of the - * error code. The valid values are: - * 0x0 - Cross-platform - * 0x1 - Windows - * 0x2 - macOS - * 0x3 - Linux - * - * Examples are: 0x01000000 (an "error" code for a successful execution on Windows, though this is only - * for demonstation purposes and SHOULD NOT be used in code), 0x03badf00 (Linux), etc. - * - * - * There are some reserved return codes like 0x0000002 which is ALWAYS the "file not found" error. 0x00000000 - * is also another one of these codes. It's not necessarily an "error" code, though it is a return code for success. - */ - -/** - * Comment/uncomment this to toggle Win32 errors. - */ -#ifdef _WIN32 - #define WIN32_ERROR_CODES -#endif - -// Internal error codes and other things -#define ERROR_NO_FILES_SPECIFIED 0x000003f0L -#define ERROR_GENERIC_XML_ERROR 0x000003f1L -#define ERROR_XML_NO_ROOT 0x000003f2L -#define ERROR_XML_NO_WINDOW 0x000003f3L -#define ERROR_FILE_NOT_FOUND 0x0000002L -#define ERROR_FONT_NOT_FOUND 0x0000003L -#define ERROR_HEX_COLOR_MALFORMED 0x000003f4L -#define ERROR_LINUX_X11_NOT_INITIALIZED 0x030003f5L -#define ERROR_CANNOT_LOAD_SHARED_LIBRARY 0x000003f9L -#define ERROR_CANNOT_LOAD_LIBRARY_FUNCTION 0x000003faL -#define ERROR_XML_NOT_COMPATIBLE 0x000003fbL -#define ERROR_UNHANDLED_EXCEPTION 0x000003fcL -// Win32 specific errors -#if defined(_WIN32) && defined(WIN32_ERROR_CODES) - #define ERROR_WIN_PARENT_HWND_INVALID 0x010003f5L - // more errors go here -#endif \ No newline at end of file diff --git a/src/LuaAPI.cpp b/src/LuaAPI.cpp deleted file mode 100644 index 54140d2..0000000 --- a/src/LuaAPI.cpp +++ /dev/null @@ -1,121 +0,0 @@ -#ifdef CTOAST_LUA - #include "LuaAPI.h" - #include - #include - #include "ui/Components.h" - #include "ui/TextComponent.h" - #include "Console.h" - using namespace CinnamonToast; - namespace { - bool luaReadWrite = false; - } - int LuaAPI::LuaInfo(lua_State* L) { - const char* msg = lua_tostring(L, 1); - Console::info(msg); - return 0; - } - int LuaAPI::LuaWarn(lua_State* L) { - const char* msg = lua_tostring(L, 1); - Console::warn(msg); - return 0; - } - int LuaAPI::LuaCError(lua_State* L) { - const char* msg = lua_tostring(L, 1); - Console::error(msg); - return 0; - } - int LuaAPI::LuaDebug(lua_State* L) { - const char* msg = lua_tostring(L, 1); - Console::debug(msg); - return 0; - } - int LuaAPI::LuaGetComponentText(lua_State* L) { - // Retrieve the upvalue (Component pointer) - TextComponent* comp = (TextComponent*)lua_touserdata(L, lua_upvalueindex(1)); - - if (!comp) { - lua_pushnil(L); - return 1; - } - - // Call GetText() and return the result as a string - std::string text = comp->GetText(); - lua_pushstring(L, text.c_str()); - - return 1; - } - int LuaAPI::LuaReadFile(lua_State* L) { - if (!luaReadWrite) { - lua_pushnil(L); - return 1; - } - const char* path = lua_tostring(L, 1); - - std::ifstream file(path, ios::binary); - std::string content((std::istreambuf_iterator(file)), std::istreambuf_iterator()); - file.close(); - lua_pushstring(L, content.c_str()); - - - } - int LuaAPI::LuaWriteFile(lua_State* L) { - if (!luaReadWrite) { - lua_pushnil(L); - return 1; - } - const char* path = lua_tostring(L, 1); - const char* content = lua_tostring(L, 2); - std::ofstream file(path, ios::binary); - file << content; - file.close(); - lua_pushboolean(L, true); - return 1; - } - int LuaAPI::LuaRequestPermission(lua_State* L) { - string permission = string(lua_tostring(L, 1)); - if (permission == "PERMISSION_FILESYSTEM") { - int result = MessageBoxA(NULL, "The app is requesting permission for read/write operations. Are you sure?", "Permission Request", MB_YESNO | MB_ICONQUESTION); - if (result == IDYES) { - luaReadWrite = true; - lua_pushboolean(L, true); - return 1; - } - else { - lua_pushboolean(L, false); - return 1; - } - } - return 0; - } - // table constructor for components - int LuaAPI::GetComponentById(lua_State* L) { - const char* id = lua_tostring(L, 1); - Component* comp = Components::GetComponentById(id); - if (!comp) return 0; // If no component was found, return nil - - // Create a new Lua table to represent the object - lua_newtable(L); - - // Push the component pointer as a lightuserdata and store it as an upvalue - lua_pushlightuserdata(L, comp); - // upcast and see if its a text component - if (dynamic_cast(comp)) { - - lua_pushcclosure(L, LuaGetComponentText, 1); // Closure with 1 upvalue - lua_setfield(L, -2, "getText"); - } - - return 1; // Return the new table - } - void CinnamonToast::InjectLuaApis(LuaInstance* self) { - self->RegisterFunction("CinnamonToast", "getComponentById", LuaAPI::GetComponentById); - self->RegisterFunction("CinnamonToast", "requestPermission", LuaAPI::LuaRequestPermission); - self->RegisterFunction("info", LuaAPI::LuaInfo); - self->RegisterFunction("warn", LuaAPI::LuaWarn); - self->RegisterFunction("cerror", LuaAPI::LuaCError); - self->RegisterFunction("debug", LuaAPI::LuaDebug); - self->RegisterFunction("writeFile", LuaAPI::LuaWriteFile); - self->RegisterFunction("readFile", LuaAPI::LuaReadFile); - }; - -#endif \ No newline at end of file diff --git a/src/LuaAPI.h b/src/LuaAPI.h deleted file mode 100644 index 914340c..0000000 --- a/src/LuaAPI.h +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once -#ifdef CTOAST_LUA - typedef unsigned char byte; - #include "TypeDefinitions.h" - #include "../lua/CToastLua.h" - namespace CinnamonToast { - namespace LuaAPI { - CTOAST_API int GetComponentById(lua_State* L); - CTOAST_API int LuaGetComponentText(lua_State* L); - CTOAST_API int LuaInfo(lua_State* L); - CTOAST_API int LuaWarn(lua_State* L); - CTOAST_API int LuaCError(lua_State* L); - CTOAST_API int LuaReadFile(lua_State* L); - CTOAST_API int LuaWriteFile(lua_State* L); - CTOAST_API int LuaRequestPermission(lua_State* L); - CTOAST_API int LuaDebug(lua_State* L); - } - CTOAST_API void InjectLuaApis(LuaInstance* self); - } -#endif - - diff --git a/src/Main.cpp b/src/Main.cpp deleted file mode 100644 index d40ffbf..0000000 --- a/src/Main.cpp +++ /dev/null @@ -1,393 +0,0 @@ -/** -* Copyright (c) 2025 thebest12lines -* Permission is hereby granted, free of charge, to any person obtaining a copy of this software -* and associated documentation files (the "Software"), to deal in the Software without restriction, -* including without limitation the rights to use, copy, modify, merge, publish, distribute, -* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING -* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -// define byte as unsigned char to prevent conflicts -typedef unsigned char byte; - -// if win32 -#ifdef _WIN32 - // include windows.h - #include -#endif - -// standard libraries we need -#include -#include -#include -#include -#include -#include - - -// other libraries -#include "../lib/tinyxml2/tinyxml2.h" -#ifdef CTOAST_LUA - extern "C" { - #include "../lua/CToastLua.h" - } -#endif - -// our header files here -#include "Main.h" -#include "Console.h" -#include "CToastAPI.h" -#include "Utilities.h" -#include "Definitions.h" -#include "CrashHandler.h" -#include "TypeDefinitions.h" -// ui components -#include "ui/Label.h" -#include "ui/Button.h" -#include "ui/Colors.h" -#include "ui/Vector2.h" -#include "ui/Component.h" -#include "ui/Components.h" -#include "ui/TextComponent.h" -#ifdef CTOAST_LUA - #include "LuaAPI.h" -#endif -// windows-specific code -#ifdef _WIN32 - - // include commctrl.h (for visual styles) - #include - - // standard libs - #include - #include // for std::unique_ptr - #include - #include - #include - #include - - - - //using namespaces and alias - using namespace CinnamonToast::Console; - using namespace CinnamonToast::Utilities; - - namespace fs = std::filesystem; - - - /** - * Invokes and loads a .xml file and also loads the specific libraries. It will setup the GUI as well as - * registering APIs for the libraries to use. - */ - int ctoast InvokeExecutable(string xmlFile) { - // if lua enabled - - // load the xml file - tinyxml2::XMLDocument doc; - - // platform - info("platform: "+GetOSPlatformAndVersion(), "CLIMain"); - - // common control stuff - INITCOMMONCONTROLSEX icex; - icex.dwSize = sizeof(INITCOMMONCONTROLSEX); - icex.dwICC = ICC_STANDARD_CLASSES; - - InitCommonControlsEx(&icex); - - // file doesnt exist - if (!fs::exists(xmlFile)) { - // error and return - error("file not found!"); - return ERROR_FILE_NOT_FOUND; - } - - // debug print and load xml file - debug("loading XML file...","InvokeExecutable"); - tinyxml2::XMLError eResult = doc.LoadFile(xmlFile.c_str()); - - // error handling - if (eResult != tinyxml2::XML_SUCCESS) { - error(string("cannot load XML file: "+string(doc.ErrorStr()))); - return ERROR_GENERIC_XML_ERROR; - } - - // get the root element - debug("getting root...","InvokeExecutable"); - tinyxml2::XMLElement* root = doc.FirstChildElement("root"); - // handling - if (root == nullptr) { - error("no root element found."); - return ERROR_XML_NO_ROOT; - } - - // checking compat - debug("file is compatible with app?","InvokeExecutable"); - const uint32_t version = stoi(root->Attribute("version")); - if (version > APP_INTERNAL_VERSION) { - // handle and return - error("file not compatible! please upgrade to a newer version."); - return ERROR_XML_NOT_COMPATIBLE; - } - tinyxml2::XMLElement* winXml = root->FirstChildElement("window"); - if (winXml == nullptr) { - error("no window element found."); - return ERROR_XML_NO_WINDOW; - } - - #ifdef _WIN32 - debug("getting HINSTANCE...","InvokeExecutable"); - HINSTANCE hInstance = GetModuleHandle(nullptr); - debug("creating window...","InvokeExecutable"); - Window win(hInstance); - #endif - - debug("window title: "+string(winXml->Attribute("title")),"InvokeExecutable"); - win.SetTitle(winXml->Attribute("title")); - debug("resizing window...","InvokeExecutable"); - win.SetSize(Vector2(stoi(winXml->Attribute("width")), stoi(winXml->Attribute("height")))); - string bgColor = winXml->Attribute("bgColor"); - debug("setting window background color...","InvokeExecutable"); - if (bgColor == "systemDefault") { - win.SetColor(255,255,255); - } else { - if (bgColor.at(0) == '#' && bgColor.length() == 7) { - - const string hex = bgColor.substr(1); - - const uint8_t r = stoi(hex.substr(0,2), nullptr, 16); - const uint8_t g = stoi(hex.substr(2,2), nullptr, 16); - const uint8_t b = stoi(hex.substr(4,2), nullptr, 16); - const Color3 color = { r,g,b }; - win.SetColor(color); - } else { - error("invalid hex color representation"); - return ERROR_HEX_COLOR_MALFORMED; - } - - - } - debug("parsing labels...","InvokeExecutable"); - for (tinyxml2::XMLElement* label = winXml->FirstChildElement("label"); label != nullptr; label = label->NextSiblingElement("label")) { - // Access attributes - string c = string(label->GetText()); - string* contents = &c; - string id = label->Attribute("id"); - Vector2 position(stoi(label->Attribute("x")),stoi(label->Attribute("y"))); - Label* labelComp = new Label(*contents, position); - labelComp->SetFont(label->Attribute("font")); - labelComp->SetFontSize(stoi(label->Attribute("fontSize"))); - win.Add(*labelComp, id); - - } - debug("parsing buttons...", "InvokeExecutable"); - for (tinyxml2::XMLElement* button = winXml->FirstChildElement("button"); button != nullptr; button = button->NextSiblingElement("button")) { - string contents = button->GetText(); - string id = button->Attribute("id"); - Vector2 position(stoi(button->Attribute("x")), stoi(button->Attribute("y"))); - Button buttonComp(contents, position); - buttonComp.SetFont(button->Attribute("font")); - buttonComp.SetFontSize(stoi(button->Attribute("fontSize"))); - win.Add(buttonComp,id); - - - } - debug("loading libraries...", "InvokeExecutable"); - #ifdef CTOAST_LUA - LuaInstance* lua = nullptr; - #endif - - for (tinyxml2::XMLElement* sharedLib = winXml->FirstChildElement("library"); sharedLib != nullptr; sharedLib = sharedLib->NextSiblingElement("library")) { - if (string(sharedLib->Attribute("type")) == "native") { - HMODULE hDll = LoadLibrary((const char*)(fs::absolute(fs::path(xmlFile)).parent_path().string() + "\\" + sharedLib->Attribute("location")).c_str()); - if (!hDll) { - error("cannot load shared library", "InvokeExecutable"); - return ERROR_CANNOT_LOAD_SHARED_LIBRARY; - } - debug("loaded shared library!", "InvokeExecutable"); - - // Get the address of the Add function - SharedLibraryMain mainFunc = (SharedLibraryMain)GetProcAddress(hDll, "CToastMain"); - if (!mainFunc) { - error("cannot find CToastMain function of library!", "InvokeExecutable"); - - FreeLibrary(hDll); // Free the DLL - return ERROR_CANNOT_LOAD_LIBRARY_FUNCTION; - } - CToastAPI ctoastApi = { ExternalAPI::GetComponentById, ExternalAPI::GetComponentText }; - mainFunc(&ctoastApi); - } - #ifdef CTOAST_LUA - else if (string(sharedLib->Attribute("type")) == "lua") { - debug("loading lua file...", "InvokeExecutable"); - if (lua == nullptr) { - debug("initializing lua...", "InvokeExecutable"); - lua = new LuaInstance(); - lua->InitializeLuaApis(InjectLuaApis); - } - - lua->ExecuteFile((fs::absolute(fs::path(xmlFile)).parent_path().string() + "\\" + sharedLib->Attribute("location")).c_str()); - - } - #endif - - } - debug("entering main loop...","InvokeExecutable"); - win.SetVisible(true); - - return win.Run(); - } - int ctoast CLIMain(const uint8_t argc, const vector argv) { - CrashConfig config = {}; - config.CrashType = CRASH_INVOKE | CRASH_SEGFAULT | CRASH_UNHANDLED_EXCEPTION; - - CrashHandler* ch = new CrashHandler(config); - CrashManager::SetActiveCrashHandler(ch); - - try { - println(APP_NAME+string(" ")+APP_VERSION); - if (argv.size() == 1) { - error("error: no files specified. please pass an argument to a valid file"); - error("error code: ERROR_NO_FILES_SPECIFIED"); - return ERROR_NO_FILES_SPECIFIED; - } else { - info("launching executable...","CLIMain"); - return CinnamonToast::InvokeExecutable(argv[1]); - } - } catch (exception e) { - ch->InvokeUnhandledExceptionCrash(e); - } - } - - - -#elif __linux__ - #include - #include - #include - #include - #include - #include - - #include - - - - using namespace CinnamonToast::Console; - using namespace CinnamonToast::Utilities; - namespace fs = std::filesystem; - - - - int ctoast InvokeExecutable(string xmlFile) { - tinyxml2::XMLDocument doc; - // Load the XML file - info("Platform: "+GetOSPlatformAndVersion(), "CLIMain"); - if (!fs::exists(xmlFile)) { - error("file not found!"); - return error_file_not_found; - } - debug("loading XML file...","InvokeExecutable"); - tinyxml2::XMLError eResult = doc.LoadFile(xmlFile.c_str()); - - if (eResult != tinyxml2::XML_SUCCESS) { - error(string("cannot load XML file: "+string(doc.ErrorStr()))); - return error_generic_xml_error; - } - - // Get the root element - debug("getting root...","InvokeExecutable"); - tinyxml2::XMLElement* root = doc.FirstChildElement("root"); - if (root == nullptr) { - error("no root element found."); - return error_xml_no_root; - } - debug("file is compatible with app?","InvokeExecutable"); - const uint32_t version = stoi(root->Attribute("version")); - if (version > app_internal_version) { - error("file not compatible! please upgrade to a newer version."); - } - tinyxml2::XMLElement* winXml = root->FirstChildElement("window"); - if (winXml == nullptr) { - error("no window element found."); - return error_xml_no_window; - } - - #ifdef _WIN32 - debug("getting HINSTANCE...","InvokeExecutable"); - HINSTANCE hInstance = GetModuleHandle(nullptr); - debug("creating window...","InvokeExecutable"); - Window win(hInstance); - #elif __linux__ - Window win(XOpenDisplay(NULL)); - #endif - - debug("window title: "+string(winXml->Attribute("title")),"InvokeExecutable"); - win.SetTitle(winXml->Attribute("title")); - debug("resizing window...","InvokeExecutable"); - win.SetSize(Vector2(stoi(winXml->Attribute("width")), stoi(winXml->Attribute("height")))); - string bgColor = winXml->Attribute("bgColor"); - debug("setting window background color...","InvokeExecutable"); - if (bgColor == "systemDefault") { - win.SetColor(255,255,255); - } else { - if (bgColor.at(0) == '#' && bgColor.length() == 7) { - - const string hex = bgColor.substr(1); - - const uint8_t r = stoi(hex.substr(0,2), nullptr, 16); - const uint8_t g = stoi(hex.substr(2,2), nullptr, 16); - const uint8_t b = stoi(hex.substr(4,2), nullptr, 16); - - win.SetColor(r,g,b); - } else { - error("invalid hex color representation"); - return error_hex_color_malformed; - } - - - } - debug("parsing labels...","InvokeExecutable"); - for (tinyxml2::XMLElement* label = winXml->FirstChildElement("label"); label != nullptr; label = label->NextSiblingElement("label")) { - // Access attributes - string contents = label->GetText(); - Vector2 position(stoi(label->Attribute("x")),stoi(label->Attribute("y"))); - Label* labelComp = new Label(contents, position); - labelComp->SetFont(label->Attribute("font")); - labelComp->SetFontSize(stoi(label->Attribute("fontSize"))); - - win.Add(labelComp); - - - } - debug("entering main loop...","InvokeExecutable"); - win.SetVisible(true); - - return win.Run(); - } - int ctoast CLIMain(const uint8_t argc, const vector argv) { - println(app_name+string(" ")+app_version); - if (argv.size() == 1) { - error("error: no files specified. please pass an argument to a valid file"); - error("error code: ERROR_NO_FILES_SPECIFIED"); - return error_no_files_specified; - } else { - info("launching executable...","CLIMain"); - return CinnamonToast::InvokeExecutable(argv[1]); - } - } -#endif -// Main entrypoint - -#ifndef CTOAST_API_library -int main(const int argc, const char* argv[]) { - return CinnamonToast::CLIMain(argc, CstrArrToVector(argv)); -} -#endif \ No newline at end of file diff --git a/src/Main.h b/src/Main.h deleted file mode 100644 index 87e521a..0000000 --- a/src/Main.h +++ /dev/null @@ -1,27 +0,0 @@ -/** -* Copyright (c) 2025 thebest12lines -* Permission is hereby granted, free of charge, to any person obtaining a copy of this software -* and associated documentation files (the "Software"), to deal in the Software without restriction, -* including without limitation the rights to use, copy, modify, merge, publish, distribute, -* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING -* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ -#include -#include -#include -#include "TypeDefinitions.h" - -#pragma once - -namespace CinnamonToast { - CTOAST_API int InvokeExecutable(string xmlFile); - CTOAST_API int CLIMain(const uint8_t argc, const vector argv); -} -int main(const int argc, const char* argv[]); \ No newline at end of file diff --git a/src/Utilities.cpp b/src/Utilities.cpp deleted file mode 100644 index 4d05872..0000000 --- a/src/Utilities.cpp +++ /dev/null @@ -1,127 +0,0 @@ -/** -* Copyright (c) 2025 thebest12lines -* Permission is hereby granted, free of charge, to any person obtaining a copy of this software -* and associated documentation files (the "Software"), to deal in the Software without restriction, -* including without limitation the rights to use, copy, modify, merge, publish, distribute, -* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING -* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ -#include "TypeDefinitions.h" -#include "Utilities.h" - -vector ctoast Utilities::CstrArrToVector(const char* arr[]) { - vector vec; - - // Iterate through the array until the end (null pointer) - for (int i = 0; arr[i] != nullptr; ++i) { - vec.push_back(string(arr[i])); // Convert each const char* to string - } - - return vec; -} -vector ctoast Utilities::SplitString(std::string str, char delimiter) { - std::vector result; - std::string token; - for (char ch : str) { - if (ch == delimiter) { - if (!token.empty()) { - result.push_back(token); // Add token to the result - } - token.clear(); // Reset the token - } else { - token += ch; // Append current character to the token - } - } - if (!token.empty()) { - result.push_back(token); // Add the last token, if any - } - return result; -} - -#ifdef _WIN32 - HFONT ctoast Utilities::GetFont(string fontName, int size, int fontWeight, bool italic, bool underline, bool strikeout) { - - HFONT hFont = CreateFont( - size, // Height of font - 0, // Width of font (0 for default) - 0, // Angle of escapement - 0, // Orientation angle - fontWeight, // Font weight - italic, // Italic - underline, // Underline - strikeout, // Strikeout - ANSI_CHARSET, // Character set - OUT_DEFAULT_PRECIS, // Output precision - CLIP_DEFAULT_PRECIS, // Clipping precision - DEFAULT_QUALITY, // Quality - DEFAULT_PITCH | FF_SWISS, // Pitch and family - fontName.c_str() // Typeface name - ); - - return hFont; - } - string ctoast Utilities::GetLastErrorAsString() { - DWORD errorMessageID = ::GetLastError(); // Get the last error code - if (errorMessageID == 0) { - return "No error"; // No error occurred - } - - LPSTR messageBuffer = nullptr; - - // Format the error message - size_t size = FormatMessageA( - FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, - errorMessageID, - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - (LPSTR)&messageBuffer, - 0, - NULL - ); - - std::string message(messageBuffer, size); - - // Free the buffer allocated by FormatMessage - LocalFree(messageBuffer); - - return message; - } -#endif -#ifdef _WIN32 - #include - #include - string ctoast Utilities::GetOSPlatformAndVersion() { - OSVERSIONINFO osvi; - stringstream ss; - osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); - if (GetVersionEx(&osvi)) { - ss << "Windows " << osvi.dwMajorVersion << "." - << osvi.dwMinorVersion << " " - << osvi.szCSDVersion << std::endl; - } - return ss.str(); - } - -#elif __linux__ - #include - #include - - string ctoast Utilities::GetOSPlatformAndVersion() { - struct utsname buffer; - stringstream ss; - if (uname(&buffer) == 0) { - ss << "Linux " << buffer.sysname << " " - << buffer.release << " " - << buffer.version << " " - << buffer.machine << std::endl; - } - return ss.str(); - } -#endif diff --git a/src/Utilities.h b/src/Utilities.h deleted file mode 100644 index e4a856e..0000000 --- a/src/Utilities.h +++ /dev/null @@ -1,39 +0,0 @@ -/** -* Copyright (c) 2025 thebest12lines -* Permission is hereby granted, free of charge, to any person obtaining a copy of this software -* and associated documentation files (the "Software"), to deal in the Software without restriction, -* including without limitation the rights to use, copy, modify, merge, publish, distribute, -* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING -* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ -#pragma once - -#ifdef _WIN32 - #include // or any other conflicting headers -#endif -#include -#include "TypeDefinitions.h" -#include "Definitions.h" -#include - - -namespace CinnamonToast { - namespace Utilities { - CTOAST_API vector CstrArrToVector(const char* arr[]); - CTOAST_API vector SplitString(std::string str, char delimiter); - - #ifdef _WIN32 - CTOAST_API HFONT GetFont(string fontName = DEFAULT_FONT, int size = 16, int fontWeight = 400, bool italic = false, bool underline = false, bool strikeout = false); - CTOAST_API string GetLastErrorAsString(); - #endif - CTOAST_API string GetOSPlatformAndVersion(); - } -} - diff --git a/src/api/cstyle/CToastC.cpp b/src/api/cstyle/CToastC.cpp new file mode 100644 index 0000000..a145a0e --- /dev/null +++ b/src/api/cstyle/CToastC.cpp @@ -0,0 +1,39 @@ +#include "../../core/CToastAPI.h" + +#include "CToastC.h" + +using namespace CinnamonToast; + +CTOAST_API CToastComponent CToast_getComponentById(CToastString id) { + + return {(uint8_t)ExternalAPI::getComponentById(id)}; +}; +CTOAST_API bool CToast_setColor(CToastComponent component, uint8_t r, uint8_t g, + uint8_t b) { + ExternalAPI::setComponentColor(component.id, r, g, b); + return true; +}; +CTOAST_API CToastString CToast_getText(CToastComponent component) { + return ExternalAPI::getComponentText(component.id); +} +CTOAST_API bool CToast_addComponent(CToastComponent parent, + CToastComponent child) { + ExternalAPI::addComponent(parent.id, child.id); + return true; +}; +CTOAST_API bool CToast_setVisibleCommand(CToastComponent comp, uint8_t cmd) { + ExternalAPI::setComponentVisibleCommand(comp.id, cmd); + return true; +}; +CTOAST_API bool CToast_setVisible(CToastComponent comp, bool flag) { + ExternalAPI::setComponentVisible(comp.id, flag); + return true; +} +CTOAST_API bool CToast_setFont(CToastComponent comp, CToastString font) { + ExternalAPI::setComponentFont(comp.id, font); + return true; +} +CTOAST_API bool CToast_setFontSize(CToastComponent comp, uint8_t fontSize) { + ExternalAPI::setComponentFontSize(comp.id, fontSize); + return true; +}; \ No newline at end of file diff --git a/src/api/cstyle/CToastC.h b/src/api/cstyle/CToastC.h new file mode 100644 index 0000000..4d28074 --- /dev/null +++ b/src/api/cstyle/CToastC.h @@ -0,0 +1,43 @@ +// pragma once if supported +#if defined(__cplusplus) && (defined(_MSVC_VER) || defined(__GNUC__) || \ + defined(__clang__) || defined(__MINGW__)) +#pragma once +#endif + +#ifndef CTOASTC_H +#define CTOASTC_H +#undef CTOAST_API +#ifdef CTOAST_BUILDING +#define CTOAST_API __declspec(dllexport) +#else +#define CTOAST_API __declspec(dllimport) +#endif +#ifdef __cplusplus +#include "../../src/core/ui/Components.h" +#include +#else +#include +#include +#endif // + +#ifdef __cplusplus +extern "C" { +#endif +typedef struct { + uint8_t id; +} CToastComponent; +typedef const char *CToastString; +CTOAST_API CToastComponent CToast_getComponentById(CToastString id); +CTOAST_API bool CToast_setColor(CToastComponent component, uint8_t r, uint8_t g, + uint8_t b); +CTOAST_API CToastString CToast_getText(CToastComponent component); +CTOAST_API bool CToast_addComponent(CToastComponent parent, + CToastComponent child); +CTOAST_API bool CToast_setVisibleCommand(CToastComponent comp, uint8_t cmd); +CTOAST_API bool CToast_setVisible(CToastComponent comp, bool flag); +CTOAST_API bool CToast_setFont(CToastComponent comp, CToastString font); +CTOAST_API bool CToast_setFontSize(CToastComponent comp, uint8_t fontSize); +#ifdef __cplusplus +} +#endif +#endif diff --git a/src/api/cstyle/CToastCExtern.h b/src/api/cstyle/CToastCExtern.h new file mode 100644 index 0000000..caf8a47 --- /dev/null +++ b/src/api/cstyle/CToastCExtern.h @@ -0,0 +1,36 @@ +// pragma once if supported +#if defined(__cplusplus) && (defined(_MSVC_VER) || defined(__GNUC__) || \ + defined(__clang__) || defined(__MINGW__)) +#pragma once +#endif + +#ifndef CTOASTC_H +#define CTOASTC_H +#ifdef __cplusplus +#include "../core/ui/Components.h" +#include +#else +#include +#include +#endif // + +#ifdef __cplusplus +extern "C" { +#endif +typedef struct { + uint8_t id; +} CToastComponent; +typedef const char *CToastString; +CToastComponent CToast_getComponentById(CToastString id); +bool CToast_setColor(CToastComponent component, uint8_t r, uint8_t g, + uint8_t b); +CToastString CToast_getText(CToastComponent component); +bool CToast_addComponent(CToastComponent parent, CToastComponent child); +bool CToast_setVisibleCommand(CToastComponent comp, uint8_t cmd); +bool CToast_setVisible(CToastComponent comp, bool flag); +bool CToast_setFont(CToastComponent comp, CToastString font); +bool CToast_setFontSize(CToastComponent comp, uint8_t fontSize); +#ifdef __cplusplus +} +#endif +#endif diff --git a/src/api/java/CToastJava.c b/src/api/java/CToastJava.c new file mode 100644 index 0000000..982f575 --- /dev/null +++ b/src/api/java/CToastJava.c @@ -0,0 +1,37 @@ +#include "CToastJava.h" +#include "../cstyle/CToastCExtern.h" +#include "CToastJavaUtil.h" +#include + +JNIEXPORT jint JNICALL JavaFunction(CToastNative, + getReferenceById)(JNI_PARAM_DECL, + jstring id) { + // Convert jstring to const char* + const char *nativeId = (*env)->GetStringUTFChars(env, id, 0); + + // Get the component reference using the nativeId + CToastComponent ref = CToast_getComponentById(nativeId); + + // Release the jstring memory + (*env)->ReleaseStringUTFChars(env, id, nativeId); + + // Return the component id as jint + return (jint)ref.id; +} + +JNIEXPORT jstring JNICALL JavaFunction(CToastNative, getText)(JNI_PARAM_DECL, + jint ref) { + CToastComponent comp; + comp.id = ref; + return (*env)->NewStringUTF(env, CToast_getText(comp)); +} + +JNIEXPORT void JNICALL JavaFunction(CToastNative, addComp)(JNI_PARAM_DECL, + jint parentRef, + jint compRef) { + CToastComponent comp1; + comp1.id = parentRef; + CToastComponent comp2; + comp2.id = compRef; + CToast_addComponent(comp1, comp2); +} diff --git a/src/api/java/CToastJava.h b/src/api/java/CToastJava.h new file mode 100644 index 0000000..d8b0123 --- /dev/null +++ b/src/api/java/CToastJava.h @@ -0,0 +1,104 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class ctoast4j_CToastNative */ + +#ifndef _Included_ctoast4j_CToastNative +#define _Included_ctoast4j_CToastNative +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: ctoast4j_CToastNative + * Method: getReferenceById + * Signature: (Ljava/lang/String;)I + */ +JNIEXPORT jint JNICALL Java_ctoast4j_CToastNative_getReferenceById(JNIEnv *, + jclass, + jstring); + +/* + * Class: ctoast4j_CToastNative + * Method: getText + * Signature: (I)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_ctoast4j_CToastNative_getText(JNIEnv *, jclass, + jint); + +/* + * Class: ctoast4j_CToastNative + * Method: addComp + * Signature: (II)V + */ +JNIEXPORT void JNICALL Java_ctoast4j_CToastNative_addComp(JNIEnv *, jclass, + jint, jint); + +/* + * Class: ctoast4j_CToastNative + * Method: createLabel + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_ctoast4j_CToastNative_createLabel(JNIEnv *, jclass); + +/* + * Class: ctoast4j_CToastNative + * Method: setText + * Signature: (ILjava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_ctoast4j_CToastNative_setText(JNIEnv *, jclass, + jint, jstring); + +/* + * Class: ctoast4j_CToastNative + * Method: renderComp + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_ctoast4j_CToastNative_renderComp(JNIEnv *, jclass, + jint); + +/* + * Class: ctoast4j_CToastNative + * Method: setSize + * Signature: (III)V + */ +JNIEXPORT void JNICALL Java_ctoast4j_CToastNative_setSize(JNIEnv *, jclass, + jint, jint, jint); + +/* + * Class: ctoast4j_CToastNative + * Method: getColor + * Signature: (I)[I + */ +JNIEXPORT jintArray JNICALL Java_ctoast4j_CToastNative_getColor(JNIEnv *, + jclass, jint); + +/* + * Class: ctoast4j_CToastNative + * Method: setColor + * Signature: (IIII)V + */ +JNIEXPORT void JNICALL Java_ctoast4j_CToastNative_setColor(JNIEnv *, jclass, + jint, jint, jint, + jint); + +/* + * Class: ctoast4j_CToastNative + * Method: setVisible + * Signature: (IZ)V + */ +JNIEXPORT void JNICALL Java_ctoast4j_CToastNative_setVisible__IZ(JNIEnv *, + jclass, jint, + jboolean); + +/* + * Class: ctoast4j_CToastNative + * Method: setVisible + * Signature: (II)V + */ +JNIEXPORT void JNICALL Java_ctoast4j_CToastNative_setVisible__II(JNIEnv *, + jclass, jint, + jint); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/src/api/java/CToastJavaUtil.h b/src/api/java/CToastJavaUtil.h new file mode 100644 index 0000000..65d4d2e --- /dev/null +++ b/src/api/java/CToastJavaUtil.h @@ -0,0 +1,5 @@ +#ifndef _CTOAST_JAVA_UTIL_H +#define _CTOAST_JAVA_UTIL_H +#define JavaFunction(clazz, method) Java_ctoast4j_##clazz##_##method +#define JNI_PARAM_DECL JNIEnv *env, jclass clazz +#endif // !_CTOAST_JAVA_UTIL_H diff --git a/lua/CToastLua.cpp b/src/api/lua/CToastLua.cpp similarity index 100% rename from lua/CToastLua.cpp rename to src/api/lua/CToastLua.cpp diff --git a/src/api/lua/CToastLua.h b/src/api/lua/CToastLua.h new file mode 100644 index 0000000..1998675 --- /dev/null +++ b/src/api/lua/CToastLua.h @@ -0,0 +1,95 @@ +#pragma once +/** + * Copyright (c) 2025 thebest12lines + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED + * "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR + * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +#undef byte +typedef unsigned char byte; +#ifdef _WIN32 +#include +#endif + +extern "C" { +#include "lauxlib.h" +#include "lua.h" +#include "lualib.h" +} +#include "TypeDefinitions.h" +#include +#include +#include +#include + +extern "C++" { +namespace CinnamonToast { +template +concept ValidLuaType = std::is_same_v || std::is_same_v || + std::is_same_v; +template struct IsValidLuaTypeOrVectorTrait : std::false_type {}; + +template +struct IsValidLuaTypeOrVectorTrait> + : std::conditional_t || + IsValidLuaTypeOrVectorTrait::value, + std::true_type, std::false_type> {}; + +template +constexpr bool IsValidLuaTypeOrVector = IsValidLuaTypeOrVectorTrait::value; + +template +concept ValidLuaVector = requires(T t) { + typename T::value_type; + requires IsValidLuaTypeOrVector; +}; + +template +concept LuaType = ValidLuaType || ValidLuaVector; + +class LuaInstance { +private: + lua_State *L; + template CTOAST_IMPORT void setValue(int index, T value); + +public: + CTOAST_IMPORT void execute(std::string code); + CTOAST_IMPORT void executeFile(std::string filePath); + CTOAST_IMPORT void registerFunction(std::string name, lua_CFunction func); + + template CTOAST_IMPORT void setValue(std::string name, T value); + template + CTOAST_IMPORT void setValue(std::string hierarchy, std::string key, T value); + CTOAST_IMPORT void createTable(std::string name); + + // Note: hierarchy corresponds to the table hierarchy (not including the table + // itself), e.g. "table1.table2.table3" or "foo" (if foo.bar will be + // initialized). + CTOAST_IMPORT void createTable(std::string hierarchy, std::string name); + // CTOAST_IMPORT void SetValue(std::string tableName, std::string key, + // int value); + // CTOAST_IMPORT void SetValue(std::string tableName, std::string key, + // double value); + CTOAST_IMPORT void setValue(std::string tableName, std::string key, + std::string value); + CTOAST_IMPORT void registerFunction(std::string tableName, std::string name, + lua_CFunction func); + CTOAST_IMPORT void + initializeLuaApis(void (*customInitializer)(LuaInstance *self)); + CTOAST_IMPORT LuaInstance(); +}; + +} // namespace CinnamonToast +} diff --git a/src/api/lua/Console.h b/src/api/lua/Console.h new file mode 100644 index 0000000..83f1b3c --- /dev/null +++ b/src/api/lua/Console.h @@ -0,0 +1,50 @@ +/** + * Copyright (c) 2025 thebest12lines + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED + * "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR + * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +#pragma once + +#include "TypeDefinitions.h" +#include +#include + +namespace CinnamonToast { +namespace Console { + +// std:: part is omitted because of `using namespace std;`. +template CTOAST_API void print(const T &obj) { std::cout << obj; }; +template CTOAST_API void println(const T &obj) { + std::cout << obj << std::endl; +}; +template +CTOAST_API void ctoastError(const T &obj, std::string ctx = "default") { + std::cerr << "[ERROR] " << "[" << ctx << "]: " << obj << std::endl; +}; +template +CTOAST_API void ctoastInfo(const T &obj, std::string ctx = "default") { + std::cout << "[INFO] " << "[" << ctx << "]: " << obj << std::endl; +}; +template +CTOAST_API void warn(const T &obj, std::string ctx = "default") { + std::cout << "[WARN] " << "[" << ctx << "]: " << obj << std::endl; +}; +template +CTOAST_API void debug(const T &obj, std::string ctx = "default") { + std::cout << "[DEBUG] " << "[" << ctx << "]: " << obj << std::endl; +}; +} // namespace Console +} // namespace CinnamonToast diff --git a/src/api/lua/LuaInstance.h b/src/api/lua/LuaInstance.h new file mode 100644 index 0000000..b08f6b0 --- /dev/null +++ b/src/api/lua/LuaInstance.h @@ -0,0 +1,223 @@ +#pragma once +/** + * Copyright (c) 2025 thebest12lines + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED + * "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR + * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#include "Console.h" +#include "TypeDefinitions.h" +#include "lua.hpp" +#include +#include +#include +#include + +#define CTOAST_LUA_API "CinnamonToast" + +namespace CinnamonToast { +template +concept ValidLuaType = std::is_same_v || std::is_same_v || + std::is_same_v; +template struct IsValidLuaTypeOrVectorTrait : std::false_type {}; + +template +struct IsValidLuaTypeOrVectorTrait> + : std::conditional_t || + IsValidLuaTypeOrVectorTrait::value, + std::true_type, std::false_type> {}; + +template +constexpr bool IsValidLuaTypeOrVector = IsValidLuaTypeOrVectorTrait::value; + +template +concept ValidLuaVector = requires(T t) { + typename T::value_type; + requires IsValidLuaTypeOrVector; +}; + +template +concept LuaType = ValidLuaType || ValidLuaVector; + +class LuaInstance { +private: + lua_State *L; + template CTOAST_API void setValue(int index, T value) { + // push to stack + if constexpr (std::is_same_v) { + lua_pushinteger(L, value); + } else if constexpr (std::is_same_v) { + lua_pushnumber(L, value); + } else if constexpr (std::is_same_v) { + lua_pushstring(L, value.c_str()); + } else if constexpr (ValidLuaVector) { + lua_newtable(L); + for (int i = 0; i < value.size(); i++) { + if constexpr (ValidLuaType) { + SetValue(i + 1, value[i]); + } else if constexpr (ValidLuaVector) { + SetValue(i + 1, value[i]); + } + } + } + } + +public: + CTOAST_API void execute(std::string code) { luaL_dostring(L, code.c_str()); }; + CTOAST_API void executeFile(std::string filePath) { + luaL_dofile(L, filePath.c_str()); + }; + CTOAST_API void registerFunction(std::string name, lua_CFunction func) { + lua_register(L, name.c_str(), func); + }; + + template CTOAST_API void setValue(std::string name, T value) { + if constexpr (ValidLuaType) { + if constexpr (std::is_same_v) { + lua_pushinteger(L, value); + } else if constexpr (std::is_same_v) { + lua_pushnumber(L, value); + } else if constexpr (std::is_same_v) { + lua_pushstring(L, value.c_str()); + } + } else if constexpr (ValidLuaVector) { + lua_newtable(L); + for (int i = 0; i < value.size(); i++) { + SetValue(i + 1, value[i]); + } + } + lua_setglobal(L, name.c_str()); + }; + template + CTOAST_API void setValue(std::string hierarchy, std::string key, T value) { + std::vector tables; + std::string currentTable = ""; + for (int i = 0; i < hierarchy.size(); i++) { + if (hierarchy[i] == '.') { + tables.push_back(currentTable); + currentTable = ""; + } else { + currentTable += hierarchy[i]; + } + } + tables.push_back(currentTable); + lua_getglobal(L, tables[0].c_str()); + for (int i = 1; i < tables.size(); i++) { + lua_pushstring(L, tables[i].c_str()); + lua_gettable(L, -2); + } + if constexpr (ValidLuaType) { + if constexpr (std::is_same_v) { + lua_pushinteger(L, value); + } else if constexpr (std::is_same_v) { + lua_pushnumber(L, value); + } else if constexpr (std::is_same_v) { + lua_pushstring(L, value.c_str()); + } + } else if constexpr (ValidLuaVector) { + lua_newtable(L); + for (int i = 0; i < value.size(); i++) { + SetValue(i + 1, value[i]); + } + } + lua_setfield(L, -2, key.c_str()); + }; + CTOAST_API void setValue(std::string hierarchy, std::string key, + std::string value) { + std::vector tables; + std::string currentTable = ""; + for (int i = 0; i < hierarchy.size(); i++) { + if (hierarchy[i] == '.') { + tables.push_back(currentTable); + currentTable = ""; + } else { + currentTable += hierarchy[i]; + } + } + tables.push_back(currentTable); + lua_getglobal(L, tables[0].c_str()); + for (int i = 1; i < tables.size(); i++) { + lua_pushstring(L, tables[i].c_str()); + lua_gettable(L, -2); + } + lua_pushstring(L, value.c_str()); + lua_setfield(L, -2, key.c_str()); + } + CTOAST_API void createTable(std::string name) { + lua_newtable(L); + lua_setglobal(L, name.c_str()); + }; + + // Note: hierarchy corresponds to the table hierarchy (not including the table + // itself), e.g. "table1.table2.table3" or "foo" (if foo.bar will be + // initialized). + CTOAST_API void createTable(std::string hierarchy, std::string name) { + std::vector tables; + std::string currentTable = ""; + for (int i = 0; i < hierarchy.size(); i++) { + if (hierarchy[i] == '.') { + tables.push_back(currentTable); + currentTable = ""; + } else { + currentTable += hierarchy[i]; + } + } + tables.push_back(currentTable); + lua_getglobal(L, tables[0].c_str()); + for (int i = 1; i < tables.size(); i++) { + lua_pushstring(L, tables[i].c_str()); + lua_gettable(L, -2); + } + lua_newtable(L); + lua_setglobal(L, name.c_str()); + }; + /*void SetValue(std::string tableName, std::string key, int value); + void SetValue(std::string tableName, std::string key, double value); + void SetValue(std::string tableName, std::string key, std::string value);*/ + CTOAST_API void registerFunction(std::string tableName, std::string name, + lua_CFunction func) { + lua_getglobal(L, tableName.c_str()); + lua_pushcfunction(L, func); + lua_setfield(L, -2, name.c_str()); + }; + + CTOAST_API void + initializeLuaApis(void (*customInitializer)(LuaInstance *self)) { + createTable(CTOAST_LUA_API); + if (customInitializer != nullptr) { + customInitializer(this); + } + }; + CTOAST_API LuaInstance() { + L = luaL_newstate(); + luaopen_base(L); // Opens basic functions (_G) + luaopen_table(L); // Opens table library + luaopen_string(L); // Opens std::string library + luaopen_math(L); // Opens math library + lua_pushnil(L); + lua_setglobal(L, "dofile"); // Remove dofile (prevents running files) + lua_pushnil(L); + lua_setglobal(L, "loadfile"); // Remove loadfile (prevents loading scripts) + lua_pushnil(L); + lua_setglobal(L, + "load"); // Remove load (prevents running arbitrary Lua code) + lua_pushnil(L); + lua_setglobal( + L, "require"); // Remove require (prevents loading additional modules) + } +}; + +} // namespace CinnamonToast diff --git a/src/cli/Main.cpp b/src/cli/Main.cpp new file mode 100644 index 0000000..e5702b8 --- /dev/null +++ b/src/cli/Main.cpp @@ -0,0 +1,41 @@ +/** + * Copyright (c) 2025 thebest12lines + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED + * "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR + * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#ifndef CTOAST_TESTS +// set byte to unsigned char to prevent ambiguity +using byte = unsigned char; + +// if windows +#ifdef _WIN32 +#include +// visual styles +#pragma comment( \ + linker, \ + "\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version = '6.0.0.0' processorArchitecture = '*' publicKeyToken = '6595b64144ccf1df' language = '*'\"") +#endif +#include "Main.h" +#include "Utilities.h" + +// main function +int main(int argc, char const *argv[]) { + // expression to load ctoast + return CinnamonToast::cliMain( + argc, CinnamonToast::Utilities::cstrArrToVector(argv)); +} +#endif diff --git a/src/cli/Main.h b/src/cli/Main.h new file mode 100644 index 0000000..875dffe --- /dev/null +++ b/src/cli/Main.h @@ -0,0 +1,29 @@ +/** + * Copyright (c) 2025 thebest12lines + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED + * "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR + * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +#include "TypeDefinitions.h" +#include +#include +#include +#pragma once + +namespace CinnamonToast { +CTOAST_API int invokeExecutable(std::string xmlFile); +CTOAST_API int cliMain(const uint8_t argc, const std::vector argv); +} // namespace CinnamonToast +int main(const int argc, const char *argv[]); \ No newline at end of file diff --git a/src/cli/Utilities.h b/src/cli/Utilities.h new file mode 100644 index 0000000..c0cd0c6 --- /dev/null +++ b/src/cli/Utilities.h @@ -0,0 +1,43 @@ +/** + * Copyright (c) 2025 thebest12lines + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED + * "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR + * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +#pragma once + +#ifdef _WIN32 +#include // or any other conflicting headers +#endif +#include "Definitions.h" +#include "TypeDefinitions.h" +#include +#include + +namespace CinnamonToast { +namespace Utilities { +CTOAST_API std::vector cstrArrToVector(const char *arr[]); +CTOAST_API std::vector splitString(std::string str, + char delimiter); + +#ifdef _WIN32 +CTOAST_API HFONT getFont(std::string fontName = DEFAULT_FONT, int size = 16, + int fontWeight = 400, bool italic = false, + bool underline = false, bool strikeout = false); +CTOAST_API std::string getLastErrorAsString(); +#endif +CTOAST_API std::string getOSPlatformAndVersion(); +} // namespace Utilities +} // namespace CinnamonToast diff --git a/src/common/Console.h b/src/common/Console.h new file mode 100644 index 0000000..988191d --- /dev/null +++ b/src/common/Console.h @@ -0,0 +1,54 @@ +/** + * Copyright (c) 2025 thebest12lines + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED + * "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR + * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +#pragma once + +#include "TypeDefinitions.h" +#include +#include +#define ctoastPrint(obj) CinnamonToast::Console::print(obj); +#define ctoastPrintln(obj) CinnamonToast::Console::println(obj); +#define ctoastError(obj) CinnamonToast::Console::error(obj, __func__); +#define ctoastInfo(obj) CinnamonToast::Console::info(obj, __func__); +#define ctoastWarn(obj) CinnamonToast::Console::warn(obj, __func__); +#define ctoastDebug(obj) CinnamonToast::Console::debug(obj, __func__); +namespace CinnamonToast { +namespace Console { + +template CTOAST_API void print(const T &obj) { std::cout << obj; }; +template CTOAST_API void println(const T &obj) { + std::cout << obj << std::endl; +}; +template +CTOAST_API void error(const T &obj, std::string ctx = "default") { + std::cerr << "[ERROR] " << "[" << ctx << "]: " << obj << std::endl; +}; +template +CTOAST_API void info(const T &obj, std::string ctx = "default") { + std::cout << "[INFO] " << "[" << ctx << "]: " << obj << std::endl; +}; +template +CTOAST_API void warn(const T &obj, std::string ctx = "default") { + std::cout << "[WARN] " << "[" << ctx << "]: " << obj << std::endl; +}; +template +CTOAST_API void debug(const T &obj, std::string ctx = "default") { + std::cout << "[DEBUG] " << "[" << ctx << "]: " << obj << std::endl; +}; +} // namespace Console +} // namespace CinnamonToast diff --git a/src/common/Definitions.h b/src/common/Definitions.h new file mode 100644 index 0000000..2c19c20 --- /dev/null +++ b/src/common/Definitions.h @@ -0,0 +1,116 @@ +/** + * Copyright (c) 2025 thebest12lines + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED + * "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR + * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +#pragma once +/* +Default font for CinnamonToast to use. +*/ +#define DEFAULT_FONT "Segoe UI" + +/** + * External app name to be shown to the end user. + */ +#define APP_NAME "Project CinnamonToast" + +/** + * Internal app version for compatibility checks. + */ +#define APP_INTERNAL_VERSION 0x00000008L + +/** + * External app version to be shown to the end user. + */ +#define APP_VERSION "1.5.0" + +/** + * Error code specification + * + * These ctoastError codes should be used to indicate a specific ctoastError. + * Some ctoastErrors are platform-specific, and this is indicated by the second + * leftmost digit of the ctoastError code. The valid values are: 0x0 - + * Cross-platform 0x1 - Windows 0x2 + * - macOS 0x3 - Linux + * + * Examples are: 0x01000000 (an "ctoastError" code for a successful execution on + * Windows, though this is only for demonstation purposes and SHOULD NOT be used + * in code), 0x03badf00 (Linux), etc. + * + * + * There are some reserved return codes like 0x0000002 which is ALWAYS the "file + * not found" ctoastError. 0x00000000 is also another one of these codes. It's + * not necessarily an "ctoastError" code, though it is a return code for + * success. + */ + +/** + * Comment/uncomment this to toggle Win32 ctoastErrors. + */ +#ifdef _WIN32 +// Define Win32 ctoastError codes +#define WIN32_ERROR_CODES +#endif + +// Internal ctoastError codes and other things + +// Error for if there isn't a file specified. +#define CTOAST_ERROR_NO_FILES_SPECIFIED 0x000003f0L + +// Error for an XML ctoastError that does not originate from the program. +#define CTOAST_ERROR_GENERIC_XML_ERROR 0x000003f1L + +// Error for if the XML file does not have a root element. +#define CTOAST_ERROR_XML_NO_ROOT 0x000003f2L + +// Error for if the XML file does not have a window element inside the root +// element. +#define CTOAST_ERROR_XML_NO_WINDOW 0x000003f3L + +// Error for if a file is not found. +#define CTOAST_ERROR_FILE_NOT_FOUND 0x0000002L + +// Error for if a font is not found. +#define CTOAST_ERROR_FONT_NOT_FOUND 0x0000003L + +// Error if a hex color (like #ffffff) is malformed. +#define CTOAST_ERROR_HEX_COLOR_MALFORMED 0x000003f4L + +// A Linux-specific ctoastError that X11 isn't initialized. +#define CTOAST_ERROR_LINUX_X11_NOT_INITIALIZED 0x030003f5L + +// Error if the shared library (.dll, .so, etc.) can't be loaded primarily due +// to filesystem ctoastErrors or other reasons. +#define CTOAST_ERROR_CANNOT_LOAD_SHARED_LIBRARY 0x000003f9L + +// Error if the shared library's `CToastMain` function does not exist or there +// is another problem. +#define CTOAST_ERROR_CANNOT_LOAD_LIBRARY_FUNCTION 0x000003faL + +// Error if the XML document's app version is above the current app version. +#define CTOAST_ERROR_XML_NOT_COMPATIBLE 0x000003fbL + +// Error if an unhandled exception (std::exception) occurs. +#define CTOAST_ERROR_UNHANDLED_EXCEPTION 0x000003fcL + +// Win32 specific ctoastErrors +#if defined(_WIN32) && defined(WIN32_ERROR_CODES) + +// Error if the parent HWND (window handle) is invalid in Windows. +#define CTOAST_ERROR_WIN_PARENT_HWND_INVALID 0x010003f5L + +// more ctoastErrors go here +#endif \ No newline at end of file diff --git a/src/common/TypeDefinitions.h b/src/common/TypeDefinitions.h new file mode 100644 index 0000000..72af6f8 --- /dev/null +++ b/src/common/TypeDefinitions.h @@ -0,0 +1,72 @@ +/** + * Copyright (c) 2025 thebest12lines + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED + * "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR + * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +#pragma once +#include +#include +typedef unsigned char byte; +#include "Definitions.h" + +/* +The macro to specify whether or not CinnamonToast should export or import +functions. +*/ +#define CTOAST_API +#undef CTOAST_API +// Check if CTOAST_API is already defined +#if !defined(CTOAST_API) && !defined(CTOAST_BUILDING) +#define CTOAST_API __declspec(dllimport) +#define CTOAST_IMPORT __declspec(dllimport) +#ifdef __linux__ +#undef CTOAST_IMPORT +#define CTOAST_IMPORT extern +#endif +#endif +#ifdef CTOAST_BUNDLED +#undef CTOAST_IMPORT +#define CTOAST_IMPORT +#endif +#ifdef __linux__ +#include +typedef XID XWindow; +#endif +/* +Alias for CinnamonToast +*/ +#define ctoast CinnamonToast:: +#define LIBC_NAMESPACE CinnamonToast + +/* +The namespace which holds everything related to CinnamonToast as well as +additional types and objects. +*/ +namespace CinnamonToast {}; + +// if defined +#undef CTOAST_SHARED_LIBRARY +#define CTOAST_SHARED_LIBRARY + +#ifdef CTOAST_SHARED_LIBRARY +#ifdef _WIN32 +#undef CTOAST_API // Undefine CTOAST_API if it was previously defined +#define CTOAST_API __declspec(dllexport) +#elif __linux__ +#undef CTOAST_API // Undefine CTOAST_API if it was previously defined +#define CTOAST_API __attribute__((visibility("default"))) +#endif +#endif \ No newline at end of file diff --git a/src/core/CToastAPI.cpp b/src/core/CToastAPI.cpp new file mode 100644 index 0000000..b609493 --- /dev/null +++ b/src/core/CToastAPI.cpp @@ -0,0 +1,190 @@ +/** + * Copyright (c) 2025 thebest12lines + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED + * "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR + * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +typedef unsigned char byte; +#include "CToastAPI.h" +#include "Console.h" +#include "ui/Component.h" +#include "ui/Components.h" +#include "ui/Label.h" +#include "ui/TextComponent.h" +#include +#include +#include +using namespace CinnamonToast; +namespace { +std::vector cull = {}; +} + +ComponentId ExternalAPI::getComponentById(const char *id) { + + cull.push_back(id); + return cull.size(); +}; +const char *ExternalAPI::getComponentText(ComponentId ref) { + // Ensure the ref is within bounds + if (ref - 1 < 0 || ref - 1 >= cull.size()) { + + return nullptr; // Return null if invalid + } + + // Attempt dynamic_cast to TextComponent* + TextComponent *comp = + (TextComponent *)(Components::getComponentById(cull[ref - 1])); + Label *label = dynamic_cast