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

Codechange: Use std::filesystem::directory_iterator instead of opendir. #12524

Merged
merged 4 commits into from
Apr 18, 2024

Conversation

PeterN
Copy link
Member

@PeterN PeterN commented Apr 17, 2024

Motivation / Problem

We use opendir/readdir/closedir to scan for files inside directories.

This a C API so requires char * strings, and does not exist on Windows, so we have our own custom implementation using the Windows APIs.

C++'s take on this is std::filesystem::directory_iterator (which I've previously use for language file scanning), which is cross-platform and basically much nicer to use.

Description

This changeset make use of std::filesystem::directory_iterator, tweaks a couple of still-specific functions (Windows does hidden files differently) and then removes all of the custom opendir/readdir/closedir implemention for Windows.

The first commit is actually #12493, which is simplified with a different call but is included here because the current implementation uses ttd_opendir.

Limitations

Not actually tested on Windows because I don't use it.

Checklist for review

Some things are not automated, and forgotten often. This list is a reminder for the reviewers.

  • The bug fix is important enough to be backported? (label: 'backport requested')
  • This PR touches english.txt or translations? Check the guidelines
  • This PR affects the save game format? (label 'savegame upgrade')
  • This PR affects the GS/AI API? (label 'needs review: Script API')
    • ai_changelog.hpp, game_changelog.hpp need updating.
    • The compatibility wrappers (compat_*.nut) need updating.
  • This PR affects the NewGRF API? (label 'needs review: NewGRF')

`std::filesystem` provides `create_directories()` as a cross-platform way to create a directory tree.
src/os/windows/win32.cpp Outdated Show resolved Hide resolved
glx22
glx22 previously approved these changes Apr 17, 2024
…indows.

This replaces use of custom ttd_opendir. Files are listed separately using ScanPath as that handles downloaded content.
Replaces use of custom ttd_opendir.
std::filesystem::directory_iterator is now used instead.
@PeterN PeterN merged commit 63ce815 into OpenTTD:master Apr 18, 2024
15 checks passed
@PeterN PeterN deleted the directory_iterator branch April 18, 2024 00:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants