Skip to content

Commit ca9364a

Browse files
authored
Add trailing periods support to FindFirstFileA (#75)
* idk * meh * Implement trailing periods on FindFirstFileA * ah? * Remove assert
1 parent 396008c commit ca9364a

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

dll/kernel32.cpp

+16-2
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ namespace kernel32 {
119119
}
120120

121121
uint32_t WIN_FUNC GetLastError() {
122+
DEBUG_LOG("GetLastError() -> %u\n", wibo::lastError);
122123
return wibo::lastError;
123124
}
124125

@@ -276,6 +277,7 @@ namespace kernel32 {
276277
}
277278

278279
int WIN_FUNC GetSystemDefaultLangID() {
280+
DEBUG_LOG("STUB GetSystemDefaultLangID\n");
279281
return 0;
280282
}
281283

@@ -680,6 +682,13 @@ namespace kernel32 {
680682
};
681683

682684
bool findNextFile(FindFirstFileHandle *handle) {
685+
if ((handle->it != std::filesystem::directory_iterator()) && (handle->pattern == "")) {
686+
// The caller (ie `FindFirstFileA`) was passed a path with a
687+
// trailing period (like `include/.`). This behavior doesn't seem
688+
// to be documented, so we treat it as an "find any file on this
689+
// directory".
690+
return true;
691+
}
683692
while (handle->it != std::filesystem::directory_iterator()) {
684693
std::filesystem::path path = *handle->it;
685694
if (fnmatch(handle->pattern.c_str(), path.filename().c_str(), 0) == 0) {
@@ -774,6 +783,7 @@ namespace kernel32 {
774783
}
775784

776785
int WIN_FUNC FindNextFileA(void *hFindFile, WIN32_FIND_DATA<char> *lpFindFileData) {
786+
DEBUG_LOG("FindNextFileA(%p, %p)\n", hFindFile, lpFindFileData);
777787
// Special value from FindFirstFileA
778788
if (hFindFile == (void *) 1) {
779789
wibo::lastError = ERROR_NO_MORE_FILES;
@@ -1279,7 +1289,7 @@ namespace kernel32 {
12791289
}
12801290

12811291
unsigned int WIN_FUNC SetConsoleCtrlHandler(void *HandlerRoutine, unsigned int Add) {
1282-
DEBUG_LOG("SetConsoleCtrlHandler\n");
1292+
DEBUG_LOG("STUB SetConsoleCtrlHandler\n");
12831293
// This is a function that gets called when doing ^C
12841294
// We might want to call this later (being mindful that it'll be stdcall I think)
12851295

@@ -1302,6 +1312,7 @@ namespace kernel32 {
13021312
};
13031313

13041314
unsigned int WIN_FUNC GetConsoleScreenBufferInfo(void *hConsoleOutput, CONSOLE_SCREEN_BUFFER_INFO *lpConsoleScreenBufferInfo) {
1315+
DEBUG_LOG("GetConsoleScreenBufferInfo(%p, %p)\n", hConsoleOutput, lpConsoleScreenBufferInfo);
13051316
// Tell a lie
13061317
// mwcc doesn't care about anything else
13071318
lpConsoleScreenBufferInfo->dwSize_x = 80;
@@ -1368,17 +1379,19 @@ namespace kernel32 {
13681379
}
13691380

13701381
unsigned int WIN_FUNC GetCurrentDirectoryA(unsigned int uSize, char *lpBuffer) {
1371-
DEBUG_LOG("GetCurrentDirectoryA(%u, %p)\n", uSize, lpBuffer);
1382+
DEBUG_LOG("GetCurrentDirectoryA(%u, %p)", uSize, lpBuffer);
13721383

13731384
std::filesystem::path cwd = std::filesystem::current_path();
13741385
std::string path = files::pathToWindows(cwd);
13751386

13761387
// If the buffer is too small, return the required buffer size.
13771388
// (Add 1 to include the NUL terminator)
13781389
if (path.size() + 1 > uSize) {
1390+
DEBUG_LOG(" !! Buffer too small: %i, %i\n", path.size() + 1, uSize);
13791391
return path.size() + 1;
13801392
}
13811393

1394+
DEBUG_LOG(" -> %s\n", path.c_str());
13821395
strcpy(lpBuffer, path.c_str());
13831396
return path.size();
13841397
}
@@ -1786,6 +1799,7 @@ namespace kernel32 {
17861799
return 1;
17871800

17881801
// sure.. we have that feature...
1802+
DEBUG_LOG(" IsProcessorFeaturePresent: we don't know about feature %u, lying...\n", processorFeature);
17891803
return 1;
17901804
}
17911805

files.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ namespace files {
3232
return path;
3333
}
3434

35-
path = path.lexically_normal();
3635
std::filesystem::path newPath = ".";
3736
bool followingExisting = true;
3837
for (const auto& component : path) {

0 commit comments

Comments
 (0)