mirror of
https://github.com/DarkStore-3DS/DarkStore.git
synced 2026-07-05 16:49:10 +00:00
Make extract progress be of the full file
This commit is contained in:
@@ -39,6 +39,8 @@ enum ExtractError {
|
|||||||
EXTRACT_ERROR_WRITEFILE,
|
EXTRACT_ERROR_WRITEFILE,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Result getExtractedSize(const std::string &archivePath, const std::string &wantedFile);
|
||||||
|
|
||||||
Result extractArchive(const std::string &archivePath, const std::string &wantedFile, const std::string &outputPath);
|
Result extractArchive(const std::string &archivePath, const std::string &wantedFile, const std::string &outputPath);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -68,7 +68,7 @@ static bool killThread = false;
|
|||||||
static bool writeError = false;
|
static bool writeError = false;
|
||||||
#define FILE_ALLOC_SIZE 0x60000
|
#define FILE_ALLOC_SIZE 0x60000
|
||||||
|
|
||||||
extern int filesExtracted;
|
extern int filesExtracted, extractFilesCount;
|
||||||
extern std::string extractingFile;
|
extern std::string extractingFile;
|
||||||
char progressBarMsg[128] = "";
|
char progressBarMsg[128] = "";
|
||||||
bool showProgressBar = false;
|
bool showProgressBar = false;
|
||||||
@@ -477,7 +477,7 @@ void displayProgressBar() {
|
|||||||
|
|
||||||
case ProgressBar::Extracting:
|
case ProgressBar::Extracting:
|
||||||
Gui::DrawStringCentered(0, 180, 0.6f, TEXT_COLOR, str, 400);
|
Gui::DrawStringCentered(0, 180, 0.6f, TEXT_COLOR, str, 400);
|
||||||
Gui::DrawStringCentered(0, 100, 0.6f, TEXT_COLOR, std::to_string(filesExtracted) + " " + (filesExtracted == 1 ? (Lang::get("FILE_EXTRACTED")).c_str() :(Lang::get("FILES_EXTRACTED"))), 400);
|
Gui::DrawStringCentered(0, 100, 0.6f, TEXT_COLOR, std::to_string(filesExtracted) + " / " + std::to_string(extractFilesCount) + " " + (filesExtracted == 1 ? (Lang::get("FILE_EXTRACTED")).c_str() :(Lang::get("FILES_EXTRACTED"))), 400);
|
||||||
Gui::DrawStringCentered(0, 40, 0.6f, TEXT_COLOR, Lang::get("CURRENTLY_EXTRACTING") + "\n" + extractingFile, 400);
|
Gui::DrawStringCentered(0, 40, 0.6f, TEXT_COLOR, Lang::get("CURRENTLY_EXTRACTING") + "\n" + extractingFile, 400);
|
||||||
Animation::DrawProgressBar(writeOffset, extractSize);
|
Animation::DrawProgressBar(writeOffset, extractSize);
|
||||||
break;
|
break;
|
||||||
|
|||||||
+26
-10
@@ -30,24 +30,42 @@
|
|||||||
#include <archive_entry.h>
|
#include <archive_entry.h>
|
||||||
#include <regex>
|
#include <regex>
|
||||||
|
|
||||||
int filesExtracted = 0;
|
int filesExtracted = 0, extractFilesCount = 0;
|
||||||
std::string extractingFile = "";
|
std::string extractingFile = "";
|
||||||
|
|
||||||
/* That are our File Progressbar variable. */
|
/* That are our File Progressbar variable. */
|
||||||
u64 extractSize = 0, writeOffset = 0;
|
u64 extractSize = 0, writeOffset = 0;
|
||||||
|
|
||||||
Result extractArchive(const std::string &archivePath, const std::string &wantedFile, const std::string &outputPath) {
|
Result getExtractedSize(const std::string &archivePath, const std::string &wantedFile) {
|
||||||
extractSize = 0, writeOffset = 0, filesExtracted = 0;
|
extractSize = 0, writeOffset = 0, filesExtracted = 0;
|
||||||
|
|
||||||
archive *a = archive_read_new();
|
archive *a = archive_read_new();
|
||||||
archive_entry *entry;
|
archive_entry *entry;
|
||||||
int flags;
|
|
||||||
|
|
||||||
/* Select which attributes we want to restore. */
|
archive_read_support_format_all(a);
|
||||||
flags = ARCHIVE_EXTRACT_TIME;
|
|
||||||
flags |= ARCHIVE_EXTRACT_PERM;
|
if (archive_read_open_filename(a, archivePath.c_str(), 0x4000) != ARCHIVE_OK) return EXTRACT_ERROR_OPENFILE;
|
||||||
flags |= ARCHIVE_EXTRACT_ACL;
|
|
||||||
flags |= ARCHIVE_EXTRACT_FFLAGS;
|
while(archive_read_next_header(a, &entry) == ARCHIVE_OK) {
|
||||||
|
int size = archive_entry_size(entry);
|
||||||
|
if (size > 0) { /* Ignore folders. */
|
||||||
|
std::smatch match;
|
||||||
|
std::string entryName();
|
||||||
|
if (std::regex_search(entryName, match, std::regex(wantedFile))) {
|
||||||
|
extractSize += size;
|
||||||
|
extractFilesCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
archive_read_close(a);
|
||||||
|
archive_read_free(a);
|
||||||
|
return EXTRACT_ERROR_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
Result extractArchive(const std::string &archivePath, const std::string &wantedFile, const std::string &outputPath) {
|
||||||
|
archive *a = archive_read_new();
|
||||||
|
archive_entry *entry;
|
||||||
|
|
||||||
a = archive_read_new();
|
a = archive_read_new();
|
||||||
archive_read_support_format_all(a);
|
archive_read_support_format_all(a);
|
||||||
@@ -69,8 +87,6 @@ Result extractArchive(const std::string &archivePath, const std::string &wantedF
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint sizeLeft = archive_entry_size(entry);
|
uint sizeLeft = archive_entry_size(entry);
|
||||||
extractSize = sizeLeft;
|
|
||||||
writeOffset = 0;
|
|
||||||
|
|
||||||
FILE *file = fopen(extractingFile.c_str(), "wb");
|
FILE *file = fopen(extractingFile.c_str(), "wb");
|
||||||
if (!file) return EXTRACT_ERROR_WRITEFILE;
|
if (!file) return EXTRACT_ERROR_WRITEFILE;
|
||||||
|
|||||||
@@ -219,6 +219,7 @@ void ScriptUtils::extractFile(const std::string &file, const std::string &input,
|
|||||||
svcGetThreadPriority(&prio, CUR_THREAD_HANDLE);
|
svcGetThreadPriority(&prio, CUR_THREAD_HANDLE);
|
||||||
thread = threadCreate((ThreadFunc)displayProgressBar, NULL, 64 * 1024, prio - 1, -2, false);
|
thread = threadCreate((ThreadFunc)displayProgressBar, NULL, 64 * 1024, prio - 1, -2, false);
|
||||||
|
|
||||||
|
getExtractedSize(in, input);
|
||||||
extractArchive(in, input, out);
|
extractArchive(in, input, out);
|
||||||
showProgressBar = false;
|
showProgressBar = false;
|
||||||
threadJoin(thread, U64_MAX);
|
threadJoin(thread, U64_MAX);
|
||||||
|
|||||||
Reference in New Issue
Block a user