Compare commits

..

No commits in common. "f87c2b47a60cf4f46c0045b730efdd1812ce7121" and "c8c39080855ab7d1b537e74a2d55c53dd651a67f" have entirely different histories.

7 changed files with 11 additions and 167 deletions

View File

@ -70,13 +70,8 @@ namespace Aurora::Data
{
UUID = val;
}
Value(const AuString &val)
{
string = val;
}
Value(const char *val)
Value(const AuString &val)
{
string = val;
}

View File

@ -9,8 +9,10 @@
namespace Aurora::Registry
{
enum class ERegistrySource
enum ERegistrySource
{
eFS
eFSGlobal,
eFSProfile,
eGlobal
};
}

View File

@ -10,7 +10,7 @@
namespace Aurora::Registry
{
using RegistryType = Aurora::Data::DataType;
using RegistryValue = Aurora::Data::TypedValue;
using RegistryValue = Aurora::Data::Value;
class IRegistry
{

View File

@ -204,7 +204,7 @@ namespace Aurora::Debug
AUKN_SYM void _PushError(AuUInt address, FailureCategory category, const char *msg)
{
LastError error{ address, category, msg ? msg : "" };
LastError error{ address, category, msg };
AuUInt32 rng = GetFenceId();
Telemetry::InsertManualFence(rng);
@ -214,8 +214,7 @@ namespace Aurora::Debug
Telemetry::InsertManualFence(rng);
#if defined(DEBUG) || defined(INTERNAL)
PrintError();
LogWarn("ERROR: {}", error.dbg);
LogWarn("ERROR: {}", msg);
#endif
}

View File

@ -54,7 +54,7 @@ namespace Aurora::IO::FS
auto win32Path = Locale::ConvertFromUTF8(pathNormalized);
auto fileHandle = CreateFileW(win32Path.c_str(), GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (fileHandle == INVALID_HANDLE_VALUE)
if (fileHandle != INVALID_HANDLE_VALUE)
{
SysPushErrorIO("Couldn't open handle: {}", path);
return false;
@ -102,7 +102,7 @@ namespace Aurora::IO::FS
auto win32Path = Locale::ConvertFromUTF8(NormalizePathRet(path));
auto fileHandle = CreateFileW(win32Path.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (fileHandle == INVALID_HANDLE_VALUE)
if (fileHandle != INVALID_HANDLE_VALUE)
{
SysPushErrorIO("Couldn't open handle: {}", path);
return false;

View File

@ -5,156 +5,3 @@
Date: 2021-6-13
Author: Reece
***/
#include <RuntimeInternal.hpp>
#include "Registry.hpp"
#include <nlohmann/json.hpp>
using json = nlohmann::json;
namespace Aurora::Registry
{
class FSRegistry : public IRegistry
{
public:
json document;
AuString path;
bool Init(const AuString &path);
bool KeyExists(const AuString &key, RegistryType &type);
bool GetOrCreateKey(const AuString &key, const RegistryValue &ref, RegistryValue &value);
bool GetKey(const AuString &key, RegistryValue &value);
bool SetKey(const AuString &key, const RegistryValue &value);
bool Save();
};
bool FSRegistry::Init(const AuString &path)
{
try
{
this->path = path;
AuString file;
if (!IO::FS::ReadString(path, file))
{
return IO::FS::WriteString(path, "{}");
}
document = json::parse(file);
}
catch (...)
{
return false;
}
return true;
}
bool FSRegistry::KeyExists(const AuString &key, RegistryType &type)
{
auto itrObject = document.find(key);
if (itrObject == document.end()) return false;
auto itrType = itrObject->find("type");
if (itrType == itrObject->end()) return false;
auto itrValue = itrObject->find("value");
if (itrValue == itrObject->end()) return false;
return true;
}
bool FSRegistry::GetOrCreateKey(const AuString &key, const RegistryValue &ref, RegistryValue &value)
{
if (GetKey(key, value))
{
return true;
}
return SetKey(key, ref);
}
bool FSRegistry::GetKey(const AuString &key, RegistryValue &value)
{
auto itrObject = document.find(key);
if (itrObject == document.end())
{
return false;
}
auto itrType = itrObject->find("type");
auto itrValue = itrObject->find("value");
if ((itrType == itrObject->end()) ||
(itrValue == itrObject->end()))
{
return false;
}
if (!itrValue->is_string())
{
return false;
}
if (!itrType->is_number_integer())
{
return false;
}
Parse::ParsableTag type = *itrType;
AuString strValue = *itrValue;
Parse::ParseValueEx parsedValue;
if (!Parse::ConsumeToken(type, strValue , parsedValue))
{
return false;
}
value.type = static_cast<Data::DataType>(type);
value.value = parsedValue;
return true;
}
bool FSRegistry::SetKey(const AuString &key, const RegistryValue &value)
{
json object {};
object["type"] = value.type;
AuString stringified;
Parse::SerializeToken(static_cast<Parse::ParsableTag>(value.type), value.value, stringified);
object["value"] = stringified;
document[key] = object;
return Save();
}
bool FSRegistry::Save()
{
if (!IO::FS::WriteString(path, document.dump(4)))
{
SysPushErrorIO("Couldn't write registry to: {}", path);
return false;
}
return true;
}
AUKN_SYM IRegistry *RegistryNew(ERegistrySource source, const AuString &name)
{
SysAssert(source == ERegistrySource::eFS, "Unknown registry type");
auto registry = _new FSRegistry();
if (!registry)
{
return nullptr;
}
if (!registry->Init(name))
{
delete registry;
return nullptr;
}
return registry;
}
AUKN_SYM void RegistryRelease(IRegistry *registry)
{
SafeDelete<FSRegistry *>(registry);
}
}

View File

@ -6,3 +6,4 @@
Author: Reece
***/
#pragma once