more path utils and fixing get os username that was returning a string including the \0
User now can be serialized properly
This commit is contained in:
1 parent
1367146503
commit
f32a3f73a9
7 files changed
+42
-23
No files matched your search
@@ -0,0 +1,2 @@
|
||||
; Paul
|
||||
1
|
||||
@@ -28,7 +28,7 @@ JULIET_API Path GetAssetPath(NonNullPtr<Arena> arena, AssetType type, String fil
|
||||
|
||||
JULIET_API bool IsAbsolutePath(String path);
|
||||
|
||||
JULIET_API String CleanPath(NonNullPtr<Arena> arena, String path);
|
||||
JULIET_API Path fs_create_clean_path(NonNullPtr<Arena> arena, String path);
|
||||
|
||||
JULIET_API bool fs_create_directory(String path, bool recursive);
|
||||
|
||||
|
||||
@@ -78,11 +78,8 @@ Path GetAssetPath(NonNullPtr<Arena> 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> arena, String path)
|
||||
Path fs_create_clean_path(NonNullPtr<Arena> 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> 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> 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ namespace Platform
|
||||
{
|
||||
Path GetBasePath(NonNullPtr<Arena> arena);
|
||||
bool IsAbsolutePath(String path);
|
||||
String CleanPath(NonNullPtr<Arena> arena, String path);
|
||||
Path fs_create_clean_path(NonNullPtr<Arena> arena, String path);
|
||||
bool fs_create_directory(String path, bool recursive);
|
||||
bool fs_path_exists(String path);
|
||||
} // namespace Platform
|
||||
@@ -94,7 +94,7 @@ namespace Platform
|
||||
return false;
|
||||
}
|
||||
|
||||
String CleanPath(NonNullPtr<Arena> arena, String path)
|
||||
Path fs_create_clean_path(NonNullPtr<Arena> 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
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user