diff --git a/src/linker/os_ext/core/os_core.h b/src/linker/os_ext/core/os_core.h index 5396e19e..c7791972 100644 --- a/src/linker/os_ext/core/os_core.h +++ b/src/linker/os_ext/core/os_core.h @@ -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); diff --git a/src/linker/os_ext/core/os_core_win32.c b/src/linker/os_ext/core/os_core_win32.c deleted file mode 100644 index a50afce4..00000000 --- a/src/linker/os_ext/core/os_core_win32.c +++ /dev/null @@ -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; -} - diff --git a/src/os/core/os_core.h b/src/os/core/os_core.h index 7f27f17a..fadd181b 100644 --- a/src/os/core/os_core.h +++ b/src/os/core/os_core.h @@ -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 diff --git a/src/os/core/win32/os_core_win32.c b/src/os/core/win32/os_core_win32.c index d45be2c5..59a323a4 100644 --- a/src/os/core/win32/os_core_win32.c +++ b/src/os/core/win32/os_core_win32.c @@ -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) {