mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-15 02:15:55 +08:00
Additional checks on filename creation in downloader
This commit is contained in:
parent
43ce4d1894
commit
1dc8ed5610
@ -137,13 +137,30 @@ void FileGet::priv::get_perform()
|
|||||||
std::string extension = boost::filesystem::extension(dest_path);
|
std::string extension = boost::filesystem::extension(dest_path);
|
||||||
std::string just_filename = m_filename.substr(0, m_filename.size() - extension.size());
|
std::string just_filename = m_filename.substr(0, m_filename.size() - extension.size());
|
||||||
std::string final_filename = just_filename;
|
std::string final_filename = just_filename;
|
||||||
|
// Find unsed filename
|
||||||
|
try {
|
||||||
size_t version = 0;
|
size_t version = 0;
|
||||||
while (boost::filesystem::exists(m_dest_folder / (final_filename + extension)) || boost::filesystem::exists(m_dest_folder / (final_filename + extension + "." + std::to_string(get_current_pid()) + ".download")))
|
while (boost::filesystem::exists(m_dest_folder / (final_filename + extension)) || boost::filesystem::exists(m_dest_folder / (final_filename + extension + "." + std::to_string(get_current_pid()) + ".download")))
|
||||||
{
|
{
|
||||||
++version;
|
++version;
|
||||||
final_filename = just_filename + "(" + std::to_string(version) + ")";
|
if (version > 999) {
|
||||||
|
wxCommandEvent* evt = new wxCommandEvent(EVT_DWNLDR_FILE_ERROR);
|
||||||
|
evt->SetString(GUI::format_wxstr(L"Failed to find suitable filename. Last name: %1%." , (m_dest_folder / (final_filename + extension)).string()));
|
||||||
|
evt->SetInt(m_id);
|
||||||
|
m_evt_handler->QueueEvent(evt);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
final_filename = GUI::format("%1%(%2%)", just_filename, std::to_string(version));
|
||||||
|
}
|
||||||
|
} catch (const boost::filesystem::filesystem_error& e)
|
||||||
|
{
|
||||||
|
wxCommandEvent* evt = new wxCommandEvent(EVT_DWNLDR_FILE_ERROR);
|
||||||
|
evt->SetString(e.what());
|
||||||
|
evt->SetInt(m_id);
|
||||||
|
m_evt_handler->QueueEvent(evt);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
m_filename = final_filename + extension;
|
m_filename = final_filename + extension;
|
||||||
|
|
||||||
m_tmp_path = m_dest_folder / (m_filename + "." + std::to_string(get_current_pid()) + ".download");
|
m_tmp_path = m_dest_folder / (m_filename + "." + std::to_string(get_current_pid()) + ".download");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user