feat/fix: fixed storage error, added async stuff

This commit is contained in:
CT5
2026-03-14 14:32:19 +11:00
parent c42c4c36c5
commit f6df2bf149
21 changed files with 719 additions and 36 deletions

View File

@@ -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

View File

@@ -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}"

View File

@@ -1,10 +1,13 @@
//
// Created by DexrnZacAttack on 1/23/26 using zPc-i2.
//
#pragma once
#include "File.h"
#include <thread>
#include <string>
#include <string_view>
#include <functional>
#include <concurrencpp/concurrencpp.h>
#include <filesystem>
#include <memory>
#include <coroutine>
namespace wd::common::interfaces::storage
{
@@ -24,9 +27,7 @@ namespace wd::common::interfaces::storage
}
virtual bool open() = 0;
virtual std::shared_ptr<File> 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<File> 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<Directory> 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<bool> openAsync() = 0;
virtual concurrencpp::result<std::shared_ptr<File>> CreateFileAsync(std::filesystem::path path) = 0;
virtual concurrencpp::result<std::shared_ptr<Directory>> CreateFolderAsync(std::filesystem::path path) = 0;
virtual concurrencpp::result<std::filesystem::path> dirpathAsync() = 0;
virtual concurrencpp::result<bool> renameAsync(std::string) = 0;
virtual concurrencpp::result<bool> removeAsync() = 0;
virtual concurrencpp::result<bool> moveAsync(std::filesystem::path path) = 0;
virtual concurrencpp::result<bool> copyAsync(std::filesystem::path path) = 0;
virtual concurrencpp::result<bool> dirExistsAsync(std::string) = 0;
virtual concurrencpp::result<bool> fileExistsAsync(std::string) = 0;
};
} // namespace wd::common::interfaces::storage

View File

@@ -4,6 +4,7 @@
#pragma once
#include <filesystem>
#include <istream>
#include <concurrencpp/concurrencpp.h>
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<bool> openAsync() = 0;
virtual concurrencpp::result<bool> createAsync() = 0;
virtual concurrencpp::result<std::string> readAsync() = 0;
virtual concurrencpp::result<bool> writeAsync(std::string data) = 0; // write
virtual concurrencpp::result<bool> closeAsync() = 0;
virtual concurrencpp::result<std::filesystem::path> filepathAsync() = 0;
virtual concurrencpp::result<std::filesystem::path> fullfilepathAsync() = 0;
virtual concurrencpp::result<bool> renameAsync(std::string) = 0;
virtual concurrencpp::result<bool> removeAsync() = 0;
virtual concurrencpp::result<bool> moveAsync(std::filesystem::path path) = 0;
virtual concurrencpp::result<bool> copyAsync(std::filesystem::path path) = 0;
};
} // namespace wd::common::interfaces::storage

View File

@@ -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)
target_compile_definitions(WinDurango.Implementation.WinRT PRIVATE _WINRT_DLL WIN32_LEAN_AND_MEAN WINRT_LEAN_AND_MEAN NOMINMAX)

View File

@@ -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<bool> openAsync() override;
virtual concurrencpp::result<std::shared_ptr<wd::common::interfaces::storage::File>> CreateFileAsync(std::filesystem::path path) override;
virtual concurrencpp::result<std::shared_ptr<wd::common::interfaces::storage::Directory>> CreateFolderAsync(std::filesystem::path path) override;
virtual concurrencpp::result<std::filesystem::path> dirpathAsync() override;
virtual concurrencpp::result<bool> renameAsync(std::string) override;
virtual concurrencpp::result<bool> removeAsync() override;
virtual concurrencpp::result<bool> moveAsync(std::filesystem::path path) override;
virtual concurrencpp::result<bool> copyAsync(std::filesystem::path path) override;
virtual concurrencpp::result<bool> dirExistsAsync(std::string) override;
virtual concurrencpp::result<bool> fileExistsAsync(std::string) override;
private:
std::filesystem::path path;
StorageFolder dir;

View File

@@ -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<bool> openAsync() override;
virtual concurrencpp::result<bool> createAsync() override;
virtual concurrencpp::result<std::string> readAsync() override;
virtual concurrencpp::result<bool> writeAsync(std::string data) override;
virtual concurrencpp::result<bool> closeAsync() override;
virtual concurrencpp::result<std::filesystem::path> filepathAsync() override;
virtual concurrencpp::result<std::filesystem::path> fullfilepathAsync() override;
virtual concurrencpp::result<bool> renameAsync(std::string) override;
virtual concurrencpp::result<bool> removeAsync() override;
virtual concurrencpp::result<bool> moveAsync(std::filesystem::path path) override;
virtual concurrencpp::result<bool> copyAsync(std::filesystem::path path) override;
private:
std::filesystem::path path;
StorageFile file;

View File

@@ -268,4 +268,253 @@ bool wd::impl::winrt::interfaces::storage::WinRTDirectory::fileExists(std::strin
return false;
}
return false;
}
}
concurrencpp::result<bool> 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<std::shared_ptr<wd::common::interfaces::storage::File>> 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<wd::impl::winrt::interfaces::storage::WinRTFile> fileRT =
std::make_shared<wd::impl::winrt::interfaces::storage::WinRTFile>(path / targetPath.filename());
co_return fileRT;
}
catch (const hresult_error &ex)
{
co_return nullptr;
}
}
concurrencpp::result<std::shared_ptr<wd::common::interfaces::storage::Directory>> 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<wd::impl::winrt::interfaces::storage::WinRTDirectory> folderRT =
std::make_shared<wd::impl::winrt::interfaces::storage::WinRTDirectory>(path / targetPath.filename());
co_return folderRT;
}
catch (const hresult_error &ex)
{
co_return nullptr;
}
}
concurrencpp::result<std::filesystem::path> wd::impl::winrt::interfaces::storage::WinRTDirectory::dirpathAsync()
{
co_return path;
}
concurrencpp::result<bool> 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<bool> 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<bool> 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<bool> 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<bool> 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<bool> 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<bool> 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<bool> 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;
}

View File

@@ -229,4 +229,231 @@ namespace wd::impl::winrt::interfaces::storage
}
return false;
}
concurrencpp::result<bool> 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<bool> 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<std::string> 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<bool> 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<bool> WinRTFile::closeAsync()
{
if (file == nullptr)
{
co_return false;
}
file = nullptr;
co_return false;
}
concurrencpp::result<std::filesystem::path> WinRTFile::filepathAsync()
{
co_return path;
}
concurrencpp::result<std::filesystem::path> WinRTFile::fullfilepathAsync()
{
StorageFolder sf = ApplicationData::Current().LocalFolder();
std::filesystem::path rootPath{sf.Path().c_str()};
co_return rootPath / path;
}
concurrencpp::result<bool> 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<bool> 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<bool> 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<bool> 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

View File

@@ -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"
)

View File

@@ -154,7 +154,7 @@ class FrameworkViewEra : public IFrameworkView
HRESULT Run() override
{
return m_realView->Run();
}
}
HRESULT Uninitialize() override
{

View File

@@ -3,10 +3,19 @@
#include "kernelx.h"
#include <Windows.h>
#include <thread>
#include <algorithm>
// All of the types were provided by DaZombieKiller, a huge thanks to him!
#include <winioctl.h>
#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);

View File

@@ -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<IActivationFactory> temp;

View File

@@ -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);

View File

@@ -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)

View File

@@ -1,5 +1,7 @@
#pragma once
#include <winrt/Windows.Foundation.h>
#include <winrt/Windows.Foundation.Collections.h>
#include <winrt/Windows.Storage.Streams.h>
#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<winrt::hstring, winrt::Windows::Storage::Streams::IBuffer> data) const;
//winrt::Windows::Foundation::IAsyncAction Upload(winrt::hstring containerName, winrt::Windows::Foundation::Collections::IMapView<winrt::hstring, winrt::Windows::Storage::Streams::IBuffer> blobsToWrite, winrt::Windows::Foundation::Collections::IIterable<winrt::hstring> blobsToDelete, winrt::hstring displayName = {}) const;
//winrt::Windows::Foundation::IAsyncOperation<winrt::Windows::Foundation::Collections::IVectorView<winrt::Windows::Xbox::Storage::BlobInfo>> GetBlobInfoAsync(winrt::hstring parentContainerName, winrt::hstring blobNamePrefix);
//winrt::Windows::Foundation::IAsyncOperation<winrt::Windows::Foundation::Collections::IVectorView<winrt::Windows::Xbox::Storage::ContainerInfo2>> GetContainerInfo2Async();
winrt::Windows::Foundation::IAsyncAction DeleteContainer(winrt::hstring containerName);
private:
uint32_t userId;
std::shared_ptr<wd::common::interfaces::storage::Directory> dir;
bool isInitialised = false;
};
inline ConnectedStorage* s_userStorage;
inline ConnectedStorage* s_machineStorage;
}

View File

@@ -17,7 +17,7 @@ namespace winrt::Windows::Xbox::Storage::implementation
struct ConnectedStorageContainer : ConnectedStorageContainerT<ConnectedStorageContainer>
{
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;
};
}

View File

@@ -9,8 +9,8 @@ namespace winrt::Windows::Xbox::Storage::implementation
struct ConnectedStorageSpace : ConnectedStorageSpaceT<ConnectedStorageSpace>
{
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<winrt::Windows::Xbox::Storage::ConnectedStorageSpace> GetForUserAsync(winrt::Windows::Xbox::System::User unk);
static winrt::Windows::Foundation::IAsyncOperation<winrt::Windows::Xbox::Storage::ConnectedStorageSpace> 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<int32_t> GetRemainingBytesInQuotaAsync();
winrt::Windows::Foundation::IAsyncOperation<int64_t> 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<hstring, winrt::Windows::Xbox::Storage::ConnectedStorageContainer> containers{};
};

View File

@@ -1,7 +1,27 @@
#include "WinDurangoWinRT.h"
#include "Windows/Xbox/Storage/Windows.Xbox.Storage.ConnectedStorage.h"
std::shared_ptr<wd::common::WinDurango> 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.
}

View File

@@ -2,17 +2,63 @@
namespace wd::WinRT
{
ConnectedStorage::ConnectedStorage(uint32_t id) : userId(id)
{
std::shared_ptr<wd::common::interfaces::storage::Directory> 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<winrt::hstring, winrt::Windows::Storage::Streams::IBuffer> data) const
{
if (!isInitialised)
{
p_wd->log.Error("WinDurango::WinRT::Windows::Xbox::ConnectedStorage", "Connected Storage not Initialised");
co_return;
}
std::shared_ptr<wd::common::interfaces::storage::Directory> 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<const uint8_t>(
reinterpret_cast<const uint8_t*>(bdata.data()),
reinterpret_cast<const uint8_t*>(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));

View File

@@ -1,34 +1,53 @@
#include "Windows.Xbox.Storage.ConnectedStorageSpace.h"
#include "WinDurangoWinRT.h"
namespace winrt::Windows::Xbox::Storage::implementation
{
winrt::Windows::Foundation::IAsyncOperation<winrt::Windows::Xbox::Storage::ConnectedStorageSpace> ConnectedStorageSpace::GetForUserAsync(winrt::Windows::Xbox::System::User user)
{
co_return (winrt::Windows::Xbox::Storage::ConnectedStorageSpace)winrt::make<winrt::Windows::Xbox::Storage::implementation::ConnectedStorageSpace>(wd::WinRT::ConnectedStorage(user.Id()), user.Id());
if (userStorageSpace == Storage::ConnectedStorageSpace(nullptr)) {
userStorageSpace = winrt::make<winrt::Windows::Xbox::Storage::implementation::ConnectedStorageSpace>(wd::WinRT::s_userStorage);
}
co_return userStorageSpace;
}
winrt::Windows::Foundation::IAsyncOperation<winrt::Windows::Xbox::Storage::ConnectedStorageSpace> ConnectedStorageSpace::GetForUserAsync(winrt::Windows::Xbox::System::User user, hstring unka)
{
co_return (winrt::Windows::Xbox::Storage::ConnectedStorageSpace)winrt::make<winrt::Windows::Xbox::Storage::implementation::ConnectedStorageSpace>(wd::WinRT::ConnectedStorage(user.Id()), user.Id());
if (userStorageSpace == Storage::ConnectedStorageSpace(nullptr)) {
userStorageSpace = winrt::make<winrt::Windows::Xbox::Storage::implementation::ConnectedStorageSpace>(wd::WinRT::s_userStorage);
}
co_return userStorageSpace;
}
winrt::Windows::Foundation::IAsyncOperation<winrt::Windows::Xbox::Storage::ConnectedStorageSpace> ConnectedStorageSpace::GetForMachineAsync()
{
co_return (winrt::Windows::Xbox::Storage::ConnectedStorageSpace)winrt::make<winrt::Windows::Xbox::Storage::implementation::ConnectedStorageSpace>(wd::WinRT::ConnectedStorage());
if (machineStorageSpace == Storage::ConnectedStorageSpace(nullptr)) {
machineStorageSpace = winrt::make<winrt::Windows::Xbox::Storage::implementation::ConnectedStorageSpace>(wd::WinRT::s_machineStorage);
}
co_return machineStorageSpace;
}
winrt::Windows::Foundation::IAsyncOperation<winrt::Windows::Xbox::Storage::ConnectedStorageSpace> ConnectedStorageSpace::GetForMachineAsync(hstring unk)
{
co_return (winrt::Windows::Xbox::Storage::ConnectedStorageSpace)winrt::make<winrt::Windows::Xbox::Storage::implementation::ConnectedStorageSpace>(wd::WinRT::ConnectedStorage());
if (machineStorageSpace == Storage::ConnectedStorageSpace(nullptr)) {
machineStorageSpace = winrt::make<winrt::Windows::Xbox::Storage::implementation::ConnectedStorageSpace>(wd::WinRT::s_machineStorage);
}
co_return machineStorageSpace;
}
winrt::Windows::Foundation::IAsyncOperation<winrt::Windows::Xbox::Storage::ConnectedStorageSpace> ConnectedStorageSpace::GetSyncOnDemandForUserAsync(winrt::Windows::Xbox::System::User user)
{
co_return (winrt::Windows::Xbox::Storage::ConnectedStorageSpace)winrt::make<winrt::Windows::Xbox::Storage::implementation::ConnectedStorageSpace>(wd::WinRT::ConnectedStorage(user.Id()), user.Id());
if (userStorageSpace == Storage::ConnectedStorageSpace(nullptr)) {
userStorageSpace = winrt::make<winrt::Windows::Xbox::Storage::implementation::ConnectedStorageSpace>(wd::WinRT::s_userStorage);
}
co_return userStorageSpace;
}
winrt::Windows::Foundation::IAsyncOperation<winrt::Windows::Xbox::Storage::ConnectedStorageSpace> ConnectedStorageSpace::GetSyncOnDemandForUserAsync(winrt::Windows::Xbox::System::User user, hstring unka)
{
co_return (winrt::Windows::Xbox::Storage::ConnectedStorageSpace)winrt::make<winrt::Windows::Xbox::Storage::implementation::ConnectedStorageSpace>(wd::WinRT::ConnectedStorage(user.Id()), user.Id());
if (userStorageSpace == Storage::ConnectedStorageSpace(nullptr)) {
userStorageSpace = winrt::make<winrt::Windows::Xbox::Storage::implementation::ConnectedStorageSpace>(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<hstring, winrt::Windows::Xbox::Storage::ConnectedStorageContainer>();
@@ -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)