mirror of
https://github.com/WinDurango/WinDurango.git
synced 2026-01-31 00:55:17 +01:00
Merge pull request 'dev/winrt-setup' (#3) from dev/winrt-setup into main
Reviewed-on: https://codeberg.org/WinDurango/WinDurango/pulls/3
This commit is contained in:
@@ -23,7 +23,8 @@ FetchContent_MakeAvailable(json)
|
||||
|
||||
add_library(WinDurango.Common SHARED ${FILES})
|
||||
target_include_directories(WinDurango.Common PUBLIC
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/>
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/>
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/WinDurango.Common/>
|
||||
)
|
||||
|
||||
target_link_libraries(WinDurango.Common PUBLIC nlohmann_json::nlohmann_json)
|
||||
|
||||
@@ -6,18 +6,31 @@
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include "Interfaces/Storage/File.h"
|
||||
|
||||
/*
|
||||
* TODO: Make it to write back
|
||||
*/
|
||||
namespace wd::common {
|
||||
class Config {
|
||||
public:
|
||||
Config() {}
|
||||
Config(std::string file, bool ReadOnly = false) {}
|
||||
Config() : pFile(nullptr), RO(false) {}
|
||||
Config(std::shared_ptr<interfaces::storage::File> file, bool ReadOnly = false) : pFile(file), RO(ReadOnly) {}
|
||||
|
||||
bool parse();
|
||||
|
||||
/*
|
||||
* Operator Overloading
|
||||
* https://en.cppreference.com/w/cpp/language/operators.html
|
||||
*/
|
||||
template<typename T>
|
||||
T& operator[](std::string node) {}
|
||||
T& operator[](std::string node);
|
||||
|
||||
template<typename T>
|
||||
bool set(std::string node, T type);
|
||||
private:
|
||||
std::shared_ptr<interfaces::storage::File> pFile;
|
||||
bool RO;
|
||||
nlohmann::json data;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
//
|
||||
#pragma once
|
||||
#include <filesystem>
|
||||
#include <memory>
|
||||
#include "File.h"
|
||||
|
||||
namespace wd::common::interfaces::storage {
|
||||
@@ -19,8 +20,8 @@ namespace wd::common::interfaces::storage {
|
||||
Directory() {}
|
||||
|
||||
virtual bool open() = 0;
|
||||
virtual File* CreateFile(std::filesystem::path path) = 0; // todo maybe return stream type, todo can we use this in uwp context??? I forgor
|
||||
virtual Directory* CreateFolder(std::filesystem::path path) = 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<Directory> CreateFolder(std::filesystem::path path) = 0;
|
||||
|
||||
virtual std::filesystem::path dirpath() = 0;
|
||||
|
||||
|
||||
24
projects/WinDurango.Common/src/Config.cpp
Normal file
24
projects/WinDurango.Common/src/Config.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
#include "Config.h"
|
||||
|
||||
bool wd::common::Config::parse() {
|
||||
try {
|
||||
std::string jsonData = pFile->read();
|
||||
data = nlohmann::json::parse(jsonData);
|
||||
return true;
|
||||
} catch (const std::exception& e) {
|
||||
return false;
|
||||
} catch (...) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T& wd::common::Config::operator[](std::string node) {
|
||||
return data[node];
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool wd::common::Config::set(std::string node, T type) {
|
||||
data[node] = type;
|
||||
return true;
|
||||
}
|
||||
@@ -11,6 +11,7 @@ set(FILES
|
||||
include/WinDurango.Implementation.WinRT/Interfaces/Storage/File.h
|
||||
src/interfaces/Storage/Directory.cpp
|
||||
src/interfaces/Storage/File.cpp
|
||||
src/WinRT.cpp
|
||||
)
|
||||
|
||||
add_compile_definitions(WDIMPL_API_EXPORTS)
|
||||
|
||||
@@ -19,8 +19,8 @@ namespace wd::impl::winrt::interfaces::storage {
|
||||
WinRTDirectory(std::filesystem::path dirpath) : path(dirpath), dir(nullptr) {}
|
||||
|
||||
virtual bool open() override;
|
||||
virtual wd::common::interfaces::storage::File* CreateFile(std::filesystem::path path) override;
|
||||
virtual wd::common::interfaces::storage::Directory* CreateFolder(std::filesystem::path path) override;
|
||||
virtual std::shared_ptr<wd::common::interfaces::storage::File> CreateFile(std::filesystem::path path) override;
|
||||
virtual std::shared_ptr<wd::common::interfaces::storage::Directory> CreateFolder(std::filesystem::path path) override;
|
||||
|
||||
virtual std::filesystem::path dirpath() override;
|
||||
|
||||
|
||||
11
projects/WinDurango.Implementation.WinRT/src/WinRT.cpp
Normal file
11
projects/WinDurango.Implementation.WinRT/src/WinRT.cpp
Normal file
@@ -0,0 +1,11 @@
|
||||
#include <windows.h>
|
||||
#include <iostream>
|
||||
#include "WinDurangoWinRT.h"
|
||||
|
||||
/*
|
||||
* Found here
|
||||
* https://stackoverflow.com/questions/12168113/detect-application-running-in-winrt-mode-by-pid
|
||||
*/
|
||||
bool WDIMPL_API ImplementationSupported() {
|
||||
return IsImmersiveProcess(GetCurrentProcess());
|
||||
}
|
||||
@@ -33,13 +33,13 @@ bool wd::impl::winrt::interfaces::storage::WinRTDirectory::open() {
|
||||
* TargetPath is the filename btw
|
||||
* any path will be ignored.
|
||||
*/
|
||||
wd::common::interfaces::storage::File* wd::impl::winrt::interfaces::storage::WinRTDirectory::CreateFile(std::filesystem::path targetPath) {
|
||||
std::shared_ptr<wd::common::interfaces::storage::File> wd::impl::winrt::interfaces::storage::WinRTDirectory::CreateFile(std::filesystem::path targetPath) {
|
||||
if (dir == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
try {
|
||||
auto file = dir.CreateFileAsync(hstring(targetPath.filename().wstring()), CreationCollisionOption::OpenIfExists).get();
|
||||
wd::impl::winrt::interfaces::storage::WinRTFile* fileRT = new wd::impl::winrt::interfaces::storage::WinRTFile(path / targetPath.filename());
|
||||
std::shared_ptr<wd::impl::winrt::interfaces::storage::WinRTFile> fileRT = std::make_shared<wd::impl::winrt::interfaces::storage::WinRTFile>(path / targetPath.filename());
|
||||
return fileRT;
|
||||
}
|
||||
catch (const hresult_error& ex) {
|
||||
@@ -48,15 +48,15 @@ wd::common::interfaces::storage::File* wd::impl::winrt::interfaces::storage::Win
|
||||
}
|
||||
|
||||
/*
|
||||
* TODO: Use Unique Pointers
|
||||
* TODO: Use Shared Pointers
|
||||
*/
|
||||
wd::common::interfaces::storage::Directory* wd::impl::winrt::interfaces::storage::WinRTDirectory::CreateFolder(std::filesystem::path targetPath) {
|
||||
std::shared_ptr<wd::common::interfaces::storage::Directory> wd::impl::winrt::interfaces::storage::WinRTDirectory::CreateFolder(std::filesystem::path targetPath) {
|
||||
if (dir == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
try {
|
||||
auto file = dir.CreateFolderAsync(hstring(targetPath.filename().wstring()), CreationCollisionOption::OpenIfExists).get();
|
||||
wd::impl::winrt::interfaces::storage::WinRTDirectory* folderRT = new wd::impl::winrt::interfaces::storage::WinRTDirectory(path / targetPath.filename());
|
||||
std::shared_ptr<wd::impl::winrt::interfaces::storage::WinRTDirectory> folderRT = std::make_shared<wd::impl::winrt::interfaces::storage::WinRTDirectory>(path / targetPath.filename());
|
||||
return folderRT;
|
||||
}
|
||||
catch (const hresult_error& ex) {
|
||||
|
||||
7
vcpkg.json
Normal file
7
vcpkg.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"name": "windurango",
|
||||
"version": "1.0",
|
||||
"dependencies": [
|
||||
"cppwinrt"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user