From f6df2bf1496ad30417275a0a82cc0d607b203141 Mon Sep 17 00:00:00 2001 From: CT5 <124994670+Cherrytree56567@users.noreply.github.com> Date: Sat, 14 Mar 2026 14:32:19 +1100 Subject: [PATCH] feat/fix: fixed storage error, added async stuff --- CMakeLists.txt | 2 + projects/WinDurango.Common/CMakeLists.txt | 4 +- .../Interfaces/Storage/Directory.h | 26 +- .../Interfaces/Storage/File.h | 15 ++ .../CMakeLists.txt | 7 +- .../Interfaces/Storage/Directory.h | 13 + .../Interfaces/Storage/File.h | 14 + .../src/interfaces/Storage/Directory.cpp | 251 +++++++++++++++++- .../src/interfaces/Storage/File.cpp | 227 ++++++++++++++++ projects/WinDurango.KernelX/CMakeLists.txt | 8 + .../WinDurango.KernelX/EraCoreApplication.h | 2 +- .../include/WinDurango.KernelX/Logan.h | 11 +- projects/WinDurango.KernelX/src/Hooks.cpp | 20 ++ projects/WinDurango.KernelX/src/kernelx.cpp | 2 +- projects/WinDurango.WinRT/CMakeLists.txt | 6 +- .../Windows.Xbox.Storage.ConnectedStorage.h | 15 +- ...s.Xbox.Storage.ConnectedStorageContainer.h | 4 +- ...ndows.Xbox.Storage.ConnectedStorageSpace.h | 9 +- .../WinDurango.WinRT/src/WinDurangoWinRT.cpp | 21 ++ .../Windows.Xbox.Storage.ConnectedStorage.cpp | 58 +++- ...ows.Xbox.Storage.ConnectedStorageSpace.cpp | 40 ++- 21 files changed, 719 insertions(+), 36 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e20eac2..5600735 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,7 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/) set(CMAKE_PDB_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/) add_subdirectory(projects/WinDurango.Common) +add_subdirectory(projects/WinDurango.MMDevAPI) add_subdirectory(projects/WinDurango.Implementation.WinRT) add_subdirectory(projects/WinDurango.Implementation.Native) add_subdirectory(projects/WinDurango.WinRT) @@ -18,6 +19,7 @@ add_subdirectory(projects/WinDurango.D3D11X) add_custom_target(WinDurango ALL DEPENDS WinDurango.Common + WinDurango.MMDevAPI WinDurango.Implementation.WinRT WinDurango.Implementation.Native WinDurango.WinRT diff --git a/projects/WinDurango.Common/CMakeLists.txt b/projects/WinDurango.Common/CMakeLists.txt index a0957ee..cad78c1 100644 --- a/projects/WinDurango.Common/CMakeLists.txt +++ b/projects/WinDurango.Common/CMakeLists.txt @@ -38,9 +38,11 @@ set(FILES FetchContent_Declare(json URL https://github.com/nlohmann/json/releases/download/v3.12.0/json.tar.xz) FetchContent_Declare(spdlog GIT_REPOSITORY https://github.com/Cherrytree56567/spdlog.git GIT_TAG v1.x) +FetchContent_Declare(concurrencpp GIT_REPOSITORY https://github.com/Cherrytree56567/concurrencpp.git GIT_TAG master) FetchContent_MakeAvailable(json) FetchContent_MakeAvailable(spdlog) +FetchContent_MakeAvailable(concurrencpp) add_library(WinDurango.Common SHARED ${FILES}) target_include_directories(WinDurango.Common PUBLIC @@ -50,7 +52,7 @@ target_include_directories(WinDurango.Common PUBLIC ${imgui_SOURCE_DIR} ) -target_link_libraries(WinDurango.Common PUBLIC nlohmann_json::nlohmann_json spdlog::spdlog) +target_link_libraries(WinDurango.Common PUBLIC nlohmann_json::nlohmann_json spdlog::spdlog concurrencpp::concurrencpp) target_compile_definitions(WinDurango.Common PUBLIC WINDURANGO_COMMON_COMPILER_NAME="${CMAKE_CXX_COMPILER_ID}" diff --git a/projects/WinDurango.Common/include/WinDurango.Common/Interfaces/Storage/Directory.h b/projects/WinDurango.Common/include/WinDurango.Common/Interfaces/Storage/Directory.h index 4c40251..15160c5 100644 --- a/projects/WinDurango.Common/include/WinDurango.Common/Interfaces/Storage/Directory.h +++ b/projects/WinDurango.Common/include/WinDurango.Common/Interfaces/Storage/Directory.h @@ -1,10 +1,13 @@ -// -// Created by DexrnZacAttack on 1/23/26 using zPc-i2. -// #pragma once #include "File.h" +#include +#include +#include +#include +#include #include #include +#include namespace wd::common::interfaces::storage { @@ -24,9 +27,7 @@ namespace wd::common::interfaces::storage } virtual bool open() = 0; - virtual std::shared_ptr CreateFile( - std::filesystem::path - path) = 0; // todo maybe return stream type, todo can we use this in uwp context??? I forgor + virtual std::shared_ptr CreateFile(std::filesystem::path path) = 0; // todo maybe return stream type, todo can we use this in uwp context??? I forgor virtual std::shared_ptr CreateFolder(std::filesystem::path path) = 0; virtual std::filesystem::path dirpath() = 0; @@ -37,5 +38,18 @@ namespace wd::common::interfaces::storage virtual bool copy(std::filesystem::path path) = 0; virtual bool dirExists(std::string) = 0; virtual bool fileExists(std::string) = 0; + + virtual concurrencpp::result openAsync() = 0; + virtual concurrencpp::result> CreateFileAsync(std::filesystem::path path) = 0; + virtual concurrencpp::result> CreateFolderAsync(std::filesystem::path path) = 0; + + virtual concurrencpp::result dirpathAsync() = 0; + + virtual concurrencpp::result renameAsync(std::string) = 0; + virtual concurrencpp::result removeAsync() = 0; + virtual concurrencpp::result moveAsync(std::filesystem::path path) = 0; + virtual concurrencpp::result copyAsync(std::filesystem::path path) = 0; + virtual concurrencpp::result dirExistsAsync(std::string) = 0; + virtual concurrencpp::result fileExistsAsync(std::string) = 0; }; } // namespace wd::common::interfaces::storage \ No newline at end of file diff --git a/projects/WinDurango.Common/include/WinDurango.Common/Interfaces/Storage/File.h b/projects/WinDurango.Common/include/WinDurango.Common/Interfaces/Storage/File.h index 623b392..1031851 100644 --- a/projects/WinDurango.Common/include/WinDurango.Common/Interfaces/Storage/File.h +++ b/projects/WinDurango.Common/include/WinDurango.Common/Interfaces/Storage/File.h @@ -4,6 +4,7 @@ #pragma once #include #include +#include namespace wd::common::interfaces::storage { @@ -30,5 +31,19 @@ namespace wd::common::interfaces::storage virtual bool remove() = 0; virtual bool move(std::filesystem::path path) = 0; virtual bool copy(std::filesystem::path path) = 0; + + virtual concurrencpp::result openAsync() = 0; + virtual concurrencpp::result createAsync() = 0; + virtual concurrencpp::result readAsync() = 0; + virtual concurrencpp::result writeAsync(std::string data) = 0; // write + virtual concurrencpp::result closeAsync() = 0; + + virtual concurrencpp::result filepathAsync() = 0; + virtual concurrencpp::result fullfilepathAsync() = 0; + + virtual concurrencpp::result renameAsync(std::string) = 0; + virtual concurrencpp::result removeAsync() = 0; + virtual concurrencpp::result moveAsync(std::filesystem::path path) = 0; + virtual concurrencpp::result copyAsync(std::filesystem::path path) = 0; }; } // namespace wd::common::interfaces::storage \ No newline at end of file diff --git a/projects/WinDurango.Implementation.WinRT/CMakeLists.txt b/projects/WinDurango.Implementation.WinRT/CMakeLists.txt index 6d375c3..7ee5bc2 100644 --- a/projects/WinDurango.Implementation.WinRT/CMakeLists.txt +++ b/projects/WinDurango.Implementation.WinRT/CMakeLists.txt @@ -6,6 +6,9 @@ set(CMAKE_CXX_STANDARD 20) find_package(cppwinrt CONFIG REQUIRED HINTS "${CMAKE_SOURCE_DIR}/vcpkg_installed/vcpkg/pkgs/cppwinrt_x64-windows/share/cppwinrt") +FetchContent_Declare(concurrencpp GIT_REPOSITORY https://github.com/Cherrytree56567/concurrencpp.git GIT_TAG master) +FetchContent_MakeAvailable(concurrencpp) + set(FILES include/WinDurango.Implementation.WinRT/Interfaces/Storage/Directory.h include/WinDurango.Implementation.WinRT/Interfaces/Storage/File.h @@ -32,7 +35,7 @@ set_property( "Microsoft.Windows.ImplementationLibrary_1.0.230629.1" ) -target_link_libraries(WinDurango.Implementation.WinRT PRIVATE WinDurango.Common Microsoft::CppWinRT) +target_link_libraries(WinDurango.Implementation.WinRT PRIVATE WinDurango.Common Microsoft::CppWinRT concurrencpp::concurrencpp) target_compile_definitions(WinDurango.Implementation.WinRT PUBLIC WINDURANGO_IMPLEMENTATION_WINRT_COMPILER_NAME="${CMAKE_CXX_COMPILER_ID}" @@ -45,4 +48,4 @@ target_compile_definitions(WinDurango.Implementation.WinRT PUBLIC set_target_properties(WinDurango.Implementation.WinRT PROPERTIES LINKER_LANGUAGE CXX) set_target_properties(${PROJECT_NAME} PROPERTIES VS_WINDOWS_TARGET_PLATFORM_MIN_VERSION 10.0.18362.0) -target_compile_definitions(WinDurango.Implementation.WinRT PRIVATE _WINRT_DLL WIN32_LEAN_AND_MEAN WINRT_LEAN_AND_MEAN) \ No newline at end of file +target_compile_definitions(WinDurango.Implementation.WinRT PRIVATE _WINRT_DLL WIN32_LEAN_AND_MEAN WINRT_LEAN_AND_MEAN NOMINMAX) \ No newline at end of file diff --git a/projects/WinDurango.Implementation.WinRT/include/WinDurango.Implementation.WinRT/Interfaces/Storage/Directory.h b/projects/WinDurango.Implementation.WinRT/include/WinDurango.Implementation.WinRT/Interfaces/Storage/Directory.h index 3157b23..6e9b744 100644 --- a/projects/WinDurango.Implementation.WinRT/include/WinDurango.Implementation.WinRT/Interfaces/Storage/Directory.h +++ b/projects/WinDurango.Implementation.WinRT/include/WinDurango.Implementation.WinRT/Interfaces/Storage/Directory.h @@ -36,6 +36,19 @@ namespace wd::impl::winrt::interfaces::storage virtual bool dirExists(std::string) override; virtual bool fileExists(std::string) override; + virtual concurrencpp::result openAsync() override; + virtual concurrencpp::result> CreateFileAsync(std::filesystem::path path) override; + virtual concurrencpp::result> CreateFolderAsync(std::filesystem::path path) override; + + virtual concurrencpp::result dirpathAsync() override; + + virtual concurrencpp::result renameAsync(std::string) override; + virtual concurrencpp::result removeAsync() override; + virtual concurrencpp::result moveAsync(std::filesystem::path path) override; + virtual concurrencpp::result copyAsync(std::filesystem::path path) override; + virtual concurrencpp::result dirExistsAsync(std::string) override; + virtual concurrencpp::result fileExistsAsync(std::string) override; + private: std::filesystem::path path; StorageFolder dir; diff --git a/projects/WinDurango.Implementation.WinRT/include/WinDurango.Implementation.WinRT/Interfaces/Storage/File.h b/projects/WinDurango.Implementation.WinRT/include/WinDurango.Implementation.WinRT/Interfaces/Storage/File.h index 48a17b8..7600a03 100644 --- a/projects/WinDurango.Implementation.WinRT/include/WinDurango.Implementation.WinRT/Interfaces/Storage/File.h +++ b/projects/WinDurango.Implementation.WinRT/include/WinDurango.Implementation.WinRT/Interfaces/Storage/File.h @@ -34,6 +34,20 @@ namespace wd::impl::winrt::interfaces::storage virtual bool move(std::filesystem::path path) override; virtual bool copy(std::filesystem::path path) override; + virtual concurrencpp::result openAsync() override; + virtual concurrencpp::result createAsync() override; + virtual concurrencpp::result readAsync() override; + virtual concurrencpp::result writeAsync(std::string data) override; + virtual concurrencpp::result closeAsync() override; + + virtual concurrencpp::result filepathAsync() override; + virtual concurrencpp::result fullfilepathAsync() override; + + virtual concurrencpp::result renameAsync(std::string) override; + virtual concurrencpp::result removeAsync() override; + virtual concurrencpp::result moveAsync(std::filesystem::path path) override; + virtual concurrencpp::result copyAsync(std::filesystem::path path) override; + private: std::filesystem::path path; StorageFile file; diff --git a/projects/WinDurango.Implementation.WinRT/src/interfaces/Storage/Directory.cpp b/projects/WinDurango.Implementation.WinRT/src/interfaces/Storage/Directory.cpp index 9ebbf52..c199d46 100644 --- a/projects/WinDurango.Implementation.WinRT/src/interfaces/Storage/Directory.cpp +++ b/projects/WinDurango.Implementation.WinRT/src/interfaces/Storage/Directory.cpp @@ -268,4 +268,253 @@ bool wd::impl::winrt::interfaces::storage::WinRTDirectory::fileExists(std::strin return false; } return false; -} \ No newline at end of file +} + +concurrencpp::result wd::impl::winrt::interfaces::storage::WinRTDirectory::openAsync() +{ + if (dir != nullptr) + { + co_return false; + } + try + { + StorageFolder sf = ApplicationData::Current().LocalFolder(); + + for (const auto &part : path) + { + hstring partStr = hstring(part.wstring()); + sf = co_await sf.GetFolderAsync(partStr); + } + + if (sf) + { + dir = sf; + co_return true; + } + } + catch (const hresult_error &ex) + { + co_return false; + } + co_return false; +} + +concurrencpp::result> wd::impl::winrt::interfaces::storage::WinRTDirectory::CreateFileAsync(std::filesystem::path targetPath) +{ + if (dir == nullptr) + { + co_return nullptr; + } + try + { + auto file = co_await dir.CreateFileAsync(hstring(targetPath.filename().wstring()), CreationCollisionOption::OpenIfExists); + std::shared_ptr fileRT = + std::make_shared(path / targetPath.filename()); + co_return fileRT; + } + catch (const hresult_error &ex) + { + co_return nullptr; + } +} + +concurrencpp::result> wd::impl::winrt::interfaces::storage::WinRTDirectory::CreateFolderAsync(std::filesystem::path targetPath) +{ + if (dir == nullptr) + { + co_return nullptr; + } + try + { + auto file = co_await dir.CreateFolderAsync(hstring(targetPath.filename().wstring()), CreationCollisionOption::OpenIfExists); + std::shared_ptr folderRT = + std::make_shared(path / targetPath.filename()); + co_return folderRT; + } + catch (const hresult_error &ex) + { + co_return nullptr; + } +} + +concurrencpp::result wd::impl::winrt::interfaces::storage::WinRTDirectory::dirpathAsync() +{ + co_return path; +} + +concurrencpp::result wd::impl::winrt::interfaces::storage::WinRTDirectory::renameAsync(std::string newName) +{ + if (dir == nullptr) + { + co_return false; + } + try + { + co_await dir.RenameAsync(to_hstring(newName)); + path.replace_filename(newName); + co_return true; + } + catch (const hresult_error &ex) + { + co_return false; + } + co_return false; +} + +concurrencpp::result wd::impl::winrt::interfaces::storage::WinRTDirectory::removeAsync() +{ + if (dir == nullptr) + { + co_return false; + } + try + { + co_await dir.DeleteAsync(); + co_return true; + } + catch (const hresult_error &ex) + { + co_return false; + } + co_return false; +} + +concurrencpp::result MoveFolderAsync(StorageFolder source, StorageFolder destinationContainer) +{ + try + { + StorageFolder destinationFolder = co_await destinationContainer.CreateFolderAsync(source.Name(), CreationCollisionOption::OpenIfExists); + + for (auto file : co_await source.GetFilesAsync()) + { + co_await file.MoveAsync(destinationFolder, file.Name(), NameCollisionOption::GenerateUniqueName); + } + + for (auto folder : co_await source.GetFoldersAsync()) + { + co_await MoveFolderAsync(folder, destinationFolder); + } + co_return true; + } + catch (const hresult_error &ex) + { + co_return false; + } +} + +concurrencpp::result wd::impl::winrt::interfaces::storage::WinRTDirectory::moveAsync(std::filesystem::path targetPath) +{ + if (dir == nullptr) + { + co_return false; + } + try + { + StorageFolder target = ApplicationData::Current().LocalFolder(); + + for (const auto &part : targetPath) + { + hstring partStr = hstring(part.wstring()); + target = co_await target.GetFolderAsync(partStr); + } + + if (co_await MoveFolderAsync(dir, target)) + { + path = targetPath; + co_return true; + } + } + catch (const hresult_error &ex) + { + co_return false; + } + co_return false; +} + +concurrencpp::result CopyFolderAsync(StorageFolder source, StorageFolder destinationContainer) +{ + try + { + StorageFolder destinationFolder = co_await destinationContainer.CreateFolderAsync(source.Name(), CreationCollisionOption::OpenIfExists); + + for (auto file : co_await source.GetFilesAsync()) + { + co_await file.CopyAsync(destinationFolder, file.Name(), NameCollisionOption::GenerateUniqueName); + } + + for (auto folder : co_await source.GetFoldersAsync()) + { + co_await CopyFolderAsync(folder, destinationFolder); + } + co_return true; + } + catch (const hresult_error &ex) + { + co_return false; + } +} + +concurrencpp::result wd::impl::winrt::interfaces::storage::WinRTDirectory::copyAsync(std::filesystem::path targetPath) +{ + if (dir == nullptr) + { + co_return false; + } + try + { + StorageFolder target = ApplicationData::Current().LocalFolder(); + + for (const auto &part : targetPath) + { + hstring partStr = hstring(part.wstring()); + target = co_await target.GetFolderAsync(partStr); + } + + if (co_await CopyFolderAsync(dir, target)) + { + path = targetPath; + co_return true; + } + } + catch (const hresult_error &ex) + { + co_return false; + } + co_return false; +} + +concurrencpp::result wd::impl::winrt::interfaces::storage::WinRTDirectory::dirExistsAsync(std::string name) +{ + if (dir == nullptr) + { + co_return false; + } + try + { + auto item = co_await dir.GetItemAsync(to_hstring(name)); + co_return item && item.IsOfType(StorageItemTypes::Folder); + } + catch (const hresult_error &ex) + { + co_return false; + } + co_return false; +} + +concurrencpp::result wd::impl::winrt::interfaces::storage::WinRTDirectory::fileExistsAsync(std::string name) +{ + if (dir == nullptr) + { + co_return false; + } + try + { + auto item = co_await dir.GetItemAsync(to_hstring(name)); + co_return item && item.IsOfType(StorageItemTypes::File); + } + catch (const hresult_error &ex) + { + co_return false; + } + co_return false; +} diff --git a/projects/WinDurango.Implementation.WinRT/src/interfaces/Storage/File.cpp b/projects/WinDurango.Implementation.WinRT/src/interfaces/Storage/File.cpp index 622c6ac..9c5214c 100644 --- a/projects/WinDurango.Implementation.WinRT/src/interfaces/Storage/File.cpp +++ b/projects/WinDurango.Implementation.WinRT/src/interfaces/Storage/File.cpp @@ -229,4 +229,231 @@ namespace wd::impl::winrt::interfaces::storage } return false; } + + concurrencpp::result WinRTFile::openAsync() + { + if (file != nullptr) + { + co_return false; + } + try + { + StorageFolder sf = ApplicationData::Current().LocalFolder(); + + for (const auto &part : path.parent_path()) + { + hstring partStr = hstring(part.wstring()); + sf = co_await sf.GetFolderAsync(partStr); + } + if (!sf) + { + co_return false; + } + + StorageFile npFile = co_await sf.GetFileAsync(hstring(path.filename().wstring())); + file = npFile; + if (!npFile) + { + co_return false; + } + } + catch (const hresult_error &ex) + { + co_return false; + } + co_return false; + } + + concurrencpp::result WinRTFile::createAsync() + { + if (file != nullptr) + { + co_return false; + } + try + { + StorageFolder sf = ApplicationData::Current().LocalFolder(); + + for (const auto &part : path.parent_path()) + { + hstring partStr = hstring(part.wstring()); + sf = co_await sf.GetFolderAsync(partStr); + } + if (!sf) + { + co_return false; + } + + file = co_await sf.CreateFileAsync(hstring(path.filename().wstring()), CreationCollisionOption::OpenIfExists); + if (!file) + { + co_return false; + } + co_return true; + } + catch (const hresult_error &ex) + { + co_return false; + } + co_return false; + } + + concurrencpp::result WinRTFile::readAsync() + { + if (file == nullptr) + { + co_return "Failed"; + } + try + { + co_return to_string(co_await FileIO::ReadTextAsync(file)); + } + catch (const hresult_error &ex) + { + co_return "Failed"; + } + co_return "Failed"; + } + + concurrencpp::result WinRTFile::writeAsync(std::string data) + { + if (file == nullptr) + { + co_return false; + } + try + { + co_await FileIO::WriteTextAsync(file, to_hstring(data)); + co_return true; + } + catch (const hresult_error &ex) + { + co_return false; + } + } + + concurrencpp::result WinRTFile::closeAsync() + { + if (file == nullptr) + { + co_return false; + } + file = nullptr; + co_return false; + } + + concurrencpp::result WinRTFile::filepathAsync() + { + co_return path; + } + + concurrencpp::result WinRTFile::fullfilepathAsync() + { + StorageFolder sf = ApplicationData::Current().LocalFolder(); + std::filesystem::path rootPath{sf.Path().c_str()}; + + co_return rootPath / path; + } + + concurrencpp::result WinRTFile::renameAsync(std::string name) + { + if (file == nullptr) + { + co_return false; + } + try + { + co_await file.RenameAsync(to_hstring(name), NameCollisionOption::GenerateUniqueName); + path.replace_filename(name); + co_return true; + } + catch (const hresult_error &ex) + { + co_return false; + } + co_return false; + } + + concurrencpp::result WinRTFile::removeAsync() + { + if (file == nullptr) + { + co_return false; + } + try + { + co_await file.DeleteAsync(); + co_return true; + } + catch (const hresult_error &ex) + { + co_return false; + } + co_return false; + } + + concurrencpp::result WinRTFile::moveAsync(std::filesystem::path targetPath) + { + if (file == nullptr) + { + co_return false; + } + try + { + StorageFolder target = ApplicationData::Current().LocalFolder(); + + for (const auto &part : targetPath.parent_path()) + { + hstring partStr = hstring(part.wstring()); + target = co_await target.GetFolderAsync(partStr); + } + if (!target) + { + co_return false; + } + + co_await file.MoveAsync(target); + + std::filesystem::path filename = path.filename(); + path = targetPath; + path.replace_filename(filename); + co_return true; + } + catch (const hresult_error &ex) + { + co_return false; + } + co_return false; + } + + concurrencpp::result WinRTFile::copyAsync(std::filesystem::path targetPath) + { + if (file == nullptr) + { + co_return false; + } + try + { + StorageFolder target = ApplicationData::Current().LocalFolder(); + + for (const auto &part : targetPath.parent_path()) + { + hstring partStr = hstring(part.wstring()); + target = co_await target.GetFolderAsync(partStr); + } + if (!target) + { + co_return false; + } + + co_await file.CopyAsync(target); + co_return true; + } + catch (const hresult_error &ex) + { + co_return false; + } + co_return false; + } + } // namespace wd::impl::winrt::interfaces::storage \ No newline at end of file diff --git a/projects/WinDurango.KernelX/CMakeLists.txt b/projects/WinDurango.KernelX/CMakeLists.txt index e799002..50fb436 100644 --- a/projects/WinDurango.KernelX/CMakeLists.txt +++ b/projects/WinDurango.KernelX/CMakeLists.txt @@ -4,6 +4,11 @@ project(WinDurango.KernelX VERSION 1.0.0) set(VERSION_SUFFIX "-dev.1") # used for non-stable versions, otherwise blank set(CMAKE_CXX_STANDARD 20) +FetchContent_Declare(concurrencpp GIT_REPOSITORY https://github.com/Cherrytree56567/concurrencpp.git GIT_TAG master) +FetchContent_MakeAvailable(concurrencpp) + +add_compile_definitions(NOMINMAX) + set(FILES src/kernelx.cpp src/dllmain.cpp @@ -20,6 +25,7 @@ add_library(WinDurango.KernelX SHARED ${FILES} "include/WinDurango.KernelX/EraCo target_link_libraries(WinDurango.KernelX PRIVATE WinDurango.Common WinDurango.Implementation.WinRT + concurrencpp::concurrencpp "${CMAKE_SOURCE_DIR}/vcpkg_installed/vcpkg/pkgs/detours_x64-windows/lib/detours.lib" ) @@ -35,6 +41,8 @@ target_include_directories(WinDurango.KernelX PUBLIC ${CMAKE_SOURCE_DIR}/vcpkg_installed/vcpkg/pkgs/detours_x64-windows/include/detours ) +target_compile_definitions(WinDurango.KernelX PUBLIC NOMINMAX) + set_target_properties(WinDurango.KernelX PROPERTIES OUTPUT_NAME "kernelx" ) \ No newline at end of file diff --git a/projects/WinDurango.KernelX/include/WinDurango.KernelX/EraCoreApplication.h b/projects/WinDurango.KernelX/include/WinDurango.KernelX/EraCoreApplication.h index 0e24f9d..aa186bc 100644 --- a/projects/WinDurango.KernelX/include/WinDurango.KernelX/EraCoreApplication.h +++ b/projects/WinDurango.KernelX/include/WinDurango.KernelX/EraCoreApplication.h @@ -154,7 +154,7 @@ class FrameworkViewEra : public IFrameworkView HRESULT Run() override { return m_realView->Run(); - } + } HRESULT Uninitialize() override { diff --git a/projects/WinDurango.KernelX/include/WinDurango.KernelX/Logan.h b/projects/WinDurango.KernelX/include/WinDurango.KernelX/Logan.h index e3145d3..0bb18aa 100644 --- a/projects/WinDurango.KernelX/include/WinDurango.KernelX/Logan.h +++ b/projects/WinDurango.KernelX/include/WinDurango.KernelX/Logan.h @@ -3,10 +3,19 @@ #include "kernelx.h" #include #include +#include // All of the types were provided by DaZombieKiller, a huge thanks to him! #include +#ifndef FIXmax +#define FIXmax(a,b) (((a) > (b)) ? (a) : (b)) +#endif + +#ifndef FIXmin +#define FIXmin(a,b) (((a) < (b)) ? (a) : (b)) +#endif + #define FILE_DEVICE_LOGAN 0x00008000 #define LOGAN_DEVICE_PATH "ACPI_HAL#Logan#0#{F764922A-DE30-40A5-A66E-C46CB191A1CD}" #define LOGAN_DEVICE_WPATH L"ACPI_HAL#Logan#0#{F764922A-DE30-40A5-A66E-C46CB191A1CD}" @@ -443,7 +452,7 @@ PVOID MemAlloc(_In_ SIZE_T dwSize, _In_ ULONGLONG dwAttributes) return EraVirtualAlloc(nullptr, dwSize, flAllocationType, PAGE_READWRITE); } - void *ptr = _aligned_malloc(dwSize, 1ULL << max(4, attr.s.dwAlignment)); + void *ptr = _aligned_malloc(dwSize, 1ULL << FIXmax(4, attr.s.dwAlignment)); if (ptr) memset(ptr, 0, dwSize); diff --git a/projects/WinDurango.KernelX/src/Hooks.cpp b/projects/WinDurango.KernelX/src/Hooks.cpp index 929e4fa..6b3dab9 100644 --- a/projects/WinDurango.KernelX/src/Hooks.cpp +++ b/projects/WinDurango.KernelX/src/Hooks.cpp @@ -307,6 +307,26 @@ HRESULT WINAPI WdRoGetActivationFactoryCore( return coreWindowStatic.CopyTo(iid, factory); } + if (rss == std::string("Windows.Networking.Connectivity.NetworkInformation")) { + return g_RoGetActivationFactory(activatableClassId, iid, factory); + } + + if (rss == std::string("Windows.Storage.Streams.Buffer")) { + return g_RoGetActivationFactory(activatableClassId, iid, factory); + } + + if (rss == std::string("Windows.Data.Json.JsonObject")) { + return g_RoGetActivationFactory(activatableClassId, iid, factory); + } + + if (rss == std::string("Windows.Data.Json.JsonValue")) { + return g_RoGetActivationFactory(activatableClassId, iid, factory); + } + + if (rss == std::string("Windows.Storage.Streams.DataWriter")) { + return g_RoGetActivationFactory(activatableClassId, iid, factory); + } + for (auto pfn : g_RoEntryPoints) { ComPtr temp; diff --git a/projects/WinDurango.KernelX/src/kernelx.cpp b/projects/WinDurango.KernelX/src/kernelx.cpp index b409372..8c0ff2a 100644 --- a/projects/WinDurango.KernelX/src/kernelx.cpp +++ b/projects/WinDurango.KernelX/src/kernelx.cpp @@ -610,7 +610,7 @@ EXTERN_C PVOID __stdcall XMemAllocDefault(SIZE_T dwSize, ULONGLONG dwAttributes) return EraVirtualAlloc(nullptr, dwSize, flAllocationType, PAGE_READWRITE); } - void *ptr = _aligned_malloc(dwSize, 1ULL << max(4, attr.s.dwAlignment)); + void *ptr = _aligned_malloc(dwSize, 1ULL << FIXmax(4, attr.s.dwAlignment)); if (ptr) memset(ptr, 0, dwSize); diff --git a/projects/WinDurango.WinRT/CMakeLists.txt b/projects/WinDurango.WinRT/CMakeLists.txt index fc3f099..556c0c6 100644 --- a/projects/WinDurango.WinRT/CMakeLists.txt +++ b/projects/WinDurango.WinRT/CMakeLists.txt @@ -5,6 +5,8 @@ set(VERSION_SUFFIX "-dev.1") # used for non-stable versions, otherwise blank set(CMAKE_CXX_STANDARD 20) find_package(cppwinrt CONFIG REQUIRED HINTS "${CMAKE_SOURCE_DIR}/vcpkg_installed/vcpkg/pkgs/cppwinrt_x64-windows/share/cppwinrt") +FetchContent_Declare(concurrencpp GIT_REPOSITORY https://github.com/Cherrytree56567/concurrencpp.git GIT_TAG master) +FetchContent_MakeAvailable(concurrencpp) add_compile_definitions(_AMD64_) @@ -125,7 +127,7 @@ target_include_directories(WinDurango.WinRT PUBLIC "${CMAKE_SOURCE_DIR}/projects/WinDurango.Common/include" ) -target_link_libraries(WinDurango.WinRT PRIVATE WinDurango.Common Microsoft::CppWinRT windowsapp runtimeobject) +target_link_libraries(WinDurango.WinRT PRIVATE WinDurango.Common Microsoft::CppWinRT windowsapp runtimeobject concurrencpp::concurrencpp) target_compile_definitions(WinDurango.WinRT PUBLIC WINDURANGO_WINRT_COMPILER_NAME="${CMAKE_CXX_COMPILER_ID}" @@ -137,7 +139,7 @@ target_compile_definitions(WinDurango.WinRT PUBLIC set_target_properties(WinDurango.WinRT PROPERTIES LINKER_LANGUAGE CXX) -target_compile_definitions(WinDurango.WinRT PRIVATE WINRT_DLL WIN32_LEAN_AND_MEAN WINRT_LEAN_AND_MEAN) +target_compile_definitions(WinDurango.WinRT PRIVATE WINRT_DLL WIN32_LEAN_AND_MEAN WINRT_LEAN_AND_MEAN NOMINMAX) if (WINRT_USE_CROSS_PLATFORM STREQUAL ON) target_link_libraries(WinDurango.WinRT PUBLIC WinDurango.Implementation.Native) diff --git a/projects/WinDurango.WinRT/include/WinDurango.WinRT/Windows/Xbox/Storage/Windows.Xbox.Storage.ConnectedStorage.h b/projects/WinDurango.WinRT/include/WinDurango.WinRT/Windows/Xbox/Storage/Windows.Xbox.Storage.ConnectedStorage.h index 0c69ea3..a2c0a76 100644 --- a/projects/WinDurango.WinRT/include/WinDurango.WinRT/Windows/Xbox/Storage/Windows.Xbox.Storage.ConnectedStorage.h +++ b/projects/WinDurango.WinRT/include/WinDurango.WinRT/Windows/Xbox/Storage/Windows.Xbox.Storage.ConnectedStorage.h @@ -1,5 +1,7 @@ #pragma once +#include #include +#include #include "WinDurangoWinRT.h" namespace wd::WinRT @@ -7,13 +9,22 @@ namespace wd::WinRT class ConnectedStorage { public: - ConnectedStorage(uint32_t id); // User Storage - ConnectedStorage(); // Machine Storage + ConnectedStorage(); + winrt::Windows::Foundation::IAsyncAction InitializeStorage(const wchar_t* name); + winrt::Windows::Foundation::IAsyncAction CreateContainer(winrt::hstring name) const; + winrt::Windows::Foundation::IAsyncAction Read(winrt::hstring containerName, winrt::Windows::Foundation::Collections::IMapView data) const; + //winrt::Windows::Foundation::IAsyncAction Upload(winrt::hstring containerName, winrt::Windows::Foundation::Collections::IMapView blobsToWrite, winrt::Windows::Foundation::Collections::IIterable blobsToDelete, winrt::hstring displayName = {}) const; + //winrt::Windows::Foundation::IAsyncOperation> GetBlobInfoAsync(winrt::hstring parentContainerName, winrt::hstring blobNamePrefix); + //winrt::Windows::Foundation::IAsyncOperation> GetContainerInfo2Async(); winrt::Windows::Foundation::IAsyncAction DeleteContainer(winrt::hstring containerName); private: uint32_t userId; std::shared_ptr dir; + bool isInitialised = false; }; + + inline ConnectedStorage* s_userStorage; + inline ConnectedStorage* s_machineStorage; } \ No newline at end of file diff --git a/projects/WinDurango.WinRT/include/WinDurango.WinRT/Windows/Xbox/Storage/Windows.Xbox.Storage.ConnectedStorageContainer.h b/projects/WinDurango.WinRT/include/WinDurango.WinRT/Windows/Xbox/Storage/Windows.Xbox.Storage.ConnectedStorageContainer.h index 8320f24..77a1898 100644 --- a/projects/WinDurango.WinRT/include/WinDurango.WinRT/Windows/Xbox/Storage/Windows.Xbox.Storage.ConnectedStorageContainer.h +++ b/projects/WinDurango.WinRT/include/WinDurango.WinRT/Windows/Xbox/Storage/Windows.Xbox.Storage.ConnectedStorageContainer.h @@ -17,7 +17,7 @@ namespace winrt::Windows::Xbox::Storage::implementation struct ConnectedStorageContainer : ConnectedStorageContainerT { ConnectedStorageContainer() = default; - ConnectedStorageContainer(hstring name, wd::WinRT::ConnectedStorage storage) : name(name), storage(storage) {} + ConnectedStorageContainer(hstring name, wd::WinRT::ConnectedStorage* storage) : name(name), storage(storage) {} hstring Name(); winrt::Windows::Xbox::Storage::ConnectedStorageSpace OwningSpace(); @@ -30,6 +30,6 @@ namespace winrt::Windows::Xbox::Storage::implementation winrt::Windows::Xbox::Storage::BlobInfoQueryResult CreateBlobInfoQuery(hstring const& unk); private: hstring name; - wd::WinRT::ConnectedStorage storage; + wd::WinRT::ConnectedStorage* storage; }; } diff --git a/projects/WinDurango.WinRT/include/WinDurango.WinRT/Windows/Xbox/Storage/Windows.Xbox.Storage.ConnectedStorageSpace.h b/projects/WinDurango.WinRT/include/WinDurango.WinRT/Windows/Xbox/Storage/Windows.Xbox.Storage.ConnectedStorageSpace.h index b135810..be26cd1 100644 --- a/projects/WinDurango.WinRT/include/WinDurango.WinRT/Windows/Xbox/Storage/Windows.Xbox.Storage.ConnectedStorageSpace.h +++ b/projects/WinDurango.WinRT/include/WinDurango.WinRT/Windows/Xbox/Storage/Windows.Xbox.Storage.ConnectedStorageSpace.h @@ -9,8 +9,8 @@ namespace winrt::Windows::Xbox::Storage::implementation struct ConnectedStorageSpace : ConnectedStorageSpaceT { ConnectedStorageSpace() = default; - ConnectedStorageSpace(wd::WinRT::ConnectedStorage storage) : storage(storage) {} - ConnectedStorageSpace(wd::WinRT::ConnectedStorage storage, uint32_t id) : storage(storage), id(id) {} + ConnectedStorageSpace(wd::WinRT::ConnectedStorage* storage) : storage(storage) {} + //ConnectedStorageSpace(wd::WinRT::ConnectedStorage storage, uint32_t id) : storage(storage), id(id) {} static winrt::Windows::Foundation::IAsyncOperation GetForUserAsync(winrt::Windows::Xbox::System::User unk); static winrt::Windows::Foundation::IAsyncOperation GetForUserAsync(winrt::Windows::Xbox::System::User unk, hstring unka); @@ -26,8 +26,11 @@ namespace winrt::Windows::Xbox::Storage::implementation winrt::Windows::Xbox::Storage::ContainerInfoQueryResult CreateContainerInfoQuery(hstring const& unk); winrt::Windows::Foundation::IAsyncOperation GetRemainingBytesInQuotaAsync(); winrt::Windows::Foundation::IAsyncOperation GetRemainingBytesInQuota64Async(); + inline static winrt::Windows::Xbox::Storage::ConnectedStorageSpace userStorageSpace = { nullptr }; + inline static winrt::Windows::Xbox::Storage::ConnectedStorageSpace machineStorageSpace = { nullptr }; + inline static winrt::Windows::Xbox::Storage::ConnectedStorageContainer staticContainer = { nullptr }; private: - wd::WinRT::ConnectedStorage storage; + wd::WinRT::ConnectedStorage* storage; uint32_t id = 0; inline static winrt::Windows::Foundation::Collections::IMap containers{}; }; diff --git a/projects/WinDurango.WinRT/src/WinDurangoWinRT.cpp b/projects/WinDurango.WinRT/src/WinDurangoWinRT.cpp index 591939f..af86006 100644 --- a/projects/WinDurango.WinRT/src/WinDurangoWinRT.cpp +++ b/projects/WinDurango.WinRT/src/WinDurangoWinRT.cpp @@ -1,7 +1,27 @@ #include "WinDurangoWinRT.h" +#include "Windows/Xbox/Storage/Windows.Xbox.Storage.ConnectedStorage.h" std::shared_ptr p_wd = nullptr; +DWORD WINAPI BackgroundSetup(LPVOID lpParam) +{ + UNREFERENCED_PARAMETER(lpParam); + + if (wd::WinRT::s_userStorage == nullptr) + { + wd::WinRT::s_userStorage = new wd::WinRT::ConnectedStorage(); + wd::WinRT::s_userStorage->InitializeStorage(L"UserStorage").get(); + } + + if (wd::WinRT::s_machineStorage == nullptr) + { + wd::WinRT::s_machineStorage = new wd::WinRT::ConnectedStorage(); + wd::WinRT::s_machineStorage->InitializeStorage(L"MachineStorage").get(); + } + + return TRUE; +} + /* * https://learn.microsoft.com/en-us/windows/win32/dlls/dllmain */ @@ -14,6 +34,7 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, // handle to DLL module p_wd = wd::common::WinDurango::GetInstance(); p_wd->log.Log("WinDurango::WinRT", "Initialized"); } + CreateThread(nullptr, 0, BackgroundSetup, nullptr, 0, nullptr); return TRUE; // Successful DLL_PROCESS_ATTACH. } diff --git a/projects/WinDurango.WinRT/src/Windows/Xbox/Storage/Windows.Xbox.Storage.ConnectedStorage.cpp b/projects/WinDurango.WinRT/src/Windows/Xbox/Storage/Windows.Xbox.Storage.ConnectedStorage.cpp index 12cc878..5a5b11f 100644 --- a/projects/WinDurango.WinRT/src/Windows/Xbox/Storage/Windows.Xbox.Storage.ConnectedStorage.cpp +++ b/projects/WinDurango.WinRT/src/Windows/Xbox/Storage/Windows.Xbox.Storage.ConnectedStorage.cpp @@ -2,17 +2,63 @@ namespace wd::WinRT { - ConnectedStorage::ConnectedStorage(uint32_t id) : userId(id) - { - std::shared_ptr usersDir = p_wd->rootDir->CreateFolder("Users"); - dir = usersDir->CreateFolder("User_" + std::to_string(id)); - } - ConnectedStorage::ConnectedStorage() { dir = p_wd->rootDir->CreateFolder("Machine"); } + winrt::Windows::Foundation::IAsyncAction ConnectedStorage::InitializeStorage(const wchar_t* name) + { + try + { + dir = co_await dir->CreateFolderAsync(name); + isInitialised = true; + p_wd->log.Log("WinDurango::WinRT::Windows::Xbox::ConnectedStorage", "User storage initialized at {}", (co_await dir->dirpathAsync()).string()); + } + catch (winrt::hresult_error const& ex) + { + p_wd->log.Error("WinDurango::WinRT::Windows::Xbox::ConnectedStorage", "Failed to initialize storage: {}", winrt::to_string(ex.message().c_str())); + throw; + } + } + + winrt::Windows::Foundation::IAsyncAction ConnectedStorage::CreateContainer(winrt::hstring name) const + { + if (!isInitialised) + { + p_wd->log.Error("WinDurango::WinRT::Windows::Xbox::ConnectedStorage", "Connected Storage not Initialised"); + co_return; + } + + co_await dir->CreateFolderAsync(std::filesystem::path(winrt::to_string(name))); + co_return; + } + + winrt::Windows::Foundation::IAsyncAction ConnectedStorage::Read(winrt::hstring containerName, winrt::Windows::Foundation::Collections::IMapView data) const + { + if (!isInitialised) + { + p_wd->log.Error("WinDurango::WinRT::Windows::Xbox::ConnectedStorage", "Connected Storage not Initialised"); + co_return; + } + + std::shared_ptr cont = co_await dir->CreateFolderAsync(std::filesystem::path(winrt::to_string(containerName))); + + for (auto const& part : data) + { + std::string blobName = winrt::to_string(part.Key()); + auto file = co_await cont->CreateFileAsync(std::filesystem::path(blobName)); + co_await file->openAsync(); + std::string bdata = co_await file->readAsync(); + auto writer = winrt::Windows::Storage::Streams::DataWriter(); + writer.WriteBytes(winrt::array_view( + reinterpret_cast(bdata.data()), + reinterpret_cast(bdata.data() + bdata.size()) + )); + part.Value() = writer.DetachBuffer(); + } + } + winrt::Windows::Foundation::IAsyncAction ConnectedStorage::DeleteContainer(winrt::hstring containerName) { bool exists = dir->dirExists(winrt::to_string(containerName)); diff --git a/projects/WinDurango.WinRT/src/Windows/Xbox/Storage/Windows.Xbox.Storage.ConnectedStorageSpace.cpp b/projects/WinDurango.WinRT/src/Windows/Xbox/Storage/Windows.Xbox.Storage.ConnectedStorageSpace.cpp index 591c230..ed4739d 100644 --- a/projects/WinDurango.WinRT/src/Windows/Xbox/Storage/Windows.Xbox.Storage.ConnectedStorageSpace.cpp +++ b/projects/WinDurango.WinRT/src/Windows/Xbox/Storage/Windows.Xbox.Storage.ConnectedStorageSpace.cpp @@ -1,34 +1,53 @@ #include "Windows.Xbox.Storage.ConnectedStorageSpace.h" +#include "WinDurangoWinRT.h" namespace winrt::Windows::Xbox::Storage::implementation { winrt::Windows::Foundation::IAsyncOperation ConnectedStorageSpace::GetForUserAsync(winrt::Windows::Xbox::System::User user) { - co_return (winrt::Windows::Xbox::Storage::ConnectedStorageSpace)winrt::make(wd::WinRT::ConnectedStorage(user.Id()), user.Id()); + if (userStorageSpace == Storage::ConnectedStorageSpace(nullptr)) { + userStorageSpace = winrt::make(wd::WinRT::s_userStorage); + } + co_return userStorageSpace; } winrt::Windows::Foundation::IAsyncOperation ConnectedStorageSpace::GetForUserAsync(winrt::Windows::Xbox::System::User user, hstring unka) { - co_return (winrt::Windows::Xbox::Storage::ConnectedStorageSpace)winrt::make(wd::WinRT::ConnectedStorage(user.Id()), user.Id()); + if (userStorageSpace == Storage::ConnectedStorageSpace(nullptr)) { + userStorageSpace = winrt::make(wd::WinRT::s_userStorage); + } + co_return userStorageSpace; } winrt::Windows::Foundation::IAsyncOperation ConnectedStorageSpace::GetForMachineAsync() { - co_return (winrt::Windows::Xbox::Storage::ConnectedStorageSpace)winrt::make(wd::WinRT::ConnectedStorage()); + if (machineStorageSpace == Storage::ConnectedStorageSpace(nullptr)) { + machineStorageSpace = winrt::make(wd::WinRT::s_machineStorage); + } + co_return machineStorageSpace; } winrt::Windows::Foundation::IAsyncOperation ConnectedStorageSpace::GetForMachineAsync(hstring unk) { - co_return (winrt::Windows::Xbox::Storage::ConnectedStorageSpace)winrt::make(wd::WinRT::ConnectedStorage()); + if (machineStorageSpace == Storage::ConnectedStorageSpace(nullptr)) { + machineStorageSpace = winrt::make(wd::WinRT::s_machineStorage); + } + co_return machineStorageSpace; } winrt::Windows::Foundation::IAsyncOperation ConnectedStorageSpace::GetSyncOnDemandForUserAsync(winrt::Windows::Xbox::System::User user) { - co_return (winrt::Windows::Xbox::Storage::ConnectedStorageSpace)winrt::make(wd::WinRT::ConnectedStorage(user.Id()), user.Id()); + if (userStorageSpace == Storage::ConnectedStorageSpace(nullptr)) { + userStorageSpace = winrt::make(wd::WinRT::s_userStorage); + } + co_return userStorageSpace; } winrt::Windows::Foundation::IAsyncOperation ConnectedStorageSpace::GetSyncOnDemandForUserAsync(winrt::Windows::Xbox::System::User user, hstring unka) { - co_return (winrt::Windows::Xbox::Storage::ConnectedStorageSpace)winrt::make(wd::WinRT::ConnectedStorage(user.Id()), user.Id()); + if (userStorageSpace == Storage::ConnectedStorageSpace(nullptr)) { + userStorageSpace = winrt::make(wd::WinRT::s_userStorage); + } + co_return userStorageSpace; } winrt::Windows::Xbox::System::User ConnectedStorageSpace::User() { - return winrt::Windows::Xbox::System::User::Users().GetAt(id); + return winrt::Windows::Xbox::System::User::Users().GetAt(0); } hstring ConnectedStorageSpace::ServiceConfigurationId() { @@ -41,6 +60,11 @@ namespace winrt::Windows::Xbox::Storage::implementation } winrt::Windows::Xbox::Storage::ConnectedStorageContainer ConnectedStorageSpace::CreateContainer(hstring const& containerName) { + if (wd::WinRT::s_userStorage == nullptr || wd::WinRT::s_machineStorage == nullptr) + { + p_wd->log.Warn("WinRT::Windows::Xbox::Storage::Impl", "User Storage or Machine Storage is nullptr"); + } + if (!containers) { containers = winrt::single_threaded_map(); @@ -58,7 +82,7 @@ namespace winrt::Windows::Xbox::Storage::implementation } winrt::Windows::Foundation::IAsyncAction ConnectedStorageSpace::DeleteContainerAsync(hstring containerName) { - co_await storage.DeleteContainer(containerName); + co_await storage->DeleteContainer(containerName); containers.Remove(containerName); } winrt::Windows::Xbox::Storage::ContainerInfoQueryResult ConnectedStorageSpace::CreateContainerInfoQuery(hstring const& unk)