diff --git a/.gitmodules b/.gitmodules index adcfb3a5..ed276a42 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,3 @@ -[submodule "src/Engine/vendor/debugbreak"] - path = src/Engine/vendor/debugbreak - url = https://github.com/scottt/debugbreak.git [submodule "src/Engine/vendor/glm"] path = src/Engine/vendor/glm url = https://github.com/g-truc/glm @@ -10,9 +7,6 @@ [submodule "src/tests/vendor/gtest"] path = src/tests/vendor/gtest url = https://github.com/google/googletest -[submodule "src/Engine/vendor/gsl"] - path = src/Engine/vendor/gsl - url = https://github.com/microsoft/GSL.git [submodule "src/Engine/vendor/entt"] path = src/Engine/vendor/entt url = https://github.com/skypjack/entt.git @@ -50,6 +44,6 @@ [submodule "src/Engine/vendor/msdfgen/msdf-atlas-gen"] path = src/Engine/vendor/msdfgen/msdf-atlas-gen url = https://github.com/Chlumsky/msdf-atlas-gen -[submodule "src/Editor/vendor/ImGuizmo/imguizmo"] - path = src/Editor/vendor/ImGuizmo/imguizmo - url = https://github.com/CedricGuillemet/ImGuizmo +[submodule "src/Engine/vendor/ImGuizmo/imguizmo"] + path = src/Engine/vendor/ImGuizmo/imguizmo + url = https://github.com/CedricGuillemet/ImGuizmo.git diff --git a/CMakeLists.txt b/CMakeLists.txt index efe4a873..8de9127c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,10 @@ option(BEE_BUILD_SANDBOX OFF) option(BEE_BUILD_LOC_TOOL OFF) option(BEE_BUILD_EDITOR ON) option(BEE_BUILD_RUNTIME ON) +option(BEE_BUILD_BEEENGINE ON) +option(BEE_NO_DOTNET OFF "Disable dotnet and C# scripting") +message("Build BeeEngine library? ${BEE_BUILD_BEEENGINE}") message("Build Tests? ${BEE_BUILD_TESTS}") message("Build Sandbox? ${BEE_BUILD_SANDBOX}") message("Build Localization Tool? ${BEE_BUILD_LOC_TOOL}") @@ -109,7 +112,11 @@ include(cmake/StandardProjectSettings.cmake) #include(cmake/CompilerWarnings.cmake) #set_project_warnings(project_warnings) -add_subdirectory(src/Engine) +include(cmake/set_compile_definitions.cmake) + +if(${BEE_BUILD_BEEENGINE}) + add_subdirectory(src/Engine) +endif() if(${BEE_BUILD_SANDBOX}) add_subdirectory(src/Sandbox2D) endif() diff --git a/CMakePresets.json b/CMakePresets.json index 38d2c16c..3fdc3eb4 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -63,8 +63,39 @@ "CMAKE_BUILD_WITH_INSTALL_RPATH": "ON", "BEE_USE_VCPKG": "OFF", "NETHOST_LIB": "$env{NETHOST_LIB}", + "BEE_BUILD_BEEENGINE": "ON", "BEE_BUILD_EDITOR": "ON", "BEE_BUILD_LOC_TOOL": "ON", + "BEE_BUILD_RUNTIME": "ON", + "BEE_BUILD_TESTS": "ON", + "BEE_USE_SYSTEM_SDL3": "ON" + }, + "vendor": {}, + "condition": { + "type": "notEquals", + "lhs": "${hostSystemName}", + "rhs": "Windows" + } + }, + { + "name": "Release-NixOS", + "displayName": "Release-NixOS Config", + "description": "Release build using Ninja generator", + "generator": "Ninja", + "binaryDir": "${sourceDir}/build/Release-NixOS", + "installDir": "${sourceDir}/install/Release-NixOS", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Release", + "CMAKE_C_COMPILER": "gcc", + "CMAKE_CXX_COMPILER": "g++", + "CMAKE_BUILD_WITH_INSTALL_RPATH": "ON", + "BEE_USE_VCPKG": "OFF", + "NETHOST_LIB": "$env{NETHOST_LIB}", + "BEE_BUILD_BEEENGINE": "ON", + "BEE_BUILD_EDITOR": "OFF", + "BEE_BUILD_LOC_TOOL": "OFF", + "BEE_BUILD_RUNTIME": "OFF", + "BEE_BUILD_TESTS": "OFF", "BEE_USE_SYSTEM_SDL3": "ON" }, "vendor": {}, diff --git a/cmake/set_compile_definitions.cmake b/cmake/set_compile_definitions.cmake new file mode 100644 index 00000000..08f7237e --- /dev/null +++ b/cmake/set_compile_definitions.cmake @@ -0,0 +1,126 @@ +function(DesktopPlatformsOnly) + add_compile_definitions(DESKTOP_PLATFORM) +endfunction(DesktopPlatformsOnly) + +function(MobilePlatformsOnly) + add_compile_definitions(MOBILE_PLATFORM) +endfunction(MobilePlatformsOnly) + +if(IOS) + # Covers iOS implementation + set(BEE_COMPILE_WEBGPU OFF) + set(BEE_COMPILE_VULKAN ON) + set(BEE_COMPILE_SDL ON) +elseif(APPLE) + # Covers macOS implementation + DesktopPlatformsOnly() + set(BEE_COMPILE_WEBGPU OFF) + set(BEE_COMPILE_VULKAN ON) + set(BEE_COMPILE_SDL ON) +elseif(ANDROID) + # Covers Android implementation + MobilePlatformsOnly() + set(BEE_COMPILE_WEBGPU OFF) + set(BEE_COMPILE_VULKAN ON) + set(BEE_COMPILE_SDL ON) +elseif(WIN32) + # Covers Windows implementation + DesktopPlatformsOnly() + set(BEE_COMPILE_WEBGPU OFF) + set(BEE_COMPILE_VULKAN ON) + set(BEE_COMPILE_SDL OFF) +elseif (UNIX AND NOT APPLE) + # Covers Linux implementation + DesktopPlatformsOnly() + set(BEE_COMPILE_WEBGPU OFF) + set(BEE_COMPILE_VULKAN ON) + set(BEE_COMPILE_SDL ON) +endif() + +function(DesktopPlatformsOnlyPostTarget) + + +endfunction(DesktopPlatformsOnlyPostTarget) + +if(${BEE_COMPILE_WEBGPU}) + include(${CMAKE_CURRENT_LIST_DIR}/cmake/InstallWebGPU.cmake) +endif () + +if(IOS) + # Covers iOS implementation + add_compile_definitions(IOS) +elseif(APPLE) + # Covers macOS implementation + add_compile_definitions(MACOS) + DesktopPlatformsOnlyPostTarget() +elseif(ANDROID) + # Covers Android implementation + add_compile_definitions(ANDROID) +elseif(WIN32) + # Covers Windows implementation + add_compile_definitions(WINDOWS) + DesktopPlatformsOnlyPostTarget() +elseif (UNIX AND NOT APPLE) + # Covers Linux implementation + add_compile_definitions(LINUX) + DesktopPlatformsOnlyPostTarget() +endif() + +if(${BEE_COMPILE_WEBGPU}) + message("Compiling WebGPU") + add_compile_definitions(BEE_COMPILE_WEBGPU) +endif() + +if (${BEE_COMPILE_SDL}) + message("Compiling with SDL3") + add_compile_definitions(BEE_COMPILE_SDL) +endif() + +if(${BEE_COMPILE_VULKAN}) + message("Compiling with Vulkan") + add_compile_definitions(BEE_COMPILE_VULKAN) +endif() + +if (${BEE_USE_VCPKG}) +function(extract_vcpkg_path ICU_LIB_LIST RESULT_VAR) + list(GET ICU_LIB_LIST 0 ICU_LIB_PATH) + string(REGEX REPLACE "(.*/vcpkg_installed/[^/]+).*$" "\\1" EXTRACTED_PATH ${ICU_LIB_PATH}) + set(${RESULT_VAR} ${EXTRACTED_PATH} PARENT_SCOPE) +endfunction() + +extract_vcpkg_path("${ICU_LIBRARIES}" ICU_VCPKG_PATH) +set(ICU_INCLUDE_DIR ${ICU_VCPKG_PATH}/include) +endif() + +add_compile_definitions(GLM_FORCE_DEPTH_ZERO_TO_ONE) +add_compile_definitions(GLM_FORCE_LEFT_HANDED) + +add_compile_definitions($<$:DEBUG>) + +add_compile_definitions(BEE_ENABLE_CHECKS) + +add_compile_definitions($<$:BEE_ENABLE_ASSERTS>) +add_compile_definitions($<$:BEE_ENABLE_ASSERTS>) + +add_compile_definitions($<$:BEE_ENABLE_PROFILING>) +add_compile_definitions($<$:BEE_ENABLE_PROFILING>) # should be disabled in the future by default? + +add_compile_definitions($<$:BEE_VULKAN_ENABLE_VALIDATION_LAYERS>) + +add_compile_definitions($<$:RELEASE>) + +set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "Publish") + +if(CMAKE_BUILD_TYPE STREQUAL "Debug") + #add_compile_options(-O0) +endif() +if(CMAKE_BUILD_TYPE STREQUAL "Release") + add_compile_options(-O3) +endif() +if(CMAKE_BUILD_TYPE STREQUAL "Publish") + add_compile_options(-O3) +endif() + +if(NOT ${BEE_NO_DOTNET}) + add_compile_definitions(BEE_ENABLE_SCRIPTING) +endif() diff --git a/flake.nix b/flake.nix index cdf03629..f4a6d0f6 100644 --- a/flake.nix +++ b/flake.nix @@ -9,10 +9,17 @@ outputs = { self, nixpkgs, ... }@inputs: let inherit (nixpkgs) lib; eachSystem = lib.genAttrs [ "x86_64-linux" "aarch64-linux" ]; + defaultOverlay = system: + final: _prev: { + beeengineeditor = self.packages.${system}.BeeEngineEditor; + beelocalization = self.packages.${system}.BeeLocalization; + beeengine = self.packages.${system}.BeeEngine; + }; pkgsFor = eachSystem (system: import nixpkgs { localSystem = system; overlays = with self.overlays; [ + (defaultOverlay system) ]; }); pkgsCrossFor = eachSystem (system: crossSystem: @@ -20,15 +27,12 @@ localSystem = system; inherit crossSystem; overlays = with self.overlays; [ + (defaultOverlay system) ]; }); src = self; in { - overlays = eachSystem (system: - final: _prev: { - beeengineeditor = self.packages.${system}.BeeEngineEditor; - beelocalization = self.packages.${system}.BeeLocalization; - }); + overlays = eachSystem defaultOverlay; devShells = eachSystem (system: let pkgs = pkgsFor.${system}; buildInputsFile = (import ./nix/buildInputs.nix {inherit pkgs;}); @@ -52,6 +56,7 @@ BeeEngineEditor-Debug = pkgs.callPackage ./nix/editor.nix { inherit src; inherit buildInputsFile; cmakeBuildType = "Debug"; }; BeeLocalization = pkgs.callPackage ./nix/localizationtool.nix { inherit src; inherit buildInputsFile; }; BeeLocalization-Debug = pkgs.callPackage ./nix/localizationtool.nix { inherit src; inherit buildInputsFile; cmakeBuildType = "Debug"; }; + BeeEngine = pkgs.callPackage ./nix/libbeeengine.nix { inherit src; inherit buildInputsFile; }; }); }; } diff --git a/nix/editor.nix b/nix/editor.nix index 1d4c8800..37ed9405 100644 --- a/nix/editor.nix +++ b/nix/editor.nix @@ -27,9 +27,11 @@ let "-DBEE_USE_VCPKG=OFF" "-DBEE_BUILD_TESTS=OFF" "-DBEE_BUILD_EDITOR=ON" + "-DBEE_BUILD_BEEENGINE=ON" "-DNETHOST_LIB=${nethost-lib-path}" "-DBEE_USE_SYSTEM_SDL3=ON" ]; + enableParallelBuilding = true; meta = with lib; { homepage = "https://github.com/KyleKrein/BeeEngine"; description = '' diff --git a/nix/libbeeengine.nix b/nix/libbeeengine.nix new file mode 100644 index 00000000..f5d35c11 --- /dev/null +++ b/nix/libbeeengine.nix @@ -0,0 +1,40 @@ +{ + lib, + pkgs, + src, + buildInputsFile, + cmakeBuildType ? "Release" +}: +assert pkgs.lib.assertMsg (src.submodules == true) + "Unable to build without submodules. Append '?submodules=1#' to the URL."; +let + nethost-lib-path = (import ./unofficial-nethost.nix {inherit pkgs; inherit lib;}).nethost-lib-path; +in + pkgs.gcc14Stdenv.mkDerivation rec { + pname = "BeeEngine"; + version = "1.0.0-alpha.1.2"; + + inherit src; + + nativeBuildInputs = buildInputsFile.dotnetNativeBuildInputs; + buildInputs = buildInputsFile.buildInputs; + + cmakeFlags = [ + "-DCMAKE_BUILD_TYPE=${cmakeBuildType}" + "-DBEE_USE_VCPKG=OFF" + "-DBEE_BUILD_TESTS=OFF" + "-DBEE_BUILD_BEEENGINE=ON" + "-DNETHOST_LIB=${nethost-lib-path}" + "-DBEE_USE_SYSTEM_SDL3=ON" + ]; + enableParallelBuilding = true; + meta = with lib; { + homepage = "https://github.com/KyleKrein/BeeEngine"; + description = '' + BeeEngine library that can be used to build other native C++ apps. + ''; + licencse = licenses.mit; + platforms = with platforms; linux ++ darwin; + maintainers = [ maintainers.KyleKrein ]; + }; + } diff --git a/nix/localizationtool.nix b/nix/localizationtool.nix index e3ebaa52..e36ae742 100644 --- a/nix/localizationtool.nix +++ b/nix/localizationtool.nix @@ -23,10 +23,12 @@ tool = pkgs.gcc14Stdenv.mkDerivation rec { "-DCMAKE_BUILD_TYPE=${cmakeBuildType}" "-DBEE_USE_VCPKG=OFF" "-DBEE_BUILD_TESTS=OFF" + "-DBEE_BUILD_BEEENGINE=ON" "-DBEE_BUILD_LOC_TOOL=ON" "-DBEE_USE_SYSTEM_SDL3=ON" "-DBEE_NO_DOTNET=ON" ]; + enableParallelBuilding = true; meta = with lib; { homepage = "https://github.com/KyleKrein/BeeEngine"; description = '' diff --git a/src/Editor/CMakeLists.txt b/src/Editor/CMakeLists.txt index 9fa6afd9..ee74d54d 100644 --- a/src/Editor/CMakeLists.txt +++ b/src/Editor/CMakeLists.txt @@ -15,22 +15,28 @@ add_executable(BeeEngineEditor Start.cpp src/EditorApplication.cpp src/EditorApp src/Panels/ProjectSettings.cpp) set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 23) -add_subdirectory(vendor/ImGuizmo) +if(NOT ${BEE_BUILD_BEEENGINE}) + find_library(BeeEngine_LIB BeeEngine REQUIRED) + message("Found BeeEngine: ${BeeEngine_LIB}") + get_filename_component(BeeEngineLibDir "${BeeEngine_LIB}" DIRECTORY) + get_filename_component(BeeEnginePrefix "${BeeEngineLibDir}" DIRECTORY) + set(BEE_CSHARP_LIBRARY_PATH ${BeeEnginePrefix}/share/BeeEngine/libs) + add_library(BeeEngine STATIC IMPORTED GLOBAL) + set_target_properties(BeeEngine PROPERTIES + IMPORTED_LOCATION ${BeeEngine_LIB} + INTERFACE_INCLUDE_DIRECTORIES ${BeeEnginePrefix}/include/BeeEngine + ) + set(CMAKE_CXX_LINK_EXECUTABLE " -o -Wl,--start-group -Wl,--whole-archive -Wl,--no-whole-archive -Wl,--end-group") + +endif() + target_include_directories(BeeEngineEditor - PUBLIC ../Engine/include/ - PRIVATE ../Engine/vendor/ - PRIVATE vendor/FileWatcher PUBLIC src - PUBLIC ${ImGuizmo_SOURCE_DIR} ) target_link_libraries(BeeEngineEditor - PUBLIC BeeEngine::WithScripting - PUBLIC ImGuizmo + PUBLIC BeeEngine ) -add_compile_definitions(BEE_ENABLE_CHECKS) -add_compile_definitions($<$:BEE_ENABLE_PROFILING>) -add_compile_definitions($<$:BEE_ENABLE_PROFILING>) file(COPY ../Engine/Assets/Shaders DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) configure_file(${BEE_CSHARP_LIBRARY_PATH}/BeeEngine.Core.dll ${CMAKE_CURRENT_BINARY_DIR}/libs/BeeEngine.Core.dll COPYONLY) diff --git a/src/Editor/Start.cpp b/src/Editor/Start.cpp index e0a73c13..137326b5 100644 --- a/src/Editor/Start.cpp +++ b/src/Editor/Start.cpp @@ -2,12 +2,12 @@ // Created by alexl on 26.05.2023. // -#include "BeeEngine.h" -#include "Core/Move.h" +#include +#include #include "src/ConfigFile.h" #include "src/EditorApplication.h" -gsl::not_null BeeEngine::CreateApplication(const BeeEngine::ApplicationArgs& args) +BeeEngine::Application* BeeEngine::CreateApplication(const BeeEngine::ApplicationArgs& args) { Editor::ConfigFile config = Editor::ConfigFile::Load(Editor::ConfigFile::DefaultPath()); return new BeeEngine::Editor::EditorApplication(BeeMove(config)); diff --git a/src/Editor/src/AssetScanner.cpp b/src/Editor/src/AssetScanner.cpp index 9e060272..afe69285 100644 --- a/src/Editor/src/AssetScanner.cpp +++ b/src/Editor/src/AssetScanner.cpp @@ -3,7 +3,7 @@ // #include "AssetScanner.h" -#include "Core/ResourceManager.h" +#include namespace BeeEngine::Editor { diff --git a/src/Editor/src/AssetScanner.h b/src/Editor/src/AssetScanner.h index 45923af6..2e8e3f49 100644 --- a/src/Editor/src/AssetScanner.h +++ b/src/Editor/src/AssetScanner.h @@ -3,7 +3,7 @@ // #pragma once -#include "Core/Path.h" +#include #include #include diff --git a/src/Editor/src/ConfigFile.h b/src/Editor/src/ConfigFile.h index b5d5a98d..4361a988 100644 --- a/src/Editor/src/ConfigFile.h +++ b/src/Editor/src/ConfigFile.h @@ -3,8 +3,8 @@ // #pragma once -#include "BeeEngine.h" -#include "Windowing/VSync.h" +#include +#include #include #include diff --git a/src/Editor/src/EditorApplication.cpp b/src/Editor/src/EditorApplication.cpp index e900019b..bfd3b4a3 100644 --- a/src/Editor/src/EditorApplication.cpp +++ b/src/Editor/src/EditorApplication.cpp @@ -3,12 +3,12 @@ // #include "EditorApplication.h" -#include "Core/Application.h" -#include "Core/Move.h" -#include "Debug/DebugLayer.h" +#include +#include +#include #include "EditorLayer.h" -#include "Locale/Locale.h" -#include "Windowing/WindowHandler/WindowHandler.h" +#include +#include namespace BeeEngine::Editor { diff --git a/src/Editor/src/EditorApplication.h b/src/Editor/src/EditorApplication.h index 1d837760..bb88d11e 100644 --- a/src/Editor/src/EditorApplication.h +++ b/src/Editor/src/EditorApplication.h @@ -3,7 +3,7 @@ // #pragma once -#include "BeeEngine.h" +#include #include "ConfigFile.h" namespace BeeEngine::Editor diff --git a/src/Editor/src/EditorLayer.cpp b/src/Editor/src/EditorLayer.cpp index 90a7c6d7..21174516 100644 --- a/src/Editor/src/EditorLayer.cpp +++ b/src/Editor/src/EditorLayer.cpp @@ -4,40 +4,40 @@ #include "EditorLayer.h" #include "AssetScanner.h" #include "ConfigFile.h" -#include "Core/Application.h" -#include "Core/AssetManagement/Asset.h" -#include "Core/AssetManagement/AssetManager.h" -#include "Core/AssetManagement/AssetRegistrySerializer.h" -#include "Core/AssetManagement/EngineAssetRegistry.h" -#include "Core/Events/EventImplementations.h" -#include "Core/Logging/Log.h" -#include "Core/TypeDefines.h" -#include "Debug/Instrumentor.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include #include "EditorApplication.h" -#include "FileSystem/File.h" -#include "Gui/ImGui/ImGuiExtension.h" -#include "Gui/MessageBox.h" -#include "JobSystem/JobScheduler.h" -#include "Locale/Locale.h" -#include "Locale/LocalizationGenerator.h" +#include +#include +#include +#include +#include +#include #include "Panels/ProjectSettings.h" -#include "Platform/ImGui/ImGuiController.h" -#include "Renderer/Texture.h" -#include "Scene/Components.h" -#include "Scene/Entity.h" -#include "Scene/Scene.h" -#include "Scene/SceneSerializer.h" -#include "Scripting/MAssembly.h" -#include "Scripting/MClass.h" -#include "Scripting/NativeToManaged.h" -#include "Scripting/ScriptGlue.h" -#include "Scripting/ScriptingEngine.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #if defined(BEE_COMPILE_VULKAN) -#include "backends/imgui_impl_vulkan.h" +#include #endif -#include "imgui.h" -#include <../../Engine/Assets/EmbeddedResources.h> +#include +#include "../../Engine/Assets/EmbeddedResources.h" #include #include diff --git a/src/Editor/src/EditorLayer.h b/src/Editor/src/EditorLayer.h index 26dff2fc..3f102b2d 100644 --- a/src/Editor/src/EditorLayer.h +++ b/src/Editor/src/EditorLayer.h @@ -4,15 +4,15 @@ #pragma once -#include "BeeEngine.h" +#include #include "ConfigFile.h" -#include "Core/AssetManagement/Asset.h" -#include "Core/AssetManagement/EditorAssetManager.h" -#include "Gui/ImGui/FpsCounter.h" -#include "Gui/ImGui/ImGuiOutputConsole.h" +#include +#include +#include +#include #include "ImGuiNativeDragAndDrop.h" -#include "Locale/ImGuiLocalizationPanel.h" -#include "Locale/Locale.h" +#include +#include #include "Panels/AssetPanel.h" #include "Panels/ContentBrowserPanel.h" #include "Panels/DockSpace.h" @@ -23,7 +23,7 @@ #include "Panels/SceneHierarchyPanel.h" #include "Panels/ViewPort.h" #include "ProjectFile.h" -#include "kdbindings/property.h" +#include #include namespace BeeEngine::Editor diff --git a/src/Editor/src/ImGuiNativeDragAndDrop.h b/src/Editor/src/ImGuiNativeDragAndDrop.h index e7ad8c64..c7cf4001 100644 --- a/src/Editor/src/ImGuiNativeDragAndDrop.h +++ b/src/Editor/src/ImGuiNativeDragAndDrop.h @@ -3,10 +3,10 @@ // #pragma once -#include "Core/Events/Event.h" -#include "Core/Events/EventImplementations.h" -#include "Core/Path.h" -#include "Gui/ImGui/ImGuiExtension.h" +#include +#include +#include +#include #include namespace BeeEngine diff --git a/src/Editor/src/Panels/InspectorPanel.cpp b/src/Editor/src/Panels/InspectorPanel.cpp index d4711fef..59cd0abc 100644 --- a/src/Editor/src/Panels/InspectorPanel.cpp +++ b/src/Editor/src/Panels/InspectorPanel.cpp @@ -14,7 +14,7 @@ #include "Scripting/GameScript.h" #include "Scripting/MClass.h" #include "Scripting/ScriptingEngine.h" -#include "gtc/type_ptr.hpp" +#include #include "imgui.h" #include "imgui_internal.h" #include diff --git a/src/Editor/src/Panels/ViewPort.cpp b/src/Editor/src/Panels/ViewPort.cpp index 47d79d2c..343e7034 100644 --- a/src/Editor/src/Panels/ViewPort.cpp +++ b/src/Editor/src/Panels/ViewPort.cpp @@ -19,7 +19,7 @@ #include "Scene/SceneSerializer.h" #include "Scripting/ScriptingEngine.h" #include "Windowing/WindowHandler/WindowHandler.h" -#include "gtc/type_ptr.hpp" +#include #include "imgui.h" namespace BeeEngine::Editor @@ -93,8 +93,8 @@ namespace BeeEngine::Editor if (IsMouseInViewport()) { - mouseX = gsl::narrow_cast(mouseX * WindowHandler::GetInstance()->GetScaleFactor()); - mouseY = gsl::narrow_cast(mouseY * WindowHandler::GetInstance()->GetScaleFactor()); + mouseX = narrow_cast(mouseX * WindowHandler::GetInstance()->GetScaleFactor()); + mouseY = narrow_cast(mouseY * WindowHandler::GetInstance()->GetScaleFactor()); ScriptingEngine::SetMousePosition(mouseX, mouseY); } @@ -162,8 +162,8 @@ namespace BeeEngine::Editor if (IsMouseInViewport()) { - int mouseX = gsl::narrow_cast(mx * WindowHandler::GetInstance()->GetScaleFactor()); - int mouseY = gsl::narrow_cast(my * WindowHandler::GetInstance()->GetScaleFactor()); + int mouseX = narrow_cast(mx * WindowHandler::GetInstance()->GetScaleFactor()); + int mouseY = narrow_cast(my * WindowHandler::GetInstance()->GetScaleFactor()); ScriptingEngine::SetMousePosition(mouseX, mouseY); m_HoveredEntity = GetHoveredEntity(); } @@ -243,10 +243,10 @@ namespace BeeEngine::Editor auto size = ImGui::GetContentRegionAvail(); size.x = size.x > 0 ? size.x : 1; size.y = size.y > 0 ? size.y : 1; - if (gsl::narrow_cast(m_Width) != size.x || gsl::narrow_cast(m_Height) != size.y) + if (narrow_cast(m_Width) != size.x || narrow_cast(m_Height) != size.y) { - m_Width = gsl::narrow_cast(size.x); - m_Height = gsl::narrow_cast(size.y); + m_Width = narrow_cast(size.x); + m_Height = narrow_cast(size.y); m_FrameBuffer->Resize(m_Width * WindowHandler::GetInstance()->GetScaleFactor(), m_Height * WindowHandler::GetInstance()->GetScaleFactor()); CurrentScene()->OnViewPortResize(m_Width, m_Height); @@ -358,8 +358,8 @@ namespace BeeEngine::Editor Entity ViewPort::GetHoveredEntity() { - int mouseX = gsl::narrow_cast(m_MousePosition.x * WindowHandler::GetInstance()->GetScaleFactor()); - int mouseY = gsl::narrow_cast(m_MousePosition.y * WindowHandler::GetInstance()->GetScaleFactor()); + int mouseX = narrow_cast(m_MousePosition.x * WindowHandler::GetInstance()->GetScaleFactor()); + int mouseY = narrow_cast(m_MousePosition.y * WindowHandler::GetInstance()->GetScaleFactor()); int pixelData = m_FrameBuffer->ReadPixel(1, mouseX, mouseY); pixelData--; // I make it -1 because entt starts from 0 and clear value for red integer in webgpu is // 0 and I need to make invalid number -1 too, so in scene I make + 1 diff --git a/src/Editor/src/ProjectFile.cpp b/src/Editor/src/ProjectFile.cpp index 79927866..8d1f3617 100644 --- a/src/Editor/src/ProjectFile.cpp +++ b/src/Editor/src/ProjectFile.cpp @@ -3,18 +3,18 @@ // #include "ProjectFile.h" -#include "Core/AssetManagement/Asset.h" -#include "Core/AssetManagement/AssetRegistrySerializer.h" -#include "Core/CodeSafety/Expects.h" -#include "Core/Format.h" -#include "Core/Logging/Log.h" -#include "Core/OsPlatform.h" -#include "Core/ResourceManager.h" -#include "Core/ScopeGuard.h" -#include "FileSystem/File.h" -#include "Locale/LocalizationGenerator.h" -#include "Utils/Commands.h" -#include "VSProjectGeneration.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include #include @@ -204,7 +204,7 @@ namespace BeeEngine::Editor public: Ref GetAssetRef(AssetHandle handle) const { return nullptr; } Asset* GetAsset(AssetHandle handle) const { return nullptr; } - void LoadAsset(gsl::span data, AssetHandle handle, const String& name, AssetType type) {} + void LoadAsset(std::span data, AssetHandle handle, const String& name, AssetType type) {} void LoadAsset(const Path& path, AssetHandle handle) {} void UnloadAsset(AssetHandle handle) {} diff --git a/src/Editor/src/ProjectFile.h b/src/Editor/src/ProjectFile.h index 7e2bed38..0be164cb 100644 --- a/src/Editor/src/ProjectFile.h +++ b/src/Editor/src/ProjectFile.h @@ -3,15 +3,15 @@ // #pragma once -#include "Core/AssetManagement/Asset.h" -#include "Core/AssetManagement/EditorAssetManager.h" -#include "Core/Coroutines/Generator.h" -#include "Core/OsPlatform.h" -#include "Core/Property.h" -#include "Core/TypeDefines.h" -#include "Core/UUID.h" -#include "FileSystem/FileWatcher.h" -#include "Locale/Locale.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include #include namespace BeeEngine::Editor diff --git a/src/Editor/src/VSProjectGeneration.cpp b/src/Editor/src/VSProjectGeneration.cpp index 462be781..83dd008f 100644 --- a/src/Editor/src/VSProjectGeneration.cpp +++ b/src/Editor/src/VSProjectGeneration.cpp @@ -3,8 +3,8 @@ // #include "VSProjectGeneration.h" -#include "Core/CodeSafety/Expects.h" -#include "FileSystem/File.h" +#include +#include #include #include namespace BeeEngine @@ -140,4 +140,4 @@ namespace BeeEngine ofs.close(); } } -} // namespace BeeEngine \ No newline at end of file +} // namespace BeeEngine diff --git a/src/Editor/src/VSProjectGeneration.h b/src/Editor/src/VSProjectGeneration.h index aaba78e0..6a624f38 100644 --- a/src/Editor/src/VSProjectGeneration.h +++ b/src/Editor/src/VSProjectGeneration.h @@ -3,7 +3,7 @@ // #pragma once -#include "Core/Path.h" +#include #include namespace BeeEngine @@ -16,4 +16,4 @@ namespace BeeEngine private: }; -} // namespace BeeEngine \ No newline at end of file +} // namespace BeeEngine diff --git a/src/Editor/vendor/ImGuizmo/imguizmo b/src/Editor/vendor/ImGuizmo/imguizmo deleted file mode 160000 index 2310acda..00000000 --- a/src/Editor/vendor/ImGuizmo/imguizmo +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 2310acda820d7383d4c4884b7945ada92cd16a47 diff --git a/src/Engine/Assets/EmbeddedResources.cpp b/src/Engine/Assets/EmbeddedResources.cpp index 865ff4fc..e44f786b 100644 --- a/src/Engine/Assets/EmbeddedResources.cpp +++ b/src/Engine/Assets/EmbeddedResources.cpp @@ -3,63 +3,6 @@ // #include "EmbeddedResources.h" -#if 0 //! defined(_MSC_VER) -#define INCBIN_SILENCE_BITCODE_WARNING -#include "incbin.h" - -#define EmbedResource(name, path) \ - extern "C" \ - { \ - INCBIN(name, ASSETS_PATH path); \ - } - -EmbedResource(OpenSansRegular, "Fonts/OpenSans/static/OpenSans-Regular.ttf"); -EmbedResource(OpenSansBold, "Fonts/OpenSans/static/OpenSans-Bold.ttf"); -EmbedResource(ManropeRegular, "Fonts/Manrope/static/Manrope-Regular.ttf"); -EmbedResource(ManropeBold, "Fonts/Manrope/static/Manrope-Bold.ttf"); -EmbedResource(DirectoryTexture, "Textures/directory.png"); -EmbedResource(FileTexture, "Textures/file.png"); -EmbedResource(PlayButtonTexture, "Textures/PlayButton.png"); -EmbedResource(PauseButtonTexture, "Textures/PauseButton.png"); -EmbedResource(StopButtonTexture, "Textures/StopButton.png"); -EmbedResource(Standart2DShaderVertex, "Shaders/Standart2DVertex.glsl"); -EmbedResource(Standart2DShaderFragment, "Shaders/Standart2DFragment.glsl"); - -namespace BeeEngine::Internal -{ - gsl::span GetEmbeddedResource(EmbeddedResource resource) noexcept - { - switch (resource) - { - case EmbeddedResource::OpenSansRegular: - return {(std::byte*)gOpenSansRegularData, gOpenSansRegularSize}; - case EmbeddedResource::OpenSansBold: - return {(std::byte*)gOpenSansBoldData, gOpenSansBoldSize}; - case EmbeddedResource::ManropeRegular: - return {(std::byte*)gManropeRegularData, gManropeRegularSize}; - case EmbeddedResource::ManropeBold: - return {(std::byte*)gManropeBoldData, gManropeBoldSize}; - case EmbeddedResource::DirectoryTexture: - return {(std::byte*)gDirectoryTextureData, gDirectoryTextureSize}; - case EmbeddedResource::FileTexture: - return {(std::byte*)gFileTextureData, gFileTextureSize}; - case EmbeddedResource::PlayButtonTexture: - return {(std::byte*)gPlayButtonTextureData, gPlayButtonTextureSize}; - case EmbeddedResource::PauseButtonTexture: - return {(std::byte*)gPauseButtonTextureData, gPauseButtonTextureSize}; - case EmbeddedResource::StopButtonTexture: - return {(std::byte*)gStopButtonTextureData, gStopButtonTextureSize}; - case EmbeddedResource::Standart2DShaderVertex: - return {(std::byte*)gStandart2DShaderVertexData, gStandart2DShaderVertexSize}; - case EmbeddedResource::Standart2DShaderFragment: - return {(std::byte*)gStandart2DShaderFragmentData, gStandart2DShaderFragmentSize}; - default: - return {}; - } - } -} - -#else extern "C" { #include @@ -79,7 +22,7 @@ extern "C" namespace BeeEngine::Internal { - gsl::span GetEmbeddedResource(EmbeddedResource resource) noexcept + std::span GetEmbeddedResource(EmbeddedResource resource) noexcept { switch (resource) { @@ -112,4 +55,3 @@ namespace BeeEngine::Internal } } } // namespace BeeEngine::Internal -#endif diff --git a/src/Engine/Assets/EmbeddedResources.h b/src/Engine/Assets/EmbeddedResources.h index 00e8a003..0b297571 100644 --- a/src/Engine/Assets/EmbeddedResources.h +++ b/src/Engine/Assets/EmbeddedResources.h @@ -3,8 +3,7 @@ // #pragma once - -#include "gsl/gsl" +#include enum class EmbeddedResource { @@ -24,5 +23,5 @@ enum class EmbeddedResource namespace BeeEngine::Internal { - gsl::span GetEmbeddedResource(EmbeddedResource resource) noexcept; + std::span GetEmbeddedResource(EmbeddedResource resource) noexcept; } diff --git a/src/Engine/CMakeLists.txt b/src/Engine/CMakeLists.txt index 9e1e8d32..e30e8085 100644 --- a/src/Engine/CMakeLists.txt +++ b/src/Engine/CMakeLists.txt @@ -8,9 +8,8 @@ project( #set(CMAKE_CXX_STANDARD 23) #set(BEE_COMPILE_GLFW OFF) #set(BEE_COMPILE_WEBGPU ON) -option(BEE_NO_DOTNET OFF "Disable dotnet and C# scripting") -set(SOURCE_FILES src/BeeEngine.cpp src/Core/TypeDefines.h src/Core/EntryPoint.cpp src/Core/Application.cpp src/Core/Application.h src/Core/EntryPoint.h src/Windowing/WindowHandler/WindowHandler.cpp src/Windowing/WindowHandler/WindowHandler.h src/Windowing/ApplicationProperties.h src/Core/Logging/Log.h src/Core/Logging/Log.cpp src/Core/Events/Event.h src/Core/Events/EventQueue.cpp src/Core/Events/EventQueue.h src/Core/Layer.h src/Core/LayerStack.cpp src/Core/LayerStack.h src/Core/Input.cpp src/Core/Input.h src/KeyCodes.h src/Core/Events/EventImplementations.h src/Windowing/VSync.h src/Renderer/Renderer.cpp src/Renderer/Renderer.h src/Renderer/RendererAPI.h src/Platform/ImGui/ImGuiController.h src/Core/Layer.cpp src/Renderer/RendererAPI.cpp src/Core/Color4.cpp src/Core/Color4.h src/Renderer/BufferLayout.cpp src/Renderer/BufferLayout.h src/Renderer/Texture.cpp src/Renderer/Texture.h src/Core/Events/Event.cpp src/Allocator/Allocator.h src/Debug/MemoryProfiler.cpp src/Debug/MemoryProfiler.h src/Debug/DebugLayer.cpp src/Debug/DebugLayer.h src/Core/SharedPointer.cpp src/Core/SharedPointer.h src/Renderer/FrameBuffer.cpp src/Renderer/FrameBuffer.h src/Core/ResourceManager.cpp src/Core/ResourceManager.h src/Core/Cameras/ICamera.cpp src/Core/Cameras/ICamera.h src/Renderer/RectangleProperties.h src/Core/Time.cpp src/Core/Time.h src/Debug/Timer.h src/Debug/Instrumentor.h src/Core/CodeSafety/Expects.h src/Gui/ImGui/FpsCounter.cpp src/Gui/ImGui/FpsCounter.h src/Scene/Scene.cpp src/Scene/Scene.h src/Scene/EntityID.h src/Scene/Components.h src/Scene/Entity.cpp src/Scene/Entity.h src/Core/Cameras/Camera.cpp src/Core/Cameras/Camera.h src/Scene/SceneCamera.cpp src/Scene/SceneCamera.h src/Scene/ScriptableEntity.cpp src/Scene/ScriptableEntity.h src/Platform/ImGui/ImGuiController.cpp vendor/Incbin/incbin.h Assets/EmbeddedResources.h src/Gui/ImGuiFonts.h src/Scene/SceneSerializer.cpp src/Scene/SceneSerializer.h src/source_location.h src/Property.h src/Utils/FileDialogs.h src/Core/Math/Math.h src/Core/Math/Math.cpp src/Renderer/EditorCamera.cpp src/Renderer/EditorCamera.h Assets/EmbeddedResources.cpp src/Core/CodeSafety/DebugLog.cpp src/Core/CodeSafety/DebugLog.h src/Core/OsPlatform.h src/Renderer/RenderAPI.h src/Renderer/Surface.cpp src/Renderer/Surface.h src/Renderer/DeviceID.cpp src/Renderer/DeviceID.h src/Renderer/SwapChain.cpp src/Renderer/SwapChain.h src/Platform/Vulkan/VulkanGraphicsDevice.cpp src/Platform/Vulkan/VulkanGraphicsDevice.h src/Platform/Vulkan/VulkanSwapChain.cpp src/Platform/Vulkan/VulkanSwapChain.h src/Renderer/Instance.cpp src/Renderer/Instance.h src/Platform/Vulkan/VulkanInstance.cpp src/Platform/Vulkan/VulkanInstance.h src/Renderer/QueueFamilyIndices.cpp src/Renderer/QueueFamilyIndices.h src/FileSystem/File.cpp src/FileSystem/File.h src/Platform/ImGui/ImGuiControllerVulkan.h src/Platform/ImGui/ImGuiControllerVulkan.cpp src/Utils/ShaderConverter.h src/Utils/ShaderConverter.cpp vendor/VulkanMemoryAllocator/vk_mem_alloc.h src/Core/CodeSafety/NotNull.h src/Core/CodeSafety/BoundsChecking.h src/Platform/Vulkan/VulkanBuffer.h src/Renderer/Vertex.h src/Core/DeletionQueue.cpp src/Core/DeletionQueue.h src/Platform/Vulkan/Utils.h src/Platform/Vulkan/Utils.cpp src/Renderer/AssetManager.cpp src/Renderer/AssetManager.h src/Renderer/Mesh.h src/Renderer/Mesh.cpp src/Renderer/Material.cpp src/Renderer/Material.h src/Windowing/WindowHandler/SDLWindowHandler.cpp src/Windowing/WindowHandler/SDLWindowHandler.h src/Platform/WebGPU/WebGPUInstance.cpp src/Platform/WebGPU/WebGPUInstance.h src/Platform/WebGPU/WebGPUGraphicsDevice.cpp src/Platform/WebGPU/WebGPUGraphicsDevice.h src/Platform/WebGPU/WebGPUSwapchain.cpp src/Platform/WebGPU/WebGPUSwapchain.h src/Platform/WebGPU/WebGPURendererAPI.cpp src/Platform/WebGPU/WebGPURendererAPI.h src/Renderer/CommandBuffer.h src/Platform/WebGPU/WebGPUCommandBuffer.cpp src/Platform/WebGPU/WebGPUCommandBuffer.h src/Platform/ImGui/ImGuiControllerWebGPU.h src/Platform/ImGui/ImGuiControllerWebGPU.cpp src/Renderer/RenderPass.h src/Platform/WebGPU/WebGPUPipeline.cpp src/Platform/WebGPU/WebGPUPipeline.h src/Renderer/Pipeline.h src/Renderer/ShaderTypes.h src/Renderer/ShaderModule.h src/Renderer/ShaderModule.cpp src/Platform/WebGPU/WebGPUShaderModule.cpp src/Platform/WebGPU/WebGPUShaderModule.h src/Renderer/Pipeline.cpp src/Platform/WebGPU/WebGPUMesh.cpp src/Platform/WebGPU/WebGPUMesh.h src/Renderer/UniformBuffer.cpp src/Renderer/UniformBuffer.h src/Platform/WebGPU/WebGPUUniformBuffer.cpp src/Platform/WebGPU/WebGPUUniformBuffer.h src/Renderer/InstancedBuffer.h src/Platform/WebGPU/WebGPUInstancedBuffer.cpp src/Platform/WebGPU/WebGPUInstancedBuffer.h src/Core/RestartApplication.h src/Renderer/Model.h src/Platform/WebGPU/WebGPUMaterial.cpp src/Platform/WebGPU/WebGPUMaterial.h src/Renderer/Model.cpp src/Platform/WebGPU/WebGPUModel.cpp src/Platform/WebGPU/WebGPUTexture2D.cpp src/Platform/WebGPU/WebGPUTexture2D.h vendor/Implementations.cpp src/Renderer/BindingSet.cpp src/Renderer/BindingSet.h src/Renderer/IBindable.h src/Renderer/MaterialDescriptor.h src/Core/ValueType.h src/Platform/WebGPU/WebGPUBindingSet.cpp src/Platform/WebGPU/WebGPUBindingSet.h src/Platform/WebGPU/WebGPUBufferPool.cpp src/Platform/WebGPU/WebGPUBufferPool.h src/Renderer/RenderingQueue.cpp src/Renderer/RenderingQueue.h src/Renderer/InstancedBuffer.cpp src/Renderer/RendererStatistics.h src/Gui/ImGui/RendererStatisticsGUI.cpp src/Gui/ImGui/RendererStatisticsGUI.h src/Platform/WebGPU/WebGPUFramebuffer.cpp src/Platform/WebGPU/WebGPUFramebuffer.h src/Core/FramePtr.cpp src/Core/FramePtr.h src/Scene/INativeScriptRegistry.h src/Scene/NativeScriptFactory.cpp src/Scene/NativeScriptFactory.h src/Scene/INativeScriptFactory.h src/Utils/DynamicLibrary.cpp src/Utils/DynamicLibrary.h src/Core/Logging/GameLogger.cpp src/Core/Logging/GameLogger.h src/Scene/DefaultNativeScript.h src/Core/UUID.cpp src/Core/UUID.h src/Scene/Components.cpp src/Allocator/AllocatorStatistics.h src/Allocator/AllocatorStatistics.h +set(SOURCE_FILES src/BeeEngine.cpp src/Core/TypeDefines.h src/Core/EntryPoint.cpp src/Core/Application.cpp src/Core/Application.h src/Core/EntryPoint.h src/Windowing/WindowHandler/WindowHandler.cpp src/Windowing/WindowHandler/WindowHandler.h src/Windowing/ApplicationProperties.h src/Core/Logging/Log.h src/Core/Logging/Log.cpp src/Core/Events/Event.h src/Core/Events/EventQueue.cpp src/Core/Events/EventQueue.h src/Core/Layer.h src/Core/LayerStack.cpp src/Core/LayerStack.h src/Core/Input.cpp src/Core/Input.h src/KeyCodes.h src/Core/Events/EventImplementations.h src/Windowing/VSync.h src/Renderer/Renderer.cpp src/Renderer/Renderer.h src/Renderer/RendererAPI.h src/Platform/ImGui/ImGuiController.h src/Core/Layer.cpp src/Renderer/RendererAPI.cpp src/Core/Color4.cpp src/Core/Color4.h src/Renderer/BufferLayout.cpp src/Renderer/BufferLayout.h src/Renderer/Texture.cpp src/Renderer/Texture.h src/Core/Events/Event.cpp src/Allocator/Allocator.h src/Debug/MemoryProfiler.cpp src/Debug/MemoryProfiler.h src/Debug/DebugLayer.cpp src/Debug/DebugLayer.h src/Core/SharedPointer.cpp src/Core/SharedPointer.h src/Renderer/FrameBuffer.cpp src/Renderer/FrameBuffer.h src/Core/ResourceManager.cpp src/Core/ResourceManager.h src/Core/Cameras/ICamera.cpp src/Core/Cameras/ICamera.h src/Renderer/RectangleProperties.h src/Core/Time.cpp src/Core/Time.h src/Debug/Timer.h src/Debug/Instrumentor.h src/Core/CodeSafety/Expects.h src/Gui/ImGui/FpsCounter.cpp src/Gui/ImGui/FpsCounter.h src/Scene/Scene.cpp src/Scene/Scene.h src/Scene/EntityID.h src/Scene/Components.h src/Scene/Entity.cpp src/Scene/Entity.h src/Core/Cameras/Camera.cpp src/Core/Cameras/Camera.h src/Scene/SceneCamera.cpp src/Scene/SceneCamera.h src/Scene/ScriptableEntity.cpp src/Scene/ScriptableEntity.h src/Platform/ImGui/ImGuiController.cpp Assets/EmbeddedResources.h src/Gui/ImGuiFonts.h src/Scene/SceneSerializer.cpp src/Scene/SceneSerializer.h src/source_location.h src/Property.h src/Utils/FileDialogs.h src/Core/Math/Math.h src/Core/Math/Math.cpp src/Renderer/EditorCamera.cpp src/Renderer/EditorCamera.h Assets/EmbeddedResources.cpp src/Core/CodeSafety/DebugLog.cpp src/Core/CodeSafety/DebugLog.h src/Core/OsPlatform.h src/Renderer/RenderAPI.h src/Renderer/Surface.cpp src/Renderer/Surface.h src/Renderer/DeviceID.cpp src/Renderer/DeviceID.h src/Renderer/SwapChain.cpp src/Renderer/SwapChain.h src/Platform/Vulkan/VulkanGraphicsDevice.cpp src/Platform/Vulkan/VulkanGraphicsDevice.h src/Platform/Vulkan/VulkanSwapChain.cpp src/Platform/Vulkan/VulkanSwapChain.h src/Renderer/Instance.cpp src/Renderer/Instance.h src/Platform/Vulkan/VulkanInstance.cpp src/Platform/Vulkan/VulkanInstance.h src/Renderer/QueueFamilyIndices.cpp src/Renderer/QueueFamilyIndices.h src/FileSystem/File.cpp src/FileSystem/File.h src/Platform/ImGui/ImGuiControllerVulkan.h src/Platform/ImGui/ImGuiControllerVulkan.cpp src/Utils/ShaderConverter.h src/Utils/ShaderConverter.cpp src/Core/CodeSafety/NotNull.h src/Core/CodeSafety/BoundsChecking.h src/Platform/Vulkan/VulkanBuffer.h src/Renderer/Vertex.h src/Core/DeletionQueue.cpp src/Core/DeletionQueue.h src/Platform/Vulkan/Utils.h src/Platform/Vulkan/Utils.cpp src/Renderer/AssetManager.cpp src/Renderer/AssetManager.h src/Renderer/Mesh.h src/Renderer/Mesh.cpp src/Renderer/Material.cpp src/Renderer/Material.h src/Windowing/WindowHandler/SDLWindowHandler.cpp src/Windowing/WindowHandler/SDLWindowHandler.h src/Platform/WebGPU/WebGPUInstance.cpp src/Platform/WebGPU/WebGPUInstance.h src/Platform/WebGPU/WebGPUGraphicsDevice.cpp src/Platform/WebGPU/WebGPUGraphicsDevice.h src/Platform/WebGPU/WebGPUSwapchain.cpp src/Platform/WebGPU/WebGPUSwapchain.h src/Platform/WebGPU/WebGPURendererAPI.cpp src/Platform/WebGPU/WebGPURendererAPI.h src/Renderer/CommandBuffer.h src/Platform/WebGPU/WebGPUCommandBuffer.cpp src/Platform/WebGPU/WebGPUCommandBuffer.h src/Platform/ImGui/ImGuiControllerWebGPU.h src/Platform/ImGui/ImGuiControllerWebGPU.cpp src/Renderer/RenderPass.h src/Platform/WebGPU/WebGPUPipeline.cpp src/Platform/WebGPU/WebGPUPipeline.h src/Renderer/Pipeline.h src/Renderer/ShaderTypes.h src/Renderer/ShaderModule.h src/Renderer/ShaderModule.cpp src/Platform/WebGPU/WebGPUShaderModule.cpp src/Platform/WebGPU/WebGPUShaderModule.h src/Renderer/Pipeline.cpp src/Platform/WebGPU/WebGPUMesh.cpp src/Platform/WebGPU/WebGPUMesh.h src/Renderer/UniformBuffer.cpp src/Renderer/UniformBuffer.h src/Platform/WebGPU/WebGPUUniformBuffer.cpp src/Platform/WebGPU/WebGPUUniformBuffer.h src/Renderer/InstancedBuffer.h src/Platform/WebGPU/WebGPUInstancedBuffer.cpp src/Platform/WebGPU/WebGPUInstancedBuffer.h src/Core/RestartApplication.h src/Renderer/Model.h src/Platform/WebGPU/WebGPUMaterial.cpp src/Platform/WebGPU/WebGPUMaterial.h src/Renderer/Model.cpp src/Platform/WebGPU/WebGPUModel.cpp src/Platform/WebGPU/WebGPUTexture2D.cpp src/Platform/WebGPU/WebGPUTexture2D.h vendor/Implementations.cpp src/Renderer/BindingSet.cpp src/Renderer/BindingSet.h src/Renderer/IBindable.h src/Renderer/MaterialDescriptor.h src/Core/ValueType.h src/Platform/WebGPU/WebGPUBindingSet.cpp src/Platform/WebGPU/WebGPUBindingSet.h src/Platform/WebGPU/WebGPUBufferPool.cpp src/Platform/WebGPU/WebGPUBufferPool.h src/Renderer/RenderingQueue.cpp src/Renderer/RenderingQueue.h src/Renderer/InstancedBuffer.cpp src/Renderer/RendererStatistics.h src/Gui/ImGui/RendererStatisticsGUI.cpp src/Gui/ImGui/RendererStatisticsGUI.h src/Platform/WebGPU/WebGPUFramebuffer.cpp src/Platform/WebGPU/WebGPUFramebuffer.h src/Core/FramePtr.cpp src/Core/FramePtr.h src/Scene/INativeScriptRegistry.h src/Scene/NativeScriptFactory.cpp src/Scene/NativeScriptFactory.h src/Scene/INativeScriptFactory.h src/Utils/DynamicLibrary.cpp src/Utils/DynamicLibrary.h src/Core/Logging/GameLogger.cpp src/Core/Logging/GameLogger.h src/Scene/DefaultNativeScript.h src/Core/UUID.cpp src/Core/UUID.h src/Scene/Components.cpp src/Allocator/AllocatorStatistics.h src/Allocator/AllocatorStatistics.h src/Renderer/Font.cpp src/Renderer/Font.h src/Renderer/MSDFData.h @@ -147,8 +146,8 @@ set(SOURCE_FILES src/BeeEngine.cpp src/Core/TypeDefines.h src/Core/EntryPoint.cp src/Core/GameConfig.cpp src/Gui/ImGui/ImGuiOutputConsole.cpp src/Gui/ImGui/ImGuiOutputConsole.h - vendor/SIMDString/SIMDString.h - vendor/SIMDString/SIMDString.cpp + src/Core/SIMDString.h + src/Core/SIMDString.cpp src/Gui/MessageBox.h src/Gui/MessageBox.cpp src/Core/Property.h @@ -156,15 +155,6 @@ set(SOURCE_FILES src/BeeEngine.cpp src/Core/TypeDefines.h src/Core/EntryPoint.cp src/Renderer/BufferLayoutSerializer.hpp ) - -function(DesktopPlatformsOnly) - add_compile_definitions(DESKTOP_PLATFORM) -endfunction(DesktopPlatformsOnly) - -function(MobilePlatformsOnly) - add_compile_definitions(MOBILE_PLATFORM) -endfunction(MobilePlatformsOnly) - if(IOS) # Covers iOS implementation execute_process(COMMAND xcrun --find swiftc @@ -176,12 +166,6 @@ if(IOS) _cmake_find_compiler_path(Swift) endif() enable_language(CXX C Swift OBJCXX OBJC) - MobilePlatformsOnly() - set(BEE_COMPILE_WEBGPU OFF) - set(BEE_COMPILE_VULKAN ON) - set(BEE_COMPILE_SDL ON) - - #list(APPEND SOURCE_FILES "ios/MyClass.mm") elseif(APPLE) # Covers macOS implementation enable_language(Swift OBJCXX OBJC) @@ -194,17 +178,8 @@ elseif(APPLE) src/Platform/MacOS/MacOSInternal.h src/Platform/MacOS/MacOSInternal.mm) list(APPEND SOURCE_FILES ${MACOS_SOURCE_FILES}) - DesktopPlatformsOnly() - set(BEE_COMPILE_WEBGPU OFF) - set(BEE_COMPILE_VULKAN ON) - set(BEE_COMPILE_SDL ON) elseif(ANDROID) # Covers Android implementation - MobilePlatformsOnly() - set(BEE_COMPILE_WEBGPU OFF) - set(BEE_COMPILE_VULKAN ON) - set(BEE_COMPILE_SDL ON) - #list(APPEND SOURCE_FILES "android/MyClass.cpp") elseif(WIN32) # Covers Windows implementation set(WINDOWS_SOURCE_FILES @@ -217,10 +192,6 @@ elseif(WIN32) src/Platform/Windows/WindowsThreads.cpp src/Platform/Windows/WindowsPlatform.cpp) list(APPEND SOURCE_FILES ${WINDOWS_SOURCE_FILES}) - DesktopPlatformsOnly() - set(BEE_COMPILE_WEBGPU OFF) - set(BEE_COMPILE_VULKAN ON) - set(BEE_COMPILE_SDL OFF) elseif (UNIX AND NOT APPLE) # Covers Linux implementation set(LINUX_SOURCE_FILES @@ -228,10 +199,6 @@ elseif (UNIX AND NOT APPLE) src/Platform/Linux/LinuxThreads.cpp src/Platform/Linux/LinuxPlatform.cpp) list(APPEND SOURCE_FILES ${LINUX_SOURCE_FILES}) - DesktopPlatformsOnly() - set(BEE_COMPILE_WEBGPU OFF) - set(BEE_COMPILE_VULKAN ON) - set(BEE_COMPILE_SDL ON) endif() #Embedded Resources @@ -283,78 +250,12 @@ if(NOT ${BEE_NO_DOTNET}) else() message("Building BeeEngine without C# support") endif() -#[[if(IOS OR APPLE) - set(CMAKE_Swift_LANGUAGE_VERSION 5) - add_library(BeeEngine_Internal_Swift STATIC - src/Platform/MacOS/SwiftToCpp.h - #src/Platform/MacOS/FileDialogs.swift - ) - target_compile_options(BeeEngine_Internal_Swift PUBLIC - "$<$:-cxx-interoperability-mode=default>") - target_include_directories(BeeEngine_Internal_Swift - PUBLIC src/Platform/MacOS - ) - target_link_libraries(BeeEngine PRIVATE BeeEngine_Internal_Swift) -endif ()]] target_link_libraries(BeeEngine PRIVATE file_embed) - -install(TARGETS BeeEngine - EXPORT BeeEngine - LIBRARY DESTINATION lib - ARCHIVE DESTINATION lib - RUNTIME DESTINATION bin - INCLUDES DESTINATION include - ) - -function(DesktopPlatformsOnlyPostTarget) - - -endfunction(DesktopPlatformsOnlyPostTarget) - -#if(XCODE) -# set_target_properties(BeeEngine PROPERTIES -# XCODE_GENERATE_SCHEME ON -# XCODE_SCHEME_ENABLE_GPU_FRAME_CAPTURE_MODE "Metal" -# XCODE_STD_CXX "c++23") -#endif() - -#set(CMAKE_WARN_DEPRECATED FALSE) - -#set_property(TARGET BeeEngine PROPERTY COMPILE_WARNING_AS_ERROR ON) - -#target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_23) - add_subdirectory(vendor/glslang) -if(BEE_COMPILE_WEBGPU) - include(${CMAKE_CURRENT_LIST_DIR}/cmake/InstallWebGPU.cmake) -endif () - -if(IOS) - # Covers iOS implementation - target_compile_definitions(BeeEngine PUBLIC IOS) -elseif(APPLE) - # Covers macOS implementation - target_compile_definitions(BeeEngine PUBLIC MACOS) - DesktopPlatformsOnlyPostTarget() -elseif(ANDROID) - # Covers Android implementation - target_compile_definitions(BeeEngine PUBLIC ANDROID) -elseif(WIN32) - # Covers Windows implementation - target_compile_definitions(BeeEngine PUBLIC WINDOWS) - DesktopPlatformsOnlyPostTarget() -elseif (UNIX AND NOT APPLE) - # Covers Linux implementation - target_compile_definitions(BeeEngine PUBLIC LINUX) - DesktopPlatformsOnlyPostTarget() -endif() - -if(BEE_COMPILE_WEBGPU) - message("Compiling WebGPU") +if(${BEE_COMPILE_WEBGPU}) enable_webgpu(BeeEngine) - target_compile_definitions(BeeEngine PUBLIC BEE_COMPILE_WEBGPU) endif () function(add_sdl_subdirectory) @@ -366,17 +267,12 @@ if (${BEE_COMPILE_SDL}) else() add_sdl_subdirectory() endif() - target_compile_definitions(BeeEngine PUBLIC BEE_COMPILE_SDL) - #target_include_directories(BeeEngine - # PUBLIC vendor/sdl/include - #) target_link_libraries(BeeEngine PRIVATE SDL3::SDL3) endif () add_subdirectory(vendor/spdlog) add_subdirectory(vendor/glm) add_subdirectory(vendor/ImGui) # Must be after DesktopPlatformsOnlyPostTarget -add_subdirectory(vendor/gsl) -#add_subdirectory(vendor/BeeAlloc) +add_subdirectory(vendor/ImGuizmo) add_subdirectory(vendor/entt) add_subdirectory(vendor/yaml-cpp) add_subdirectory(vendor/magic_enum) @@ -397,119 +293,65 @@ if(NOT ${BEE_NO_DOTNET}) target_link_libraries(BeeEngine PRIVATE unofficial::nethost::nethost) endif() endif() -if(BEE_COMPILE_VULKAN) +if(${BEE_COMPILE_VULKAN}) find_package(Vulkan REQUIRED) - target_compile_definitions(BeeEngine PUBLIC BEE_COMPILE_VULKAN) target_include_directories(BeeEngine PUBLIC vendor/VulkanMemoryAllocator ) target_link_libraries(BeeEngine PUBLIC Vulkan::Vulkan) endif () -if (${BEE_USE_VCPKG}) -function(extract_vcpkg_path ICU_LIB_LIST RESULT_VAR) - list(GET ICU_LIB_LIST 0 ICU_LIB_PATH) - string(REGEX REPLACE "(.*/vcpkg_installed/[^/]+).*$" "\\1" EXTRACTED_PATH ${ICU_LIB_PATH}) - set(${RESULT_VAR} ${EXTRACTED_PATH} PARENT_SCOPE) -endfunction() -extract_vcpkg_path("${ICU_LIBRARIES}" ICU_VCPKG_PATH) -target_include_directories(BeeEngine PUBLIC ${ICU_VCPKG_PATH}/include) -endif() target_include_directories( ${PROJECT_NAME} PUBLIC include PUBLIC src - PUBLIC vendor - PUBLIC vendor/spdlog/include - PUBLIC vendor/debugbreak - PUBLIC vendor/glm/glm - PUBLIC vendor/stb - PUBLIC vendor/gsl/include - #PUBLIC vendor/BeeAlloc/include - PUBLIC vendor/entt/single_include - PUBLIC vendor/Incbin - PUBLIC vendor/yaml-cpp/include - PUBLIC vendor/glslang - PUBLIC vendor/magic_enum/include - PUBLIC vendor/utfcpp/include + PRIVATE vendor PUBLIC ${ICU_INCLUDE_DIR} + PUBLIC ${ImGuizmo_SOURCE_DIR} ) target_link_libraries( ${PROJECT_NAME} #PRIVATE project_warnings PUBLIC spdlog::spdlog PUBLIC glm PUBLIC ImGui - PUBLIC GSL - #PUBLIC BeeAlloc PUBLIC EnTT PUBLIC yaml-cpp - PUBLIC SPIRV - PUBLIC glslang + PRIVATE SPIRV + PRIVATE glslang PUBLIC magic_enum - PUBLIC Box2D - PUBLIC MSDFGEN + PRIVATE Box2D + PRIVATE MSDFGEN PUBLIC ${ICU_LIBRARIES} PUBLIC Boost::context PRIVATE fastgltf PUBLIC KDAB::KDBindings + PUBLIC ImGuizmo ) - -target_compile_definitions(BeeEngine - PUBLIC GLM_FORCE_DEPTH_ZERO_TO_ONE - PUBLIC GLM_FORCE_LEFT_HANDED - ) - -# Создаем определение DEBUG только для debug configuration -add_compile_definitions($<$:DEBUG>) - -# Включаем проверки только для debug configuration -add_compile_definitions($<$:BEE_ENABLE_CHECKS>) - -add_compile_definitions($<$:BEE_ENABLE_ASSERTS>) -add_compile_definitions($<$:BEE_ENABLE_ASSERTS>) - -add_compile_definitions($<$:BEE_ENABLE_PROFILING>) -add_compile_definitions($<$:BEE_ENABLE_PROFILING>) - -# Включаем валидацию слоев Vulkan только для debug configuration -add_compile_definitions($<$:BEE_VULKAN_ENABLE_VALIDATION_LAYERS>) - -# Создаем определение RELEASE только для release configuration -add_compile_definitions($<$:RELEASE>) - -# Добавляем имена конфигураций для всех существующих конфигураций сборки -set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "Publish") - -# Включение Google Sanitizers только для отладочной сборки -if(CMAKE_BUILD_TYPE STREQUAL "Debug") - # Включение Google Sanitizers - add_compile_options(-fsanitize=address,undefined,leak,memory,thread) - - # Отключение оптимизации компилятора для Google Sanitizers - add_compile_options(-O0) -endif() -if(CMAKE_BUILD_TYPE STREQUAL "Release") - add_compile_options(-O3) -endif() -if(CMAKE_BUILD_TYPE STREQUAL "Publish") - add_compile_options(-O3) -endif() - -#add_compile_options(-static-libstdc++) - -if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") - # Использование максимального уровня предупреждений - add_compile_options(-Wall -Wextra -pedantic -Wmost -Wmost-extra) -endif () - target_link_libraries(BeeEngine PRIVATE file_embed) # for embedding assets add_compile_definitions(ASSETS_PATH="${PROJECT_SOURCE_DIR}/Assets/") -add_library(BeeEngine::BeeEngine ALIAS BeeEngine) if(NOT ${BEE_NO_DOTNET}) add_library(BeeEngine::WithScripting ALIAS BeeEngine) - target_compile_definitions(BeeEngine PRIVATE BEE_ENABLE_SCRIPTING) endif() target_compile_definitions(BeeEngine PUBLIC _SILENCE_STDEXT_ARR_ITERS_DEPRECATION_WARNING) # for spdlog -#clang_format(BeeEngine "${SOURCE_FILES}") +#installing +install(TARGETS BeeEngine + EXPORT BeeEngine + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib + RUNTIME DESTINATION bin + INCLUDES DESTINATION include +) + +include(cmake/install_target_includes.cmake) + +install_target_public_headers(BeeEngine) + +set(BEEENGINE_RESOURCES_INSTALL_PATH share/BeeEngine) +install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/Assets/Shaders + DESTINATION ${BEEENGINE_RESOURCES_INSTALL_PATH}/Shaders) +if(NOT ${BEE_NO_DOTNET}) +install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/net${BEEENGINE_DOTNET_VERSION}/ + DESTINATION ${BEEENGINE_RESOURCES_INSTALL_PATH}/libs) +endif() diff --git a/src/Engine/cmake/copy_headers.cmake b/src/Engine/cmake/copy_headers.cmake new file mode 100644 index 00000000..794def08 --- /dev/null +++ b/src/Engine/cmake/copy_headers.cmake @@ -0,0 +1,21 @@ +set(PY_SCRIPT_PATH ${CMAKE_CURRENT_LIST_DIR}/copy_headers.py) +find_package(Python3 REQUIRED) +function(copy_headers SOURCE_DIR DEST_DIR) + if(IS_ABSOLUTE ${SOURCE_DIR} AND EXISTS ${SOURCE_DIR}) + execute_process( + COMMAND ${Python3_EXECUTABLE} ${PY_SCRIPT_PATH} ${SOURCE_DIR} ${DEST_DIR} + RESULT_VARIABLE result + OUTPUT_VARIABLE output + ERROR_VARIABLE error_output + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_STRIP_TRAILING_WHITESPACE + ) + if(NOT result EQUAL 0) + message(FATAL_ERROR "Failed to copy includes from ${SOURCE_DIR}: ${error_output}") + else() + message(STATUS "Copied includes from: ${SOURCE_DIR} → ${DEST_DIR}") + endif() + else() + message(WARNING "Skipping non-existent or non-absolute path: ${SOURCE_DIR}") + endif() +endfunction() diff --git a/src/Engine/cmake/copy_headers.py b/src/Engine/cmake/copy_headers.py new file mode 100644 index 00000000..bb9d00aa --- /dev/null +++ b/src/Engine/cmake/copy_headers.py @@ -0,0 +1,30 @@ +import sys +import os +import shutil + +def copy_headers(src_dir, dst_dir): + if not os.path.isdir(src_dir): + print(f"Error: '{src_dir}' is not a valid directory.") + return + + for root, _, files in os.walk(src_dir): + for file in files: + if file.endswith(('.h', '.hpp', '.inl')): + src_file_path = os.path.join(root, file) + relative_path = os.path.relpath(root, src_dir) + dst_folder_path = os.path.join(dst_dir, relative_path) + dst_file_path = os.path.join(dst_folder_path, file) + + os.makedirs(dst_folder_path, exist_ok=True) + shutil.copy2(src_file_path, dst_file_path) + print(f"Copied: {src_file_path} → {dst_file_path}") + +if __name__ == "__main__": + if len(sys.argv) != 3: + print("Usage: python script.py ") + sys.exit(1) + + src = sys.argv[1] + dst = sys.argv[2] + copy_headers(src, dst) + diff --git a/src/Engine/cmake/install_target_includes.cmake b/src/Engine/cmake/install_target_includes.cmake new file mode 100644 index 00000000..233e0755 --- /dev/null +++ b/src/Engine/cmake/install_target_includes.cmake @@ -0,0 +1,66 @@ +function(collect_all_public_includes target result) + get_target_property(dirs ${target} INTERFACE_INCLUDE_DIRECTORIES) + if(dirs) + list(APPEND includes ${dirs}) + endif() + + get_target_property(deps ${target} INTERFACE_LINK_LIBRARIES) + foreach(dep IN LISTS deps) + if(TARGET ${dep}) + collect_all_public_includes(${dep} child_includes) + list(APPEND includes ${child_includes}) + endif() + endforeach() + + # Удалить дубликаты + list(REMOVE_DUPLICATES includes) + set(${result} "${includes}" PARENT_SCOPE) +endfunction() + + +function(install_target_public_headers TARGET) + include(${CMAKE_CURRENT_FUNCTION_LIST_DIR}/copy_headers.cmake) + + if(NOT TARGET ${TARGET}) + message(FATAL_ERROR "Target '${TARGET}' does not exist.") + endif() + + collect_all_public_includes(${TARGET} INTERFACE_INCLUDES) + + if(NOT INTERFACE_INCLUDES) + message(WARNING "Target '${TARGET}' has no PUBLIC or INTERFACE includes.") + return() + endif() + get_filename_component(PROJECT_SOURCE_ABS "${CMAKE_SOURCE_DIR}" ABSOLUTE) + set(FILTERED_INCLUDES "") + + foreach(inc IN LISTS INTERFACE_INCLUDES) + set(resolved_inc "") + if("${inc}" MATCHES "^\\$]+)>$") + set(resolved_inc "${CMAKE_MATCH_1}") + else() + set(resolved_inc "${inc}") + endif() + + if("${resolved_inc}" MATCHES "^${PROJECT_SOURCE_ABS}") + list(APPEND FILTERED_INCLUDES "${resolved_inc}") + else() + message(STATUS "Ignoring external include: ${resolved_inc}") + endif() + endforeach() + + set(INTERFACE_INCLUDES ${FILTERED_INCLUDES}) + + string(REPLACE ";" "|" INTERFACE_INCLUDES_ESCAPED "${INTERFACE_INCLUDES}") + + message(STATUS "Copying public headers for target: ${TARGET}") + + set(INTERFACE_INCLUDES "${INTERFACE_INCLUDES_ESCAPED}") + string(REPLACE "|" ";" INTERFACE_INCLUDES "${INTERFACE_INCLUDES}") + + foreach(INC_DIR ${INTERFACE_INCLUDES}) + copy_headers(${INC_DIR} ${CMAKE_CURRENT_BINARY_DIR}/include) + endforeach() + + install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/ DESTINATION include/${TARGET}) +endfunction() diff --git a/src/Engine/src/Core/AssetManagement/AssetManager.h b/src/Engine/src/Core/AssetManagement/AssetManager.h index 0fdd325f..7a8cbb11 100644 --- a/src/Engine/src/Core/AssetManagement/AssetManager.h +++ b/src/Engine/src/Core/AssetManagement/AssetManager.h @@ -10,6 +10,7 @@ #include "LocalizedAsset.h" #include #include +#include namespace BeeEngine { @@ -77,7 +78,7 @@ namespace BeeEngine BeeExpects(s_AssetManager); s_AssetManager->UnloadAsset(handle); } - static void LoadAsset(gsl::span data, AssetHandle handle, const String& name, AssetType type) + static void LoadAsset(std::span data, AssetHandle handle, const String& name, AssetType type) { BeeExpects(s_AssetManager); s_AssetManager->LoadAsset(data, std::move(handle), name, type); diff --git a/src/Engine/src/Core/AssetManagement/AssetMetadata.h b/src/Engine/src/Core/AssetManagement/AssetMetadata.h index 79d88297..d0aeb70a 100644 --- a/src/Engine/src/Core/AssetManagement/AssetMetadata.h +++ b/src/Engine/src/Core/AssetManagement/AssetMetadata.h @@ -6,7 +6,6 @@ #include "Asset.h" #include "Core/Path.h" #include "Core/TypeDefines.h" -#include "gsl/span" #include #include @@ -17,8 +16,8 @@ namespace BeeEngine String Name; AssetType Type = AssetType::None; AssetLocation Location = AssetLocation::FileSystem; - std::variant, Path> Data; + std::variant, Path> Data; operator bool() const { return Type != AssetType::None; } }; -} // namespace BeeEngine \ No newline at end of file +} // namespace BeeEngine diff --git a/src/Engine/src/Core/AssetManagement/EditorAssetManager.cpp b/src/Engine/src/Core/AssetManagement/EditorAssetManager.cpp index bf9e27fb..6291d21a 100644 --- a/src/Engine/src/Core/AssetManagement/EditorAssetManager.cpp +++ b/src/Engine/src/Core/AssetManagement/EditorAssetManager.cpp @@ -24,7 +24,7 @@ namespace BeeEngine return m_AssetMap.at(handle); } - void EditorAssetManager::LoadAsset(gsl::span data, AssetHandle handle, const String& name, AssetType type) + void EditorAssetManager::LoadAsset(std::span data, AssetHandle handle, const String& name, AssetType type) { BeeExpects(!IsAssetHandleValid(handle) && !IsAssetLoaded(handle)); AssetMetadata metadata; diff --git a/src/Engine/src/Core/AssetManagement/EditorAssetManager.h b/src/Engine/src/Core/AssetManagement/EditorAssetManager.h index 1abda222..8ec9b270 100644 --- a/src/Engine/src/Core/AssetManagement/EditorAssetManager.h +++ b/src/Engine/src/Core/AssetManagement/EditorAssetManager.h @@ -25,7 +25,7 @@ namespace BeeEngine GetAssetHandleByName( const String& name) const; // TODO write the replacement, that works on path, not on the name - void LoadAsset(gsl::span data, AssetHandle handle, const String& name, AssetType type) final; + void LoadAsset(std::span data, AssetHandle handle, const String& name, AssetType type) final; void LoadAsset(const Path& path, AssetHandle handle) final; diff --git a/src/Engine/src/Core/AssetManagement/FontImporter.cpp b/src/Engine/src/Core/AssetManagement/FontImporter.cpp index b73f0951..914dfcef 100644 --- a/src/Engine/src/Core/AssetManagement/FontImporter.cpp +++ b/src/Engine/src/Core/AssetManagement/FontImporter.cpp @@ -16,7 +16,7 @@ namespace BeeEngine } else { - result = CreateRef(metadata.Name, std::get>(metadata.Data)); + result = CreateRef(metadata.Name, std::get>(metadata.Data)); } result->Handle = handle; result->Location = metadata.Location; diff --git a/src/Engine/src/Core/AssetManagement/IAssetManager.h b/src/Engine/src/Core/AssetManagement/IAssetManager.h index bcca2433..c5892d40 100644 --- a/src/Engine/src/Core/AssetManagement/IAssetManager.h +++ b/src/Engine/src/Core/AssetManagement/IAssetManager.h @@ -7,7 +7,6 @@ #include "AssetMetadata.h" #include "Core/Path.h" #include "Core/String.h" -#include "gsl/span" #include namespace BeeEngine @@ -19,7 +18,7 @@ namespace BeeEngine public: virtual Ref GetAssetRef(AssetHandle handle) const = 0; virtual Asset* GetAsset(AssetHandle handle) const = 0; - virtual void LoadAsset(gsl::span data, AssetHandle handle, const String& name, AssetType type) = 0; + virtual void LoadAsset(std::span data, AssetHandle handle, const String& name, AssetType type) = 0; virtual void LoadAsset(const Path& path, AssetHandle handle) = 0; virtual void UnloadAsset(AssetHandle handle) = 0; diff --git a/src/Engine/src/Core/AssetManagement/LocalizedAsset.cpp b/src/Engine/src/Core/AssetManagement/LocalizedAsset.cpp index 1e6996ac..2ff90cb5 100644 --- a/src/Engine/src/Core/AssetManagement/LocalizedAsset.cpp +++ b/src/Engine/src/Core/AssetManagement/LocalizedAsset.cpp @@ -38,8 +38,8 @@ namespace BeeEngine } else if (metadata.Location == AssetLocation::Embedded) { - String content = String((char*)std::get>(metadata.Data).data(), - std::get>(metadata.Data).size()); + String content = String((char*)std::get>(metadata.Data).data(), + std::get>(metadata.Data).size()); return LocalizedAssetSerializer::Deserialize(content); } BeeCoreError("Unknown asset location: {}", metadata.Location); @@ -72,4 +72,4 @@ namespace BeeEngine } return CreateRef(std::move(assets)); } -} // namespace BeeEngine \ No newline at end of file +} // namespace BeeEngine diff --git a/src/Engine/src/Core/AssetManagement/PrefabImporter.cpp b/src/Engine/src/Core/AssetManagement/PrefabImporter.cpp index cace1375..abc0453a 100644 --- a/src/Engine/src/Core/AssetManagement/PrefabImporter.cpp +++ b/src/Engine/src/Core/AssetManagement/PrefabImporter.cpp @@ -27,7 +27,7 @@ namespace BeeEngine } else if (metadata.Location == AssetLocation::Embedded) { - auto& data = std::get>(metadata.Data); + auto& data = std::get>(metadata.Data); prefabFile = String((char*)data.data(), data.size()); } else diff --git a/src/Engine/src/Core/AssetManagement/TextureImporter.cpp b/src/Engine/src/Core/AssetManagement/TextureImporter.cpp index 28040b35..45f27f55 100644 --- a/src/Engine/src/Core/AssetManagement/TextureImporter.cpp +++ b/src/Engine/src/Core/AssetManagement/TextureImporter.cpp @@ -4,6 +4,7 @@ #include "TextureImporter.h" #include "Core/AssetManagement/Asset.h" +#include "Core/Casts.h" #include "Core/CodeSafety/Expects.h" #include "Core/ScopeGuard.h" #include "Renderer/Texture.h" @@ -11,7 +12,7 @@ #define STBI_WINDOWS_UTF8 #include "Platform/Windows/WindowsString.h" #endif -#include +#include #if defined(WINDOWS) STBIDEF stbi_uc* stbi_load(const wchar_t* filename, int* x, int* y, int* comp, int req_comp); #endif @@ -41,13 +42,13 @@ namespace BeeEngine } return GPUTextureResource::Create(width, height, {(byte*)data, size_t(width * height * channels)}, channels); } - Scope TextureImporter::LoadTextureFromMemory(gsl::span textureData) + Scope TextureImporter::LoadTextureFromMemory(std::span textureData) { BeeExpects(!textureData.empty()); int width, height, channels; stbi_set_flip_vertically_on_load(true); stbi_uc* data = stbi_load_from_memory(reinterpret_cast(textureData.data()), - gsl::narrow_cast(textureData.size()), + narrow_cast(textureData.size()), &width, &height, &channels, @@ -75,7 +76,7 @@ namespace BeeEngine case AssetLocation::FileSystem: return CreateRef(LoadTextureFromFile(std::get(metadata.Data))); case AssetLocation::Embedded: - return CreateRef(LoadTextureFromMemory(std::get>(metadata.Data))); + return CreateRef(LoadTextureFromMemory(std::get>(metadata.Data))); } BeeEnsures(false && "Unknown location of asset"); }(); diff --git a/src/Engine/src/Core/AssetManagement/TextureImporter.h b/src/Engine/src/Core/AssetManagement/TextureImporter.h index 154611a6..b206de21 100644 --- a/src/Engine/src/Core/AssetManagement/TextureImporter.h +++ b/src/Engine/src/Core/AssetManagement/TextureImporter.h @@ -6,6 +6,7 @@ #include "AssetMetadata.h" #include "Core/TypeDefines.h" #include "Renderer/Texture.h" +#include namespace BeeEngine { @@ -14,6 +15,6 @@ namespace BeeEngine public: static Ref ImportTexture2D(AssetHandle handle, const AssetMetadata& metadata); static Scope LoadTextureFromFile(const Path& path); - static Scope LoadTextureFromMemory(gsl::span data); + static Scope LoadTextureFromMemory(std::span data); }; } // namespace BeeEngine diff --git a/src/Engine/src/Core/Cameras/Camera.h b/src/Engine/src/Core/Cameras/Camera.h index a97e22d5..b454a906 100644 --- a/src/Engine/src/Core/Cameras/Camera.h +++ b/src/Engine/src/Core/Cameras/Camera.h @@ -3,7 +3,7 @@ // #pragma once -#include "glm.hpp" +#include namespace BeeEngine { class Camera diff --git a/src/Engine/src/Core/Cameras/ICamera.h b/src/Engine/src/Core/Cameras/ICamera.h index 416b476b..06a45d08 100644 --- a/src/Engine/src/Core/Cameras/ICamera.h +++ b/src/Engine/src/Core/Cameras/ICamera.h @@ -4,7 +4,7 @@ #pragma once -#include "detail/type_mat4x4.hpp" +#include namespace BeeEngine { diff --git a/src/Engine/src/Core/Color4.h b/src/Engine/src/Core/Color4.h index 604ac59c..f1ed3bba 100644 --- a/src/Engine/src/Core/Color4.h +++ b/src/Engine/src/Core/Color4.h @@ -6,8 +6,8 @@ #if defined(BEE_COMPILE_VULKAN) #include #endif -#if __has_include() -#include +#if __has_include() +#include #endif #if __has_include() #include @@ -62,7 +62,7 @@ namespace BeeEngine [[nodiscard]] inline constexpr float* ValuePtr() { return static_cast(&m_R); } -#if __has_include() +#if __has_include() constexpr inline operator glm::vec4() const { return {m_R, m_G, m_B, m_A}; } #endif diff --git a/src/Engine/src/Core/EntryPoint.cpp b/src/Engine/src/Core/EntryPoint.cpp index aaed1fff..5629e668 100644 --- a/src/Engine/src/Core/EntryPoint.cpp +++ b/src/Engine/src/Core/EntryPoint.cpp @@ -64,6 +64,7 @@ namespace BeeEngine Internal::WindowsUTF8ConsoleOutput consoleOutput; Internal::SetCorrectCurrentPath(); Application* application = CreateApplication({argc, argv}); + BeeExpects(application != nullptr); BEE_DEBUG_END_PROFILING_SESSION(); application->Run(); BEE_DEBUG_START_PROFILING_SESSION("BeeEngineShutdown", "shutdown.json"); diff --git a/src/Engine/src/Core/EntryPoint.h b/src/Engine/src/Core/EntryPoint.h index 555ac07c..2a54bcb5 100644 --- a/src/Engine/src/Core/EntryPoint.h +++ b/src/Engine/src/Core/EntryPoint.h @@ -73,7 +73,7 @@ namespace BeeEngine * @param args The arguments to be passed to the application. * @return A non-null pointer to the created application instance. */ - extern gsl::not_null CreateApplication(const ApplicationArgs& args); + extern Application* CreateApplication(const ApplicationArgs& args); } // namespace BeeEngine #ifdef __cplusplus diff --git a/src/Engine/src/Core/Events/Event.h b/src/Engine/src/Core/Events/Event.h index 659ce650..bbd83068 100644 --- a/src/Engine/src/Core/Events/Event.h +++ b/src/Engine/src/Core/Events/Event.h @@ -1,6 +1,6 @@ #pragma once - -#include +#include +#include "Core/CodeSafety/Expects.h" namespace BeeEngine { @@ -49,27 +49,15 @@ namespace BeeEngine protected: bool m_Handled = false; EventType m_Type; - - public: - /* //Events pool - static void* operator new(size_t size); - static void operator delete(void* ptr, size_t size) noexcept; - static void* operator new[](size_t size); - static void operator delete[](void* ptr, size_t size) noexcept; - - static void ClearPool() - { - s_EventPool.Clear(); - } - - private: - static ObjectPool s_EventPool;*/ }; class EventDispatcher { public: - explicit EventDispatcher(gsl::not_null event) : m_event(event) {} + explicit EventDispatcher(Event* event) : m_event(event) + { + BeeExpects(event != nullptr); + } [[nodiscard]] inline EventCategory GetCategory() const { return m_event->Category; } [[nodiscard]] inline EventType GetType() const { return m_event->GetType(); } @@ -91,4 +79,4 @@ namespace BeeEngine private: Event* m_event; }; -} // namespace BeeEngine \ No newline at end of file +} // namespace BeeEngine diff --git a/src/Engine/src/Core/Hash.h b/src/Engine/src/Core/Hash.h index 3189e712..8b75c6dd 100644 --- a/src/Engine/src/Core/Hash.h +++ b/src/Engine/src/Core/Hash.h @@ -44,6 +44,17 @@ namespace BeeEngine { return value.Hash(seed); } + + inline uint64_t Hash(const String& value, uint64_t seed = 0) + { + return HashAlgorithm::MurmurHash2_64(value.data(), value.size(), seed); + } + + template + uint64_t Hash(const T& value, uint64_t seed = 0) + { + return HashAlgorithm::MurmurHash2_64(&value, sizeof(T), seed); + } template requires(!std::convertible_to) uint64_t Hash(const T& value, uint64_t seed = 0) @@ -56,17 +67,6 @@ namespace BeeEngine } return hash; } - - inline uint64_t Hash(const String& value, uint64_t seed = 0) - { - return HashAlgorithm::MurmurHash2_64(value.data(), value.size(), seed); - } - - template - uint64_t Hash(const T& value, uint64_t seed = 0) - { - return HashAlgorithm::MurmurHash2_64(&value, sizeof(T), seed); - } namespace Reflection { template @@ -94,4 +94,4 @@ namespace std { size_t operator()(const T& obj) const { return static_cast(BeeEngine::Hash(obj)); } }; -} // namespace std \ No newline at end of file +} // namespace std diff --git a/src/Engine/src/Core/Logging/Log.h b/src/Engine/src/Core/Logging/Log.h index 18719360..e8abd625 100644 --- a/src/Engine/src/Core/Logging/Log.h +++ b/src/Engine/src/Core/Logging/Log.h @@ -7,7 +7,7 @@ #include "Core/Format.h" #include "Core/Logging/ConsoleOutput.h" #include "Core/ToString.h" -#include "debugbreak.h" +#include "Core/debugbreak.h" #include "memory.h" #include "spdlog/sinks/stdout_color_sinks.h" #include "spdlog/spdlog.h" diff --git a/src/Engine/src/Core/Math/Math.cpp b/src/Engine/src/Core/Math/Math.cpp index 3518747f..c881b7ee 100644 --- a/src/Engine/src/Core/Math/Math.cpp +++ b/src/Engine/src/Core/Math/Math.cpp @@ -4,9 +4,9 @@ #include "Math.h" #include "Scene/Components.h" -#include "ext/scalar_constants.hpp" -#include "gtc/epsilon.hpp" -#include "gtx/matrix_decompose.inl" +#include +#include +#include namespace BeeEngine::Math { @@ -296,4 +296,4 @@ namespace BeeEngine::Math radians = rad; return *this; } -} // namespace BeeEngine::Math \ No newline at end of file +} // namespace BeeEngine::Math diff --git a/src/Engine/src/Core/Math/Math.h b/src/Engine/src/Core/Math/Math.h index dca1502a..3597ae85 100644 --- a/src/Engine/src/Core/Math/Math.h +++ b/src/Engine/src/Core/Math/Math.h @@ -4,15 +4,16 @@ #pragma once -#include "glm.hpp" +#include #include #include +#include namespace BeeEngine::Math { consteval float32_t PI() { - return 3.141592653589793238462643383279502884197169399375105820974944592307816406286f; + return std::numbers::pi_v; } struct DecomposedTransform { @@ -137,4 +138,4 @@ namespace BeeEngine::Math glm::vec3 GetScaleFromMatrix(const glm::mat4& mat); glm::mat4 GetTransformFromTo(const glm::vec3& start, const glm::vec3& end, float lineWidth); -} // namespace BeeEngine::Math \ No newline at end of file +} // namespace BeeEngine::Math diff --git a/src/Engine/src/Core/ResourceManager.h b/src/Engine/src/Core/ResourceManager.h index 84d86af9..892f1326 100644 --- a/src/Engine/src/Core/ResourceManager.h +++ b/src/Engine/src/Core/ResourceManager.h @@ -11,7 +11,6 @@ #include "String.h" #include "TypeDefines.h" #include "algorithm" -#include #include #include diff --git a/src/Engine/vendor/SIMDString/SIMDString.cpp b/src/Engine/src/Core/SIMDString.cpp similarity index 100% rename from src/Engine/vendor/SIMDString/SIMDString.cpp rename to src/Engine/src/Core/SIMDString.cpp diff --git a/src/Engine/vendor/SIMDString/SIMDString.h b/src/Engine/src/Core/SIMDString.h similarity index 100% rename from src/Engine/vendor/SIMDString/SIMDString.h rename to src/Engine/src/Core/SIMDString.h diff --git a/src/Engine/src/Core/String.cpp b/src/Engine/src/Core/String.cpp index 6568847a..21d1dc19 100644 --- a/src/Engine/src/Core/String.cpp +++ b/src/Engine/src/Core/String.cpp @@ -7,7 +7,7 @@ #define UTF_CPP_CPLUSPLUS 201703L #include #include -#include +#include namespace BeeEngine { diff --git a/src/Engine/src/Core/String.h b/src/Engine/src/Core/String.h index 324ee94e..451cb052 100644 --- a/src/Engine/src/Core/String.h +++ b/src/Engine/src/Core/String.h @@ -3,7 +3,7 @@ // #pragma once -#include +#include "SIMDString.h" #include #include #include @@ -179,4 +179,4 @@ namespace BeeEngine } } // namespace BeeEngine using namespace BeeEngine::StringLiterals; // May be removed in future -#undef CONSTEXPR \ No newline at end of file +#undef CONSTEXPR diff --git a/src/Engine/src/Core/debugbreak.h b/src/Engine/src/Core/debugbreak.h new file mode 100644 index 00000000..bfb82884 --- /dev/null +++ b/src/Engine/src/Core/debugbreak.h @@ -0,0 +1,174 @@ +/* Copyright (c) 2011-2021, Scott Tsai + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef DEBUG_BREAK_H +#define DEBUG_BREAK_H + +#ifdef _MSC_VER + +#define debug_break __debugbreak + +#else + +#ifdef __cplusplus +extern "C" { +#endif + +#define DEBUG_BREAK_USE_TRAP_INSTRUCTION 1 +#define DEBUG_BREAK_USE_BULTIN_TRAP 2 +#define DEBUG_BREAK_USE_SIGTRAP 3 + +#if defined(__i386__) || defined(__x86_64__) + #define DEBUG_BREAK_IMPL DEBUG_BREAK_USE_TRAP_INSTRUCTION +__inline__ static void trap_instruction(void) +{ + __asm__ volatile("int $0x03"); +} +#elif defined(__thumb__) + #define DEBUG_BREAK_IMPL DEBUG_BREAK_USE_TRAP_INSTRUCTION +/* FIXME: handle __THUMB_INTERWORK__ */ +__attribute__((always_inline)) +__inline__ static void trap_instruction(void) +{ + /* See 'arm-linux-tdep.c' in GDB source. + * Both instruction sequences below work. */ +#if 1 + /* 'eabi_linux_thumb_le_breakpoint' */ + __asm__ volatile(".inst 0xde01"); +#else + /* 'eabi_linux_thumb2_le_breakpoint' */ + __asm__ volatile(".inst.w 0xf7f0a000"); +#endif + + /* Known problem: + * After a breakpoint hit, can't 'stepi', 'step', or 'continue' in GDB. + * 'step' would keep getting stuck on the same instruction. + * + * Workaround: use the new GDB commands 'debugbreak-step' and + * 'debugbreak-continue' that become available + * after you source the script from GDB: + * + * $ gdb -x debugbreak-gdb.py <... USUAL ARGUMENTS ...> + * + * 'debugbreak-step' would jump over the breakpoint instruction with + * roughly equivalent of: + * (gdb) set $instruction_len = 2 + * (gdb) tbreak *($pc + $instruction_len) + * (gdb) jump *($pc + $instruction_len) + */ +} +#elif defined(__arm__) && !defined(__thumb__) + #define DEBUG_BREAK_IMPL DEBUG_BREAK_USE_TRAP_INSTRUCTION +__attribute__((always_inline)) +__inline__ static void trap_instruction(void) +{ + /* See 'arm-linux-tdep.c' in GDB source, + * 'eabi_linux_arm_le_breakpoint' */ + __asm__ volatile(".inst 0xe7f001f0"); + /* Known problem: + * Same problem and workaround as Thumb mode */ +} +#elif defined(__aarch64__) && defined(__APPLE__) + #define DEBUG_BREAK_IMPL DEBUG_BREAK_USE_BULTIN_DEBUGTRAP +#elif defined(__aarch64__) + #define DEBUG_BREAK_IMPL DEBUG_BREAK_USE_TRAP_INSTRUCTION +__attribute__((always_inline)) +__inline__ static void trap_instruction(void) +{ + /* See 'aarch64-tdep.c' in GDB source, + * 'aarch64_default_breakpoint' */ + __asm__ volatile(".inst 0xd4200000"); +} +#elif defined(__powerpc__) + /* PPC 32 or 64-bit, big or little endian */ + #define DEBUG_BREAK_IMPL DEBUG_BREAK_USE_TRAP_INSTRUCTION +__attribute__((always_inline)) +__inline__ static void trap_instruction(void) +{ + /* See 'rs6000-tdep.c' in GDB source, + * 'rs6000_breakpoint' */ + __asm__ volatile(".4byte 0x7d821008"); + + /* Known problem: + * After a breakpoint hit, can't 'stepi', 'step', or 'continue' in GDB. + * 'step' stuck on the same instruction ("twge r2,r2"). + * + * The workaround is the same as ARM Thumb mode: use debugbreak-gdb.py + * or manually jump over the instruction. */ +} +#elif defined(__riscv) + /* RISC-V 32 or 64-bit, whether the "C" extension + * for compressed, 16-bit instructions are supported or not */ + #define DEBUG_BREAK_IMPL DEBUG_BREAK_USE_TRAP_INSTRUCTION +__attribute__((always_inline)) +__inline__ static void trap_instruction(void) +{ + /* See 'riscv-tdep.c' in GDB source, + * 'riscv_sw_breakpoint_from_kind' */ + __asm__ volatile(".4byte 0x00100073"); +} +#else + #define DEBUG_BREAK_IMPL DEBUG_BREAK_USE_SIGTRAP +#endif + + +#ifndef DEBUG_BREAK_IMPL +#error "debugbreak.h is not supported on this target" +#elif DEBUG_BREAK_IMPL == DEBUG_BREAK_USE_TRAP_INSTRUCTION +__attribute__((always_inline)) +__inline__ static void debug_break(void) +{ + trap_instruction(); +} +#elif DEBUG_BREAK_IMPL == DEBUG_BREAK_USE_BULTIN_DEBUGTRAP +__attribute__((always_inline)) +__inline__ static void debug_break(void) +{ + __builtin_debugtrap(); +} +#elif DEBUG_BREAK_IMPL == DEBUG_BREAK_USE_BULTIN_TRAP +__attribute__((always_inline)) +__inline__ static void debug_break(void) +{ + __builtin_trap(); +} +#elif DEBUG_BREAK_IMPL == DEBUG_BREAK_USE_SIGTRAP +#include +__attribute__((always_inline)) +__inline__ static void debug_break(void) +{ + raise(SIGTRAP); +} +#else +#error "invalid DEBUG_BREAK_IMPL value" +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* ifdef _MSC_VER */ + +#endif /* ifndef DEBUG_BREAK_H */ diff --git a/src/Engine/src/Debug/Instrumentor.h b/src/Engine/src/Debug/Instrumentor.h index abf8185f..1df0cdfa 100644 --- a/src/Engine/src/Debug/Instrumentor.h +++ b/src/Engine/src/Debug/Instrumentor.h @@ -20,6 +20,7 @@ // You will probably want to macro-fy this, to switch on/off easily and use things like __FUNCSIG__ for the profile // name. // +#include "Core/Casts.h" #include "version" #ifdef BEE_ENABLE_PROFILING @@ -45,7 +46,6 @@ #include #include #include -#include #include #include @@ -163,7 +163,7 @@ namespace BeeEngine std::chrono::time_point_cast(endTimepoint).time_since_epoch().count(); uint32_t threadID = - gsl::narrow_cast(std::hash{}(std::this_thread::get_id())); + narrow_cast(std::hash{}(std::this_thread::get_id())); Instrumentor::Get().WriteProfile({m_Name, start, end, threadID}); m_Stopped = true; diff --git a/src/Engine/src/FileSystem/File.cpp b/src/Engine/src/FileSystem/File.cpp index 3e20cdd8..c42a25a3 100644 --- a/src/Engine/src/FileSystem/File.cpp +++ b/src/Engine/src/FileSystem/File.cpp @@ -44,7 +44,7 @@ namespace BeeEngine return buffer; } - void File::WriteBinaryFile(const Path& path, gsl::span content) + void File::WriteBinaryFile(const Path& path, std::span content) { std::ofstream ofs(path.ToStdPath(), std::ios::out | std::ios::binary); if (!ofs) diff --git a/src/Engine/src/FileSystem/File.h b/src/Engine/src/FileSystem/File.h index 9cb6da62..35599537 100644 --- a/src/Engine/src/FileSystem/File.h +++ b/src/Engine/src/FileSystem/File.h @@ -6,10 +6,10 @@ #include "Core/Path.h" #include "Core/String.h" -#include "gsl/span" #include #include #include +#include #undef CreateDirectory #undef CopyFile namespace BeeEngine @@ -21,7 +21,7 @@ namespace BeeEngine static std::vector ReadBinaryFile(const Path& path); static void WriteFile(const Path& path, std::string_view content); static void WriteFile(const Path& path, const String& content); - static void WriteBinaryFile(const Path& path, gsl::span content); + static void WriteBinaryFile(const Path& path, std::span content); static size_t Size(const Path& path); static bool Exists(std::string_view path); static bool Exists(const std::filesystem::path& path); diff --git a/src/Engine/src/Platform/Vulkan/VulkanGraphicsDevice.cpp b/src/Engine/src/Platform/Vulkan/VulkanGraphicsDevice.cpp index bee8f847..fdc8c9c3 100644 --- a/src/Engine/src/Platform/Vulkan/VulkanGraphicsDevice.cpp +++ b/src/Engine/src/Platform/Vulkan/VulkanGraphicsDevice.cpp @@ -767,7 +767,7 @@ namespace BeeEngine::Internal }); } - void VulkanGraphicsDevice::CopyToBuffer(gsl::span data, VulkanBuffer& outBuffer) const + void VulkanGraphicsDevice::CopyToBuffer(std::span data, VulkanBuffer& outBuffer) const { void* mappedData; vmaMapMemory(m_DeviceHandle.allocator, outBuffer.Memory, &mappedData); diff --git a/src/Engine/src/Platform/Vulkan/VulkanGraphicsDevice.h b/src/Engine/src/Platform/Vulkan/VulkanGraphicsDevice.h index 859dc733..5ce70d5f 100644 --- a/src/Engine/src/Platform/Vulkan/VulkanGraphicsDevice.h +++ b/src/Engine/src/Platform/Vulkan/VulkanGraphicsDevice.h @@ -73,7 +73,7 @@ namespace BeeEngine::Internal void DestroyImage(VulkanImage& image) const; void DestroyImageWithView(VulkanImage& image, vk::ImageView imageView) const; - void CopyToBuffer(gsl::span data, VulkanBuffer& outBuffer) const; + void CopyToBuffer(std::span data, VulkanBuffer& outBuffer) const; vk::CommandBuffer BeginSingleTimeCommands(); diff --git a/src/Engine/src/Platform/Vulkan/VulkanTLAS.cpp b/src/Engine/src/Platform/Vulkan/VulkanTLAS.cpp index b22e6b78..81d19332 100644 --- a/src/Engine/src/Platform/Vulkan/VulkanTLAS.cpp +++ b/src/Engine/src/Platform/Vulkan/VulkanTLAS.cpp @@ -4,8 +4,8 @@ #include "VulkanTLAS.h" -#include -#include +#include +#include namespace BeeEngine::Internal { diff --git a/src/Engine/src/Platform/Vulkan/VulkanTexture2D.cpp b/src/Engine/src/Platform/Vulkan/VulkanTexture2D.cpp index 4b853058..2f997fa5 100644 --- a/src/Engine/src/Platform/Vulkan/VulkanTexture2D.cpp +++ b/src/Engine/src/Platform/Vulkan/VulkanTexture2D.cpp @@ -59,7 +59,7 @@ namespace BeeEngine::Internal return {imageWrite, samplerWrite}; } - void VulkanGPUTextureResource::SetData(gsl::span data, uint32_t numberOfChannels) + void VulkanGPUTextureResource::SetData(std::span data, uint32_t numberOfChannels) { std::vector dataWithAlpha; if (numberOfChannels == 3) @@ -158,7 +158,7 @@ namespace BeeEngine::Internal VulkanGPUTextureResource::VulkanGPUTextureResource(uint32_t width, uint32_t height, - gsl::span data, + std::span data, uint32_t numberOfChannels) : m_Device(VulkanGraphicsDevice::GetInstance()) { diff --git a/src/Engine/src/Platform/Vulkan/VulkanTexture2D.h b/src/Engine/src/Platform/Vulkan/VulkanTexture2D.h index d36cdfbe..082f80e2 100644 --- a/src/Engine/src/Platform/Vulkan/VulkanTexture2D.h +++ b/src/Engine/src/Platform/Vulkan/VulkanTexture2D.h @@ -3,6 +3,7 @@ // #pragma once +#include #include "Renderer/Texture.h" #include "VulkanGraphicsDevice.h" @@ -15,14 +16,14 @@ namespace BeeEngine::Internal std::vector GetBindGroupEntry() const override; - void SetData(gsl::span data, uint32_t numberOfChannels) override; + void SetData(std::span data, uint32_t numberOfChannels) override; VulkanGPUTextureResource( uint32_t width, uint32_t height, VulkanImage image, vk::ImageView view, vk::Sampler sampler); VulkanImage& GetVulkanImage() { return m_Image; } VulkanImage GetVulkanImage() const { return m_Image; } vk::ImageView& GetVulkanImageView() { return m_ImageView; } - VulkanGPUTextureResource(uint32_t width, uint32_t height, gsl::span data, uint32_t numberOfChannels); + VulkanGPUTextureResource(uint32_t width, uint32_t height, std::span data, uint32_t numberOfChannels); ~VulkanGPUTextureResource() override; private: diff --git a/src/Engine/src/Renderer/AssetManager.cpp b/src/Engine/src/Renderer/AssetManager.cpp index f07bd678..15f73d85 100644 --- a/src/Engine/src/Renderer/AssetManager.cpp +++ b/src/Engine/src/Renderer/AssetManager.cpp @@ -5,7 +5,8 @@ #include "AssetManager.h" #include "../../Assets/EmbeddedResources.h" #include "Vertex.h" -#include +#include +#include BeeEngine::Material& BeeEngine::InternalAssetManager::LoadMaterial(const String& name, const std::filesystem::path& vertexShader, @@ -132,7 +133,7 @@ bool BeeEngine::InternalAssetManager::HasModel(const String& name) const } BeeEngine::Texture2D& -BeeEngine::InternalAssetManager::LoadTexture(const String& name, uint32_t width, uint32_t height, gsl::span data) +BeeEngine::InternalAssetManager::LoadTexture(const String& name, uint32_t width, uint32_t height, std::span data) { m_Textures.emplace(name, Texture2D::Create(width, height, data)); return *m_Textures.at(name); @@ -146,7 +147,7 @@ BeeEngine::Font& BeeEngine::InternalAssetManager::LoadFont(const String& name, c return *m_Fonts.emplace(name, CreateRef(path)).first->second; } -BeeEngine::Font& BeeEngine::InternalAssetManager::LoadFont(const String& name, gsl::span data) +BeeEngine::Font& BeeEngine::InternalAssetManager::LoadFont(const String& name, std::span data) { if (HasFont(name)) return GetFont(name); diff --git a/src/Engine/src/Renderer/AssetManager.h b/src/Engine/src/Renderer/AssetManager.h index fc8024a4..9a018b9e 100644 --- a/src/Engine/src/Renderer/AssetManager.h +++ b/src/Engine/src/Renderer/AssetManager.h @@ -26,10 +26,10 @@ namespace BeeEngine [[nodiscard]] Mesh& LoadMesh(const String& name, std::vector& vertices, std::vector& indices); [[nodiscard]] Texture2D& LoadTexture(const String& name, const std::filesystem::path& path); - [[nodiscard]] Texture2D& LoadTexture(const String& name, uint32_t width, uint32_t height, gsl::span data); + [[nodiscard]] Texture2D& LoadTexture(const String& name, uint32_t width, uint32_t height, std::span data); [[nodiscard]] Model& LoadModel(const String& name, Material& material, Mesh& mesh); [[nodiscard]] Font& LoadFont(const String& name, const std::filesystem::path& path); - [[nodiscard]] Font& LoadFont(const String& name, gsl::span data); + [[nodiscard]] Font& LoadFont(const String& name, std::span data); [[nodiscard]] Material& GetMaterial(const String& name); [[nodiscard]] Mesh& GetMesh(const String& name); diff --git a/src/Engine/src/Renderer/CommandBuffer.cpp b/src/Engine/src/Renderer/CommandBuffer.cpp index cd1a4ff3..2c7f35cc 100644 --- a/src/Engine/src/Renderer/CommandBuffer.cpp +++ b/src/Engine/src/Renderer/CommandBuffer.cpp @@ -43,7 +43,7 @@ namespace BeeEngine } void - CommandBuffer::SubmitInstance(Model& model, std::vector& bindingSets, gsl::span instanceData) + CommandBuffer::SubmitInstance(Model& model, std::vector& bindingSets, std::span instanceData) { BeeExpects(IsValid()); m_RenderingQueue->SubmitInstance({&model, bindingSets}, instanceData); diff --git a/src/Engine/src/Renderer/CommandBuffer.h b/src/Engine/src/Renderer/CommandBuffer.h index 0b6af653..40a11731 100644 --- a/src/Engine/src/Renderer/CommandBuffer.h +++ b/src/Engine/src/Renderer/CommandBuffer.h @@ -3,7 +3,7 @@ // #pragma once -#include +#include #include "Core/String.h" #include "Core/TypeDefines.h" @@ -38,7 +38,7 @@ namespace BeeEngine const TextRenderingConfiguration& config, int32_t entityId = -1); void DrawRect(const glm::mat4& transform, const Color4& color, BindingSet& cameraBindingSet, float lineWidth); - void SubmitInstance(Model& model, std::vector& bindingSets, gsl::span instanceData); + void SubmitInstance(Model& model, std::vector& bindingSets, std::span instanceData); void SubmitLine(const glm::vec3& start, const glm::vec3& end, BindingSet& cameraBindingSet, diff --git a/src/Engine/src/Renderer/EditorCamera.cpp b/src/Engine/src/Renderer/EditorCamera.cpp index d1e0f3a6..6f12a9a9 100644 --- a/src/Engine/src/Renderer/EditorCamera.cpp +++ b/src/Engine/src/Renderer/EditorCamera.cpp @@ -5,9 +5,9 @@ #include "EditorCamera.h" #include "Core/Input.h" #include "Debug/Instrumentor.h" -#include "detail/type_quat.hpp" -#include "ext/matrix_clip_space.hpp" -#include "gtx/quaternion.hpp" +#include +#include +#include namespace BeeEngine { diff --git a/src/Engine/src/Renderer/Font.cpp b/src/Engine/src/Renderer/Font.cpp index a918deab..b90ee29a 100644 --- a/src/Engine/src/Renderer/Font.cpp +++ b/src/Engine/src/Renderer/Font.cpp @@ -19,11 +19,11 @@ #include "ext/save-png.h" #include #include -#include +#include #include #include #include -#include +#include #include "Core/Application.h" #include #include @@ -308,7 +308,7 @@ namespace BeeEngine } } - Font::Font(const String& name, gsl::span data) : m_Data(new Internal::MSDFData()) + Font::Font(const String& name, std::span data) : m_Data(new Internal::MSDFData()) { { std::unique_lock lock(s_Lock); diff --git a/src/Engine/src/Renderer/Font.h b/src/Engine/src/Renderer/Font.h index d41b496f..37283e63 100644 --- a/src/Engine/src/Renderer/Font.h +++ b/src/Engine/src/Renderer/Font.h @@ -37,7 +37,7 @@ namespace BeeEngine * @param name The name of the font. * @param data The raw font data as a span of bytes. */ - Font(const String& name, gsl::span data); + Font(const String& name, std::span data); /// Deleted copy constructor to prevent copying. Font(const Font&) = delete; diff --git a/src/Engine/src/Renderer/RenderingQueue.cpp b/src/Engine/src/Renderer/RenderingQueue.cpp index 60d9f0ef..87793e2e 100644 --- a/src/Engine/src/Renderer/RenderingQueue.cpp +++ b/src/Engine/src/Renderer/RenderingQueue.cpp @@ -13,8 +13,8 @@ #include "Platform/WebGPU/WebGPUGraphicsDevice.h" #include "Renderer.h" #include "SceneRenderer.h" -#include "ext/matrix_transform.hpp" -#include "gtx/quaternion.hpp" +#include +#include namespace BeeEngine::Internal { @@ -50,7 +50,7 @@ namespace BeeEngine::Internal s_Statistics.AllocatedGPUBuffers++; } - void RenderingQueue::SubmitInstance(RenderInstance&& instance, gsl::span instanceData) + void RenderingQueue::SubmitInstance(RenderInstance&& instance, std::span instanceData) { if (!m_SubmittedInstances.contains(instance)) { diff --git a/src/Engine/src/Renderer/RenderingQueue.h b/src/Engine/src/Renderer/RenderingQueue.h index ee476f11..04399aa5 100644 --- a/src/Engine/src/Renderer/RenderingQueue.h +++ b/src/Engine/src/Renderer/RenderingQueue.h @@ -10,7 +10,7 @@ #include "Model.h" #include "RendererStatistics.h" #include "TextRenderingConfiguration.h" -#include +#include namespace BeeEngine::Internal { @@ -68,7 +68,7 @@ namespace BeeEngine::Internal RenderingQueue(); RenderingQueue(size_t sizeInBytes); ~RenderingQueue(); - void SubmitInstance(RenderInstance&& instance, gsl::span instanceData); + void SubmitInstance(RenderInstance&& instance, std::span instanceData); void SubmitLine(const glm::vec3& start, const glm::vec3& end, const Color4& color, diff --git a/src/Engine/src/Renderer/SceneRenderer.cpp b/src/Engine/src/Renderer/SceneRenderer.cpp index 8ffd1b07..08ce3d62 100644 --- a/src/Engine/src/Renderer/SceneRenderer.cpp +++ b/src/Engine/src/Renderer/SceneRenderer.cpp @@ -13,7 +13,7 @@ #include "Scene/Components.h" #include "Scripting/ScriptingEngine.h" #include "UniformBuffer.h" -#include "gtc/type_ptr.hpp" +#include #include #include @@ -397,4 +397,4 @@ namespace BeeEngine } } } -} // namespace BeeEngine \ No newline at end of file +} // namespace BeeEngine diff --git a/src/Engine/src/Renderer/SceneTreeRenderer.cpp b/src/Engine/src/Renderer/SceneTreeRenderer.cpp index 3f5b7f75..ad596c8a 100644 --- a/src/Engine/src/Renderer/SceneTreeRenderer.cpp +++ b/src/Engine/src/Renderer/SceneTreeRenderer.cpp @@ -21,7 +21,7 @@ namespace BeeEngine bool isTransparent, Model& model, const std::vector& bindingSets, - gsl::span instancedData) + std::span instancedData) { auto& vec = isTransparent ? m_Transparent : m_Opaque; std::vector instancedDataVector(instancedData.size()); @@ -168,4 +168,4 @@ namespace BeeEngine } } } -} // namespace BeeEngine \ No newline at end of file +} // namespace BeeEngine diff --git a/src/Engine/src/Renderer/SceneTreeRenderer.h b/src/Engine/src/Renderer/SceneTreeRenderer.h index e6642f86..e9a0fd8b 100644 --- a/src/Engine/src/Renderer/SceneTreeRenderer.h +++ b/src/Engine/src/Renderer/SceneTreeRenderer.h @@ -9,9 +9,9 @@ #include "Renderer/BindingSet.h" #include "Renderer/Model.h" #include "TextRenderingConfiguration.h" -#include "gsl/gsl" -#include +#include #include +#include namespace BeeEngine { @@ -26,7 +26,7 @@ namespace BeeEngine bool isTransparent, Model& model, const std::vector& bindingSets, - gsl::span instancedData); + std::span instancedData); void AddText(const UTF8String& text, Font* font, const glm::mat4& transform, diff --git a/src/Engine/src/Renderer/ShaderModule.cpp b/src/Engine/src/Renderer/ShaderModule.cpp index 3bf6ceac..ced69e91 100644 --- a/src/Engine/src/Renderer/ShaderModule.cpp +++ b/src/Engine/src/Renderer/ShaderModule.cpp @@ -112,7 +112,7 @@ namespace BeeEngine std::vector ShaderModule::LoadSpirVFromCache(const Path& path) { auto result = File::ReadBinaryFile(path); - gsl::span span((uint32_t*)result.data(), result.size() / sizeof(uint32_t)); + std::span span((uint32_t*)result.data(), result.size() / sizeof(uint32_t)); BeeCoreTrace("Loaded SPIRV from cache"); return {span.begin(), span.end()}; } diff --git a/src/Engine/src/Renderer/Texture.cpp b/src/Engine/src/Renderer/Texture.cpp index 295e9ad8..92d555e9 100644 --- a/src/Engine/src/Renderer/Texture.cpp +++ b/src/Engine/src/Renderer/Texture.cpp @@ -13,13 +13,13 @@ namespace BeeEngine { Ref - Texture2D::Create(uint32_t width, uint32_t height, gsl::span data, uint32_t numberOfChannels) + Texture2D::Create(uint32_t width, uint32_t height, std::span data, uint32_t numberOfChannels) { return CreateRef( CreateScope(width, height, data, numberOfChannels)); } Scope - GPUTextureResource::Create(uint32_t width, uint32_t height, gsl::span data, uint32_t numberOfChannels) + GPUTextureResource::Create(uint32_t width, uint32_t height, std::span data, uint32_t numberOfChannels) { BEE_PROFILE_FUNCTION(); switch (Renderer::GetAPI()) diff --git a/src/Engine/src/Renderer/Texture.h b/src/Engine/src/Renderer/Texture.h index e01f87c7..5e89fc4f 100644 --- a/src/Engine/src/Renderer/Texture.h +++ b/src/Engine/src/Renderer/Texture.h @@ -9,7 +9,7 @@ #include "Core/TypeDefines.h" #include "IBindable.h" #include "Renderer/BindingSet.h" -#include "gsl/gsl" +#include namespace BeeEngine { @@ -30,7 +30,7 @@ namespace BeeEngine * @param data The texture data to be uploaded to the GPU. * @param numberOfChannels The number of color channels in the texture (default is 4). */ - virtual void SetData(gsl::span data, uint32_t numberOfChannels = 4) = 0; + virtual void SetData(std::span data, uint32_t numberOfChannels = 4) = 0; /** * @brief Gets the width of the texture. @@ -79,7 +79,7 @@ namespace BeeEngine * @return A scoped pointer to the created GPU texture resource. */ static Scope - Create(uint32_t width, uint32_t height, gsl::span data, uint32_t numberOfChannels = 4); + Create(uint32_t width, uint32_t height, std::span data, uint32_t numberOfChannels = 4); /** * @brief Creates a new GPU texture resource from a file path. @@ -168,7 +168,7 @@ namespace BeeEngine * @return A reference-counted pointer to the created Texture2D asset. */ static Ref - Create(uint32_t width, uint32_t height, gsl::span data, uint32_t numberOfChannels = 4); + Create(uint32_t width, uint32_t height, std::span data, uint32_t numberOfChannels = 4); private: Scope m_TextureResource; ///< The GPU texture resource managed by this asset. diff --git a/src/Engine/src/Renderer/Vertex.h b/src/Engine/src/Renderer/Vertex.h index ff734aeb..74dda990 100644 --- a/src/Engine/src/Renderer/Vertex.h +++ b/src/Engine/src/Renderer/Vertex.h @@ -4,7 +4,7 @@ #pragma once -#include "glm.hpp" +#include namespace BeeEngine { @@ -14,4 +14,4 @@ namespace BeeEngine glm::vec3 Normal{0.0f, 0.0f, 0.0f}; glm::vec2 TexCoord{0.0f, 0.0f}; }; -} // namespace BeeEngine \ No newline at end of file +} // namespace BeeEngine diff --git a/src/Engine/src/Scene/Components.h b/src/Engine/src/Scene/Components.h index 147ef502..c74abfe1 100644 --- a/src/Engine/src/Scene/Components.h +++ b/src/Engine/src/Scene/Components.h @@ -25,9 +25,9 @@ #include "Scripting/GameScript.h" #include "Scripting/MObject.h" #include "Serialization/ISerializer.h" -#include "ext/matrix_transform.hpp" -#include "glm.hpp" -#include "gtx/quaternion.hpp" +#include +#include +#include namespace BeeEngine { diff --git a/src/Engine/src/Scene/Scene.cpp b/src/Engine/src/Scene/Scene.cpp index 6c2c756d..599a0bf7 100644 --- a/src/Engine/src/Scene/Scene.cpp +++ b/src/Engine/src/Scene/Scene.cpp @@ -13,7 +13,7 @@ #include "Renderer/Renderer.h" #include "Scripting/ScriptingEngine.h" #include "box2d/b2_world_callbacks.h" -#include "gtc/type_ptr.hpp" +#include #include #include @@ -357,7 +357,7 @@ namespace BeeEngine } m_2DPhysicsWorld->Step( - gsl::narrow_cast(Time::secondsD(Time::DeltaTime()).count()), velocityIterations, positionIterations); + narrow_cast(Time::secondsD(Time::DeltaTime()).count()), velocityIterations, positionIterations); for (auto e : view) { diff --git a/src/Engine/src/Scene/SceneCamera.cpp b/src/Engine/src/Scene/SceneCamera.cpp index 58ffc9cc..851d0730 100644 --- a/src/Engine/src/Scene/SceneCamera.cpp +++ b/src/Engine/src/Scene/SceneCamera.cpp @@ -3,8 +3,8 @@ // #include "SceneCamera.h" -#include "ext/matrix_clip_space.hpp" -#include +#include "Core/Casts.h" +#include namespace BeeEngine { @@ -31,7 +31,7 @@ namespace BeeEngine void SceneCamera::SetViewportSize(uint32_t width, uint32_t height) { - const float newAspectRatio = gsl::narrow_cast(width) / gsl::narrow_cast(height); + const float newAspectRatio = narrow_cast(width) / narrow_cast(height); if (m_AspectRatio != newAspectRatio) { m_AspectRatio = newAspectRatio; diff --git a/src/Engine/src/Scripting/MUtils.cpp b/src/Engine/src/Scripting/MUtils.cpp index 092c8935..59f7c2b1 100644 --- a/src/Engine/src/Scripting/MUtils.cpp +++ b/src/Engine/src/Scripting/MUtils.cpp @@ -8,9 +8,7 @@ #include "Core/TypeDefines.h" #include "MField.h" #include "MTypes.h" -#include "vec2.hpp" -#include "vec3.hpp" -#include "vec4.hpp" +#include namespace BeeEngine { diff --git a/src/Engine/src/Scripting/ScriptGlue.h b/src/Engine/src/Scripting/ScriptGlue.h index 4d375808..1dd8ca0a 100644 --- a/src/Engine/src/Scripting/ScriptGlue.h +++ b/src/Engine/src/Scripting/ScriptGlue.h @@ -10,7 +10,7 @@ #include "Renderer/FrameBuffer.h" #include "Renderer/UniformBuffer.h" #include "Scene/Components.h" -#include "vec3.hpp" +#include #include namespace BeeEngine diff --git a/src/Engine/src/Windowing/WindowHandler/SDLWindowHandler.cpp b/src/Engine/src/Windowing/WindowHandler/SDLWindowHandler.cpp index 8d0c1d1e..d19f6ef9 100644 --- a/src/Engine/src/Windowing/WindowHandler/SDLWindowHandler.cpp +++ b/src/Engine/src/Windowing/WindowHandler/SDLWindowHandler.cpp @@ -225,6 +225,8 @@ namespace BeeEngine return "SDL_EVENT_LAST"; case SDL_EVENT_ENUM_PADDING: return "SDL_EVENT_ENUM_PADDING"; + default: + return "Unknown SDL Event"; } } } // namespace BeeEngine @@ -304,7 +306,7 @@ namespace BeeEngine::Internal m_Title = properties.Title; m_Window = SDL_CreateWindow( - properties.Title.c_str(), gsl::narrow_cast(m_Width), gsl::narrow_cast(m_Height), windowFlags); + properties.Title.c_str(), narrow_cast(m_Width), narrow_cast(m_Height), windowFlags); if (m_Window == nullptr) { BeeCoreError("Failed to create SDL3 window! {}", SDL_GetError()); @@ -774,7 +776,7 @@ namespace BeeEngine::Internal SetDeltaTime(Time::secondsD(deltatime), Time::secondsD(((double)currentTime) / (double)SDL_GetPerformanceFrequency())); return Time::secondsD(deltatime); - // UpdateDeltaTime(gsl::narrow_cast(SDL_GetPerformanceCounter())); + // UpdateDeltaTime(narrow_cast(SDL_GetPerformanceCounter())); } void SDLWindowHandler::Close() diff --git a/src/Engine/src/Windowing/WindowHandler/WindowHandler.cpp b/src/Engine/src/Windowing/WindowHandler/WindowHandler.cpp index 5d0ab869..78239b32 100644 --- a/src/Engine/src/Windowing/WindowHandler/WindowHandler.cpp +++ b/src/Engine/src/Windowing/WindowHandler/WindowHandler.cpp @@ -15,7 +15,7 @@ namespace BeeEngine { WindowHandler* WindowHandler::s_Instance = nullptr; WindowHandlerAPI WindowHandler::s_API = WindowHandlerAPI::SDL; - gsl::not_null + WindowHandler* WindowHandler::Create(WindowHandlerAPI api, const ApplicationProperties& properties, EventQueue& eventQueue) { BEE_PROFILE_FUNCTION(); diff --git a/src/Engine/src/Windowing/WindowHandler/WindowHandler.h b/src/Engine/src/Windowing/WindowHandler/WindowHandler.h index 27ffc602..4827533f 100644 --- a/src/Engine/src/Windowing/WindowHandler/WindowHandler.h +++ b/src/Engine/src/Windowing/WindowHandler/WindowHandler.h @@ -40,7 +40,7 @@ namespace BeeEngine virtual ~WindowHandler() = default; WindowHandler(const WindowHandler&) = delete; WindowHandler& operator=(const WindowHandler&) = delete; - static gsl::not_null + static WindowHandler* Create(WindowHandlerAPI api, const ApplicationProperties& properties, EventQueue& eventQueue); uint16_t GetWidth() const { return m_Width; } uint16_t GetHeight() const { return m_Height; } @@ -53,7 +53,7 @@ namespace BeeEngine virtual WindowNativeInfo GetNativeInfo() = 0; virtual void SetWidth(uint16_t width) = 0; virtual void SetHeight(uint16_t height) = 0; - static gsl::not_null GetInstance() { return s_Instance; } + static WindowHandler* GetInstance() { return s_Instance; } static WindowHandlerAPI GetAPI() { return s_API; } virtual uint64_t GetWindow() = 0; VSync GetVSync() const { return m_vsync; } diff --git a/src/Engine/vendor/ICU/CMakeLists.txt b/src/Engine/vendor/ICU/CMakeLists.txt deleted file mode 100644 index 8275f3fd..00000000 --- a/src/Engine/vendor/ICU/CMakeLists.txt +++ /dev/null @@ -1,26 +0,0 @@ -cmake_minimum_required(VERSION 3.25) - -set(BUILD_ICU ON CACHE BOOL "Build ICU" FORCE) -set(ICU_BUILD_VERSION "73.2" CACHE STRING "ICU version to build" FORCE) -set(ICU_STATIC ON CACHE BOOL "Build ICU static" FORCE) - -CPMAddPackage( - NAME ICU - GITHUB_REPOSITORY viaduck/icu-cmake #https://github.com/viaduck/icu-cmake - GIT_TAG 4b56d4ae0c7883c9cc7655c8357685ca34807754 #v73.2 set 21.10.23 -) - -function(link_icu_data target) - if(WIN32) - set(ICU_LIB "${CMAKE_BINARY_DIR}/_deps/icu-build/icu_host-build/stubdata/libicudata.lib") - elseif(APPLE OR UNIX) - set(ICU_LIB "${CMAKE_BINARY_DIR}/_deps/icu-build/icu_host-build/stubdata/libicudata.a") - endif() - - #find_library(ICU_DATA NAMES ${ICU_LIB} REQUIRED) - #target_link_libraries(${target} INTERFACE ${ICU_DATA}) -endfunction() - -add_library(ICU INTERFACE) -target_link_libraries(ICU INTERFACE icu) -link_icu_data(ICU) diff --git a/src/Editor/vendor/ImGuizmo/CMakeLists.txt b/src/Engine/vendor/ImGuizmo/CMakeLists.txt similarity index 100% rename from src/Editor/vendor/ImGuizmo/CMakeLists.txt rename to src/Engine/vendor/ImGuizmo/CMakeLists.txt diff --git a/src/Editor/vendor/ImGuizmo/LICENSE b/src/Engine/vendor/ImGuizmo/LICENSE similarity index 100% rename from src/Editor/vendor/ImGuizmo/LICENSE rename to src/Engine/vendor/ImGuizmo/LICENSE diff --git a/src/Engine/vendor/ImGuizmo/imguizmo b/src/Engine/vendor/ImGuizmo/imguizmo new file mode 160000 index 00000000..b10e9175 --- /dev/null +++ b/src/Engine/vendor/ImGuizmo/imguizmo @@ -0,0 +1 @@ +Subproject commit b10e91756d32395f5c1fefd417899b657ed7cb88 diff --git a/src/Engine/vendor/Implementations.cpp b/src/Engine/vendor/Implementations.cpp index d0784800..976cfd81 100644 --- a/src/Engine/vendor/Implementations.cpp +++ b/src/Engine/vendor/Implementations.cpp @@ -6,8 +6,8 @@ #if defined(WINDOWS) #define STBI_WINDOWS_UTF8 #endif -#include "stb_image.h" -#include "stb_image_write.h" +#include +#include #if defined(WINDOWS) STBIDEF stbi_uc* stbi_load(const wchar_t* filename, int* x, int* y, int* comp, int req_comp) { @@ -43,4 +43,4 @@ int stbi_write_png(const wchar_t* filename, int x, int y, int comp, const void* #if defined(BEE_COMPILE_VULKAN) #define VMA_IMPLEMENTATION #include "vk_mem_alloc.h" -#endif \ No newline at end of file +#endif diff --git a/src/Engine/vendor/Incbin/incbin.h b/src/Engine/vendor/Incbin/incbin.h deleted file mode 100644 index 6ad84438..00000000 --- a/src/Engine/vendor/Incbin/incbin.h +++ /dev/null @@ -1,422 +0,0 @@ -/** - * @file incbin.h - * @author Dale Weiler - * @brief Utility for including binary files - * - * Facilities for including binary files into the current translation unit and - * making use from them externally in other translation units. - */ -#ifndef INCBIN_HDR -#define INCBIN_HDR -#ifdef _MSC_VER -#define ASM_START __asm( -#define ASM_END ) -#else -#define ASM_START __asm__ ( -#define ASM_END ) -#endif -#include -#if defined(__AVX512BW__) || defined(__AVX512CD__) || defined(__AVX512DQ__) || defined(__AVX512ER__) || \ - defined(__AVX512PF__) || defined(__AVX512VL__) || defined(__AVX512F__) -#define INCBIN_ALIGNMENT_INDEX 6 -#elif defined(__AVX__) || defined(__AVX2__) -#define INCBIN_ALIGNMENT_INDEX 5 -#elif defined(__SSE__) || defined(__SSE2__) || defined(__SSE3__) || defined(__SSSE3__) || defined(__SSE4_1__) || \ - defined(__SSE4_2__) || defined(__neon__) || defined(__ARM_NEON) || defined(__ALTIVEC__) -#define INCBIN_ALIGNMENT_INDEX 4 -#elif ULONG_MAX != 0xffffffffu -#define INCBIN_ALIGNMENT_INDEX 3 -#else -#define INCBIN_ALIGNMENT_INDEX 2 -#endif - -/* Lookup table of (1 << n) where `n' is `INCBIN_ALIGNMENT_INDEX' */ -#define INCBIN_ALIGN_SHIFT_0 1 -#define INCBIN_ALIGN_SHIFT_1 2 -#define INCBIN_ALIGN_SHIFT_2 4 -#define INCBIN_ALIGN_SHIFT_3 8 -#define INCBIN_ALIGN_SHIFT_4 16 -#define INCBIN_ALIGN_SHIFT_5 32 -#define INCBIN_ALIGN_SHIFT_6 64 - -/* Actual alignment value */ -#define INCBIN_ALIGNMENT INCBIN_CONCATENATE(INCBIN_CONCATENATE(INCBIN_ALIGN_SHIFT, _), INCBIN_ALIGNMENT_INDEX) - -/* Stringize */ -#define INCBIN_STR(X) #X -#define INCBIN_STRINGIZE(X) INCBIN_STR(X) -/* Concatenate */ -#define INCBIN_CAT(X, Y) X##Y -#define INCBIN_CONCATENATE(X, Y) INCBIN_CAT(X, Y) -/* Deferred macro expansion */ -#define INCBIN_EVAL(X) X -#define INCBIN_INVOKE(N, ...) INCBIN_EVAL(N(__VA_ARGS__)) -/* Variable argument count for overloading by arity */ -#define INCBIN_VA_ARG_COUNTER(_1, _2, _3, N, ...) N -#define INCBIN_VA_ARGC(...) INCBIN_VA_ARG_COUNTER(__VA_ARGS__, 3, 2, 1, 0) - -/* Green Hills uses a different directive for including binary data */ -#if defined(__ghs__) -#if (__ghs_asm == 2) -#define INCBIN_MACRO ".file" -/* Or consider the ".myrawdata" entry in the ld file */ -#else -#define INCBIN_MACRO "\tINCBIN" -#endif -#else -#define INCBIN_MACRO ".incbin" -#endif - -#ifndef _MSC_VER -#define INCBIN_ALIGN __attribute__((aligned(INCBIN_ALIGNMENT))) -#else -#define INCBIN_ALIGN __declspec(align(INCBIN_ALIGNMENT)) -#endif - -#if defined(__arm__) || /* GNU C and RealView */ \ - defined(__arm) || /* Diab */ \ - defined(_ARM) /* ImageCraft */ -#define INCBIN_ARM -#endif - -#ifdef __GNUC__ -/* Utilize .balign where supported */ -#define INCBIN_ALIGN_HOST ".balign " INCBIN_STRINGIZE(INCBIN_ALIGNMENT) "\n" -#define INCBIN_ALIGN_BYTE ".balign 1\n" -#elif defined(INCBIN_ARM) -/* - * On arm assemblers, the alignment value is calculated as (1 << n) where `n' is - * the shift count. This is the value passed to `.align' - */ -#define INCBIN_ALIGN_HOST ".align " INCBIN_STRINGIZE(INCBIN_ALIGNMENT_INDEX) "\n" -#define INCBIN_ALIGN_BYTE ".align 0\n" -#else -/* We assume other inline assembler's treat `.align' as `.balign' */ -#define INCBIN_ALIGN_HOST ".align " INCBIN_STRINGIZE(INCBIN_ALIGNMENT) "\n" -#define INCBIN_ALIGN_BYTE ".align 1\n" -#endif - -/* INCBIN_CONST is used by incbin.c generated files */ -#if defined(__cplusplus) -#define INCBIN_EXTERNAL extern "C" -#define INCBIN_CONST extern const -#else -#define INCBIN_EXTERNAL extern -#define INCBIN_CONST const -#endif - -/** - * @brief Optionally override the linker section into which size and data is - * emitted. - * - * @warning If you use this facility, you might have to deal with - * platform-specific linker output section naming on your own. - */ -#if !defined(INCBIN_OUTPUT_SECTION) -#if defined(__APPLE__) -#define INCBIN_OUTPUT_SECTION ".const_data" -#else -#define INCBIN_OUTPUT_SECTION ".rodata" -#endif -#endif - -/** - * @brief Optionally override the linker section into which data is emitted. - * - * @warning If you use this facility, you might have to deal with - * platform-specific linker output section naming on your own. - */ -#if !defined(INCBIN_OUTPUT_DATA_SECTION) -#define INCBIN_OUTPUT_DATA_SECTION INCBIN_OUTPUT_SECTION -#endif - -/** - * @brief Optionally override the linker section into which size is emitted. - * - * @warning If you use this facility, you might have to deal with - * platform-specific linker output section naming on your own. - * - * @note This is useful for Harvard architectures where program memory cannot - * be directly read from the program without special instructions. With this you - * can chose to put the size variable in RAM rather than ROM. - */ -#if !defined(INCBIN_OUTPUT_SIZE_SECTION) -#define INCBIN_OUTPUT_SIZE_SECTION INCBIN_OUTPUT_SECTION -#endif - -#if defined(__APPLE__) -#include "TargetConditionals.h" -#if defined(TARGET_OS_IPHONE) && !defined(INCBIN_SILENCE_BITCODE_WARNING) -#warning \ - "incbin is incompatible with bitcode. Using the library will break upload to App Store if you have bitcode enabled. Add `#define INCBIN_SILENCE_BITCODE_WARNING` before including this header to silence this warning." -#endif -/* The directives are different for Apple branded compilers */ -#define INCBIN_SECTION INCBIN_OUTPUT_SECTION "\n" -#define INCBIN_GLOBAL(NAME) ".globl " INCBIN_MANGLE INCBIN_STRINGIZE(INCBIN_PREFIX) #NAME "\n" -#define INCBIN_INT ".long " -#define INCBIN_MANGLE "_" -#define INCBIN_BYTE ".byte " -#define INCBIN_TYPE(...) -#else -#define INCBIN_SECTION ".section " INCBIN_OUTPUT_SECTION "\n" -#define INCBIN_GLOBAL(NAME) ".global " INCBIN_STRINGIZE(INCBIN_PREFIX) #NAME "\n" -#if defined(__ghs__) -#define INCBIN_INT ".word " -#else -#define INCBIN_INT ".int " -#endif -#if defined(__USER_LABEL_PREFIX__) -#define INCBIN_MANGLE INCBIN_STRINGIZE(__USER_LABEL_PREFIX__) -#else -#define INCBIN_MANGLE "" -#endif -#if defined(INCBIN_ARM) -/* On arm assemblers, `@' is used as a line comment token */ -#define INCBIN_TYPE(NAME) ".type " INCBIN_STRINGIZE(INCBIN_PREFIX) #NAME ", %object\n" -#elif defined(__MINGW32__) || defined(__MINGW64__) -/* Mingw doesn't support this directive either */ -#define INCBIN_TYPE(NAME) -#else -/* It's safe to use `@' on other architectures */ -#define INCBIN_TYPE(NAME) ".type " INCBIN_STRINGIZE(INCBIN_PREFIX) #NAME ", @object\n" -#endif -#define INCBIN_BYTE ".byte " -#endif - -/* List of style types used for symbol names */ -#define INCBIN_STYLE_CAMEL 0 -#define INCBIN_STYLE_SNAKE 1 - -/** - * @brief Specify the prefix to use for symbol names. - * - * @note By default this is "g". - * - * @code - * #define INCBIN_PREFIX incbin - * #include "incbin.h" - * INCBIN(Foo, "foo.txt"); - * - * // Now you have the following symbols instead: - * // const unsigned char incbinFoo[]; - * // const unsigned char *const incbinFoo; - * // const unsigned int incbinFoo; - * @endcode - */ -#if !defined(INCBIN_PREFIX) -#define INCBIN_PREFIX g -#endif - -/** - * @brief Specify the style used for symbol names. - * - * Possible options are - * - INCBIN_STYLE_CAMEL "CamelCase" - * - INCBIN_STYLE_SNAKE "snake_case" - * - * @note By default this is INCBIN_STYLE_CAMEL - * - * @code - * #define INCBIN_STYLE INCBIN_STYLE_SNAKE - * #include "incbin.h" - * INCBIN(foo, "foo.txt"); - * - * // Now you have the following symbols: - * // const unsigned char foo_data[]; - * // const unsigned char *const foo_end; - * // const unsigned int foo_size; - * @endcode - */ -#if !defined(INCBIN_STYLE) -#define INCBIN_STYLE INCBIN_STYLE_CAMEL -#endif - -/* Style lookup tables */ -#define INCBIN_STYLE_0_DATA Data -#define INCBIN_STYLE_0_END End -#define INCBIN_STYLE_0_SIZE Size -#define INCBIN_STYLE_1_DATA _data -#define INCBIN_STYLE_1_END _end -#define INCBIN_STYLE_1_SIZE _size - -/* Style lookup: returning identifier */ -#define INCBIN_STYLE_IDENT(TYPE) \ - INCBIN_CONCATENATE(INCBIN_STYLE_, INCBIN_CONCATENATE(INCBIN_EVAL(INCBIN_STYLE), INCBIN_CONCATENATE(_, TYPE))) - -/* Style lookup: returning string literal */ -#define INCBIN_STYLE_STRING(TYPE) INCBIN_STRINGIZE(INCBIN_STYLE_IDENT(TYPE)) - -/* Generate the global labels by indirectly invoking the macro with our style - * type and concatenating the name against them. */ -#define INCBIN_GLOBAL_LABELS(NAME, TYPE) \ - INCBIN_INVOKE(INCBIN_GLOBAL, INCBIN_CONCATENATE(NAME, INCBIN_INVOKE(INCBIN_STYLE_IDENT, TYPE))) \ - INCBIN_INVOKE(INCBIN_TYPE, INCBIN_CONCATENATE(NAME, INCBIN_INVOKE(INCBIN_STYLE_IDENT, TYPE))) - -/** - * @brief Externally reference binary data included in another translation unit. - * - * Produces three external symbols that reference the binary data included in - * another translation unit. - * - * The symbol names are a concatenation of `INCBIN_PREFIX' before *NAME*; with - * "Data", as well as "End" and "Size" after. An example is provided below. - * - * @param TYPE Optional array type. Omitting this picks a default of `unsigned char`. - * @param NAME The name given for the binary data - * - * @code - * INCBIN_EXTERN(Foo); - * - * // Now you have the following symbols: - * // extern const unsigned char Foo[]; - * // extern const unsigned char *const Foo; - * // extern const unsigned int Foo; - * @endcode - * - * You may specify a custom optional data type as well as the first argument. - * @code - * INCBIN_EXTERN(custom_type, Foo); - * - * // Now you have the following symbols: - * // extern const custom_type Foo[]; - * // extern const custom_type *const Foo; - * // extern const unsigned int Foo; - * @endcode - */ -#define INCBIN_EXTERN(...) INCBIN_CONCATENATE(INCBIN_EXTERN_, INCBIN_VA_ARGC(__VA_ARGS__))(__VA_ARGS__) -#define INCBIN_EXTERN_1(NAME, ...) INCBIN_EXTERN_2(unsigned char, NAME) -#define INCBIN_EXTERN_2(TYPE, NAME) \ - INCBIN_EXTERNAL const INCBIN_ALIGN TYPE INCBIN_CONCATENATE(INCBIN_CONCATENATE(INCBIN_PREFIX, NAME), \ - INCBIN_STYLE_IDENT(DATA))[]; \ - INCBIN_EXTERNAL const INCBIN_ALIGN TYPE* const INCBIN_CONCATENATE(INCBIN_CONCATENATE(INCBIN_PREFIX, NAME), \ - INCBIN_STYLE_IDENT(END)); \ - INCBIN_EXTERNAL const unsigned int INCBIN_CONCATENATE(INCBIN_CONCATENATE(INCBIN_PREFIX, NAME), \ - INCBIN_STYLE_IDENT(SIZE)) - -/** - * @brief Externally reference textual data included in another translation unit. - * - * Produces three external symbols that reference the textual data included in - * another translation unit. - * - * The symbol names are a concatenation of `INCBIN_PREFIX' before *NAME*; with - * "Data", as well as "End" and "Size" after. An example is provided below. - * - * @param NAME The name given for the textual data - * - * @code - * INCBIN_EXTERN(Foo); - * - * // Now you have the following symbols: - * // extern const char Foo[]; - * // extern const char *const Foo; - * // extern const unsigned int Foo; - * @endcode - */ -#define INCTXT_EXTERN(NAME) INCBIN_EXTERN_2(char, NAME) - -/** - * @brief Include a binary file into the current translation unit. - * - * Includes a binary file into the current translation unit, producing three symbols - * for objects that encode the data and size respectively. - * - * The symbol names are a concatenation of `INCBIN_PREFIX' before *NAME*; with - * "Data", as well as "End" and "Size" after. An example is provided below. - * - * @param TYPE Optional array type. Omitting this picks a default of `unsigned char`. - * @param NAME The name to associate with this binary data (as an identifier.) - * @param FILENAME The file to include (as a string literal.) - * - * @code - * INCBIN(Icon, "icon.png"); - * - * // Now you have the following symbols: - * // const unsigned char Icon[]; - * // const unsigned char *const Icon; - * // const unsigned int Icon; - * @endcode - * - * You may specify a custom optional data type as well as the first argument. - * These macros are specialized by arity. - * @code - * INCBIN(custom_type, Icon, "icon.png"); - * - * // Now you have the following symbols: - * // const custom_type Icon[]; - * // const custom_type *const Icon; - * // const unsigned int Icon; - * @endcode - * - * @warning This must be used in global scope - * @warning The identifiers may be different if INCBIN_STYLE is not default - * - * To externally reference the data included by this in another translation unit - * please @see INCBIN_EXTERN. - */ -#ifdef z_MSC_VER -#define INCBIN(NAME, FILENAME) INCBIN_EXTERN(NAME) -#else -#define INCBIN(...) INCBIN_CONCATENATE(INCBIN_, INCBIN_VA_ARGC(__VA_ARGS__))(__VA_ARGS__) -#if defined(__GNUC__) -#define INCBIN_1(...) _Pragma("GCC error \"Single argument INCBIN not allowed\"") -#elif defined(__clang__) -#define INCBIN_1(...) _Pragma("clang error \"Single argument INCBIN not allowed\"") -#else -#define INCBIN_1(...) /* Cannot do anything here */ -#endif -#define INCBIN_2(NAME, FILENAME) INCBIN_3(unsigned char, NAME, FILENAME) -#define INCBIN_3(TYPE, NAME, FILENAME) INCBIN_COMMON(TYPE, NAME, FILENAME, /* No terminator for binary data */) -#define INCBIN_COMMON(TYPE, NAME, FILENAME, TERMINATOR) \ - ASM_START INCBIN_SECTION INCBIN_GLOBAL_LABELS(NAME, DATA) \ - INCBIN_ALIGN_HOST \ - INCBIN_MANGLE INCBIN_STRINGIZE(INCBIN_PREFIX) #NAME INCBIN_STYLE_STRING( \ - DATA) ":\n" INCBIN_MACRO " \"" FILENAME "\"\n" TERMINATOR INCBIN_GLOBAL_LABELS(NAME, END) \ - INCBIN_ALIGN_BYTE \ - INCBIN_MANGLE INCBIN_STRINGIZE(INCBIN_PREFIX) #NAME INCBIN_STYLE_STRING( \ - END) ":\n" INCBIN_BYTE "1\n" INCBIN_GLOBAL_LABELS(NAME, SIZE) \ - INCBIN_ALIGN_HOST INCBIN_MANGLE INCBIN_STRINGIZE(INCBIN_PREFIX) #NAME INCBIN_STYLE_STRING( \ - SIZE) ":\n" INCBIN_INT INCBIN_MANGLE \ - INCBIN_STRINGIZE(INCBIN_PREFIX) #NAME INCBIN_STYLE_STRING(END) " - " INCBIN_MANGLE INCBIN_STRINGIZE( \ - INCBIN_PREFIX) #NAME INCBIN_STYLE_STRING(DATA) "\n" INCBIN_ALIGN_HOST ".text\n" ASM_END; \ - INCBIN_EXTERN(TYPE, NAME) -#endif - -/** - * @brief Include a textual file into the current translation unit. - * - * This behaves the same as INCBIN except it produces char compatible arrays - * and implicitly adds a null-terminator byte, thus the size of data included - * by this is one byte larger than that of INCBIN. - * - * Includes a textual file into the current translation unit, producing three - * symbols for objects that encode the data and size respectively. - * - * The symbol names are a concatenation of `INCBIN_PREFIX' before *NAME*; with - * "Data", as well as "End" and "Size" after. An example is provided below. - * - * @param NAME The name to associate with this binary data (as an identifier.) - * @param FILENAME The file to include (as a string literal.) - * - * @code - * INCTXT(Readme, "readme.txt"); - * - * // Now you have the following symbols: - * // const char Readme[]; - * // const char *const Readme; - * // const unsigned int Readme; - * @endcode - * - * @warning This must be used in global scope - * @warning The identifiers may be different if INCBIN_STYLE is not default - * - * To externally reference the data included by this in another translation unit - * please @see INCBIN_EXTERN. - */ -#if defined(_MSC_VER) -#define INCTXT(NAME, FILENAME) INCBIN_EXTERN(NAME) -#else -#define INCTXT(NAME, FILENAME) INCBIN_COMMON(char, NAME, FILENAME, INCBIN_BYTE "0\n") -#endif - -#endif \ No newline at end of file diff --git a/src/Engine/vendor/debugbreak b/src/Engine/vendor/debugbreak deleted file mode 160000 index 5dcbe41d..00000000 --- a/src/Engine/vendor/debugbreak +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 5dcbe41d2bd4712c8014aa7e843723ad7b40fd74 diff --git a/src/Engine/vendor/gsl b/src/Engine/vendor/gsl deleted file mode 160000 index 4300304e..00000000 --- a/src/Engine/vendor/gsl +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 4300304ef24c247b3db0255763f46b9f95c3a83d diff --git a/src/Engine/vendor/tinyfiledialogs/tinyfiledialogs.c b/src/Engine/vendor/tinyfiledialogs/tinyfiledialogs.c deleted file mode 100644 index da1983a6..00000000 --- a/src/Engine/vendor/tinyfiledialogs/tinyfiledialogs.c +++ /dev/null @@ -1,7963 +0,0 @@ -/* SPDX-License-Identifier: ZLIB - -this file can be renamed with extension ".cpp" and compiled as C++. -The code is 100% compatible C C++ -(just comment out << extern "C" >> in the header file) - -********* TINY FILE DIALOGS OFFICIAL WEBSITE IS ON SOURCEFORGE ********* - _________ - / \ tinyfiledialogs.c v3.16 [Nov 23, 2023] zlib licence - |tiny file| Unique code file created [November 9, 2014] - | dialogs | Copyright (c) 2014 - 2023 Guillaume Vareille http://ysengrin.com - \____ ___/ http://tinyfiledialogs.sourceforge.net - \| git clone http://git.code.sf.net/p/tinyfiledialogs/code tinyfd - ____________________________________________ - | | - | email: tinyfiledialogs at ysengrin.com | - |____________________________________________| - _________________________________________________________________________________ - | | - | the windows only wchar_t UTF-16 prototypes are at the bottom of the header file | - |_________________________________________________________________________________| - _________________________________________________________ - | | - | on windows: - since v3.6 char is UTF-8 by default | - | - if you want MBCS set tinyfd_winUtf8 to 0 | - | - functions like fopen expect MBCS | - |_________________________________________________________| - -If you like tinyfiledialogs, please upvote my stackoverflow answer -https://stackoverflow.com/a/47651444 - -- License - -This software is provided 'as-is', without any express or implied -warranty. In no event will the authors be held liable for any damages -arising from the use of this software. -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it -freely, subject to the following restrictions: -1. The origin of this software must not be misrepresented; you must not -claim that you wrote the original software. If you use this software -in a product, an acknowledgment in the product documentation would be -appreciated but is not required. -2. Altered source versions must be plainly marked as such, and must not be -misrepresented as being the original software. -3. This notice may not be removed or altered from any source distribution. - - __________________________________________ - | ______________________________________ | - | | | | - | | DO NOT USE USER INPUT IN THE DIALOGS | | - | |______________________________________| | - |__________________________________________| -*/ - - -#ifndef __sun -#ifndef _POSIX_C_SOURCE -#define _POSIX_C_SOURCE 2 /* to accept POSIX 2 in old ANSI C standards */ -#endif -#endif - -#if !defined(_WIN32) && ( defined(__GNUC__) || defined(__clang__) ) -#if !defined(_GNU_SOURCE) - #define _GNU_SOURCE /* used only to resolve symbolic links. Can be commented out */ -#endif -#endif - -#include -#include -#include -#include -#include - -#ifdef _WIN32 - #ifdef __BORLANDC__ - #define _getch getch - #endif - #ifndef _WIN32_WINNT - #define _WIN32_WINNT 0x0500 - #endif - #include - #include - #include - #include - #include - #define TINYFD_NOCCSUNICODE - #define SLASH "\\" -#else - #include - #include - #include /* on old systems try instead */ - #include - #include - #include /* on old systems try instead */ - #define SLASH "/" -#endif /* _WIN32 */ - -#include "tinyfiledialogs.h" - -#define MAX_PATH_OR_CMD 1024 /* _MAX_PATH or MAX_PATH */ - -#ifndef MAX_MULTIPLE_FILES -#define MAX_MULTIPLE_FILES 1024 -#endif -#define LOW_MULTIPLE_FILES 32 - -char tinyfd_version[8] = "3.16"; - -/******************************************************************************************************/ -/**************************************** UTF-8 on Windows ********************************************/ -/******************************************************************************************************/ -#ifdef _WIN32 -/* if you want to use UTF-8 ( instead of the UTF-16/wchar_t functions at the end of tinyfiledialogs.h ) -Make sure your code is really prepared for UTF-8 (on windows, functions like fopen() expect MBCS and not UTF-8) */ -int tinyfd_winUtf8 = 1; /* on windows char strings can be 1:UTF-8(default) or 0:MBCS */ -/* for MBCS change this to 0, here or in your code */ -#endif -/******************************************************************************************************/ -/******************************************************************************************************/ -/******************************************************************************************************/ - -int tinyfd_verbose = 0 ; /* on unix: prints the command line calls */ -int tinyfd_silent = 1 ; /* 1 (default) or 0 : on unix, hide errors and warnings from called dialogs */ - -/* Curses dialogs are difficult to use, on windows they are only ascii and uses the unix backslah */ -int tinyfd_allowCursesDialogs = 0 ; /* 0 (default) or 1 */ -int tinyfd_forceConsole = 0 ; /* 0 (default) or 1 */ -/* for unix & windows: 0 (graphic mode) or 1 (console mode). -0: try to use a graphic solution, if it fails then it uses console mode. -1: forces all dialogs into console mode even when the X server is present. - it can use the package dialog or dialog.exe. - on windows it only make sense for console applications */ - -int tinyfd_assumeGraphicDisplay = 0; /* 0 (default) or 1 */ -/* some systems don't set the environment variable DISPLAY even when a graphic display is present. -set this to 1 to tell tinyfiledialogs to assume the existence of a graphic display */ - - -char tinyfd_response[1024]; -/* if you pass "tinyfd_query" as aTitle, -the functions will not display the dialogs -but and return 0 for console mode, 1 for graphic mode. -tinyfd_response is then filled with the retain solution. -possible values for tinyfd_response are (all lowercase) -for graphic mode: - windows_wchar windows applescript kdialog zenity zenity3 yad matedialog - shellementary qarma python2-tkinter python3-tkinter python-dbus - perl-dbus gxmessage gmessage xmessage xdialog gdialog dunst -for console mode: - dialog whiptail basicinput no_solution */ - -static int gWarningDisplayed = 0 ; -static char gTitle[]="missing software! (we will try basic console input)"; - -#ifdef _WIN32 -char tinyfd_needs[] = "\ - ___________\n\ -/ \\ \n\ -| tiny file |\n\ -| dialogs |\n\ -\\_____ ____/\n\ - \\|\ -\ntiny file dialogs on Windows needs:\ -\n a graphic display\ -\nor dialog.exe (curses console mode ** Disabled by default **)\ -\nor a console for basic input"; -#else -char tinyfd_needs[] = "\ - ___________\n\ -/ \\ \n\ -| tiny file |\n\ -| dialogs |\n\ -\\_____ ____/\n\ - \\|\ -\ntiny file dialogs on UNIX needs:\ -\n applescript or kdialog or yad or Xdialog\ -\nor zenity (or matedialog or shellementary or qarma)\ -\nor python (2 or 3) + tkinter + python-dbus (optional)\ -\nor dialog (opens console if needed) ** Disabled by default **\ -\nor xterm + bash (opens console for basic input)\ -\nor existing console for basic input."; - -#endif - -#ifdef _MSC_VER -#pragma warning(disable:4996) /* allows usage of strncpy, strcpy, strcat, sprintf, fopen */ -#pragma warning(disable:4100) /* allows usage of strncpy, strcpy, strcat, sprintf, fopen */ -#pragma warning(disable:4706) /* allows usage of strncpy, strcpy, strcat, sprintf, fopen */ -#endif - -static int getenvDISPLAY(void) -{ - return tinyfd_assumeGraphicDisplay || getenv("DISPLAY"); -} - - -static char * getCurDir(void) -{ - static char lCurDir[MAX_PATH_OR_CMD]; - return getcwd(lCurDir, sizeof(lCurDir)); -} - - -static char * getPathWithoutFinalSlash( - char * aoDestination, /* make sure it is allocated, use _MAX_PATH */ - char const * aSource) /* aoDestination and aSource can be the same */ -{ - char const * lTmp ; - if ( aSource ) - { - lTmp = strrchr(aSource, '/'); - if (!lTmp) - { - lTmp = strrchr(aSource, '\\'); - } - if (lTmp) - { - strncpy(aoDestination, aSource, lTmp - aSource ); - aoDestination[lTmp - aSource] = '\0'; - } - else - { - * aoDestination = '\0'; - } - } - else - { - * aoDestination = '\0'; - } - return aoDestination; -} - - -static char * getLastName( - char * aoDestination, /* make sure it is allocated */ - char const * aSource) -{ - /* copy the last name after '/' or '\' */ - char const * lTmp ; - if ( aSource ) - { - lTmp = strrchr(aSource, '/'); - if (!lTmp) - { - lTmp = strrchr(aSource, '\\'); - } - if (lTmp) - { - strcpy(aoDestination, lTmp + 1); - } - else - { - strcpy(aoDestination, aSource); - } - } - else - { - * aoDestination = '\0'; - } - return aoDestination; -} - - -static void ensureFinalSlash( char * aioString ) -{ - if ( aioString && strlen( aioString ) ) - { - char * lastcar = aioString + strlen( aioString ) - 1 ; - if ( strncmp( lastcar , SLASH , 1 ) ) - { - strcat( lastcar , SLASH ) ; - } - } -} - - -static void Hex2RGB( char const aHexRGB[8] , unsigned char aoResultRGB[3] ) -{ - char lColorChannel[8] ; - if ( aoResultRGB ) - { - if ( aHexRGB ) - { - strcpy(lColorChannel, aHexRGB ) ; - aoResultRGB[2] = (unsigned char)strtoul(lColorChannel+5,NULL,16); - lColorChannel[5] = '\0'; - aoResultRGB[1] = (unsigned char)strtoul(lColorChannel+3,NULL,16); - lColorChannel[3] = '\0'; - aoResultRGB[0] = (unsigned char)strtoul(lColorChannel+1,NULL,16); -/* printf("%d %d %d\n", aoResultRGB[0], aoResultRGB[1], aoResultRGB[2]); */ - } - else - { - aoResultRGB[0]=0; - aoResultRGB[1]=0; - aoResultRGB[2]=0; - } - } -} - -static void RGB2Hex( unsigned char const aRGB[3], char aoResultHexRGB[8] ) -{ - if ( aoResultHexRGB ) - { - if ( aRGB ) - { -#if (defined(__cplusplus ) && __cplusplus >= 201103L) || (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__clang__) - sprintf(aoResultHexRGB, "#%02hhx%02hhx%02hhx", aRGB[0], aRGB[1], aRGB[2]); -#else - sprintf(aoResultHexRGB, "#%02hx%02hx%02hx", aRGB[0], aRGB[1], aRGB[2]); -#endif - /*printf("aoResultHexRGB %s\n", aoResultHexRGB);*/ - } - else - { - aoResultHexRGB[0]=0; - aoResultHexRGB[1]=0; - aoResultHexRGB[2]=0; - } - } -} - - -void tfd_replaceSubStr( char const * aSource, char const * aOldSubStr, - char const * aNewSubStr, char * aoDestination ) -{ - char const * pOccurence ; - char const * p ; - char const * lNewSubStr = "" ; - size_t lOldSubLen = strlen( aOldSubStr ) ; - - if ( ! aSource ) - { - * aoDestination = '\0' ; - return ; - } - if ( ! aOldSubStr ) - { - strcpy( aoDestination , aSource ) ; - return ; - } - if ( aNewSubStr ) - { - lNewSubStr = aNewSubStr ; - } - p = aSource ; - * aoDestination = '\0' ; - while ( ( pOccurence = strstr( p , aOldSubStr ) ) != NULL ) - { - strncat( aoDestination , p , pOccurence - p ) ; - strcat( aoDestination , lNewSubStr ) ; - p = pOccurence + lOldSubLen ; - } - strcat( aoDestination , p ) ; -} - - -static int filenameValid( char const * aFileNameWithoutPath ) -{ - if ( ! aFileNameWithoutPath - || ! strlen(aFileNameWithoutPath) - || strpbrk(aFileNameWithoutPath , "\\/:*?\"<>|") ) - { - return 0 ; - } - return 1 ; -} - -#ifndef _WIN32 - -static int fileExists( char const * aFilePathAndName ) -{ - FILE * lIn ; - if ( ! aFilePathAndName || ! strlen(aFilePathAndName) ) - { - return 0 ; - } - lIn = fopen( aFilePathAndName , "r" ) ; - if ( ! lIn ) - { - return 0 ; - } - fclose( lIn ) ; - return 1 ; -} - -#endif - - -static void wipefile(char const * aFilename) -{ - int i; - struct stat st; - FILE * lIn; - - if (stat(aFilename, &st) == 0) - { - if ((lIn = fopen(aFilename, "w"))) - { - for (i = 0; i < st.st_size; i++) - { - fputc('A', lIn); - } - fclose(lIn); - } - } -} - - -int tfd_quoteDetected(char const * aString) -{ - char const * p; - - if (!aString) return 0; - - p = aString; - if ( strchr(p, '\'')) - { - return 1; - } - - if ( strchr(p, '\"')) - { - return 1; - } - - if ( strchr(p, '`')) - { - return 1; - } - - p = aString; - while ((p = strchr(p, '$'))) - { - p ++ ; - if ( ( * p == '(' ) || ( * p == '_' ) || isalpha( * p) ) return 1 ; - } - - return 0; -} - - -char const * tinyfd_getGlobalChar(char const * aCharVariableName) /* to be called from C# (you don't need this in C or C++) */ -{ - if (!aCharVariableName || !strlen(aCharVariableName)) return NULL; - else if (!strcmp(aCharVariableName, "tinyfd_version")) return tinyfd_version; - else if (!strcmp(aCharVariableName, "tinyfd_needs")) return tinyfd_needs; - else if (!strcmp(aCharVariableName, "tinyfd_response")) return tinyfd_response; - else return NULL ; -} - - -int tinyfd_getGlobalInt(char const * aIntVariableName) /* to be called from C# (you don't need this in C or C++) */ -{ - if ( !aIntVariableName || !strlen(aIntVariableName) ) return -1 ; - else if ( !strcmp(aIntVariableName, "tinyfd_verbose") ) return tinyfd_verbose ; - else if ( !strcmp(aIntVariableName, "tinyfd_silent") ) return tinyfd_silent ; - else if ( !strcmp(aIntVariableName, "tinyfd_allowCursesDialogs") ) return tinyfd_allowCursesDialogs ; - else if ( !strcmp(aIntVariableName, "tinyfd_forceConsole") ) return tinyfd_forceConsole ; - else if ( !strcmp(aIntVariableName, "tinyfd_assumeGraphicDisplay") ) return tinyfd_assumeGraphicDisplay ; -#ifdef _WIN32 - else if ( !strcmp(aIntVariableName, "tinyfd_winUtf8") ) return tinyfd_winUtf8 ; -#endif - else return -1; -} - - -int tinyfd_setGlobalInt(char const * aIntVariableName, int aValue) /* to be called from C# (you don't need this in C or C++) */ -{ - if (!aIntVariableName || !strlen(aIntVariableName)) return -1 ; - else if (!strcmp(aIntVariableName, "tinyfd_verbose")) { tinyfd_verbose = aValue; return tinyfd_verbose; } - else if (!strcmp(aIntVariableName, "tinyfd_silent")) { tinyfd_silent = aValue; return tinyfd_silent; } - else if (!strcmp(aIntVariableName, "tinyfd_allowCursesDialogs")) { tinyfd_allowCursesDialogs = aValue; return tinyfd_allowCursesDialogs; } - else if (!strcmp(aIntVariableName, "tinyfd_forceConsole")) { tinyfd_forceConsole = aValue; return tinyfd_forceConsole; } - else if (!strcmp(aIntVariableName, "tinyfd_assumeGraphicDisplay")) { tinyfd_assumeGraphicDisplay = aValue; return tinyfd_assumeGraphicDisplay; } -#ifdef _WIN32 - else if (!strcmp(aIntVariableName, "tinyfd_winUtf8")) { tinyfd_winUtf8 = aValue; return tinyfd_winUtf8; } -#endif - else return -1; -} - - -#ifdef _WIN32 -static int powershellPresent(void) -{ /*only on vista and above (or installed on xp)*/ - static int lPowershellPresent = -1; - char lBuff[MAX_PATH_OR_CMD]; - FILE* lIn; - char const* lString = "powershell.exe"; - - if (lPowershellPresent < 0) - { - if (!(lIn = _popen("where powershell.exe", "r"))) - { - lPowershellPresent = 0; - return 0; - } - while (fgets(lBuff, sizeof(lBuff), lIn) != NULL) - { - } - _pclose(lIn); - if (lBuff[strlen(lBuff) - 1] == '\n') - { - lBuff[strlen(lBuff) - 1] = '\0'; - } - if (strcmp(lBuff + strlen(lBuff) - strlen(lString), lString)) - { - lPowershellPresent = 0; - } - else - { - lPowershellPresent = 1; - } - } - return lPowershellPresent; -} - -static int windowsVersion(void) -{ -#if !defined(__MINGW32__) || defined(__MINGW64_VERSION_MAJOR) - typedef LONG NTSTATUS ; - typedef NTSTATUS(WINAPI* RtlGetVersionPtr)(PRTL_OSVERSIONINFOW); - HMODULE hMod; - RtlGetVersionPtr lFxPtr; - RTL_OSVERSIONINFOW lRovi = { 0 }; - - hMod = GetModuleHandleW(L"ntdll.dll"); - if (hMod) { - lFxPtr = (RtlGetVersionPtr)GetProcAddress(hMod, "RtlGetVersion"); - if (lFxPtr) - { - lRovi.dwOSVersionInfoSize = sizeof(lRovi); - if (!lFxPtr(&lRovi)) - { - return lRovi.dwMajorVersion; - } - } - } -#endif - if (powershellPresent()) return 6; /*minimum is vista or installed on xp*/ - return 0; -} - - -static void replaceChr(char * aString, char aOldChr, char aNewChr) -{ - char * p; - - if (!aString) return; - if (aOldChr == aNewChr) return; - - p = aString; - while ((p = strchr(p, aOldChr))) - { - *p = aNewChr; - p++; - } - return; -} - - -#if !defined(WC_ERR_INVALID_CHARS) -/* undefined prior to Vista, so not yet in MINGW header file */ -#define WC_ERR_INVALID_CHARS 0x00000000 /* 0x00000080 for MINGW maybe ? */ -#endif - -static int sizeUtf16From8(char const * aUtf8string) -{ - return MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, - aUtf8string, -1, NULL, 0); -} - - -static int sizeUtf16FromMbcs(char const * aMbcsString) -{ - return MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS, - aMbcsString, -1, NULL, 0); -} - - -static int sizeUtf8(wchar_t const * aUtf16string) -{ - return WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, - aUtf16string, -1, NULL, 0, NULL, NULL); -} - - -static int sizeMbcs(wchar_t const * aMbcsString) -{ - int lRes = WideCharToMultiByte(CP_ACP, 0, - aMbcsString, -1, NULL, 0, NULL, NULL); - /* DWORD licic = GetLastError(); */ - return lRes; -} - - -wchar_t* tinyfd_mbcsTo16(char const* aMbcsString) -{ - static wchar_t* lMbcsString = NULL; - int lSize; - - free(lMbcsString); - if (!aMbcsString) { lMbcsString = NULL; return NULL; } - lSize = sizeUtf16FromMbcs(aMbcsString); - if (lSize) - { - lMbcsString = (wchar_t*)malloc(lSize * sizeof(wchar_t)); - lSize = MultiByteToWideChar(CP_ACP, 0, aMbcsString, -1, lMbcsString, lSize); - } - else wcscpy(lMbcsString, L""); - return lMbcsString; -} - - -wchar_t * tinyfd_utf8to16(char const * aUtf8string) -{ - static wchar_t * lUtf16string = NULL; - int lSize; - - free(lUtf16string); - if (!aUtf8string) {lUtf16string = NULL; return NULL;} - lSize = sizeUtf16From8(aUtf8string); - if (lSize) - { - lUtf16string = (wchar_t*)malloc(lSize * sizeof(wchar_t)); - lSize = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, - aUtf8string, -1, lUtf16string, lSize); - return lUtf16string; - } - else - { - /* let's try mbcs anyway */ - lUtf16string = NULL; - return tinyfd_mbcsTo16(aUtf8string); - } -} - - -char * tinyfd_utf16toMbcs(wchar_t const * aUtf16string) -{ - static char * lMbcsString = NULL; - int lSize; - - free(lMbcsString); - if (!aUtf16string) { lMbcsString = NULL; return NULL; } - lSize = sizeMbcs(aUtf16string); - if (lSize) - { - lMbcsString = (char*)malloc(lSize); - lSize = WideCharToMultiByte(CP_ACP, 0, aUtf16string, -1, lMbcsString, lSize, NULL, NULL); - } - else strcpy(lMbcsString, ""); - return lMbcsString; -} - - -char * tinyfd_utf8toMbcs(char const * aUtf8string) -{ - wchar_t const * lUtf16string; - lUtf16string = tinyfd_utf8to16(aUtf8string); - return tinyfd_utf16toMbcs(lUtf16string); -} - - -char * tinyfd_utf16to8(wchar_t const * aUtf16string) -{ - static char * lUtf8string = NULL; - int lSize; - - free(lUtf8string); - if (!aUtf16string) { lUtf8string = NULL; return NULL; } - lSize = sizeUtf8(aUtf16string); - if (lSize) - { - lUtf8string = (char*)malloc(lSize); - lSize = WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, aUtf16string, -1, lUtf8string, lSize, NULL, NULL); - } - else strcpy(lUtf8string, ""); - return lUtf8string; -} - - -char * tinyfd_mbcsTo8(char const * aMbcsString) -{ - wchar_t const * lUtf16string; - lUtf16string = tinyfd_mbcsTo16(aMbcsString); - return tinyfd_utf16to8(lUtf16string); -} - - -void tinyfd_beep(void) -{ - if (windowsVersion() > 5) Beep(440, 300); - else MessageBeep(MB_OK); -} - - -static void wipefileW(wchar_t const * aFilename) -{ - int i; - FILE * lIn; -#if defined(__MINGW32_MAJOR_VERSION) && !defined(__MINGW64__) && (__MINGW32_MAJOR_VERSION <= 3) - struct _stat st; - if (_wstat(aFilename, &st) == 0) -#else - struct __stat64 st; - if (_wstat64(aFilename, &st) == 0) -#endif - { - if ((lIn = _wfopen(aFilename, L"w"))) - { - for (i = 0; i < st.st_size; i++) - { - fputc('A', lIn); - } - fclose(lIn); - } - } -} - - -static wchar_t * getPathWithoutFinalSlashW( - wchar_t * aoDestination, /* make sure it is allocated, use _MAX_PATH */ - wchar_t const * aSource) /* aoDestination and aSource can be the same */ -{ - wchar_t const * lTmp; - if (aSource) - { - lTmp = wcsrchr(aSource, L'/'); - if (!lTmp) - { - lTmp = wcsrchr(aSource, L'\\'); - } - if (lTmp) - { - wcsncpy(aoDestination, aSource, lTmp - aSource); - aoDestination[lTmp - aSource] = L'\0'; - } - else - { - *aoDestination = L'\0'; - } - } - else - { - *aoDestination = L'\0'; - } - return aoDestination; -} - - -static wchar_t * getLastNameW( - wchar_t * aoDestination, /* make sure it is allocated */ - wchar_t const * aSource) -{ - /* copy the last name after '/' or '\' */ - wchar_t const * lTmp; - if (aSource) - { - lTmp = wcsrchr(aSource, L'/'); - if (!lTmp) - { - lTmp = wcsrchr(aSource, L'\\'); - } - if (lTmp) - { - wcscpy(aoDestination, lTmp + 1); - } - else - { - wcscpy(aoDestination, aSource); - } - } - else - { - *aoDestination = L'\0'; - } - return aoDestination; -} - - -static void Hex2RGBW(wchar_t const aHexRGB[8], unsigned char aoResultRGB[3]) -{ - wchar_t lColorChannel[8]; - if (aoResultRGB) - { - if (aHexRGB) - { - wcscpy(lColorChannel, aHexRGB); - aoResultRGB[2] = (unsigned char)wcstoul(lColorChannel + 5, NULL, 16); - lColorChannel[5] = '\0'; - aoResultRGB[1] = (unsigned char)wcstoul(lColorChannel + 3, NULL, 16); - lColorChannel[3] = '\0'; - aoResultRGB[0] = (unsigned char)wcstoul(lColorChannel + 1, NULL, 16); - /* printf("%d %d %d\n", aoResultRGB[0], aoResultRGB[1], aoResultRGB[2]); */ - } - else - { - aoResultRGB[0] = 0; - aoResultRGB[1] = 0; - aoResultRGB[2] = 0; - } - } -} - - -static void RGB2HexW( unsigned char const aRGB[3], wchar_t aoResultHexRGB[8]) -{ -#if (defined(__cplusplus ) && __cplusplus >= 201103L) || (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__clang__) - wchar_t const * const lPrintFormat = L"#%02hhx%02hhx%02hhx"; -#else - wchar_t const * const lPrintFormat = L"#%02hx%02hx%02hx"; -#endif - - if (aoResultHexRGB) - { - if (aRGB) - { - /* wprintf(L"aoResultHexRGB %s\n", aoResultHexRGB); */ -#if !defined(__BORLANDC__) && !defined(__TINYC__) && !(defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR)) - swprintf(aoResultHexRGB, 8, lPrintFormat, aRGB[0], aRGB[1], aRGB[2]); -#else - swprintf(aoResultHexRGB, lPrintFormat, aRGB[0], aRGB[1], aRGB[2]); -#endif - - } - else - { - aoResultHexRGB[0] = 0; - aoResultHexRGB[1] = 0; - aoResultHexRGB[2] = 0; - } - } -} - - -static int dirExists(char const * aDirPath) -{ -#if defined(__MINGW32_MAJOR_VERSION) && !defined(__MINGW64__) && (__MINGW32_MAJOR_VERSION <= 3) - struct _stat lInfo; -#else - struct __stat64 lInfo; -#endif - wchar_t * lTmpWChar; - int lStatRet; - size_t lDirLen; - - if (!aDirPath) - return 0; - lDirLen = strlen(aDirPath); - if (!lDirLen) - return 1; - if ( (lDirLen == 2) && (aDirPath[1] == ':') ) - return 1; - - if (tinyfd_winUtf8) - { - lTmpWChar = tinyfd_utf8to16(aDirPath); -#if defined(__MINGW32_MAJOR_VERSION) && !defined(__MINGW64__) && (__MINGW32_MAJOR_VERSION <= 3) - lStatRet = _wstat(lTmpWChar, &lInfo); -#else - lStatRet = _wstat64(lTmpWChar, &lInfo); -#endif - if (lStatRet != 0) - return 0; - else if (lInfo.st_mode & S_IFDIR) - return 1; - else - return 0; - } -#if defined(__MINGW32_MAJOR_VERSION) && !defined(__MINGW64__) && (__MINGW32_MAJOR_VERSION <= 3) - else if (_stat(aDirPath, &lInfo) != 0) -#else - else if (_stat64(aDirPath, &lInfo) != 0) -#endif - return 0; - else if (lInfo.st_mode & S_IFDIR) - return 1; - else - return 0; -} - - -static int fileExists(char const * aFilePathAndName) -{ -#if defined(__MINGW32_MAJOR_VERSION) && !defined(__MINGW64__) && (__MINGW32_MAJOR_VERSION <= 3) - struct _stat lInfo; -#else - struct __stat64 lInfo; -#endif - wchar_t * lTmpWChar; - int lStatRet; - FILE * lIn; - - if (!aFilePathAndName || !strlen(aFilePathAndName)) - { - return 0; - } - - if (tinyfd_winUtf8) - { - lTmpWChar = tinyfd_utf8to16(aFilePathAndName); -#if defined(__MINGW32_MAJOR_VERSION) && !defined(__MINGW64__) && (__MINGW32_MAJOR_VERSION <= 3) - lStatRet = _wstat(lTmpWChar, &lInfo); -#else - lStatRet = _wstat64(lTmpWChar, &lInfo); -#endif - - if (lStatRet != 0) - return 0; - else if (lInfo.st_mode & _S_IFREG) - return 1; - else - return 0; - } - else - { - lIn = fopen(aFilePathAndName, "r"); - if (!lIn) - { - return 0; - } - fclose(lIn); - return 1; - } -} - -static void replaceWchar(wchar_t * aString, - wchar_t aOldChr, - wchar_t aNewChr) -{ - wchar_t * p; - - if (!aString) - { - return ; - } - - if (aOldChr == aNewChr) - { - return ; - } - - p = aString; - while ((p = wcsrchr(p, aOldChr))) - { - *p = aNewChr; -#ifdef TINYFD_NOCCSUNICODE - p++; -#endif - p++; - } - return ; -} - - -static int quoteDetectedW(wchar_t const * aString) -{ - wchar_t const * p; - - if (!aString) return 0; - - p = aString; - while ((p = wcsrchr(p, L'\''))) - { - return 1; - } - - p = aString; - while ((p = wcsrchr(p, L'\"'))) - { - return 1; - } - - return 0; -} - -#endif /* _WIN32 */ - -/* source and destination can be the same or ovelap*/ -static char * ensureFilesExist(char * aDestination, - char const * aSourcePathsAndNames) -{ - char * lDestination = aDestination; - char const * p; - char const * p2; - size_t lLen; - - if (!aSourcePathsAndNames) - { - return NULL; - } - lLen = strlen(aSourcePathsAndNames); - if (!lLen) - { - return NULL; - } - - p = aSourcePathsAndNames; - while ((p2 = strchr(p, '|')) != NULL) - { - lLen = p2 - p; - memmove(lDestination, p, lLen); - lDestination[lLen] = '\0'; - if (fileExists(lDestination)) - { - lDestination += lLen; - *lDestination = '|'; - lDestination++; - } - p = p2 + 1; - } - if (fileExists(p)) - { - lLen = strlen(p); - memmove(lDestination, p, lLen); - lDestination[lLen] = '\0'; - } - else - { - *(lDestination - 1) = '\0'; - } - return aDestination; -} - -#ifdef _WIN32 - -static int __stdcall EnumThreadWndProc(HWND hwnd, LPARAM lParam) -{ - wchar_t lTitleName[MAX_PATH]; - wchar_t const* lDialogTitle = (wchar_t const *) lParam; - - GetWindowTextW(hwnd, lTitleName, MAX_PATH); - /* wprintf(L"lTitleName %ls \n", lTitleName); */ - - if (wcscmp(lDialogTitle, lTitleName) == 0) - { - SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); - return 0; - } - return 1; -} - - -static void hiddenConsoleW(wchar_t const * aString, wchar_t const * aDialogTitle, int aInFront) -{ - STARTUPINFOW StartupInfo; - PROCESS_INFORMATION ProcessInfo; - - if (!aString || !wcslen(aString) ) return; - - memset(&StartupInfo, 0, sizeof(StartupInfo)); - StartupInfo.cb = sizeof(STARTUPINFOW); - StartupInfo.dwFlags = STARTF_USESHOWWINDOW; - StartupInfo.wShowWindow = SW_HIDE; - - if (!CreateProcessW(NULL, (LPWSTR)aString, NULL, NULL, FALSE, - CREATE_NEW_CONSOLE, NULL, NULL, - &StartupInfo, &ProcessInfo)) - { - return; /* GetLastError(); */ - } - - WaitForInputIdle(ProcessInfo.hProcess, INFINITE); - if (aInFront) - { - while (EnumWindows(EnumThreadWndProc, (LPARAM)aDialogTitle)) {} - } - WaitForSingleObject(ProcessInfo.hProcess, INFINITE); - CloseHandle(ProcessInfo.hThread); - CloseHandle(ProcessInfo.hProcess); -} - - -int tinyfd_messageBoxW( - wchar_t const * aTitle, /* NULL or "" */ - wchar_t const * aMessage, /* NULL or "" may contain \n and \t */ - wchar_t const * aDialogType, /* "ok" "okcancel" "yesno" "yesnocancel" */ - wchar_t const * aIconType, /* "info" "warning" "error" "question" */ - int aDefaultButton) /* 0 for cancel/no , 1 for ok/yes , 2 for no in yesnocancel */ -{ - int lBoxReturnValue; - UINT aCode; - - if (aTitle&&!wcscmp(aTitle, L"tinyfd_query")){ strcpy(tinyfd_response, "windows_wchar"); return 1; } - - /*if (quoteDetectedW(aTitle)) return tinyfd_messageBoxW(L"INVALID TITLE WITH QUOTES", aMessage, aDialogType, aIconType, aDefaultButton); - if (quoteDetectedW(aMessage)) return tinyfd_messageBoxW(aTitle, L"INVALID MESSAGE WITH QUOTES", aDialogType, aIconType, aDefaultButton);*/ - - if (aIconType && !wcscmp(L"warning", aIconType)) - { - aCode = MB_ICONWARNING; - } - else if (aIconType && !wcscmp(L"error", aIconType)) - { - aCode = MB_ICONERROR; - } - else if (aIconType && !wcscmp(L"question", aIconType)) - { - aCode = MB_ICONQUESTION; - } - else - { - aCode = MB_ICONINFORMATION; - } - - if (aDialogType && !wcscmp(L"okcancel", aDialogType)) - { - aCode += MB_OKCANCEL; - if (!aDefaultButton) - { - aCode += MB_DEFBUTTON2; - } - } - else if (aDialogType && !wcscmp(L"yesno", aDialogType)) - { - aCode += MB_YESNO; - if (!aDefaultButton) - { - aCode += MB_DEFBUTTON2; - } - } - else if (aDialogType && !wcscmp(L"yesnocancel", aDialogType)) - { - aCode += MB_YESNOCANCEL; - if (aDefaultButton == 1) - { - aCode += MB_DEFBUTTON1; - } - else if (aDefaultButton == 2) - { - aCode += MB_DEFBUTTON2; - } - else - { - aCode += MB_DEFBUTTON3; - } - } - else - { - aCode += MB_OK; - } - - aCode += MB_TOPMOST; - - lBoxReturnValue = MessageBoxW(GetForegroundWindow(), aMessage, aTitle, aCode); - - if ( (lBoxReturnValue == IDNO) && (aDialogType && !wcscmp(L"yesnocancel", aDialogType)) ) - { - return 2; - } - else if ( (lBoxReturnValue == IDOK) || (lBoxReturnValue == IDYES) ) - { - return 1; - } - else - { - return 0; - } -} - - -/* return has only meaning for tinyfd_query */ -int tinyfd_notifyPopupW( - wchar_t const * aTitle, /* NULL or L"" */ - wchar_t const * aMessage, /* NULL or L"" may contain \n \t */ - wchar_t const * aIconType) /* L"info" L"warning" L"error" */ -{ - wchar_t * lDialogString; - size_t lTitleLen; - size_t lMessageLen; - size_t lDialogStringLen; - - if (aTitle && !wcscmp(aTitle, L"tinyfd_query")) { strcpy(tinyfd_response, "windows_wchar"); return 1; } - - if (quoteDetectedW(aTitle)) return tinyfd_notifyPopupW(L"INVALID TITLE WITH QUOTES", aMessage, aIconType); - if (quoteDetectedW(aMessage)) return tinyfd_notifyPopupW(aTitle, L"INVALID MESSAGE WITH QUOTES", aIconType); - - lTitleLen = aTitle ? wcslen(aTitle) : 0; - lMessageLen = aMessage ? wcslen(aMessage) : 0; - lDialogStringLen = 3 * MAX_PATH_OR_CMD + lTitleLen + lMessageLen; - lDialogString = (wchar_t *)malloc(2 * lDialogStringLen); - if (!lDialogString) return 0; - - wcscpy(lDialogString, L"powershell.exe -command \"\ -function Show-BalloonTip {\ -[cmdletbinding()] \ -param( \ -[string]$Title = ' ', \ -[string]$Message = ' ', \ -[ValidateSet('info', 'warning', 'error')] \ -[string]$IconType = 'info');\ -[system.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms') | Out-Null ; \ -$balloon = New-Object System.Windows.Forms.NotifyIcon ; \ -$path = Get-Process -id $pid | Select-Object -ExpandProperty Path ; \ -$icon = [System.Drawing.Icon]::ExtractAssociatedIcon($path) ;"); - - wcscat(lDialogString, L"\ -$balloon.Icon = $icon ; \ -$balloon.BalloonTipIcon = $IconType ; \ -$balloon.BalloonTipText = $Message ; \ -$balloon.BalloonTipTitle = $Title ; \ -$balloon.Text = 'tinyfiledialogs' ; \ -$balloon.Visible = $true ; \ -$balloon.ShowBalloonTip(5000)};\ -Show-BalloonTip"); - - if (aTitle && wcslen(aTitle)) - { - wcscat(lDialogString, L" -Title '"); - wcscat(lDialogString, aTitle); - wcscat(lDialogString, L"'"); - } - if (aMessage && wcslen(aMessage)) - { - wcscat(lDialogString, L" -Message '"); - wcscat(lDialogString, aMessage); - wcscat(lDialogString, L"'"); - } - if (aMessage && wcslen(aIconType)) - { - wcscat(lDialogString, L" -IconType '"); - wcscat(lDialogString, aIconType); - wcscat(lDialogString, L"'"); - } - wcscat(lDialogString, L"\""); - - /* wprintf ( L"lDialogString: %ls\n" , lDialogString ) ; */ - - hiddenConsoleW(lDialogString, aTitle, 0); - free(lDialogString); - return 1; -} - - -wchar_t * tinyfd_inputBoxW( - wchar_t const * aTitle, /* NULL or L"" */ - wchar_t const * aMessage, /* NULL or L"" (\n and \t have no effect) */ - wchar_t const * aDefaultInput) /* L"" , if NULL it's a passwordBox */ -{ - static wchar_t lBuff[MAX_PATH_OR_CMD]; - wchar_t * lDialogString; - FILE * lIn; - FILE * lFile; - int lResult; - size_t lTitleLen; - size_t lMessageLen; - size_t lDialogStringLen; - - if (aTitle&&!wcscmp(aTitle, L"tinyfd_query")){ strcpy(tinyfd_response, "windows_wchar"); return (wchar_t *)1; } - - if (quoteDetectedW(aTitle)) return tinyfd_inputBoxW(L"INVALID TITLE WITH QUOTES", aMessage, aDefaultInput); - if (quoteDetectedW(aMessage)) return tinyfd_inputBoxW(aTitle, L"INVALID MESSAGE WITH QUOTES", aDefaultInput); - if (quoteDetectedW(aDefaultInput)) return tinyfd_inputBoxW(aTitle, aMessage, L"INVALID DEFAULT_INPUT WITH QUOTES: use the GRAVE ACCENT \\x60 instead."); - - lTitleLen = aTitle ? wcslen(aTitle) : 0 ; - lMessageLen = aMessage ? wcslen(aMessage) : 0 ; - lDialogStringLen = 3 * MAX_PATH_OR_CMD + lTitleLen + lMessageLen; - lDialogString = (wchar_t *)malloc(2 * lDialogStringLen); - - if (aDefaultInput) - { - swprintf(lDialogString, -#if !defined(__BORLANDC__) && !defined(__TINYC__) && !(defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR)) - lDialogStringLen, -#endif - L"%ls\\tinyfd.vbs", _wgetenv(L"TEMP")); - } - else - { - swprintf(lDialogString, -#if !defined(__BORLANDC__) && !defined(__TINYC__) && !(defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR)) - lDialogStringLen, -#endif - L"%ls\\tinyfd.hta", _wgetenv(L"TEMP")); - } - lIn = _wfopen(lDialogString, L"w"); - if (!lIn) - { - free(lDialogString); - return NULL; - } - - if ( aDefaultInput ) - { - wcscpy(lDialogString, L"Dim result:result=InputBox(\""); - if (aMessage && wcslen(aMessage)) - { - wcscpy(lBuff, aMessage); - replaceWchar(lBuff, L'\n', L' '); - wcscat(lDialogString, lBuff); - } - wcscat(lDialogString, L"\",\""); - if (aTitle) wcscat(lDialogString, aTitle); - wcscat(lDialogString, L"\",\""); - - if (aDefaultInput && wcslen(aDefaultInput)) - { - wcscpy(lBuff, aDefaultInput); - replaceWchar(lBuff, L'\n', L' '); - wcscat(lDialogString, lBuff); - } - wcscat(lDialogString, L"\"):If IsEmpty(result) then:WScript.Echo 0"); - wcscat(lDialogString, L":Else: WScript.Echo \"1\" & result : End If"); - } - else - { - wcscpy(lDialogString, L"\n\ -\n\ -\n\ -"); - if (aTitle) wcscat(lDialogString, aTitle); - wcscat(lDialogString, L"\n\ -\n\ -\n\ -\n\ -\n\ -\n\ -\n\ -\n\ -\n\ -\n\ -\n\ -
\n"); - - wcscat(lDialogString, aMessage ? aMessage : L""); - - wcscat(lDialogString, L"\n\ -\n\ -\n\ -\n\ -
\n\ -

\n\ -\n\ -
\n\ -
\n"); - - wcscat(lDialogString, L"\n\ -\n\ -\n\ -\n\ -
\n\ -
\n\ -
\n\ -\n\ -\n\ -" ) ; - } - fputws(lDialogString, lIn); - fclose(lIn); - - if (aDefaultInput) - { - swprintf(lDialogString, -#if !defined(__BORLANDC__) && !defined(__TINYC__) && !(defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR)) - lDialogStringLen, -#endif - L"%ls\\tinyfd.txt",_wgetenv(L"TEMP")); - -#ifdef TINYFD_NOCCSUNICODE - lFile = _wfopen(lDialogString, L"w"); - fputc(0xFF, lFile); - fputc(0xFE, lFile); -#else - lFile = _wfopen(lDialogString, L"wt, ccs=UNICODE"); /*or ccs=UTF-16LE*/ -#endif - fclose(lFile); - - wcscpy(lDialogString, L"cmd.exe /c cscript.exe //U //Nologo "); - wcscat(lDialogString, L"\"%TEMP%\\tinyfd.vbs\" "); - wcscat(lDialogString, L">> \"%TEMP%\\tinyfd.txt\""); - } - else - { - wcscpy(lDialogString, - L"cmd.exe /c mshta.exe \"%TEMP%\\tinyfd.hta\""); - } - - /* wprintf ( "lDialogString: %ls\n" , lDialogString ) ; */ - - hiddenConsoleW(lDialogString, aTitle, 1); - - swprintf(lDialogString, -#if !defined(__BORLANDC__) && !defined(__TINYC__) && !(defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR)) - lDialogStringLen, -#endif - L"%ls\\tinyfd.txt", _wgetenv(L"TEMP")); - /* wprintf(L"lDialogString: %ls\n", lDialogString); */ -#ifdef TINYFD_NOCCSUNICODE - if (!(lIn = _wfopen(lDialogString, L"r"))) -#else - if (!(lIn = _wfopen(lDialogString, L"rt, ccs=UNICODE"))) /*or ccs=UTF-16LE*/ -#endif - { - _wremove(lDialogString); - free(lDialogString); - return NULL; - } - - memset(lBuff, 0, MAX_PATH_OR_CMD * sizeof(wchar_t) ); - -#ifdef TINYFD_NOCCSUNICODE - fgets((char *)lBuff, 2*MAX_PATH_OR_CMD, lIn); -#else - fgetws(lBuff, MAX_PATH_OR_CMD, lIn); -#endif - fclose(lIn); - wipefileW(lDialogString); - _wremove(lDialogString); - - if (aDefaultInput) - { - swprintf(lDialogString, -#if !defined(__BORLANDC__) && !defined(__TINYC__) && !(defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR)) - lDialogStringLen, -#endif - L"%ls\\tinyfd.vbs", _wgetenv(L"TEMP")); - } - else - { - swprintf(lDialogString, -#if !defined(__BORLANDC__) && !defined(__TINYC__) && !(defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR)) - lDialogStringLen, -#endif - L"%ls\\tinyfd.hta", _wgetenv(L"TEMP")); - } - _wremove(lDialogString); - free(lDialogString); - /* wprintf( L"lBuff: %ls\n" , lBuff ) ; */ -#ifdef TINYFD_NOCCSUNICODE - lResult = !wcsncmp(lBuff+1, L"1", 1); -#else - lResult = !wcsncmp(lBuff, L"1", 1); -#endif - - /* printf( "lResult: %d \n" , lResult ) ; */ - if (!lResult) - { - return NULL ; - } - - /* wprintf( "lBuff+1: %ls\n" , lBuff+1 ) ; */ - -#ifdef TINYFD_NOCCSUNICODE - if (aDefaultInput) - { - lDialogStringLen = wcslen(lBuff) ; - lBuff[lDialogStringLen - 1] = L'\0'; - lBuff[lDialogStringLen - 2] = L'\0'; - } - return lBuff + 2; -#else - if (aDefaultInput) lBuff[wcslen(lBuff) - 1] = L'\0'; - return lBuff + 1; -#endif -} - - -wchar_t * tinyfd_saveFileDialogW( - wchar_t const * aTitle, /* NULL or "" */ - wchar_t const * aDefaultPathAndFile, /* NULL or "" */ - int aNumOfFilterPatterns, /* 0 */ - wchar_t const * const * aFilterPatterns, /* NULL or {"*.jpg","*.png"} */ - wchar_t const * aSingleFilterDescription) /* NULL or "image files" */ -{ - static wchar_t lBuff[MAX_PATH_OR_CMD]; - wchar_t lDirname[MAX_PATH_OR_CMD]; - wchar_t lDialogString[MAX_PATH_OR_CMD]; - wchar_t lFilterPatterns[MAX_PATH_OR_CMD] = L""; - wchar_t * p; - wchar_t * lRetval; - wchar_t const * ldefExt = NULL; - int i; - HRESULT lHResult; - OPENFILENAMEW ofn = {0}; - - if (aTitle&&!wcscmp(aTitle, L"tinyfd_query")){ strcpy(tinyfd_response, "windows_wchar"); return (wchar_t *)1; } - - /*if (quoteDetectedW(aTitle)) return tinyfd_saveFileDialogW(L"INVALID TITLE WITH QUOTES", aDefaultPathAndFile, aNumOfFilterPatterns, aFilterPatterns, aSingleFilterDescription); - if (quoteDetectedW(aDefaultPathAndFile)) return tinyfd_saveFileDialogW(aTitle, L"INVALID DEFAULT_PATH WITH QUOTES: use the GRAVE ACCENT \\x60 instead.", aNumOfFilterPatterns, aFilterPatterns, aSingleFilterDescription); - if (quoteDetectedW(aSingleFilterDescription)) return tinyfd_saveFileDialogW(aTitle, aDefaultPathAndFile, aNumOfFilterPatterns, aFilterPatterns, L"INVALID FILTER_DESCRIPTION WITH QUOTES: use the GRAVE ACCENT \\x60 instead."); - for (i = 0; i < aNumOfFilterPatterns; i++) - { - if (quoteDetectedW(aFilterPatterns[i])) return tinyfd_saveFileDialogW(L"INVALID FILTER_PATTERN WITH QUOTES: use the GRAVE ACCENT \\x60 instead.", aDefaultPathAndFile, 0, NULL, NULL); - }*/ - - lHResult = CoInitializeEx(NULL, 0); - - getPathWithoutFinalSlashW(lDirname, aDefaultPathAndFile); - getLastNameW(lBuff, aDefaultPathAndFile); - - if (aNumOfFilterPatterns > 0) - { - ldefExt = aFilterPatterns[0]; - - if (aSingleFilterDescription && wcslen(aSingleFilterDescription)) - { - wcscpy(lFilterPatterns, aSingleFilterDescription); - wcscat(lFilterPatterns, L"\n"); - } - wcscat(lFilterPatterns, aFilterPatterns[0]); - for (i = 1; i < aNumOfFilterPatterns; i++) - { - wcscat(lFilterPatterns, L";"); - wcscat(lFilterPatterns, aFilterPatterns[i]); - } - wcscat(lFilterPatterns, L"\n"); - if (!(aSingleFilterDescription && wcslen(aSingleFilterDescription))) - { - wcscpy(lDialogString, lFilterPatterns); - wcscat(lFilterPatterns, lDialogString); - } - wcscat(lFilterPatterns, L"All Files\n*.*\n"); - p = lFilterPatterns; - while ((p = wcschr(p, L'\n')) != NULL) - { - *p = L'\0'; - p++; - } - } - - ofn.lStructSize = sizeof(OPENFILENAMEW); - ofn.hwndOwner = GetForegroundWindow(); - ofn.hInstance = 0; - ofn.lpstrFilter = wcslen(lFilterPatterns) ? lFilterPatterns : NULL; - ofn.lpstrCustomFilter = NULL; - ofn.nMaxCustFilter = 0; - ofn.nFilterIndex = 1; - ofn.lpstrFile = lBuff; - - ofn.nMaxFile = MAX_PATH_OR_CMD; - ofn.lpstrFileTitle = NULL; - ofn.nMaxFileTitle = MAX_PATH_OR_CMD/2; - ofn.lpstrInitialDir = wcslen(lDirname) ? lDirname : NULL; - ofn.lpstrTitle = aTitle && wcslen(aTitle) ? aTitle : NULL; - ofn.Flags = OFN_OVERWRITEPROMPT | OFN_NOCHANGEDIR | OFN_PATHMUSTEXIST ; - ofn.nFileOffset = 0; - ofn.nFileExtension = 0; - ofn.lpstrDefExt = ldefExt; - ofn.lCustData = 0L; - ofn.lpfnHook = NULL; - ofn.lpTemplateName = NULL; - - if (GetSaveFileNameW(&ofn) == 0) - { - lRetval = NULL; - } - else - { - lRetval = lBuff; - } - - if (lHResult == S_OK || lHResult == S_FALSE) - { - CoUninitialize(); - } - return lRetval; -} - - -wchar_t * tinyfd_openFileDialogW( - wchar_t const * aTitle, /* NULL or "" */ - wchar_t const * aDefaultPathAndFile, /* NULL or "" */ - int aNumOfFilterPatterns, /* 0 */ - wchar_t const * const * aFilterPatterns, /* NULL or {"*.jpg","*.png"} */ - wchar_t const * aSingleFilterDescription, /* NULL or "image files" */ - int aAllowMultipleSelects) /* 0 or 1 ; -1 to free allocated memory and return */ -{ - size_t lLengths[MAX_MULTIPLE_FILES]; - wchar_t lDirname[MAX_PATH_OR_CMD]; - wchar_t lFilterPatterns[MAX_PATH_OR_CMD] = L""; - wchar_t lDialogString[MAX_PATH_OR_CMD]; - wchar_t * lPointers[MAX_MULTIPLE_FILES+1]; - wchar_t * p; - int i, j; - size_t lBuffLen; - DWORD lFullBuffLen; - HRESULT lHResult; - OPENFILENAMEW ofn = { 0 }; - static wchar_t * lBuff = NULL; - - free(lBuff); - lBuff = NULL; - if (aAllowMultipleSelects < 0) return (wchar_t *)0; - - if (aTitle&&!wcscmp(aTitle, L"tinyfd_query")){ strcpy(tinyfd_response, "windows_wchar"); return (wchar_t *)1; } - - /*if (quoteDetectedW(aTitle)) return tinyfd_openFileDialogW(L"INVALID TITLE WITH QUOTES", aDefaultPathAndFile, aNumOfFilterPatterns, aFilterPatterns, aSingleFilterDescription, aAllowMultipleSelects); - if (quoteDetectedW(aDefaultPathAndFile)) return tinyfd_openFileDialogW(aTitle, L"INVALID DEFAULT_PATH WITH QUOTES: use the GRAVE ACCENT \\x60 instead.", aNumOfFilterPatterns, aFilterPatterns, aSingleFilterDescription, aAllowMultipleSelects); - if (quoteDetectedW(aSingleFilterDescription)) return tinyfd_openFileDialogW(aTitle, aDefaultPathAndFile, aNumOfFilterPatterns, aFilterPatterns, L"INVALID FILTER_DESCRIPTION WITH QUOTES: use the GRAVE ACCENT \\x60 instead.", aAllowMultipleSelects); - for (i = 0; i < aNumOfFilterPatterns; i++) - { - if (quoteDetectedW(aFilterPatterns[i])) return tinyfd_openFileDialogW(L"INVALID FILTER_PATTERN WITH QUOTES: use the GRAVE ACCENT \\x60 instead.", aDefaultPathAndFile, 0, NULL, NULL, aAllowMultipleSelects); - }*/ - - if (aAllowMultipleSelects) - { - lFullBuffLen = MAX_MULTIPLE_FILES * MAX_PATH_OR_CMD + 1; - lBuff = (wchar_t*)(malloc(lFullBuffLen * sizeof(wchar_t))); - if (!lBuff) - { - lFullBuffLen = LOW_MULTIPLE_FILES * MAX_PATH_OR_CMD + 1; - lBuff = (wchar_t*)( malloc( lFullBuffLen * sizeof(wchar_t))); - } - } - else - { - lFullBuffLen = MAX_PATH_OR_CMD + 1; - lBuff = (wchar_t*)(malloc(lFullBuffLen * sizeof(wchar_t))); - } - if (!lBuff) return NULL; - - lHResult = CoInitializeEx(NULL, 0); - - getPathWithoutFinalSlashW(lDirname, aDefaultPathAndFile); - getLastNameW(lBuff, aDefaultPathAndFile); - - if (aNumOfFilterPatterns > 0) - { - if (aSingleFilterDescription && wcslen(aSingleFilterDescription)) - { - wcscpy(lFilterPatterns, aSingleFilterDescription); - wcscat(lFilterPatterns, L"\n"); - } - wcscat(lFilterPatterns, aFilterPatterns[0]); - for (i = 1; i < aNumOfFilterPatterns; i++) - { - wcscat(lFilterPatterns, L";"); - wcscat(lFilterPatterns, aFilterPatterns[i]); - } - wcscat(lFilterPatterns, L"\n"); - if (!(aSingleFilterDescription && wcslen(aSingleFilterDescription))) - { - wcscpy(lDialogString, lFilterPatterns); - wcscat(lFilterPatterns, lDialogString); - } - wcscat(lFilterPatterns, L"All Files\n*.*\n"); - p = lFilterPatterns; - while ((p = wcschr(p, L'\n')) != NULL) - { - *p = L'\0'; - p++; - } - } - - ofn.lStructSize = sizeof(OPENFILENAME); - ofn.hwndOwner = GetForegroundWindow(); - ofn.hInstance = 0; - ofn.lpstrFilter = wcslen(lFilterPatterns) ? lFilterPatterns : NULL; - ofn.lpstrCustomFilter = NULL; - ofn.nMaxCustFilter = 0; - ofn.nFilterIndex = 1; - ofn.lpstrFile = lBuff; - ofn.nMaxFile = lFullBuffLen; - ofn.lpstrFileTitle = NULL; - ofn.nMaxFileTitle = MAX_PATH_OR_CMD / 2; - ofn.lpstrInitialDir = wcslen(lDirname) ? lDirname : NULL; - ofn.lpstrTitle = aTitle && wcslen(aTitle) ? aTitle : NULL; - ofn.Flags = OFN_EXPLORER | OFN_NOCHANGEDIR | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST; - ofn.nFileOffset = 0; - ofn.nFileExtension = 0; - ofn.lpstrDefExt = NULL; - ofn.lCustData = 0L; - ofn.lpfnHook = NULL; - ofn.lpTemplateName = NULL; - - if (aAllowMultipleSelects) - { - ofn.Flags |= OFN_ALLOWMULTISELECT; - } - - if (GetOpenFileNameW(&ofn) == 0) - { - free(lBuff); - lBuff = NULL; - } - else - { - lBuffLen = wcslen(lBuff); - lPointers[0] = lBuff + lBuffLen + 1; - if (aAllowMultipleSelects && (lPointers[0][0] != L'\0')) - { - i = 0; - do - { - lLengths[i] = wcslen(lPointers[i]); - lPointers[i + 1] = lPointers[i] + lLengths[i] + 1; - i++; - } while (lPointers[i][0] != L'\0' && i < MAX_MULTIPLE_FILES ); - - if (i > MAX_MULTIPLE_FILES) - { - free(lBuff); - lBuff = NULL; - } - else - { - i--; - p = lBuff + lFullBuffLen - 1; - *p = L'\0'; - for (j = i; j >= 0; j--) - { - p -= lLengths[j]; - memmove(p, lPointers[j], lLengths[j] * sizeof(wchar_t)); - p--; - *p = L'\\'; - p -= lBuffLen; - memmove(p, lBuff, lBuffLen*sizeof(wchar_t)); - p--; - *p = L'|'; - } - p++; - wcscpy(lBuff, p); - lBuffLen = wcslen(lBuff); - } - } - if (lBuff) lBuff = (wchar_t*)(realloc(lBuff, (lBuffLen + 1) * sizeof(wchar_t))); - } - - if (lHResult == S_OK || lHResult == S_FALSE) - { - CoUninitialize(); - } - - return lBuff; -} - - -BOOL CALLBACK BrowseCallbackProcW_enum(HWND hWndChild, LPARAM lParam) -{ - wchar_t buf[255]; - GetClassNameW(hWndChild, buf, sizeof(buf)); - if (wcscmp(buf, L"SysTreeView32") == 0) - { - HTREEITEM hNode = TreeView_GetSelection(hWndChild); - TreeView_EnsureVisible(hWndChild, hNode); - return FALSE; - } - return TRUE; -} - - -static int __stdcall BrowseCallbackProcW(HWND hwnd, UINT uMsg, LPARAM lp, LPARAM pData) -{ - switch (uMsg) - { - case BFFM_INITIALIZED: - SendMessage(hwnd, BFFM_SETSELECTIONW, TRUE, (LPARAM)pData); - break; - case BFFM_SELCHANGED: - EnumChildWindows(hwnd, BrowseCallbackProcW_enum, 0); - } - return 0; -} - -wchar_t * tinyfd_selectFolderDialogW( - wchar_t const * aTitle, /* NULL or "" */ - wchar_t const * aDefaultPath) /* NULL or "" */ -{ - static wchar_t lBuff[MAX_PATH_OR_CMD]; - wchar_t * lRetval; - - BROWSEINFOW bInfo; - LPITEMIDLIST lpItem; - HRESULT lHResult; - - if (aTitle&&!wcscmp(aTitle, L"tinyfd_query")){ strcpy(tinyfd_response, "windows_wchar"); return (wchar_t *)1; } - - /*if (quoteDetectedW(aTitle)) return tinyfd_selectFolderDialogW(L"INVALID TITLE WITH QUOTES", aDefaultPath); - if (quoteDetectedW(aDefaultPath)) return tinyfd_selectFolderDialogW(aTitle, L"INVALID DEFAULT_PATH WITH QUOTES: use the GRAVE ACCENT \\x60 instead.");*/ - - lHResult = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); - - bInfo.hwndOwner = GetForegroundWindow(); - bInfo.pidlRoot = NULL; - bInfo.pszDisplayName = lBuff; - bInfo.lpszTitle = aTitle && wcslen(aTitle) ? aTitle : NULL; - if (lHResult == S_OK || lHResult == S_FALSE) - { - bInfo.ulFlags = BIF_USENEWUI; - } - bInfo.lpfn = BrowseCallbackProcW; - bInfo.lParam = (LPARAM)aDefaultPath; - bInfo.iImage = -1; - - lpItem = SHBrowseForFolderW(&bInfo); - if (!lpItem) - { - lRetval = NULL; - } - else - { - SHGetPathFromIDListW(lpItem, lBuff); - lRetval = lBuff ; - } - - if (lHResult == S_OK || lHResult == S_FALSE) - { - CoUninitialize(); - } - return lRetval; -} - - -wchar_t * tinyfd_colorChooserW( - wchar_t const * aTitle, /* NULL or "" */ - wchar_t const * aDefaultHexRGB, /* NULL or "#FF0000"*/ - unsigned char const aDefaultRGB[3], /* { 0 , 255 , 255 } */ - unsigned char aoResultRGB[3]) /* { 0 , 0 , 0 } */ -{ - static wchar_t lResultHexRGB[8]; - CHOOSECOLORW cc; - COLORREF crCustColors[16]; - unsigned char lDefaultRGB[3]; - int lRet; - - HRESULT lHResult; - - if (aTitle&&!wcscmp(aTitle, L"tinyfd_query")){ strcpy(tinyfd_response, "windows_wchar"); return (wchar_t *)1; } - - /*if (quoteDetectedW(aTitle)) return tinyfd_colorChooserW(L"INVALID TITLE WITH QUOTES", aDefaultHexRGB, aDefaultRGB, aoResultRGB); - if (quoteDetectedW(aDefaultHexRGB)) return tinyfd_colorChooserW(aTitle, L"INVALID DEFAULT_HEX_RGB WITH QUOTES: use the GRAVE ACCENT \\x60 instead.", aDefaultRGB, aoResultRGB);*/ - - lHResult = CoInitializeEx(NULL, 0); - - if ( aDefaultHexRGB ) - { - Hex2RGBW(aDefaultHexRGB, lDefaultRGB); - } - else - { - lDefaultRGB[0] = aDefaultRGB[0]; - lDefaultRGB[1] = aDefaultRGB[1]; - lDefaultRGB[2] = aDefaultRGB[2]; - } - - /* we can't use aTitle */ - cc.lStructSize = sizeof(CHOOSECOLOR); - cc.hwndOwner = GetForegroundWindow(); - cc.hInstance = NULL; - cc.rgbResult = RGB(lDefaultRGB[0], lDefaultRGB[1], lDefaultRGB[2]); - cc.lpCustColors = crCustColors; - cc.Flags = CC_RGBINIT | CC_FULLOPEN | CC_ANYCOLOR ; - cc.lCustData = 0; - cc.lpfnHook = NULL; - cc.lpTemplateName = NULL; - - lRet = ChooseColorW(&cc); - - if (!lRet) - { - return NULL; - } - - aoResultRGB[0] = GetRValue(cc.rgbResult); - aoResultRGB[1] = GetGValue(cc.rgbResult); - aoResultRGB[2] = GetBValue(cc.rgbResult); - - RGB2HexW(aoResultRGB, lResultHexRGB); - - if (lHResult == S_OK || lHResult == S_FALSE) - { - CoUninitialize(); - } - - return lResultHexRGB; -} - - -static int messageBoxWinGui( - char const * aTitle, /* NULL or "" */ - char const * aMessage, /* NULL or "" may contain \n and \t */ - char const * aDialogType, /* "ok" "okcancel" "yesno" "yesnocancel" */ - char const * aIconType, /* "info" "warning" "error" "question" */ - int aDefaultButton) /* 0 for cancel/no , 1 for ok/yes , 2 for no in yesnocancel */ -{ - int lIntRetVal; - wchar_t lTitle[128] = L""; - wchar_t * lMessage = NULL; - wchar_t lDialogType[16] = L""; - wchar_t lIconType[16] = L""; - wchar_t * lTmpWChar; - - if (aTitle) - { - if (tinyfd_winUtf8) lTmpWChar = tinyfd_utf8to16(aTitle); - else lTmpWChar = tinyfd_mbcsTo16(aTitle); - wcscpy(lTitle, lTmpWChar); - } - if (aMessage) - { - if (tinyfd_winUtf8) lTmpWChar = tinyfd_utf8to16(aMessage); - else lTmpWChar = tinyfd_mbcsTo16(aMessage); - lMessage = (wchar_t *) malloc((wcslen(lTmpWChar) + 1)* sizeof(wchar_t)); - if (lMessage) wcscpy(lMessage, lTmpWChar); - } - if (aDialogType) - { - if (tinyfd_winUtf8) lTmpWChar = tinyfd_utf8to16(aDialogType); - else lTmpWChar = tinyfd_mbcsTo16(aDialogType); - wcscpy(lDialogType, lTmpWChar); - } - if (aIconType) - { - if (tinyfd_winUtf8) lTmpWChar = tinyfd_utf8to16(aIconType); - else lTmpWChar = tinyfd_mbcsTo16(aIconType); - wcscpy(lIconType, lTmpWChar); - } - - lIntRetVal = tinyfd_messageBoxW(lTitle, lMessage, lDialogType, lIconType, aDefaultButton); - - free(lMessage); - - return lIntRetVal; -} - - -static int notifyWinGui( - char const * aTitle, /* NULL or "" */ - char const * aMessage, /* NULL or "" may NOT contain \n nor \t */ - char const * aIconType) -{ - wchar_t lTitle[128] = L""; - wchar_t * lMessage = NULL; - wchar_t lIconType[16] = L""; - wchar_t * lTmpWChar; - - if (aTitle) - { - if (tinyfd_winUtf8) lTmpWChar = tinyfd_utf8to16(aTitle); - else lTmpWChar = tinyfd_mbcsTo16(aTitle); - wcscpy(lTitle, lTmpWChar); - } - if (aMessage) - { - if (tinyfd_winUtf8) lTmpWChar = tinyfd_utf8to16(aMessage); - else lTmpWChar = tinyfd_mbcsTo16(aMessage); - lMessage = (wchar_t *) malloc((wcslen(lTmpWChar) + 1)* sizeof(wchar_t)); - if (lMessage) wcscpy(lMessage, lTmpWChar); - } - if (aIconType) - { - if (tinyfd_winUtf8) lTmpWChar = tinyfd_utf8to16(aIconType); - else lTmpWChar = tinyfd_mbcsTo16(aIconType); - wcscpy(lIconType, lTmpWChar); - } - - tinyfd_notifyPopupW(lTitle, lMessage, lIconType); - - free(lMessage); - - return 1; -} - - -static int inputBoxWinGui( - char * aoBuff, - char const * aTitle, /* NULL or "" */ - char const * aMessage, /* NULL or "" may NOT contain \n nor \t */ - char const * aDefaultInput) /* "" , if NULL it's a passwordBox */ -{ - wchar_t lTitle[128] = L""; - wchar_t * lMessage = NULL; - wchar_t lDefaultInput[MAX_PATH_OR_CMD] = L""; - wchar_t * lTmpWChar; - char * lTmpChar; - - if (aTitle) - { - if (tinyfd_winUtf8) lTmpWChar = tinyfd_utf8to16(aTitle); - else lTmpWChar = tinyfd_mbcsTo16(aTitle); - wcscpy(lTitle, lTmpWChar); - } - if (aMessage) - { - if (tinyfd_winUtf8) lTmpWChar = tinyfd_utf8to16(aMessage); - else lTmpWChar = tinyfd_mbcsTo16(aMessage); - lMessage = (wchar_t *) malloc((wcslen(lTmpWChar) + 1)* sizeof(wchar_t)); - if (lMessage) wcscpy(lMessage, lTmpWChar); - } - if (aDefaultInput) - { - if (tinyfd_winUtf8) lTmpWChar = tinyfd_utf8to16(aDefaultInput); - else lTmpWChar = tinyfd_mbcsTo16(aDefaultInput); - wcscpy(lDefaultInput, lTmpWChar); - lTmpWChar = tinyfd_inputBoxW(lTitle, lMessage, lDefaultInput); - } - else lTmpWChar = tinyfd_inputBoxW(lTitle, lMessage, NULL); - - free(lMessage); - - if (!lTmpWChar) - { - aoBuff[0] = '\0'; - return 0; - } - - if (tinyfd_winUtf8) lTmpChar = tinyfd_utf16to8(lTmpWChar); - else lTmpChar = tinyfd_utf16toMbcs(lTmpWChar); - - strcpy(aoBuff, lTmpChar); - - return 1; -} - - -static char * saveFileDialogWinGui( - char * aoBuff, - char const * aTitle, /* NULL or "" */ - char const * aDefaultPathAndFile, /* NULL or "" */ - int aNumOfFilterPatterns, /* 0 */ - char const * const * aFilterPatterns, /* NULL or {"*.jpg","*.png"} */ - char const * aSingleFilterDescription) /* NULL or "image files" */ -{ - wchar_t lTitle[128] = L""; - wchar_t lDefaultPathAndFile[MAX_PATH_OR_CMD] = L""; - wchar_t lSingleFilterDescription[128] = L""; - wchar_t * * lFilterPatterns; - wchar_t * lTmpWChar; - char * lTmpChar; - int i; - - lFilterPatterns = (wchar_t **)malloc(aNumOfFilterPatterns*sizeof(wchar_t *)); - for (i = 0; i < aNumOfFilterPatterns; i++) - { - if (tinyfd_winUtf8) lTmpWChar = tinyfd_utf8to16(aFilterPatterns[i]); - else lTmpWChar = tinyfd_mbcsTo16(aFilterPatterns[i]); - lFilterPatterns[i] = (wchar_t *)malloc((wcslen(lTmpWChar) + 1) * sizeof(wchar_t *)); - if (lFilterPatterns[i]) wcscpy(lFilterPatterns[i], lTmpWChar); - } - - if (aTitle) - { - if (tinyfd_winUtf8) lTmpWChar = tinyfd_utf8to16(aTitle); - else lTmpWChar = tinyfd_mbcsTo16(aTitle); - wcscpy(lTitle, lTmpWChar); - } - if (aDefaultPathAndFile) - { - if (tinyfd_winUtf8) lTmpWChar = tinyfd_utf8to16(aDefaultPathAndFile); - else lTmpWChar = tinyfd_mbcsTo16(aDefaultPathAndFile); - wcscpy(lDefaultPathAndFile, lTmpWChar); - } - if (aSingleFilterDescription) - { - if (tinyfd_winUtf8) lTmpWChar = tinyfd_utf8to16(aSingleFilterDescription); - else lTmpWChar = tinyfd_mbcsTo16(aSingleFilterDescription); - wcscpy(lSingleFilterDescription, lTmpWChar); - } - - lTmpWChar = tinyfd_saveFileDialogW( - lTitle, - lDefaultPathAndFile, - aNumOfFilterPatterns, - (wchar_t const**) lFilterPatterns, /*stupid cast for gcc*/ - lSingleFilterDescription); - - for (i = 0; i < aNumOfFilterPatterns; i++) - { - free(lFilterPatterns[i]); - } - free(lFilterPatterns); - - if (!lTmpWChar) - { - return NULL; - } - - if (tinyfd_winUtf8) lTmpChar = tinyfd_utf16to8(lTmpWChar); - else lTmpChar = tinyfd_utf16toMbcs(lTmpWChar); - strcpy(aoBuff, lTmpChar); - if (tinyfd_winUtf8) (void)tinyfd_utf16to8(NULL); - else (void)tinyfd_utf16toMbcs(NULL); - - return aoBuff; -} - - -static char * openFileDialogWinGui( - char const * aTitle, /* NULL or "" */ - char const * aDefaultPathAndFile, /* NULL or "" */ - int aNumOfFilterPatterns, /* 0 */ - char const * const * aFilterPatterns, /* NULL or {"*.jpg","*.png"} */ - char const * aSingleFilterDescription, /* NULL or "image files" */ - int aAllowMultipleSelects) /* 0 or 1 */ -{ - wchar_t lTitle[128] = L""; - wchar_t lDefaultPathAndFile[MAX_PATH_OR_CMD] = L""; - wchar_t lSingleFilterDescription[128] = L""; - wchar_t * * lFilterPatterns; - wchar_t * lTmpWChar; - char * lTmpChar; - int i; - - lFilterPatterns = (wchar_t * *)malloc(aNumOfFilterPatterns*sizeof(wchar_t *)); - for (i = 0; i < aNumOfFilterPatterns; i++) - { - if (tinyfd_winUtf8) lTmpWChar = tinyfd_utf8to16(aFilterPatterns[i]); - else lTmpWChar = tinyfd_mbcsTo16(aFilterPatterns[i]); - lFilterPatterns[i] = (wchar_t *)malloc((wcslen(lTmpWChar) + 1)*sizeof(wchar_t *)); - if (lFilterPatterns[i]) wcscpy(lFilterPatterns[i], lTmpWChar); - } - - if (aTitle) - { - if (tinyfd_winUtf8) lTmpWChar = tinyfd_utf8to16(aTitle); - else lTmpWChar = tinyfd_mbcsTo16(aTitle); - wcscpy(lTitle, lTmpWChar); - } - if (aDefaultPathAndFile) - { - if (tinyfd_winUtf8) lTmpWChar = tinyfd_utf8to16(aDefaultPathAndFile); - else lTmpWChar = tinyfd_mbcsTo16(aDefaultPathAndFile); - wcscpy(lDefaultPathAndFile, lTmpWChar); - } - if (aSingleFilterDescription) - { - if (tinyfd_winUtf8) lTmpWChar = tinyfd_utf8to16(aSingleFilterDescription); - else lTmpWChar = tinyfd_mbcsTo16(aSingleFilterDescription); - wcscpy(lSingleFilterDescription, lTmpWChar); - } - - lTmpWChar = tinyfd_openFileDialogW( - lTitle, - lDefaultPathAndFile, - aNumOfFilterPatterns, - (wchar_t const**) lFilterPatterns, /*stupid cast for gcc*/ - lSingleFilterDescription, - aAllowMultipleSelects); - - for (i = 0; i < aNumOfFilterPatterns; i++) - { - free(lFilterPatterns[i]); - } - free(lFilterPatterns); - - if (!lTmpWChar) return NULL; - - if (tinyfd_winUtf8) lTmpChar = tinyfd_utf16to8(lTmpWChar); - else lTmpChar = tinyfd_utf16toMbcs(lTmpWChar); - (void)tinyfd_openFileDialogW(NULL, NULL, 0, NULL, NULL, -1); - - return lTmpChar; -} - - -static char * selectFolderDialogWinGui( - char * aoBuff, - char const * aTitle, /* NULL or "" */ - char const * aDefaultPath) /* NULL or "" */ -{ - wchar_t lTitle[128] = L""; - wchar_t lDefaultPath[MAX_PATH_OR_CMD] = L""; - wchar_t * lTmpWChar; - char * lTmpChar; - - if (aTitle) - { - if (tinyfd_winUtf8) lTmpWChar = tinyfd_utf8to16(aTitle); - else lTmpWChar = tinyfd_mbcsTo16(aTitle); - wcscpy(lTitle, lTmpWChar); - } - if (aDefaultPath) - { - if (tinyfd_winUtf8) lTmpWChar = tinyfd_utf8to16(aDefaultPath); - else lTmpWChar = tinyfd_mbcsTo16(aDefaultPath); - wcscpy(lDefaultPath, lTmpWChar); - } - - lTmpWChar = tinyfd_selectFolderDialogW( - lTitle, - lDefaultPath); - - if (!lTmpWChar) - { - return NULL; - } - - if (tinyfd_winUtf8) lTmpChar = tinyfd_utf16to8(lTmpWChar); - else lTmpChar = tinyfd_utf16toMbcs(lTmpWChar); - strcpy(aoBuff, lTmpChar); - - return aoBuff; -} - - -static char * colorChooserWinGui( - char const * aTitle, /* NULL or "" */ - char const * aDefaultHexRGB, /* NULL or "#FF0000"*/ - unsigned char const aDefaultRGB[3], /* { 0 , 255 , 255 } */ - unsigned char aoResultRGB[3]) /* { 0 , 0 , 0 } */ -{ - static char lResultHexRGB[8]; - - wchar_t lTitle[128]; - wchar_t lDefaultHexRGB[16]; - wchar_t * lTmpWChar; - char * lTmpChar; - - if (aTitle) - { - if (tinyfd_winUtf8) lTmpWChar = tinyfd_utf8to16(aTitle); - else lTmpWChar = tinyfd_mbcsTo16(aTitle); - wcscpy(lTitle, lTmpWChar); - } - if (aDefaultHexRGB) - { - if (tinyfd_winUtf8) lTmpWChar = tinyfd_utf8to16(aDefaultHexRGB); - else lTmpWChar = tinyfd_mbcsTo16(aDefaultHexRGB); - wcscpy(lDefaultHexRGB, lTmpWChar); - } - - lTmpWChar = tinyfd_colorChooserW( - lTitle, - lDefaultHexRGB, - aDefaultRGB, - aoResultRGB ); - - if (!lTmpWChar) - { - return NULL; - } - - if (tinyfd_winUtf8) lTmpChar = tinyfd_utf16to8(lTmpWChar); - else lTmpChar = tinyfd_utf16toMbcs(lTmpWChar); - strcpy(lResultHexRGB, lTmpChar); - - return lResultHexRGB; -} - - -static int dialogPresent(void) -{ - static int lDialogPresent = -1 ; - char lBuff[MAX_PATH_OR_CMD] ; - FILE * lIn ; - char const * lString = "dialog.exe"; - if (!tinyfd_allowCursesDialogs) return 0; - if (lDialogPresent < 0) - { - if (!(lIn = _popen("where dialog.exe","r"))) - { - lDialogPresent = 0 ; - return 0 ; - } - while ( fgets( lBuff , sizeof( lBuff ) , lIn ) != NULL ) - {} - _pclose( lIn ) ; - if ( lBuff[strlen( lBuff ) -1] == '\n' ) - { - lBuff[strlen( lBuff ) -1] = '\0' ; - } - if ( strcmp(lBuff+strlen(lBuff)-strlen(lString),lString) ) - { - lDialogPresent = 0 ; - } - else - { - lDialogPresent = 1 ; - } - } - return lDialogPresent; -} - - -static int messageBoxWinConsole( - char const * aTitle , /* NULL or "" */ - char const * aMessage , /* NULL or "" may contain \n and \t */ - char const * aDialogType , /* "ok" "okcancel" "yesno" "yesnocancel" */ - char const * aIconType , /* "info" "warning" "error" "question" */ - int aDefaultButton ) /* 0 for cancel/no , 1 for ok/yes , 2 for no in yesnocancel */ -{ - char lDialogString[MAX_PATH_OR_CMD]; - char lDialogFile[MAX_PATH_OR_CMD]; - FILE * lIn; - char lBuff[MAX_PATH_OR_CMD] = ""; - - strcpy(lDialogString, "dialog "); - if (aTitle && strlen(aTitle)) - { - strcat(lDialogString, "--title \"") ; - strcat(lDialogString, aTitle) ; - strcat(lDialogString, "\" ") ; - } - - if ( aDialogType && ( !strcmp( "okcancel" , aDialogType ) - || !strcmp("yesno", aDialogType) || !strcmp("yesnocancel", aDialogType) ) ) - { - strcat(lDialogString, "--backtitle \"") ; - strcat(lDialogString, "tab: move focus") ; - strcat(lDialogString, "\" ") ; - } - - if ( aDialogType && ! strcmp( "okcancel" , aDialogType ) ) - { - if ( ! aDefaultButton ) - { - strcat( lDialogString , "--defaultno " ) ; - } - strcat( lDialogString , - "--yes-label \"Ok\" --no-label \"Cancel\" --yesno " ) ; - } - else if ( aDialogType && ! strcmp( "yesno" , aDialogType ) ) - { - if ( ! aDefaultButton ) - { - strcat( lDialogString , "--defaultno " ) ; - } - strcat( lDialogString , "--yesno " ) ; - } - else if (aDialogType && !strcmp("yesnocancel", aDialogType)) - { - if (!aDefaultButton) - { - strcat(lDialogString, "--defaultno "); - } - strcat(lDialogString, "--menu "); - } - else - { - strcat( lDialogString , "--msgbox " ) ; - } - - strcat( lDialogString , "\"" ) ; - if ( aMessage && strlen(aMessage) ) - { - tfd_replaceSubStr( aMessage , "\n" , "\\n" , lBuff ) ; - strcat(lDialogString, lBuff) ; - lBuff[0]='\0'; - } - strcat(lDialogString, "\" "); - - if (aDialogType && !strcmp("yesnocancel", aDialogType)) - { - strcat(lDialogString, "0 60 0 Yes \"\" No \"\""); - strcat(lDialogString, "2>>"); - } - else - { - strcat(lDialogString, "10 60"); - strcat(lDialogString, " && echo 1 > "); - } - - strcpy(lDialogFile, getenv("TEMP")); - strcat(lDialogFile, "\\tinyfd.txt"); - strcat(lDialogString, lDialogFile); - - /*if (tinyfd_verbose) printf( "lDialogString: %s\n" , lDialogString ) ;*/ - system( lDialogString ) ; - - if (!(lIn = fopen(lDialogFile, "r"))) - { - remove(lDialogFile); - return 0 ; - } - while (fgets(lBuff, sizeof(lBuff), lIn) != NULL) - {} - fclose(lIn); - remove(lDialogFile); - if ( lBuff[strlen( lBuff ) -1] == '\n' ) - { - lBuff[strlen( lBuff ) -1] = '\0' ; - } - - /* if (tinyfd_verbose) printf("lBuff: %s\n", lBuff); */ - if ( ! strlen(lBuff) ) - { - return 0; - } - - if (aDialogType && !strcmp("yesnocancel", aDialogType)) - { - if (lBuff[0] == 'Y') return 1; - else return 2; - } - - return 1; -} - - -static int inputBoxWinConsole( - char * aoBuff , - char const * aTitle , /* NULL or "" */ - char const * aMessage , /* NULL or "" may NOT contain \n nor \t */ - char const * aDefaultInput ) /* "" , if NULL it's a passwordBox */ -{ - char lDialogString[MAX_PATH_OR_CMD]; - char lDialogFile[MAX_PATH_OR_CMD]; - FILE * lIn; - int lResult; - - strcpy(lDialogFile, getenv("TEMP")); - strcat(lDialogFile, "\\tinyfd.txt"); - strcpy(lDialogString , "echo|set /p=1 >" ) ; - strcat(lDialogString, lDialogFile); - strcat( lDialogString , " & " ) ; - - strcat( lDialogString , "dialog " ) ; - if ( aTitle && strlen(aTitle) ) - { - strcat(lDialogString, "--title \"") ; - strcat(lDialogString, aTitle) ; - strcat(lDialogString, "\" ") ; - } - - strcat(lDialogString, "--backtitle \"") ; - strcat(lDialogString, "tab: move focus") ; - if ( ! aDefaultInput ) - { - strcat(lDialogString, " (sometimes nothing, no blink nor star, is shown in text field)") ; - } - - strcat(lDialogString, "\" ") ; - - if ( ! aDefaultInput ) - { - strcat( lDialogString , "--insecure --passwordbox" ) ; - } - else - { - strcat( lDialogString , "--inputbox" ) ; - } - strcat( lDialogString , " \"" ) ; - if ( aMessage && strlen(aMessage) ) - { - strcat(lDialogString, aMessage) ; - } - strcat(lDialogString,"\" 10 60 ") ; - if ( aDefaultInput && strlen(aDefaultInput) ) - { - strcat(lDialogString, "\"") ; - strcat(lDialogString, aDefaultInput) ; - strcat(lDialogString, "\" ") ; - } - - strcat(lDialogString, "2>>"); - strcpy(lDialogFile, getenv("TEMP")); - strcat(lDialogFile, "\\tinyfd.txt"); - strcat(lDialogString, lDialogFile); - strcat(lDialogString, " || echo 0 > "); - strcat(lDialogString, lDialogFile); - - /* printf( "lDialogString: %s\n" , lDialogString ) ; */ - system( lDialogString ) ; - - if (!(lIn = fopen(lDialogFile, "r"))) - { - remove(lDialogFile); - aoBuff[0] = '\0'; - return 0; - } - while (fgets(aoBuff, MAX_PATH_OR_CMD, lIn) != NULL) - {} - fclose(lIn); - - wipefile(lDialogFile); - remove(lDialogFile); - if ( aoBuff[strlen( aoBuff ) -1] == '\n' ) - { - aoBuff[strlen( aoBuff ) -1] = '\0' ; - } - /* printf( "aoBuff: %s\n" , aoBuff ) ; */ - - /* printf( "aoBuff: %s len: %lu \n" , aoBuff , strlen(aoBuff) ) ; */ - lResult = strncmp( aoBuff , "1" , 1) ? 0 : 1 ; - /* printf( "lResult: %d \n" , lResult ) ; */ - if ( ! lResult ) - { - aoBuff[0] = '\0'; - return 0 ; - } - /* printf( "aoBuff+1: %s\n" , aoBuff+1 ) ; */ - strcpy(aoBuff, aoBuff+3); - return 1; -} - - -static char * saveFileDialogWinConsole( - char * aoBuff , - char const * aTitle , /* NULL or "" */ - char const * aDefaultPathAndFile ) /* NULL or "" */ -{ - char lDialogString[MAX_PATH_OR_CMD]; - char lPathAndFile[MAX_PATH_OR_CMD] = ""; - FILE * lIn; - - strcpy( lDialogString , "dialog " ) ; - if ( aTitle && strlen(aTitle) ) - { - strcat(lDialogString, "--title \"") ; - strcat(lDialogString, aTitle) ; - strcat(lDialogString, "\" ") ; - } - - strcat(lDialogString, "--backtitle \"") ; - strcat(lDialogString, - "tab: focus | /: populate | spacebar: fill text field | ok: TEXT FIELD ONLY") ; - strcat(lDialogString, "\" ") ; - - strcat( lDialogString , "--fselect \"" ) ; - if ( aDefaultPathAndFile && strlen(aDefaultPathAndFile) ) - { - /* dialog.exe uses unix separators even on windows */ - strcpy(lPathAndFile, aDefaultPathAndFile); - replaceChr( lPathAndFile , '\\' , '/' ) ; - } - - /* dialog.exe needs at least one separator */ - if ( ! strchr(lPathAndFile, '/') ) - { - strcat(lDialogString, "./") ; - } - strcat(lDialogString, lPathAndFile) ; - strcat(lDialogString, "\" 0 60 2>"); - strcpy(lPathAndFile, getenv("TEMP")); - strcat(lPathAndFile, "\\tinyfd.txt"); - strcat(lDialogString, lPathAndFile); - - /* printf( "lDialogString: %s\n" , lDialogString ) ; */ - system( lDialogString ) ; - - if (!(lIn = fopen(lPathAndFile, "r"))) - { - remove(lPathAndFile); - return NULL; - } - while (fgets(aoBuff, MAX_PATH_OR_CMD, lIn) != NULL) - {} - fclose(lIn); - remove(lPathAndFile); - replaceChr( aoBuff , '/' , '\\' ) ; - /* printf( "aoBuff: %s\n" , aoBuff ) ; */ - getLastName(lDialogString,aoBuff); - if ( ! strlen(lDialogString) ) - { - return NULL; - } - return aoBuff; -} - - -static char * openFileDialogWinConsole( - char const * aTitle , /* NULL or "" */ - char const * aDefaultPathAndFile ) /* NULL or "" */ -{ - char lFilterPatterns[MAX_PATH_OR_CMD] = ""; - char lDialogString[MAX_PATH_OR_CMD] ; - FILE * lIn; - - static char aoBuff[MAX_PATH_OR_CMD]; - - strcpy( lDialogString , "dialog " ) ; - if ( aTitle && strlen(aTitle) ) - { - strcat(lDialogString, "--title \"") ; - strcat(lDialogString, aTitle) ; - strcat(lDialogString, "\" ") ; - } - - strcat(lDialogString, "--backtitle \"") ; - strcat(lDialogString, - "tab: focus | /: populate | spacebar: fill text field | ok: TEXT FIELD ONLY") ; - strcat(lDialogString, "\" ") ; - - strcat( lDialogString , "--fselect \"" ) ; - if ( aDefaultPathAndFile && strlen(aDefaultPathAndFile) ) - { - /* dialog.exe uses unix separators even on windows */ - strcpy(lFilterPatterns, aDefaultPathAndFile); - replaceChr( lFilterPatterns , '\\' , '/' ) ; - } - - /* dialog.exe needs at least one separator */ - if ( ! strchr(lFilterPatterns, '/') ) - { - strcat(lDialogString, "./") ; - } - strcat(lDialogString, lFilterPatterns) ; - strcat(lDialogString, "\" 0 60 2>"); - strcpy(lFilterPatterns, getenv("TEMP")); - strcat(lFilterPatterns, "\\tinyfd.txt"); - strcat(lDialogString, lFilterPatterns); - - /* printf( "lDialogString: %s\n" , lDialogString ) ; */ - system( lDialogString ) ; - - if (!(lIn = fopen(lFilterPatterns, "r"))) - { - remove(lFilterPatterns); - return NULL; - } - while (fgets(aoBuff, MAX_PATH_OR_CMD, lIn) != NULL) - {} - fclose(lIn); - remove(lFilterPatterns); - replaceChr( aoBuff , '/' , '\\' ) ; - /* printf( "aoBuff: %s\n" , aoBuff ) ; */ - return aoBuff; -} - - -static char * selectFolderDialogWinConsole( - char * aoBuff , - char const * aTitle , /* NULL or "" */ - char const * aDefaultPath ) /* NULL or "" */ -{ - char lDialogString[MAX_PATH_OR_CMD] ; - char lString[MAX_PATH_OR_CMD] ; - FILE * lIn ; - - strcpy( lDialogString , "dialog " ) ; - if ( aTitle && strlen(aTitle) ) - { - strcat(lDialogString, "--title \"") ; - strcat(lDialogString, aTitle) ; - strcat(lDialogString, "\" ") ; - } - - strcat(lDialogString, "--backtitle \"") ; - strcat(lDialogString, - "tab: focus | /: populate | spacebar: fill text field | ok: TEXT FIELD ONLY") ; - strcat(lDialogString, "\" ") ; - - strcat( lDialogString , "--dselect \"" ) ; - if ( aDefaultPath && strlen(aDefaultPath) ) - { - /* dialog.exe uses unix separators even on windows */ - strcpy(lString, aDefaultPath) ; - ensureFinalSlash(lString); - replaceChr( lString , '\\' , '/' ) ; - strcat(lDialogString, lString) ; - } - else - { - /* dialog.exe needs at least one separator */ - strcat(lDialogString, "./") ; - } - strcat(lDialogString, "\" 0 60 2>"); - strcpy(lString, getenv("TEMP")); - strcat(lString, "\\tinyfd.txt"); - strcat(lDialogString, lString); - - /* printf( "lDialogString: %s\n" , lDialogString ) ; */ - system( lDialogString ) ; - - if (!(lIn = fopen(lString, "r"))) - { - remove(lString); - return NULL; - } - while (fgets(aoBuff, MAX_PATH_OR_CMD, lIn) != NULL) - {} - fclose(lIn); - remove(lString); - replaceChr( aoBuff , '/' , '\\' ) ; - /* printf( "aoBuff: %s\n" , aoBuff ) ; */ - return aoBuff; -} - -static void writeUtf8( char const * aUtf8String ) -{ - unsigned long lNum; - void * lConsoleHandle; - wchar_t * lTmpWChar; - - lConsoleHandle = GetStdHandle(STD_OUTPUT_HANDLE); - lTmpWChar = tinyfd_utf8to16(aUtf8String); - (void)WriteConsoleW(lConsoleHandle, lTmpWChar, (DWORD) wcslen(lTmpWChar), &lNum, NULL); -} - - -int tinyfd_messageBox( - char const * aTitle, /* NULL or "" */ - char const * aMessage, /* NULL or "" may contain \n and \t */ - char const * aDialogType, /* "ok" "okcancel" "yesno" "yesnocancel" */ - char const * aIconType, /* "info" "warning" "error" "question" */ - int aDefaultButton) /* 0 for cancel/no , 1 for ok/yes , 2 for no in yesnocancel */ -{ - char lChar; - UINT lOriginalCP = 0; - UINT lOriginalOutputCP = 0; - - if (tfd_quoteDetected(aTitle)) return tinyfd_messageBox("INVALID TITLE WITH QUOTES", aMessage, aDialogType, aIconType, aDefaultButton); - if (tfd_quoteDetected(aMessage)) return tinyfd_messageBox(aTitle, "INVALID MESSAGE WITH QUOTES", aDialogType, aIconType, aDefaultButton); - - if ((!tinyfd_forceConsole || !(GetConsoleWindow() || dialogPresent())) - && (!getenv("SSH_CLIENT") || getenvDISPLAY())) - { - if (aTitle&&!strcmp(aTitle, "tinyfd_query")){ strcpy(tinyfd_response, "windows"); return 1; } - return messageBoxWinGui(aTitle, aMessage, aDialogType, aIconType, aDefaultButton); - } - else if (dialogPresent()) - { - if (aTitle&&!strcmp(aTitle, "tinyfd_query")){ strcpy(tinyfd_response, "dialog"); return 0; } - return messageBoxWinConsole( - aTitle, aMessage, aDialogType, aIconType, aDefaultButton); - } - else - { - if (!tinyfd_winUtf8) - { - lOriginalCP = GetConsoleCP(); - lOriginalOutputCP = GetConsoleOutputCP(); - (void)SetConsoleCP(GetACP()); - (void)SetConsoleOutputCP(GetACP()); - } - - if (aTitle&&!strcmp(aTitle, "tinyfd_query")){ strcpy(tinyfd_response, "basicinput"); return 0; } - if (!gWarningDisplayed && !tinyfd_forceConsole) - { - gWarningDisplayed = 1; - printf("\n\n%s\n", gTitle); - printf("%s\n\n", tinyfd_needs); - } - - if (aTitle && strlen(aTitle)) - { - printf("\n"); - if (tinyfd_winUtf8) writeUtf8(aTitle); - else printf("%s", aTitle); - printf("\n\n"); - } - if (aDialogType && !strcmp("yesno", aDialogType)) - { - do - { - if (aMessage && strlen(aMessage)) - { - if (tinyfd_winUtf8) writeUtf8(aMessage); - else printf("%s", aMessage); - printf("\n"); - } - printf("y/n: "); - lChar = (char)tolower(_getch()); - printf("\n\n"); - } while (lChar != 'y' && lChar != 'n'); - if (!tinyfd_winUtf8) { (void)SetConsoleCP(lOriginalCP); (void)SetConsoleOutputCP(lOriginalOutputCP); } - return lChar == 'y' ? 1 : 0; - } - else if (aDialogType && !strcmp("okcancel", aDialogType)) - { - do - { - if (aMessage && strlen(aMessage)) - { - if (tinyfd_winUtf8) writeUtf8(aMessage); - else printf("%s", aMessage); - printf("\n"); - } - printf("[O]kay/[C]ancel: "); - lChar = (char)tolower(_getch()); - printf("\n\n"); - } while (lChar != 'o' && lChar != 'c'); - if (!tinyfd_winUtf8) { (void)SetConsoleCP(lOriginalCP); (void)SetConsoleOutputCP(lOriginalOutputCP); } - return lChar == 'o' ? 1 : 0; - } - else if (aDialogType && !strcmp("yesnocancel", aDialogType)) - { - do - { - if (aMessage && strlen(aMessage)) - { - if (tinyfd_winUtf8) writeUtf8(aMessage); - else printf("%s", aMessage); - printf("\n"); - } - printf("[Y]es/[N]o/[C]ancel: "); - lChar = (char)tolower(_getch()); - printf("\n\n"); - } while (lChar != 'y' && lChar != 'n' && lChar != 'c'); - if (!tinyfd_winUtf8) { (void)SetConsoleCP(lOriginalCP); (void)SetConsoleOutputCP(lOriginalOutputCP); } - return (lChar == 'y') ? 1 : (lChar == 'n') ? 2 : 0; - } - else - { - if (aMessage && strlen(aMessage)) - { - if (tinyfd_winUtf8) writeUtf8(aMessage); - else printf("%s", aMessage); - printf("\n\n"); - } - printf("press enter to continue "); - lChar = (char)_getch(); - printf("\n\n"); - if (!tinyfd_winUtf8) { (void)SetConsoleCP(lOriginalCP); (void)SetConsoleOutputCP(lOriginalOutputCP); } - return 1; - } - } -} - - -/* return has only meaning for tinyfd_query */ -int tinyfd_notifyPopup( - char const * aTitle, /* NULL or "" */ - char const * aMessage , /* NULL or "" may contain \n \t */ - char const * aIconType ) /* "info" "warning" "error" */ -{ - if (tfd_quoteDetected(aTitle)) return tinyfd_notifyPopup("INVALID TITLE WITH QUOTES", aMessage, aIconType); - if (tfd_quoteDetected(aMessage)) return tinyfd_notifyPopup(aTitle, "INVALID MESSAGE WITH QUOTES", aIconType); - - if ( powershellPresent() && (!tinyfd_forceConsole || !( - GetConsoleWindow() || - dialogPresent())) - && (!getenv("SSH_CLIENT") || getenvDISPLAY())) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"windows");return 1;} - return notifyWinGui(aTitle, aMessage, aIconType); - } - else - return tinyfd_messageBox(aTitle, aMessage, "ok" , aIconType, 0); -} - - -/* returns NULL on cancel */ -char * tinyfd_inputBox( - char const * aTitle , /* NULL or "" */ - char const * aMessage , /* NULL or "" (\n and \t have no effect) */ - char const * aDefaultInput ) /* "" , if NULL it's a passwordBox */ -{ - static char lBuff[MAX_PATH_OR_CMD] = ""; - char * lEOF; - - DWORD mode = 0; - HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE); - - unsigned long lNum; - void * lConsoleHandle; - char * lTmpChar; - wchar_t lBuffW[1024]; - - UINT lOriginalCP = 0; - UINT lOriginalOutputCP = 0; - - if (!aTitle && !aMessage && !aDefaultInput) return lBuff; /* now I can fill lBuff from outside */ - - if (tfd_quoteDetected(aTitle)) return tinyfd_inputBox("INVALID TITLE WITH QUOTES", aMessage, aDefaultInput); - if (tfd_quoteDetected(aMessage)) return tinyfd_inputBox(aTitle, "INVALID MESSAGE WITH QUOTES", aDefaultInput); - if (tfd_quoteDetected(aDefaultInput)) return tinyfd_inputBox(aTitle, aMessage, "INVALID DEFAULT_INPUT WITH QUOTES: use the GRAVE ACCENT \\x60 instead."); - - mode = 0; - hStdin = GetStdHandle(STD_INPUT_HANDLE); - - if ((!tinyfd_forceConsole || !( - GetConsoleWindow() || - dialogPresent())) - && (!getenv("SSH_CLIENT") || getenvDISPLAY())) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"windows");return (char *)1;} - lBuff[0]='\0'; - if (inputBoxWinGui(lBuff, aTitle, aMessage, aDefaultInput)) return lBuff; - else return NULL; - } - else if ( dialogPresent() ) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"dialog");return (char *)0;} - lBuff[0]='\0'; - if (inputBoxWinConsole(lBuff, aTitle, aMessage, aDefaultInput) ) return lBuff; - else return NULL; - } - else - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"basicinput");return (char *)0;} - lBuff[0]='\0'; - if (!gWarningDisplayed && !tinyfd_forceConsole) - { - gWarningDisplayed = 1 ; - printf("\n\n%s\n", gTitle); - printf("%s\n\n", tinyfd_needs); - } - - if (!tinyfd_winUtf8) - { - lOriginalCP = GetConsoleCP(); - lOriginalOutputCP = GetConsoleOutputCP(); - (void)SetConsoleCP(GetACP()); - (void)SetConsoleOutputCP(GetACP()); - } - - if (aTitle && strlen(aTitle)) - { - printf("\n"); - if (tinyfd_winUtf8) writeUtf8(aTitle); - else printf("%s", aTitle); - printf("\n\n"); - } - if ( aMessage && strlen(aMessage) ) - { - if (tinyfd_winUtf8) writeUtf8(aMessage); - else printf("%s", aMessage); - printf("\n"); - } - printf("(ctrl-Z + enter to cancel): "); - if ( ! aDefaultInput ) - { - (void) GetConsoleMode(hStdin, &mode); - (void) SetConsoleMode(hStdin, mode & (~ENABLE_ECHO_INPUT)); - } - if (tinyfd_winUtf8) - { - lConsoleHandle = GetStdHandle(STD_INPUT_HANDLE); - (void) ReadConsoleW(lConsoleHandle, lBuffW, MAX_PATH_OR_CMD, &lNum, NULL); - if (!aDefaultInput) - { - (void)SetConsoleMode(hStdin, mode); - printf("\n"); - } - lBuffW[lNum] = '\0'; - if (lBuffW[wcslen(lBuffW) - 1] == '\n') lBuffW[wcslen(lBuffW) - 1] = '\0'; - if (lBuffW[wcslen(lBuffW) - 1] == '\r') lBuffW[wcslen(lBuffW) - 1] = '\0'; - lTmpChar = tinyfd_utf16to8(lBuffW); - if (lTmpChar) - { - strcpy(lBuff, lTmpChar); - return lBuff; - } - else - return NULL; - } - else - { - lEOF = fgets(lBuff, MAX_PATH_OR_CMD, stdin); - if (!aDefaultInput) - { - (void)SetConsoleMode(hStdin, mode); - printf("\n"); - } - - if (!tinyfd_winUtf8) - { - (void)SetConsoleCP(lOriginalCP); - (void)SetConsoleOutputCP(lOriginalOutputCP); - } - - if (!lEOF) - { - return NULL; - } - printf("\n"); - if (strchr(lBuff, 27)) - { - return NULL; - } - if (lBuff[strlen(lBuff) - 1] == '\n') - { - lBuff[strlen(lBuff) - 1] = '\0'; - } - return lBuff; - } - } -} - - -char * tinyfd_saveFileDialog( - char const * aTitle , /* NULL or "" */ - char const * aDefaultPathAndFile , /* NULL or "" */ - int aNumOfFilterPatterns , /* 0 */ - char const * const * aFilterPatterns , /* NULL or {"*.jpg","*.png"} */ - char const * aSingleFilterDescription ) /* NULL or "image files" */ -{ - static char lBuff[MAX_PATH_OR_CMD] ; - char lString[MAX_PATH_OR_CMD] ; - char * p ; - char * lPointerInputBox; - int i; - - lBuff[0]='\0'; - - if ( ! aFilterPatterns ) aNumOfFilterPatterns = 0 ; - if (tfd_quoteDetected(aTitle)) return tinyfd_saveFileDialog("INVALID TITLE WITH QUOTES", aDefaultPathAndFile, aNumOfFilterPatterns, aFilterPatterns, aSingleFilterDescription); - if (tfd_quoteDetected(aDefaultPathAndFile)) return tinyfd_saveFileDialog(aTitle, "INVALID DEFAULT_PATH WITH QUOTES: use the GRAVE ACCENT \\x60 instead.", aNumOfFilterPatterns, aFilterPatterns, aSingleFilterDescription); - if (tfd_quoteDetected(aSingleFilterDescription)) return tinyfd_saveFileDialog(aTitle, aDefaultPathAndFile, aNumOfFilterPatterns, aFilterPatterns, "INVALID FILTER_DESCRIPTION WITH QUOTES: use the GRAVE ACCENT \\x60 instead."); - for (i = 0; i < aNumOfFilterPatterns; i++) - { - if (tfd_quoteDetected(aFilterPatterns[i])) return tinyfd_saveFileDialog("INVALID FILTER_PATTERN WITH QUOTES: use the GRAVE ACCENT \\x60 instead.", aDefaultPathAndFile, 0, NULL, NULL); - } - - - if ( ( !tinyfd_forceConsole || !( GetConsoleWindow() || dialogPresent() ) ) - && (!getenv("SSH_CLIENT") || getenvDISPLAY())) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"windows");return (char *)1;} - p = saveFileDialogWinGui(lBuff, - aTitle, aDefaultPathAndFile, aNumOfFilterPatterns, (char const * const *)aFilterPatterns, aSingleFilterDescription); - } - else if (dialogPresent()) - { - if (aTitle&&!strcmp(aTitle, "tinyfd_query")){ strcpy(tinyfd_response, "dialog"); return (char *)0; } - p = saveFileDialogWinConsole(lBuff, aTitle, aDefaultPathAndFile); - } - else - { - if (aTitle&&!strcmp(aTitle, "tinyfd_query")){ strcpy(tinyfd_response, "basicinput"); return (char *)0; } - strcpy(lBuff, "Save file in "); - strcat(lBuff, getCurDir()); - - lPointerInputBox = tinyfd_inputBox(NULL,NULL,NULL); /* obtain a pointer on the current content of tinyfd_inputBox */ - if (lPointerInputBox) strcpy(lString, lPointerInputBox); /* preserve the current content of tinyfd_inputBox */ - p = tinyfd_inputBox(aTitle, lBuff, ""); - if (p) strcpy(lBuff, p); else lBuff[0] = '\0'; - if (lPointerInputBox) strcpy(lPointerInputBox, lString); /* restore its previous content to tinyfd_inputBox */ - p = lBuff; - } - - if ( ! p || ! strlen( p ) ) - { - return NULL; - } - getPathWithoutFinalSlash( lString , p ) ; - if ( strlen( lString ) && ! dirExists( lString ) ) - { - return NULL ; - } - getLastName(lString,p); - if ( ! filenameValid(lString) ) - { - return NULL; - } - return p ; -} - - -/* in case of multiple files, the separator is | */ -char * tinyfd_openFileDialog( - char const * aTitle , /* NULL or "" */ - char const * aDefaultPathAndFile, /* NULL or "" */ - int aNumOfFilterPatterns , /* 0 */ - char const * const * aFilterPatterns, /* NULL or {"*.jpg","*.png"} */ - char const * aSingleFilterDescription, /* NULL or "image files" */ - int aAllowMultipleSelects ) /* 0 or 1 */ -{ - static char lBuff[MAX_PATH_OR_CMD]; - char lString[MAX_PATH_OR_CMD]; - char * p; - char * lPointerInputBox; - int i; - - if ( ! aFilterPatterns ) aNumOfFilterPatterns = 0 ; - if (tfd_quoteDetected(aTitle)) return tinyfd_openFileDialog("INVALID TITLE WITH QUOTES", aDefaultPathAndFile, aNumOfFilterPatterns, aFilterPatterns, aSingleFilterDescription, aAllowMultipleSelects); - if (tfd_quoteDetected(aDefaultPathAndFile)) return tinyfd_openFileDialog(aTitle, "INVALID DEFAULT_PATH WITH QUOTES: use the GRAVE ACCENT \\x60 instead.", aNumOfFilterPatterns, aFilterPatterns, aSingleFilterDescription, aAllowMultipleSelects); - if (tfd_quoteDetected(aSingleFilterDescription)) return tinyfd_openFileDialog(aTitle, aDefaultPathAndFile, aNumOfFilterPatterns, aFilterPatterns, "INVALID FILTER_DESCRIPTION WITH QUOTES: use the GRAVE ACCENT \\x60 instead.", aAllowMultipleSelects); - for (i = 0; i < aNumOfFilterPatterns; i++) - { - if (tfd_quoteDetected(aFilterPatterns[i])) return tinyfd_openFileDialog("INVALID FILTER_PATTERN WITH QUOTES: use the GRAVE ACCENT \\x60 instead.", aDefaultPathAndFile, 0, NULL, NULL, aAllowMultipleSelects); - } - - if ( ( !tinyfd_forceConsole || !( GetConsoleWindow() || dialogPresent() ) ) - && (!getenv("SSH_CLIENT") || getenvDISPLAY())) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"windows");return (char *)1;} - p = openFileDialogWinGui( aTitle, aDefaultPathAndFile, aNumOfFilterPatterns, - (char const * const *)aFilterPatterns, aSingleFilterDescription, aAllowMultipleSelects); - } - else if (dialogPresent()) - { - if (aTitle&&!strcmp(aTitle, "tinyfd_query")){ strcpy(tinyfd_response, "dialog"); return (char *)0; } - p = openFileDialogWinConsole(aTitle, aDefaultPathAndFile); - } - else - { - if (aTitle&&!strcmp(aTitle, "tinyfd_query")){ strcpy(tinyfd_response, "basicinput"); return (char *)0; } - strcpy(lBuff, "Open file from "); - strcat(lBuff, getCurDir()); - lPointerInputBox = tinyfd_inputBox(NULL, NULL, NULL); /* obtain a pointer on the current content of tinyfd_inputBox */ - if (lPointerInputBox) strcpy(lString, lPointerInputBox); /* preserve the current content of tinyfd_inputBox */ - p = tinyfd_inputBox(aTitle, lBuff, ""); - if (p) strcpy(lBuff, p); else lBuff[0] = '\0'; - if (lPointerInputBox) strcpy(lPointerInputBox, lString); /* restore its previous content to tinyfd_inputBox */ - p = lBuff; - } - - if ( ! p || ! strlen( p ) ) - { - return NULL; - } - if ( aAllowMultipleSelects && strchr(p, '|') ) - { - p = ensureFilesExist( (char *) p , p ) ; - } - else if ( ! fileExists(p) ) - { - return NULL ; - } - /* printf( "lBuff3: %s\n" , p ) ; */ - return p ; -} - - -char * tinyfd_selectFolderDialog( - char const * aTitle , /* NULL or "" */ - char const * aDefaultPath ) /* NULL or "" */ -{ - static char lBuff[MAX_PATH_OR_CMD]; - char * p; - char * lPointerInputBox; - char lString[MAX_PATH_OR_CMD]; - - if (tfd_quoteDetected(aTitle)) return tinyfd_selectFolderDialog("INVALID TITLE WITH QUOTES", aDefaultPath); - if (tfd_quoteDetected(aDefaultPath)) return tinyfd_selectFolderDialog(aTitle, "INVALID DEFAULT_PATH WITH QUOTES: use the GRAVE ACCENT \\x60 instead."); - - if ( ( !tinyfd_forceConsole || !( GetConsoleWindow() || dialogPresent() ) ) - && (!getenv("SSH_CLIENT") || getenvDISPLAY())) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"windows");return (char *)1;} - p = selectFolderDialogWinGui(lBuff, aTitle, aDefaultPath); - } - else - if (dialogPresent()) - { - if (aTitle&&!strcmp(aTitle, "tinyfd_query")){ strcpy(tinyfd_response, "dialog"); return (char *)0; } - p = selectFolderDialogWinConsole(lBuff, aTitle, aDefaultPath); - } - else - { - if (aTitle&&!strcmp(aTitle, "tinyfd_query")){ strcpy(tinyfd_response, "basicinput"); return (char *)0; } - strcpy(lBuff, "Select folder from "); - strcat(lBuff, getCurDir()); - lPointerInputBox = tinyfd_inputBox(NULL, NULL, NULL); /* obtain a pointer on the current content of tinyfd_inputBox */ - if (lPointerInputBox) strcpy(lString, lPointerInputBox); /* preserve the current content of tinyfd_inputBox */ - p = tinyfd_inputBox(aTitle, lBuff, ""); - if (p) strcpy(lBuff, p); else lBuff[0] = '\0'; - if (lPointerInputBox) strcpy(lPointerInputBox, lString); /* restore its previous content to tinyfd_inputBox */ - p = lBuff; - } - - if ( ! p || ! strlen( p ) || ! dirExists( p ) ) - { - return NULL ; - } - return p ; -} - - -/* aDefaultRGB is used only if aDefaultHexRGB is absent */ -/* aDefaultRGB and aoResultRGB can be the same array */ -/* returns NULL on cancel */ -/* returns the hexcolor as a string "#FF0000" */ -/* aoResultRGB also contains the result */ -char * tinyfd_colorChooser( - char const * aTitle, /* NULL or "" */ - char const * aDefaultHexRGB, /* NULL or "" or "#FF0000"*/ - unsigned char const aDefaultRGB[3], /* { 0 , 255 , 255 } */ - unsigned char aoResultRGB[3]) /* { 0 , 0 , 0 } */ -{ - static char lDefaultHexRGB[16]; - int i; - char * p ; - char * lPointerInputBox; - char lString[MAX_PATH_OR_CMD]; - - lDefaultHexRGB[0] = '\0'; - - if (tfd_quoteDetected(aTitle)) return tinyfd_colorChooser("INVALID TITLE WITH QUOTES", aDefaultHexRGB, aDefaultRGB, aoResultRGB); - if (tfd_quoteDetected(aDefaultHexRGB)) return tinyfd_colorChooser(aTitle, "INVALID DEFAULT_HEX_RGB WITH QUOTES: use the GRAVE ACCENT \\x60 instead.", aDefaultRGB, aoResultRGB); - - if ( (!tinyfd_forceConsole || !( GetConsoleWindow() || dialogPresent()) ) - && (!getenv("SSH_CLIENT") || getenvDISPLAY())) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"windows");return (char *)1;} - p = colorChooserWinGui(aTitle, aDefaultHexRGB, aDefaultRGB, aoResultRGB); - if (p) - { - strcpy(lDefaultHexRGB, p); - return lDefaultHexRGB; - } - return NULL; - } - else if (dialogPresent()) - { - if (aTitle&&!strcmp(aTitle, "tinyfd_query")){ strcpy(tinyfd_response, "dialog"); return (char *)0; } - } - else - { - if (aTitle&&!strcmp(aTitle, "tinyfd_query")){ strcpy(tinyfd_response, "basicinput"); return (char *)0; } - } - - if (aDefaultHexRGB && (strlen(aDefaultHexRGB)==7) ) - { - strncpy(lDefaultHexRGB, aDefaultHexRGB,7); - lDefaultHexRGB[7]='\0'; - } - else - { - RGB2Hex(aDefaultRGB, lDefaultHexRGB); - } - - lPointerInputBox = tinyfd_inputBox(NULL, NULL, NULL); /* obtain a pointer on the current content of tinyfd_inputBox */ - if (lPointerInputBox) strcpy(lString, lPointerInputBox); /* preserve the current content of tinyfd_inputBox */ - p = tinyfd_inputBox(aTitle, "Enter hex rgb color (i.e. #f5ca20)", lDefaultHexRGB); - - if ( !p || (strlen(p) != 7) || (p[0] != '#') ) - { - return NULL ; - } - for ( i = 1 ; i < 7 ; i ++ ) - { - if ( ! isxdigit( (int) p[i] ) ) - { - return NULL ; - } - } - Hex2RGB(p,aoResultRGB); - - strcpy(lDefaultHexRGB, p); - - if (lPointerInputBox) strcpy(lPointerInputBox, lString); /* restore its previous content to tinyfd_inputBox */ - - return lDefaultHexRGB; -} - - -#else /* unix */ - -static char gPython2Name[16]; -static char gPython3Name[16]; -static char gPythonName[16]; - -int tfd_isDarwin(void) -{ - static int lsIsDarwin = -1 ; - struct utsname lUtsname ; - if ( lsIsDarwin < 0 ) - { - lsIsDarwin = !uname(&lUtsname) && !strcmp(lUtsname.sysname,"Darwin") ; - } - return lsIsDarwin ; -} - - -static int dirExists( char const * aDirPath ) -{ - DIR * lDir ; - if ( ! aDirPath || ! strlen( aDirPath ) ) - return 0 ; - lDir = opendir( aDirPath ) ; - if ( ! lDir ) - { - return 0 ; - } - closedir( lDir ) ; - return 1 ; -} - - -static int detectPresence( char const * aExecutable ) -{ - char lBuff[MAX_PATH_OR_CMD] ; - char lTestedString[MAX_PATH_OR_CMD] = "command -v " ; - FILE * lIn ; -#ifdef _GNU_SOURCE - char* lAllocatedCharString; - int lSubstringUndetected; -#endif - - strcat( lTestedString , aExecutable ) ; - strcat( lTestedString, " 2>/dev/null "); - lIn = popen( lTestedString , "r" ) ; - if ( ( fgets( lBuff , sizeof( lBuff ) , lIn ) != NULL ) - && ( ! strchr( lBuff , ':' ) ) && ( strncmp(lBuff, "no ", 3) ) ) - { /* present */ - pclose( lIn ) ; - -#ifdef _GNU_SOURCE /*to bypass this, just comment out "#define _GNU_SOURCE" at the top of the file*/ - if ( lBuff[strlen( lBuff ) -1] == '\n' ) lBuff[strlen( lBuff ) -1] = '\0' ; - lAllocatedCharString = realpath(lBuff,NULL); /*same as canonicalize_file_name*/ - lSubstringUndetected = ! strstr(lAllocatedCharString, aExecutable); - free(lAllocatedCharString); - if (lSubstringUndetected) - { - if (tinyfd_verbose) printf("detectPresence %s %d\n", aExecutable, 0); - return 0; - } -#endif /*_GNU_SOURCE*/ - - if (tinyfd_verbose) printf("detectPresence %s %d\n", aExecutable, 1); - return 1 ; - } - else - { - pclose( lIn ) ; - if (tinyfd_verbose) printf("detectPresence %s %d\n", aExecutable, 0); - return 0 ; - } -} - - -static char * getVersion( char const * aExecutable ) /*version must be first numeral*/ -{ - static char lBuff[MAX_PATH_OR_CMD] ; - char lTestedString[MAX_PATH_OR_CMD] ; - FILE * lIn ; - char * lTmp ; - - strcpy( lTestedString , aExecutable ) ; - strcat( lTestedString , " --version" ) ; - - lIn = popen( lTestedString , "r" ) ; - lTmp = fgets( lBuff , sizeof( lBuff ) , lIn ) ; - pclose( lIn ) ; - - lTmp += strcspn(lTmp,"0123456789"); - /* printf("lTmp:%s\n", lTmp); */ - return lTmp ; -} - - -static int * getMajorMinorPatch( char const * aExecutable ) -{ - static int lArray[3] ; - char * lTmp ; - - lTmp = (char *) getVersion(aExecutable); - lArray[0] = atoi( strtok(lTmp," ,.-") ) ; - /* printf("lArray0 %d\n", lArray[0]); */ - lArray[1] = atoi( strtok(0," ,.-") ) ; - /* printf("lArray1 %d\n", lArray[1]); */ - lArray[2] = atoi( strtok(0," ,.-") ) ; - /* printf("lArray2 %d\n", lArray[2]); */ - - if ( !lArray[0] && !lArray[1] && !lArray[2] ) return NULL; - return lArray ; -} - - -static int tryCommand( char const * aCommand ) -{ - char lBuff[MAX_PATH_OR_CMD] ; - FILE * lIn ; - - lIn = popen( aCommand , "r" ) ; - if ( fgets( lBuff , sizeof( lBuff ) , lIn ) == NULL ) - { /* present */ - pclose( lIn ) ; - return 1 ; - } - else - { - pclose( lIn ) ; - return 0 ; - } - -} - - -static int isTerminalRunning(void) -{ - static int lIsTerminalRunning = -1 ; - if ( lIsTerminalRunning < 0 ) - { - lIsTerminalRunning = isatty(1); - if (tinyfd_verbose) printf("isTerminalRunning %d\n", lIsTerminalRunning ); - } - return lIsTerminalRunning; -} - - -static char * dialogNameOnly(void) -{ - static char lDialogName[128] = "*" ; - if ( lDialogName[0] == '*' ) - { - if (!tinyfd_allowCursesDialogs) - { - strcpy(lDialogName , "" ); - } - else if ( tfd_isDarwin() && * strcpy(lDialogName , "/opt/local/bin/dialog" ) - && detectPresence( lDialogName ) ) - {} - else if ( * strcpy(lDialogName , "dialog" ) - && detectPresence( lDialogName ) ) - {} - else - { - strcpy(lDialogName , "" ); - } - } - return lDialogName ; -} - - -int isDialogVersionBetter09b(void) -{ - char const * lDialogName ; - char * lVersion ; - int lMajor ; - int lMinor ; - int lDate ; - int lResult ; - char * lMinorP ; - char * lLetter ; - char lBuff[128] ; - - /*char lTest[128] = " 0.9b-20031126" ;*/ - - lDialogName = dialogNameOnly() ; - if ( ! strlen(lDialogName) || !(lVersion = (char *) getVersion(lDialogName)) ) return 0 ; - /*lVersion = lTest ;*/ - /*printf("lVersion %s\n", lVersion);*/ - strcpy(lBuff,lVersion); - lMajor = atoi( strtok(lVersion," ,.-") ) ; - /*printf("lMajor %d\n", lMajor);*/ - lMinorP = strtok(0," ,.-abcdefghijklmnopqrstuvxyz"); - lMinor = atoi( lMinorP ) ; - /*printf("lMinor %d\n", lMinor );*/ - lDate = atoi( strtok(0," ,.-") ) ; - if (lDate<0) lDate = - lDate; - /*printf("lDate %d\n", lDate);*/ - lLetter = lMinorP + strlen(lMinorP) ; - strcpy(lVersion,lBuff); - strtok(lLetter," ,.-"); - /*printf("lLetter %s\n", lLetter);*/ - lResult = (lMajor > 0) || ( ( lMinor == 9 ) && (*lLetter == 'b') && (lDate >= 20031126) ); - /*printf("lResult %d\n", lResult);*/ - return lResult; -} - - -static int whiptailPresentOnly(void) -{ - static int lWhiptailPresent = -1 ; - if (!tinyfd_allowCursesDialogs) return 0; - if ( lWhiptailPresent < 0 ) - { - lWhiptailPresent = detectPresence( "whiptail" ) ; - } - return lWhiptailPresent ; -} - - -static char * terminalName(void) -{ - static char lTerminalName[128] = "*" ; - char lShellName[64] = "*" ; - int * lArray; - - if ( lTerminalName[0] == '*' ) - { - if ( detectPresence( "bash" ) ) - { - strcpy(lShellName , "bash -c " ) ; /*good for basic input*/ - } - else if ( strlen(dialogNameOnly()) || whiptailPresentOnly() ) - { - strcpy(lShellName , "sh -c " ) ; /*good enough for dialog & whiptail*/ - } - else - { - strcpy(lTerminalName , "" ) ; - return NULL ; - } - - if ( tfd_isDarwin() ) - { - if ( * strcpy(lTerminalName , "/opt/X11/bin/xterm" ) - && detectPresence( lTerminalName ) ) - { - strcat(lTerminalName , " -fa 'DejaVu Sans Mono' -fs 10 -title tinyfiledialogs -e " ) ; - strcat(lTerminalName , lShellName ) ; - } - else - { - strcpy(lTerminalName , "" ) ; - } - } - else if ( * strcpy(lTerminalName,"xterm") /*good (small without parameters)*/ - && detectPresence(lTerminalName) ) - { - strcat(lTerminalName , " -fa 'DejaVu Sans Mono' -fs 10 -title tinyfiledialogs -e " ) ; - strcat(lTerminalName , lShellName ) ; - } - else if ( * strcpy(lTerminalName,"terminator") /*good*/ - && detectPresence(lTerminalName) ) - { - strcat(lTerminalName , " -x " ) ; - strcat(lTerminalName , lShellName ) ; - } - else if ( * strcpy(lTerminalName,"lxterminal") /*good*/ - && detectPresence(lTerminalName) ) - { - strcat(lTerminalName , " -e " ) ; - strcat(lTerminalName , lShellName ) ; - } - else if ( * strcpy(lTerminalName,"konsole") /*good*/ - && detectPresence(lTerminalName) ) - { - strcat(lTerminalName , " -e " ) ; - strcat(lTerminalName , lShellName ) ; - } - else if ( * strcpy(lTerminalName,"kterm") /*good*/ - && detectPresence(lTerminalName) ) - { - strcat(lTerminalName , " -e " ) ; - strcat(lTerminalName , lShellName ) ; - } - else if ( * strcpy(lTerminalName,"tilix") /*good*/ - && detectPresence(lTerminalName) ) - { - strcat(lTerminalName , " -e " ) ; - strcat(lTerminalName , lShellName ) ; - } - else if ( * strcpy(lTerminalName,"xfce4-terminal") /*good*/ - && detectPresence(lTerminalName) ) - { - strcat(lTerminalName , " -x " ) ; - strcat(lTerminalName , lShellName ) ; - } - else if ( * strcpy(lTerminalName,"mate-terminal") /*good*/ - && detectPresence(lTerminalName) ) - { - strcat(lTerminalName , " -x " ) ; - strcat(lTerminalName , lShellName ) ; - } - else if ( * strcpy(lTerminalName,"Eterm") /*good*/ - && detectPresence(lTerminalName) ) - { - strcat(lTerminalName , " -e " ) ; - strcat(lTerminalName , lShellName ) ; - } - else if ( * strcpy(lTerminalName,"evilvte") /*good*/ - && detectPresence(lTerminalName) ) - { - strcat(lTerminalName , " -e " ) ; - strcat(lTerminalName , lShellName ) ; - } - else if ( * strcpy(lTerminalName,"pterm") /*good (only letters)*/ - && detectPresence(lTerminalName) ) - { - strcat(lTerminalName , " -e " ) ; - strcat(lTerminalName , lShellName ) ; - } - else if ( * strcpy(lTerminalName,"gnome-terminal") - && detectPresence(lTerminalName) && (lArray = getMajorMinorPatch(lTerminalName)) - && ((lArray[0]<3) || (lArray[0]==3 && lArray[1]<=6)) ) - { - strcat(lTerminalName , " --disable-factory -x " ) ; - strcat(lTerminalName , lShellName ) ; - } - else - { - strcpy(lTerminalName , "" ) ; - } - /* bad: koi rxterm guake tilda vala-terminal qterminal kgx - aterm Terminal terminology sakura lilyterm weston-terminal - roxterm termit xvt rxvt mrxvt urxvt */ - } - if ( strlen(lTerminalName) ) - { - return lTerminalName ; - } - else - { - return NULL ; - } -} - - -static char * dialogName(void) -{ - char * lDialogName ; - lDialogName = dialogNameOnly( ) ; - if ( strlen(lDialogName) && ( isTerminalRunning() || terminalName() ) ) - { - return lDialogName ; - } - else - { - return NULL ; - } -} - - -static int whiptailPresent(void) -{ - int lWhiptailPresent ; - lWhiptailPresent = whiptailPresentOnly( ) ; - if ( lWhiptailPresent && ( isTerminalRunning() || terminalName() ) ) - { - return lWhiptailPresent ; - } - else - { - return 0 ; - } -} - - - -static int graphicMode(void) -{ - return !( tinyfd_forceConsole && (isTerminalRunning() || terminalName()) ) - && ( getenvDISPLAY() - || (tfd_isDarwin() && (!getenv("SSH_TTY") || getenvDISPLAY() ) ) ) ; -} - - -static int pactlPresent(void) -{ - static int lPactlPresent = -1 ; - if ( lPactlPresent < 0 ) - { - lPactlPresent = detectPresence("pactl") ; - } - return lPactlPresent ; -} - - -static int speakertestPresent(void) -{ - static int lSpeakertestPresent = -1 ; - if ( lSpeakertestPresent < 0 ) - { - lSpeakertestPresent = detectPresence("speaker-test") ; - } - return lSpeakertestPresent ; -} - - -static int playPresent() -{ - static int lPlayPresent = -1; - if (lPlayPresent < 0) - { - lPlayPresent = detectPresence("sox"); /*if sox is present, play is ready*/ - } - return lPlayPresent; -} - - -static int beepexePresent() -{ - static int lBeepexePresent = -1; - if (lBeepexePresent < 0) - { - lBeepexePresent = detectPresence("beep.exe"); - } - return lBeepexePresent; -} - - -static int beepPresent(void) -{ - static int lBeepPresent = -1 ; - if ( lBeepPresent < 0 ) - { - lBeepPresent = detectPresence("beep") ; - } - return lBeepPresent ; -} - - -static int xmessagePresent(void) -{ - static int lXmessagePresent = -1 ; - if ( lXmessagePresent < 0 ) - { - lXmessagePresent = detectPresence("xmessage");/*if not tty,not on osxpath*/ - } - return lXmessagePresent && graphicMode( ) ; -} - - -static int gxmessagePresent(void) -{ - static int lGxmessagePresent = -1 ; - if ( lGxmessagePresent < 0 ) - { - lGxmessagePresent = detectPresence("gxmessage") ; - } - return lGxmessagePresent && graphicMode( ) ; -} - - -static int gmessagePresent(void) -{ - static int lGmessagePresent = -1 ; - if ( lGmessagePresent < 0 ) - { - lGmessagePresent = detectPresence("gmessage") ; - } - return lGmessagePresent && graphicMode( ) ; -} - - -static int notifysendPresent(void) -{ - static int lNotifysendPresent = -1 ; - if ( lNotifysendPresent < 0 ) - { - lNotifysendPresent = detectPresence("notify-send") ; - } - return lNotifysendPresent && graphicMode( ) ; -} - - -static int perlPresent(void) -{ - static int lPerlPresent = -1 ; - char lBuff[MAX_PATH_OR_CMD] ; - FILE * lIn ; - - if ( lPerlPresent < 0 ) - { - lPerlPresent = detectPresence("perl") ; - if (lPerlPresent) - { - lIn = popen("perl -MNet::DBus -e \"Net::DBus->session->get_service('org.freedesktop.Notifications')\" 2>&1", "r"); - if (fgets(lBuff, sizeof(lBuff), lIn) == NULL) - { - lPerlPresent = 2; - } - pclose(lIn); - if (tinyfd_verbose) printf("perl-dbus %d\n", lPerlPresent); - } - } - return graphicMode() ? lPerlPresent : 0 ; -} - - -static int afplayPresent(void) -{ - static int lAfplayPresent = -1 ; - char lBuff[MAX_PATH_OR_CMD] ; - FILE * lIn ; - - if ( lAfplayPresent < 0 ) - { - lAfplayPresent = detectPresence("afplay") ; - if ( lAfplayPresent ) - { - lIn = popen( "test -e /System/Library/Sounds/Ping.aiff || echo Ping" , "r" ) ; - if ( fgets( lBuff , sizeof( lBuff ) , lIn ) == NULL ) - { - lAfplayPresent = 2 ; - } - pclose( lIn ) ; - if (tinyfd_verbose) printf("afplay %d\n", lAfplayPresent); - } - } - return graphicMode() ? lAfplayPresent : 0 ; -} - - -static int xdialogPresent(void) -{ - static int lXdialogPresent = -1 ; - if ( lXdialogPresent < 0 ) - { - lXdialogPresent = detectPresence("Xdialog") ; - } - return lXdialogPresent && graphicMode( ) ; -} - - -static int gdialogPresent(void) -{ - static int lGdialoglPresent = -1 ; - if ( lGdialoglPresent < 0 ) - { - lGdialoglPresent = detectPresence( "gdialog" ) ; - } - return lGdialoglPresent && graphicMode( ) ; -} - - -static int osascriptPresent(void) -{ - static int lOsascriptPresent = -1 ; - if ( lOsascriptPresent < 0 ) - { - gWarningDisplayed |= !!getenv("SSH_TTY"); - lOsascriptPresent = detectPresence( "osascript" ) ; - } - return lOsascriptPresent && graphicMode() && !getenv("SSH_TTY") ; -} - - -static int dunstifyPresent(void) -{ - static int lDunstifyPresent = -1 ; - static char lBuff[MAX_PATH_OR_CMD] ; - FILE * lIn ; - char * lTmp ; - - if ( lDunstifyPresent < 0 ) - { - lDunstifyPresent = detectPresence( "dunstify" ) ; - if ( lDunstifyPresent ) - { - lIn = popen( "dunstify -s" , "r" ) ; - lTmp = fgets( lBuff , sizeof( lBuff ) , lIn ) ; - pclose( lIn ) ; - /* printf("lTmp:%s\n", lTmp); */ - lDunstifyPresent = strstr(lTmp,"name:dunst\n") ? 1 : 0 ; - if (tinyfd_verbose) printf("lDunstifyPresent %d\n", lDunstifyPresent); - } - } - return lDunstifyPresent && graphicMode( ) ; -} - - -static int dunstPresent(void) -{ - static int lDunstPresent = -1 ; - static char lBuff[MAX_PATH_OR_CMD] ; - FILE * lIn ; - char * lTmp ; - - if ( lDunstPresent < 0 ) - { - lDunstPresent = detectPresence( "dunst" ) ; - if ( lDunstPresent ) - { - lIn = popen( "ps -e | grep dunst | grep -v grep" , "r" ) ; /* add "| wc -l" to receive the number of lines */ - lTmp = fgets( lBuff , sizeof( lBuff ) , lIn ) ; - pclose( lIn ) ; - /* if ( lTmp ) printf("lTmp:%s\n", lTmp); */ - if ( lTmp ) lDunstPresent = 1 ; - else lDunstPresent = 0 ; - if (tinyfd_verbose) printf("lDunstPresent %d\n", lDunstPresent); - } - } - return lDunstPresent && graphicMode( ) ; -} - - -int tfd_qarmaPresent(void) -{ - static int lQarmaPresent = -1 ; - if ( lQarmaPresent < 0 ) - { - lQarmaPresent = detectPresence("qarma") ; - } - return lQarmaPresent && graphicMode( ) ; -} - - -int tfd_matedialogPresent(void) -{ - static int lMatedialogPresent = -1 ; - if ( lMatedialogPresent < 0 ) - { - lMatedialogPresent = detectPresence("matedialog") ; - } - return lMatedialogPresent && graphicMode( ) ; -} - - -int tfd_shellementaryPresent(void) -{ - static int lShellementaryPresent = -1 ; - if ( lShellementaryPresent < 0 ) - { - lShellementaryPresent = 0 ; /*detectPresence("shellementary"); shellementary is not ready yet */ - } - return lShellementaryPresent && graphicMode( ) ; -} - - -int tfd_xpropPresent(void) -{ - static int lXpropPresent = -1 ; - if ( lXpropPresent < 0 ) - { - lXpropPresent = detectPresence("xprop") ; - } - return lXpropPresent && graphicMode( ) ; -} - - -int tfd_zenityPresent(void) -{ - static int lZenityPresent = -1 ; - if ( lZenityPresent < 0 ) - { - lZenityPresent = detectPresence("zenity") ; - } - return lZenityPresent && graphicMode( ) ; -} - - -int tfd_yadPresent(void) -{ - static int lYadPresent = -1; - if (lYadPresent < 0) - { - lYadPresent = detectPresence("yad"); - } - return lYadPresent && graphicMode(); -} - - -int tfd_zenity3Present(void) -{ - static int lZenity3Present = -1 ; - char lBuff[MAX_PATH_OR_CMD] ; - FILE * lIn ; - int lIntTmp ; - - if ( lZenity3Present < 0 ) - { - lZenity3Present = 0 ; - if ( tfd_zenityPresent() ) - { - lIn = popen( "zenity --version" , "r" ) ; - if ( fgets( lBuff , sizeof( lBuff ) , lIn ) != NULL ) - { - if ( atoi(lBuff) >= 3 ) - { - lZenity3Present = 3 ; - lIntTmp = atoi(strtok(lBuff,".")+2 ) ; - if ( lIntTmp >= 18 ) - { - lZenity3Present = 5 ; - } - else if ( lIntTmp >= 10 ) - { - lZenity3Present = 4 ; - } - } - else if ( ( atoi(lBuff) == 2 ) && ( atoi(strtok(lBuff,".")+2 ) >= 32 ) ) - { - lZenity3Present = 2 ; - } - if (tinyfd_verbose) printf("zenity type %d\n", lZenity3Present); - } - pclose( lIn ) ; - } - } - return graphicMode() ? lZenity3Present : 0 ; -} - - -int tfd_kdialogPresent(void) -{ - static int lKdialogPresent = -1 ; - char lBuff[MAX_PATH_OR_CMD] ; - FILE * lIn ; - char * lDesktop; - - if ( lKdialogPresent < 0 ) - { - if ( tfd_zenityPresent() ) - { - lDesktop = getenv("XDG_SESSION_DESKTOP"); - if ( !lDesktop || ( strcmp(lDesktop, "KDE") && strcmp(lDesktop, "lxqt") ) ) - { - lKdialogPresent = 0 ; - return lKdialogPresent ; - } - } - - lKdialogPresent = detectPresence("kdialog") ; - if ( lKdialogPresent && !getenv("SSH_TTY") ) - { - lIn = popen( "kdialog --attach 2>&1" , "r" ) ; - if ( fgets( lBuff , sizeof( lBuff ) , lIn ) != NULL ) - { - if ( ! strstr( "Unknown" , lBuff ) ) - { - lKdialogPresent = 2 ; - if (tinyfd_verbose) printf("kdialog-attach %d\n", lKdialogPresent); - } - } - pclose( lIn ) ; - - if (lKdialogPresent == 2) - { - lKdialogPresent = 1 ; - lIn = popen( "kdialog --passivepopup 2>&1" , "r" ) ; - if ( fgets( lBuff , sizeof( lBuff ) , lIn ) != NULL ) - { - if ( ! strstr( "Unknown" , lBuff ) ) - { - lKdialogPresent = 2 ; - if (tinyfd_verbose) printf("kdialog-popup %d\n", lKdialogPresent); - } - } - pclose( lIn ) ; - } - } - } - return graphicMode() ? lKdialogPresent : 0 ; -} - - -static int osx9orBetter(void) -{ - static int lOsx9orBetter = -1 ; - char lBuff[MAX_PATH_OR_CMD] ; - FILE * lIn ; - int V,v; - - if ( lOsx9orBetter < 0 ) - { - lOsx9orBetter = 0 ; - lIn = popen( "osascript -e 'set osver to system version of (system info)'" , "r" ) ; - V = 0 ; - if ( ( fgets( lBuff , sizeof( lBuff ) , lIn ) != NULL ) - && ( 2 == sscanf(lBuff, "%d.%d", &V, &v) ) ) - { - V = V * 100 + v; - if ( V >= 1009 ) - { - lOsx9orBetter = 1 ; - } - } - pclose( lIn ) ; - if (tinyfd_verbose) printf("Osx10 = %d, %d = %s\n", lOsx9orBetter, V, lBuff) ; - } - return lOsx9orBetter ; -} - - -static int python3Present(void) -{ - static int lPython3Present = -1 ; - int i; - - if ( lPython3Present < 0 ) - { - lPython3Present = 0 ; - strcpy(gPython3Name , "python3" ) ; - if ( detectPresence(gPython3Name) ) lPython3Present = 1; - /*else - { - for ( i = 9 ; i >= 0 ; i -- ) - { - sprintf( gPython3Name , "python3.%d" , i ) ; - if ( detectPresence(gPython3Name) ) - { - lPython3Present = 1; - break; - } - } - }*/ - if (tinyfd_verbose) printf("lPython3Present %d\n", lPython3Present) ; - if (tinyfd_verbose) printf("gPython3Name %s\n", gPython3Name) ; - } - return lPython3Present ; -} - - -static int python2Present(void) -{ - static int lPython2Present = -1 ; - - if ( lPython2Present < 0 ) - { - lPython2Present = 0 ; - strcpy(gPython2Name , "python2" ) ; - if ( detectPresence(gPython2Name) ) lPython2Present = 1; - /*else - { - for ( i = 9 ; i >= 0 ; i -- ) - { - sprintf( gPython2Name , "python2.%d" , i ) ; - if ( detectPresence(gPython2Name) ) - { - lPython2Present = 1; - break; - } - } - }*/ - if (tinyfd_verbose) printf("lPython2Present %d\n", lPython2Present) ; - if (tinyfd_verbose) printf("gPython2Name %s\n", gPython2Name) ; - } - return lPython2Present ; -} - - -static int tkinter3Present(void) -{ - static int lTkinter3Present = -1 ; - char lPythonCommand[256]; - char lPythonParams[128] = - "-S -c \"try:\n\timport tkinter;\nexcept:\n\tprint(0);\""; - - if ( lTkinter3Present < 0 ) - { - lTkinter3Present = 0 ; - if ( python3Present() ) - { - sprintf( lPythonCommand , "%s %s" , gPython3Name , lPythonParams ) ; - lTkinter3Present = tryCommand(lPythonCommand) ; - } - if (tinyfd_verbose) printf("lTkinter3Present %d\n", lTkinter3Present) ; - } - return lTkinter3Present && graphicMode() && !(tfd_isDarwin() && getenv("SSH_TTY") ); -} - - -static int tkinter2Present(void) -{ - static int lTkinter2Present = -1 ; - char lPythonCommand[256]; - char lPythonParams[128] = - "-S -c \"try:\n\timport Tkinter;\nexcept:\n\tprint 0;\""; - - if ( lTkinter2Present < 0 ) - { - lTkinter2Present = 0 ; - if ( python2Present() ) - { - sprintf( lPythonCommand , "%s %s" , gPython2Name , lPythonParams ) ; - lTkinter2Present = tryCommand(lPythonCommand) ; - } - if (tinyfd_verbose) printf("lTkinter2Present %d graphicMode %d \n", lTkinter2Present, graphicMode() ) ; - } - return lTkinter2Present && graphicMode() && !(tfd_isDarwin() && getenv("SSH_TTY") ); -} - - -static int pythonDbusPresent(void) -{ - static int lPythonDbusPresent = -1 ; - char lPythonCommand[384]; - char lPythonParams[256] = -"-c \"try:\n\timport dbus;bus=dbus.SessionBus();\ -notif=bus.get_object('org.freedesktop.Notifications','/org/freedesktop/Notifications');\ -notify=dbus.Interface(notif,'org.freedesktop.Notifications');\nexcept:\n\tprint(0);\""; - - if (lPythonDbusPresent < 0 ) - { - lPythonDbusPresent = 0 ; - if ( python2Present() ) - { - strcpy(gPythonName , gPython2Name ) ; - sprintf( lPythonCommand , "%s %s" , gPythonName , lPythonParams ) ; - lPythonDbusPresent = tryCommand(lPythonCommand) ; - } - - if ( !lPythonDbusPresent && python3Present() ) - { - strcpy(gPythonName , gPython3Name ) ; - sprintf( lPythonCommand , "%s %s" , gPythonName , lPythonParams ) ; - lPythonDbusPresent = tryCommand(lPythonCommand) ; - } - - if (tinyfd_verbose) printf("lPythonDbusPresent %d\n", lPythonDbusPresent) ; - if (tinyfd_verbose) printf("gPythonName %s\n", gPythonName) ; - } - return lPythonDbusPresent && graphicMode() && !(tfd_isDarwin() && getenv("SSH_TTY") ); -} - - -static void sigHandler(int signum) -{ - FILE * lIn ; - if ( ( lIn = popen( "pactl unload-module module-sine" , "r" ) ) ) - { - pclose( lIn ) ; - } - if (tinyfd_verbose) printf("tinyfiledialogs caught signal %d\n", signum); -} - -void tinyfd_beep(void) -{ - char lDialogString[256] ; - FILE * lIn ; - - if ( osascriptPresent() ) - { - if ( afplayPresent() >= 2 ) - { - strcpy( lDialogString , "afplay /System/Library/Sounds/Ping.aiff") ; - } - else - { - strcpy( lDialogString , "osascript -e 'tell application \"System Events\" to beep'") ; - } - } - else if ( pactlPresent() ) - { - signal(SIGINT, sigHandler); - /*strcpy( lDialogString , "pactl load-module module-sine frequency=440;sleep .3;pactl unload-module module-sine" ) ;*/ - strcpy( lDialogString , "thnum=$(pactl load-module module-sine frequency=440);sleep .3;pactl unload-module $thnum" ) ; - } - else if ( speakertestPresent() ) - { - /*strcpy( lDialogString , "timeout -k .3 .3 speaker-test --frequency 440 --test sine > /dev/tty" ) ;*/ - strcpy( lDialogString , "( speaker-test -t sine -f 440 > /dev/tty )& pid=$!;sleep .5; kill -9 $pid" ) ; /*.3 was too short for mac g3*/ - } - else if (beepexePresent()) - { - strcpy(lDialogString, "beep.exe 440 300"); - } - else if (playPresent()) /* play is part of sox */ - { - strcpy(lDialogString, "play -q -n synth .3 sine 440"); - } - else if ( beepPresent() ) - { - strcpy( lDialogString , "beep -f 440 -l 300" ) ; - } - else - { - strcpy( lDialogString , "printf '\\a' > /dev/tty" ) ; - } - - if (tinyfd_verbose) printf( "lDialogString: %s\n" , lDialogString ) ; - - if ( ( lIn = popen( lDialogString , "r" ) ) ) - { - pclose( lIn ) ; - } - - if ( pactlPresent() ) - { - signal(SIGINT, SIG_DFL); - } -} - - -int tinyfd_messageBox( - char const * aTitle , /* NULL or "" */ - char const * aMessage , /* NULL or "" may contain \n and \t */ - char const * aDialogType , /* "ok" "okcancel" "yesno" "yesnocancel" */ - char const * aIconType , /* "info" "warning" "error" "question" */ - int aDefaultButton ) /* 0 for cancel/no , 1 for ok/yes , 2 for no in yesnocancel */ -{ - char lBuff[MAX_PATH_OR_CMD] ; - char * lDialogString = NULL ; - char * lpDialogString; - FILE * lIn ; - int lWasGraphicDialog = 0 ; - int lWasXterm = 0 ; - int lResult ; - char lChar ; - struct termios infoOri; - struct termios info; - size_t lTitleLen ; - size_t lMessageLen ; - - lBuff[0]='\0'; - - if (tfd_quoteDetected(aTitle)) return tinyfd_messageBox("INVALID TITLE WITH QUOTES", aMessage, aDialogType, aIconType, aDefaultButton); - if (tfd_quoteDetected(aMessage)) return tinyfd_messageBox(aTitle, "INVALID MESSAGE WITH QUOTES", aDialogType, aIconType, aDefaultButton); - - lTitleLen = aTitle ? strlen(aTitle) : 0 ; - lMessageLen = aMessage ? strlen(aMessage) : 0 ; - if ( !aTitle || strcmp(aTitle,"tinyfd_query") ) - { - lDialogString = (char *) malloc( MAX_PATH_OR_CMD + lTitleLen + lMessageLen ); - } - - if ( osascriptPresent( ) ) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"applescript");return 1;} - - strcpy( lDialogString , "osascript "); - if ( ! osx9orBetter() ) strcat( lDialogString , " -e 'tell application \"System Events\"' -e 'Activate'"); - strcat( lDialogString , " -e 'try' -e 'set {vButton} to {button returned} of ( display dialog \"") ; - if ( aMessage && strlen(aMessage) ) - { - strcat(lDialogString, aMessage) ; - } - strcat(lDialogString, "\" ") ; - if ( aTitle && strlen(aTitle) ) - { - strcat(lDialogString, "with title \"") ; - strcat(lDialogString, aTitle) ; - strcat(lDialogString, "\" ") ; - } - strcat(lDialogString, "with icon ") ; - if ( aIconType && ! strcmp( "error" , aIconType ) ) - { - strcat(lDialogString, "stop " ) ; - } - else if ( aIconType && ! strcmp( "warning" , aIconType ) ) - { - strcat(lDialogString, "caution " ) ; - } - else /* question or info */ - { - strcat(lDialogString, "note " ) ; - } - if ( aDialogType && ! strcmp( "okcancel" , aDialogType ) ) - { - if ( ! aDefaultButton ) - { - strcat( lDialogString ,"default button \"Cancel\" " ) ; - } - } - else if ( aDialogType && ! strcmp( "yesno" , aDialogType ) ) - { - strcat( lDialogString ,"buttons {\"No\", \"Yes\"} " ) ; - if (aDefaultButton) - { - strcat( lDialogString ,"default button \"Yes\" " ) ; - } - else - { - strcat( lDialogString ,"default button \"No\" " ) ; - } - strcat( lDialogString ,"cancel button \"No\"" ) ; - } - else if ( aDialogType && ! strcmp( "yesnocancel" , aDialogType ) ) - { - strcat( lDialogString ,"buttons {\"No\", \"Yes\", \"Cancel\"} " ) ; - switch (aDefaultButton) - { - case 1: strcat( lDialogString ,"default button \"Yes\" " ) ; break; - case 2: strcat( lDialogString ,"default button \"No\" " ) ; break; - case 0: strcat( lDialogString ,"default button \"Cancel\" " ) ; break; - } - strcat( lDialogString ,"cancel button \"Cancel\"" ) ; - } - else - { - strcat( lDialogString ,"buttons {\"OK\"} " ) ; - strcat( lDialogString ,"default button \"OK\" " ) ; - } - strcat( lDialogString, ")' ") ; - - strcat( lDialogString, -"-e 'if vButton is \"Yes\" then' -e 'return 1'\ - -e 'else if vButton is \"OK\" then' -e 'return 1'\ - -e 'else if vButton is \"No\" then' -e 'return 2'\ - -e 'else' -e 'return 0' -e 'end if' " ); - - strcat( lDialogString, "-e 'on error number -128' " ) ; - strcat( lDialogString, "-e '0' " ); - - strcat( lDialogString, "-e 'end try'") ; - if ( ! osx9orBetter() ) strcat( lDialogString, " -e 'end tell'") ; - } - else if ( tfd_kdialogPresent() ) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"kdialog");return 1;} - - strcpy( lDialogString , "kdialog" ) ; - if ( (tfd_kdialogPresent() == 2) && tfd_xpropPresent() ) - { - strcat(lDialogString, " --attach=$(xprop -root 32x '\t$0' _NET_ACTIVE_WINDOW | cut -f 2)"); /* contribution: Paul Rouget */ - } - - strcat( lDialogString , " --" ) ; - if ( aDialogType && ( ! strcmp( "okcancel" , aDialogType ) - || ! strcmp( "yesno" , aDialogType ) || ! strcmp( "yesnocancel" , aDialogType ) ) ) - { - if ( aIconType && ( ! strcmp( "warning" , aIconType ) - || ! strcmp( "error" , aIconType ) ) ) - { - strcat( lDialogString , "warning" ) ; - } - if ( ! strcmp( "yesnocancel" , aDialogType ) ) - { - strcat( lDialogString , "yesnocancel" ) ; - } - else - { - strcat( lDialogString , "yesno" ) ; - } - } - else if ( aIconType && ! strcmp( "error" , aIconType ) ) - { - strcat( lDialogString , "error" ) ; - } - else if ( aIconType && ! strcmp( "warning" , aIconType ) ) - { - strcat( lDialogString , "sorry" ) ; - } - else - { - strcat( lDialogString , "msgbox" ) ; - } - strcat( lDialogString , " \"" ) ; - if ( aMessage ) - { - strcat( lDialogString , aMessage ) ; - } - strcat( lDialogString , "\"" ) ; - if ( aDialogType && ! strcmp( "okcancel" , aDialogType ) ) - { - strcat( lDialogString , - " --yes-label Ok --no-label Cancel" ) ; - } - if ( aTitle && strlen(aTitle) ) - { - strcat(lDialogString, " --title \"") ; - strcat(lDialogString, aTitle) ; - strcat(lDialogString, "\"") ; - } - - if ( ! strcmp( "yesnocancel" , aDialogType ) ) - { - strcat( lDialogString , "; x=$? ;if [ $x = 0 ] ;then echo 1;elif [ $x = 1 ] ;then echo 2;else echo 0;fi"); - } - else - { - strcat( lDialogString , ";if [ $? = 0 ];then echo 1;else echo 0;fi"); - } - } - else if ( tfd_zenityPresent() || tfd_matedialogPresent() || tfd_shellementaryPresent() || tfd_qarmaPresent() ) - { - if ( tfd_zenityPresent() ) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"zenity");return 1;} - strcpy( lDialogString , "szAnswer=$(zenity" ) ; - if ( (tfd_zenity3Present() >= 4) && !getenv("SSH_TTY") && tfd_xpropPresent() ) - { - strcat(lDialogString, " --attach=$(sleep .01;xprop -root 32x '\t$0' _NET_ACTIVE_WINDOW | cut -f 2)"); /* contribution: Paul Rouget */ - } - } - else if ( tfd_matedialogPresent() ) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"matedialog");return 1;} - strcpy( lDialogString , "szAnswer=$(matedialog" ) ; - } - else if ( tfd_shellementaryPresent() ) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"shellementary");return 1;} - strcpy( lDialogString , "szAnswer=$(shellementary" ) ; - } - else - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"qarma");return 1;} - strcpy( lDialogString , "szAnswer=$(qarma" ) ; - if ( !getenv("SSH_TTY") && tfd_xpropPresent() ) - { - strcat(lDialogString, " --attach=$(xprop -root 32x '\t$0' _NET_ACTIVE_WINDOW | cut -f 2)"); /* contribution: Paul Rouget */ - } - } - strcat(lDialogString, " --"); - - if ( aDialogType && ! strcmp( "okcancel" , aDialogType ) ) - { - strcat( lDialogString , - "question --ok-label=Ok --cancel-label=Cancel" ) ; - } - else if ( aDialogType && ! strcmp( "yesno" , aDialogType ) ) - { - strcat( lDialogString , "question" ) ; - } - else if ( aDialogType && ! strcmp( "yesnocancel" , aDialogType ) ) - { - strcat( lDialogString , "list --column \"\" --hide-header \"Yes\" \"No\"" ) ; - } - else if ( aIconType && ! strcmp( "error" , aIconType ) ) - { - strcat( lDialogString , "error" ) ; - } - else if ( aIconType && ! strcmp( "warning" , aIconType ) ) - { - strcat( lDialogString , "warning" ) ; - } - else - { - strcat( lDialogString , "info" ) ; - } - - strcat(lDialogString, " --title=\""); - if ( aTitle && strlen(aTitle) ) strcat(lDialogString, aTitle) ; - strcat(lDialogString, "\""); - - if (strcmp("yesnocancel", aDialogType)) strcat(lDialogString, " --no-wrap"); - - strcat(lDialogString, " --text=\"") ; - if (aMessage && strlen(aMessage)) strcat(lDialogString, aMessage) ; - strcat(lDialogString, "\"") ; - - if ( (tfd_zenity3Present() >= 3) || (!tfd_zenityPresent() && (tfd_shellementaryPresent() || tfd_qarmaPresent()) ) ) - { - strcat( lDialogString , " --icon-name=dialog-" ) ; - if ( aIconType && (! strcmp( "question" , aIconType ) - || ! strcmp( "error" , aIconType ) - || ! strcmp( "warning" , aIconType ) ) ) - { - strcat( lDialogString , aIconType ) ; - } - else - { - strcat( lDialogString , "information" ) ; - } - } - - if (tinyfd_silent) strcat( lDialogString , " 2>/dev/null "); - - if ( ! strcmp( "yesnocancel" , aDialogType ) ) - { - strcat( lDialogString , -");if [ $? = 1 ];then echo 0;elif [ $szAnswer = \"No\" ];then echo 2;else echo 1;fi"); - } - else - { - strcat( lDialogString , ");if [ $? = 0 ];then echo 1;else echo 0;fi"); - } - } - - else if (tfd_yadPresent()) - { - if (aTitle && !strcmp(aTitle, "tinyfd_query")) { strcpy(tinyfd_response, "yad"); return 1; } - strcpy(lDialogString, "szAnswer=$(yad --"); - if (aDialogType && !strcmp("ok", aDialogType)) - { - strcat(lDialogString,"button=Ok:1"); - } - else if (aDialogType && !strcmp("okcancel", aDialogType)) - { - strcat(lDialogString,"button=Ok:1 --button=Cancel:0"); - } - else if (aDialogType && !strcmp("yesno", aDialogType)) - { - strcat(lDialogString, "button=Yes:1 --button=No:0"); - } - else if (aDialogType && !strcmp("yesnocancel", aDialogType)) - { - strcat(lDialogString, "button=Yes:1 --button=No:2 --button=Cancel:0"); - } - else if (aIconType && !strcmp("error", aIconType)) - { - strcat(lDialogString, "error"); - } - else if (aIconType && !strcmp("warning", aIconType)) - { - strcat(lDialogString, "warning"); - } - else - { - strcat(lDialogString, "info"); - } - if (aTitle && strlen(aTitle)) - { - strcat(lDialogString, " --title=\""); - strcat(lDialogString, aTitle); - strcat(lDialogString, "\""); - } - if (aMessage && strlen(aMessage)) - { - strcat(lDialogString, " --text=\""); - strcat(lDialogString, aMessage); - strcat(lDialogString, "\""); - } - - strcat(lDialogString, " --image=dialog-"); - if (aIconType && (!strcmp("question", aIconType) - || !strcmp("error", aIconType) - || !strcmp("warning", aIconType))) - { - strcat(lDialogString, aIconType); - } - else - { - strcat(lDialogString, "information"); - } - - if (tinyfd_silent) strcat(lDialogString, " 2>/dev/null "); - strcat(lDialogString,");echo $?"); - } - - else if ( !gxmessagePresent() && !gmessagePresent() && !gdialogPresent() && !xdialogPresent() && tkinter3Present() ) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"python3-tkinter");return 1;} - - strcpy( lDialogString , gPython3Name ) ; - strcat( lDialogString , - " -S -c \"import tkinter;from tkinter import messagebox;root=tkinter.Tk();root.withdraw();"); - - strcat( lDialogString ,"res=messagebox." ) ; - if ( aDialogType && ! strcmp( "okcancel" , aDialogType ) ) - { - strcat( lDialogString , "askokcancel(" ) ; - if ( aDefaultButton ) - { - strcat( lDialogString , "default=messagebox.OK," ) ; - } - else - { - strcat( lDialogString , "default=messagebox.CANCEL," ) ; - } - } - else if ( aDialogType && ! strcmp( "yesno" , aDialogType ) ) - { - strcat( lDialogString , "askyesno(" ) ; - if ( aDefaultButton ) - { - strcat( lDialogString , "default=messagebox.YES," ) ; - } - else - { - strcat( lDialogString , "default=messagebox.NO," ) ; - } - } - else if ( aDialogType && ! strcmp( "yesnocancel" , aDialogType ) ) - { - strcat( lDialogString , "askyesnocancel(" ) ; - switch ( aDefaultButton ) - { - case 1: strcat( lDialogString , "default=messagebox.YES," ); break; - case 2: strcat( lDialogString , "default=messagebox.NO," ); break; - case 0: strcat( lDialogString , "default=messagebox.CANCEL," ); break; - } - } - else - { - strcat( lDialogString , "showinfo(" ) ; - } - - strcat( lDialogString , "icon='" ) ; - if ( aIconType && (! strcmp( "question" , aIconType ) - || ! strcmp( "error" , aIconType ) - || ! strcmp( "warning" , aIconType ) ) ) - { - strcat( lDialogString , aIconType ) ; - } - else - { - strcat( lDialogString , "info" ) ; - } - - strcat(lDialogString, "',") ; - if ( aTitle && strlen(aTitle) ) - { - strcat(lDialogString, "title='") ; - strcat(lDialogString, aTitle) ; - strcat(lDialogString, "',") ; - } - if ( aMessage && strlen(aMessage) ) - { - strcat(lDialogString, "message='") ; - lpDialogString = lDialogString + strlen(lDialogString); - tfd_replaceSubStr( aMessage , "\n" , "\\n" , lpDialogString ) ; - strcat(lDialogString, "'") ; - } - - if ( aDialogType && ! strcmp( "yesnocancel" , aDialogType ) ) - { - strcat(lDialogString, ");\n\ -if res is None :\n\tprint(0)\n\ -elif res is False :\n\tprint(2)\n\ -else :\n\tprint (1)\n\"" ) ; - } - else - { - strcat(lDialogString, ");\n\ -if res is False :\n\tprint(0)\n\ -else :\n\tprint(1)\n\"" ) ; - } - } - else if ( !gxmessagePresent() && !gmessagePresent() && !gdialogPresent() && !xdialogPresent() && tkinter2Present() ) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"python2-tkinter");return 1;} - strcpy( lDialogString , "export PYTHONIOENCODING=utf-8;" ) ; - strcat( lDialogString , gPython2Name ) ; - if ( ! isTerminalRunning( ) && tfd_isDarwin( ) ) - { - strcat( lDialogString , " -i" ) ; /* for osx without console */ - } - - strcat( lDialogString , -" -S -c \"import Tkinter,tkMessageBox;root=Tkinter.Tk();root.withdraw();"); - - if ( tfd_isDarwin( ) ) - { - strcat( lDialogString , -"import os;os.system('''/usr/bin/osascript -e 'tell app \\\"Finder\\\" to set \ -frontmost of process \\\"Python\\\" to true' ''');"); - } - - strcat( lDialogString ,"res=tkMessageBox." ) ; - if ( aDialogType && ! strcmp( "okcancel" , aDialogType ) ) - { - strcat( lDialogString , "askokcancel(" ) ; - if ( aDefaultButton ) - { - strcat( lDialogString , "default=tkMessageBox.OK," ) ; - } - else - { - strcat( lDialogString , "default=tkMessageBox.CANCEL," ) ; - } - } - else if ( aDialogType && ! strcmp( "yesno" , aDialogType ) ) - { - strcat( lDialogString , "askyesno(" ) ; - if ( aDefaultButton ) - { - strcat( lDialogString , "default=tkMessageBox.YES," ) ; - } - else - { - strcat( lDialogString , "default=tkMessageBox.NO," ) ; - } - } - else if ( aDialogType && ! strcmp( "yesnocancel" , aDialogType ) ) - { - strcat( lDialogString , "askyesnocancel(" ) ; - switch ( aDefaultButton ) - { - case 1: strcat( lDialogString , "default=tkMessageBox.YES," ); break; - case 2: strcat( lDialogString , "default=tkMessageBox.NO," ); break; - case 0: strcat( lDialogString , "default=tkMessageBox.CANCEL," ); break; - } - } - else - { - strcat( lDialogString , "showinfo(" ) ; - } - - strcat( lDialogString , "icon='" ) ; - if ( aIconType && (! strcmp( "question" , aIconType ) - || ! strcmp( "error" , aIconType ) - || ! strcmp( "warning" , aIconType ) ) ) - { - strcat( lDialogString , aIconType ) ; - } - else - { - strcat( lDialogString , "info" ) ; - } - - strcat(lDialogString, "',") ; - if ( aTitle && strlen(aTitle) ) - { - strcat(lDialogString, "title='") ; - strcat(lDialogString, aTitle) ; - strcat(lDialogString, "',") ; - } - if ( aMessage && strlen(aMessage) ) - { - strcat(lDialogString, "message='") ; - lpDialogString = lDialogString + strlen(lDialogString); - tfd_replaceSubStr( aMessage , "\n" , "\\n" , lpDialogString ) ; - strcat(lDialogString, "'") ; - } - - if ( aDialogType && ! strcmp( "yesnocancel" , aDialogType ) ) - { - strcat(lDialogString, ");\n\ -if res is None :\n\tprint 0\n\ -elif res is False :\n\tprint 2\n\ -else :\n\tprint 1\n\"" ) ; - } - else - { - strcat(lDialogString, ");\n\ -if res is False :\n\tprint 0\n\ -else :\n\tprint 1\n\"" ) ; - } - } - else if ( gxmessagePresent() || gmessagePresent() || (!gdialogPresent() && !xdialogPresent() && xmessagePresent()) ) - { - if ( gxmessagePresent() ) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"gxmessage");return 1;} - strcpy( lDialogString , "gxmessage"); - } - else if ( gmessagePresent() ) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"gmessage");return 1;} - strcpy( lDialogString , "gmessage"); - } - else - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"xmessage");return 1;} - strcpy( lDialogString , "xmessage"); - } - - if ( aDialogType && ! strcmp("okcancel" , aDialogType) ) - { - strcat( lDialogString , " -buttons Ok:1,Cancel:0"); - switch ( aDefaultButton ) - { - case 1: strcat( lDialogString , " -default Ok"); break; - case 0: strcat( lDialogString , " -default Cancel"); break; - } - } - else if ( aDialogType && ! strcmp("yesno" , aDialogType) ) - { - strcat( lDialogString , " -buttons Yes:1,No:0"); - switch ( aDefaultButton ) - { - case 1: strcat( lDialogString , " -default Yes"); break; - case 0: strcat( lDialogString , " -default No"); break; - } - } - else if ( aDialogType && ! strcmp("yesnocancel" , aDialogType) ) - { - strcat( lDialogString , " -buttons Yes:1,No:2,Cancel:0"); - switch ( aDefaultButton ) - { - case 1: strcat( lDialogString , " -default Yes"); break; - case 2: strcat( lDialogString , " -default No"); break; - case 0: strcat( lDialogString , " -default Cancel"); break; - } - } - else - { - strcat( lDialogString , " -buttons Ok:1"); - strcat( lDialogString , " -default Ok"); - } - - strcat( lDialogString , " -center \""); - if ( aMessage && strlen(aMessage) ) - { - strcat( lDialogString , aMessage ) ; - } - strcat(lDialogString, "\"" ) ; - if ( aTitle && strlen(aTitle) ) - { - strcat( lDialogString , " -title \""); - strcat( lDialogString , aTitle ) ; - strcat( lDialogString, "\"" ) ; - } - strcat( lDialogString , " ; echo $? "); - } - else if ( xdialogPresent() || gdialogPresent() || dialogName() || whiptailPresent() ) - { - if ( gdialogPresent( ) ) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"gdialog");return 1;} - lWasGraphicDialog = 1 ; - strcpy( lDialogString , "(gdialog " ) ; - } - else if ( xdialogPresent( ) ) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"xdialog");return 1;} - lWasGraphicDialog = 1 ; - strcpy( lDialogString , "(Xdialog " ) ; - } - else if ( dialogName( ) ) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"dialog");return 0;} - if ( isTerminalRunning( ) ) - { - strcpy( lDialogString , "(dialog " ) ; - } - else - { - lWasXterm = 1 ; - strcpy( lDialogString , terminalName() ) ; - strcat( lDialogString , "'(" ) ; - strcat( lDialogString , dialogName() ) ; - strcat( lDialogString , " " ) ; - } - } - else if ( isTerminalRunning( ) ) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"whiptail");return 0;} - strcpy( lDialogString , "(whiptail " ) ; - } - else - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"whiptail");return 0;} - lWasXterm = 1 ; - strcpy( lDialogString , terminalName() ) ; - strcat( lDialogString , "'(whiptail " ) ; - } - - if ( aTitle && strlen(aTitle) ) - { - strcat(lDialogString, "--title \"") ; - strcat(lDialogString, aTitle) ; - strcat(lDialogString, "\" ") ; - } - - if ( !xdialogPresent() && !gdialogPresent() ) - { - if ( aDialogType && ( !strcmp( "okcancel" , aDialogType ) || !strcmp( "yesno" , aDialogType ) - || !strcmp( "yesnocancel" , aDialogType ) ) ) - { - strcat(lDialogString, "--backtitle \"") ; - strcat(lDialogString, "tab: move focus") ; - strcat(lDialogString, "\" ") ; - } - } - - if ( aDialogType && ! strcmp( "okcancel" , aDialogType ) ) - { - if ( ! aDefaultButton ) - { - strcat( lDialogString , "--defaultno " ) ; - } - strcat( lDialogString , - "--yes-label \"Ok\" --no-label \"Cancel\" --yesno " ) ; - } - else if ( aDialogType && ! strcmp( "yesno" , aDialogType ) ) - { - if ( ! aDefaultButton ) - { - strcat( lDialogString , "--defaultno " ) ; - } - strcat( lDialogString , "--yesno " ) ; - } - else if (aDialogType && !strcmp("yesnocancel", aDialogType)) - { - if (!aDefaultButton) - { - strcat(lDialogString, "--defaultno "); - } - strcat(lDialogString, "--menu "); - } - else - { - strcat( lDialogString , "--msgbox " ) ; - - } - strcat( lDialogString , "\"" ) ; - if ( aMessage && strlen(aMessage) ) - { - strcat(lDialogString, aMessage) ; - } - strcat(lDialogString, "\" "); - - if ( lWasGraphicDialog ) - { - if (aDialogType && !strcmp("yesnocancel", aDialogType)) - { - strcat(lDialogString,"0 60 0 Yes \"\" No \"\") 2>/tmp/tinyfd.txt;\ -if [ $? = 0 ];then tinyfdBool=1;else tinyfdBool=0;fi;\ -tinyfdRes=$(cat /tmp/tinyfd.txt);echo $tinyfdBool$tinyfdRes") ; - } - else - { - strcat(lDialogString, - "10 60 ) 2>&1;if [ $? = 0 ];then echo 1;else echo 0;fi"); - } - } - else - { - if (aDialogType && !strcmp("yesnocancel", aDialogType)) - { - strcat(lDialogString,"0 60 0 Yes \"\" No \"\" >/dev/tty ) 2>/tmp/tinyfd.txt;\ - if [ $? = 0 ];then tinyfdBool=1;else tinyfdBool=0;fi;\ - tinyfdRes=$(cat /tmp/tinyfd.txt);echo $tinyfdBool$tinyfdRes") ; - - if ( lWasXterm ) - { - strcat(lDialogString," >/tmp/tinyfd0.txt';cat /tmp/tinyfd0.txt"); - } - else - { - strcat(lDialogString, "; clear >/dev/tty") ; - } - } - else - { - strcat(lDialogString, "10 60 >/dev/tty) 2>&1;if [ $? = 0 ];"); - if ( lWasXterm ) - { - strcat( lDialogString , -"then\n\techo 1\nelse\n\techo 0\nfi >/tmp/tinyfd.txt';cat /tmp/tinyfd.txt;rm /tmp/tinyfd.txt"); - } - else - { - strcat(lDialogString, - "then echo 1;else echo 0;fi;clear >/dev/tty"); - } - } - } - } - else if ( !isTerminalRunning() && terminalName() ) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"basicinput");return 0;} - strcpy( lDialogString , terminalName() ) ; - strcat( lDialogString , "'" ) ; - if ( !gWarningDisplayed && !tinyfd_forceConsole) - { - gWarningDisplayed = 1 ; - strcat( lDialogString , "echo \"" ) ; - strcat( lDialogString, gTitle) ; - strcat( lDialogString , "\";" ) ; - strcat( lDialogString , "echo \"" ) ; - strcat( lDialogString, tinyfd_needs) ; - strcat( lDialogString , "\";echo;echo;" ) ; - } - if ( aTitle && strlen(aTitle) ) - { - strcat( lDialogString , "echo \"" ) ; - strcat( lDialogString, aTitle) ; - strcat( lDialogString , "\";echo;" ) ; - } - if ( aMessage && strlen(aMessage) ) - { - strcat( lDialogString , "echo \"" ) ; - strcat( lDialogString, aMessage) ; - strcat( lDialogString , "\"; " ) ; - } - if ( aDialogType && !strcmp("yesno",aDialogType) ) - { - strcat( lDialogString , "echo -n \"y/n: \"; " ) ; - strcat( lDialogString , "stty sane -echo;" ) ; - strcat( lDialogString , - "answer=$( while ! head -c 1 | grep -i [ny];do true ;done);"); - strcat( lDialogString , - "if echo \"$answer\" | grep -iq \"^y\";then\n"); - strcat( lDialogString , "\techo 1\nelse\n\techo 0\nfi" ) ; - } - else if ( aDialogType && !strcmp("okcancel",aDialogType) ) - { - strcat( lDialogString , "echo -n \"[O]kay/[C]ancel: \"; " ) ; - strcat( lDialogString , "stty sane -echo;" ) ; - strcat( lDialogString , - "answer=$( while ! head -c 1 | grep -i [oc];do true ;done);"); - strcat( lDialogString , - "if echo \"$answer\" | grep -iq \"^o\";then\n"); - strcat( lDialogString , "\techo 1\nelse\n\techo 0\nfi" ) ; - } - else if ( aDialogType && !strcmp("yesnocancel",aDialogType) ) - { - strcat( lDialogString , "echo -n \"[Y]es/[N]o/[C]ancel: \"; " ) ; - strcat( lDialogString , "stty sane -echo;" ) ; - strcat( lDialogString , - "answer=$( while ! head -c 1 | grep -i [nyc];do true ;done);"); - strcat( lDialogString , - "if echo \"$answer\" | grep -iq \"^y\";then\n\techo 1\n"); - strcat( lDialogString , "elif echo \"$answer\" | grep -iq \"^n\";then\n\techo 2\n" ) ; - strcat( lDialogString , "else\n\techo 0\nfi" ) ; - } - else - { - strcat(lDialogString , "echo -n \"press enter to continue \"; "); - strcat( lDialogString , "stty sane -echo;" ) ; - strcat( lDialogString , - "answer=$( while ! head -c 1;do true ;done);echo 1"); - } - strcat( lDialogString , - " >/tmp/tinyfd.txt';cat /tmp/tinyfd.txt;rm /tmp/tinyfd.txt"); - } - else if ( !isTerminalRunning() && pythonDbusPresent() && !strcmp("ok" , aDialogType) ) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"python-dbus");return 1;} - strcpy( lDialogString , gPythonName ) ; - strcat( lDialogString ," -c \"import dbus;bus=dbus.SessionBus();"); - strcat( lDialogString ,"notif=bus.get_object('org.freedesktop.Notifications','/org/freedesktop/Notifications');" ) ; - strcat( lDialogString ,"notify=dbus.Interface(notif,'org.freedesktop.Notifications');" ) ; - strcat( lDialogString ,"notify.Notify('',0,'" ) ; - if ( aIconType && strlen(aIconType) ) - { - strcat( lDialogString , aIconType ) ; - } - strcat(lDialogString, "','") ; - if ( aTitle && strlen(aTitle) ) - { - strcat(lDialogString, aTitle) ; - } - strcat(lDialogString, "','") ; - if ( aMessage && strlen(aMessage) ) - { - lpDialogString = lDialogString + strlen(lDialogString); - tfd_replaceSubStr( aMessage , "\n" , "\\n" , lpDialogString ) ; - } - strcat(lDialogString, "','','',5000)\"") ; - } - else if ( !isTerminalRunning() && (perlPresent() >= 2) && !strcmp("ok" , aDialogType) ) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"perl-dbus");return 1;} - - strcpy( lDialogString , "perl -e \"use Net::DBus;\ -my \\$sessionBus = Net::DBus->session;\ -my \\$notificationsService = \\$sessionBus->get_service('org.freedesktop.Notifications');\ -my \\$notificationsObject = \\$notificationsService->get_object('/org/freedesktop/Notifications',\ -'org.freedesktop.Notifications');"); - - sprintf( lDialogString + strlen(lDialogString), -"my \\$notificationId;\\$notificationId = \\$notificationsObject->Notify(shift, 0, '%s', '%s', '%s', [], {}, -1);\" ", - aIconType?aIconType:"", aTitle?aTitle:"", aMessage?aMessage:"" ) ; - } - else if ( !isTerminalRunning() && notifysendPresent() && !strcmp("ok" , aDialogType) ) - { - - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"notifysend");return 1;} - strcpy( lDialogString , "notify-send" ) ; - if ( aIconType && strlen(aIconType) ) - { - strcat( lDialogString , " -i '" ) ; - strcat( lDialogString , aIconType ) ; - strcat( lDialogString , "'" ) ; - } - strcat( lDialogString , " \"" ) ; - if ( aTitle && strlen(aTitle) ) - { - strcat(lDialogString, aTitle) ; - strcat( lDialogString , " | " ) ; - } - if ( aMessage && strlen(aMessage) ) - { - tfd_replaceSubStr( aMessage , "\n\t" , " | " , lBuff ) ; - tfd_replaceSubStr( aMessage , "\n" , " | " , lBuff ) ; - tfd_replaceSubStr( aMessage , "\t" , " " , lBuff ) ; - strcat(lDialogString, lBuff) ; - } - strcat( lDialogString , "\"" ) ; - } - else - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"basicinput");return 0;} - if ( !gWarningDisplayed && !tinyfd_forceConsole) - { - gWarningDisplayed = 1 ; - printf("\n\n%s\n", gTitle); - printf("%s\n\n", tinyfd_needs); - } - if ( aTitle && strlen(aTitle) ) - { - printf("\n%s\n", aTitle); - } - - tcgetattr(0, &infoOri); - tcgetattr(0, &info); - info.c_lflag &= ~ICANON; - info.c_cc[VMIN] = 1; - info.c_cc[VTIME] = 0; - tcsetattr(0, TCSANOW, &info); - if ( aDialogType && !strcmp("yesno",aDialogType) ) - { - do - { - if ( aMessage && strlen(aMessage) ) - { - printf("\n%s\n",aMessage); - } - printf("y/n: "); fflush(stdout); - lChar = (char) tolower( getchar() ) ; - printf("\n\n"); - } - while ( lChar != 'y' && lChar != 'n' ); - lResult = lChar == 'y' ? 1 : 0 ; - } - else if ( aDialogType && !strcmp("okcancel",aDialogType) ) - { - do - { - if ( aMessage && strlen(aMessage) ) - { - printf("\n%s\n",aMessage); - } - printf("[O]kay/[C]ancel: "); fflush(stdout); - lChar = (char) tolower( getchar() ) ; - printf("\n\n"); - } - while ( lChar != 'o' && lChar != 'c' ); - lResult = lChar == 'o' ? 1 : 0 ; - } - else if ( aDialogType && !strcmp("yesnocancel",aDialogType) ) - { - do - { - if ( aMessage && strlen(aMessage) ) - { - printf("\n%s\n",aMessage); - } - printf("[Y]es/[N]o/[C]ancel: "); fflush(stdout); - lChar = (char) tolower( getchar() ) ; - printf("\n\n"); - } - while ( lChar != 'y' && lChar != 'n' && lChar != 'c' ); - lResult = (lChar == 'y') ? 1 : (lChar == 'n') ? 2 : 0 ; - } - else - { - if ( aMessage && strlen(aMessage) ) - { - printf("\n%s\n\n",aMessage); - } - printf("press enter to continue "); fflush(stdout); - getchar() ; - printf("\n\n"); - lResult = 1 ; - } - tcsetattr(0, TCSANOW, &infoOri); - free(lDialogString); - return lResult ; - } - - if (tinyfd_verbose) printf( "lDialogString: %s\n" , lDialogString ) ; - - if ( ! ( lIn = popen( lDialogString , "r" ) ) ) - { - free(lDialogString); - return 0 ; - } - while ( fgets( lBuff , sizeof( lBuff ) , lIn ) != NULL ) - {} - - pclose( lIn ) ; - - /* printf( "lBuff: %s len: %lu \n" , lBuff , strlen(lBuff) ) ; */ - if ( lBuff[strlen( lBuff ) -1] == '\n' ) - { - lBuff[strlen( lBuff ) -1] = '\0' ; - } - /* printf( "lBuff1: %s len: %lu \n" , lBuff , strlen(lBuff) ) ; */ - - if (aDialogType && !strcmp("yesnocancel", aDialogType)) - { - if ( lBuff[0]=='1' ) - { - if ( !strcmp( lBuff+1 , "Yes" )) strcpy(lBuff,"1"); - else if ( !strcmp( lBuff+1 , "No" )) strcpy(lBuff,"2"); - } - } - /* printf( "lBuff2: %s len: %lu \n" , lBuff , strlen(lBuff) ) ; */ - - lResult = !strcmp( lBuff , "2" ) ? 2 : !strcmp( lBuff , "1" ) ? 1 : 0; - - /* printf( "lResult: %d\n" , lResult ) ; */ - free(lDialogString); - return lResult ; -} - - -/* return has only meaning for tinyfd_query */ -int tinyfd_notifyPopup( - char const * aTitle , /* NULL or "" */ - char const * aMessage , /* NULL or "" may contain \n and \t */ - char const * aIconType ) /* "info" "warning" "error" */ -{ - char lBuff[MAX_PATH_OR_CMD]; - char * lDialogString = NULL ; - char * lpDialogString ; - FILE * lIn ; - size_t lTitleLen ; - size_t lMessageLen ; - - if (tfd_quoteDetected(aTitle)) return tinyfd_notifyPopup("INVALID TITLE WITH QUOTES", aMessage, aIconType); - if (tfd_quoteDetected(aMessage)) return tinyfd_notifyPopup(aTitle, "INVALID MESSAGE WITH QUOTES", aIconType); - - if ( getenv("SSH_TTY") && !dunstifyPresent() && !dunstPresent() ) - { - return tinyfd_messageBox(aTitle, aMessage, "ok", aIconType, 0); - } - - lTitleLen = aTitle ? strlen(aTitle) : 0 ; - lMessageLen = aMessage ? strlen(aMessage) : 0 ; - if ( !aTitle || strcmp(aTitle,"tinyfd_query") ) - { - lDialogString = (char *) malloc( MAX_PATH_OR_CMD + lTitleLen + lMessageLen ); - } - - if ( getenv("SSH_TTY") ) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"dunst");return 1;} - strcpy( lDialogString , "notify-send \"" ) ; - if ( aTitle && strlen(aTitle) ) - { - strcat( lDialogString , aTitle ) ; - strcat( lDialogString , "\" \"" ) ; - } - if ( aMessage && strlen(aMessage) ) - { - strcat(lDialogString, aMessage) ; - } - strcat( lDialogString , "\"" ) ; - } - else if ( osascriptPresent( ) ) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"applescript");return 1;} - - strcpy( lDialogString , "osascript "); - if ( ! osx9orBetter() ) strcat( lDialogString , " -e 'tell application \"System Events\"' -e 'Activate'"); - strcat( lDialogString , " -e 'try' -e 'display notification \"") ; - if ( aMessage && strlen(aMessage) ) - { - strcat(lDialogString, aMessage) ; - } - strcat(lDialogString, " \" ") ; - if ( aTitle && strlen(aTitle) ) - { - strcat(lDialogString, "with title \"") ; - strcat(lDialogString, aTitle) ; - strcat(lDialogString, "\" ") ; - } - - strcat( lDialogString, "' -e 'end try'") ; - if ( ! osx9orBetter() ) strcat( lDialogString, " -e 'end tell'") ; - } - else if ( tfd_kdialogPresent() ) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"kdialog");return 1;} - strcpy( lDialogString , "kdialog" ) ; - - if ( aIconType && strlen(aIconType) ) - { - strcat( lDialogString , " --icon '" ) ; - strcat( lDialogString , aIconType ) ; - strcat( lDialogString , "'" ) ; - } - if ( aTitle && strlen(aTitle) ) - { - strcat( lDialogString , " --title \"" ) ; - strcat( lDialogString , aTitle ) ; - strcat( lDialogString , "\"" ) ; - } - - strcat( lDialogString , " --passivepopup" ) ; - strcat( lDialogString , " \"" ) ; - if ( aMessage ) - { - strcat( lDialogString , aMessage ) ; - } - strcat( lDialogString , " \" 5" ) ; - } - else if ( tfd_yadPresent() ) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"yad");return 1;} - strcpy( lDialogString , "yad --notification"); - - if ( aIconType && strlen( aIconType ) ) - { - strcat( lDialogString , " --image=\""); - strcat( lDialogString , aIconType ) ; - strcat( lDialogString , "\"" ) ; - } - - strcat( lDialogString , " --text=\"" ) ; - if ( aTitle && strlen(aTitle) ) - { - strcat(lDialogString, aTitle) ; - strcat(lDialogString, "\n") ; - } - if ( aMessage && strlen( aMessage ) ) - { - strcat( lDialogString , aMessage ) ; - } - strcat( lDialogString , " \"" ) ; - } - else if ( perlPresent() >= 2 ) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"perl-dbus");return 1;} - - strcpy( lDialogString , "perl -e \"use Net::DBus;\ -my \\$sessionBus = Net::DBus->session;\ -my \\$notificationsService = \\$sessionBus->get_service('org.freedesktop.Notifications');\ -my \\$notificationsObject = \\$notificationsService->get_object('/org/freedesktop/Notifications',\ -'org.freedesktop.Notifications');"); - - sprintf( lDialogString + strlen(lDialogString) , -"my \\$notificationId;\\$notificationId = \\$notificationsObject->Notify(shift, 0, '%s', '%s', '%s', [], {}, -1);\" ", -aIconType?aIconType:"", aTitle?aTitle:"", aMessage?aMessage:"" ) ; - } - else if ( pythonDbusPresent( ) ) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"python-dbus");return 1;} - strcpy( lDialogString , gPythonName ) ; - strcat( lDialogString ," -c \"import dbus;bus=dbus.SessionBus();"); - strcat( lDialogString ,"notif=bus.get_object('org.freedesktop.Notifications','/org/freedesktop/Notifications');" ) ; - strcat( lDialogString ,"notify=dbus.Interface(notif,'org.freedesktop.Notifications');" ) ; - strcat( lDialogString ,"notify.Notify('',0,'" ) ; - if ( aIconType && strlen(aIconType) ) - { - strcat( lDialogString , aIconType ) ; - } - strcat(lDialogString, "','") ; - if ( aTitle && strlen(aTitle) ) - { - strcat(lDialogString, aTitle) ; - } - strcat(lDialogString, "','") ; - if ( aMessage && strlen(aMessage) ) - { - lpDialogString = lDialogString + strlen(lDialogString); - tfd_replaceSubStr( aMessage , "\n" , "\\n" , lpDialogString ) ; - } - strcat(lDialogString, "','','',5000)\"") ; - } - else if ( notifysendPresent() ) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"notifysend");return 1;} - strcpy( lDialogString , "notify-send" ) ; - if ( aIconType && strlen(aIconType) ) - { - strcat( lDialogString , " -i '" ) ; - strcat( lDialogString , aIconType ) ; - strcat( lDialogString , "'" ) ; - } - strcat( lDialogString , " \"" ) ; - if ( aTitle && strlen(aTitle) ) - { - strcat(lDialogString, aTitle) ; - strcat( lDialogString , " | " ) ; - } - if ( aMessage && strlen(aMessage) ) - { - tfd_replaceSubStr( aMessage , "\n\t" , " | " , lBuff ) ; - tfd_replaceSubStr( aMessage , "\n" , " | " , lBuff ) ; - tfd_replaceSubStr( aMessage , "\t" , " " , lBuff ) ; - strcat(lDialogString, lBuff) ; - } - strcat( lDialogString , "\"" ) ; - } - else if ( (tfd_zenity3Present()>=5) ) - { - /* zenity 2.32 & 3.14 has the notification but with a bug: it doesnt return from it */ - /* zenity 3.8 show the notification as an alert ok cancel box */ - /* zenity 3.44 doesn't have the notification (3.42 has it) */ - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"zenity");return 1;} - strcpy( lDialogString , "zenity --notification"); - - if ( aIconType && strlen( aIconType ) ) - { - strcat( lDialogString , " --window-icon '"); - strcat( lDialogString , aIconType ) ; - strcat( lDialogString , "'" ) ; - } - - strcat( lDialogString , " --text \"" ) ; - if ( aTitle && strlen(aTitle) ) - { - strcat(lDialogString, aTitle) ; - strcat(lDialogString, "\n") ; - } - if ( aMessage && strlen( aMessage ) ) - { - strcat( lDialogString , aMessage ) ; - } - strcat( lDialogString , " \"" ) ; - } - else - { - if (lDialogString) free(lDialogString); - return tinyfd_messageBox(aTitle, aMessage, "ok", aIconType, 0); - } - - if (tinyfd_verbose) printf( "lDialogString: %s\n" , lDialogString ) ; - - if ( ! ( lIn = popen( lDialogString , "r" ) ) ) - { - free(lDialogString); - return 0 ; - } - - pclose( lIn ) ; - free(lDialogString); - return 1; -} - - -/* returns NULL on cancel */ -char * tinyfd_inputBox( - char const * aTitle , /* NULL or "" */ - char const * aMessage , /* NULL or "" (\n and \t have no effect) */ - char const * aDefaultInput ) /* "" , if NULL it's a passwordBox */ -{ - static char lBuff[MAX_PATH_OR_CMD]; - char * lDialogString = NULL; - char * lpDialogString; - FILE * lIn ; - int lResult ; - int lWasGdialog = 0 ; - int lWasGraphicDialog = 0 ; - int lWasXterm = 0 ; - int lWasBasicXterm = 0 ; - struct termios oldt ; - struct termios newt ; - char * lEOF; - size_t lTitleLen ; - size_t lMessageLen ; - - if (!aTitle && !aMessage && !aDefaultInput) return lBuff; /* now I can fill lBuff from outside */ - - lBuff[0]='\0'; - - if (tfd_quoteDetected(aTitle)) return tinyfd_inputBox("INVALID TITLE WITH QUOTES", aMessage, aDefaultInput); - if (tfd_quoteDetected(aMessage)) return tinyfd_inputBox(aTitle, "INVALID MESSAGE WITH QUOTES", aDefaultInput); - if (tfd_quoteDetected(aDefaultInput)) return tinyfd_inputBox(aTitle, aMessage, "INVALID DEFAULT_INPUT WITH QUOTES: use the GRAVE ACCENT \\x60 instead."); - - lTitleLen = aTitle ? strlen(aTitle) : 0 ; - lMessageLen = aMessage ? strlen(aMessage) : 0 ; - if ( !aTitle || strcmp(aTitle,"tinyfd_query") ) - { - lDialogString = (char *) malloc( MAX_PATH_OR_CMD + lTitleLen + lMessageLen ); - } - - if ( osascriptPresent( ) ) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"applescript");return (char *)1;} - strcpy( lDialogString , "osascript "); - if ( ! osx9orBetter() ) strcat( lDialogString , " -e 'tell application \"System Events\"' -e 'Activate'"); - strcat( lDialogString , " -e 'try' -e 'display dialog \"") ; - if ( aMessage && strlen(aMessage) ) - { - strcat(lDialogString, aMessage) ; - } - strcat(lDialogString, "\" ") ; - strcat(lDialogString, "default answer \"") ; - if ( aDefaultInput && strlen(aDefaultInput) ) - { - strcat(lDialogString, aDefaultInput) ; - } - strcat(lDialogString, "\" ") ; - if ( ! aDefaultInput ) - { - strcat(lDialogString, "hidden answer true ") ; - } - if ( aTitle && strlen(aTitle) ) - { - strcat(lDialogString, "with title \"") ; - strcat(lDialogString, aTitle) ; - strcat(lDialogString, "\" ") ; - } - strcat(lDialogString, "with icon note' ") ; - strcat(lDialogString, "-e '\"1\" & text returned of result' " ); - strcat(lDialogString, "-e 'on error number -128' " ) ; - strcat(lDialogString, "-e '0' " ); - strcat(lDialogString, "-e 'end try'") ; - if ( ! osx9orBetter() ) strcat(lDialogString, " -e 'end tell'") ; - } - else if ( tfd_kdialogPresent() ) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"kdialog");return (char *)1;} - strcpy( lDialogString , "szAnswer=$(kdialog" ) ; - - if ( (tfd_kdialogPresent() == 2) && tfd_xpropPresent() ) - { - strcat(lDialogString, " --attach=$(xprop -root 32x '\t$0' _NET_ACTIVE_WINDOW | cut -f 2)"); /* contribution: Paul Rouget */ - } - - if ( ! aDefaultInput ) - { - strcat(lDialogString, " --password ") ; - } - else - { - strcat(lDialogString, " --inputbox ") ; - - } - strcat(lDialogString, "\"") ; - if ( aMessage && strlen(aMessage) ) - { - strcat(lDialogString, aMessage ) ; - } - strcat(lDialogString , "\" \"" ) ; - if ( aDefaultInput && strlen(aDefaultInput) ) - { - strcat(lDialogString, aDefaultInput ) ; - } - strcat(lDialogString , "\"" ) ; - if ( aTitle && strlen(aTitle) ) - { - strcat(lDialogString, " --title \"") ; - strcat(lDialogString, aTitle) ; - strcat(lDialogString, "\"") ; - } - strcat( lDialogString , - ");if [ $? = 0 ];then echo 1$szAnswer;else echo 0$szAnswer;fi"); - } - else if ( tfd_zenityPresent() || tfd_matedialogPresent() || tfd_shellementaryPresent() || tfd_qarmaPresent() ) - { - if ( tfd_zenityPresent() ) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"zenity");return (char *)1;} - strcpy( lDialogString , "szAnswer=$(zenity" ) ; - if ( (tfd_zenity3Present() >= 4) && !getenv("SSH_TTY") && tfd_xpropPresent() ) - { - strcat( lDialogString, " --attach=$(sleep .01;xprop -root 32x '\t$0' _NET_ACTIVE_WINDOW | cut -f 2)"); /* contribution: Paul Rouget */ - } - } - else if ( tfd_matedialogPresent() ) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"matedialog");return (char *)1;} - strcpy( lDialogString , "szAnswer=$(matedialog" ) ; - } - else if ( tfd_shellementaryPresent() ) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"shellementary");return (char *)1;} - strcpy( lDialogString , "szAnswer=$(shellementary" ) ; - } - else - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"qarma");return (char *)1;} - strcpy( lDialogString , "szAnswer=$(qarma" ) ; - if ( !getenv("SSH_TTY") && tfd_xpropPresent() ) - { - strcat(lDialogString, " --attach=$(xprop -root 32x '\t$0' _NET_ACTIVE_WINDOW | cut -f 2)"); /* contribution: Paul Rouget */ - } - } - strcat( lDialogString ," --entry" ) ; - - strcat(lDialogString, " --title=\"") ; - if (aTitle && strlen(aTitle)) strcat(lDialogString, aTitle) ; - strcat(lDialogString, "\"") ; - - strcat(lDialogString, " --text=\"") ; - if (aMessage && strlen(aMessage)) strcat(lDialogString, aMessage) ; - strcat(lDialogString, "\"") ; - - if ( aDefaultInput ) - { - strcat(lDialogString, " --entry-text=\"") ; - strcat(lDialogString, aDefaultInput) ; - strcat(lDialogString, "\"") ; - } - else - { - strcat(lDialogString, " --hide-text") ; - } - if (tinyfd_silent) strcat( lDialogString , " 2>/dev/null "); - strcat( lDialogString , - ");if [ $? = 0 ];then echo 1$szAnswer;else echo 0$szAnswer;fi"); - } - else if (tfd_yadPresent()) - { - if (aTitle && !strcmp(aTitle, "tinyfd_query")) { strcpy(tinyfd_response, "yad"); return (char*)1; } - strcpy(lDialogString, "szAnswer=$(yad --entry"); - if (aTitle && strlen(aTitle)) - { - strcat(lDialogString, " --title=\""); - strcat(lDialogString, aTitle); - strcat(lDialogString, "\""); - } - if (aMessage && strlen(aMessage)) - { - strcat(lDialogString, " --text=\""); - strcat(lDialogString, aMessage); - strcat(lDialogString, "\""); - } - if (aDefaultInput && strlen(aDefaultInput)) - { - strcat(lDialogString, " --entry-text=\""); - strcat(lDialogString, aDefaultInput); - strcat(lDialogString, "\""); - } - else - { - strcat(lDialogString, " --hide-text"); - } - if (tinyfd_silent) strcat(lDialogString, " 2>/dev/null "); - strcat(lDialogString, - ");if [ $? = 0 ];then echo 1$szAnswer;else echo 0$szAnswer;fi"); - } - else if ( gxmessagePresent() || gmessagePresent() ) - { - if ( gxmessagePresent() ) { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"gxmessage");return (char *)1;} - strcpy( lDialogString , "szAnswer=$(gxmessage -buttons Ok:1,Cancel:0 -center \""); - } - else - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"gmessage");return (char *)1;} - strcpy( lDialogString , "szAnswer=$(gmessage -buttons Ok:1,Cancel:0 -center \""); - } - - if ( aMessage && strlen(aMessage) ) - { - strcat( lDialogString , aMessage ) ; - } - strcat(lDialogString, "\"" ) ; - if ( aTitle && strlen(aTitle) ) - { - strcat( lDialogString , " -title \""); - strcat( lDialogString , aTitle ) ; - strcat(lDialogString, "\" " ) ; - } - strcat(lDialogString, " -entrytext \"" ) ; - if ( aDefaultInput && strlen(aDefaultInput) ) - { - strcat( lDialogString , aDefaultInput ) ; - } - strcat(lDialogString, "\"" ) ; - strcat( lDialogString , ");echo $?$szAnswer"); - } - else if ( !gdialogPresent() && !xdialogPresent() && tkinter3Present( ) ) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"python3-tkinter");return (char *)1;} - strcpy( lDialogString , gPython3Name ) ; - strcat( lDialogString , - " -S -c \"import tkinter; from tkinter import simpledialog;root=tkinter.Tk();root.withdraw();"); - strcat( lDialogString ,"res=simpledialog.askstring(" ) ; - if ( aTitle && strlen(aTitle) ) - { - strcat(lDialogString, "title='") ; - strcat(lDialogString, aTitle) ; - strcat(lDialogString, "',") ; - } - if ( aMessage && strlen(aMessage) ) - { - - strcat(lDialogString, "prompt='") ; - lpDialogString = lDialogString + strlen(lDialogString); - tfd_replaceSubStr( aMessage , "\n" , "\\n" , lpDialogString ) ; - strcat(lDialogString, "',") ; - } - if ( aDefaultInput ) - { - if ( strlen(aDefaultInput) ) - { - strcat(lDialogString, "initialvalue='") ; - strcat(lDialogString, aDefaultInput) ; - strcat(lDialogString, "',") ; - } - } - else - { - strcat(lDialogString, "show='*'") ; - } - strcat(lDialogString, ");\nif res is None :\n\tprint(0)"); - strcat(lDialogString, "\nelse :\n\tprint('1'+res)\n\"" ) ; - } - else if ( !gdialogPresent() && !xdialogPresent() && tkinter2Present( ) ) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"python2-tkinter");return (char *)1;} - strcpy( lDialogString , "export PYTHONIOENCODING=utf-8;" ) ; - strcat( lDialogString , gPython2Name ) ; - if ( ! isTerminalRunning( ) && tfd_isDarwin( ) ) - { - strcat( lDialogString , " -i" ) ; /* for osx without console */ - } - - strcat( lDialogString , - " -S -c \"import Tkinter,tkSimpleDialog;root=Tkinter.Tk();root.withdraw();"); - - if ( tfd_isDarwin( ) ) - { - strcat( lDialogString , -"import os;os.system('''/usr/bin/osascript -e 'tell app \\\"Finder\\\" to set \ -frontmost of process \\\"Python\\\" to true' ''');"); - } - - strcat( lDialogString ,"res=tkSimpleDialog.askstring(" ) ; - if ( aTitle && strlen(aTitle) ) - { - strcat(lDialogString, "title='") ; - strcat(lDialogString, aTitle) ; - strcat(lDialogString, "',") ; - } - if ( aMessage && strlen(aMessage) ) - { - - strcat(lDialogString, "prompt='") ; - lpDialogString = lDialogString + strlen(lDialogString); - tfd_replaceSubStr( aMessage , "\n" , "\\n" , lpDialogString ) ; - strcat(lDialogString, "',") ; - } - if ( aDefaultInput ) - { - if ( strlen(aDefaultInput) ) - { - strcat(lDialogString, "initialvalue='") ; - strcat(lDialogString, aDefaultInput) ; - strcat(lDialogString, "',") ; - } - } - else - { - strcat(lDialogString, "show='*'") ; - } - strcat(lDialogString, ");\nif res is None :\n\tprint 0"); - strcat(lDialogString, "\nelse :\n\tprint '1'+res\n\"" ) ; - } - else if ( gdialogPresent() || xdialogPresent() || dialogName() || whiptailPresent() ) - { - if ( gdialogPresent( ) ) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"gdialog");return (char *)1;} - lWasGraphicDialog = 1 ; - lWasGdialog = 1 ; - strcpy( lDialogString , "(gdialog " ) ; - } - else if ( xdialogPresent( ) ) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"xdialog");return (char *)1;} - lWasGraphicDialog = 1 ; - strcpy( lDialogString , "(Xdialog " ) ; - } - else if ( dialogName( ) ) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"dialog");return (char *)0;} - if ( isTerminalRunning( ) ) - { - strcpy( lDialogString , "(dialog " ) ; - } - else - { - lWasXterm = 1 ; - strcpy( lDialogString , terminalName() ) ; - strcat( lDialogString , "'(" ) ; - strcat( lDialogString , dialogName() ) ; - strcat( lDialogString , " " ) ; - } - } - else if ( isTerminalRunning( ) ) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"whiptail");return (char *)0;} - strcpy( lDialogString , "(whiptail " ) ; - } - else - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"whiptail");return (char *)0;} - lWasXterm = 1 ; - strcpy( lDialogString , terminalName() ) ; - strcat( lDialogString , "'(whiptail " ) ; - } - - if ( aTitle && strlen(aTitle) ) - { - strcat(lDialogString, "--title \"") ; - strcat(lDialogString, aTitle) ; - strcat(lDialogString, "\" ") ; - } - - if ( !xdialogPresent() && !gdialogPresent() ) - { - strcat(lDialogString, "--backtitle \"") ; - strcat(lDialogString, "tab: move focus") ; - if ( ! aDefaultInput && !lWasGdialog ) - { - strcat(lDialogString, " (sometimes nothing, no blink nor star, is shown in text field)") ; - } - strcat(lDialogString, "\" ") ; - } - - if ( aDefaultInput || lWasGdialog ) - { - strcat( lDialogString , "--inputbox" ) ; - } - else - { - if ( !lWasGraphicDialog && dialogName() && isDialogVersionBetter09b() ) - { - strcat( lDialogString , "--insecure " ) ; - } - strcat( lDialogString , "--passwordbox" ) ; - } - strcat( lDialogString , " \"" ) ; - if ( aMessage && strlen(aMessage) ) - { - strcat(lDialogString, aMessage) ; - } - strcat(lDialogString,"\" 10 60 ") ; - if ( aDefaultInput && strlen(aDefaultInput) ) - { - strcat(lDialogString, "\"") ; - strcat(lDialogString, aDefaultInput) ; - strcat(lDialogString, "\" ") ; - } - if ( lWasGraphicDialog ) - { - strcat(lDialogString,") 2>/tmp/tinyfd.txt;\ - if [ $? = 0 ];then tinyfdBool=1;else tinyfdBool=0;fi;\ - tinyfdRes=$(cat /tmp/tinyfd.txt);echo $tinyfdBool$tinyfdRes") ; - } - else - { - strcat(lDialogString,">/dev/tty ) 2>/tmp/tinyfd.txt;\ - if [ $? = 0 ];then tinyfdBool=1;else tinyfdBool=0;fi;\ - tinyfdRes=$(cat /tmp/tinyfd.txt);echo $tinyfdBool$tinyfdRes") ; - - if ( lWasXterm ) - { - strcat(lDialogString," >/tmp/tinyfd0.txt';cat /tmp/tinyfd0.txt"); - } - else - { - strcat(lDialogString, "; clear >/dev/tty") ; - } - } - } - else if ( ! isTerminalRunning( ) && terminalName() ) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"basicinput");return (char *)0;} - lWasBasicXterm = 1 ; - strcpy( lDialogString , terminalName() ) ; - strcat( lDialogString , "'" ) ; - if ( !gWarningDisplayed && !tinyfd_forceConsole) - { - gWarningDisplayed = 1 ; - tinyfd_messageBox(gTitle,tinyfd_needs,"ok","warning",0); - } - if ( aTitle && strlen(aTitle) && !tinyfd_forceConsole) - { - strcat( lDialogString , "echo \"" ) ; - strcat( lDialogString, aTitle) ; - strcat( lDialogString , "\";echo;" ) ; - } - - strcat( lDialogString , "echo \"" ) ; - if ( aMessage && strlen(aMessage) ) - { - strcat( lDialogString, aMessage) ; - } - strcat( lDialogString , "\";read " ) ; - if ( ! aDefaultInput ) - { - strcat( lDialogString , "-s " ) ; - } - strcat( lDialogString , "-p \"" ) ; - strcat( lDialogString , "(esc+enter to cancel): \" ANSWER " ) ; - strcat( lDialogString , ";echo 1$ANSWER >/tmp/tinyfd.txt';" ) ; - strcat( lDialogString , "cat -v /tmp/tinyfd.txt"); - } - else if ( !gWarningDisplayed && ! isTerminalRunning( ) && ! terminalName() ) { - gWarningDisplayed = 1 ; - tinyfd_messageBox(gTitle,tinyfd_needs,"ok","warning",0); - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"no_solution");return (char *)0;} - free(lDialogString); - return NULL; - } - else - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"basicinput");return (char *)0;} - if ( !gWarningDisplayed && !tinyfd_forceConsole) - { - gWarningDisplayed = 1 ; - tinyfd_messageBox(gTitle,tinyfd_needs,"ok","warning",0); - } - if ( aTitle && strlen(aTitle) ) - { - printf("\n%s\n", aTitle); - } - if ( aMessage && strlen(aMessage) ) - { - printf("\n%s\n",aMessage); - } - printf("(esc+enter to cancel): "); fflush(stdout); - if ( ! aDefaultInput ) - { - tcgetattr(STDIN_FILENO, & oldt) ; - newt = oldt ; - newt.c_lflag &= ~ECHO ; - tcsetattr(STDIN_FILENO, TCSANOW, & newt); - } - - lEOF = fgets(lBuff, MAX_PATH_OR_CMD, stdin); - /* printf("lbuff<%c><%d>\n",lBuff[0],lBuff[0]); */ - if ( ! lEOF || (lBuff[0] == '\0') ) - { - free(lDialogString); - return NULL; - } - - if ( lBuff[0] == '\n' ) - { - lEOF = fgets(lBuff, MAX_PATH_OR_CMD, stdin); - /* printf("lbuff<%c><%d>\n",lBuff[0],lBuff[0]); */ - if ( ! lEOF || (lBuff[0] == '\0') ) - { - free(lDialogString); - return NULL; - } - } - - if ( ! aDefaultInput ) - { - tcsetattr(STDIN_FILENO, TCSANOW, & oldt); - printf("\n"); - } - printf("\n"); - if ( strchr(lBuff,27) ) - { - free(lDialogString); - return NULL ; - } - if ( lBuff[strlen( lBuff ) -1] == '\n' ) - { - lBuff[strlen( lBuff ) -1] = '\0' ; - } - free(lDialogString); - return lBuff ; - } - - if (tinyfd_verbose) printf( "lDialogString: %s\n" , lDialogString ) ; - lIn = popen( lDialogString , "r" ); - if ( ! lIn ) - { - if ( fileExists("/tmp/tinyfd.txt") ) - { - wipefile("/tmp/tinyfd.txt"); - remove("/tmp/tinyfd.txt"); - } - if ( fileExists("/tmp/tinyfd0.txt") ) - { - wipefile("/tmp/tinyfd0.txt"); - remove("/tmp/tinyfd0.txt"); - } - free(lDialogString); - return NULL ; - } - while ( fgets( lBuff , sizeof( lBuff ) , lIn ) != NULL ) - {} - - pclose( lIn ) ; - - if ( fileExists("/tmp/tinyfd.txt") ) - { - wipefile("/tmp/tinyfd.txt"); - remove("/tmp/tinyfd.txt"); - } - if ( fileExists("/tmp/tinyfd0.txt") ) - { - wipefile("/tmp/tinyfd0.txt"); - remove("/tmp/tinyfd0.txt"); - } - - /* printf( "len Buff: %lu\n" , strlen(lBuff) ) ; */ - /* printf( "lBuff0: %s\n" , lBuff ) ; */ - if ( lBuff[strlen( lBuff ) -1] == '\n' ) - { - lBuff[strlen( lBuff ) -1] = '\0' ; - } - /* printf( "lBuff1: %s len: %lu \n" , lBuff , strlen(lBuff) ) ; */ - if ( lWasBasicXterm ) - { - if ( strstr(lBuff,"^[") ) /* esc was pressed */ - { - free(lDialogString); - return NULL ; - } - } - - lResult = strncmp( lBuff , "1" , 1) ? 0 : 1 ; - /* printf( "lResult: %d \n" , lResult ) ; */ - if ( ! lResult ) - { - free(lDialogString); - return NULL ; - } - - /* printf( "lBuff+1: %s\n" , lBuff+1 ) ; */ - free(lDialogString); - return lBuff+1 ; -} - - -char * tinyfd_saveFileDialog( - char const * aTitle , /* NULL or "" */ - char const * aDefaultPathAndFile , /* NULL or "" */ - int aNumOfFilterPatterns , /* 0 */ - char const * const * aFilterPatterns , /* NULL or {"*.txt","*.doc"} */ - char const * aSingleFilterDescription ) /* NULL or "text files" */ -{ - static char lBuff[MAX_PATH_OR_CMD] ; - char lDialogString[MAX_PATH_OR_CMD] ; - char lString[MAX_PATH_OR_CMD] ; - int i ; - int lWasGraphicDialog = 0 ; - int lWasXterm = 0 ; - char * p ; - char * lPointerInputBox ; - FILE * lIn ; - lBuff[0]='\0'; - - if ( ! aFilterPatterns ) aNumOfFilterPatterns = 0 ; - if (tfd_quoteDetected(aTitle)) return tinyfd_saveFileDialog("INVALID TITLE WITH QUOTES", aDefaultPathAndFile, aNumOfFilterPatterns, aFilterPatterns, aSingleFilterDescription); - if (tfd_quoteDetected(aDefaultPathAndFile)) return tinyfd_saveFileDialog(aTitle, "INVALID DEFAULT_PATH WITH QUOTES: use the GRAVE ACCENT \\x60 instead.", aNumOfFilterPatterns, aFilterPatterns, aSingleFilterDescription); - if (tfd_quoteDetected(aSingleFilterDescription)) return tinyfd_saveFileDialog(aTitle, aDefaultPathAndFile, aNumOfFilterPatterns, aFilterPatterns, "INVALID FILTER_DESCRIPTION WITH QUOTES: use the GRAVE ACCENT \\x60 instead."); - for (i = 0; i < aNumOfFilterPatterns; i++) - { - if (tfd_quoteDetected(aFilterPatterns[i])) return tinyfd_saveFileDialog("INVALID FILTER_PATTERN WITH QUOTES: use the GRAVE ACCENT \\x60 instead.", aDefaultPathAndFile, 0, NULL, NULL); - } - - if ( osascriptPresent( ) ) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"applescript");return (char *)1;} - strcpy( lDialogString , "osascript "); - if ( ! osx9orBetter() ) strcat( lDialogString , " -e 'tell application \"Finder\"' -e 'Activate'"); - strcat( lDialogString , " -e 'try' -e 'POSIX path of ( choose file name " ); - if ( aTitle && strlen(aTitle) ) - { - strcat(lDialogString, "with prompt \"") ; - strcat(lDialogString, aTitle) ; - strcat(lDialogString, "\" ") ; - } - getPathWithoutFinalSlash( lString , aDefaultPathAndFile ) ; - if ( strlen(lString) ) - { - strcat(lDialogString, "default location \"") ; - strcat(lDialogString, lString ) ; - strcat(lDialogString , "\" " ) ; - } - getLastName( lString , aDefaultPathAndFile ) ; - if ( strlen(lString) ) - { - strcat(lDialogString, "default name \"") ; - strcat(lDialogString, lString ) ; - strcat(lDialogString , "\" " ) ; - } - strcat( lDialogString , ")' " ) ; - strcat(lDialogString, "-e 'on error number -128' " ) ; - strcat(lDialogString, "-e 'end try'") ; - if ( ! osx9orBetter() ) strcat( lDialogString, " -e 'end tell'") ; - } - else if ( tfd_kdialogPresent() ) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"kdialog");return (char *)1;} - - strcpy( lDialogString , "kdialog" ) ; - if ( (tfd_kdialogPresent() == 2) && tfd_xpropPresent() ) - { - strcat(lDialogString, " --attach=$(xprop -root 32x '\t$0' _NET_ACTIVE_WINDOW | cut -f 2)"); /* contribution: Paul Rouget */ - } - strcat( lDialogString , " --getsavefilename " ) ; - - if ( aDefaultPathAndFile && strlen(aDefaultPathAndFile) ) - { - if ( aDefaultPathAndFile[0] != '/' ) - { - strcat(lDialogString, "$PWD/") ; - } - strcat(lDialogString, "\"") ; - strcat(lDialogString, aDefaultPathAndFile ) ; - strcat(lDialogString , "\"" ) ; - } - else - { - strcat(lDialogString, "$PWD/") ; - } - - if ( aNumOfFilterPatterns > 0 ) - { - strcat(lDialogString , " \"" ) ; - strcat( lDialogString , aFilterPatterns[0] ) ; - for ( i = 1 ; i < aNumOfFilterPatterns ; i ++ ) - { - strcat( lDialogString , " " ) ; - strcat( lDialogString , aFilterPatterns[i] ) ; - } - if ( aSingleFilterDescription && strlen(aSingleFilterDescription) ) - { - strcat( lDialogString , " | " ) ; - strcat( lDialogString , aSingleFilterDescription ) ; - } - strcat( lDialogString , "\"" ) ; - } - if ( aTitle && strlen(aTitle) ) - { - strcat(lDialogString, " --title \"") ; - strcat(lDialogString, aTitle) ; - strcat(lDialogString, "\"") ; - } - } - else if ( tfd_zenityPresent() || tfd_matedialogPresent() || tfd_shellementaryPresent() || tfd_qarmaPresent() ) - { - if ( tfd_zenityPresent() ) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"zenity");return (char *)1;} - strcpy( lDialogString , "zenity" ) ; - if ( (tfd_zenity3Present() >= 4) && !getenv("SSH_TTY") && tfd_xpropPresent() ) - { - strcat( lDialogString, " --attach=$(sleep .01;xprop -root 32x '\t$0' _NET_ACTIVE_WINDOW | cut -f 2)"); /* contribution: Paul Rouget */ - } - } - else if ( tfd_matedialogPresent() ) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"matedialog");return (char *)1;} - strcpy( lDialogString , "matedialog" ) ; - } - else if ( tfd_shellementaryPresent() ) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"shellementary");return (char *)1;} - strcpy( lDialogString , "shellementary" ) ; - } - else - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"qarma");return (char *)1;} - strcpy( lDialogString , "qarma" ) ; - if ( !getenv("SSH_TTY") && tfd_xpropPresent() ) - { - strcat(lDialogString, " --attach=$(xprop -root 32x '\t$0' _NET_ACTIVE_WINDOW | cut -f 2)"); /* contribution: Paul Rouget */ - } - } - strcat(lDialogString, " --file-selection --save --confirm-overwrite" ) ; - - strcat(lDialogString, " --title=\"") ; - if (aTitle && strlen(aTitle)) strcat(lDialogString, aTitle) ; - strcat(lDialogString, "\"") ; - - if ( aDefaultPathAndFile && strlen(aDefaultPathAndFile) ) - { - strcat(lDialogString, " --filename=\"") ; - strcat(lDialogString, aDefaultPathAndFile) ; - strcat(lDialogString, "\"") ; - } - if ( aNumOfFilterPatterns > 0 ) - { - strcat( lDialogString , " --file-filter='" ) ; - if ( aSingleFilterDescription && strlen(aSingleFilterDescription) ) - { - strcat( lDialogString , aSingleFilterDescription ) ; - strcat( lDialogString , " |" ) ; - } - for ( i = 0 ; i < aNumOfFilterPatterns ; i ++ ) - { - strcat( lDialogString , " " ) ; - strcat( lDialogString , aFilterPatterns[i] ) ; - } - strcat( lDialogString , "' --file-filter='All files | *'" ) ; - } - if (tinyfd_silent) strcat( lDialogString , " 2>/dev/null "); - } - else if (tfd_yadPresent()) - { - if (aTitle && !strcmp(aTitle, "tinyfd_query")) { strcpy(tinyfd_response, "yad"); return (char*)1; } - strcpy(lDialogString, "yad --file --save --confirm-overwrite"); - if (aTitle && strlen(aTitle)) - { - strcat(lDialogString, " --title=\""); - strcat(lDialogString, aTitle); - strcat(lDialogString, "\""); - } - if (aDefaultPathAndFile && strlen(aDefaultPathAndFile)) - { - strcat(lDialogString, " --filename=\""); - strcat(lDialogString, aDefaultPathAndFile); - strcat(lDialogString, "\""); - } - if (aNumOfFilterPatterns > 0) - { - strcat(lDialogString, " --file-filter='"); - if (aSingleFilterDescription && strlen(aSingleFilterDescription)) - { - strcat(lDialogString, aSingleFilterDescription); - strcat(lDialogString, " |"); - } - for (i = 0; i < aNumOfFilterPatterns; i++) - { - strcat(lDialogString, " "); - strcat(lDialogString, aFilterPatterns[i]); - } - strcat(lDialogString, "' --file-filter='All files | *'"); - } - if (tinyfd_silent) strcat(lDialogString, " 2>/dev/null "); - } - else if ( !xdialogPresent() && tkinter3Present( ) ) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"python3-tkinter");return (char *)1;} - strcpy( lDialogString , gPython3Name ) ; - strcat( lDialogString , - " -S -c \"import tkinter;from tkinter import filedialog;root=tkinter.Tk();root.withdraw();"); - strcat( lDialogString , "res=filedialog.asksaveasfilename("); - if ( aTitle && strlen(aTitle) ) - { - strcat(lDialogString, "title='") ; - strcat(lDialogString, aTitle) ; - strcat(lDialogString, "',") ; - } - if ( aDefaultPathAndFile && strlen(aDefaultPathAndFile) ) - { - getPathWithoutFinalSlash( lString , aDefaultPathAndFile ) ; - if ( strlen(lString) ) - { - strcat(lDialogString, "initialdir='") ; - strcat(lDialogString, lString ) ; - strcat(lDialogString , "'," ) ; - } - getLastName( lString , aDefaultPathAndFile ) ; - if ( strlen(lString) ) - { - strcat(lDialogString, "initialfile='") ; - strcat(lDialogString, lString ) ; - strcat(lDialogString , "'," ) ; - } - } - if ( ( aNumOfFilterPatterns > 1 ) - || ( (aNumOfFilterPatterns == 1) /* test because poor osx behaviour */ - && ( aFilterPatterns[0][strlen(aFilterPatterns[0])-1] != '*' ) ) ) - { - strcat(lDialogString , "filetypes=(" ) ; - strcat( lDialogString , "('" ) ; - if ( aSingleFilterDescription && strlen(aSingleFilterDescription) ) - { - strcat( lDialogString , aSingleFilterDescription ) ; - } - strcat( lDialogString , "',(" ) ; - for ( i = 0 ; i < aNumOfFilterPatterns ; i ++ ) - { - strcat( lDialogString , "'" ) ; - strcat( lDialogString , aFilterPatterns[i] ) ; - strcat( lDialogString , "'," ) ; - } - strcat( lDialogString , "))," ) ; - strcat( lDialogString , "('All files','*'))" ) ; - } - strcat( lDialogString, ");\nif not isinstance(res, tuple):\n\tprint(res)\n\"" ) ; - } - else if ( !xdialogPresent() && tkinter2Present( ) ) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"python2-tkinter");return (char *)1;} - strcpy( lDialogString , "export PYTHONIOENCODING=utf-8;" ) ; - strcat( lDialogString , gPython2Name ) ; - if ( ! isTerminalRunning( ) && tfd_isDarwin( )) - { - strcat( lDialogString , " -i" ) ; /* for osx without console */ - } - strcat( lDialogString , -" -S -c \"import Tkinter,tkFileDialog;root=Tkinter.Tk();root.withdraw();"); - - if ( tfd_isDarwin( ) ) - { - strcat( lDialogString , -"import os;os.system('''/usr/bin/osascript -e 'tell app \\\"Finder\\\" to set\ - frontmost of process \\\"Python\\\" to true' ''');"); - } - - strcat( lDialogString , "res=tkFileDialog.asksaveasfilename("); - if ( aTitle && strlen(aTitle) ) - { - strcat(lDialogString, "title='") ; - strcat(lDialogString, aTitle) ; - strcat(lDialogString, "',") ; - } - if ( aDefaultPathAndFile && strlen(aDefaultPathAndFile) ) - { - getPathWithoutFinalSlash( lString , aDefaultPathAndFile ) ; - if ( strlen(lString) ) - { - strcat(lDialogString, "initialdir='") ; - strcat(lDialogString, lString ) ; - strcat(lDialogString , "'," ) ; - } - getLastName( lString , aDefaultPathAndFile ) ; - if ( strlen(lString) ) - { - strcat(lDialogString, "initialfile='") ; - strcat(lDialogString, lString ) ; - strcat(lDialogString , "'," ) ; - } - } - if ( ( aNumOfFilterPatterns > 1 ) - || ( (aNumOfFilterPatterns == 1) /* test because poor osx behaviour */ - && ( aFilterPatterns[0][strlen(aFilterPatterns[0])-1] != '*' ) ) ) - { - strcat(lDialogString , "filetypes=(" ) ; - strcat( lDialogString , "('" ) ; - if ( aSingleFilterDescription && strlen(aSingleFilterDescription) ) - { - strcat( lDialogString , aSingleFilterDescription ) ; - } - strcat( lDialogString , "',(" ) ; - for ( i = 0 ; i < aNumOfFilterPatterns ; i ++ ) - { - strcat( lDialogString , "'" ) ; - strcat( lDialogString , aFilterPatterns[i] ) ; - strcat( lDialogString , "'," ) ; - } - strcat( lDialogString , "))," ) ; - strcat( lDialogString , "('All files','*'))" ) ; - } - strcat( lDialogString, ");\nif not isinstance(res, tuple):\n\tprint res \n\"" ) ; - } - else if ( xdialogPresent() || dialogName() ) - { - if ( xdialogPresent( ) ) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"xdialog");return (char *)1;} - lWasGraphicDialog = 1 ; - strcpy( lDialogString , "(Xdialog " ) ; - } - else if ( isTerminalRunning( ) ) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"dialog");return (char *)0;} - strcpy( lDialogString , "(dialog " ) ; - } - else - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"dialog");return (char *)0;} - lWasXterm = 1 ; - strcpy( lDialogString , terminalName() ) ; - strcat( lDialogString , "'(" ) ; - strcat( lDialogString , dialogName() ) ; - strcat( lDialogString , " " ) ; - } - - if ( aTitle && strlen(aTitle) ) - { - strcat(lDialogString, "--title \"") ; - strcat(lDialogString, aTitle) ; - strcat(lDialogString, "\" ") ; - } - - if ( !xdialogPresent() && !gdialogPresent() ) - { - strcat(lDialogString, "--backtitle \"") ; - strcat(lDialogString, - "tab: focus | /: populate | spacebar: fill text field | ok: TEXT FIELD ONLY") ; - strcat(lDialogString, "\" ") ; - } - - strcat( lDialogString , "--fselect \"" ) ; - if ( aDefaultPathAndFile && strlen(aDefaultPathAndFile) ) - { - if ( ! strchr(aDefaultPathAndFile, '/') ) - { - strcat(lDialogString, "./") ; - } - strcat(lDialogString, aDefaultPathAndFile) ; - } - else if ( ! isTerminalRunning( ) && !lWasGraphicDialog ) - { - strcat(lDialogString, getenv("HOME")) ; - strcat(lDialogString, "/") ; - } - else - { - strcat(lDialogString, "./") ; - } - - if ( lWasGraphicDialog ) - { - strcat(lDialogString, "\" 0 60 ) 2>&1 ") ; - } - else - { - strcat(lDialogString, "\" 0 60 >/dev/tty) ") ; - if ( lWasXterm ) - { - strcat( lDialogString , - "2>/tmp/tinyfd.txt';cat /tmp/tinyfd.txt;rm /tmp/tinyfd.txt"); - } - else - { - strcat(lDialogString, "2>&1 ; clear >/dev/tty") ; - } - } - } - else - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){return tinyfd_inputBox(aTitle,NULL,NULL);} - strcpy(lBuff, "Save file in "); - strcat(lBuff, getCurDir()); - lPointerInputBox = tinyfd_inputBox(NULL, NULL, NULL); /* obtain a pointer on the current content of tinyfd_inputBox */ - if (lPointerInputBox) strcpy(lString, lPointerInputBox); /* preserve the current content of tinyfd_inputBox */ - p = tinyfd_inputBox(aTitle, lBuff, ""); - if (p) strcpy(lBuff, p); else lBuff[0] = '\0'; - if (lPointerInputBox) strcpy(lPointerInputBox, lString); /* restore its previous content to tinyfd_inputBox */ - p = lBuff; - - getPathWithoutFinalSlash( lString , p ) ; - if ( strlen( lString ) && ! dirExists( lString ) ) - { - return NULL ; - } - getLastName(lString,p); - if ( ! strlen(lString) ) - { - return NULL; - } - return p ; - } - - if (tinyfd_verbose) printf( "lDialogString: %s\n" , lDialogString ) ; - if ( ! ( lIn = popen( lDialogString , "r" ) ) ) - { - return NULL ; - } - while ( fgets( lBuff , sizeof( lBuff ) , lIn ) != NULL ) - {} - pclose( lIn ) ; - if ( lBuff[strlen( lBuff ) -1] == '\n' ) - { - lBuff[strlen( lBuff ) -1] = '\0' ; - } - /* printf( "lBuff: %s\n" , lBuff ) ; */ - if ( ! strlen(lBuff) ) - { - return NULL; - } - getPathWithoutFinalSlash( lString , lBuff ) ; - if ( strlen( lString ) && ! dirExists( lString ) ) - { - return NULL ; - } - getLastName(lString,lBuff); - if ( ! filenameValid(lString) ) - { - return NULL; - } - return lBuff ; -} - - -/* in case of multiple files, the separator is | */ -char * tinyfd_openFileDialog( - char const * aTitle , /* NULL or "" */ - char const * aDefaultPathAndFile , /* NULL or "" */ - int aNumOfFilterPatterns , /* 0 */ - char const * const * aFilterPatterns , /* NULL or {"*.jpg","*.png"} */ - char const * aSingleFilterDescription , /* NULL or "image files" */ - int aAllowMultipleSelects ) /* 0 or 1 */ -{ - char lDialogString[MAX_PATH_OR_CMD] ; - char lString[MAX_PATH_OR_CMD] ; - int i ; - FILE * lIn ; - char * p ; - char * lPointerInputBox ; - int lWasKdialog = 0 ; - int lWasGraphicDialog = 0 ; - int lWasXterm = 0 ; - size_t lFullBuffLen ; - static char * lBuff = NULL; - - if ( ! aFilterPatterns ) aNumOfFilterPatterns = 0 ; - if (tfd_quoteDetected(aTitle)) return tinyfd_openFileDialog("INVALID TITLE WITH QUOTES", aDefaultPathAndFile, aNumOfFilterPatterns, aFilterPatterns, aSingleFilterDescription, aAllowMultipleSelects); - if (tfd_quoteDetected(aDefaultPathAndFile)) return tinyfd_openFileDialog(aTitle, "INVALID DEFAULT_PATH WITH QUOTES: use the GRAVE ACCENT \\x60 instead.", aNumOfFilterPatterns, aFilterPatterns, aSingleFilterDescription, aAllowMultipleSelects); - if (tfd_quoteDetected(aSingleFilterDescription)) return tinyfd_openFileDialog(aTitle, aDefaultPathAndFile, aNumOfFilterPatterns, aFilterPatterns, "INVALID FILTER_DESCRIPTION WITH QUOTES: use the GRAVE ACCENT \\x60 instead.", aAllowMultipleSelects); - for (i = 0; i < aNumOfFilterPatterns; i++) - { - if (tfd_quoteDetected(aFilterPatterns[i])) return tinyfd_openFileDialog("INVALID FILTER_PATTERN WITH QUOTES: use the GRAVE ACCENT \\x60 instead.", aDefaultPathAndFile, 0, NULL, NULL, aAllowMultipleSelects); - } - - free(lBuff); - if (aTitle&&!strcmp(aTitle,"tinyfd_query")) - { - lBuff = NULL; - } - else - { - if (aAllowMultipleSelects) - { - lFullBuffLen = MAX_MULTIPLE_FILES * MAX_PATH_OR_CMD + 1; - lBuff = (char *)(malloc(lFullBuffLen * sizeof(char))); - if (!lBuff) - { - lFullBuffLen = LOW_MULTIPLE_FILES * MAX_PATH_OR_CMD + 1; - lBuff = (char *)( malloc( lFullBuffLen * sizeof(char))); - } - } - else - { - lFullBuffLen = MAX_PATH_OR_CMD + 1; - lBuff = (char *)(malloc(lFullBuffLen * sizeof(char))); - } - if (!lBuff) return NULL; - lBuff[0]='\0'; - } - - if ( osascriptPresent( ) ) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"applescript");return (char *)1;} - strcpy( lDialogString , "osascript "); - if ( ! osx9orBetter() ) strcat( lDialogString , " -e 'tell application \"System Events\"' -e 'Activate'"); - strcat( lDialogString , " -e 'try' -e '" ); - if ( ! aAllowMultipleSelects ) - { - - - strcat( lDialogString , "POSIX path of ( " ); - } - else - { - strcat( lDialogString , "set mylist to " ); - } - strcat( lDialogString , "choose file " ); - if ( aTitle && strlen(aTitle) ) - { - strcat(lDialogString, "with prompt \"") ; - strcat(lDialogString, aTitle) ; - strcat(lDialogString, "\" ") ; - } - getPathWithoutFinalSlash( lString , aDefaultPathAndFile ) ; - if ( strlen(lString) ) - { - strcat(lDialogString, "default location \"") ; - strcat(lDialogString, lString ) ; - strcat(lDialogString , "\" " ) ; - } - if ( aNumOfFilterPatterns > 0 ) - { - strcat(lDialogString , "of type {\"" ); - strcat( lDialogString , aFilterPatterns[0] + 2 ) ; - strcat( lDialogString , "\"" ) ; - for ( i = 1 ; i < aNumOfFilterPatterns ; i ++ ) - { - strcat( lDialogString , ",\"" ) ; - strcat( lDialogString , aFilterPatterns[i] + 2) ; - strcat( lDialogString , "\"" ) ; - } - strcat( lDialogString , "} " ) ; - } - if ( aAllowMultipleSelects ) - { - strcat( lDialogString , "multiple selections allowed true ' " ) ; - strcat( lDialogString , - "-e 'set mystring to POSIX path of item 1 of mylist' " ); - strcat( lDialogString , - "-e 'repeat with i from 2 to the count of mylist' " ); - strcat( lDialogString , "-e 'set mystring to mystring & \"|\"' " ); - strcat( lDialogString , - "-e 'set mystring to mystring & POSIX path of item i of mylist' " ); - strcat( lDialogString , "-e 'end repeat' " ); - strcat( lDialogString , "-e 'mystring' " ); - } - else - { - strcat( lDialogString , ")' " ) ; - } - strcat(lDialogString, "-e 'on error number -128' " ) ; - strcat(lDialogString, "-e 'end try'") ; - if ( ! osx9orBetter() ) strcat( lDialogString, " -e 'end tell'") ; - } - else if ( tfd_kdialogPresent() ) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"kdialog");return (char *)1;} - lWasKdialog = 1 ; - - strcpy( lDialogString , "kdialog" ) ; - if ( (tfd_kdialogPresent() == 2) && tfd_xpropPresent() ) - { - strcat(lDialogString, " --attach=$(xprop -root 32x '\t$0' _NET_ACTIVE_WINDOW | cut -f 2)"); /* contribution: Paul Rouget */ - } - strcat( lDialogString , " --getopenfilename " ) ; - - if ( aDefaultPathAndFile && strlen(aDefaultPathAndFile) ) - { - if ( aDefaultPathAndFile[0] != '/' ) - { - strcat(lDialogString, "$PWD/") ; - } - strcat(lDialogString, "\"") ; - strcat(lDialogString, aDefaultPathAndFile ) ; - strcat(lDialogString , "\"" ) ; - } - else - { - strcat(lDialogString, "$PWD/") ; - } - - if ( aNumOfFilterPatterns > 0 ) - { - strcat(lDialogString , " \"" ) ; - strcat( lDialogString , aFilterPatterns[0] ) ; - for ( i = 1 ; i < aNumOfFilterPatterns ; i ++ ) - { - strcat( lDialogString , " " ) ; - strcat( lDialogString , aFilterPatterns[i] ) ; - } - if ( aSingleFilterDescription && strlen(aSingleFilterDescription) ) - { - strcat( lDialogString , " | " ) ; - strcat( lDialogString , aSingleFilterDescription ) ; - } - strcat( lDialogString , "\"" ) ; - } - if ( aAllowMultipleSelects ) - { - strcat( lDialogString , " --multiple --separate-output" ) ; - } - if ( aTitle && strlen(aTitle) ) - { - strcat(lDialogString, " --title \"") ; - strcat(lDialogString, aTitle) ; - strcat(lDialogString, "\"") ; - } - } - else if ( tfd_zenityPresent() || tfd_matedialogPresent() || tfd_shellementaryPresent() || tfd_qarmaPresent() ) - { - if ( tfd_zenityPresent() ) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"zenity");return (char *)1;} - strcpy( lDialogString , "zenity" ) ; - if ( (tfd_zenity3Present() >= 4) && !getenv("SSH_TTY") && tfd_xpropPresent() ) - { - strcat( lDialogString, " --attach=$(sleep .01;xprop -root 32x '\t$0' _NET_ACTIVE_WINDOW | cut -f 2)"); /* contribution: Paul Rouget */ - } - } - else if ( tfd_matedialogPresent() ) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"matedialog");return (char *)1;} - strcpy( lDialogString , "matedialog" ) ; - } - else if ( tfd_shellementaryPresent() ) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"shellementary");return (char *)1;} - strcpy( lDialogString , "shellementary" ) ; - } - else - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"qarma");return (char *)1;} - strcpy( lDialogString , "qarma" ) ; - if ( !getenv("SSH_TTY") && tfd_xpropPresent() ) - { - strcat(lDialogString, " --attach=$(xprop -root 32x '\t$0' _NET_ACTIVE_WINDOW | cut -f 2)"); /* contribution: Paul Rouget */ - } - } - strcat( lDialogString , " --file-selection" ) ; - - if ( aAllowMultipleSelects ) - { - strcat( lDialogString , " --multiple" ) ; - } - - strcat(lDialogString, " --title=\"") ; - if (aTitle && strlen(aTitle)) strcat(lDialogString, aTitle) ; - strcat(lDialogString, "\"") ; - - if ( aDefaultPathAndFile && strlen(aDefaultPathAndFile) ) - { - strcat(lDialogString, " --filename=\"") ; - strcat(lDialogString, aDefaultPathAndFile) ; - strcat(lDialogString, "\"") ; - } - if ( aNumOfFilterPatterns > 0 ) - { - strcat( lDialogString , " --file-filter='" ) ; - if ( aSingleFilterDescription && strlen(aSingleFilterDescription) ) - { - strcat( lDialogString , aSingleFilterDescription ) ; - strcat( lDialogString , " |" ) ; - } - for ( i = 0 ; i < aNumOfFilterPatterns ; i ++ ) - { - strcat( lDialogString , " " ) ; - strcat( lDialogString , aFilterPatterns[i] ) ; - } - strcat( lDialogString , "' --file-filter='All files | *'" ) ; - } - if (tinyfd_silent) strcat( lDialogString , " 2>/dev/null "); - } - else if (tfd_yadPresent()) - { - if (aTitle && !strcmp(aTitle, "tinyfd_query")) { strcpy(tinyfd_response, "yad"); return (char*)1; } - strcpy(lDialogString, "yad --file"); - if (aAllowMultipleSelects) - { - strcat(lDialogString, " --multiple"); - } - if (aTitle && strlen(aTitle)) - { - strcat(lDialogString, " --title=\""); - strcat(lDialogString, aTitle); - strcat(lDialogString, "\""); - } - if (aDefaultPathAndFile && strlen(aDefaultPathAndFile)) - { - strcat(lDialogString, " --filename=\""); - strcat(lDialogString, aDefaultPathAndFile); - strcat(lDialogString, "\""); - } - if (aNumOfFilterPatterns > 0) - { - strcat(lDialogString, " --file-filter='"); - if (aSingleFilterDescription && strlen(aSingleFilterDescription)) - { - strcat(lDialogString, aSingleFilterDescription); - strcat(lDialogString, " |"); - } - for (i = 0; i < aNumOfFilterPatterns; i++) - { - strcat(lDialogString, " "); - strcat(lDialogString, aFilterPatterns[i]); - } - strcat(lDialogString, "' --file-filter='All files | *'"); - } - if (tinyfd_silent) strcat(lDialogString, " 2>/dev/null "); - } - else if ( tkinter3Present( ) ) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"python3-tkinter");return (char *)1;} - strcpy( lDialogString , gPython3Name ) ; - strcat( lDialogString , - " -S -c \"import tkinter;from tkinter import filedialog;root=tkinter.Tk();root.withdraw();"); - strcat( lDialogString , "lFiles=filedialog.askopenfilename("); - if ( aAllowMultipleSelects ) - { - strcat( lDialogString , "multiple=1," ) ; - } - if ( aTitle && strlen(aTitle) ) - { - strcat(lDialogString, "title='") ; - strcat(lDialogString, aTitle) ; - strcat(lDialogString, "',") ; - } - if ( aDefaultPathAndFile && strlen(aDefaultPathAndFile) ) - { - getPathWithoutFinalSlash( lString , aDefaultPathAndFile ) ; - if ( strlen(lString) ) - { - strcat(lDialogString, "initialdir='") ; - strcat(lDialogString, lString ) ; - strcat(lDialogString , "'," ) ; - } - getLastName( lString , aDefaultPathAndFile ) ; - if ( strlen(lString) ) - { - strcat(lDialogString, "initialfile='") ; - strcat(lDialogString, lString ) ; - strcat(lDialogString , "'," ) ; - } - } - if ( ( aNumOfFilterPatterns > 1 ) - || ( ( aNumOfFilterPatterns == 1 ) /*test because poor osx behaviour*/ - && ( aFilterPatterns[0][strlen(aFilterPatterns[0])-1] != '*' ) ) ) - { - strcat(lDialogString , "filetypes=(" ) ; - strcat( lDialogString , "('" ) ; - if ( aSingleFilterDescription && strlen(aSingleFilterDescription) ) - { - strcat( lDialogString , aSingleFilterDescription ) ; - } - strcat( lDialogString , "',(" ) ; - for ( i = 0 ; i < aNumOfFilterPatterns ; i ++ ) - { - strcat( lDialogString , "'" ) ; - strcat( lDialogString , aFilterPatterns[i] ) ; - strcat( lDialogString , "'," ) ; - } - strcat( lDialogString , "))," ) ; - strcat( lDialogString , "('All files','*'))" ) ; - } - strcat( lDialogString , ");\ -\nif not isinstance(lFiles, tuple):\n\tprint(lFiles)\nelse:\ -\n\tlFilesString=''\n\tfor lFile in lFiles:\n\t\tlFilesString+=str(lFile)+'|'\ -\n\tprint(lFilesString[:-1])\n\"" ) ; - } - else if ( tkinter2Present( ) ) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"python2-tkinter");return (char *)1;} - strcpy( lDialogString , "export PYTHONIOENCODING=utf-8;" ) ; - strcat( lDialogString , gPython2Name ) ; - if ( ! isTerminalRunning( ) && tfd_isDarwin( ) ) - { - strcat( lDialogString , " -i" ) ; /* for osx without console */ - } - strcat( lDialogString , -" -S -c \"import Tkinter,tkFileDialog;root=Tkinter.Tk();root.withdraw();"); - - if ( tfd_isDarwin( ) ) - { - strcat( lDialogString , -"import os;os.system('''/usr/bin/osascript -e 'tell app \\\"Finder\\\" to set \ -frontmost of process \\\"Python\\\" to true' ''');"); - } - strcat( lDialogString , "lFiles=tkFileDialog.askopenfilename("); - if ( aAllowMultipleSelects ) - { - strcat( lDialogString , "multiple=1," ) ; - } - if ( aTitle && strlen(aTitle) ) - { - strcat(lDialogString, "title='") ; - strcat(lDialogString, aTitle) ; - strcat(lDialogString, "',") ; - } - if ( aDefaultPathAndFile && strlen(aDefaultPathAndFile) ) - { - getPathWithoutFinalSlash( lString , aDefaultPathAndFile ) ; - if ( strlen(lString) ) - { - strcat(lDialogString, "initialdir='") ; - strcat(lDialogString, lString ) ; - strcat(lDialogString , "'," ) ; - } - getLastName( lString , aDefaultPathAndFile ) ; - if ( strlen(lString) ) - { - strcat(lDialogString, "initialfile='") ; - strcat(lDialogString, lString ) ; - strcat(lDialogString , "'," ) ; - } - } - if ( ( aNumOfFilterPatterns > 1 ) - || ( ( aNumOfFilterPatterns == 1 ) /*test because poor osx behaviour*/ - && ( aFilterPatterns[0][strlen(aFilterPatterns[0])-1] != '*' ) ) ) - { - strcat(lDialogString , "filetypes=(" ) ; - strcat( lDialogString , "('" ) ; - if ( aSingleFilterDescription && strlen(aSingleFilterDescription) ) - { - strcat( lDialogString , aSingleFilterDescription ) ; - } - strcat( lDialogString , "',(" ) ; - for ( i = 0 ; i < aNumOfFilterPatterns ; i ++ ) - { - strcat( lDialogString , "'" ) ; - strcat( lDialogString , aFilterPatterns[i] ) ; - strcat( lDialogString , "'," ) ; - } - strcat( lDialogString , "))," ) ; - strcat( lDialogString , "('All files','*'))" ) ; - } - strcat( lDialogString , ");\ -\nif not isinstance(lFiles, tuple):\n\tprint lFiles\nelse:\ -\n\tlFilesString=''\n\tfor lFile in lFiles:\n\t\tlFilesString+=str(lFile)+'|'\ -\n\tprint lFilesString[:-1]\n\"" ) ; - } - else if ( xdialogPresent() || dialogName() ) - { - if ( xdialogPresent( ) ) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"xdialog");return (char *)1;} - lWasGraphicDialog = 1 ; - strcpy( lDialogString , "(Xdialog " ) ; - } - else if ( isTerminalRunning( ) ) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"dialog");return (char *)0;} - strcpy( lDialogString , "(dialog " ) ; - } - else - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"dialog");return (char *)0;} - lWasXterm = 1 ; - strcpy( lDialogString , terminalName() ) ; - strcat( lDialogString , "'(" ) ; - strcat( lDialogString , dialogName() ) ; - strcat( lDialogString , " " ) ; - } - - if ( aTitle && strlen(aTitle) ) - { - strcat(lDialogString, "--title \"") ; - strcat(lDialogString, aTitle) ; - strcat(lDialogString, "\" ") ; - } - - if ( !xdialogPresent() && !gdialogPresent() ) - { - strcat(lDialogString, "--backtitle \"") ; - strcat(lDialogString, - "tab: focus | /: populate | spacebar: fill text field | ok: TEXT FIELD ONLY") ; - strcat(lDialogString, "\" ") ; - } - - strcat( lDialogString , "--fselect \"" ) ; - if ( aDefaultPathAndFile && strlen(aDefaultPathAndFile) ) - { - if ( ! strchr(aDefaultPathAndFile, '/') ) - { - strcat(lDialogString, "./") ; - } - strcat(lDialogString, aDefaultPathAndFile) ; - } - else if ( ! isTerminalRunning( ) && !lWasGraphicDialog ) - { - strcat(lDialogString, getenv("HOME")) ; - strcat(lDialogString, "/"); - } - else - { - strcat(lDialogString, "./") ; - } - - if ( lWasGraphicDialog ) - { - strcat(lDialogString, "\" 0 60 ) 2>&1 ") ; - } - else - { - strcat(lDialogString, "\" 0 60 >/dev/tty) ") ; - if ( lWasXterm ) - { - strcat( lDialogString , - "2>/tmp/tinyfd.txt';cat /tmp/tinyfd.txt;rm /tmp/tinyfd.txt"); - } - else - { - strcat(lDialogString, "2>&1 ; clear >/dev/tty") ; - } - } - } - else - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){return tinyfd_inputBox(aTitle,NULL,NULL);} - strcpy(lBuff, "Open file from "); - strcat(lBuff, getCurDir()); - lPointerInputBox = tinyfd_inputBox(NULL, NULL, NULL); /* obtain a pointer on the current content of tinyfd_inputBox */ - if (lPointerInputBox) strcpy(lDialogString, lPointerInputBox); /* preserve the current content of tinyfd_inputBox */ - p = tinyfd_inputBox(aTitle, lBuff, ""); - if ( p ) strcpy(lBuff, p); else lBuff[0] = '\0'; - if (lPointerInputBox) strcpy(lPointerInputBox, lDialogString); /* restore its previous content to tinyfd_inputBox */ - if ( ! fileExists(lBuff) ) - { - free(lBuff); - lBuff = NULL; - } - else - { - lBuff = (char *)( realloc( lBuff, (strlen(lBuff)+1) * sizeof(char))); - } - return lBuff ; - } - - if (tinyfd_verbose) printf( "lDialogString: %s\n" , lDialogString ) ; - if ( ! ( lIn = popen( lDialogString , "r" ) ) ) - { - free(lBuff); - lBuff = NULL; - return NULL ; - } - lBuff[0]='\0'; - p = lBuff; - while ( fgets( p , sizeof( lBuff ) , lIn ) != NULL ) - { - p += strlen( p ); - } - pclose( lIn ) ; - - if ( strlen( lBuff ) && lBuff[strlen( lBuff ) -1] == '\n' ) - { - lBuff[strlen( lBuff ) -1] = '\0' ; - } - /* printf( "strlen lBuff: %d\n" , strlen( lBuff ) ) ; */ - if ( lWasKdialog && aAllowMultipleSelects ) - { - p = lBuff ; - while ( ( p = strchr( p , '\n' ) ) ) - * p = '|' ; - } - /* printf( "lBuff2: %s\n" , lBuff ) ; */ - if ( ! strlen( lBuff ) ) - { - free(lBuff); - lBuff = NULL; - return NULL; - } - if ( aAllowMultipleSelects && strchr(lBuff, '|') ) - { - if( ! ensureFilesExist( lBuff , lBuff ) ) - { - free(lBuff); - lBuff = NULL; - return NULL; - } - } - else if ( !fileExists(lBuff) ) - { - free(lBuff); - lBuff = NULL; - return NULL; - } - - lBuff = (char *)( realloc( lBuff, (strlen(lBuff)+1) * sizeof(char))); - - /*printf( "lBuff3 [%lu]: %s\n" , strlen(lBuff) , lBuff ) ; */ - return lBuff ; -} - - -char * tinyfd_selectFolderDialog( - char const * aTitle , /* "" */ - char const * aDefaultPath ) /* "" */ -{ - static char lBuff[MAX_PATH_OR_CMD] ; - char lDialogString[MAX_PATH_OR_CMD] ; - FILE * lIn ; - char * p ; - char * lPointerInputBox ; - int lWasGraphicDialog = 0 ; - int lWasXterm = 0 ; - lBuff[0]='\0'; - - if (tfd_quoteDetected(aTitle)) return tinyfd_selectFolderDialog("INVALID TITLE WITH QUOTES", aDefaultPath); - if (tfd_quoteDetected(aDefaultPath)) return tinyfd_selectFolderDialog(aTitle, "INVALID DEFAULT_PATH WITH QUOTES: use the GRAVE ACCENT \\x60 instead."); - - if ( osascriptPresent( )) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"applescript");return (char *)1;} - strcpy( lDialogString , "osascript "); - if ( ! osx9orBetter() ) strcat( lDialogString , " -e 'tell application \"System Events\"' -e 'Activate'"); - strcat( lDialogString , " -e 'try' -e 'POSIX path of ( choose folder "); - if ( aTitle && strlen(aTitle) ) - { - strcat(lDialogString, "with prompt \"") ; - strcat(lDialogString, aTitle) ; - strcat(lDialogString, "\" ") ; - } - if ( aDefaultPath && strlen(aDefaultPath) ) - { - strcat(lDialogString, "default location \"") ; - strcat(lDialogString, aDefaultPath ) ; - strcat(lDialogString , "\" " ) ; - } - strcat( lDialogString , ")' " ) ; - strcat(lDialogString, "-e 'on error number -128' " ) ; - strcat(lDialogString, "-e 'end try'") ; - if ( ! osx9orBetter() ) strcat( lDialogString, " -e 'end tell'") ; - } - else if ( tfd_kdialogPresent() ) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"kdialog");return (char *)1;} - strcpy( lDialogString , "kdialog" ) ; - if ( (tfd_kdialogPresent() == 2) && tfd_xpropPresent() ) - { - strcat(lDialogString, " --attach=$(xprop -root 32x '\t$0' _NET_ACTIVE_WINDOW | cut -f 2)"); /* contribution: Paul Rouget */ - } - strcat( lDialogString , " --getexistingdirectory " ) ; - - if ( aDefaultPath && strlen(aDefaultPath) ) - { - if ( aDefaultPath[0] != '/' ) - { - strcat(lDialogString, "$PWD/") ; - } - strcat(lDialogString, "\"") ; - strcat(lDialogString, aDefaultPath ) ; - strcat(lDialogString , "\"" ) ; - } - else - { - strcat(lDialogString, "$PWD/") ; - } - - if ( aTitle && strlen(aTitle) ) - { - strcat(lDialogString, " --title \"") ; - strcat(lDialogString, aTitle) ; - strcat(lDialogString, "\"") ; - } - } - else if ( tfd_zenityPresent() || tfd_matedialogPresent() || tfd_shellementaryPresent() || tfd_qarmaPresent() ) - { - if ( tfd_zenityPresent() ) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"zenity");return (char *)1;} - strcpy( lDialogString , "zenity" ) ; - if ( (tfd_zenity3Present() >= 4) && !getenv("SSH_TTY") && tfd_xpropPresent() ) - { - strcat( lDialogString, " --attach=$(sleep .01;xprop -root 32x '\t$0' _NET_ACTIVE_WINDOW | cut -f 2)"); /* contribution: Paul Rouget */ - } - } - else if ( tfd_matedialogPresent() ) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"matedialog");return (char *)1;} - strcpy( lDialogString , "matedialog" ) ; - } - else if ( tfd_shellementaryPresent() ) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"shellementary");return (char *)1;} - strcpy( lDialogString , "shellementary" ) ; - } - else - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"qarma");return (char *)1;} - strcpy( lDialogString , "qarma" ) ; - if ( !getenv("SSH_TTY") && tfd_xpropPresent() ) - { - strcat(lDialogString, " --attach=$(xprop -root 32x '\t$0' _NET_ACTIVE_WINDOW | cut -f 2)"); /* contribution: Paul Rouget */ - } - } - strcat( lDialogString , " --file-selection --directory" ) ; - - strcat(lDialogString, " --title=\"") ; - if (aTitle && strlen(aTitle)) strcat(lDialogString, aTitle) ; - strcat(lDialogString, "\"") ; - - if ( aDefaultPath && strlen(aDefaultPath) ) - { - strcat(lDialogString, " --filename=\"") ; - strcat(lDialogString, aDefaultPath) ; - strcat(lDialogString, "\"") ; - } - if (tinyfd_silent) strcat( lDialogString , " 2>/dev/null "); - } - else if (tfd_yadPresent()) - { - if (aTitle && !strcmp(aTitle, "tinyfd_query")) { strcpy(tinyfd_response, "yad"); return (char*)1; } - strcpy(lDialogString, "yad --file --directory"); - if (aTitle && strlen(aTitle)) - { - strcat(lDialogString, " --title=\""); - strcat(lDialogString, aTitle); - strcat(lDialogString, "\""); - } - if (aDefaultPath && strlen(aDefaultPath)) - { - strcat(lDialogString, " --filename=\""); - strcat(lDialogString, aDefaultPath); - strcat(lDialogString, "\""); - } - if (tinyfd_silent) strcat(lDialogString, " 2>/dev/null "); - } - else if ( !xdialogPresent() && tkinter3Present( ) ) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"python3-tkinter");return (char *)1;} - strcpy( lDialogString , gPython3Name ) ; - strcat( lDialogString , - " -S -c \"import tkinter;from tkinter import filedialog;root=tkinter.Tk();root.withdraw();"); - strcat( lDialogString , "res=filedialog.askdirectory("); - if ( aTitle && strlen(aTitle) ) - { - strcat(lDialogString, "title='") ; - strcat(lDialogString, aTitle) ; - strcat(lDialogString, "',") ; - } - if ( aDefaultPath && strlen(aDefaultPath) ) - { - strcat(lDialogString, "initialdir='") ; - strcat(lDialogString, aDefaultPath ) ; - strcat(lDialogString , "'" ) ; - } - strcat( lDialogString, ");\nif not isinstance(res, tuple):\n\tprint(res)\n\"" ) ; - } - else if ( !xdialogPresent() && tkinter2Present( ) ) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"python2-tkinter");return (char *)1;} - strcpy( lDialogString , "export PYTHONIOENCODING=utf-8;" ) ; - strcat( lDialogString , gPython2Name ) ; - if ( ! isTerminalRunning( ) && tfd_isDarwin( ) ) - { - strcat( lDialogString , " -i" ) ; /* for osx without console */ - } - strcat( lDialogString , -" -S -c \"import Tkinter,tkFileDialog;root=Tkinter.Tk();root.withdraw();"); - - if ( tfd_isDarwin( ) ) - { - strcat( lDialogString , -"import os;os.system('''/usr/bin/osascript -e 'tell app \\\"Finder\\\" to set \ -frontmost of process \\\"Python\\\" to true' ''');"); - } - - strcat( lDialogString , "print tkFileDialog.askdirectory("); - if ( aTitle && strlen(aTitle) ) - { - strcat(lDialogString, "title='") ; - strcat(lDialogString, aTitle) ; - strcat(lDialogString, "',") ; - } - if ( aDefaultPath && strlen(aDefaultPath) ) - { - strcat(lDialogString, "initialdir='") ; - strcat(lDialogString, aDefaultPath ) ; - strcat(lDialogString , "'" ) ; - } - strcat( lDialogString , ")\"" ) ; - } - else if ( xdialogPresent() || dialogName() ) - { - if ( xdialogPresent( ) ) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"xdialog");return (char *)1;} - lWasGraphicDialog = 1 ; - strcpy( lDialogString , "(Xdialog " ) ; - } - else if ( isTerminalRunning( ) ) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"dialog");return (char *)0;} - strcpy( lDialogString , "(dialog " ) ; - } - else - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"dialog");return (char *)0;} - lWasXterm = 1 ; - strcpy( lDialogString , terminalName() ) ; - strcat( lDialogString , "'(" ) ; - strcat( lDialogString , dialogName() ) ; - strcat( lDialogString , " " ) ; - } - - if ( aTitle && strlen(aTitle) ) - { - strcat(lDialogString, "--title \"") ; - strcat(lDialogString, aTitle) ; - strcat(lDialogString, "\" ") ; - } - - if ( !xdialogPresent() && !gdialogPresent() ) - { - strcat(lDialogString, "--backtitle \"") ; - strcat(lDialogString, - "tab: focus | /: populate | spacebar: fill text field | ok: TEXT FIELD ONLY") ; - strcat(lDialogString, "\" ") ; - } - - strcat( lDialogString , "--dselect \"" ) ; - if ( aDefaultPath && strlen(aDefaultPath) ) - { - strcat(lDialogString, aDefaultPath) ; - ensureFinalSlash(lDialogString); - } - else if ( ! isTerminalRunning( ) && !lWasGraphicDialog ) - { - strcat(lDialogString, getenv("HOME")) ; - strcat(lDialogString, "/"); - } - else - { - strcat(lDialogString, "./") ; - } - - if ( lWasGraphicDialog ) - { - strcat(lDialogString, "\" 0 60 ) 2>&1 ") ; - } - else - { - strcat(lDialogString, "\" 0 60 >/dev/tty) ") ; - if ( lWasXterm ) - { - strcat( lDialogString , - "2>/tmp/tinyfd.txt';cat /tmp/tinyfd.txt;rm /tmp/tinyfd.txt"); - } - else - { - strcat(lDialogString, "2>&1 ; clear >/dev/tty") ; - } - } - } - else - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){return tinyfd_inputBox(aTitle,NULL,NULL);} - strcpy(lBuff, "Select folder from "); - strcat(lBuff, getCurDir()); - lPointerInputBox = tinyfd_inputBox(NULL, NULL, NULL); /* obtain a pointer on the current content of tinyfd_inputBox */ - if (lPointerInputBox) strcpy(lDialogString, lPointerInputBox); /* preserve the current content of tinyfd_inputBox */ - p = tinyfd_inputBox(aTitle, lBuff, ""); - if (p) strcpy(lBuff, p); else lBuff[0] = '\0'; - if (lPointerInputBox) strcpy(lPointerInputBox, lDialogString); /* restore its previous content to tinyfd_inputBox */ - p = lBuff; - - if ( !p || ! strlen( p ) || ! dirExists( p ) ) - { - return NULL ; - } - return p ; - } - if (tinyfd_verbose) printf( "lDialogString: %s\n" , lDialogString ) ; - if ( ! ( lIn = popen( lDialogString , "r" ) ) ) - { - return NULL ; - } - while ( fgets( lBuff , sizeof( lBuff ) , lIn ) != NULL ) - {} - pclose( lIn ) ; - if ( lBuff[strlen( lBuff ) -1] == '\n' ) - { - lBuff[strlen( lBuff ) -1] = '\0' ; - } - /* printf( "lBuff: %s\n" , lBuff ) ; */ - if ( ! strlen( lBuff ) || ! dirExists( lBuff ) ) - { - return NULL ; - } - return lBuff ; -} - - -/* aDefaultRGB is used only if aDefaultHexRGB is absent */ -/* aDefaultRGB and aoResultRGB can be the same array */ -/* returns NULL on cancel */ -/* returns the hexcolor as a string "#FF0000" */ -/* aoResultRGB also contains the result */ -char * tinyfd_colorChooser( - char const * aTitle , /* NULL or "" */ - char const * aDefaultHexRGB , /* NULL or "#FF0000"*/ - unsigned char const aDefaultRGB[3] , /* { 0 , 255 , 255 } */ - unsigned char aoResultRGB[3] ) /* { 0 , 0 , 0 } */ -{ - static char lDefaultHexRGB[16]; - char lBuff[128] ; - - char lTmp[128] ; -#if !((defined(__cplusplus ) && __cplusplus >= 201103L) || (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__clang__)) - char * lTmp2 ; -#endif - char lDialogString[MAX_PATH_OR_CMD] ; - unsigned char lDefaultRGB[3]; - char * p; - char * lPointerInputBox; - FILE * lIn ; - int i ; - int lWasZenity3 = 0 ; - int lWasOsascript = 0 ; - int lWasXdialog = 0 ; - lBuff[0]='\0'; - - if (tfd_quoteDetected(aTitle)) return tinyfd_colorChooser("INVALID TITLE WITH QUOTES", aDefaultHexRGB, aDefaultRGB, aoResultRGB); - if (tfd_quoteDetected(aDefaultHexRGB)) return tinyfd_colorChooser(aTitle, "INVALID DEFAULT_HEX_RGB WITH QUOTES: use the GRAVE ACCENT \\x60 instead.", aDefaultRGB, aoResultRGB); - - if (aDefaultHexRGB && (strlen(aDefaultHexRGB)==7) ) - { - Hex2RGB(aDefaultHexRGB, lDefaultRGB); - strcpy(lDefaultHexRGB, aDefaultHexRGB); - } - else - { - lDefaultRGB[0] = aDefaultRGB[0]; - lDefaultRGB[1] = aDefaultRGB[1]; - lDefaultRGB[2] = aDefaultRGB[2]; - RGB2Hex(aDefaultRGB, lDefaultHexRGB); - } - - if ( osascriptPresent( ) ) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"applescript");return (char *)1;} - lWasOsascript = 1 ; - strcpy( lDialogString , "osascript"); - - if ( ! osx9orBetter() ) - { - strcat( lDialogString , " -e 'tell application \"System Events\"' -e 'Activate'"); - strcat( lDialogString , " -e 'try' -e 'set mycolor to choose color default color {"); - } - else - { - strcat( lDialogString , -" -e 'try' -e 'tell app (path to frontmost application as Unicode text) \ -to set mycolor to choose color default color {"); - } - - sprintf(lTmp, "%d", 256 * lDefaultRGB[0] ) ; - strcat(lDialogString, lTmp ) ; - strcat(lDialogString, "," ) ; - sprintf(lTmp, "%d", 256 * lDefaultRGB[1] ) ; - strcat(lDialogString, lTmp ) ; - strcat(lDialogString, "," ) ; - sprintf(lTmp, "%d", 256 * lDefaultRGB[2] ) ; - strcat(lDialogString, lTmp ) ; - strcat(lDialogString, "}' " ) ; - strcat( lDialogString , -"-e 'set mystring to ((item 1 of mycolor) div 256 as integer) as string' " ); - strcat( lDialogString , -"-e 'repeat with i from 2 to the count of mycolor' " ); - strcat( lDialogString , -"-e 'set mystring to mystring & \" \" & ((item i of mycolor) div 256 as integer) as string' " ); - strcat( lDialogString , "-e 'end repeat' " ); - strcat( lDialogString , "-e 'mystring' "); - strcat(lDialogString, "-e 'on error number -128' " ) ; - strcat(lDialogString, "-e 'end try'") ; - if ( ! osx9orBetter() ) strcat( lDialogString, " -e 'end tell'") ; - } - else if ( tfd_kdialogPresent() ) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"kdialog");return (char *)1;} - strcpy( lDialogString , "kdialog" ) ; - if ( (tfd_kdialogPresent() == 2) && tfd_xpropPresent() ) - { - strcat(lDialogString, " --attach=$(xprop -root 32x '\t$0' _NET_ACTIVE_WINDOW | cut -f 2)"); /* contribution: Paul Rouget */ - } - sprintf( lDialogString + strlen(lDialogString) , " --getcolor --default '%s'" , lDefaultHexRGB ) ; - - if ( aTitle && strlen(aTitle) ) - { - strcat(lDialogString, " --title \"") ; - strcat(lDialogString, aTitle) ; - strcat(lDialogString, "\"") ; - } - } - else if ( tfd_zenity3Present() || tfd_matedialogPresent() || tfd_shellementaryPresent() || tfd_qarmaPresent() ) - { - lWasZenity3 = 1 ; - if ( tfd_zenity3Present() ) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"zenity3");return (char *)1;} - strcpy( lDialogString , "zenity" ); - if ( (tfd_zenity3Present() >= 4) && !getenv("SSH_TTY") && tfd_xpropPresent() ) - { - strcat( lDialogString, " --attach=$(sleep .01;xprop -root 32x '\t$0' _NET_ACTIVE_WINDOW | cut -f 2)"); /* contribution: Paul Rouget */ - } - } - else if ( tfd_matedialogPresent() ) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"matedialog");return (char *)1;} - strcpy( lDialogString , "matedialog" ) ; - } - else if ( tfd_shellementaryPresent() ) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"shellementary");return (char *)1;} - strcpy( lDialogString , "shellementary" ) ; - } - else - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"qarma");return (char *)1;} - strcpy( lDialogString , "qarma" ) ; - if ( !getenv("SSH_TTY") && tfd_xpropPresent() ) - { - strcat(lDialogString, " --attach=$(xprop -root 32x '\t$0' _NET_ACTIVE_WINDOW | cut -f 2)"); /* contribution: Paul Rouget */ - } - } - strcat( lDialogString , " --color-selection --show-palette" ) ; - sprintf( lDialogString + strlen(lDialogString), " --color=%s" , lDefaultHexRGB ) ; - - strcat(lDialogString, " --title=\"") ; - if (aTitle && strlen(aTitle)) strcat(lDialogString, aTitle) ; - strcat(lDialogString, "\"") ; - - if (tinyfd_silent) strcat( lDialogString , " 2>/dev/null "); - } - else if (tfd_yadPresent()) - { - if (aTitle && !strcmp(aTitle, "tinyfd_query")) { strcpy(tinyfd_response, "yad"); return (char*)1; } - strcpy(lDialogString, "yad --color"); - sprintf(lDialogString + strlen(lDialogString), " --init-color=%s", lDefaultHexRGB); - if (aTitle && strlen(aTitle)) - { - strcat(lDialogString, " --title=\""); - strcat(lDialogString, aTitle); - strcat(lDialogString, "\""); - } - if (tinyfd_silent) strcat(lDialogString, " 2>/dev/null "); - } - else if ( xdialogPresent() ) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"xdialog");return (char *)1;} - lWasXdialog = 1 ; - strcpy( lDialogString , "Xdialog --colorsel \"" ) ; - if ( aTitle && strlen(aTitle) ) - { - strcat(lDialogString, aTitle) ; - } - strcat(lDialogString, "\" 0 60 ") ; -#if (defined(__cplusplus ) && __cplusplus >= 201103L) || (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__clang__) - sprintf(lTmp,"%hhu %hhu %hhu",lDefaultRGB[0],lDefaultRGB[1],lDefaultRGB[2]); -#else - sprintf(lTmp,"%hu %hu %hu",lDefaultRGB[0],lDefaultRGB[1],lDefaultRGB[2]); -#endif - strcat(lDialogString, lTmp) ; - strcat(lDialogString, " 2>&1"); - } - else if ( tkinter3Present( ) ) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"python3-tkinter");return (char *)1;} - strcpy( lDialogString , gPython3Name ) ; - strcat( lDialogString , - " -S -c \"import tkinter;from tkinter import colorchooser;root=tkinter.Tk();root.withdraw();"); - strcat( lDialogString , "res=colorchooser.askcolor(color='" ) ; - strcat(lDialogString, lDefaultHexRGB ) ; - strcat(lDialogString, "'") ; - - if ( aTitle && strlen(aTitle) ) - { - strcat(lDialogString, ",title='") ; - strcat(lDialogString, aTitle) ; - strcat(lDialogString, "'") ; - } - strcat( lDialogString , ");\ -\nif res[1] is not None:\n\tprint(res[1])\"" ) ; - } - else if ( tkinter2Present( ) ) - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"python2-tkinter");return (char *)1;} - strcpy( lDialogString , "export PYTHONIOENCODING=utf-8;" ) ; - strcat( lDialogString , gPython2Name ) ; - if ( ! isTerminalRunning( ) && tfd_isDarwin( ) ) - { - strcat( lDialogString , " -i" ) ; /* for osx without console */ - } - - strcat( lDialogString , -" -S -c \"import Tkinter,tkColorChooser;root=Tkinter.Tk();root.withdraw();"); - - if ( tfd_isDarwin( ) ) - { - strcat( lDialogString , -"import os;os.system('''osascript -e 'tell app \\\"Finder\\\" to set \ -frontmost of process \\\"Python\\\" to true' ''');"); - } - - strcat( lDialogString , "res=tkColorChooser.askcolor(color='" ) ; - strcat(lDialogString, lDefaultHexRGB ) ; - strcat(lDialogString, "'") ; - - - if ( aTitle && strlen(aTitle) ) - { - strcat(lDialogString, ",title='") ; - strcat(lDialogString, aTitle) ; - strcat(lDialogString, "'") ; - } - strcat( lDialogString , ");\ -\nif res[1] is not None:\n\tprint res[1]\"" ) ; - } - else - { - if (aTitle&&!strcmp(aTitle,"tinyfd_query")){return tinyfd_inputBox(aTitle,NULL,NULL);} - lPointerInputBox = tinyfd_inputBox(NULL, NULL, NULL); /* obtain a pointer on the current content of tinyfd_inputBox */ - if (lPointerInputBox) strcpy(lDialogString, lPointerInputBox); /* preserve the current content of tinyfd_inputBox */ - p = tinyfd_inputBox(aTitle, "Enter hex rgb color (i.e. #f5ca20)", lDefaultHexRGB); - - if ( !p || (strlen(p) != 7) || (p[0] != '#') ) - { - return NULL ; - } - for ( i = 1 ; i < 7 ; i ++ ) - { - if ( ! isxdigit( (int) p[i] ) ) - { - return NULL ; - } - } - Hex2RGB(p,aoResultRGB); - strcpy(lDefaultHexRGB, p); - if (lPointerInputBox) strcpy(lPointerInputBox, lDialogString); /* restore its previous content to tinyfd_inputBox */ - return lDefaultHexRGB; - } - - if (tinyfd_verbose) printf( "lDialogString: %s\n" , lDialogString ) ; - if ( ! ( lIn = popen( lDialogString , "r" ) ) ) - { - return NULL ; - } - while ( fgets( lBuff , sizeof( lBuff ) , lIn ) != NULL ) - { - } - pclose( lIn ) ; - if ( ! strlen( lBuff ) ) - { - return NULL ; - } - /* printf( "len Buff: %lu\n" , strlen(lBuff) ) ; */ - /* printf( "lBuff0: %s\n" , lBuff ) ; */ - if ( lBuff[strlen( lBuff ) -1] == '\n' ) - { - lBuff[strlen( lBuff ) -1] = '\0' ; - } - - if ( lWasZenity3 ) - { - if ( lBuff[0] == '#' ) - { - if ( strlen(lBuff)>7 ) - { - lBuff[3]=lBuff[5]; - lBuff[4]=lBuff[6]; - lBuff[5]=lBuff[9]; - lBuff[6]=lBuff[10]; - lBuff[7]='\0'; - } - Hex2RGB(lBuff,aoResultRGB); - } - else if ( lBuff[3] == '(' ) { -#if (defined(__cplusplus ) && __cplusplus >= 201103L) || (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__clang__) - sscanf(lBuff,"rgb(%hhu,%hhu,%hhu", & aoResultRGB[0], & aoResultRGB[1],& aoResultRGB[2]); -#else - aoResultRGB[0] = strtol(lBuff+4, & lTmp2, 10 ); - aoResultRGB[1] = strtol(lTmp2+1, & lTmp2, 10 ); - aoResultRGB[2] = strtol(lTmp2+1, NULL, 10 ); -#endif - RGB2Hex(aoResultRGB,lBuff); - } - else if ( lBuff[4] == '(' ) { -#if (defined(__cplusplus ) && __cplusplus >= 201103L) || (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__clang__) - sscanf(lBuff,"rgba(%hhu,%hhu,%hhu", & aoResultRGB[0], & aoResultRGB[1],& aoResultRGB[2]); -#else - aoResultRGB[0] = strtol(lBuff+5, & lTmp2, 10 ); - aoResultRGB[1] = strtol(lTmp2+1, & lTmp2, 10 ); - aoResultRGB[2] = strtol(lTmp2+1, NULL, 10 ); -#endif - RGB2Hex(aoResultRGB,lBuff); - } - } - else if ( lWasOsascript || lWasXdialog ) - { - /* printf( "lBuff: %s\n" , lBuff ) ; */ -#if (defined(__cplusplus ) && __cplusplus >= 201103L) || (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__clang__) - sscanf(lBuff,"%hhu %hhu %hhu", & aoResultRGB[0], & aoResultRGB[1],& aoResultRGB[2]); -#else - aoResultRGB[0] = strtol(lBuff, & lTmp2, 10 ); - aoResultRGB[1] = strtol(lTmp2+1, & lTmp2, 10 ); - aoResultRGB[2] = strtol(lTmp2+1, NULL, 10 ); -#endif - RGB2Hex(aoResultRGB,lBuff); - } - else - { - Hex2RGB(lBuff,aoResultRGB); - } - /* printf("%d %d %d\n", aoResultRGB[0],aoResultRGB[1],aoResultRGB[2]); */ - /* printf( "lBuff: %s\n" , lBuff ) ; */ - - strcpy(lDefaultHexRGB,lBuff); - return lDefaultHexRGB ; -} - -#endif /* _WIN32 */ - - -/* Modified prototypes for R */ - -void tfd_messageBox( - char const * aTitle , - char const * aMessage , - char const * aDialogType , - char const * aIconType , - int * aiDefaultButton ) -{ - * aiDefaultButton = tinyfd_messageBox( aTitle , aMessage , aDialogType , aIconType , * aiDefaultButton ) ; -} - - -void tfd_inputBox( - char const * aTitle , - char const * aMessage , - char * * aiDefaultInput ) -{ - char * lReturnedInput ; - if ( ! strcmp( * aiDefaultInput , "NULL") ) lReturnedInput = tinyfd_inputBox( aTitle , aMessage , NULL ) ; - else lReturnedInput = tinyfd_inputBox( aTitle , aMessage , * aiDefaultInput ) ; - - if ( lReturnedInput ) strcpy ( * aiDefaultInput , lReturnedInput ) ; - else strcpy ( * aiDefaultInput , "NULL" ) ; -} - - -void tfd_saveFileDialog( - char const * aTitle , - char * * aiDefaultPathAndFile , - int const * aNumOfFilterPatterns , - char const * const * aFilterPatterns , - char const * aSingleFilterDescription ) -{ - char * lSavefile ; - - /* printf( "aFilterPatterns %s\n" , aFilterPatterns [0]); */ - - lSavefile = tinyfd_saveFileDialog( aTitle , * aiDefaultPathAndFile , * aNumOfFilterPatterns , - aFilterPatterns, aSingleFilterDescription ) ; - if ( lSavefile ) strcpy ( * aiDefaultPathAndFile , lSavefile ) ; - else strcpy ( * aiDefaultPathAndFile , "NULL" ) ; -} - - -void tfd_openFileDialog( - char const * aTitle , - char * * aiDefaultPathAndFile , - int const * aNumOfFilterPatterns , - char const * const * aFilterPatterns , - char const * aSingleFilterDescription , - int const * aAllowMultipleSelects ) -{ - char * lOpenfile ; - - /* printf( "aFilterPatterns %s\n" , aFilterPatterns [0]); */ - - lOpenfile = tinyfd_openFileDialog( aTitle , * aiDefaultPathAndFile , * aNumOfFilterPatterns , - aFilterPatterns , aSingleFilterDescription , * aAllowMultipleSelects ) ; - - if ( lOpenfile ) strcpy ( * aiDefaultPathAndFile , lOpenfile ) ; - else strcpy ( * aiDefaultPathAndFile , "NULL" ) ; -} - - -void tfd_selectFolderDialog( - char const * aTitle , - char * * aiDefaultPath ) -{ - char * lSelectedfolder ; - lSelectedfolder = tinyfd_selectFolderDialog( aTitle, * aiDefaultPath ) ; - if ( lSelectedfolder ) strcpy ( * aiDefaultPath , lSelectedfolder ) ; - else strcpy ( * aiDefaultPath , "NULL" ) ; -} - - -void tfd_colorChooser( - char const * aTitle , - char * * aiDefaultHexRGB ) -{ - unsigned char const aDefaultRGB [ 3 ] = {128,128,128} ; - unsigned char aoResultRGB [ 3 ] = {128,128,128} ; - char * lChosenColor ; - lChosenColor = tinyfd_colorChooser( aTitle, * aiDefaultHexRGB, aDefaultRGB, aoResultRGB ) ; - if ( lChosenColor ) strcpy ( * aiDefaultHexRGB , lChosenColor ) ; - else strcpy ( * aiDefaultHexRGB , "NULL" ) ; -} - -/* end of Modified prototypes for R */ - - - -/* -int main( int argc , char * argv[] ) -{ -char const * lTmp; -char const * lTheSaveFileName; -char const * lTheOpenFileName; -char const * lTheSelectFolderName; -char const * lTheHexColor; -char const * lWillBeGraphicMode; -unsigned char lRgbColor[3]; -FILE * lIn; -char lBuffer[1024]; -char lString[1024]; -char const * lFilterPatterns[2] = { "*.txt", "*.text" }; - -tinyfd_verbose = argc - 1; -tinyfd_silent = 1; - -lWillBeGraphicMode = tinyfd_inputBox("tinyfd_query", NULL, NULL); - -strcpy(lBuffer, "v"); -strcat(lBuffer, tinyfd_version); -if (lWillBeGraphicMode) -{ - strcat(lBuffer, "\ngraphic mode: "); -} -else -{ - strcat(lBuffer, "\nconsole mode: "); -} -strcat(lBuffer, tinyfd_response); -strcat(lBuffer, "\n"); -strcat(lBuffer, tinyfd_needs+78); -strcpy(lString, "tinyfiledialogs"); -tinyfd_messageBox(lString, lBuffer, "ok", "info", 0); - -tinyfd_notifyPopup("the title", "the message\n\tfrom outer-space", "info"); - -if (lWillBeGraphicMode && !tinyfd_forceConsole) -{ - tinyfd_forceConsole = ! tinyfd_messageBox("Hello World", - "graphic dialogs [yes] / console mode [no]?", - "yesno", "question", 1); -} - -lTmp = tinyfd_inputBox( - "a password box", "your password will be revealed", NULL); - -if (!lTmp) return 1; - -strcpy(lString, lTmp); - -lTheSaveFileName = tinyfd_saveFileDialog( - "let us save this password", - "passwordFile.txt", - 2, - lFilterPatterns, - NULL); - -if (!lTheSaveFileName) -{ - tinyfd_messageBox( - "Error", - "Save file name is NULL", - "ok", - "error", - 1); - return 1; -} - -lIn = fopen(lTheSaveFileName, "w"); -if (!lIn) -{ - tinyfd_messageBox( - "Error", - "Can not open this file in write mode", - "ok", - "error", - 1); - return 1; -} -fputs(lString, lIn); -fclose(lIn); - -lTheOpenFileName = tinyfd_openFileDialog( - "let us read the password back", - "", - 2, - lFilterPatterns, - NULL, - 0); - -if (!lTheOpenFileName) -{ - tinyfd_messageBox( - "Error", - "Open file name is NULL", - "ok", - "error", - 1); - return 1; -} - -lIn = fopen(lTheOpenFileName, "r"); - -if (!lIn) -{ - tinyfd_messageBox( - "Error", - "Can not open this file in read mode", - "ok", - "error", - 1); - return(1); -} -lBuffer[0] = '\0'; -fgets(lBuffer, sizeof(lBuffer), lIn); -fclose(lIn); - -tinyfd_messageBox("your password is", - lBuffer, "ok", "info", 1); - -lTheSelectFolderName = tinyfd_selectFolderDialog( - "let us just select a directory", NULL); - -if (!lTheSelectFolderName) -{ - tinyfd_messageBox( - "Error", - "Select folder name is NULL", - "ok", - "error", - 1); - return 1; -} - -tinyfd_messageBox("The selected folder is", - lTheSelectFolderName, "ok", "info", 1); - -lTheHexColor = tinyfd_colorChooser( - "choose a nice color", - "#FF0077", - lRgbColor, - lRgbColor); - -if (!lTheHexColor) -{ - tinyfd_messageBox( - "Error", - "hexcolor is NULL", - "ok", - "error", - 1); - return 1; -} - -tinyfd_messageBox("The selected hexcolor is", - lTheHexColor, "ok", "info", 1); - - tinyfd_beep(); - - return 0; -} -*/ - -#ifdef _MSC_VER -#pragma warning(default:4996) -#pragma warning(default:4100) -#pragma warning(default:4706) -#endif diff --git a/src/Engine/vendor/tinyfiledialogs/tinyfiledialogs.h b/src/Engine/vendor/tinyfiledialogs/tinyfiledialogs.h deleted file mode 100644 index 1a5bb50c..00000000 --- a/src/Engine/vendor/tinyfiledialogs/tinyfiledialogs.h +++ /dev/null @@ -1,315 +0,0 @@ -/* SPDX-License-Identifier: ZLIB -Copyright (c) 2014 - 2023 Guillaume Vareille http://ysengrin.com - -If you are using a C++ compiler to compile tinyfiledialogs.c (maybe renamed with the extension ".cpp") -then comment out << extern "C" >> bellow in this header file) - -********* TINY FILE DIALOGS OFFICIAL WEBSITE IS ON SOURCEFORGE ********* - _________ - / \ tinyfiledialogs.h v3.16 [Nov 23, 2023] - |tiny file| Unique header file created [November 9, 2014] - | dialogs | - \____ ___/ http://tinyfiledialogs.sourceforge.net - \| git clone http://git.code.sf.net/p/tinyfiledialogs/code tinyfd - ____________________________________________ -| | -| email: tinyfiledialogs at ysengrin.com | -|____________________________________________| - ________________________________________________________________________________ -| ____________________________________________________________________________ | -| | | | -| | - in tinyfiledialogs, char is UTF-8 by default (since v3.6) | | -| | | | -| | on windows: | | -| | - for UTF-16, use the wchar_t functions at the bottom of the header file | | -| | - _wfopen() requires wchar_t | | -| | | | -| | - but fopen() expects MBCS (not UTF-8) | | -| | - if you want char to be MBCS: set tinyfd_winUtf8 to 0 | | -| | | | -| | - alternatively, tinyfiledialogs provides | | -| | functions to convert between UTF-8, UTF-16 and MBCS | | -| |____________________________________________________________________________| | -|________________________________________________________________________________| - -If you like tinyfiledialogs, please upvote my stackoverflow answer -https://stackoverflow.com/a/47651444 - -- License - -This software is provided 'as-is', without any express or implied -warranty. In no event will the authors be held liable for any damages -arising from the use of this software. -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it -freely, subject to the following restrictions: -1. The origin of this software must not be misrepresented; you must not -claim that you wrote the original software. If you use this software -in a product, an acknowledgment in the product documentation would be -appreciated but is not required. -2. Altered source versions must be plainly marked as such, and must not be -misrepresented as being the original software. -3. This notice may not be removed or altered from any source distribution. - - __________________________________________ - | ______________________________________ | - | | | | - | | DO NOT USE USER INPUT IN THE DIALOGS | | - | |______________________________________| | - |__________________________________________| -*/ - -#ifndef TINYFILEDIALOGS_H -#define TINYFILEDIALOGS_H - -#ifdef __cplusplus -/* if tinydialogs.c is compiled as C++ code rather than C code, you may need to comment this out - and the corresponding closing bracket near the end of this file. */ -extern "C" { -#endif - -/******************************************************************************************************/ -/**************************************** UTF-8 on Windows ********************************************/ -/******************************************************************************************************/ -#ifdef _WIN32 -/* On windows, if you want to use UTF-8 ( instead of the UTF-16/wchar_t functions at the end of this file ) -Make sure your code is really prepared for UTF-8 (on windows, functions like fopen() expect MBCS and not UTF-8) */ -extern int tinyfd_winUtf8; /* on windows char strings can be 1:UTF-8(default) or 0:MBCS */ -/* for MBCS change this to 0, in tinyfiledialogs.c or in your code */ - -/* Here are some functions to help you convert between UTF-16 UTF-8 MBSC */ -char * tinyfd_utf8toMbcs(char const * aUtf8string); -char * tinyfd_utf16toMbcs(wchar_t const * aUtf16string); -wchar_t * tinyfd_mbcsTo16(char const * aMbcsString); -char * tinyfd_mbcsTo8(char const * aMbcsString); -wchar_t * tinyfd_utf8to16(char const * aUtf8string); -char * tinyfd_utf16to8(wchar_t const * aUtf16string); -#endif -/******************************************************************************************************/ -/******************************************************************************************************/ -/******************************************************************************************************/ - -/************* 3 funtions for C# (you don't need this in C or C++) : */ -char const * tinyfd_getGlobalChar(char const * aCharVariableName); /* returns NULL on error */ -int tinyfd_getGlobalInt(char const * aIntVariableName); /* returns -1 on error */ -int tinyfd_setGlobalInt(char const * aIntVariableName, int aValue); /* returns -1 on error */ -/* aCharVariableName: "tinyfd_version" "tinyfd_needs" "tinyfd_response" - aIntVariableName : "tinyfd_verbose" "tinyfd_silent" "tinyfd_allowCursesDialogs" - "tinyfd_forceConsole" "tinyfd_assumeGraphicDisplay" "tinyfd_winUtf8" -**************/ - -extern char tinyfd_version[8]; /* contains tinyfd current version number */ -extern char tinyfd_needs[]; /* info about requirements */ -extern int tinyfd_verbose; /* 0 (default) or 1 : on unix, prints the command line calls */ -extern int tinyfd_silent; /* 1 (default) or 0 : on unix, hide errors and warnings from called dialogs */ - -/** Curses dialogs are difficult to use and counter-intuitive. -On windows they are only ascii and still uses the unix backslash ! **/ -extern int tinyfd_allowCursesDialogs; /* 0 (default) or 1 */ - -extern int tinyfd_forceConsole; /* 0 (default) or 1 */ -/* for unix & windows: 0 (graphic mode) or 1 (console mode). -0: try to use a graphic solution, if it fails then it uses console mode. -1: forces all dialogs into console mode even when an X server is present. - if enabled, it can use the package Dialog or dialog.exe. - on windows it only make sense for console applications */ - -extern int tinyfd_assumeGraphicDisplay; /* 0 (default) or 1 */ -/* some systems don't set the environment variable DISPLAY even when a graphic display is present. -set this to 1 to tell tinyfiledialogs to assume the existence of a graphic display */ - -extern char tinyfd_response[1024]; -/* if you pass "tinyfd_query" as aTitle, -the functions will not display the dialogs -but will return 0 for console mode, 1 for graphic mode. -tinyfd_response is then filled with the retain solution. -possible values for tinyfd_response are (all lowercase) -for graphic mode: - windows_wchar windows applescript kdialog zenity zenity3 yad matedialog - shellementary qarma python2-tkinter python3-tkinter python-dbus - perl-dbus gxmessage gmessage xmessage xdialog gdialog dunst -for console mode: - dialog whiptail basicinput no_solution */ - -void tinyfd_beep(void); - -int tinyfd_notifyPopup( - char const * aTitle, /* NULL or "" */ - char const * aMessage, /* NULL or "" may contain \n \t */ - char const * aIconType); /* "info" "warning" "error" */ - /* return has only meaning for tinyfd_query */ - -int tinyfd_messageBox( - char const * aTitle , /* NULL or "" */ - char const * aMessage , /* NULL or "" may contain \n \t */ - char const * aDialogType , /* "ok" "okcancel" "yesno" "yesnocancel" */ - char const * aIconType , /* "info" "warning" "error" "question" */ - int aDefaultButton ) ; - /* 0 for cancel/no , 1 for ok/yes , 2 for no in yesnocancel */ - -char * tinyfd_inputBox( - char const * aTitle , /* NULL or "" */ - char const * aMessage , /* NULL or "" (\n and \t have no effect) */ - char const * aDefaultInput ) ; /* NULL = passwordBox, "" = inputbox */ - /* returns NULL on cancel */ - -char * tinyfd_saveFileDialog( - char const * aTitle , /* NULL or "" */ - char const * aDefaultPathAndFile , /* NULL or "" */ - int aNumOfFilterPatterns , /* 0 (1 in the following example) */ - char const * const * aFilterPatterns , /* NULL or char const * lFilterPatterns[1]={"*.txt"} */ - char const * aSingleFilterDescription ) ; /* NULL or "text files" */ - /* returns NULL on cancel */ - -char * tinyfd_openFileDialog( - char const * aTitle, /* NULL or "" */ - char const * aDefaultPathAndFile, /* NULL or "" */ - int aNumOfFilterPatterns , /* 0 (2 in the following example) */ - char const * const * aFilterPatterns, /* NULL or char const * lFilterPatterns[2]={"*.png","*.jpg"}; */ - char const * aSingleFilterDescription, /* NULL or "image files" */ - int aAllowMultipleSelects ) ; /* 0 or 1 */ - /* in case of multiple files, the separator is | */ - /* returns NULL on cancel */ - -char * tinyfd_selectFolderDialog( - char const * aTitle, /* NULL or "" */ - char const * aDefaultPath); /* NULL or "" */ - /* returns NULL on cancel */ - -char * tinyfd_colorChooser( - char const * aTitle, /* NULL or "" */ - char const * aDefaultHexRGB, /* NULL or "" or "#FF0000" */ - unsigned char const aDefaultRGB[3] , /* unsigned char lDefaultRGB[3] = { 0 , 128 , 255 }; */ - unsigned char aoResultRGB[3] ) ; /* unsigned char lResultRGB[3]; */ - /* aDefaultRGB is used only if aDefaultHexRGB is absent */ - /* aDefaultRGB and aoResultRGB can be the same array */ - /* returns NULL on cancel */ - /* returns the hexcolor as a string "#FF0000" */ - /* aoResultRGB also contains the result */ - - -/************ WINDOWS ONLY SECTION ************************/ -#ifdef _WIN32 - -/* windows only - utf-16 version */ -int tinyfd_notifyPopupW( - wchar_t const * aTitle, /* NULL or L"" */ - wchar_t const * aMessage, /* NULL or L"" may contain \n \t */ - wchar_t const * aIconType); /* L"info" L"warning" L"error" */ - -/* windows only - utf-16 version */ -int tinyfd_messageBoxW( - wchar_t const * aTitle, /* NULL or L"" */ - wchar_t const * aMessage, /* NULL or L"" may contain \n \t */ - wchar_t const * aDialogType, /* L"ok" L"okcancel" L"yesno" */ - wchar_t const * aIconType, /* L"info" L"warning" L"error" L"question" */ - int aDefaultButton ); /* 0 for cancel/no , 1 for ok/yes */ - /* returns 0 for cancel/no , 1 for ok/yes */ - -/* windows only - utf-16 version */ -wchar_t * tinyfd_inputBoxW( - wchar_t const * aTitle, /* NULL or L"" */ - wchar_t const * aMessage, /* NULL or L"" (\n nor \t not respected) */ - wchar_t const * aDefaultInput); /* NULL passwordBox, L"" inputbox */ - -/* windows only - utf-16 version */ -wchar_t * tinyfd_saveFileDialogW( - wchar_t const * aTitle, /* NULL or L"" */ - wchar_t const * aDefaultPathAndFile, /* NULL or L"" */ - int aNumOfFilterPatterns, /* 0 (1 in the following example) */ - wchar_t const * const * aFilterPatterns, /* NULL or wchar_t const * lFilterPatterns[1]={L"*.txt"} */ - wchar_t const * aSingleFilterDescription); /* NULL or L"text files" */ - /* returns NULL on cancel */ - -/* windows only - utf-16 version */ -wchar_t * tinyfd_openFileDialogW( - wchar_t const * aTitle, /* NULL or L"" */ - wchar_t const * aDefaultPathAndFile, /* NULL or L"" */ - int aNumOfFilterPatterns , /* 0 (2 in the following example) */ - wchar_t const * const * aFilterPatterns, /* NULL or wchar_t const * lFilterPatterns[2]={L"*.png","*.jpg"} */ - wchar_t const * aSingleFilterDescription, /* NULL or L"image files" */ - int aAllowMultipleSelects ) ; /* 0 or 1 */ - /* in case of multiple files, the separator is | */ - /* returns NULL on cancel */ - -/* windows only - utf-16 version */ -wchar_t * tinyfd_selectFolderDialogW( - wchar_t const * aTitle, /* NULL or L"" */ - wchar_t const * aDefaultPath); /* NULL or L"" */ - /* returns NULL on cancel */ - -/* windows only - utf-16 version */ -wchar_t * tinyfd_colorChooserW( - wchar_t const * aTitle, /* NULL or L"" */ - wchar_t const * aDefaultHexRGB, /* NULL or L"#FF0000" */ - unsigned char const aDefaultRGB[3], /* unsigned char lDefaultRGB[3] = { 0 , 128 , 255 }; */ - unsigned char aoResultRGB[3]); /* unsigned char lResultRGB[3]; */ - /* returns the hexcolor as a string L"#FF0000" */ - /* aoResultRGB also contains the result */ - /* aDefaultRGB is used only if aDefaultHexRGB is NULL */ - /* aDefaultRGB and aoResultRGB can be the same array */ - /* returns NULL on cancel */ - -#endif /*_WIN32 */ - -#ifdef __cplusplus -} /*extern "C"*/ -#endif - -#endif /* TINYFILEDIALOGS_H */ - -/* - ________________________________________________________________________________ -| ____________________________________________________________________________ | -| | | | -| | on windows: | | -| | - for UTF-16, use the wchar_t functions at the bottom of the header file | | -| | - _wfopen() requires wchar_t | | -| | | | -| | - in tinyfiledialogs, char is UTF-8 by default (since v3.6) | | -| | - but fopen() expects MBCS (not UTF-8) | | -| | - if you want char to be MBCS: set tinyfd_winUtf8 to 0 | | -| | | | -| | - alternatively, tinyfiledialogs provides | | -| | functions to convert between UTF-8, UTF-16 and MBCS | | -| |____________________________________________________________________________| | -|________________________________________________________________________________| - -- This is not for ios nor android (it works in termux though). -- The files can be renamed with extension ".cpp" as the code is 100% compatible C C++ - (just comment out << extern "C" >> in the header file) -- Windows is fully supported from XP to 10 (maybe even older versions) -- C# & LUA via dll, see files in the folder EXTRAS -- OSX supported from 10.4 to latest (maybe even older versions) -- Do not use " and ' as the dialogs will be displayed with a warning - instead of the title, message, etc... -- There's one file filter only, it may contain several patterns. -- If no filter description is provided, - the list of patterns will become the description. -- On windows link against Comdlg32.lib and Ole32.lib - (on windows the no linking claim is a lie) -- On unix: it tries command line calls, so no such need (NO LINKING). -- On unix you need one of the following: - applescript, kdialog, zenity, matedialog, shellementary, qarma, yad, - python (2 or 3)/tkinter/python-dbus (optional), Xdialog - or curses dialogs (opens terminal if running without console). -- One of those is already included on most (if not all) desktops. -- In the absence of those it will use gdialog, gxmessage or whiptail - with a textinputbox. If nothing is found, it switches to basic console input, - it opens a console if needed (requires xterm + bash). -- for curses dialogs you must set tinyfd_allowCursesDialogs=1 -- You can query the type of dialog that will be used (pass "tinyfd_query" as aTitle) -- String memory is preallocated statically for all the returned values. -- File and path names are tested before return, they should be valid. -- tinyfd_forceConsole=1; at run time, forces dialogs into console mode. -- On windows, console mode only make sense for console applications. -- On windows, console mode is not implemented for wchar_T UTF-16. -- Mutiple selects are not possible in console mode. -- The package dialog must be installed to run in curses dialogs in console mode. - It is already installed on most unix systems. -- On osx, the package dialog can be installed via - http://macappstore.org/dialog or http://macports.org -- On windows, for curses dialogs console mode, - dialog.exe should be copied somewhere on your executable path. - It can be found at the bottom of the following page: - http://andrear.altervista.org/home/cdialog.php -*/ diff --git a/src/LocalizationTool/Start.cpp b/src/LocalizationTool/Start.cpp index ddd7c236..f1de6a44 100644 --- a/src/LocalizationTool/Start.cpp +++ b/src/LocalizationTool/Start.cpp @@ -4,7 +4,7 @@ #include #include "LocalizationToolApplication.h" -gsl::not_null BeeEngine::CreateApplication(const BeeEngine::ApplicationArgs& args) +BeeEngine::Application* BeeEngine::CreateApplication(const BeeEngine::ApplicationArgs& args) { return new BeeEngine::LocalizationTool::LocalizationToolApplication({1280, 720, "BeeEngine Localization Tool", VSync::On}); -} \ No newline at end of file +} diff --git a/src/Runtime/CMakeLists.txt b/src/Runtime/CMakeLists.txt index bcef0db8..2e4969f4 100644 --- a/src/Runtime/CMakeLists.txt +++ b/src/Runtime/CMakeLists.txt @@ -17,9 +17,6 @@ configure_file(${BEE_CSHARP_LIBRARY_PATH}/BeeEngine.NativeBridge.dll ${CMAKE_CUR file(COPY ../Engine/Assets/Shaders DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) -add_compile_definitions(BEE_ENABLE_CHECKS) -add_compile_definitions($<$:BEE_ENABLE_PROFILING>) - include(InstallRequiredSystemLibraries) install(TARGETS GameRuntime DESTINATION bin) #install(FILES "${CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS}" DESTINATION bin) diff --git a/src/Runtime/Start.cpp b/src/Runtime/Start.cpp index 3c782236..1db7fcf7 100644 --- a/src/Runtime/Start.cpp +++ b/src/Runtime/Start.cpp @@ -2,7 +2,7 @@ #include #include -gsl::not_null BeeEngine::CreateApplication(const ApplicationArgs& args) +BeeEngine::Application* BeeEngine::CreateApplication(const ApplicationArgs& args) { BeeEngine::Runtime::RuntimeConfiguration config{ .GameConfig = BeeEngine::GameConfig::Deserialize(), .ApplicationProperties = {}, .ApplicationArgs = args}; diff --git a/src/Runtime/src/GameApplication.cpp b/src/Runtime/src/GameApplication.cpp index cd75cecd..de2e2400 100644 --- a/src/Runtime/src/GameApplication.cpp +++ b/src/Runtime/src/GameApplication.cpp @@ -18,7 +18,7 @@ namespace BeeEngine::Runtime LoadStartingScene(); FrameBufferPreferences preferences; - auto& window = *WindowHandler::GetInstance().get(); + auto& window = *WindowHandler::GetInstance(); preferences.Width = window.GetWidthInPixels(); preferences.Height = window.GetHeightInPixels(); preferences.SwapChainTarget = false; diff --git a/src/Runtime/src/GameLayer.cpp b/src/Runtime/src/GameLayer.cpp index f12757b5..f6b72b90 100644 --- a/src/Runtime/src/GameLayer.cpp +++ b/src/Runtime/src/GameLayer.cpp @@ -126,8 +126,8 @@ namespace BeeEngine::Runtime Entity GameLayer::GetHoveredEntity() { - int mouseX = gsl::narrow_cast(m_MousePosition.x * WindowHandler::GetInstance()->GetScaleFactor()); - int mouseY = gsl::narrow_cast(m_MousePosition.y * WindowHandler::GetInstance()->GetScaleFactor()); + int mouseX = narrow_cast(m_MousePosition.x * WindowHandler::GetInstance()->GetScaleFactor()); + int mouseY = narrow_cast(m_MousePosition.y * WindowHandler::GetInstance()->GetScaleFactor()); int pixelData = m_FrameBuffer->ReadPixel(1, mouseX, mouseY); pixelData--; // I make it -1 because entt starts from 0 and clear value for red integer in webgpu is // 0 and I need to make invalid number -1 too, so in scene I make + 1 diff --git a/src/tests/TransformTests.cpp b/src/tests/TransformTests.cpp index 62cc96e6..7122b8f6 100644 --- a/src/tests/TransformTests.cpp +++ b/src/tests/TransformTests.cpp @@ -7,8 +7,8 @@ #include #include #include -#include "gtc/epsilon.hpp" -#include "gtx/matrix_decompose.inl" +#include +#include using namespace BeeEngine; TEST(TransformComponentTest, GetTransform) { diff --git a/src/tests/tests_main.cpp b/src/tests/tests_main.cpp index 51f22319..e8d320b6 100644 --- a/src/tests/tests_main.cpp +++ b/src/tests/tests_main.cpp @@ -6,7 +6,7 @@ #include "gtest/gtest.h" #include "ApplicationInit.h" using namespace BeeEngine; -gsl::not_null BeeEngine::CreateApplication(const ApplicationArgs& args) +Application* BeeEngine::CreateApplication(const ApplicationArgs& args) { auto windowProperties = BeeEngine::ApplicationProperties{1280, 720, "BeeEngineTests", VSync::On}; int argc = args.GetArgc();