Compare commits

...

4 Commits

Author SHA1 Message Date
f87c2b47a6 [+] i can has registry 2021-06-30 17:35:02 +01:00
22c1681132 Bad handle checks 2021-06-30 17:34:49 +01:00
f7403c944c [*] Bug: Some Value constructor seems to be deduced down to accepting
const char *. Ensure const char* always assigns a string
2021-06-30 17:34:36 +01:00
784d58b184 [*] Crash fix: Null SysPushErrors should be assigned empty strings 2021-06-30 17:33:18 +01:00
7 changed files with 167 additions and 11 deletions

View File

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

View File

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

View File

@ -10,7 +10,7 @@
namespace Aurora::Registry
{
using RegistryType = Aurora::Data::DataType;
using RegistryValue = Aurora::Data::Value;
using RegistryValue = Aurora::Data::TypedValue;
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 };
LastError error{ address, category, msg ? msg : "" };
AuUInt32 rng = GetFenceId();
Telemetry::InsertManualFence(rng);
@ -214,7 +214,8 @@ namespace Aurora::Debug
Telemetry::InsertManualFence(rng);
#if defined(DEBUG) || defined(INTERNAL)
LogWarn("ERROR: {}", msg);
PrintError();
LogWarn("ERROR: {}", error.dbg);
#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,3 +5,156 @@
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,4 +6,3 @@
Author: Reece
***/
#pragma once