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
+46
-27
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 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);
|
JULIET_API bool fs_create_directory(String path, bool recursive);
|
||||||
|
|
||||||
|
|||||||
@@ -78,11 +78,8 @@ Path GetAssetPath(NonNullPtr<Arena> arena, AssetType type, String filename)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
String asset_path = CleanPath(arena, { buffer, totalSize - 1 });
|
Path asset_path = fs_create_clean_path(arena, { buffer, totalSize - 1 });
|
||||||
String directories = asset_path;
|
return asset_path;
|
||||||
directories.Size -= filename.Size;
|
|
||||||
Path path = { directories, asset_path };
|
|
||||||
return path;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsAbsolutePath(String path)
|
bool IsAbsolutePath(String path)
|
||||||
@@ -94,9 +91,9 @@ bool IsAbsolutePath(String path)
|
|||||||
return Platform::IsAbsolutePath(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)
|
bool fs_create_directory(String path, bool recursive)
|
||||||
@@ -129,9 +126,9 @@ void InitFilesystem(NonNullPtr<Arena> arena)
|
|||||||
if (DirectoryExists(probePath))
|
if (DirectoryExists(probePath))
|
||||||
{
|
{
|
||||||
// Clean the path first to remove any relative parts
|
// Clean the path first to remove any relative parts
|
||||||
String abs_path = CleanPath(arena, WrapString(probePath));
|
Path abs_path = fs_create_clean_path(arena, WrapString(probePath));
|
||||||
CachedAssetBasePath = { abs_path, abs_path };
|
CachedAssetBasePath = abs_path;
|
||||||
Log(LogLevel::Message, LogCategory::Core, "Asset base path: %s", CStr(abs_path));
|
Log(LogLevel::Message, LogCategory::Core, "Asset base path: %s", CStr(abs_path.FullPath));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -149,9 +146,9 @@ void InitFilesystem(NonNullPtr<Arena> arena)
|
|||||||
if (DirectoryExists(probePath))
|
if (DirectoryExists(probePath))
|
||||||
{
|
{
|
||||||
// Clean the path first to remove any relative parts
|
// Clean the path first to remove any relative parts
|
||||||
String abs_path = CleanPath(arena, WrapString(probePath));
|
Path abs_path = fs_create_clean_path(arena, WrapString(probePath));
|
||||||
CachedShaderBasePath = { abs_path, abs_path };
|
CachedShaderBasePath = abs_path;
|
||||||
Log(LogLevel::Message, LogCategory::Core, "Asset base path: %s", CStr(abs_path));
|
Log(LogLevel::Message, LogCategory::Core, "Asset base path: %s", CStr(abs_path.FullPath));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,9 +4,9 @@
|
|||||||
|
|
||||||
namespace Platform
|
namespace Platform
|
||||||
{
|
{
|
||||||
Path GetBasePath(NonNullPtr<Arena> arena);
|
Path GetBasePath(NonNullPtr<Arena> arena);
|
||||||
bool IsAbsolutePath(String path);
|
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_create_directory(String path, bool recursive);
|
||||||
bool fs_path_exists(String path);
|
bool fs_path_exists(String path);
|
||||||
} // namespace Platform
|
} // namespace Platform
|
||||||
@@ -94,7 +94,7 @@ namespace Platform
|
|||||||
return false;
|
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];
|
char clean_path_buffer[MAX_PATH];
|
||||||
LPSTR file_part = nullptr;
|
LPSTR file_part = nullptr;
|
||||||
@@ -104,7 +104,20 @@ namespace Platform
|
|||||||
LogError(LogCategory::Core, "Failed to resolve path. Error: %lu\n", GetLastError());
|
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)
|
bool fs_create_directory(String path, bool recursive)
|
||||||
@@ -174,10 +187,8 @@ namespace Platform
|
|||||||
|
|
||||||
bool fs_path_exists(String path)
|
bool fs_path_exists(String path)
|
||||||
{
|
{
|
||||||
DWORD attribs = GetFileAttributesA(CStr(path));
|
const DWORD attribs = GetFileAttributesA(CStr(path));
|
||||||
|
const bool result = (attribs != INVALID_FILE_ATTRIBUTES);
|
||||||
// If the function fails, the file or directory does not exist (or path is invalid)
|
|
||||||
bool result = (attribs == INVALID_FILE_ATTRIBUTES);
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
} // namespace Platform
|
} // namespace Platform
|
||||||
@@ -125,7 +125,8 @@ namespace Internal
|
|||||||
String result = {};
|
String result = {};
|
||||||
if (GetUserNameA(username, &usernameLength) && usernameLength > 1)
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ void initialize_user_system()
|
|||||||
|
|
||||||
String username = os_get_username(temp.Arena);
|
String username = os_get_username(temp.Arena);
|
||||||
|
|
||||||
if (file_exists)
|
if (!file_exists)
|
||||||
{
|
{
|
||||||
fs_create_directory(user_system_path.Directories, true);
|
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);
|
ParsedArchive parsed_archive = tokenize_archive(temp.Arena, user_file);
|
||||||
|
|
||||||
Archive ar = { .arena = temp.Arena, .loading = true, .base = parsed_archive };
|
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);
|
scratch_end(temp);
|
||||||
|
|||||||
Reference in new issue
Block a user