MCPcopy Create free account
hub / github.com/XorTroll/Goldleaf / StartCopy

Method StartCopy

Goldleaf/source/ui/ui_CopyLayout.cpp:78–168  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

76 }
77
78 void CopyLayout::StartCopy(const std::string &path, const std::string &new_path) {
79 ScopeGuard on_exit([&]() {
80 g_MainApplication->ReturnToParentLayout();
81 });
82
83 auto exp = fs::GetExplorerForPath(path);
84 auto new_exp = fs::GetExplorerForPath(new_path);
85 if(exp->IsDirectory(path)) {
86 g_MainApplication->LoadCommonIconMenuData(true, cfg::Strings.GetString(506), CommonIconKind::Copy, cfg::Strings.GetString(473));
87
88 if(new_exp->IsDirectory(new_path)) {
89 const auto option = g_MainApplication->DisplayDialog(cfg::Strings.GetString(135), cfg::Strings.GetString(471), { cfg::Strings.GetString(111), cfg::Strings.GetString(112), cfg::Strings.GetString(18) }, true);
90 if(option == 0) {
91 new_exp->DeleteDirectory(new_path);
92 }
93 else if(option != 1) {
94 return;
95 }
96 }
97
98 const auto dir_name = fs::GetBaseName(path);
99 hos::LockExit();
100 this->copy_file_p_bar->SetVisible(true);
101 this->file_info_text->SetVisible(true);
102
103 auto last_tp = std::chrono::steady_clock::now();
104 exp->CopyDirectoryProgress(path, new_path, [&](const size_t total_size) {
105 this->copy_total_p_bar->SetMaxProgress(total_size);
106 }, [&](const size_t file_size, const std::string &old_file, const std::string &new_file) {
107 this->copy_file_src_info_text->SetText(exp->MakePresentablePath(old_file));
108 this->copy_file_dst_info_text->SetText(new_exp->MakePresentablePath(new_file));
109 this->copy_file_p_bar->SetMaxProgress(file_size);
110 this->copy_file_p_bar->SetProgress(0);
111 }, [&](const size_t cur_rw_size) {
112 this->copy_total_p_bar->IncrementProgress(cur_rw_size);
113 this->copy_file_p_bar->IncrementProgress(cur_rw_size);
114
115 const auto cur_tp = std::chrono::steady_clock::now();
116 const auto time_diff = (double)std::chrono::duration_cast<std::chrono::milliseconds>(cur_tp - last_tp).count();
117 last_tp = cur_tp;
118 // By elapsed time and rw size, compute how much data has been written in 1 second
119 const auto speed_bps = (1000.0f / time_diff) * (double)cur_rw_size;
120 const auto speed_text = cfg::Strings.GetString(458) + ": " + fs::FormatSize(speed_bps) + "/s, " + cfg::Strings.GetString(459) + ": " + util::FormatTime((u64)((1.0f / speed_bps) * (this->copy_total_p_bar->GetMaxProgress() - this->copy_total_p_bar->GetProgress())));
121
122 this->copy_speed_eta_info_text->SetText(speed_text);
123
124 g_MainApplication->CallForRender();
125 });
126 hos::UnlockExit();
127 g_MainApplication->ShowNotification(cfg::Strings.GetString(141));
128 }
129 else {
130 g_MainApplication->LoadCommonIconMenuData(true, cfg::Strings.GetString(506), CommonIconKind::Copy, cfg::Strings.GetString(472));
131
132 if(new_exp->IsFile(new_path)) {
133 const auto option = g_MainApplication->DisplayDialog(cfg::Strings.GetString(153), cfg::Strings.GetString(143), { cfg::Strings.GetString(239), cfg::Strings.GetString(18) }, true);
134 if(option != 0) {
135 return;

Callers 1

OnInputMethod · 0.80

Calls 15

GetExplorerForPathFunction · 0.85
GetBaseNameFunction · 0.85
LockExitFunction · 0.85
FormatSizeFunction · 0.85
UnlockExitFunction · 0.85
ReturnToParentLayoutMethod · 0.80
DisplayDialogMethod · 0.80
CopyDirectoryProgressMethod · 0.80
MakePresentablePathMethod · 0.80
ShowNotificationMethod · 0.80
CopyFileProgressMethod · 0.80

Tested by

no test coverage detected