Compare commits
2
Commits
0f262fb06e
...
10ac51f167
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
10ac51f167 | ||
|
|
9e8bbad5d4 |
No files matched your search
@@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
using UserID = uint8;
|
||||
|
||||
void initialize_user_system();
|
||||
void shutdown_user_system();
|
||||
|
||||
uint8 get_local_user_id();
|
||||
@@ -0,0 +1,48 @@
|
||||
#include <Engine/user.h>
|
||||
|
||||
#include <Core/Common/CRC32.h>
|
||||
#include <Core/Common/serialization.h>
|
||||
#include <Core/HAL/Filesystem/Filesystem.h>
|
||||
#include <Core/HAL/IO/IOStream.h>
|
||||
#include <Core/HAL/OS/OS.h>
|
||||
#include <Core/Thread/ThreadContext.h>
|
||||
#include <Engine/Engine.h>
|
||||
|
||||
void initialize_user_system()
|
||||
{
|
||||
// Project needs a user.ini file with all users
|
||||
// When starting if none exists -> create it
|
||||
// User name is basically found in a env variable, if not, the local windows user will be used.
|
||||
TempArena temp = scratch_begin(nullptr, 0);
|
||||
|
||||
String user_system_path = GetAssetPath(temp.Arena, AssetType::Config, ConstString("users.ini"));
|
||||
ByteBuffer user_file = LoadFile(temp.Arena, user_system_path);
|
||||
|
||||
String username = os_get_username(temp.Arena);
|
||||
|
||||
if (user_file.Size == 0)
|
||||
{
|
||||
IOStream* stream = IOFromFile(temp.Arena, user_system_path, ConstString("w+"));
|
||||
Archive ar = { .arena = temp.Arena, .loading = false, .stream = stream };
|
||||
|
||||
uint8 id = 1;
|
||||
serialize(ar, username, crc32(username), id);
|
||||
|
||||
IOClose(stream);
|
||||
}
|
||||
else
|
||||
{
|
||||
ParsedArchive parsed_archive = tokenize_archive(temp.Arena, user_file);
|
||||
|
||||
Archive ar = { .arena = temp.Arena, .loading = true, .base = parsed_archive };
|
||||
}
|
||||
|
||||
scratch_end(temp);
|
||||
}
|
||||
|
||||
void shutdown_user_system() {}
|
||||
|
||||
uint8 get_local_user_id()
|
||||
{
|
||||
return 0u;
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
#if JULIET_DEBUG
|
||||
|
||||
#include <Core/HAL/OS/OS.h>
|
||||
#include <Core/Logging/LogManager.h>
|
||||
#include <Core/Logging/LogTypes.h>
|
||||
#include <Core/Thread/ThreadContext.h>
|
||||
|
||||
namespace UnitTest
|
||||
{
|
||||
void os_unit_test()
|
||||
{
|
||||
LogMessage(LogCategory::Core, "=== Running OS Unit Tests (Juliet) ===");
|
||||
|
||||
TempArena scratch = scratch_begin(nullptr, 0);
|
||||
String username = os_get_username(scratch.Arena);
|
||||
|
||||
Assert(IsValid(username));
|
||||
|
||||
String env = os_get_env_var(scratch.Arena, ConstString("JULIET_UNIT_TEST"));
|
||||
|
||||
os_set_env_var(ConstString("JULIET_UNIT_TEST"), username);
|
||||
|
||||
String env2 = os_get_env_var(scratch.Arena, ConstString("JULIET_UNIT_TEST"));
|
||||
|
||||
os_set_env_var(ConstString("JULIET_UNIT_TEST"), env);
|
||||
|
||||
Assert(StringCompare(env, env2) != 0);
|
||||
|
||||
// String os_get_env_var(NonNullPtr<Arena> arena, const String& name)
|
||||
// {
|
||||
// String result = Internal::os_get_env_var(arena, name);
|
||||
// return result;
|
||||
// }
|
||||
//
|
||||
// void os_set_env_var(const String& name, const String& value)
|
||||
// {
|
||||
// Internal::os_set_env_var(name, value);
|
||||
// }
|
||||
//
|
||||
// String os_get_username(NonNullPtr<Arena> arena)
|
||||
// {
|
||||
// Internal::os_get_username(arena);
|
||||
// }
|
||||
//
|
||||
|
||||
scratch_end(scratch);
|
||||
LogMessage(LogCategory::Core, "=== All OS Unit Tests Passed Successfully ===");
|
||||
}
|
||||
} // namespace UnitTest
|
||||
|
||||
#endif
|
||||
Reference in new issue
Block a user