From 1aedad326b60b44500126956a2bb5d5fa3a02ded Mon Sep 17 00:00:00 2001 From: "Vladimir Golovnev (glassez)" Date: Sun, 19 Nov 2023 14:50:00 +0300 Subject: [PATCH] Add file_renamed_alert::old_name() --- include/libtorrent/alert_types.hpp | 5 ++++- src/alert.cpp | 11 ++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/include/libtorrent/alert_types.hpp b/include/libtorrent/alert_types.hpp index 18c1dae27db..3c227e95372 100644 --- a/include/libtorrent/alert_types.hpp +++ b/include/libtorrent/alert_types.hpp @@ -345,19 +345,22 @@ TORRENT_VERSION_NAMESPACE_2 { // internal file_renamed_alert(aux::stack_allocator& alloc, torrent_handle const& h - , string_view n, file_index_t idx); + , string_view n, string_view old, file_index_t idx); TORRENT_DEFINE_ALERT_PRIO(file_renamed_alert, 7, alert_priority_critical) static constexpr alert_category_t static_category = alert_category::storage; std::string message() const override; + // returns the new and previous file name, respectively. char const* new_name() const; + char const* old_name() const; // refers to the index of the file that was renamed, file_index_t const index; private: aux::allocation_slot m_name_idx; + aux::allocation_slot m_old_name_idx; #if TORRENT_ABI_VERSION == 1 #if defined __clang__ diff --git a/src/alert.cpp b/src/alert.cpp index 1e24a4d9e22..feed46cb301 100644 --- a/src/alert.cpp +++ b/src/alert.cpp @@ -248,6 +248,7 @@ namespace libtorrent { : torrent_alert(alloc, h) , index(idx) , m_name_idx(alloc.copy_string(n)) + , m_old_name_idx(alloc.copy_string(old)) #if TORRENT_ABI_VERSION == 1 , name(n) #endif @@ -258,6 +259,11 @@ namespace libtorrent { return m_alloc.get().ptr(m_name_idx); } + char const* file_renamed_alert::old_name() const + { + return m_alloc.get().ptr(m_old_name_idx); + } + std::string file_renamed_alert::message() const { #ifdef TORRENT_DISABLE_ALERT_MSG @@ -265,10 +271,13 @@ namespace libtorrent { #else std::string ret { torrent_alert::message() }; char msg[200]; - std::snprintf(msg, sizeof(msg), ": file %d renamed to " + std::snprintf(msg, sizeof(msg), ": file %d renamed from \"" , static_cast(index)); ret.append(msg); + ret.append(old_name()); + ret.append("\" to \""); ret.append(new_name()); + ret.append("\""); return ret; #endif }