moved os_folder_exists to the main layer and deleted win32 layer from linker folder

This commit is contained in:
Nikita Smith
2024-11-07 13:54:56 -08:00
parent ef5287d2a9
commit daeb08e79f
4 changed files with 12 additions and 104 deletions
-7
View File
@@ -3,12 +3,6 @@
#pragma once
#if OS_WINDOWS
# include "os_core_win32.c"
#else
# error "undefined OS"
#endif
typedef struct
{
String8Array path_arr;
@@ -27,5 +21,4 @@ typedef struct
internal String8Array os_data_from_file_path_parallel(TP_Context *tp, Arena *arena, String8Array path_arr);
internal String8List os_file_search(Arena *arena, String8List dir_list, String8 file_path);
internal B32 os_folder_path_exists(String8 path);
-97
View File
@@ -1,97 +0,0 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
internal B32
os_w32_has_path_volume_prefix(String8 path)
{
if (path.size >= 2) {
U8 *ptr = path.str;
U8 *opl = path.str + path.size;
UnicodeDecode a = utf8_decode(ptr, (U64)(opl-ptr));
ptr += a.inc;
UnicodeDecode b = utf8_decode(ptr, (U64)(opl-ptr));
return a.codepoint < max_U8 && char_is_alpha(a.codepoint) && b.codepoint == ':';
}
return 0;
}
internal B32
os_w32_has_device_prefix(String8 path)
{
if (path.size >= 3) {
U8 *ptr = path.str;
U8 *opl = path.str + path.size;
UnicodeDecode a = utf8_decode(ptr, (U64)(opl-ptr));
ptr += a.inc;
UnicodeDecode b = utf8_decode(ptr, (U64)(opl-ptr));
ptr += b.inc;
UnicodeDecode c = utf8_decode(ptr, (U64)(opl-ptr));
return a.codepoint == '\\' && b.codepoint == '\\' && (c.codepoint == '?' || c.codepoint == '.');
}
return 0;
}
internal B32
os_w32_has_unc_prefix(String8 path)
{
if (path.size >= 2) {
U8 *ptr = path.str;
U8 *opl = path.str + path.size;
UnicodeDecode a = utf8_decode(ptr, (U64)(opl-ptr));
ptr += a.inc;
UnicodeDecode b = utf8_decode(ptr, (U64)(opl-ptr));
return a.codepoint == '\\' && b.codepoint == '\\';
}
return 0;
}
internal B32
os_w32_has_root_drive_prefix(String8 path)
{
if (path.size >= 1) {
UnicodeDecode a = utf8_decode(path.str, path.size);
return a.codepoint == '\\';
}
return 0;
}
internal B32
os_w32_is_path_relative_current_directory(String8 path)
{
if (os_w32_has_path_volume_prefix(path)) {
return 0;
}
if (os_w32_has_device_prefix(path)) {
return 0;
}
if (os_w32_has_unc_prefix(path)) {
return 0;
}
if (os_w32_has_root_drive_prefix(path)) {
return 0;
}
return 1;
}
internal B32
os_folder_path_exists(String8 path)
{
Temp scratch = scratch_begin(0,0);
String8 actual_path = path;
if (os_w32_is_path_relative_current_directory(path)) {
String8 current = os_get_current_path(scratch.arena);
String8List list = {0};
str8_list_push(scratch.arena, &list, current);
str8_list_push(scratch.arena, &list, path);
StringJoin join = { .sep = str8_lit_comp("\\") };
actual_path =str8_list_join(scratch.arena, &list, &join);
}
String16 path16 = str16_from_8(scratch.arena, actual_path);
DWORD attributes = GetFileAttributesW((WCHAR *)path16.str);
B32 exists = (attributes != INVALID_FILE_ATTRIBUTES) && (attributes & FILE_ATTRIBUTE_DIRECTORY);
scratch_end(scratch);
return exists;
}
+1
View File
@@ -210,6 +210,7 @@ internal B32 os_delete_file_at_path(String8 path);
internal B32 os_copy_file_path(String8 dst, String8 src);
internal String8 os_full_path_from_path(Arena *arena, String8 path);
internal B32 os_file_path_exists(String8 path);
internal B32 os_folder_path_exists(String8 path);
internal FileProperties os_properties_from_file_path(String8 path);
//- rjf: file maps
+11
View File
@@ -521,6 +521,17 @@ os_file_path_exists(String8 path)
return exists;
}
internal B32
os_folder_path_exists(String8 path)
{
Temp scratch = scratch_begin(0,0);
String16 path16 = str16_from_8(scratch.arena, path);
DWORD attributes = GetFileAttributesW((WCHAR *)path16.str);
B32 exists = (attributes != INVALID_FILE_ATTRIBUTES) && (attributes & FILE_ATTRIBUTE_DIRECTORY);
scratch_end(scratch);
return exists;
}
internal FileProperties
os_properties_from_file_path(String8 path)
{