Git commit f4e9e60069bae447098972e7a0dfdffb5c749dbc by Sebastian Kügler. Committed on 24/09/2026 at 15:33. Pushed by sebas into branch 'Seabass/0.8'.
GUI: every QString and std::string path crosses to std::filesystem through the UTF-8 helpers The controllers under src/gui turned QStrings into paths with fs::path(q.toStdString()) and paths back into QStrings with QString::fromStdString(p.string()), 102 times by the lint's count and a few dozen more where the conversion was implicit: fs::exists(s) on a std::string, a fs::path variable direct-initialised from toStdString(), a std::string returned where a fs::path was expected, std::ifstream opened by a std::string. On Windows each of those reads or writes the ANSI code page, so a stick with a Japanese artist folder or an emoji in a playlist name comes out as a path that does not exist. Every crossing now goes through pathFromQString / pathToQString (src/gui/qt_path.hpp) or pathFromUtf8 / pathToUtf8 / pathToGenericUtf8 (utf8_path.hpp), so a grep finds them all. The OneLibrary -wal sidecar is now spelled fs::path(oneLibrary) += "-wal" instead of re-parsing the string form. FormatWriteSession keeps its scratch subdirectory and file name as fs::path members, so the scratch file is built once and never through path / std::string. The checkpoint loop in SaveContext converts each member once and copies to a fs::path instead of round-tripping through the string it records. No behaviour change on Linux or macOS, where the old spellings were already UTF-8. The clang-query audit that found the implicit crossings is not part of the tree; the lint still only sees spellings. (cherry picked from commit e2e1b041adee5fcb3d2648c4780a0c54f005c0b0) M +3 -2 src/gui/anonymize_library_controller.cpp M +6 -5 src/gui/app_settings_controller.cpp M +4 -3 src/gui/artwork_rescue_sources.cpp M +6 -5 src/gui/backup_advisor_controller.cpp M +3 -2 src/gui/backup_changelog_text.cpp M +10 -9 src/gui/cleanup_controller.cpp M +5 -4 src/gui/clone_stick_controller.cpp M +2 -1 src/gui/duplicates_controller.cpp M +2 -1 src/gui/edit/changes/add_cue_change.cpp M +3 -2 src/gui/edit/changes/change_helpers.cpp M +7 -6 src/gui/edit/changes/cleanup_group_change.cpp M +3 -2 src/gui/edit/changes/device_setting_change.cpp M +2 -1 src/gui/edit/changes/repair_issue_change.cpp M +2 -1 src/gui/edit/changes/restore_backups_change.cpp M +5 -4 src/gui/edit/changes/restore_metadata_change.cpp M +2 -1 src/gui/edit/changes/sync_plan_change.cpp M +5 -4 src/gui/edit/edit_session_registry.cpp M +13 -12 src/gui/edit/format_write_session.cpp M +2 -2 src/gui/edit/format_write_session.hpp M +3 -2 src/gui/edit/library_edit_session.cpp M +34 -29 src/gui/edit/save_context.cpp M +2 -1 src/gui/engine_library_creator_controller.cpp M +10 -9 src/gui/full_backups_controller.cpp M +2 -1 src/gui/home_backups_controller.cpp M +7 -6 src/gui/library_catalog_cache.cpp M +6 -11 src/gui/library_consistency_controller.cpp M +12 -11 src/gui/media_controller.cpp M +3 -2 src/gui/metadata_backup_controller.cpp M +4 -3 src/gui/metadata_restore_controller.cpp M +8 -7 src/gui/restore_stick_backup_controller.cpp M +16 -15 src/gui/stick_backup_controller.cpp M +8 -7 src/gui/stick_catalogs.cpp M +5 -4 src/gui/stick_statistics_controller.cpp M +4 -3 src/gui/sync_controller.cpp https://invent.kde.org/multimedia/seabass/-/commit/f4e9e60069bae447098972e7a0dfdffb5c749dbc diff --git a/src/gui/anonymize_library_controller.cpp b/src/gui/anonymize_library_controller.cpp index 3bbac060..e1cc6672 100644 --- a/src/gui/anonymize_library_controller.cpp +++ b/src/gui/anonymize_library_controller.cpp @@ -13,6 +13,7 @@ #include <system_error> #include "application/use_cases/anonymize_library.hpp" +#include "gui/qt_path.hpp" namespace seabass::gui { @@ -144,7 +145,7 @@ void AnonymizeLibraryController::run(const QString &rekordboxPath, const QString // directory is the requested path with the suffix taken off -- which // keeps the zip exactly where the user pointed, rather than one // directory beside it. - std::filesystem::path requested(outPath.toStdString()); + std::filesystem::path requested = pathFromQString(outPath); if (requested.extension() == ".zip") { requested.replace_extension(); } @@ -155,7 +156,7 @@ void AnonymizeLibraryController::run(const QString &rekordboxPath, const QString if (requested.has_parent_path()) { std::filesystem::create_directories(requested.parent_path(), dirEc); } - const QString outDir = QString::fromStdString(requested.string()); + const QString outDir = pathToQString(requested); setErrorMessage({}); m_summaryText.clear(); m_manifestText.clear(); diff --git a/src/gui/app_settings_controller.cpp b/src/gui/app_settings_controller.cpp index 63771eda..63bad63f 100644 --- a/src/gui/app_settings_controller.cpp +++ b/src/gui/app_settings_controller.cpp @@ -10,6 +10,7 @@ #include "gui/seabass_settings.hpp" #include "infrastructure/paths/seabass_paths.hpp" #include "app_settings_controller.hpp" +#include "gui/qt_path.hpp" #include <QDir> #include <QStandardPaths> @@ -19,7 +20,7 @@ namespace seabass::gui QString AppSettingsController::defaultStickBackupDirectory() { - return QString::fromStdString(infrastructure::paths::localFullBackupsDir().string()); + return pathToQString(infrastructure::paths::localFullBackupsDir()); } AppSettingsController::AppSettingsController(QObject *parent) @@ -50,7 +51,7 @@ AppSettingsController::AppSettingsController(QObject *parent) if (m_seabassHomeDirectory.isEmpty()) { m_seabassHomeDirectory = defaultSeabassHomeDirectory(); } - infrastructure::paths::setLocalRootOverride(m_seabassHomeDirectory.toStdString()); + infrastructure::paths::setLocalRootOverride(pathFromQString(m_seabassHomeDirectory)); m_lastPlaylistName = m_settings.value("lastPlaylistName", "").toString(); #ifdef SEABASS_EXPERIMENTAL_BUILD m_experimentalFeaturesEnabled = m_settings.value("experimentalFeaturesEnabled", false).toBool(); @@ -196,12 +197,12 @@ QString AppSettingsController::defaultSeabassHomeDirectory() // Asked of the paths module rather than rebuilt here, so the app and // everything Qt-free agree on one answer. infrastructure::paths::setLocalRootOverride({}); - return QString::fromStdString(infrastructure::paths::localRoot().string()); + return pathToQString(infrastructure::paths::localRoot()); } QString AppSettingsController::anonymizedExportDirectory() const { - return QString::fromStdString((std::filesystem::path(m_seabassHomeDirectory.toStdString()) / "testdata").string()); + return pathToQString(pathFromQString(m_seabassHomeDirectory) / "testdata"); } void AppSettingsController::setSeabassHomeDirectory(const QString &value) @@ -217,7 +218,7 @@ void AppSettingsController::setSeabassHomeDirectory(const QString &value) // localRoot(), so a setting that only took effect after a restart // would leave the two halves of the app disagreeing about where the // user's data lives. - infrastructure::paths::setLocalRootOverride(effective.toStdString()); + infrastructure::paths::setLocalRootOverride(pathFromQString(effective)); emit seabassHomeDirectoryChanged(); } diff --git a/src/gui/artwork_rescue_sources.cpp b/src/gui/artwork_rescue_sources.cpp index 087e04fc..2adcc418 100644 --- a/src/gui/artwork_rescue_sources.cpp +++ b/src/gui/artwork_rescue_sources.cpp @@ -8,6 +8,7 @@ #ifdef SEABASS_HAVE_TAGLIB #include "infrastructure/audio/embedded_artwork.hpp" +#include "infrastructure/paths/utf8_path.hpp" #endif #include <algorithm> @@ -25,7 +26,7 @@ std::vector<fs::path> stickBackupArchives(const std::string &backupDirectory) return archives; } std::error_code ec; - for (const fs::directory_entry &entry : fs::directory_iterator(backupDirectory, ec)) { + for (const fs::directory_entry &entry : fs::directory_iterator(pathFromUtf8(backupDirectory), ec)) { if (!entry.is_regular_file(ec)) { continue; } @@ -52,8 +53,8 @@ ArtworkRescueSources::ArtworkRescueSources(const std::string &backupDirectory, c : m_impl(std::make_shared<Impl>(stickBackupArchives(backupDirectory))) { std::error_code ec; - const fs::path resolved = fs::weakly_canonical(fs::path(stickRoot), ec); - m_stickRoot = (ec ? fs::path(stickRoot) : resolved).string(); + const fs::path resolved = fs::weakly_canonical(pathFromUtf8(stickRoot), ec); + m_stickRoot = pathToUtf8(ec ? pathFromUtf8(stickRoot) : resolved); } std::string ArtworkRescueSources::archivePathFor(const std::string &trackFile) const diff --git a/src/gui/backup_advisor_controller.cpp b/src/gui/backup_advisor_controller.cpp index 047ff7d1..ca420eea 100644 --- a/src/gui/backup_advisor_controller.cpp +++ b/src/gui/backup_advisor_controller.cpp @@ -18,6 +18,7 @@ #include "infrastructure/stick_backup/sqlite_db_set.hpp" #include "infrastructure/stick_backup/stick_tree_walker.hpp" #include "infrastructure/system/stick_hardware_info.hpp" +#include "gui/qt_path.hpp" namespace seabass::gui { @@ -107,7 +108,7 @@ void BackupAdvisorController::startNext() } const Request request = m_queue.front(); m_queue.erase(m_queue.begin()); - const fs::path directory(m_backupDirectory.toStdString()); + const fs::path directory = pathFromQString(m_backupDirectory); emit busyChanged(); m_watcher.setFuture(QtConcurrent::run([request, directory]() { namespace stick_backup = infrastructure::stick_backup; @@ -122,7 +123,7 @@ void BackupAdvisorController::startNext() facts.stickIdentifier = hardware.stickIdentifier; facts.freeBytes = hardware.freeBytes; facts.usedBytes = hardware.totalBytes > hardware.freeBytes ? hardware.totalBytes - hardware.freeBytes : 0; - const fs::path root(request.mountPoint.toStdString()); + const fs::path root = pathFromQString(request.mountPoint); if (facts.hasLibrary) { facts.fingerprint = readLibraryFingerprint(request.rekordboxPath, request.enginePath); facts.catalogModifiedAtUnix = stick_backup::libraryCatalogModifiedAt(root); @@ -174,7 +175,7 @@ QVariantMap BackupAdvisorController::sourceToVariant(const StickBackupAdvice::So map["kind"] = QString::fromUtf8(std::string(application::toString(source.kind)).c_str()); map["label"] = QString::fromStdString(source.label); map["mountPoint"] = QString::fromStdString(source.mountPoint); - map["backupPath"] = QString::fromStdString(source.backupPath.string()); + map["backupPath"] = pathToQString(source.backupPath); map["modifiedAt"] = isoTime(source.modifiedAtUnix); map["enoughSpace"] = source.enoughSpace; map["detail"] = QString::fromStdString(source.detail); @@ -217,7 +218,7 @@ void BackupAdvisorController::recomputeAdvice() // and BackupStick would rewrite that archive from the cache. // BackupStick refuses too; this keeps the offer from ever // appearing on an empty stick's card. - if (infrastructure::local::isBrowsedBackupRoot(std::filesystem::path(other.key().toStdString()))) { + if (infrastructure::local::isBrowsedBackupRoot(pathFromQString(other.key()))) { continue; } StickBackupAdviceInput::PeerStick peer; @@ -235,7 +236,7 @@ void BackupAdvisorController::recomputeAdvice() QVariantMap map; map["state"] = QString::fromUtf8(std::string(application::toString(result.state)).c_str()); map["matchedBy"] = QString::fromUtf8(std::string(application::toString(result.matchedBy)).c_str()); - map["backupPath"] = QString::fromStdString(result.backupPath.string()); + map["backupPath"] = pathToQString(result.backupPath); map["backupLabel"] = QString::fromStdString(result.backupLabel); map["backupCreatedAt"] = isoTime(result.backupCreatedAtUnix); map["trackOverlap"] = result.trackOverlap; diff --git a/src/gui/backup_changelog_text.cpp b/src/gui/backup_changelog_text.cpp index b295b017..1410df4d 100644 --- a/src/gui/backup_changelog_text.cpp +++ b/src/gui/backup_changelog_text.cpp @@ -11,6 +11,7 @@ #include <QStandardPaths> #include <QTextStream> +#include "gui/qt_path.hpp" #include "infrastructure/stick_backup/backup_manifest.hpp" #include "infrastructure/stick_backup/posix_archive_file.hpp" #include "infrastructure/stick_backup/zip64_reader.hpp" @@ -94,7 +95,7 @@ QString writeChangelogFile(const fs::path &archivePath, QString *error) if (directory.isEmpty()) { return fail(QStringLiteral("Nowhere to write the file to.")); } - const QString name = QFileInfo(QString::fromStdString(archivePath.filename().string())).completeBaseName(); + const QString name = QFileInfo(pathToQString(archivePath.filename())).completeBaseName(); const QString path = QDir(directory).filePath(name + QStringLiteral("-history.txt")); QFile out(path); @@ -105,7 +106,7 @@ QString writeChangelogFile(const fs::path &archivePath, QString *error) text << "Backup history\n"; text << "==============\n\n"; - text << "Archive: " << QString::fromStdString(archivePath.string()) << "\n"; + text << "Archive: " << pathToQString(archivePath) << "\n"; text << "Stick: " << QString::fromStdString(manifest->stickLabel) << "\n"; if (!manifest->userName.empty()) { text << "Name: " << QString::fromStdString(manifest->userName) << "\n"; diff --git a/src/gui/cleanup_controller.cpp b/src/gui/cleanup_controller.cpp index cf84c4c7..8120883a 100644 --- a/src/gui/cleanup_controller.cpp +++ b/src/gui/cleanup_controller.cpp @@ -54,6 +54,7 @@ #include "infrastructure/rekordbox/rekordbox_cleanup_writer.hpp" #include "infrastructure/rekordbox/rekordbox_cue_writer.hpp" #include "gui/edit/changes/cleanup_group_change.hpp" +#include "gui/qt_path.hpp" namespace seabass::gui { @@ -510,12 +511,12 @@ PendingDeletionApplyResult runDeletePendingTask(QString format, QString path, return result; } try { - fs::path stickRoot = fs::path(path.toStdString()).parent_path(); + fs::path stickRoot = pathFromQString(path).parent_path(); infrastructure::backup::StickWriteLock lock( (infrastructure::paths::stickBackupsDir(stickRoot) / ".write.lock")); infrastructure::cleanup::PendingDeletionManifest manifest( - infrastructure::paths::stickPendingDeletions(stickRoot).string()); - infrastructure::logging::FileOperationLog log(infrastructure::paths::stickOperationLog(stickRoot).string()); + pathToUtf8(infrastructure::paths::stickPendingDeletions(stickRoot))); + infrastructure::logging::FileOperationLog log(pathToUtf8(infrastructure::paths::stickOperationLog(stickRoot))); // Every catalog on the stick, not just the one this page is // working in. The same audio file routinely lives in rekordbox, @@ -667,7 +668,7 @@ CleanupTaskResult runRescanTask(QString format, QString path, QString playlistNa } auto strays = infrastructure::cleanup::scanStrayFiles( - fs::path(path.toStdString()).parent_path().string(), stickCatalogs.catalogs, stickCatalogs.failed, cancel); + pathToUtf8(pathFromQString(path).parent_path()), stickCatalogs.catalogs, stickCatalogs.failed, cancel); result.strays.filesFound = static_cast<int>(strays.filesFound); result.strays.bytesFound = static_cast<qulonglong>(strays.bytesFound); @@ -717,7 +718,7 @@ CleanupTaskResult runRescanTask(QString format, QString path, QString playlistNa // as it always did. The cache lives on the stick, so a second // scan of the same stick decodes nothing. auto audioProbe = infrastructure::audio::makeAudioContentProbe( - fs::path(path.toStdString()).parent_path().string()); + pathToUtf8(pathFromQString(path).parent_path())); result.audioComparisonUnavailable = audioProbe == nullptr && domain::MatchingPolicy::compareAudioSeconds() > domain::MatchingPolicy::exactMatchSeconds(); // Decoding is the slowest thing in the scan, so Cancel has to @@ -877,7 +878,7 @@ std::pair<qlonglong, qlonglong> stickSpace(const QString &libraryPath) return {0, 0}; } std::error_code ec; - const auto info = fs::space(fs::path(libraryPath.toStdString()), ec); + const auto info = fs::space(pathFromQString(libraryPath), ec); if (ec || info.capacity == 0 || info.capacity == static_cast<std::uintmax_t>(-1)) { return {0, 0}; } @@ -1291,9 +1292,9 @@ void CleanupController::refreshPendingDeletions() if (m_path.isEmpty()) { return; } - fs::path stickRoot = fs::path(m_path.toStdString()).parent_path(); + fs::path stickRoot = pathFromQString(m_path).parent_path(); infrastructure::cleanup::PendingDeletionManifest manifest( - infrastructure::paths::stickPendingDeletions(stickRoot).string()); + pathToUtf8(infrastructure::paths::stickPendingDeletions(stickRoot))); // rekordbox and Engine each accumulate their own separate pending // entries (see PendingDeletion::format). This page only ever shows @@ -1311,7 +1312,7 @@ void CleanupController::refreshPendingDeletions() // (deleteSelectedPendingFiles() clears an already-absent entry // from the manifest instead of erroring). std::error_code ec; - entry.fileSizeBytes = fs::file_size(entry.filePath, ec); + entry.fileSizeBytes = fs::file_size(pathFromUtf8(entry.filePath), ec); if (ec) { entry.fileSizeBytes = 0; } diff --git a/src/gui/clone_stick_controller.cpp b/src/gui/clone_stick_controller.cpp index c05409bb..90e5c0f4 100644 --- a/src/gui/clone_stick_controller.cpp +++ b/src/gui/clone_stick_controller.cpp @@ -20,6 +20,7 @@ #include "infrastructure/engine/engine_restore_check.hpp" #include "infrastructure/system/rekordbox_process_detector.hpp" #include "infrastructure/system/stick_hardware_info.hpp" +#include "gui/qt_path.hpp" namespace seabass::gui { @@ -123,7 +124,7 @@ void CloneStickController::configure(const QString &sourceLabel, const QString & m_sourceLabel = sourceLabel; m_sourceRekordboxPath = sourceRekordboxPath; m_sourceEnginePath = sourceEnginePath; - m_sourceRoot = anyPath.isEmpty() ? QString() : QString::fromStdString(fs::path(anyPath.toStdString()).parent_path().string()); + m_sourceRoot = anyPath.isEmpty() ? QString() : pathToQString(pathFromQString(anyPath).parent_path()); m_targetLabel = targetLabel; m_targetRoot = targetMountPoint; m_archivePath = archivePathForLabel(backupDirectory, sourceLabel); @@ -134,10 +135,10 @@ void CloneStickController::configure(const QString &sourceLabel, const QString & CloneStickOptions CloneStickController::baseOptions() const { CloneStickOptions options; - options.backup.stickRoot = fs::path(m_sourceRoot.toStdString()); - options.backup.archivePath = fs::path(m_archivePath.toStdString()); + options.backup.stickRoot = pathFromQString(m_sourceRoot); + options.backup.archivePath = pathFromQString(m_archivePath); options.backup.stickLabel = m_sourceLabel.toStdString(); - options.targetRoot = fs::path(m_targetRoot.toStdString()); + options.targetRoot = pathFromQString(m_targetRoot); return options; } diff --git a/src/gui/duplicates_controller.cpp b/src/gui/duplicates_controller.cpp index c894af04..17c69e26 100644 --- a/src/gui/duplicates_controller.cpp +++ b/src/gui/duplicates_controller.cpp @@ -31,6 +31,7 @@ #include "infrastructure/rekordbox/pdb_lookup.hpp" #include "infrastructure/rekordbox/rekordbox_cue_writer.hpp" #include "gui/edit/changes/copy_cues_change.hpp" +#include "gui/qt_path.hpp" namespace seabass::gui { @@ -241,7 +242,7 @@ DuplicatesTaskResult runRescanTask(QString format, QString path, std::shared_ptr // for comparing audio or this build has no decoder, which is the // behaviour this page has always had. auto audioProbe = infrastructure::audio::makeAudioContentProbe( - std::filesystem::path(path.toStdString()).parent_path().string()); + pathToUtf8(pathFromQString(path).parent_path())); result.audioComparisonUnavailable = audioProbe == nullptr && domain::MatchingPolicy::compareAudioSeconds() > domain::MatchingPolicy::exactMatchSeconds(); // Cancel has to reach the decoding, which is the slowest thing diff --git a/src/gui/edit/changes/add_cue_change.cpp b/src/gui/edit/changes/add_cue_change.cpp index 5c7ca961..a16a61be 100644 --- a/src/gui/edit/changes/add_cue_change.cpp +++ b/src/gui/edit/changes/add_cue_change.cpp @@ -16,6 +16,7 @@ #include "gui/library_catalog_cache.hpp" #include "infrastructure/engine/libdjinterop_engine_cue_writer.hpp" #include "infrastructure/onelibrary/onelibrary_cue_writer.hpp" +#include "infrastructure/paths/utf8_path.hpp" #include "infrastructure/rekordbox/pdb_lookup.hpp" #include "infrastructure/rekordbox/rekordbox_cue_writer.hpp" @@ -196,7 +197,7 @@ ChangeOutcome AddCueChange::apply(SaveContext &ctx) // open plus schema detection, and a save adding several cues to // the same library should pay that once. writer = &sharedEngineCueWriter(ctx, pioneerRoot); - ctx.backupOnce((fs::path(pioneerRoot) / "Database2" / "m.db").string(), "add-cue"); + ctx.backupOnce(pathToUtf8(pathFromUtf8(pioneerRoot) / "Database2" / "m.db"), "add-cue"); } writer->writeHotCues(id, cues); diff --git a/src/gui/edit/changes/change_helpers.cpp b/src/gui/edit/changes/change_helpers.cpp index 38f41dab..3c7b7f71 100644 --- a/src/gui/edit/changes/change_helpers.cpp +++ b/src/gui/edit/changes/change_helpers.cpp @@ -13,6 +13,7 @@ #include "application/path_key.hpp" #include "gui/edit/save_context.hpp" +#include "infrastructure/paths/utf8_path.hpp" #include "infrastructure/rekordbox/pdb_lookup.hpp" #include "infrastructure/rekordbox/rekordbox_cue_writer.hpp" @@ -72,7 +73,7 @@ std::vector<std::string> filesWrittenFor(WriteScope scope, const domain::TrackId } } if (scope.catalogRows) { - files.push_back((fs::path(rootPath) / "rekordbox" / "export.pdb").string()); + files.push_back(pathToUtf8(pathFromUtf8(rootPath) / "rekordbox" / "export.pdb")); } // Only when this workflow actually mirrors there. Presence of the // database is not the test -- Sync leaves it alone even when it @@ -83,7 +84,7 @@ std::vector<std::string> filesWrittenFor(WriteScope scope, const domain::TrackId } else if (format == "engine") { // One shared database, whatever the track: the same file every // time, deduplicated by the caller. - files.push_back((fs::path(rootPath) / "Database2" / "m.db").string()); + files.push_back(pathToUtf8(pathFromUtf8(rootPath) / "Database2" / "m.db")); } else { files.push_back(infrastructure::onelibrary::OneLibraryCueWriter::dbPathFor(rootPath)); } diff --git a/src/gui/edit/changes/cleanup_group_change.cpp b/src/gui/edit/changes/cleanup_group_change.cpp index 6dbb25bd..a0d5eb6e 100644 --- a/src/gui/edit/changes/cleanup_group_change.cpp +++ b/src/gui/edit/changes/cleanup_group_change.cpp @@ -30,6 +30,7 @@ #include "infrastructure/rekordbox/pdb_row_writer.hpp" #include "infrastructure/rekordbox/rekordbox_cleanup_writer.hpp" #include "infrastructure/rekordbox/rekordbox_cue_writer.hpp" +#include "gui/qt_path.hpp" namespace seabass::gui { @@ -80,7 +81,7 @@ CleanupFormatContext makeContext(const QString &format, const QString &path, Sav std::string effectivePath = writeRoot.value_or(engineLibraryPath); ctx.cueWriter = std::make_unique<infrastructure::engine::LibdjinteropEngineCueWriter>(effectivePath); ctx.cleanupWriter = std::make_unique<infrastructure::engine::LibdjinteropEngineCleanupWriter>(effectivePath); - std::string engineDbFile = (fs::path(engineLibraryPath) / "Database2" / "m.db").string(); + std::string engineDbFile = pathToUtf8(pathFromUtf8(engineLibraryPath) / "Database2" / "m.db"); } else { // onelibrary. `path` here is the PIONEER root, same as the // rekordbox branch -- OneLibrary lives alongside export.pdb. @@ -92,7 +93,7 @@ CleanupFormatContext makeContext(const QString &format, const QString &path, Sav // right now. std::string pioneerRoot = path.toStdString(); std::string effectivePath = writeRoot.value_or(pioneerRoot); - std::string realStickRoot = fs::path(pioneerRoot).parent_path().string(); + std::string realStickRoot = pathToUtf8(pathFromUtf8(pioneerRoot).parent_path()); auto adapter = std::make_unique<OneLibraryCueWriterAdapter>(effectivePath, oneLibrarySourceIdToPath, realStickRoot); // Through the save's one writer for this database, like @@ -128,7 +129,7 @@ struct CleanupWriterContext const std::unordered_map<std::string, std::string> &oneLibrarySourceIdToPath) : session(sharedFormatWriteSession(ctx, format.toStdString(), path.toStdString(), itemCountHint, "duplicate-file-cleanup")), - manifest(infrastructure::paths::stickPendingDeletions(fs::path(path.toStdString()).parent_path()).string()) + manifest(pathToUtf8(infrastructure::paths::stickPendingDeletions(pathFromQString(path).parent_path()))) { std::optional<std::string> writeRoot; if (session.usesScratch()) { @@ -136,7 +137,7 @@ struct CleanupWriterContext } context = makeContext(format, path, ctx, oneLibrarySourceIdToPath, writeRoot); effectiveRoot = session.writeRoot(); - realStickRootForOneLib = fs::path(path.toStdString()).parent_path().string(); + realStickRootForOneLib = pathToUtf8(pathFromQString(path).parent_path()); // Named in every pending-deletion entry, so the review page can // point at the backup that still holds the removed row. dbBackupId = ctx.backupIdOf(session.databaseFile()); @@ -405,11 +406,11 @@ ChangeOutcome CleanupGroupChange::apply(SaveContext &ctx) // The manifest is appended to, never backed up; a failed change's lines // come out again with the rest of it. ctx.protectForThisChange( - infrastructure::paths::stickPendingDeletions(fs::path(m_path.toStdString()).parent_path()).string()); + pathToUtf8(infrastructure::paths::stickPendingDeletions(pathFromQString(m_path).parent_path()))); if (!writesToCatalog(plan)) { infrastructure::cleanup::PendingDeletionManifest manifest( - infrastructure::paths::stickPendingDeletions(fs::path(m_path.toStdString()).parent_path()).string()); + pathToUtf8(infrastructure::paths::stickPendingDeletions(pathFromQString(m_path).parent_path()))); recordStrayFilesForDeletion(manifest, plan, m_format.toStdString(), ctx.log()); return ChangeOutcome::success(); } diff --git a/src/gui/edit/changes/device_setting_change.cpp b/src/gui/edit/changes/device_setting_change.cpp index 31de3b99..fb6eb07b 100644 --- a/src/gui/edit/changes/device_setting_change.cpp +++ b/src/gui/edit/changes/device_setting_change.cpp @@ -7,6 +7,7 @@ #include <filesystem> #include "gui/edit/save_context.hpp" +#include "infrastructure/paths/utf8_path.hpp" #include "infrastructure/rekordbox/rekordbox_settings_writer.hpp" namespace seabass::gui @@ -56,7 +57,7 @@ std::vector<BackupTarget> DeviceSettingChange::filesToBackup(SaveContext &ctx) c { (void)ctx; const std::string filePath = m_pioneerRoot.toStdString() + "/" + m_fileName.toStdString(); - if (!fs::exists(filePath)) { + if (!fs::exists(pathFromUtf8(filePath))) { return {}; // apply() reports the missing file; do not record one that is not there } return {{filePath, "device-settings"}}; @@ -65,7 +66,7 @@ std::vector<BackupTarget> DeviceSettingChange::filesToBackup(SaveContext &ctx) c ChangeOutcome DeviceSettingChange::apply(SaveContext &ctx) { std::string filePath = m_pioneerRoot.toStdString() + "/" + m_fileName.toStdString(); - if (!fs::exists(filePath)) { + if (!fs::exists(pathFromUtf8(filePath))) { return ChangeOutcome::failure("Settings file not found: " + m_fileName); } ctx.backupOnce(filePath, "device-settings"); diff --git a/src/gui/edit/changes/repair_issue_change.cpp b/src/gui/edit/changes/repair_issue_change.cpp index 1280b7a4..9678f3d3 100644 --- a/src/gui/edit/changes/repair_issue_change.cpp +++ b/src/gui/edit/changes/repair_issue_change.cpp @@ -14,6 +14,7 @@ #include "infrastructure/engine/libdjinterop_engine_cleanup_writer.hpp" #include "infrastructure/engine/libdjinterop_engine_cue_writer.hpp" #include "infrastructure/onelibrary/onelibrary_cue_writer.hpp" +#include "infrastructure/paths/utf8_path.hpp" #include "infrastructure/rekordbox/pdb_lookup.hpp" #include "infrastructure/rekordbox/rekordbox_cleanup_writer.hpp" #include "infrastructure/rekordbox/rekordbox_cue_writer.hpp" @@ -53,7 +54,7 @@ struct RepairWriterContext // change in SyncPlanChange for why a private instance is a // way to abort a save on a stick with both catalogs. oneLibrary = &sharedOneLibraryWriter(ctx, session.writeRoot(), - fs::path(root).parent_path().string()); + pathToUtf8(pathFromUtf8(root).parent_path())); } } diff --git a/src/gui/edit/changes/restore_backups_change.cpp b/src/gui/edit/changes/restore_backups_change.cpp index cdfc151e..7af5e7a3 100644 --- a/src/gui/edit/changes/restore_backups_change.cpp +++ b/src/gui/edit/changes/restore_backups_change.cpp @@ -16,6 +16,7 @@ #include "gui/edit/save_context.hpp" #include "infrastructure/backup/filesystem_backup_store.hpp" +#include "infrastructure/paths/utf8_path.hpp" namespace seabass::gui { @@ -94,7 +95,7 @@ ChangeOutcome RestoreBackupsChange::apply(SaveContext &ctx) ids.insert(backup.id.toStdString()); } const std::string stickRoot = infrastructure::paths::stickRootForCatalogPath(catalogPath.toStdString()); - const std::string pendingPath = infrastructure::paths::stickPendingDeletions(stickRoot).string(); + const std::string pendingPath = pathToUtf8(infrastructure::paths::stickPendingDeletions(stickRoot)); // Rewritten inside this change, so a rollback of it puts the list // back along with the catalogs. ctx.protectForThisChange(pendingPath); diff --git a/src/gui/edit/changes/restore_metadata_change.cpp b/src/gui/edit/changes/restore_metadata_change.cpp index 526e061a..3b5e9fda 100644 --- a/src/gui/edit/changes/restore_metadata_change.cpp +++ b/src/gui/edit/changes/restore_metadata_change.cpp @@ -15,6 +15,7 @@ #include "gui/onelibrary_cue_writer_adapter.hpp" #include "infrastructure/engine/libdjinterop_engine_cue_writer.hpp" #include "infrastructure/onelibrary/onelibrary_cue_writer.hpp" +#include "infrastructure/paths/utf8_path.hpp" #include "infrastructure/rekordbox/pdb_lookup.hpp" #include "infrastructure/rekordbox/pdb_row_writer.hpp" #include "infrastructure/rekordbox/rekordbox_cue_writer.hpp" @@ -100,7 +101,7 @@ struct RestoreWriterContext // format, whichever way round the sharing argument // goes. See docs/metadata-backup-plan.md. mirror = &sharedOneLibraryWriter(ctx, realRoot, - fs::path(realRoot).parent_path().string()); + pathToUtf8(pathFromUtf8(realRoot).parent_path())); } } } else if (format == "engine") { @@ -119,9 +120,9 @@ struct RestoreWriterContext // features cannot open two instances against one file. auto adapter = std::make_unique<OneLibraryCueWriterAdapter>( realRoot, std::unordered_map<std::string, std::string>{}, - fs::path(realRoot).parent_path().string()); + pathToUtf8(pathFromUtf8(realRoot).parent_path())); adapter->useSharedWriter( - sharedOneLibraryWriter(ctx, realRoot, fs::path(realRoot).parent_path().string())); + sharedOneLibraryWriter(ctx, realRoot, pathToUtf8(pathFromUtf8(realRoot).parent_path()))); writer = std::move(adapter); } } @@ -211,7 +212,7 @@ AnnotationOutcome applyAnnotation(SaveContext &ctx, RestoreWriterContext &writer // has this database redirected to a scratch copy, that copy // is the one that will be committed back. const std::string pdbPath = - (fs::path(writer.session.writeRoot()) / "rekordbox" / "export.pdb").string(); + pathToUtf8(pathFromUtf8(writer.session.writeRoot()) / "rekordbox" / "export.pdb"); infrastructure::rekordbox::PdbRowWriter rows(pdbPath); if (!rows.setTrackRating(static_cast<uint32_t>(std::stoul(sourceId)), *stars)) { // The row this proposal was built from is not in the diff --git a/src/gui/edit/changes/sync_plan_change.cpp b/src/gui/edit/changes/sync_plan_change.cpp index 00047314..2f4b7cb3 100644 --- a/src/gui/edit/changes/sync_plan_change.cpp +++ b/src/gui/edit/changes/sync_plan_change.cpp @@ -13,6 +13,7 @@ #include "gui/edit/save_context.hpp" #include "infrastructure/engine/libdjinterop_engine_cue_writer.hpp" #include "infrastructure/onelibrary/onelibrary_cue_writer.hpp" +#include "infrastructure/paths/utf8_path.hpp" #include "infrastructure/rekordbox/pdb_lookup.hpp" #include "infrastructure/rekordbox/rekordbox_cue_writer.hpp" @@ -62,7 +63,7 @@ struct SyncFormatWriter // writeRoot() may be a scratch copy whose parent is a temp // directory, and content.path lookups need the real stick. oneLibrary = &sharedOneLibraryWriter(ctx, session.writeRoot(), - fs::path(catalogPath).parent_path().string()); + pathToUtf8(pathFromUtf8(catalogPath).parent_path())); } } diff --git a/src/gui/edit/edit_session_registry.cpp b/src/gui/edit/edit_session_registry.cpp index 02372fa7..7b4a907c 100644 --- a/src/gui/edit/edit_session_registry.cpp +++ b/src/gui/edit/edit_session_registry.cpp @@ -10,6 +10,7 @@ #include <filesystem> #include "gui/media_controller.hpp" +#include "gui/qt_path.hpp" #include "infrastructure/local/file_library_edit_lock_store.hpp" #include "infrastructure/system/process_liveness.hpp" #include "infrastructure/system/stick_hardware_info.hpp" @@ -250,12 +251,12 @@ QString EditSessionRegistry::mountPointForPath(const QString &anyLibraryPath) co if (anyLibraryPath.isEmpty()) { return {}; } - fs::path p(anyLibraryPath.toStdString()); - std::string name = p.filename().string(); + fs::path p = pathFromQString(anyLibraryPath); + std::string name = pathToUtf8(p.filename()); // A catalog folder ("PIONEER", "Engine Library") sits directly under // the stick root; anything else is taken to be the root itself. if (name == "PIONEER" || name == "Engine Library") { - return QString::fromStdString(p.parent_path().string()); + return pathToQString(p.parent_path()); } return anyLibraryPath; } @@ -274,7 +275,7 @@ QString EditSessionRegistry::libraryIdForPath(const QString &anyLibraryPath) } // No media controller (tests) or a mount point it never saw: the same // filesystem-UUID-else-label+size rule, read straight from the mount. - std::string label = fs::path(mountPoint.toStdString()).filename().string(); + std::string label = pathToUtf8(pathFromQString(mountPoint).filename()); auto info = infrastructure::system::readStickHardwareInfo(mountPoint.toStdString(), label); return QString::fromStdString(info.stickIdentifier); } diff --git a/src/gui/edit/format_write_session.cpp b/src/gui/edit/format_write_session.cpp index 105abc33..5a5d1fbe 100644 --- a/src/gui/edit/format_write_session.cpp +++ b/src/gui/edit/format_write_session.cpp @@ -11,6 +11,7 @@ #include "infrastructure/bulk_write_strategy.hpp" #include "infrastructure/durable_file_write.hpp" #include "infrastructure/onelibrary/onelibrary_cue_writer.hpp" +#include "infrastructure/paths/utf8_path.hpp" namespace seabass::gui { @@ -20,12 +21,12 @@ namespace fs = std::filesystem; std::string FormatWriteSession::databaseFileFor(const std::string &format, const std::string &catalogPath) { if (format == "engine") { - return (fs::path(catalogPath) / "Database2" / "m.db").generic_string(); + return pathToGenericUtf8(pathFromUtf8(catalogPath) / "Database2" / "m.db"); } if (format == "onelibrary") { return infrastructure::onelibrary::OneLibraryCueWriter::dbPathFor(catalogPath); } - return (fs::path(catalogPath) / "rekordbox" / "export.pdb").generic_string(); + return pathToGenericUtf8(pathFromUtf8(catalogPath) / "rekordbox" / "export.pdb"); } FormatWriteSession::FormatWriteSession(std::string format, std::string catalogPath, int itemCountHint, @@ -53,12 +54,12 @@ FormatWriteSession::FormatWriteSession(std::string format, std::string catalogPa m_ctx.backupOnce(m_dbFile, m_label); std::error_code sizeEc; - m_existingBytes = fs::file_size(m_dbFile, sizeEc); + m_existingBytes = fs::file_size(pathFromUtf8(m_dbFile), sizeEc); infrastructure::BulkWriteStrategyInputs inputs; inputs.itemCount = itemCountHint; inputs.existingFileBytes = sizeEc ? 0 : m_existingBytes; bool useWholeFile = !sizeEc && infrastructure::shouldUseWholeFileReplace(inputs) - && infrastructure::hasRoomForWholeFileReplace(fs::path(m_dbFile).parent_path(), m_existingBytes); + && infrastructure::hasRoomForWholeFileReplace(pathFromUtf8(m_dbFile).parent_path(), m_existingBytes); if (useWholeFile) { fs::path scratchDir = fs::temp_directory_path() @@ -66,17 +67,17 @@ FormatWriteSession::FormatWriteSession(std::string format, std::string catalogPa + std::to_string(std::chrono::steady_clock::now().time_since_epoch().count())); std::error_code cleanupEc; fs::remove_all(scratchDir, cleanupEc); - fs::create_directories(scratchDir / m_scratchSubdir); - fs::copy_file(m_dbFile, scratchDir / m_scratchSubdir / m_scratchFilename); + const fs::path scratchFile = scratchDir / m_scratchSubdir / m_scratchFilename; + fs::create_directories(scratchFile.parent_path()); + fs::copy_file(pathFromUtf8(m_dbFile), scratchFile); m_scratch.emplace(scratchDir); - m_writeRoot = scratchDir.string(); + m_writeRoot = pathToUtf8(scratchDir); // From here on this save writes the scratch copy, so that is what a // failed change has to put back -- starting with this change. - const std::string scratchFile = (scratchDir / m_scratchSubdir / m_scratchFilename).string(); - m_ctx.redirectWrites(m_dbFile, scratchFile); - m_ctx.protectForThisChange(scratchFile); + m_ctx.redirectWrites(m_dbFile, pathToUtf8(scratchFile)); + m_ctx.protectForThisChange(pathToUtf8(scratchFile)); m_ctx.log().record(m_label + ": applying up to " + std::to_string(itemCountHint) + " " + m_format - + " update(s) to a local scratch copy first (" + m_scratchFilename + " is " + + " update(s) to a local scratch copy first (" + pathToUtf8(m_scratchFilename) + " is " + std::to_string(m_existingBytes) + " bytes)"); } @@ -101,7 +102,7 @@ void FormatWriteSession::commit(bool ok) return; } fs::path scratchFile = m_scratch->path / m_scratchSubdir / m_scratchFilename; - if (!infrastructure::copyFileDurablyAtomic(scratchFile.string(), m_dbFile)) { + if (!infrastructure::copyFileDurablyAtomic(pathToUtf8(scratchFile), m_dbFile)) { m_ctx.log().record(m_label + ": FAILED to commit the " + m_format + " scratch copy back onto the stick"); throw std::runtime_error(m_label + ": failed to commit the scratch-built " + m_format + " database back onto the stick"); diff --git a/src/gui/edit/format_write_session.hpp b/src/gui/edit/format_write_session.hpp index 6c48a562..c164ec90 100644 --- a/src/gui/edit/format_write_session.hpp +++ b/src/gui/edit/format_write_session.hpp @@ -61,8 +61,8 @@ private: std::string m_format; std::string m_catalogPath; std::string m_dbFile; - std::string m_scratchSubdir; - std::string m_scratchFilename; + std::filesystem::path m_scratchSubdir; + std::filesystem::path m_scratchFilename; std::string m_writeRoot; std::string m_label; std::uintmax_t m_existingBytes = 0; diff --git a/src/gui/edit/library_edit_session.cpp b/src/gui/edit/library_edit_session.cpp index efc8692c..6ce9f49f 100644 --- a/src/gui/edit/library_edit_session.cpp +++ b/src/gui/edit/library_edit_session.cpp @@ -22,6 +22,7 @@ #include "gui/qt_progress_reporter.hpp" #include "gui/write_guard.hpp" #include "infrastructure/backup/filesystem_backup_store.hpp" +#include "infrastructure/paths/utf8_path.hpp" #include "infrastructure/backup/stick_locks.hpp" #include "infrastructure/stick_layout.hpp" @@ -148,7 +149,7 @@ void LibraryEditSession::setLibraryPaths(const QString &rekordboxPath, const QSt const QString &any = m_rekordboxPath.isEmpty() ? m_enginePath : m_rekordboxPath; if (!any.isEmpty()) { const std::filesystem::path root = - infrastructure::backup::stickRootForCatalogPath(any.toStdString()); + pathFromUtf8(infrastructure::backup::stickRootForCatalogPath(any.toStdString())); m_stickSpaceWatcher.setFuture(QtConcurrent::run( infrastructure::backup::measureStickSpace, root)); } @@ -222,7 +223,7 @@ bool LibraryEditSession::editsBrowsedBackup() const continue; } if (infrastructure::local::isBrowsedBackupRoot( - infrastructure::backup::stickRootForCatalogPath(libraryPath.toStdString()))) { + pathFromUtf8(infrastructure::backup::stickRootForCatalogPath(libraryPath.toStdString())))) { return true; } } diff --git a/src/gui/edit/save_context.cpp b/src/gui/edit/save_context.cpp index 83bec332..d72dabbd 100644 --- a/src/gui/edit/save_context.cpp +++ b/src/gui/edit/save_context.cpp @@ -26,6 +26,7 @@ #include <filesystem> #include "application/path_key.hpp" +#include "gui/qt_path.hpp" #include "infrastructure/backup/filesystem_backup_store.hpp" #include "infrastructure/backup/stick_locks.hpp" #include "infrastructure/logging/file_operation_log.hpp" @@ -93,7 +94,7 @@ infrastructure::backup::FilesystemBackupStore &SaveContext::archiveStore() std::uint64_t SaveContext::releaseAutomaticBackupsIfTight() { - return releaseAutomaticBackupsIfTight(infrastructure::backup::measureStickSpace(stickRoot())); + return releaseAutomaticBackupsIfTight(infrastructure::backup::measureStickSpace(pathFromUtf8(stickRoot()))); } std::uint64_t SaveContext::releaseAutomaticBackupsIfTight(const infrastructure::backup::StickSpace &space) @@ -152,13 +153,14 @@ std::vector<std::string> SaveContext::walSidecarsOf(const std::string &file) // The same definition of "the database's set" Full Stick Backup // uses: the main file plus whichever of -wal / -journal exist. std::vector<std::string> sidecars; - if (fs::path(file).extension() != ".db") { + const fs::path filePath = pathFromUtf8(file); + if (filePath.extension() != ".db") { return sidecars; } - for (const fs::path &member : infrastructure::stick_backup::dbSetMembers(fs::path(file))) { + for (const fs::path &member : infrastructure::stick_backup::dbSetMembers(filePath)) { std::error_code ec; - if (member != fs::path(file) && fs::is_regular_file(member, ec) && fs::file_size(member, ec) > 0 && !ec) { - sidecars.push_back(member.string()); + if (member != filePath && fs::is_regular_file(member, ec) && fs::file_size(member, ec) > 0 && !ec) { + sidecars.push_back(pathToUtf8(member)); } } return sidecars; @@ -213,7 +215,7 @@ void SaveContext::backupAllNow(const std::vector<BackupTarget> &targets) record = archiveStore().backup(files, label); madeHere.push_back(record.id); m_recordByLabel[label] = record.id; - m_backups.push_back({QString::fromStdString(fs::path(record.path).parent_path().string()), + m_backups.push_back({pathToQString(pathFromUtf8(record.path).parent_path()), QString::fromStdString(record.id)}); } else { record = archiveStore().addToArchive(existing->second, files); @@ -358,12 +360,12 @@ bool SaveContext::backupOnce(const std::string &file, const std::string &label) if (existing == m_recordByLabel.end()) { record = archiveStore().backup({file}, label); m_recordByLabel[label] = record.id; - m_backups.push_back({QString::fromStdString(fs::path(record.path).parent_path().string()), + m_backups.push_back({pathToQString(pathFromUtf8(record.path).parent_path()), QString::fromStdString(record.id)}); } else { record = archiveStore().addToArchive(existing->second, {file}); } - log().record(label + ": backed up " + fs::path(file).filename().string() + " -> " + record.path); + log().record(label + ": backed up " + pathToUtf8(pathFromUtf8(file).filename()) + " -> " + record.path); m_backedUp[application::normalizedPathKey(file)] = record.id; return true; } @@ -380,11 +382,11 @@ namespace bool sameBytes(const std::string &a, const std::string &b) { std::error_code ec; - if (fs::file_size(a, ec) != fs::file_size(b, ec) || ec) { + if (fs::file_size(pathFromUtf8(a), ec) != fs::file_size(pathFromUtf8(b), ec) || ec) { return false; } - std::ifstream left(a, std::ios::binary); - std::ifstream right(b, std::ios::binary); + std::ifstream left(pathFromUtf8(a), std::ios::binary); + std::ifstream right(pathFromUtf8(b), std::ios::binary); // "I could not read them" is not "they are the same". Neither // stream was checked, so if either would not open -- a sharing // violation on Windows, a path this filesystem will not resolve -- @@ -434,7 +436,7 @@ void SaveContext::protectForThisChange(const std::string &file) // A SQLite database is its sidecars too. Absent ones are recorded as // absent, so one the change created is removed again. std::vector<std::string> members{target}; - if (fs::path(target).extension() == ".db") { + if (pathFromUtf8(target).extension() == ".db") { members.push_back(target + "-wal"); members.push_back(target + "-journal"); } @@ -443,8 +445,9 @@ void SaveContext::protectForThisChange(const std::string &file) continue; } Checkpoint checkpoint{member, {}}; + const fs::path memberPath = pathFromUtf8(member); std::error_code ec; - if (fs::is_regular_file(member, ec)) { + if (fs::is_regular_file(memberPath, ec)) { if (!m_checkpointDir) { fs::path dir = fs::temp_directory_path() / ("seabass-change-checkpoint-" @@ -455,19 +458,20 @@ void SaveContext::protectForThisChange(const std::string &file) // Refused up front with the numbers, rather than as a bare "no // space left" halfway through a copy. Either way the change // fails before it has written anything. - const std::uintmax_t size = fs::file_size(member); + const std::uintmax_t size = fs::file_size(memberPath); const std::uintmax_t available = fs::space(m_checkpointDir->path).available; if (available < size) { - throw std::runtime_error("not enough temporary space to protect " + fs::path(member).filename().string() + throw std::runtime_error("not enough temporary space to protect " + pathToUtf8(memberPath.filename()) + " before writing it: needs " + std::to_string(size / (1024 * 1024)) - + " MB in " + m_checkpointDir->path.parent_path().string() + ", " + + " MB in " + pathToUtf8(m_checkpointDir->path.parent_path()) + ", " + std::to_string(available / (1024 * 1024)) + " MB free"); } // A counter, not m_checkpoints.size(): see the member's own // comment. The vector shrinks under redirectWrites() and the // names must not be reissued when it does. - checkpoint.copy = (m_checkpointDir->path / std::to_string(m_nextCheckpointName++)).string(); - fs::copy_file(member, checkpoint.copy, fs::copy_options::overwrite_existing); + const fs::path copy = m_checkpointDir->path / std::to_string(m_nextCheckpointName++); + checkpoint.copy = pathToUtf8(copy); + fs::copy_file(memberPath, copy, fs::copy_options::overwrite_existing); } m_checkpoints.push_back(std::move(checkpoint)); } @@ -489,7 +493,7 @@ void SaveContext::redirectWrites(const std::string &liveFile, const std::string // weight -- a whole database held in temp beside the scratch copy and // that copy's own checkpoint. std::vector<std::string> live{liveFile}; - if (fs::path(liveFile).extension() == ".db") { + if (pathFromUtf8(liveFile).extension() == ".db") { live.push_back(liveFile + "-wal"); live.push_back(liveFile + "-journal"); } @@ -504,7 +508,7 @@ void SaveContext::redirectWrites(const std::string &liveFile, const std::string } std::error_code ec; if (!checkpoint.copy.empty()) { - fs::remove(checkpoint.copy, ec); + fs::remove(pathFromUtf8(checkpoint.copy), ec); } return true; }); @@ -565,7 +569,7 @@ std::optional<QString> SaveContext::rollBackChange() // the guard this replaced short-circuited and never even // reached the remove. Prefixing only the remove would // have left the bug exactly where it was. - const fs::path original = infrastructure::longPathSafe(it->original); + const fs::path original = infrastructure::longPathSafe(pathFromUtf8(it->original)); // "Is it there" can fail without being a no: EIO on a // dying stick, a sharing violation on Windows, a parent // directory that cannot be searched. fs::exists() answers @@ -583,7 +587,7 @@ std::optional<QString> SaveContext::rollBackChange() } if (stillThere) { std::string failure; - if (!infrastructure::removeEntry(it->original, failure)) { + if (!infrastructure::removeEntry(pathFromUtf8(it->original), failure)) { throw std::runtime_error("could not remove " + it->original + ": " + failure); } ++putBack; @@ -592,7 +596,7 @@ std::optional<QString> SaveContext::rollBackChange() } // Byte for byte, not by mtime: FAT keeps two-second mtimes, so // a same-size rewrite inside that window looks untouched. - if (fs::exists(it->original, ec) && sameBytes(it->copy, it->original)) { + if (fs::exists(pathFromUtf8(it->original), ec) && sameBytes(it->copy, it->original)) { continue; } if (!infrastructure::copyFileDurablyAtomic(it->copy, it->original)) { @@ -612,7 +616,8 @@ std::optional<QString> SaveContext::rollBackChange() if (checkpoint.original.size() > suffix.size() && checkpoint.original.compare(checkpoint.original.size() - suffix.size(), suffix.size(), suffix) == 0) { std::error_code ec; - fs::remove(checkpoint.original.substr(0, checkpoint.original.size() - suffix.size()) + "-shm", ec); + const std::string base = checkpoint.original.substr(0, checkpoint.original.size() - suffix.size()); + fs::remove(pathFromUtf8(base + "-shm"), ec); } } @@ -638,7 +643,7 @@ std::optional<QString> SaveContext::rollBackChange() // what someone may still want back. std::vector<std::string> moved; for (const char *suffix : {"-wal", "-shm", "-journal"}) { - const fs::path side = fs::path(database.path + suffix); + const fs::path side = pathFromUtf8(database.path + suffix); std::error_code ec; if (!fs::exists(side, ec) || ec) { continue; @@ -648,7 +653,7 @@ std::optional<QString> SaveContext::rollBackChange() fs::remove(stale, ec); fs::rename(side, stale, ec); if (!ec) { - moved.push_back(side.filename().string()); + moved.push_back(pathToUtf8(side.filename())); } } if (!moved.empty() && hasStick()) { @@ -657,7 +662,7 @@ std::optional<QString> SaveContext::rollBackChange() list += (list.empty() ? "" : ", ") + name; } log().record("save: moved " + list + " aside as .seabass-stale -- the rollback could not put " - + fs::path(database.path).filename().string() + + pathToUtf8(pathFromUtf8(database.path).filename()) + " back in step with them, and SQLite would replay them into the wrong generation " "on the next open. The backup taken before this save holds the state to go back to."); } @@ -675,10 +680,10 @@ std::optional<QString> SaveContext::rollBackChange() } if (!left) { log().record("save: after the rollback, could not tell whether " - + fs::path(database.path).filename().string() + + pathToUtf8(pathFromUtf8(database.path).filename()) + " still has a write-ahead log beside it"); } else if (*left > 0) { - log().record("save: after the rollback " + fs::path(database.path).filename().string() + log().record("save: after the rollback " + pathToUtf8(pathFromUtf8(database.path).filename()) + " kept " + std::to_string(*left) + " bytes in its write-ahead log; the rows of the changes that did apply are not in it " "until something folds them"); diff --git a/src/gui/engine_library_creator_controller.cpp b/src/gui/engine_library_creator_controller.cpp index 80bd10c4..fb394b39 100644 --- a/src/gui/engine_library_creator_controller.cpp +++ b/src/gui/engine_library_creator_controller.cpp @@ -13,6 +13,7 @@ #include "gui/edit/edit_session_registry.hpp" #include "gui/library_catalog_cache.hpp" +#include "gui/qt_path.hpp" #include "infrastructure/engine/engine_import_state.hpp" #include "infrastructure/engine/libdjinterop_engine_library_creator.hpp" @@ -48,7 +49,7 @@ EngineLibraryCreationTaskResult runCreateTask(QString rekordboxPath, int schemaG LibraryCatalogCache::instance().tracksFor("rekordbox", rekordboxPath.toStdString(), *reporter, cancel); std::string engineLibraryPath = - (fs::path(rekordboxPath.toStdString()).parent_path() / "Engine Library").string(); + pathToUtf8(pathFromQString(rekordboxPath).parent_path() / "Engine Library"); // Invalidated before create() runs, not just on success: a // partially-failed create() may still have written real files at // this exact path, and a stale "engine" entry from a prior diff --git a/src/gui/full_backups_controller.cpp b/src/gui/full_backups_controller.cpp index 69cb50bb..c709498f 100644 --- a/src/gui/full_backups_controller.cpp +++ b/src/gui/full_backups_controller.cpp @@ -16,6 +16,7 @@ #include <string> #include "gui/future_result.hpp" +#include "gui/qt_path.hpp" #include "infrastructure/local/browsed_backup_root.hpp" #include "infrastructure/stick_backup/backup_manifest.hpp" @@ -34,7 +35,7 @@ QString canonical(const QString &path) if (path.isEmpty()) { return {}; } - return QString::fromStdString(infrastructure::local::canonicalOrAbsolute(fs::path(path.toStdString())).string()); + return pathToQString(infrastructure::local::canonicalOrAbsolute(pathFromQString(path))); } } // namespace @@ -106,15 +107,15 @@ void FullBackupsController::refresh() m_refreshAgain = true; return; } - const fs::path directory(m_backupDirectory.toStdString()); - const fs::path current(m_currentArchivePath.toStdString()); + const fs::path directory = pathFromQString(m_backupDirectory); + const fs::path current = pathFromQString(m_currentArchivePath); m_listWatcher.setFuture(QtConcurrent::run([directory, current]() { QVariantList backups; for (const application::ManagedStickBackup &backup : application::ManageStickBackups::list(directory, current)) { const application::StickBackupDescription &d = backup.description; QVariantMap map; - map["archivePath"] = canonical(QString::fromStdString(d.archivePath.string())); - map["fileName"] = QString::fromStdString(d.archivePath.filename().string()); + map["archivePath"] = canonical(pathToQString(d.archivePath)); + map["fileName"] = pathToQString(d.archivePath.filename()); map["error"] = QString::fromStdString(d.error); map["label"] = QString::fromStdString(d.stickLabel); map["identifier"] = QString::fromStdString(d.stickIdentifier); @@ -131,7 +132,7 @@ void FullBackupsController::refresh() if (!d.error.empty()) { // describe() leaves the size unset for an unreadable file; // it still takes up space, and that is worth saying. - map["bytes"] = static_cast<qlonglong>(QFileInfo(QString::fromStdString(d.archivePath.string())).size()); + map["bytes"] = static_cast<qlonglong>(QFileInfo(pathToQString(d.archivePath)).size()); } backups.push_back(map); } @@ -165,7 +166,7 @@ void FullBackupsController::openChangelog(const QString &archivePath) return; } QString error; - const QString path = writeChangelogFile(fs::path(canonical(archivePath).toStdString()), &error); + const QString path = writeChangelogFile(pathFromQString(canonical(archivePath)), &error); if (path.isEmpty()) { // setMessages is this page's only way to speak; an error here is // never fatal, so it reads as a note rather than a failure state. @@ -189,7 +190,7 @@ void FullBackupsController::deleteBackup(const QString &archivePath) } setMessages({}, {}); m_deletingPath = path; - const fs::path archive(path.toStdString()); + const fs::path archive = pathFromQString(path); m_deleteWatcher.setFuture(QtConcurrent::run([archive]() { return application::ManageStickBackups::remove(archive); })); emit busyChanged(); } @@ -217,7 +218,7 @@ QString FullBackupsController::browsedArchiveFor(const QString &libraryRoot) con if (libraryRoot.isEmpty()) { return {}; } - const auto archive = infrastructure::local::browsedBackupArchive(fs::path(libraryRoot.toStdString())); + const auto archive = infrastructure::local::browsedBackupArchive(pathFromQString(libraryRoot)); return archive ? canonical(QString::fromStdString(archive->string())) : QString(); } diff --git a/src/gui/home_backups_controller.cpp b/src/gui/home_backups_controller.cpp index 94138656..950ef021 100644 --- a/src/gui/home_backups_controller.cpp +++ b/src/gui/home_backups_controller.cpp @@ -7,6 +7,7 @@ #include <filesystem> #include "application/use_cases/restore_stick_backup.hpp" +#include "gui/qt_path.hpp" #include "infrastructure/local/metadata_store.hpp" namespace seabass::gui @@ -34,7 +35,7 @@ void HomeBackupsController::refresh() { const int backups = m_backupDirectory.isEmpty() ? 0 - : application::RestoreStickBackup::countArchives(fs::path(m_backupDirectory.toStdString())); + : application::RestoreStickBackup::countArchives(pathFromQString(m_backupDirectory)); const int tracks = infrastructure::local::MetadataStore::storedTrackCountIfPresent(); if (backups == m_fullBackupCount && tracks == m_metadataTrackCount) { return; diff --git a/src/gui/library_catalog_cache.cpp b/src/gui/library_catalog_cache.cpp index 19f03033..ed4b2cbb 100644 --- a/src/gui/library_catalog_cache.cpp +++ b/src/gui/library_catalog_cache.cpp @@ -14,6 +14,7 @@ #include "infrastructure/file_clock.hpp" #include "infrastructure/onelibrary/onelibrary_cue_writer.hpp" #include "infrastructure/onelibrary/onelibrary_reader.hpp" +#include "infrastructure/paths/utf8_path.hpp" #include "infrastructure/rekordbox/kaitai_rekordbox_reader.hpp" namespace seabass::gui @@ -30,13 +31,13 @@ namespace fs = std::filesystem; fs::path freshnessFile(const std::string &format, const std::string &path) { if (format == "rekordbox") { - return fs::path(path) / "rekordbox" / "export.pdb"; + return pathFromUtf8(path) / "rekordbox" / "export.pdb"; } if (format == "engine") { - return fs::path(path) / "Database2" / "m.db"; + return pathFromUtf8(path) / "Database2" / "m.db"; } if (format == "onelibrary") { - return infrastructure::onelibrary::OneLibraryCueWriter::dbPathFor(path); + return pathFromUtf8(infrastructure::onelibrary::OneLibraryCueWriter::dbPathFor(path)); } throw std::invalid_argument("LibraryCatalogCache: unknown format \"" + format + "\""); } @@ -192,9 +193,9 @@ void LibraryCatalogCache::invalidateEveryCatalogOn(const std::string &stickRoot) if (stickRoot.empty()) { return; } - const fs::path root(stickRoot); - invalidateWithOneLibraryMirror("rekordbox", (root / "PIONEER").string()); - invalidate("engine", (root / "Engine Library").string()); + const fs::path root = pathFromUtf8(stickRoot); + invalidateWithOneLibraryMirror("rekordbox", pathToUtf8(root / "PIONEER")); + invalidate("engine", pathToUtf8(root / "Engine Library")); } void LibraryCatalogCache::invalidateWithOneLibraryMirror(const std::string &format, const std::string &path) diff --git a/src/gui/library_consistency_controller.cpp b/src/gui/library_consistency_controller.cpp index 9e503293..923c0d13 100644 --- a/src/gui/library_consistency_controller.cpp +++ b/src/gui/library_consistency_controller.cpp @@ -49,6 +49,7 @@ #include "gui/app_settings_controller.hpp" #include "gui/seabass_settings.hpp" #include "gui/edit/changes/repair_issue_change.hpp" +#include "gui/qt_path.hpp" namespace seabass::gui { @@ -440,7 +441,7 @@ LibraryConsistencyScanResult runScanTask(QString format, QString path, QString p // archive is opened once rather than once per cover. result.rescue = std::make_shared<ArtworkRescueSources>( backupDirectory.toStdString(), - std::filesystem::path(path.toStdString()).parent_path().string()); + pathToUtf8(pathFromQString(path).parent_path())); result.artwork = infrastructure::engine::auditArtwork(path.toStdString(), artSources, result.rescue->probe()); // The same pass asks each row for its sample rate, and each @@ -633,10 +634,8 @@ void LibraryConsistencyController::scan(const QString &rekordboxPath, const QStr emit analysisStateChanged(); m_artSources.clear(); emit artworkChanged(); - const QString stickRoot = QString::fromStdString( - std::filesystem::path((m_enginePath.isEmpty() ? m_rekordboxPath : m_enginePath).toStdString()) - .parent_path() - .string()); + const QString stickRoot = + pathToQString(pathFromQString(m_enginePath.isEmpty() ? m_rekordboxPath : m_enginePath).parent_path()); const bool wasReadOnly = m_stickReadOnly; m_stickReadOnly = !stickRoot.isEmpty() && infrastructure::media::isMountedReadOnly(stickRoot.toStdString()); @@ -1237,9 +1236,7 @@ void LibraryConsistencyController::repairStickFilesystem() return; } const std::string stickRoot = - std::filesystem::path((m_enginePath.isEmpty() ? m_rekordboxPath : m_enginePath).toStdString()) - .parent_path() - .string(); + pathToUtf8(pathFromQString(m_enginePath.isEmpty() ? m_rekordboxPath : m_enginePath).parent_path()); if (stickRoot.empty()) { return; } @@ -1269,9 +1266,7 @@ void LibraryConsistencyController::onFilesystemRepairFinished() m_repairingFilesystem = false; m_filesystemMessage = thrown.isEmpty() ? QString::fromStdString(result.message) : thrown; const std::string stickRoot = - std::filesystem::path((m_enginePath.isEmpty() ? m_rekordboxPath : m_enginePath).toStdString()) - .parent_path() - .string(); + pathToUtf8(pathFromQString(m_enginePath.isEmpty() ? m_rekordboxPath : m_enginePath).parent_path()); m_stickReadOnly = infrastructure::media::isMountedReadOnly(stickRoot); emit stickHealthChanged(); const bool worked = result.repaired && !m_stickReadOnly; diff --git a/src/gui/media_controller.cpp b/src/gui/media_controller.cpp index 82c7432a..dad62d68 100644 --- a/src/gui/media_controller.cpp +++ b/src/gui/media_controller.cpp @@ -30,6 +30,7 @@ #include "infrastructure/media/media_factory.hpp" #include "infrastructure/media/stick_root_scan.hpp" #include "gui/future_result.hpp" +#include "gui/qt_path.hpp" namespace seabass::gui { @@ -349,7 +350,7 @@ void MediaController::detect() application::DetectedStick folder = *m_openedFolder; folder.rekordboxPath.reset(); folder.enginePath.reset(); - const std::filesystem::path dir(folder.mountPoint); + const std::filesystem::path dir = pathFromUtf8(folder.mountPoint); std::error_code dirEc; if (std::filesystem::is_directory(dir, dirEc) && !dirEc) { infrastructure::media::scanMountedRoot(folder.mountPoint, folder); @@ -365,7 +366,7 @@ void MediaController::detect() continue; } std::error_code stickEc; - const auto stickRoot = std::filesystem::weakly_canonical(std::filesystem::path(stick.mountPoint), stickEc); + const auto stickRoot = std::filesystem::weakly_canonical(pathFromUtf8(stick.mountPoint), stickEc); isAMountedStick = isAMountedStick || (!stickEc && stickRoot == folderRoot); } folderListed = (folder.rekordboxPath.has_value() || folder.enginePath.has_value()) && !isAMountedStick; @@ -449,14 +450,14 @@ QString MediaController::openFolder(const QString &path, const QString &label) { std::error_code ec; const std::filesystem::path dir = - std::filesystem::canonical(std::filesystem::path(localPathFromUrl(path).toStdString()), ec); + std::filesystem::canonical(pathFromQString(localPathFromUrl(path)), ec); if (ec) { return tr("That folder could not be opened: %1").arg(QString::fromStdString(ec.message())); } if (!std::filesystem::is_directory(dir, ec) || ec) { return tr("That is not a folder."); } - const std::string canonical = dir.string(); + const std::string canonical = pathToUtf8(dir); // A mounted stick's own root is already listed, with the identity the // stick actually has. Listing it a second time as a folder would put @@ -465,7 +466,7 @@ QString MediaController::openFolder(const QString &path, const QString &label) for (const application::DetectedStick &stick : m_model.sticks()) { std::error_code cmpEc; if (!stick.isFolder && stick.mounted - && std::filesystem::weakly_canonical(std::filesystem::path(stick.mountPoint), cmpEc) == dir) { + && std::filesystem::weakly_canonical(pathFromUtf8(stick.mountPoint), cmpEc) == dir) { return tr("That is the USB stick \"%1\", which is already in the list.") .arg(QString::fromStdString(stick.label)); } @@ -501,7 +502,7 @@ QString MediaController::openFolder(const QString &path, const QString &label) QString MediaController::openBackup(const QString &archivePath) { - const std::filesystem::path archive(localPathFromUrl(archivePath).toStdString()); + const std::filesystem::path archive = pathFromQString(localPathFromUrl(archivePath)); // One cache directory per archive, named after its path rather than // its label: two backups of differently-named sticks must not land on // top of each other, and re-opening the same archive should reuse (and @@ -510,7 +511,7 @@ QString MediaController::openBackup(const QString &archivePath) // directory or a ".." spelling is one backup, one cache, one row. const std::filesystem::path archiveKey = infrastructure::local::canonicalOrAbsolute(archive); const std::filesystem::path cacheRoot = - infrastructure::paths::localBrowsedBackupsDir() / folderLibraryId(archiveKey.string()); + infrastructure::paths::localBrowsedBackupsDir() / folderLibraryId(pathToUtf8(archiveKey)); const application::OpenedStickBackup opened = application::OpenStickBackup::execute(archiveKey, cacheRoot); if (!opened.error.empty()) { @@ -519,7 +520,7 @@ QString MediaController::openBackup(const QString &archivePath) // The label is the stick the backup was taken from, when the manifest // says; the cache directory's own name is a hash and would tell the // user nothing. - return openFolder(QString::fromStdString(opened.libraryRoot.string()), + return openFolder(pathToQString(opened.libraryRoot), QString::fromStdString(opened.stickLabel)); } @@ -531,7 +532,7 @@ std::string MediaController::folderLabelFor(const std::filesystem::path &dir, co if (!given.isEmpty()) { return given.toStdString(); } - return dir.filename().empty() ? dir.string() : dir.filename().string(); + return dir.filename().empty() ? pathToUtf8(dir) : pathToUtf8(dir.filename()); } void MediaController::closeFolder(const QString &path) @@ -573,7 +574,7 @@ void MediaController::releaseBrowsedBackup(const std::string &folderPath) { // An open handle otherwise stays held until quit, and on Windows // blocks replacing that archive with a newer generation. - if (auto archive = infrastructure::local::browsedBackupArchive(std::filesystem::path(folderPath))) { + if (auto archive = infrastructure::local::browsedBackupArchive(pathFromUtf8(folderPath))) { infrastructure::rekordbox::forgetArchiveSource(archive->string()); } } @@ -597,7 +598,7 @@ void MediaController::loadOpenedFolder() folder.isFolder = true; // The label matters because a browsed backup's directory is named // after a hash; its label is the stick the backup came from. - folder.label = folderLabelFor(std::filesystem::path(folder.mountPoint), + folder.label = folderLabelFor(pathFromUtf8(folder.mountPoint), settings.value(QStringLiteral("openedFolder/label")).toString()); folder.identity.label = folder.label; folder.identity.explicitLibraryId = folderLibraryId(folder.mountPoint); diff --git a/src/gui/metadata_backup_controller.cpp b/src/gui/metadata_backup_controller.cpp index 9383048d..87e9e6ee 100644 --- a/src/gui/metadata_backup_controller.cpp +++ b/src/gui/metadata_backup_controller.cpp @@ -19,6 +19,7 @@ #include "domain/metadata_merge.hpp" #include "gui/local_file_url.hpp" #include "gui/metadata_row_text.hpp" +#include "gui/qt_path.hpp" #include "gui/stick_catalogs.hpp" #include "infrastructure/paths/seabass_paths.hpp" @@ -162,7 +163,7 @@ MetadataBackupTaskResult runStoreTask(std::vector<domain::Track> tracks, std::ve MetadataBackupTaskResult result; try { MetadataSource source; - source.stickRoot = fs::path(libraryPath.toStdString()).parent_path(); + source.stickRoot = pathFromQString(libraryPath).parent_path(); source.libraryId = libraryId.toStdString(); source.stickLabel = stickLabel.toStdString(); // Read from the files, not from the rows: the merge rule's last @@ -412,7 +413,7 @@ MetadataBackupController::~MetadataBackupController() QString MetadataBackupController::storeLocation() const { - return QString::fromStdString(MetadataStore::defaultDatabasePath().parent_path().string()); + return pathToQString(MetadataStore::defaultDatabasePath().parent_path()); } QString MetadataBackupController::state() const diff --git a/src/gui/metadata_restore_controller.cpp b/src/gui/metadata_restore_controller.cpp index e8bda71e..9ed6757d 100644 --- a/src/gui/metadata_restore_controller.cpp +++ b/src/gui/metadata_restore_controller.cpp @@ -19,6 +19,7 @@ #include "gui/future_result.hpp" #include "gui/local_file_url.hpp" #include "gui/metadata_row_text.hpp" +#include "gui/qt_path.hpp" #include "gui/stick_catalogs.hpp" #include "infrastructure/engine/engine_library_layout.hpp" #include "infrastructure/local/metadata_store.hpp" @@ -46,13 +47,13 @@ namespace fs = std::filesystem; // uses to find the catalogs in the first place. QString catalogPathForFormat(const QString &libraryPath, const std::string &format) { - const fs::path stickRoot = fs::path(libraryPath.toStdString()).parent_path(); + const fs::path stickRoot = pathFromQString(libraryPath).parent_path(); if (format == "engine") { - return QString::fromStdString(infrastructure::engine::engineLibraryPath(stickRoot).string()); + return pathToQString(infrastructure::engine::engineLibraryPath(stickRoot)); } // rekordbox and onelibrary are two formats of one library, both // under PIONEER. - return QString::fromStdString((stickRoot / "PIONEER").string()); + return pathToQString(stickRoot / "PIONEER"); } // Runs entirely on a background thread -- no access to the controller. diff --git a/src/gui/restore_stick_backup_controller.cpp b/src/gui/restore_stick_backup_controller.cpp index 5119d3a4..0da6f7f8 100644 --- a/src/gui/restore_stick_backup_controller.cpp +++ b/src/gui/restore_stick_backup_controller.cpp @@ -24,6 +24,7 @@ #include "infrastructure/media/media_factory.hpp" #include "infrastructure/stick_backup/backup_manifest.hpp" #include "infrastructure/system/stick_hardware_info.hpp" +#include "gui/qt_path.hpp" namespace seabass::gui { @@ -179,7 +180,7 @@ void RestoreStickBackupController::refreshKnownBackups() if (m_listWatcher.isRunning()) { return; } - const fs::path directory(m_defaultBackupDirectory.toStdString()); + const fs::path directory = pathFromQString(m_defaultBackupDirectory); m_listWatcher.setFuture(QtConcurrent::run([directory]() { QVariantList backups; if (directory.empty()) { @@ -187,8 +188,8 @@ void RestoreStickBackupController::refreshKnownBackups() } for (const application::StickBackupDescription &d : application::RestoreStickBackup::describeAll(directory)) { QVariantMap map; - map["archivePath"] = QString::fromStdString(d.archivePath.string()); - map["fileName"] = QString::fromStdString(d.archivePath.filename().string()); + map["archivePath"] = pathToQString(d.archivePath); + map["fileName"] = pathToQString(d.archivePath.filename()); map["error"] = QString::fromStdString(d.error); map["label"] = QString::fromStdString(d.stickLabel); map["identifier"] = QString::fromStdString(d.stickIdentifier); @@ -283,8 +284,8 @@ void RestoreStickBackupController::analyze(const QString &targetRoot) m_analyzing = true; emit busyChanged(); RestoreOptions options; - options.archivePath = fs::path(m_archivePath.toStdString()); - options.targetRoot = fs::path(targetRoot.toStdString()); + options.archivePath = pathFromQString(m_archivePath); + options.targetRoot = pathFromQString(targetRoot); bool targetGiven = !targetRoot.isEmpty(); m_analyzeWatcher.setFuture(QtConcurrent::run([options, targetGiven, targetRoot]() { auto result = std::make_shared<AnalyzeResult>(); @@ -445,8 +446,8 @@ void RestoreStickBackupController::restore(const QString &targetRoot, bool exact emit progressChanged(); m_cancel = application::CancellationToken(); RestoreOptions options; - options.archivePath = fs::path(m_archivePath.toStdString()); - options.targetRoot = fs::path(targetRoot.toStdString()); + options.archivePath = pathFromQString(m_archivePath); + options.targetRoot = pathFromQString(targetRoot); m_restoreTarget = targetRoot; options.exact = exact; options.cancel = m_cancel; diff --git a/src/gui/stick_backup_controller.cpp b/src/gui/stick_backup_controller.cpp index 47d9fe87..390b614a 100644 --- a/src/gui/stick_backup_controller.cpp +++ b/src/gui/stick_backup_controller.cpp @@ -32,6 +32,7 @@ #include "infrastructure/media/filesystem_health.hpp" #include "infrastructure/system/rekordbox_process_detector.hpp" #include "infrastructure/system/stick_hardware_info.hpp" +#include "gui/qt_path.hpp" namespace seabass::gui { @@ -118,7 +119,7 @@ void StickBackupController::configure(const QString &stickLabel, const QString & m_stickLabel = stickLabel; m_rekordboxPath = rekordboxPath; m_enginePath = enginePath; - m_stickRoot = QString::fromStdString(fs::path(anyPath.toStdString()).parent_path().string()); + m_stickRoot = pathToQString(pathFromQString(anyPath).parent_path()); m_backupDirectory = backupDirectory; m_archiveAttempt = 1; m_nameCollidedWith.clear(); @@ -139,8 +140,8 @@ void StickBackupController::configure(const QString &stickLabel, const QString & BackupStickOptions StickBackupController::baseOptions() const { BackupStickOptions options; - options.stickRoot = fs::path(m_stickRoot.toStdString()); - options.archivePath = fs::path(m_archivePath.toStdString()); + options.stickRoot = pathFromQString(m_stickRoot); + options.archivePath = pathFromQString(m_archivePath); options.stickIdentifier = m_stickIdentifier.toStdString(); options.stickLabel = m_stickLabel.toStdString(); options.sourceReadOnly = m_stickReadOnly; @@ -195,7 +196,7 @@ void StickBackupController::refresh() options.archivePath.parent_path(), options.stickIdentifier, label.toStdString()); if (!found.empty()) { options.archivePath = found; - result->adoptedArchivePath = QString::fromStdString(found.string()); + result->adoptedArchivePath = pathToQString(found); } } result->preview = BackupStick::preview(options); @@ -544,7 +545,7 @@ void StickBackupController::deleteBackup() if (!enterDirectWrite([this] { deleteBackup(); })) { return; } - const fs::path archive(m_archivePath.toStdString()); + const fs::path archive = pathFromQString(m_archivePath); std::error_code archiveError; fs::remove(archive, archiveError); // The journal goes too: left behind, the next backup would try to @@ -573,7 +574,7 @@ void StickBackupController::verify() setActivity(QStringLiteral("verify")); resetProgress(); m_cancel = application::CancellationToken(); - fs::path archive(m_archivePath.toStdString()); + fs::path archive = pathFromQString(m_archivePath); application::CancellationToken cancel = m_cancel; QPointer<StickBackupController> self(this); auto lastPost = std::make_shared<std::chrono::steady_clock::time_point>(); @@ -602,7 +603,7 @@ void StickBackupController::verify() QVariantMap StickBackupController::compactionPreflight() { - application::CompactionPreflight pre = CompactStickBackup::preflight(fs::path(m_archivePath.toStdString())); + application::CompactionPreflight pre = CompactStickBackup::preflight(pathFromQString(m_archivePath)); QVariantMap map; map["error"] = QString::fromStdString(pre.error); map["archiveBytes"] = static_cast<qlonglong>(pre.archiveBytes); @@ -632,7 +633,7 @@ void StickBackupController::compact() resetProgress(); m_cancel = application::CancellationToken(); CompactStickBackupOptions options; - options.archivePath = fs::path(m_archivePath.toStdString()); + options.archivePath = pathFromQString(m_archivePath); options.cancel = m_cancel; QPointer<StickBackupController> self(this); auto lastPost = std::make_shared<std::chrono::steady_clock::time_point>(); @@ -681,14 +682,14 @@ void StickBackupController::replaceCollidingBackup() // like a backup of neither stick. const QString colliding = archivePathForLabel(m_backupDirectory, m_stickLabel, 1); std::error_code ec; - fs::remove(fs::path(colliding.toStdString()), ec); + fs::remove(pathFromQString(colliding), ec); if (ec) { setErrorMessage(QStringLiteral("Could not remove ") + colliding + QStringLiteral(": ") + QString::fromStdString(ec.message())); emit actionFeedback(m_errorMessage, true); return; } - fs::remove(fs::path((colliding + QStringLiteral(".journal")).toStdString()), ec); + fs::remove(pathFromQString(colliding + QStringLiteral(".journal")), ec); m_nameCollidedWith.clear(); m_archiveAttempt = 1; @@ -700,7 +701,7 @@ void StickBackupController::replaceCollidingBackup() void StickBackupController::openChangelog() { QString error; - const QString path = writeChangelogFile(fs::path(m_archivePath.toStdString()), &error); + const QString path = writeChangelogFile(pathFromQString(m_archivePath), &error); if (path.isEmpty()) { emit actionFeedback(error, true); return; @@ -885,8 +886,8 @@ bool StickBackupController::renameArchiveTo(const QString &target) if (target.isEmpty() || target == m_archivePath) { return true; } - const fs::path from(m_archivePath.toStdString()); - const fs::path to(target.toStdString()); + const fs::path from = pathFromQString(m_archivePath); + const fs::path to = pathFromQString(target); std::error_code ec; if (!fs::exists(from, ec)) { // Nothing written yet: the next backup simply creates it under @@ -909,8 +910,8 @@ bool StickBackupController::renameArchiveTo(const QString &target) } // The journal only exists after an interrupted run; missing is fine. std::error_code journalEc; - fs::rename(fs::path((m_archivePath + QStringLiteral(".journal")).toStdString()), - fs::path((target + QStringLiteral(".journal")).toStdString()), journalEc); + fs::rename(pathFromQString(m_archivePath + QStringLiteral(".journal")), + pathFromQString(target + QStringLiteral(".journal")), journalEc); m_archivePath = target; emit configuredChanged(); return true; diff --git a/src/gui/stick_catalogs.cpp b/src/gui/stick_catalogs.cpp index 1eee7e5b..d39d0407 100644 --- a/src/gui/stick_catalogs.cpp +++ b/src/gui/stick_catalogs.cpp @@ -11,6 +11,7 @@ #include "gui/library_catalog_cache.hpp" #include "infrastructure/engine/engine_library_layout.hpp" #include "infrastructure/onelibrary/onelibrary_cue_writer.hpp" +#include "infrastructure/paths/utf8_path.hpp" #include "infrastructure/stick_backup/library_catalog_mtime.hpp" #include "infrastructure/stick_backup/stick_tree_walker.hpp" #include "infrastructure/stick_layout.hpp" @@ -28,7 +29,7 @@ StickCatalogRead readAllStickCatalogs(const std::string &libraryPath, applicatio return result; } - const fs::path root = fs::path(libraryPath).parent_path(); + const fs::path root = pathFromUtf8(libraryPath).parent_path(); const fs::path pioneerRoot = root / "PIONEER"; auto read = [&](const char *format, const std::string &path, @@ -44,13 +45,13 @@ StickCatalogRead readAllStickCatalogs(const std::string &libraryPath, applicatio std::error_code ec; if (fs::exists(pioneerRoot / "rekordbox" / "export.pdb", ec)) { - read("rekordbox", pioneerRoot.string(), result.catalogs.rekordbox); + read("rekordbox", pathToUtf8(pioneerRoot), result.catalogs.rekordbox); } if (fs::exists(infrastructure::engine::engineMainDatabasePath(root), ec)) { - read("engine", infrastructure::engine::engineLibraryPath(root).string(), result.catalogs.engine); + read("engine", pathToUtf8(infrastructure::engine::engineLibraryPath(root)), result.catalogs.engine); } - if (infrastructure::onelibrary::OneLibraryCueWriter::existsFor(pioneerRoot.string())) { - read("onelibrary", pioneerRoot.string(), result.catalogs.oneLibrary); + if (infrastructure::onelibrary::OneLibraryCueWriter::existsFor(pathToUtf8(pioneerRoot))) { + read("onelibrary", pathToUtf8(pioneerRoot), result.catalogs.oneLibrary); } return result; } @@ -60,7 +61,7 @@ std::int64_t catalogsLastModified(const std::string &libraryPath) if (libraryPath.empty()) { return 0; } - const fs::path root = fs::path(libraryPath).parent_path(); + const fs::path root = pathFromUtf8(libraryPath).parent_path(); // stick_backup's helper does the hard part, and the hard part is // Engine's write-ahead log. @@ -81,7 +82,7 @@ std::int64_t catalogsLastModified(const std::string &libraryPath) // third catalog a DJ's cues can live in, so a cue edit that lands // only there still has to date the stick. const fs::path oneLibrary = root / "PIONEER" / "rekordbox" / "exportLibrary.db"; - for (const fs::path &candidate : {oneLibrary, fs::path(oneLibrary.string() + "-wal")}) { + for (const fs::path &candidate : {oneLibrary, fs::path(oneLibrary) += "-wal"}) { std::error_code ec; const fs::file_time_type written = fs::last_write_time(candidate, ec); if (ec) { diff --git a/src/gui/stick_statistics_controller.cpp b/src/gui/stick_statistics_controller.cpp index ae17dddd..6aa23202 100644 --- a/src/gui/stick_statistics_controller.cpp +++ b/src/gui/stick_statistics_controller.cpp @@ -17,6 +17,7 @@ #include "domain/filesystem_compatibility.hpp" #include "domain/library_statistics.hpp" #include "gui/library_catalog_cache.hpp" +#include "gui/qt_path.hpp" #include "infrastructure/onelibrary/onelibrary_cue_writer.hpp" #include "infrastructure/system/stick_hardware_info.hpp" #include "storageprobe/walk_tree.hpp" @@ -113,7 +114,7 @@ QVariantMap toVariant(const infrastructure::system::StickHardwareInfo &hw, std::uint64_t directorySizeBytes(const std::string &dir, const application::CancellationToken &cancel) { std::error_code ec; - if (dir.empty() || !fs::exists(dir, ec) || ec) { + if (dir.empty() || !fs::exists(pathFromUtf8(dir), ec) || ec) { return 0; } auto walk = storageprobe::walkTree(dir, {}, [&cancel](std::uint64_t) { @@ -129,10 +130,10 @@ std::uint64_t directorySizeBytes(const std::string &dir, const application::Canc std::string stickRootFromPaths(const QString &rekordboxPath, const QString &enginePath) { if (!rekordboxPath.isEmpty()) { - return fs::path(rekordboxPath.toStdString()).parent_path().string(); + return pathToUtf8(pathFromQString(rekordboxPath).parent_path()); } if (!enginePath.isEmpty()) { - return fs::path(enginePath.toStdString()).parent_path().string(); + return pathToUtf8(pathFromQString(enginePath).parent_path()); } return ""; } @@ -202,7 +203,7 @@ StickStatisticsScanResult runScanTask(QString stickLabel, QString rekordboxPath, audioBytes += t.fileSizeBytes; if (!t.artworkPath.empty() && distinctArtwork.insert(t.artworkPath).second) { std::error_code ec; - auto size = fs::file_size(t.artworkPath, ec); + auto size = fs::file_size(pathFromUtf8(t.artworkPath), ec); if (!ec) { artworkBytes += size; } diff --git a/src/gui/sync_controller.cpp b/src/gui/sync_controller.cpp index ff657915..00d75c4a 100644 --- a/src/gui/sync_controller.cpp +++ b/src/gui/sync_controller.cpp @@ -38,6 +38,7 @@ #include "infrastructure/rekordbox/pdb_lookup.hpp" #include "infrastructure/rekordbox/rekordbox_cue_writer.hpp" #include "gui/edit/changes/sync_plan_change.hpp" +#include "gui/qt_path.hpp" namespace seabass::gui { @@ -50,7 +51,7 @@ namespace std::chrono::system_clock::time_point fileMtime(const std::string &path) { - return infrastructure::toSystemClock(std::filesystem::last_write_time(path)); + return infrastructure::toSystemClock(std::filesystem::last_write_time(pathFromUtf8(path))); } // Builds SyncTaskResult::playlistNames/playlistTrackCounts from the union @@ -118,7 +119,7 @@ SyncTaskResult runAnalyzeTask(QString rekordboxPath, QString enginePath, QString if (hasRekordbox) { rekordboxTracks = catalogCache.tracksFor("rekordbox", rekordboxPath.toStdString(), *reporter, cancel); - rekordboxMtime = fileMtime((fs::path(rekordboxPath.toStdString()) / "rekordbox" / "export.pdb").string()); + rekordboxMtime = fileMtime(pathToUtf8(pathFromQString(rekordboxPath) / "rekordbox" / "export.pdb")); hasOneLibrary = infrastructure::onelibrary::OneLibraryCueWriter::existsFor(rekordboxPath.toStdString()); } if (hasEngine) { @@ -129,7 +130,7 @@ SyncTaskResult runAnalyzeTask(QString rekordboxPath, QString enginePath, QString engineTracks.erase(std::remove_if(engineTracks.begin(), engineTracks.end(), [](const domain::Track &t) { return !t.streamingSource.empty(); }), engineTracks.end()); - engineMtime = fileMtime((fs::path(enginePath.toStdString()) / "Database2" / "m.db").string()); + engineMtime = fileMtime(pathToUtf8(pathFromQString(enginePath) / "Database2" / "m.db")); } if (hasOneLibrary) { oneLibraryTracks = catalogCache.tracksFor("onelibrary", rekordboxPath.toStdString(), *reporter, cancel);
