Display Percentage on Installing & Extracting.

Also add progressbar for Installing & convert `cia.c` to `cia.cpp` for `new`.
This commit is contained in:
StackZ
2020-04-28 14:35:42 +02:00
parent 59dda01f00
commit 7d8fb7eb5d
7 changed files with 231 additions and 188 deletions
+2
View File
@@ -35,6 +35,8 @@ namespace Animation {
void DrawProgressBar(float currentProgress, float totalProgress, int mode); void DrawProgressBar(float currentProgress, float totalProgress, int mode);
// Extracting progressbar. // Extracting progressbar.
void DrawProgressBarExtract(u64 currentProgress, u64 totalProgress, int mode); void DrawProgressBarExtract(u64 currentProgress, u64 totalProgress, int mode);
// Installing progressbar.
void DrawProgressBarInstall(u64 currentProgress, u64 totalProgress, int mode);
// Draw Button. // Draw Button.
void Button(int x, int y, float speed = .030); void Button(int x, int y, float speed = .030);
} }
@@ -1,4 +1,5 @@
#pragma once #ifndef CIA_HPP
#define CIA_HPP
#include "common.hpp" #include "common.hpp"
@@ -7,3 +8,5 @@
Result CIA_LaunchTitle(u64 titleId, FS_MediaType mediaType); Result CIA_LaunchTitle(u64 titleId, FS_MediaType mediaType);
Result deletePrevious(u64 titleid, FS_MediaType media); Result deletePrevious(u64 titleid, FS_MediaType media);
Result installCia(const char * ciaPath); Result installCia(const char * ciaPath);
#endif
+8
View File
@@ -41,6 +41,14 @@ void Animation::DrawProgressBar(float currentProgress, float totalProgress, int
} }
} }
void Animation::DrawProgressBarInstall(u64 currentProgress, u64 totalProgress, int mode) {
if (mode == 1) {
Gui::Draw_Rect(31, 121, (int)(((float)currentProgress / (float)totalProgress) * 338.0f), 28, progressBar);
} else {
Gui::Draw_Rect(31, 121, (int)(((float)currentProgress / (float)totalProgress) * 338.0f), 28, Config::progressbarColor);
}
}
void Animation::DrawProgressBarExtract(u64 currentProgress, u64 totalProgress, int mode) { void Animation::DrawProgressBarExtract(u64 currentProgress, u64 totalProgress, int mode) {
if (mode == 1) { if (mode == 1) {
Gui::Draw_Rect(31, 141, (int)(((float)currentProgress / (float)totalProgress) * 338.0f), 28, progressBar); Gui::Draw_Rect(31, 141, (int)(((float)currentProgress / (float)totalProgress) * 338.0f), 28, progressBar);
+59 -34
View File
@@ -50,11 +50,12 @@ extern std::string extractingFile;
char progressBarMsg[128] = ""; char progressBarMsg[128] = "";
bool showProgressBar = false; bool showProgressBar = false;
bool progressBarType = 0; // 0 = Download | 1 = Extract int progressBarType = 0; // 0 = Download | 1 = Extract | 2 = Install
// That are our extract Progressbar variables. // That are our extract Progressbar variables.
extern u64 extractSize; extern u64 extractSize, writeOffset;
extern u64 writeOffset; // That are our install Progressbar variables.
extern u64 installSize, installOffset;
#define TIME_IN_US 1 #define TIME_IN_US 1
#define TIMETYPE curl_off_t #define TIMETYPE curl_off_t
@@ -856,52 +857,38 @@ void displayProgressBar() {
downloadTotal = downloadNow; downloadTotal = downloadNow;
} }
if (progressBarType) { // Downloading.
snprintf(str, sizeof(str), "%i %s", if (progressBarType == 0){
filesExtracted,
(filesExtracted == 1 ? (Lang::get("FILE_EXTRACTED")).c_str() :(Lang::get("FILES_EXTRACTED")).c_str())
);
} else {
snprintf(str, sizeof(str), "%s / %s (%.2f%%)", snprintf(str, sizeof(str), "%s / %s (%.2f%%)",
formatBytes(downloadNow).c_str(), formatBytes(downloadNow).c_str(),
formatBytes(downloadTotal).c_str(), formatBytes(downloadTotal).c_str(),
((float)downloadNow/(float)downloadTotal) * 100.0f ((float)downloadNow/(float)downloadTotal) * 100.0f);
); // Extracting.
} } else if (progressBarType == 1) {
snprintf(str, sizeof(str), "%s / %s (%.2f%%)",
formatBytes(writeOffset).c_str(),
formatBytes(extractSize).c_str(),
((float)writeOffset/(float)extractSize) * 100.0f);
// Installing.
} else if (progressBarType == 2){
snprintf(str, sizeof(str), "%s / %s (%.2f%%)",
formatBytes(installOffset).c_str(),
formatBytes(installSize).c_str(),
((float)installOffset/(float)installSize) * 100.0f);
};
Gui::clearTextBufs(); Gui::clearTextBufs();
C3D_FrameBegin(C3D_FRAME_SYNCDRAW); C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
C2D_TargetClear(Top, BLACK); C2D_TargetClear(Top, BLACK);
C2D_TargetClear(Bottom, BLACK); C2D_TargetClear(Bottom, BLACK);
GFX::DrawTop(); GFX::DrawTop();
// Display this by all.
if (isScriptSelected == true) { if (isScriptSelected == true) {
Gui::DrawStringCentered(0, 1, 0.7f, TextColor, progressBarMsg, 400); Gui::DrawStringCentered(0, 1, 0.7f, TextColor, progressBarMsg, 400);
} else { } else {
Gui::DrawStringCentered(0, 1, 0.7f, Config::TxtColor, progressBarMsg, 400); Gui::DrawStringCentered(0, 1, 0.7f, Config::TxtColor, progressBarMsg, 400);
} }
// Display 'Currently Extracting: <Filename>'.
if (progressBarType == 1) {
// Text.
if (isScriptSelected == true) {
Gui::DrawStringCentered(0, 100, 0.6f, TextColor, str, 400);
Gui::DrawStringCentered(0, 180, 0.6f, TextColor, formatBytes(writeOffset) + " / " + formatBytes(extractSize), 400);
Gui::DrawStringCentered(0, 40, 0.6f, TextColor, Lang::get("CURRENTLY_EXTRACTING") + "\n" + extractingFile, 400);
} else {
Gui::DrawStringCentered(0, 100, 0.6f, Config::TxtColor, str, 400);
Gui::DrawStringCentered(0, 180, 0.6f, Config::TxtColor, formatBytes(writeOffset) + " / " + formatBytes(extractSize), 400);
Gui::DrawStringCentered(0, 40, 0.6f, Config::TxtColor, Lang::get("CURRENTLY_EXTRACTING") + "\n" + extractingFile, 400);
}
// Outline of progressbar.
Gui::Draw_Rect(30, 140, 340, 30, BLACK);
// Progressbar.
if (isScriptSelected == true) {
Animation::DrawProgressBarExtract(writeOffset, extractSize, 1);
} else {
Animation::DrawProgressBarExtract(writeOffset, extractSize, 2);
}
}
// Only display this by downloading. // Only display this by downloading.
if (progressBarType == 0) { if (progressBarType == 0) {
if (isScriptSelected == true) { if (isScriptSelected == true) {
@@ -917,6 +904,44 @@ void displayProgressBar() {
Animation::DrawProgressBar(downloadNow, downloadTotal, 2); Animation::DrawProgressBar(downloadNow, downloadTotal, 2);
} }
} }
// Only Display this by extracting.
if (progressBarType == 1) {
// Text.
if (isScriptSelected == true) {
Gui::DrawStringCentered(0, 180, 0.6f, TextColor, str, 400);
Gui::DrawStringCentered(0, 100, 0.6f, TextColor, std::to_string(filesExtracted) + " " + (filesExtracted == 1 ? (Lang::get("FILE_EXTRACTED")).c_str() :(Lang::get("FILES_EXTRACTED"))), 400);
Gui::DrawStringCentered(0, 40, 0.6f, TextColor, Lang::get("CURRENTLY_EXTRACTING") + "\n" + extractingFile, 400);
} else {
Gui::DrawStringCentered(0, 180, 0.6f, Config::TxtColor, str, 400);
Gui::DrawStringCentered(0, 100, 0.6f, Config::TxtColor, std::to_string(filesExtracted) + " " + (filesExtracted == 1 ? (Lang::get("FILE_EXTRACTED")).c_str() :(Lang::get("FILES_EXTRACTED"))), 400);
Gui::DrawStringCentered(0, 40, 0.6f, Config::TxtColor, Lang::get("CURRENTLY_EXTRACTING") + "\n" + extractingFile, 400);
}
// Outline of progressbar.
Gui::Draw_Rect(30, 140, 340, 30, BLACK);
// Progressbar.
if (isScriptSelected == true) {
Animation::DrawProgressBarExtract(writeOffset, extractSize, 1);
} else {
Animation::DrawProgressBarExtract(writeOffset, extractSize, 2);
}
}
// Only display this by installing.
if (progressBarType == 2) {
if (isScriptSelected == true) {
Gui::DrawStringCentered(0, 80, 0.6f, TextColor, str, 400);
} else {
Gui::DrawStringCentered(0, 80, 0.6f, Config::TxtColor, str, 400);
}
// Outline of progressbar.
Gui::Draw_Rect(30, 120, 340, 30, BLACK);
if (isScriptSelected == true) {
Animation::DrawProgressBarInstall(installOffset, installSize, 1);
} else {
Animation::DrawProgressBarInstall(installOffset, installSize, 2);
}
}
GFX::DrawBottom(); GFX::DrawBottom();
C3D_FrameEnd(0); C3D_FrameEnd(0);
gspWaitForVBlank(); gspWaitForVBlank();
+19 -14
View File
@@ -1,4 +1,4 @@
#include "cia.h" #include "cia.hpp"
bool updatingSelf = false; bool updatingSelf = false;
@@ -31,7 +31,7 @@ Result deletePrevious(u64 titleid, FS_MediaType media)
} }
u32 read_titles = 0; u32 read_titles = 0;
u64 * titleIDs = malloc(titles_amount * sizeof(u64)); u64 * titleIDs = (u64*)malloc(titles_amount * sizeof(u64));
ret = AM_GetTitleList(&read_titles, media, titles_amount, titleIDs); ret = AM_GetTitleList(&read_titles, media, titles_amount, titleIDs);
if (R_FAILED(ret)) { if (R_FAILED(ret)) {
free(titleIDs); free(titleIDs);
@@ -64,16 +64,16 @@ FS_MediaType getTitleDestination(u64 titleId) {
return platform == 0x0003 || (platform == 0x0004 && ((category & 0x8011) != 0 || (category == 0x0000 && variation == 0x02))) ? MEDIATYPE_NAND : MEDIATYPE_SD; return platform == 0x0003 || (platform == 0x0004 && ((category & 0x8011) != 0 || (category == 0x0000 && variation == 0x02))) ? MEDIATYPE_NAND : MEDIATYPE_SD;
} }
// Variables.
u64 installSize = 0, installOffset = 0;
Result installCia(const char * ciaPath) Result installCia(const char * ciaPath)
{ {
u64 size = 0; u32 bytes_read = 0, bytes_written;
u32 bytes; installSize = 0, installOffset = 0; u64 size = 0;
Handle ciaHandle; Handle ciaHandle, fileHandle;
Handle fileHandle;
AM_TitleEntry info; AM_TitleEntry info;
Result ret = 0; Result ret = 0;
FS_MediaType media = MEDIATYPE_SD; FS_MediaType media = MEDIATYPE_SD;
ret = openFile(&fileHandle, ciaPath, false); ret = openFile(&fileHandle, ciaPath, false);
@@ -110,14 +110,19 @@ Result installCia(const char * ciaPath)
return ret; return ret;
} }
u32 toRead = 0x20000; u32 toRead = 0x200000;
u8 * cia_buffer = memalign(0x1000, toRead); u8 *buf = new u8[toRead];
for (u64 startSize = size; size != 0; size -= toRead) { if(buf == nullptr) {
if (size < toRead) toRead = size; return -1;
FSFILE_Read(fileHandle, &bytes, startSize-size, cia_buffer, toRead);
FSFILE_Write(ciaHandle, &bytes, startSize-size, cia_buffer, toRead, 0);
} }
free(cia_buffer);
installSize = size;
do {
FSFILE_Read(fileHandle, &bytes_read, installOffset, buf, toRead);
FSFILE_Write(ciaHandle, &bytes_written, installOffset, buf, toRead, FS_WRITE_FLUSH);
installOffset += bytes_read;
} while(installOffset < installSize);
delete[] buf;
ret = AM_FinishCiaInstall(ciaHandle); ret = AM_FinishCiaInstall(ciaHandle);
if (R_FAILED(ret)) { if (R_FAILED(ret)) {
+1 -2
View File
@@ -35,8 +35,7 @@ int filesExtracted = 0;
std::string extractingFile = ""; std::string extractingFile = "";
// That are our File Progressbar variable. // That are our File Progressbar variable.
u64 extractSize = 0; u64 extractSize = 0, writeOffset = 0;
u64 writeOffset = 0;
Result extractArchive(std::string archivePath, std::string wantedFile, std::string outputPath) { Result extractArchive(std::string archivePath, std::string wantedFile, std::string outputPath) {
extractSize = 0, writeOffset = 0, filesExtracted = 0; extractSize = 0, writeOffset = 0, filesExtracted = 0;
+7 -6
View File
@@ -24,6 +24,7 @@
* reasonable ways as different from the original version. * reasonable ways as different from the original version.
*/ */
#include "cia.hpp"
#include "download.hpp" #include "download.hpp"
#include "extract.hpp" #include "extract.hpp"
#include "fileBrowse.hpp" #include "fileBrowse.hpp"
@@ -35,12 +36,8 @@
#include <fstream> #include <fstream>
#include <unistd.h> #include <unistd.h>
extern "C" {
#include "cia.h"
}
extern bool showProgressBar; extern bool showProgressBar;
extern bool progressBarType; extern int progressBarType;
extern char progressBarMsg[128]; extern char progressBarMsg[128];
extern int filesExtracted; extern int filesExtracted;
@@ -110,8 +107,12 @@ Result ScriptHelper::removeFile(std::string file, std::string message) {
// Install a file. // Install a file.
void ScriptHelper::installFile(std::string file, std::string message) { void ScriptHelper::installFile(std::string file, std::string message) {
Msg::DisplayMsg(message); snprintf(progressBarMsg, sizeof(progressBarMsg), message.c_str());
showProgressBar = true;
progressBarType = 2;
Threads::create((ThreadFunc)displayProgressBar);
installCia(file.c_str()); installCia(file.c_str());
showProgressBar = false;
} }
// Extract Files. // Extract Files.