diff --git a/Assets/config/users.ini b/Assets/config/users.ini new file mode 100644 index 0000000..351407e --- /dev/null +++ b/Assets/config/users.ini @@ -0,0 +1,2 @@ +; Paul +1 diff --git a/Juliet/include/Core/HAL/Filesystem/Filesystem.h b/Juliet/include/Core/HAL/Filesystem/Filesystem.h index d628fb5..54679d2 100644 --- a/Juliet/include/Core/HAL/Filesystem/Filesystem.h +++ b/Juliet/include/Core/HAL/Filesystem/Filesystem.h @@ -28,7 +28,7 @@ JULIET_API Path GetAssetPath(NonNullPtr arena, AssetType type, String fil JULIET_API bool IsAbsolutePath(String path); -JULIET_API String CleanPath(NonNullPtr arena, String path); +JULIET_API Path fs_create_clean_path(NonNullPtr arena, String path); JULIET_API bool fs_create_directory(String path, bool recursive); diff --git a/Juliet/src/Core/HAL/Filesystem/Filesystem.cpp b/Juliet/src/Core/HAL/Filesystem/Filesystem.cpp index a0bdafa..debdf3e 100644 --- a/Juliet/src/Core/HAL/Filesystem/Filesystem.cpp +++ b/Juliet/src/Core/HAL/Filesystem/Filesystem.cpp @@ -78,11 +78,8 @@ Path GetAssetPath(NonNullPtr arena, AssetType type, String filename) break; } - String asset_path = CleanPath(arena, { buffer, totalSize - 1 }); - String directories = asset_path; - directories.Size -= filename.Size; - Path path = { directories, asset_path }; - return path; + Path asset_path = fs_create_clean_path(arena, { buffer, totalSize - 1 }); + return asset_path; } bool IsAbsolutePath(String path) @@ -94,9 +91,9 @@ bool IsAbsolutePath(String path) return Platform::IsAbsolutePath(path); } -String CleanPath(NonNullPtr arena, String path) +Path fs_create_clean_path(NonNullPtr arena, String path) { - return Platform::CleanPath(arena, path); + return Platform::fs_create_clean_path(arena, path); } bool fs_create_directory(String path, bool recursive) @@ -129,9 +126,9 @@ void InitFilesystem(NonNullPtr arena) if (DirectoryExists(probePath)) { // Clean the path first to remove any relative parts - String abs_path = CleanPath(arena, WrapString(probePath)); - CachedAssetBasePath = { abs_path, abs_path }; - Log(LogLevel::Message, LogCategory::Core, "Asset base path: %s", CStr(abs_path)); + Path abs_path = fs_create_clean_path(arena, WrapString(probePath)); + CachedAssetBasePath = abs_path; + Log(LogLevel::Message, LogCategory::Core, "Asset base path: %s", CStr(abs_path.FullPath)); break; } } @@ -149,9 +146,9 @@ void InitFilesystem(NonNullPtr arena) if (DirectoryExists(probePath)) { // Clean the path first to remove any relative parts - String abs_path = CleanPath(arena, WrapString(probePath)); - CachedShaderBasePath = { abs_path, abs_path }; - Log(LogLevel::Message, LogCategory::Core, "Asset base path: %s", CStr(abs_path)); + Path abs_path = fs_create_clean_path(arena, WrapString(probePath)); + CachedShaderBasePath = abs_path; + Log(LogLevel::Message, LogCategory::Core, "Asset base path: %s", CStr(abs_path.FullPath)); break; } } diff --git a/Juliet/src/Core/HAL/Filesystem/Filesystem_Platform.h b/Juliet/src/Core/HAL/Filesystem/Filesystem_Platform.h index 571366d..87604b3 100644 --- a/Juliet/src/Core/HAL/Filesystem/Filesystem_Platform.h +++ b/Juliet/src/Core/HAL/Filesystem/Filesystem_Platform.h @@ -4,9 +4,9 @@ namespace Platform { - Path GetBasePath(NonNullPtr arena); - bool IsAbsolutePath(String path); - String CleanPath(NonNullPtr arena, String path); - bool fs_create_directory(String path, bool recursive); - bool fs_path_exists(String path); + Path GetBasePath(NonNullPtr arena); + bool IsAbsolutePath(String path); + Path fs_create_clean_path(NonNullPtr arena, String path); + bool fs_create_directory(String path, bool recursive); + bool fs_path_exists(String path); } // namespace Platform diff --git a/Juliet/src/Core/HAL/Filesystem/Win32/Win32Filesystem.cpp b/Juliet/src/Core/HAL/Filesystem/Win32/Win32Filesystem.cpp index 4cb7b93..23fcd1b 100644 --- a/Juliet/src/Core/HAL/Filesystem/Win32/Win32Filesystem.cpp +++ b/Juliet/src/Core/HAL/Filesystem/Win32/Win32Filesystem.cpp @@ -94,7 +94,7 @@ namespace Platform return false; } - String CleanPath(NonNullPtr arena, String path) + Path fs_create_clean_path(NonNullPtr arena, String path) { char clean_path_buffer[MAX_PATH]; LPSTR file_part = nullptr; @@ -104,7 +104,20 @@ namespace Platform LogError(LogCategory::Core, "Failed to resolve path. Error: %lu\n", GetLastError()); } - return StringCopy(arena, WrapString(clean_path_buffer)); + String full_path = StringCopy(arena, WrapString(clean_path_buffer)); + String temp_directories = full_path; + + if (file_part != nullptr) + { + ptrdiff_t diff = (file_part - clean_path_buffer); + temp_directories.Size = diff; + } + + String directories = StringCopy(arena, temp_directories); + + Path result_path = { directories, full_path }; + + return result_path; } bool fs_create_directory(String path, bool recursive) @@ -174,10 +187,8 @@ namespace Platform bool fs_path_exists(String path) { - DWORD attribs = GetFileAttributesA(CStr(path)); - - // If the function fails, the file or directory does not exist (or path is invalid) - bool result = (attribs == INVALID_FILE_ATTRIBUTES); + const DWORD attribs = GetFileAttributesA(CStr(path)); + const bool result = (attribs != INVALID_FILE_ATTRIBUTES); return result; } } // namespace Platform diff --git a/Juliet/src/Core/HAL/OS/Win32/Win32OS.cpp b/Juliet/src/Core/HAL/OS/Win32/Win32OS.cpp index 655324e..55093c6 100644 --- a/Juliet/src/Core/HAL/OS/Win32/Win32OS.cpp +++ b/Juliet/src/Core/HAL/OS/Win32/Win32OS.cpp @@ -125,7 +125,8 @@ namespace Internal String result = {}; if (GetUserNameA(username, &usernameLength) && usernameLength > 1) { - result = StringCopy(arena, { username, usernameLength }); + // GetUserNameA returns the length including trailing \0 + result = StringCopy(arena, { username, usernameLength - 1 }); } return result; } diff --git a/Juliet/src/Engine/user.cpp b/Juliet/src/Engine/user.cpp index 13ccae1..0f0f4ab 100644 --- a/Juliet/src/Engine/user.cpp +++ b/Juliet/src/Engine/user.cpp @@ -20,7 +20,7 @@ void initialize_user_system() String username = os_get_username(temp.Arena); - if (file_exists) + if (!file_exists) { fs_create_directory(user_system_path.Directories, true); @@ -41,6 +41,14 @@ void initialize_user_system() ParsedArchive parsed_archive = tokenize_archive(temp.Arena, user_file); Archive ar = { .arena = temp.Arena, .loading = true, .base = parsed_archive }; + + if (ArchivePropertyNode* prop = find_property(&parsed_archive, crc32(username))) + { + // User exists lets read + uint8 user_id = 0; + read_prop(ar, prop->value, user_id); + Assert(user_id != 0); + } } scratch_end(temp);