Skip to content

Commit

Permalink
Remove NanaGet::VFormatWindowsRuntimeString and NanaGet::FormatWindow…
Browse files Browse the repository at this point in the history
…sRuntimeString.
  • Loading branch information
MouriNaruto committed Nov 6, 2023
1 parent 647320c commit 248c8be
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 69 deletions.
7 changes: 4 additions & 3 deletions NanaGet/MainPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,16 +335,17 @@ namespace winrt::NanaGet::implementation
EVENT_ALL_ACCESS));
winrt::check_bool(static_cast<bool>(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;

Expand Down
59 changes: 6 additions & 53 deletions NanaGet/NanaGetCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<size_t>(::_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)
{
Expand Down Expand Up @@ -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(
Expand All @@ -321,11 +274,11 @@ winrt::hstring NanaGet::ConvertSecondsToTimeString(
int Minute = static_cast<int>(Seconds / 60 % 60);
int Second = static_cast<int>(Seconds % 60);

return NanaGet::FormatWindowsRuntimeString(
return winrt::hstring(Mile::FormatWideString(
L"%d:%02d:%02d",
Hour,
Minute,
Second);
Second));
}

bool NanaGet::FindSubString(
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 0 additions & 8 deletions NanaGet/NanaGetCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
10 changes: 5 additions & 5 deletions NanaGet/TaskItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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(),
Expand All @@ -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
{
Expand Down

0 comments on commit 248c8be

Please sign in to comment.