Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add trailing periods support to FindFirstFileA #75

Merged
merged 5 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions dll/kernel32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ namespace kernel32 {
}

uint32_t WIN_FUNC GetLastError() {
DEBUG_LOG("GetLastError() -> %u\n", wibo::lastError);
return wibo::lastError;
}

Expand Down Expand Up @@ -276,6 +277,7 @@ namespace kernel32 {
}

int WIN_FUNC GetSystemDefaultLangID() {
DEBUG_LOG("STUB GetSystemDefaultLangID\n");
return 0;
}

Expand Down Expand Up @@ -680,6 +682,13 @@ namespace kernel32 {
};

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

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

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

Expand All @@ -1302,6 +1312,7 @@ namespace kernel32 {
};

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

unsigned int WIN_FUNC GetCurrentDirectoryA(unsigned int uSize, char *lpBuffer) {
DEBUG_LOG("GetCurrentDirectoryA(%u, %p)\n", uSize, lpBuffer);
DEBUG_LOG("GetCurrentDirectoryA(%u, %p)", uSize, lpBuffer);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove the \n?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the debug logs I added get printed in the same line


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

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

DEBUG_LOG(" -> %s\n", path.c_str());
strcpy(lpBuffer, path.c_str());
return path.size();
}
Expand Down Expand Up @@ -1786,6 +1799,7 @@ namespace kernel32 {
return 1;

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

Expand Down
1 change: 0 additions & 1 deletion files.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ namespace files {
return path;
}

path = path.lexically_normal();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is important

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is duplicated, there's another lexically_normal call above. Unless calling it twice is required?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see, definitely shouldn’t be required twice. Wonder how it got that way 🤔

std::filesystem::path newPath = ".";
bool followingExisting = true;
for (const auto& component : path) {
Expand Down
Loading