From 248c8beea19b0c383f8d37c0d3aae23ab9111986 Mon Sep 17 00:00:00 2001 From: MouriNaruto Date: Mon, 6 Nov 2023 21:22:06 +0800 Subject: [PATCH] Remove NanaGet::VFormatWindowsRuntimeString and NanaGet::FormatWindowsRuntimeString. --- NanaGet/MainPage.cpp | 7 ++--- NanaGet/NanaGetCore.cpp | 59 +++++------------------------------------ NanaGet/NanaGetCore.h | 8 ------ NanaGet/TaskItem.cpp | 10 +++---- 4 files changed, 15 insertions(+), 69 deletions(-) diff --git a/NanaGet/MainPage.cpp b/NanaGet/MainPage.cpp index 9bf08fc..e988d91 100644 --- a/NanaGet/MainPage.cpp +++ b/NanaGet/MainPage.cpp @@ -335,16 +335,17 @@ namespace winrt::NanaGet::implementation EVENT_ALL_ACCESS)); winrt::check_bool(static_cast(EventHandle)); - //winrt::slim_lock_guard LockGuard(NanaGet::LocalInstance->InstanceLock()); + /*winrt::slim_lock_guard LockGuard( + NanaGet::LocalInstance->InstanceLock());*/ NanaGet::LocalInstance->RefreshInformation(); - winrt::hstring GlobalStatusText = NanaGet::FormatWindowsRuntimeString( + winrt::hstring GlobalStatusText = winrt::hstring(Mile::FormatWideString( L"\x2193 %s/s \x2191 %s/s", NanaGet::ConvertByteSizeToString( NanaGet::LocalInstance->TotalDownloadSpeed()).data(), NanaGet::ConvertByteSizeToString( - NanaGet::LocalInstance->TotalUploadSpeed()).data()); + NanaGet::LocalInstance->TotalUploadSpeed()).data())); winrt::hstring CurrentSearchFilter = this->m_SearchFilter; diff --git a/NanaGet/NanaGetCore.cpp b/NanaGet/NanaGetCore.cpp index 0910887..f750b80 100644 --- a/NanaGet/NanaGetCore.cpp +++ b/NanaGet/NanaGetCore.cpp @@ -217,53 +217,6 @@ winrt::hstring NanaGet::CreateGuidString() return winrt::to_hstring(Result); } -winrt::hstring NanaGet::VFormatWindowsRuntimeString( - _In_z_ _Printf_format_string_ wchar_t const* const Format, - _In_z_ _Printf_format_string_ va_list ArgList) -{ - // Check the argument list. - if (Format) - { - // Get the length of the format result. - size_t nLength = - static_cast(::_vscwprintf(Format, ArgList)) + 1; - - // Allocate for the format result. - std::wstring Buffer(nLength + 1, L'\0'); - - // Format the string. - int nWritten = ::_vsnwprintf_s( - &Buffer[0], - Buffer.size(), - nLength, - Format, - ArgList); - - if (nWritten > 0) - { - // If succeed, resize to fit and return result. - Buffer.resize(nWritten); - return winrt::hstring(Buffer); - } - } - - // If failed, return an empty string. - return winrt::hstring(); -} - -winrt::hstring NanaGet::FormatWindowsRuntimeString( - _In_z_ _Printf_format_string_ wchar_t const* const Format, - ...) -{ - va_list ArgList; - va_start(ArgList, Format); - winrt::hstring Result = NanaGet::VFormatWindowsRuntimeString( - Format, - ArgList); - va_end(ArgList); - return Result; -} - winrt::hstring NanaGet::ConvertByteSizeToString( std::uint64_t ByteSize) { @@ -303,10 +256,10 @@ winrt::hstring NanaGet::ConvertByteSizeToString( } - return NanaGet::FormatWindowsRuntimeString( + return winrt::hstring(Mile::FormatWideString( nSystem ? L"%.2f %s" : L"%.0f %s", result, - Systems[nSystem]); + Systems[nSystem])); } winrt::hstring NanaGet::ConvertSecondsToTimeString( @@ -321,11 +274,11 @@ winrt::hstring NanaGet::ConvertSecondsToTimeString( int Minute = static_cast(Seconds / 60 % 60); int Second = static_cast(Seconds % 60); - return NanaGet::FormatWindowsRuntimeString( + return winrt::hstring(Mile::FormatWideString( L"%d:%02d:%02d", Hour, Minute, - Second); + Second)); } bool NanaGet::FindSubString( @@ -1131,9 +1084,9 @@ void NanaGet::LocalAria2Instance::Startup() ::CloseHandle(ProcessInformation.hThread); this->UpdateInstance( - winrt::Uri(NanaGet::FormatWindowsRuntimeString( + winrt::Uri(winrt::hstring(Mile::FormatWideString( L"http://localhost:%d/jsonrpc", - ServerPort)), + ServerPort))), winrt::to_string(ServerToken)); this->m_Available = true; diff --git a/NanaGet/NanaGetCore.h b/NanaGet/NanaGetCore.h index 720e785..4db9681 100644 --- a/NanaGet/NanaGetCore.h +++ b/NanaGet/NanaGetCore.h @@ -45,14 +45,6 @@ namespace NanaGet winrt::hstring CreateGuidString(); - winrt::hstring VFormatWindowsRuntimeString( - _In_z_ _Printf_format_string_ wchar_t const* const Format, - _In_z_ _Printf_format_string_ va_list ArgList); - - winrt::hstring FormatWindowsRuntimeString( - _In_z_ _Printf_format_string_ wchar_t const* const Format, - ...); - winrt::hstring ConvertByteSizeToString( std::uint64_t ByteSize); diff --git a/NanaGet/TaskItem.cpp b/NanaGet/TaskItem.cpp index a8c1f8c..58b65b3 100644 --- a/NanaGet/TaskItem.cpp +++ b/NanaGet/TaskItem.cpp @@ -33,9 +33,9 @@ namespace winrt::NanaGet::implementation if (!Information.InfoHash.empty()) { - this->Source.Value = NanaGet::FormatWindowsRuntimeString( - L"magnet:?xt=urn:btih:%s", - winrt::to_hstring(Information.InfoHash).c_str()); + this->Source.Value = winrt::to_hstring(Mile::FormatString( + "magnet:?xt=urn:btih:%s", + Information.InfoHash.c_str())); } else { @@ -108,7 +108,7 @@ namespace winrt::NanaGet::implementation if (TaskStatus::Active == this->Status.Value || TaskStatus::Paused == this->Status.Value) { - this->StatusText.Value = NanaGet::FormatWindowsRuntimeString( + this->StatusText.Value = winrt::hstring(Mile::FormatWideString( L"%s %s / %s %s/s \x2193 %s/s \x2191", NanaGet::ConvertSecondsToTimeString( this->RemainTime.Value).data(), @@ -119,7 +119,7 @@ namespace winrt::NanaGet::implementation NanaGet::ConvertByteSizeToString( this->DownloadSpeed.Value).data(), NanaGet::ConvertByteSizeToString( - this->UploadSpeed.Value).data()); + this->UploadSpeed.Value).data())); } else {