diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 97b5db4..d59df83 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,7 +1,6 @@ cmake_minimum_required(VERSION 3.16) add_library(archive SHARED) -mo2_configure_library(archive - WARNINGS OFF PRIVATE_DEPENDS 7z fmt) +mo2_configure_library(archive WARNINGS OFF PRIVATE_DEPENDS 7z) target_compile_definitions(archive PRIVATE -DMODORGANIZER_ARCHIVE_BUILDING) mo2_install_target(archive) diff --git a/src/archive.cpp b/src/archive.cpp index 9583fad..52d899e 100644 --- a/src/archive.cpp +++ b/src/archive.cpp @@ -301,7 +301,7 @@ ArchiveImpl::ArchiveImpl() m_Valid = true; return; } catch (std::exception const& e) { - m_LogCallback(LogLevel::Error, fmt::format(L"Caught exception {}.", e)); + m_LogCallback(LogLevel::Error, std::format(L"Caught exception {}.", e)); m_LastError = Error::ERROR_LIBRARY_INVALID; } } @@ -371,12 +371,12 @@ bool ArchiveImpl::open(std::wstring const& archiveName, if (m_ArchivePtr->Open(file, 0, openCallbackPtr) != S_OK) { m_LogCallback(LogLevel::Debug, - fmt::format(L"Failed to open {} using {} (from signature).", + std::format(L"Failed to open {} using {} (from signature).", archiveName, signatureInfo.second.m_Name)); m_ArchivePtr.Release(); } else { m_LogCallback(LogLevel::Debug, - fmt::format(L"Opened {} using {} (from signature).", + std::format(L"Opened {} using {} (from signature).", archiveName, signatureInfo.second.m_Name)); // Retrieve the extension (warning: .extension() contains the dot): @@ -433,12 +433,12 @@ bool ArchiveImpl::open(std::wstring const& archiveName, if (m_ArchivePtr->Open(file, 0, openCallbackPtr) != S_OK) { m_LogCallback(LogLevel::Debug, - fmt::format(L"Failed to open {} using {} (from signature).", + std::format(L"Failed to open {} using {} (from signature).", archiveName, format.m_Name)); m_ArchivePtr.Release(); } else { m_LogCallback(LogLevel::Debug, - fmt::format(L"Opened {} using {} (from signature).", + std::format(L"Opened {} using {} (from signature).", archiveName, format.m_Name)); break; } @@ -457,7 +457,7 @@ bool ArchiveImpl::open(std::wstring const& archiveName, } m_LogCallback( LogLevel::Warning, - fmt::format(L"The format(s) expected for this extension are: {}.", + std::format(L"The format(s) expected for this extension are: {}.", ArchiveStrings::join(vformats, L", "))); } } @@ -478,7 +478,7 @@ bool ArchiveImpl::open(std::wstring const& archiveName, } if (m_ArchivePtr->Open(file, 0, openCallbackPtr) == S_OK) { m_LogCallback(LogLevel::Debug, - fmt::format(L"Opened {} using {} (from signature).", archiveName, + std::format(L"Opened {} using {} (from signature).", archiveName, format.m_Name)); m_LogCallback(LogLevel::Warning, L"This archive likely has an incorrect extension."); diff --git a/src/extractcallback.cpp b/src/extractcallback.cpp index 3ad0181..fff51cd 100644 --- a/src/extractcallback.cpp +++ b/src/extractcallback.cpp @@ -20,17 +20,15 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #include -#include -#include +#include +#include +#include +#include #include "archive.h" #include "extractcallback.h" #include "propertyvariant.h" -#include -#include -#include - std::wstring operationResultToString(Int32 operationResult) { namespace R = NArchive::NExtract::NOperationResult; @@ -67,7 +65,7 @@ std::wstring operationResultToString(Int32 operationResult) return L"Wrong password"; default: - return fmt::format(L"Unknown error {}", operationResult); + return std::format(L"Unknown error {}", operationResult); } } @@ -127,7 +125,7 @@ bool CArchiveExtractCallback::getOptionalProperty(UInt32 index, int property, PropertyVariant prop; if (m_ArchiveHandler->GetProperty(index, property, &prop) != S_OK) { m_LogCallback(Archive::LogLevel::Error, - fmt::format(L"Error getting property {}.", property)); + std::format(L"Error getting property {}.", property)); return false; } if (prop.is_empty()) { @@ -143,7 +141,7 @@ bool CArchiveExtractCallback::getProperty(UInt32 index, int property, T* result) PropertyVariant prop; if (m_ArchiveHandler->GetProperty(index, property, &prop) != S_OK) { m_LogCallback(Archive::LogLevel::Error, - fmt::format(L"Error getting property {}.", property)); + std::format(L"Error getting property {}.", property)); return false; } @@ -243,7 +241,7 @@ STDMETHODIMP CArchiveExtractCallback::GetStream(UInt32 index, auto fileSizeFound = getOptionalProperty(index, kpidSize, &fileSize); if (fileSizeFound && m_OutputFileStream->SetSize(fileSize) != S_OK) { m_LogCallback(Archive::LogLevel::Error, - fmt::format(L"SetSize() failed on {}.", m_FullProcessedPaths[0])); + std::format(L"SetSize() failed on {}.", m_FullProcessedPaths[0])); } // This is messy but I can't find another way of doing it. A simple @@ -260,7 +258,7 @@ STDMETHODIMP CArchiveExtractCallback::GetStream(UInt32 index, return S_OK; } catch (std::exception const& e) { m_LogCallback(Archive::LogLevel::Error, - fmt::format(L"Caught exception {} in GetStream.", e)); + std::format(L"Caught exception {} in GetStream.", e)); } return E_FAIL; } diff --git a/src/extractcallback.h b/src/extractcallback.h index 1b61dfa..c69737e 100644 --- a/src/extractcallback.h +++ b/src/extractcallback.h @@ -24,15 +24,13 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #include #include #include +#include #include "7zip/Archive/IArchive.h" #include "7zip/IPassword.h" #include -#include -#include - #include "archive.h" #include "formatter.h" #include "instrument.h" @@ -73,9 +71,9 @@ class CArchiveExtractCallback : public IArchiveExtractCallback, void reportError(const std::wstring& message); template - void reportError(const wchar_t* format, Args&&... args) + void reportError(std::wformat_string format, Args&&... args) { - reportError(fmt::format(format, std::forward(args)...)); + reportError(std::format(format, std::forward(args)...)); } template diff --git a/src/formatter.h b/src/formatter.h index 0a8cad7..24d2c36 100644 --- a/src/formatter.h +++ b/src/formatter.h @@ -25,62 +25,55 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // exposed outside of the library. It also contains some useful methods for // string manipulation. -#include +#include #include #include #include #include -// Specializing fmt::formatter works, but gives warning, for whatever reason... So -// putting everything in the namespace. -namespace fmt -{ - -// I don't know why fmt does not provide this... template <> -struct formatter : formatter +struct std::formatter : std::formatter { template - auto format(std::string const& s, FormatContext& ctx) + auto format(std::string const& s, FormatContext& ctx) const { - return formatter::format(std::wstring(s.begin(), s.end()), - ctx); + return std::formatter::format( + std::wstring(s.begin(), s.end()), ctx); } }; template <> -struct formatter : formatter +struct std::formatter : std::formatter { template - auto format(std::exception const& ex, FormatContext& ctx) + auto format(std::exception const& ex, FormatContext& ctx) const { - return formatter::format(ex.what(), ctx); + return std::formatter::format(ex.what(), ctx); } }; template <> -struct formatter : formatter +struct std::formatter : std::formatter { template - auto format(std::error_code const& ec, FormatContext& ctx) + auto format(std::error_code const& ec, FormatContext& ctx) const { - return formatter::format(ec.message(), ctx); + return std::formatter::format(ec.message(), ctx); } }; template <> -struct formatter : formatter +struct std::formatter + : std::formatter { template - auto format(std::filesystem::path const& path, FormatContext& ctx) + auto format(std::filesystem::path const& path, FormatContext& ctx) const { - return formatter::format(path.native(), ctx); + return std::formatter::format(path.native(), ctx); } }; -} // namespace fmt - namespace ArchiveStrings { diff --git a/src/instrument.h b/src/instrument.h index 8bbf85a..82dc3f7 100644 --- a/src/instrument.h +++ b/src/instrument.h @@ -22,8 +22,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #define ARCHIVE_INSTRUMENT_H #include - -#include +#include namespace ArchiveTimers { @@ -87,7 +86,7 @@ class Timer auto ms = [](auto&& t) { return std::chrono::duration(t); }; - return fmt::format( + return std::format( L"Instrument '{}': {} calls, total of {}ms, {:.3f}ms per call on average.", name, ncalls, ms(time).count(), ms(time).count() / ncalls); } diff --git a/src/opencallback.cpp b/src/opencallback.cpp index 95e3619..1bf8f97 100644 --- a/src/opencallback.cpp +++ b/src/opencallback.cpp @@ -26,6 +26,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #include +#include #include #include #include @@ -33,9 +34,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #include "fileio.h" -#include -#include - #define UNUSED(x) CArchiveOpenCallback::CArchiveOpenCallback(Archive::PasswordCallback passwordCallback, @@ -130,7 +128,7 @@ STDMETHODIMP CArchiveOpenCallback::GetProperty(PROPID propID, PROPVARIANT* value default: m_LogCallback(Archive::LogLevel::Warning, - fmt::format(L"Unexpected property {}.", propID)); + std::format(L"Unexpected property {}.", propID)); } return S_OK; }