mirror of
https://github.com/Dark98/threeSD.git
synced 2026-07-05 00:38:49 +00:00
Rework failed task cleanup
Now the cleanup of failed tasks (deletion of borked files) is handled by the related task itself, instead of the frontend.
This commit is contained in:
+26
-8
@@ -94,6 +94,15 @@ void SDMCImporter::AbortImporting() {
|
|||||||
|
|
||||||
bool SDMCImporter::ImportContent(const ContentSpecifier& specifier,
|
bool SDMCImporter::ImportContent(const ContentSpecifier& specifier,
|
||||||
const Common::ProgressCallback& callback) {
|
const Common::ProgressCallback& callback) {
|
||||||
|
if (!ImportContentImpl(specifier, callback)) {
|
||||||
|
DeleteContent(specifier);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SDMCImporter::ImportContentImpl(const ContentSpecifier& specifier,
|
||||||
|
const Common::ProgressCallback& callback) {
|
||||||
switch (specifier.type) {
|
switch (specifier.type) {
|
||||||
case ContentType::Application:
|
case ContentType::Application:
|
||||||
case ContentType::Update:
|
case ContentType::Update:
|
||||||
@@ -623,8 +632,13 @@ bool SDMCImporter::DumpCXI(const ContentSpecifier& specifier, std::string destin
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return dump_cxi_ncch->DecryptToFile(std::make_shared<FileUtil::IOFile>(destination, "wb"),
|
if (dump_cxi_ncch->DecryptToFile(std::make_shared<FileUtil::IOFile>(destination, "wb"),
|
||||||
callback) == ResultStatus::Success;
|
callback) == ResultStatus::Success) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
FileUtil::Delete(destination);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SDMCImporter::AbortDumpCXI() {
|
void SDMCImporter::AbortDumpCXI() {
|
||||||
@@ -675,9 +689,10 @@ bool SDMCImporter::BuildCIA(const ContentSpecifier& specifier, std::string desti
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ret = cia_builder->Init(destination, tmd, config,
|
const bool ret = cia_builder->Init(destination, tmd, config,
|
||||||
FileUtil::GetDirectoryTreeSize(physical_path), callback);
|
FileUtil::GetDirectoryTreeSize(physical_path), callback);
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
|
FileUtil::Delete(destination);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -721,11 +736,14 @@ bool SDMCImporter::BuildCIA(const ContentSpecifier& specifier, std::string desti
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!FileUtil::ForeachDirectoryEntry(nullptr, physical_path, DirectoryEntryCallback)) {
|
if (FileUtil::ForeachDirectoryEntry(nullptr, physical_path, DirectoryEntryCallback) &&
|
||||||
return false;
|
cia_builder->Finalize()) {
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return cia_builder->Finalize();
|
FileUtil::Delete(destination);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SDMCImporter::AbortBuildCIA() {
|
void SDMCImporter::AbortBuildCIA() {
|
||||||
@@ -1055,7 +1073,7 @@ void SDMCImporter::ListSysdata(std::vector<ContentSpecifier>& out) const {
|
|||||||
{ContentType::Sysdata, 2, exists, FileUtil::GetSize(config.seed_db_path), SEED_DB});
|
{ContentType::Sysdata, 2, exists, FileUtil::GetSize(config.seed_db_path), SEED_DB});
|
||||||
}
|
}
|
||||||
|
|
||||||
void SDMCImporter::DeleteContent(const ContentSpecifier& specifier) {
|
void SDMCImporter::DeleteContent(const ContentSpecifier& specifier) const {
|
||||||
switch (specifier.type) {
|
switch (specifier.type) {
|
||||||
case ContentType::Application:
|
case ContentType::Application:
|
||||||
case ContentType::Update:
|
case ContentType::Update:
|
||||||
|
|||||||
+6
-7
@@ -112,7 +112,7 @@ public:
|
|||||||
~SDMCImporter();
|
~SDMCImporter();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Imports a specific content by its specifier.
|
* Imports a specific content by its specifier, deleting it when failed.
|
||||||
* Blocks, but can be aborted on another thread if needed.
|
* Blocks, but can be aborted on another thread if needed.
|
||||||
* @return true on success, false otherwise
|
* @return true on success, false otherwise
|
||||||
*/
|
*/
|
||||||
@@ -151,12 +151,6 @@ public:
|
|||||||
*/
|
*/
|
||||||
void AbortBuildCIA();
|
void AbortBuildCIA();
|
||||||
|
|
||||||
/**
|
|
||||||
* Deletes/Cleans up a content. Used for deleting contents that have
|
|
||||||
* not been fully imported.
|
|
||||||
*/
|
|
||||||
void DeleteContent(const ContentSpecifier& specifier);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a list of dumpable content specifiers.
|
* Gets a list of dumpable content specifiers.
|
||||||
*/
|
*/
|
||||||
@@ -170,6 +164,10 @@ public:
|
|||||||
private:
|
private:
|
||||||
bool Init();
|
bool Init();
|
||||||
|
|
||||||
|
// Impl of ImportContent without deleting mechanism.
|
||||||
|
bool ImportContentImpl(
|
||||||
|
const ContentSpecifier& specifier,
|
||||||
|
const Common::ProgressCallback& callback = [](std::size_t, std::size_t) {});
|
||||||
bool ImportTitle(const ContentSpecifier& specifier, const Common::ProgressCallback& callback);
|
bool ImportTitle(const ContentSpecifier& specifier, const Common::ProgressCallback& callback);
|
||||||
bool ImportNandTitle(const ContentSpecifier& specifier,
|
bool ImportNandTitle(const ContentSpecifier& specifier,
|
||||||
const Common::ProgressCallback& callback);
|
const Common::ProgressCallback& callback);
|
||||||
@@ -187,6 +185,7 @@ private:
|
|||||||
void ListSystemArchive(std::vector<ContentSpecifier>& out) const;
|
void ListSystemArchive(std::vector<ContentSpecifier>& out) const;
|
||||||
void ListSysdata(std::vector<ContentSpecifier>& out) const;
|
void ListSysdata(std::vector<ContentSpecifier>& out) const;
|
||||||
|
|
||||||
|
void DeleteContent(const ContentSpecifier& specifier) const;
|
||||||
void DeleteTitle(u64 id) const;
|
void DeleteTitle(u64 id) const;
|
||||||
void DeleteNandTitle(u64 id) const;
|
void DeleteNandTitle(u64 id) const;
|
||||||
void DeleteSavegame(u64 id) const;
|
void DeleteSavegame(u64 id) const;
|
||||||
|
|||||||
@@ -7,10 +7,9 @@
|
|||||||
|
|
||||||
MultiJob::MultiJob(QObject* parent, Core::SDMCImporter& importer_,
|
MultiJob::MultiJob(QObject* parent, Core::SDMCImporter& importer_,
|
||||||
std::vector<Core::ContentSpecifier> contents_, ExecuteFunc execute_func_,
|
std::vector<Core::ContentSpecifier> contents_, ExecuteFunc execute_func_,
|
||||||
DeleteFunc delete_func_, AbortFunc abort_func_)
|
AbortFunc abort_func_)
|
||||||
: QThread(parent), importer(importer_), contents(std::move(contents_)),
|
: QThread(parent), importer(importer_), contents(std::move(contents_)),
|
||||||
execute_func(std::move(execute_func_)), delete_func(std::move(delete_func_)),
|
execute_func(std::move(execute_func_)), abort_func(abort_func_) {}
|
||||||
abort_func(abort_func_) {}
|
|
||||||
|
|
||||||
MultiJob::~MultiJob() = default;
|
MultiJob::~MultiJob() = default;
|
||||||
|
|
||||||
@@ -42,8 +41,6 @@ void MultiJob::run() {
|
|||||||
emit ProgressUpdated(size_imported + current_size, current_size, eta);
|
emit ProgressUpdated(size_imported + current_size, current_size, eta);
|
||||||
};
|
};
|
||||||
if (!execute_func(importer, content, callback)) {
|
if (!execute_func(importer, content, callback)) {
|
||||||
delete_func(importer, content);
|
|
||||||
importer.DeleteContent(content);
|
|
||||||
if (!cancelled) {
|
if (!cancelled) {
|
||||||
failed_contents.emplace_back(content);
|
failed_contents.emplace_back(content);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,12 +16,11 @@ class MultiJob : public QThread {
|
|||||||
public:
|
public:
|
||||||
using ExecuteFunc = std::function<bool(Core::SDMCImporter&, const Core::ContentSpecifier&,
|
using ExecuteFunc = std::function<bool(Core::SDMCImporter&, const Core::ContentSpecifier&,
|
||||||
const Common::ProgressCallback&)>;
|
const Common::ProgressCallback&)>;
|
||||||
using DeleteFunc = std::function<void(Core::SDMCImporter&, const Core::ContentSpecifier&)>;
|
|
||||||
using AbortFunc = std::function<void(Core::SDMCImporter&)>;
|
using AbortFunc = std::function<void(Core::SDMCImporter&)>;
|
||||||
|
|
||||||
explicit MultiJob(QObject* parent, Core::SDMCImporter& importer,
|
explicit MultiJob(QObject* parent, Core::SDMCImporter& importer,
|
||||||
std::vector<Core::ContentSpecifier> contents, ExecuteFunc execute_func,
|
std::vector<Core::ContentSpecifier> contents, ExecuteFunc execute_func,
|
||||||
DeleteFunc delete_func, AbortFunc abort_func);
|
AbortFunc abort_func);
|
||||||
~MultiJob() override;
|
~MultiJob() override;
|
||||||
|
|
||||||
void run() override;
|
void run() override;
|
||||||
@@ -50,7 +49,6 @@ private:
|
|||||||
std::vector<Core::ContentSpecifier> contents;
|
std::vector<Core::ContentSpecifier> contents;
|
||||||
std::vector<Core::ContentSpecifier> failed_contents;
|
std::vector<Core::ContentSpecifier> failed_contents;
|
||||||
ExecuteFunc execute_func;
|
ExecuteFunc execute_func;
|
||||||
DeleteFunc delete_func;
|
|
||||||
AbortFunc abort_func;
|
AbortFunc abort_func;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -710,7 +710,7 @@ void ImportDialog::StartImporting() {
|
|||||||
|
|
||||||
auto* job =
|
auto* job =
|
||||||
new MultiJob(this, importer, std::move(to_import), &Core::SDMCImporter::ImportContent,
|
new MultiJob(this, importer, std::move(to_import), &Core::SDMCImporter::ImportContent,
|
||||||
&Core::SDMCImporter::DeleteContent, &Core::SDMCImporter::AbortImporting);
|
&Core::SDMCImporter::AbortImporting);
|
||||||
|
|
||||||
RunMultiJob(job, total_count, total_selected_size);
|
RunMultiJob(job, total_count, total_selected_size);
|
||||||
}
|
}
|
||||||
@@ -728,11 +728,7 @@ void ImportDialog::StartDumpingCXISingle(const Core::ContentSpecifier& specifier
|
|||||||
auto* job = new SimpleJob(
|
auto* job = new SimpleJob(
|
||||||
this,
|
this,
|
||||||
[this, specifier, path](const Common::ProgressCallback& callback) {
|
[this, specifier, path](const Common::ProgressCallback& callback) {
|
||||||
if (!importer.DumpCXI(specifier, path.toStdString(), callback)) {
|
return importer.DumpCXI(specifier, path.toStdString(), callback);
|
||||||
FileUtil::Delete(path.toStdString());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
},
|
},
|
||||||
[this] { importer.AbortDumpCXI(); });
|
[this] { importer.AbortDumpCXI(); });
|
||||||
RunSimpleJob(job);
|
RunSimpleJob(job);
|
||||||
@@ -786,9 +782,6 @@ void ImportDialog::StartBatchDumpingCXI() {
|
|||||||
const Common::ProgressCallback& callback) {
|
const Common::ProgressCallback& callback) {
|
||||||
return importer.DumpCXI(specifier, path.toStdString(), callback, true);
|
return importer.DumpCXI(specifier, path.toStdString(), callback, true);
|
||||||
},
|
},
|
||||||
[path](Core::SDMCImporter& /*importer*/, const Core::ContentSpecifier& specifier) {
|
|
||||||
// TODO: FileUtil::Delete(path.toStdString() + GetCXIFileName(specifier));
|
|
||||||
},
|
|
||||||
&Core::SDMCImporter::AbortDumpCXI);
|
&Core::SDMCImporter::AbortDumpCXI);
|
||||||
RunMultiJob(job, total_count, total_size);
|
RunMultiJob(job, total_count, total_size);
|
||||||
}
|
}
|
||||||
@@ -806,11 +799,7 @@ void ImportDialog::StartBuildingCIASingle(const Core::ContentSpecifier& specifie
|
|||||||
auto* job = new SimpleJob(
|
auto* job = new SimpleJob(
|
||||||
this,
|
this,
|
||||||
[this, specifier, path](const Common::ProgressCallback& callback) {
|
[this, specifier, path](const Common::ProgressCallback& callback) {
|
||||||
if (!importer.BuildCIA(specifier, path.toStdString(), callback)) {
|
return importer.BuildCIA(specifier, path.toStdString(), callback);
|
||||||
FileUtil::Delete(path.toStdString());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
},
|
},
|
||||||
[this] { importer.AbortBuildCIA(); });
|
[this] { importer.AbortBuildCIA(); });
|
||||||
RunSimpleJob(job);
|
RunSimpleJob(job);
|
||||||
@@ -868,9 +857,6 @@ void ImportDialog::StartBatchBuildingCIA() {
|
|||||||
const Common::ProgressCallback& callback) {
|
const Common::ProgressCallback& callback) {
|
||||||
return importer.BuildCIA(specifier, path.toStdString(), callback, true);
|
return importer.BuildCIA(specifier, path.toStdString(), callback, true);
|
||||||
},
|
},
|
||||||
[path](Core::SDMCImporter& /*importer*/, const Core::ContentSpecifier& specifier) {
|
|
||||||
// TODO: FileUtil::Delete(path.toStdString() + GetCIAFileName(specifier));
|
|
||||||
},
|
|
||||||
&Core::SDMCImporter::AbortBuildCIA);
|
&Core::SDMCImporter::AbortBuildCIA);
|
||||||
RunMultiJob(job, total_count, total_size);
|
RunMultiJob(job, total_count, total_size);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user