-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use
fs::path
for paths instead of std::string
or char[MAX_PATH]
.
- Loading branch information
Showing
22 changed files
with
205 additions
and
417 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
8cd05ad
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Converting between std::string and std::filesystem::path can unfortunately be problematic for paths with non-ASCII characters, under Windows (if you ever use them in a function like std::filesystem::exists(). This is because under Windows the native encoding of std::filesystem::path is UTF-16, rather than UTF-8.
The fix for that is to use conversion functions which can properly convert between std::string (which in Stratagus we expect to have UTF-8 content) and std::filesystem::path. This can be achieved like this, for example:
That code is based on utility functions I wrote here:
https://github.com/Andrettin/Archimedes/blob/main/src/util/path_util.h
8cd05ad
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is (future deprecated)
https://en.cppreference.com/w/cpp/filesystem/path/u8path
to unify your code.I have to recheck conversion (but idea is also to decrease the number of such conversions).
thanks.
8cd05ad
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello Joris, thank you!
I was mentioning this just because I found out the hard way that these problems can occur. But it is a really good idea to use std::filesystem::path for paths, it does simplify the code a good deal (I'm also doing it for Wyrmgus).
8cd05ad
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have check code, and we are not utf-8 everywhere :-/
I think that
filesystem::string()
(and even u8 version) should be constraint to final usage (fopen-like or display API).I retest filesystem behavior:
We always have:
So, I should not have introduce bug with that.
And using
u8string()
forprintf
output would improve exactitude :).8cd05ad
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Andrettin :
Even more "fun":
SDL_RWops
uses UTF-8FILE
uses system encodingstd::fstream
uses system encoding (but acceptfs::path
).DIdin't check bz2/gzip we used...