upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/shims/file_system.cpp
diff options
context:
space:
mode:
authorjaybeebabageyus <jaybeebabageyus@users.noreply.github.com>2026-11-22 17:01:52 +0100
committerjaybeebabageyus <jaybeebabageyus@users.noreply.github.com>2026-11-22 17:01:52 +0100
commit403d59060e89d706429ec9eca23b6ce7b7ef03c4 (patch)
tree58e563b0093062d6a2aa309e09ee1ef875f28bc8 /runtime/shims/file_system.cpp
parent6a6704df1592e1dc4a3215ddf1423a78adb52045 (diff)
runtime: shim CreateFile2 and FindFirstFileExA/W for GAME: paths and overlay
Diffstat (limited to 'runtime/shims/file_system.cpp')
-rw-r--r--runtime/shims/file_system.cpp83
1 files changed, 83 insertions, 0 deletions
diff --git a/runtime/shims/file_system.cpp b/runtime/shims/file_system.cpp
index f0ae08811..7f3272e88 100644
--- a/runtime/shims/file_system.cpp
+++ b/runtime/shims/file_system.cpp
@@ -369,6 +369,20 @@ HANDLE WINAPI create_file_a(LPCSTR name, DWORD access, DWORD share, LPSECURITY_A
369 return create_file_w(wide.c_str(), access, share, attributes, disposition, flags, template_file); 369 return create_file_w(wide.c_str(), access, share, attributes, disposition, flags, template_file);
370} 370}
371 371
372HANDLE WINAPI create_file2(LPCWSTR name, DWORD access, DWORD share, DWORD disposition,
373 LPCREATEFILE2_EXTENDED_PARAMETERS params) {
374 if (!name) {
375 SetLastError(ERROR_INVALID_PARAMETER);
376 return INVALID_HANDLE_VALUE;
377 }
378 const Target t = open_target(name, access, disposition);
379 if (t.error) {
380 SetLastError(t.error);
381 return INVALID_HANDLE_VALUE;
382 }
383 return ::CreateFile2(t.path.c_str(), access, share, disposition, params);
384}
385
372DWORD WINAPI get_file_attributes_w(LPCWSTR name) { 386DWORD WINAPI get_file_attributes_w(LPCWSTR name) {
373 if (!name) { 387 if (!name) {
374 SetLastError(ERROR_INVALID_PARAMETER); 388 SetLastError(ERROR_INVALID_PARAMETER);
@@ -439,6 +453,72 @@ HANDLE WINAPI find_first_file_w(LPCWSTR pattern, LPWIN32_FIND_DATAW data) {
439 return register_enumeration(std::move(e)); 453 return register_enumeration(std::move(e));
440} 454}
441 455
456HANDLE WINAPI find_first_file_ex_w(LPCWSTR pattern, FINDEX_INFO_LEVELS info_level, LPVOID data,
457 FINDEX_SEARCH_OPS search_op, LPVOID search_filter, DWORD additional_flags) {
458 if (!pattern || !data) {
459 SetLastError(ERROR_INVALID_PARAMETER);
460 return INVALID_HANDLE_VALUE;
461 }
462 std::vector<std::wstring> parts;
463 const Parsed parsed = parse_console(pattern, parts);
464 if (parsed == Parsed::Host)
465 return ::FindFirstFileExW(pattern, info_level, data, search_op, search_filter, additional_flags);
466 if (parsed == Parsed::Refused) {
467 SetLastError(ERROR_INVALID_NAME);
468 return INVALID_HANDLE_VALUE;
469 }
470 if (info_level != FindExInfoStandard && info_level != FindExInfoBasic) {
471 SetLastError(ERROR_INVALID_PARAMETER);
472 return INVALID_HANDLE_VALUE;
473 }
474 if (search_op != FindExSearchNameMatch && search_op != FindExSearchLimitToDirectories) {
475 SetLastError(ERROR_INVALID_PARAMETER);
476 return INVALID_HANDLE_VALUE;
477 }
478
479 std::vector<WIN32_FIND_DATAW> entries;
480 DWORD error = 0;
481 if (!collect(pattern, parts, entries, error)) {
482 SetLastError(error);
483 return INVALID_HANDLE_VALUE;
484 }
485 if (search_op == FindExSearchLimitToDirectories) {
486 std::vector<WIN32_FIND_DATAW> dirs_only;
487 for (auto& entry : entries)
488 if ((entry.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0) dirs_only.push_back(entry);
489 entries = std::move(dirs_only);
490 if (entries.empty()) {
491 SetLastError(ERROR_FILE_NOT_FOUND);
492 return INVALID_HANDLE_VALUE;
493 }
494 }
495 if (info_level == FindExInfoBasic) {
496 for (auto& entry : entries) entry.cAlternateFileName[0] = L'\0';
497 }
498 auto e = std::make_unique<Enumeration>();
499 e->entries = std::move(entries);
500 e->next = 1;
501 *static_cast<LPWIN32_FIND_DATAW>(data) = e->entries[0];
502 return register_enumeration(std::move(e));
503}
504
505HANDLE WINAPI find_first_file_ex_a(LPCSTR pattern, FINDEX_INFO_LEVELS info_level, LPVOID data,
506 FINDEX_SEARCH_OPS search_op, LPVOID search_filter, DWORD additional_flags) {
507 if (!pattern || !data) {
508 SetLastError(ERROR_INVALID_PARAMETER);
509 return INVALID_HANDLE_VALUE;
510 }
511 const std::wstring wide = widen_ansi(pattern);
512 std::vector<std::wstring> parts;
513 const Parsed parsed = parse_console(wide, parts);
514 if (parsed == Parsed::Host)
515 return ::FindFirstFileExA(pattern, info_level, data, search_op, search_filter, additional_flags);
516 WIN32_FIND_DATAW wide_data{};
517 const HANDLE h = find_first_file_ex_w(wide.c_str(), info_level, &wide_data, search_op, search_filter, additional_flags);
518 if (h != INVALID_HANDLE_VALUE) to_ansi(wide_data, static_cast<LPWIN32_FIND_DATAA>(data));
519 return h;
520}
521
442HANDLE WINAPI find_first_file_a(LPCSTR pattern, LPWIN32_FIND_DATAA data) { 522HANDLE WINAPI find_first_file_a(LPCSTR pattern, LPWIN32_FIND_DATAA data) {
443 if (!pattern || !data) { 523 if (!pattern || !data) {
444 SetLastError(ERROR_INVALID_PARAMETER); 524 SetLastError(ERROR_INVALID_PARAMETER);
@@ -568,8 +648,11 @@ using namespace rt::fs;
568#define FILE_API(dll) \ 648#define FILE_API(dll) \
569 {dll, "CreateFileA", reinterpret_cast<void*>(&create_file_a)}, \ 649 {dll, "CreateFileA", reinterpret_cast<void*>(&create_file_a)}, \
570 {dll, "CreateFileW", reinterpret_cast<void*>(&create_file_w)}, \ 650 {dll, "CreateFileW", reinterpret_cast<void*>(&create_file_w)}, \
651 {dll, "CreateFile2", reinterpret_cast<void*>(&create_file2)}, \
571 {dll, "FindFirstFileA", reinterpret_cast<void*>(&find_first_file_a)}, \ 652 {dll, "FindFirstFileA", reinterpret_cast<void*>(&find_first_file_a)}, \
572 {dll, "FindFirstFileW", reinterpret_cast<void*>(&find_first_file_w)}, \ 653 {dll, "FindFirstFileW", reinterpret_cast<void*>(&find_first_file_w)}, \
654 {dll, "FindFirstFileExA", reinterpret_cast<void*>(&find_first_file_ex_a)}, \
655 {dll, "FindFirstFileExW", reinterpret_cast<void*>(&find_first_file_ex_w)}, \
573 {dll, "FindNextFileA", reinterpret_cast<void*>(&find_next_file_a)}, \ 656 {dll, "FindNextFileA", reinterpret_cast<void*>(&find_next_file_a)}, \
574 {dll, "FindNextFileW", reinterpret_cast<void*>(&find_next_file_w)}, \ 657 {dll, "FindNextFileW", reinterpret_cast<void*>(&find_next_file_w)}, \
575 {dll, "FindClose", reinterpret_cast<void*>(&find_close)}, \ 658 {dll, "FindClose", reinterpret_cast<void*>(&find_close)}, \