| 734 | } |
| 735 | |
| 736 | bool MediaFileInfoObject::rename(const QString &newPath) |
| 737 | { |
| 738 | const auto from = m_f.path(); |
| 739 | const auto fromNative = std::filesystem::path(CppUtilities::makeNativePath(from)); |
| 740 | const auto toRelUtf8 = newPath.toUtf8(); |
| 741 | const auto toRelView = CppUtilities::PathStringView(toRelUtf8.data(), static_cast<std::size_t>(toRelUtf8.size())); |
| 742 | const auto toNative = fromNative.parent_path().append(CppUtilities::makeNativePath(toRelView)); |
| 743 | const auto toView = CppUtilities::extractNativePath(toNative.native()); |
| 744 | try { |
| 745 | m_f.stream().close(); |
| 746 | std::filesystem::rename(fromNative, toNative); |
| 747 | m_f.reportPathChanged(toView); |
| 748 | m_f.stream().open(m_f.path(), std::ios_base::in | std::ios_base::out | std::ios_base::binary); |
| 749 | } catch (const std::runtime_error &e) { |
| 750 | m_diag.emplace_back(TagParser::DiagLevel::Critical, e.what(), CppUtilities::argsToString("renaming \"", from, "\" to \"", toView)); |
| 751 | return false; |
| 752 | } |
| 753 | if (!m_quiet) { |
| 754 | std::cout << " - Renamed \"" << from << "\" to \"" << toView << "\"\n"; |
| 755 | } |
| 756 | return true; |
| 757 | } |
| 758 | |
| 759 | } // namespace Cli |