Is extracted flag for local repos.

This commit is contained in:
David Kocik 2024-06-06 20:08:10 +02:00 committed by YuSanka
parent 3e0483b405
commit 4236c6d952
3 changed files with 45 additions and 24 deletions

View File

@ -3675,8 +3675,8 @@ bool ConfigWizard::priv::any_installed_vendor_for_repo(const std::string& repo_i
static bool to_delete(PagePrinters* page, const std::set<std::string>& selected_uuids)
{
const PresetArchiveDatabase* pad = wxGetApp().plater()->get_preset_archive_database();
const ArchiveRepositoryVector& archs = pad->get_archive_repositories();
const PresetArchiveDatabase* pad = wxGetApp().plater()->get_preset_archive_database();
const SharedArchiveRepositoryVector& archs = pad->get_all_archive_repositories();
bool unselect_all = true;
@ -3728,7 +3728,7 @@ bool ConfigWizard::priv::can_clear_printer_pages()
}
if (msg.IsEmpty())
return false;
return true;
wxString message = format_wxstr( _L("Next pages will be deleted after configuration update:%1%\n"
"Installed presets will be uninstalled.\n"

View File

@ -104,7 +104,8 @@ bool extract_repository_header(const pt::ptree& ptree, ArchiveRepository::Reposi
void delete_path_recursive(const fs::path& path)
{
try {
if (fs::exists(path)) {
boost::system::error_code ec;
if (fs::exists(path, ec) && !ec) {
for (fs::directory_iterator it(path); it != fs::directory_iterator(); ++it) {
const fs::path subpath = it->path();
if (fs::is_directory(subpath)) {
@ -277,8 +278,9 @@ bool LocalArchiveRepository::get_file_inner(const fs::path& source_path, const f
if (cfr != CopyFileResult::SUCCESS) {
BOOST_LOG_TRIVIAL(error) << "Copying of " << source_path << " to " << target_path << " has failed (" << cfr << "): " << error_message;
// remove target file, even if it was there before
if (fs::exists(target_path)) {
boost::system::error_code ec;
boost::system::error_code ec;
if (fs::exists(target_path, ec) && !ec) {
ec.clear();
fs::remove(target_path, ec);
if (ec) {
BOOST_LOG_TRIVIAL(error) << format("Failed to delete file: %1%", ec.message());
@ -335,11 +337,21 @@ bool PresetArchiveDatabase::set_selected_repositories(const std::vector<std::str
std::string id;
std::string name;
for (const auto& archive : m_archive_repositories) {
if (archive->get_uuid() == uuid) {
id = archive->get_manifest().id;
name = archive->get_manifest().name;
break;
}
if (archive->get_uuid() != uuid) {
continue;
}
id = archive->get_manifest().id;
name = archive->get_manifest().name;
if (!archive->is_extracted()) {
// non existent local repo since start selected
msg = GUI::format(
_L("Cannot select local repository from path: %1%. It was not extracted."
" To solve this issue either remove and load it again or restart the app."),
archive->get_manifest().source_path
);
return false;
}
break;
}
assert(!id.empty());
if (auto it = used_set.find(id); it != used_set.end()) {
@ -406,7 +418,8 @@ std::string PresetArchiveDatabase::add_local_archive(const boost::filesystem::pa
}
// Solve if it can be set true first.
m_selected_repositories_uuid[uuid] = false;
m_archive_repositories.emplace_back(std::make_unique<LocalArchiveRepository>(uuid, std::move(header_data)));
m_has_installed_printer_repositories_uuid[uuid] = false;
m_archive_repositories.emplace_back(std::make_unique<LocalArchiveRepository>(uuid, std::move(header_data), true));
save_app_manifest_json();
return uuid;
@ -426,13 +439,18 @@ void PresetArchiveDatabase::remove_local_archive(const std::string& uuid)
assert(used_it != m_selected_repositories_uuid.end());
m_selected_repositories_uuid.erase(used_it);
auto inst_it = m_has_installed_printer_repositories_uuid.find(removed_uuid);
assert(inst_it != m_has_installed_printer_repositories_uuid.end());
m_has_installed_printer_repositories_uuid.erase(inst_it);
save_app_manifest_json();
}
void PresetArchiveDatabase::load_app_manifest_json()
{
const fs::path path = get_stored_manifest_path();
if (!fs::exists(path)) {
boost::system::error_code ec;
if (!fs::exists(path, ec) || ec) {
copy_initial_manifest();
}
std::ifstream file(path.string());
@ -465,25 +483,22 @@ void PresetArchiveDatabase::load_app_manifest_json()
if (const auto source_path = subtree.second.get_optional<std::string>("source_path"); source_path) {
ArchiveRepository::RepositoryManifest manifest;
std::string uuid = get_next_uuid();
if (!extract_local_archive_repository(uuid, *source_path, m_unq_tmp_path, manifest)) {
BOOST_LOG_TRIVIAL(error) << "Local archive repository not extracted: " << *source_path;
continue;
}
bool extracted = extract_local_archive_repository(uuid, *source_path, m_unq_tmp_path, manifest);
// "selected" flag
if(const auto used = subtree.second.get_optional<bool>("selected"); used) {
m_selected_repositories_uuid[uuid] = *used;
m_selected_repositories_uuid[uuid] = extracted && *used;
} else {
assert(true);
m_selected_repositories_uuid[uuid] = true;
m_selected_repositories_uuid[uuid] = extracted;
}
// "has_installed_printers" flag
if (const auto used = subtree.second.get_optional<bool>("has_installed_printers"); used) {
m_has_installed_printer_repositories_uuid[uuid] = *used;
m_has_installed_printer_repositories_uuid[uuid] = extracted && *used;
} else {
assert(true);
m_has_installed_printer_repositories_uuid[uuid] = true;
m_has_installed_printer_repositories_uuid[uuid] = false;
}
m_archive_repositories.emplace_back(std::make_unique<LocalArchiveRepository>(std::move(uuid), std::move(manifest)));
m_archive_repositories.emplace_back(std::make_unique<LocalArchiveRepository>(std::move(uuid), std::move(manifest), extracted));
continue;
}
@ -507,7 +522,7 @@ void PresetArchiveDatabase::load_app_manifest_json()
m_has_installed_printer_repositories_uuid[uuid] = *used;
} else {
assert(true);
m_has_installed_printer_repositories_uuid[uuid] = true;
m_has_installed_printer_repositories_uuid[uuid] = false;
}
m_archive_repositories.emplace_back(std::make_unique<OnlineArchiveRepository>(std::move(uuid), std::move(manifest)));
}

View File

@ -85,6 +85,8 @@ public:
virtual bool get_ini_no_id(const std::string& source_subpath, const boost::filesystem::path& target_path) const = 0;
const RepositoryManifest& get_manifest() const { return m_data; }
std::string get_uuid() const { return m_uuid; }
// Only local archvies can return false
virtual bool is_extracted() const { return true; }
protected:
RepositoryManifest m_data;
std::string m_uuid;
@ -114,7 +116,8 @@ private:
class LocalArchiveRepository : public ArchiveRepository
{
public:
LocalArchiveRepository(const std::string& uuid, RepositoryManifest&& data) : ArchiveRepository(uuid, std::move(data)) {}
LocalArchiveRepository(const std::string& uuid, RepositoryManifest&& data, bool extracted) : ArchiveRepository(uuid, std::move(data)), m_extracted(extracted)
{}
// Gets vendor_indices.zip to target_path.
bool get_archive(const boost::filesystem::path& target_path) const override;
// Gets file if repository_id arg matches m_id.
@ -123,8 +126,11 @@ public:
// Gets file without checking id.
// Should be used only if no previous ini file exists.
bool get_ini_no_id(const std::string& source_subpath, const boost::filesystem::path& target_path) const override;
bool is_extracted() const override { return m_extracted; }
private:
bool get_file_inner(const boost::filesystem::path& source_path, const boost::filesystem::path& target_path) const;
bool m_extracted;
};
typedef std::vector<std::unique_ptr<const ArchiveRepository>> PrivateArchiveRepositoryVector;