Skip to content

Commit

Permalink
Remove NanaGet::Aria2TaskInformation.
Browse files Browse the repository at this point in the history
  • Loading branch information
MouriNaruto committed Jul 10, 2024
1 parent cee940b commit d843337
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 58 deletions.
19 changes: 10 additions & 9 deletions NanaGet/MainPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,25 +349,26 @@ namespace winrt::NanaGet::implementation

winrt::hstring CurrentSearchFilter = this->m_SearchFilter;

std::vector<Aria2TaskInformation> Tasks;
std::vector<Aria2::DownloadInformation> Tasks;

for (std::string const& Gid : NanaGet::LocalInstance->GetTaskList())
{
Tasks.emplace_back(NanaGet::LocalInstance->GetTaskInformation(Gid));
}

std::set<winrt::hstring> Gids;
for (Aria2TaskInformation const& Task : Tasks)
for (Aria2::DownloadInformation const& Task : Tasks)
{
if (!NanaGet::FindSubString(
winrt::to_hstring(Task.FriendlyName),
winrt::to_hstring(NanaGet::Aria2::ToFriendlyName(Task)),
CurrentSearchFilter,
true))
{
continue;
}

Gids.emplace(winrt::to_hstring(Task.Gid));
Gids.emplace(winrt::to_hstring(
NanaGet::Aria2::FromDownloadGid(Task.Gid)));
}

bool NeedFullRefresh = false;
Expand All @@ -381,10 +382,10 @@ namespace winrt::NanaGet::implementation
else if (this->m_Gids != Gids)
{
std::vector<NanaGet::TaskItem> RawTasks;
for (Aria2TaskInformation const& Task : Tasks)
for (Aria2::DownloadInformation const& Task : Tasks)
{
if (!NanaGet::FindSubString(
winrt::to_hstring(Task.FriendlyName),
winrt::to_hstring(NanaGet::Aria2::ToFriendlyName(Task)),
CurrentSearchFilter,
true))
{
Expand All @@ -405,11 +406,11 @@ namespace winrt::NanaGet::implementation

if (!NeedFullRefresh && this->m_Tasks)
{
std::map<winrt::hstring, Aria2TaskInformation> RawTasks;
for (Aria2TaskInformation const& Task : Tasks)
std::map<winrt::hstring, Aria2::DownloadInformation> RawTasks;
for (Aria2::DownloadInformation const& Task : Tasks)
{
RawTasks.emplace(std::pair(
winrt::to_hstring(Task.Gid),
winrt::to_hstring(NanaGet::Aria2::FromDownloadGid(Task.Gid)),
Task));
}

Expand Down
26 changes: 2 additions & 24 deletions NanaGet/NanaGetCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ void NanaGet::Aria2Instance::RefreshInformation()
}
}

NanaGet::Aria2TaskInformation NanaGet::Aria2Instance::GetTaskInformation(
NanaGet::Aria2::DownloadInformation NanaGet::Aria2Instance::GetTaskInformation(
std::string const& Gid)
{
nlohmann::json Parameters;
Expand All @@ -399,7 +399,7 @@ NanaGet::Aria2TaskInformation NanaGet::Aria2Instance::GetTaskInformation(
nlohmann::json ResponseJson = nlohmann::json::parse(
this->SimpleJsonRpcCall("aria2.tellStatus", Parameters.dump(2)));

return this->ParseTaskInformation(ResponseJson);
return NanaGet::Aria2::ToDownloadInformation(ResponseJson);
}

std::vector<std::string> NanaGet::Aria2Instance::GetTaskList()
Expand Down Expand Up @@ -618,28 +618,6 @@ void NanaGet::Aria2Instance::UpdateInstance(
// this->CloseMessageWebSocket();
//}

NanaGet::Aria2TaskInformation NanaGet::Aria2Instance::ParseTaskInformation(
nlohmann::json const& Value)
{
NanaGet::Aria2::DownloadInformation Information =
NanaGet::Aria2::ToDownloadInformation(Value);

NanaGet::Aria2TaskInformation Result;

Result.Gid = NanaGet::Aria2::FromDownloadGid(Information.Gid);
Result.Status = Information.Status;
Result.TotalLength = Information.TotalLength;
Result.CompletedLength = Information.CompletedLength;
Result.DownloadSpeed = Information.DownloadSpeed;
Result.UploadSpeed = Information.UploadSpeed;
Result.InfoHash = Information.InfoHash;
Result.Dir = Information.Dir;
Result.Files = Information.Files;
Result.FriendlyName = NanaGet::Aria2::ToFriendlyName(Information);

return Result;
}

NanaGet::LocalAria2Instance::LocalAria2Instance()
{
this->m_JobObjectHandle.attach(
Expand Down
21 changes: 2 additions & 19 deletions NanaGet/NanaGetCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,6 @@ namespace NanaGet
winrt::hstring const& SubString,
bool IgnoreCase);

struct Aria2TaskInformation
{
std::string Gid;
Aria2::DownloadStatus Status;
std::uint64_t TotalLength;
std::uint64_t CompletedLength;
std::uint64_t DownloadSpeed;
std::uint64_t UploadSpeed;
std::string InfoHash;
std::string Dir;
std::vector<Aria2::FileInformation> Files;
std::string FriendlyName;
};

class Aria2Instance
{
public:
Expand Down Expand Up @@ -133,7 +119,7 @@ namespace NanaGet

void RefreshInformation();

Aria2TaskInformation GetTaskInformation(
Aria2::DownloadInformation GetTaskInformation(
std::string const& Gid);

std::vector<std::string> GetTaskList();
Expand Down Expand Up @@ -174,10 +160,7 @@ namespace NanaGet
winrt::HttpClient m_HttpClient;

winrt::slim_mutex m_InstanceLock;
NanaGet::Aria2::GlobalStatusInformation m_GlobalStatus;

Aria2TaskInformation ParseTaskInformation(
nlohmann::json const& Value);
Aria2::GlobalStatusInformation m_GlobalStatus;
};

class LocalAria2Instance : public Aria2Instance
Expand Down
10 changes: 6 additions & 4 deletions NanaGet/TaskItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace winrt::NanaGet::implementation
using Windows::UI::Xaml::Visibility;

TaskItem::TaskItem(
Aria2TaskInformation const& Information)
Aria2::DownloadInformation const& Information)
{
this->Update(Information);
}
Expand All @@ -25,11 +25,13 @@ namespace winrt::NanaGet::implementation
}

void TaskItem::Update(
Aria2TaskInformation const& Information)
Aria2::DownloadInformation const& Information)
{
this->Gid.Value = winrt::to_hstring(Information.Gid);
this->Gid.Value = winrt::to_hstring(
NanaGet::Aria2::FromDownloadGid(Information.Gid));

this->Name.Value = winrt::to_hstring(Information.FriendlyName);
this->Name.Value = winrt::to_hstring(
NanaGet::Aria2::ToFriendlyName(Information));

if (!Information.InfoHash.empty())
{
Expand Down
4 changes: 2 additions & 2 deletions NanaGet/TaskItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ namespace winrt::NanaGet::implementation
public:

TaskItem(
Aria2TaskInformation const& Information);
Aria2::DownloadInformation const& Information);

void Notify();

void Update(
Aria2TaskInformation const& Information);
Aria2::DownloadInformation const& Information);

Mile::WinRT::Property<hstring> Gid;
Mile::WinRT::Property<hstring> Name;
Expand Down

0 comments on commit d843337

Please sign in to comment.