Skip to content
New issue

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

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

Already on GitHub? # to your account

Update tt_string's use of std::filesystem, update Image/Data list file modification tracking #1421

Merged
merged 7 commits into from
Feb 23, 2024

Conversation

Randalphwa
Copy link
Collaborator

This PR has two parts. The first is an overhaul of tt_string's use of std::filesystem. A CHAR8_T_CAST macro is now used to cast a std::string.cstr() to either (char const*) for C++17 or (char8_t const*) for C++20 and beyond. This ensures that std::filesystem::path() will correctly convert all UTF-8 encoded strings to the correct path on all platforms.

A new tt_string::assign_path() method is added which supports converting a std::filesystem::path to a tt_string that works on all platforms. This eliminates the need for the _WIN32 conditionals that were used in other methods dealing with conversion from a path to a string.

New methods:

  • std::filesystem::path make_path()
  • std::uintmax_t file_size()

The second part replaces wxDateTime with std::filesystem::file_time_type for image and data lists. This is a much more efficient way to get the modified time of a file.

std::filesystem::path will handle the conversion from UTF8 for all platforms.

CHAR8_T_CAST is used so the conversion works in both C++17 and C++20.
wxFileDialog shouldn't need these even on Windows which supports
forward slashes.
Passing this as a parameter to std::filesystem functions greatly reduces the
chance of an exception. The caller can check the error_code if needed.
This utilizes tt_string::last_file_write() for a much more efficient way to get
the modification time/date of the file.
When an image is being auto-added to an Images List, this now immediately
sets the embed parent to the image list. The rest of the changes are just
to make the code more understandable.
These aren't hooked up yet, but are available for the next PR to enhance
the UI and resolve some additional problems with SVG images.
@Randalphwa Randalphwa merged commit 9a28b50 into main Feb 23, 2024
@Randalphwa Randalphwa deleted the std_filesystem_path branch February 23, 2024 15:56
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant