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);
// Extracting progressbar.
void DrawProgressBarExtract(u64 currentProgress, u64 totalProgress, int mode);
// Installing progressbar.
void DrawProgressBarInstall(u64 currentProgress, u64 totalProgress, int mode);
// Draw Button.
void Button(int x, int y, float speed = .030);
}
@@ -1,4 +1,5 @@
#pragma once
#ifndef CIA_HPP
#define CIA_HPP
#include "common.hpp"
@@ -7,3 +8,5 @@
Result CIA_LaunchTitle(u64 titleId, FS_MediaType mediaType);
Result deletePrevious(u64 titleid, FS_MediaType media);
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) {
if (mode == 1) {
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] = "";
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.
extern u64 extractSize;
extern u64 writeOffset;
extern u64 extractSize, writeOffset;
// That are our install Progressbar variables.
extern u64 installSize, installOffset;
#define TIME_IN_US 1
#define TIMETYPE curl_off_t
@@ -856,52 +857,38 @@ void displayProgressBar() {
downloadTotal = downloadNow;
}
if (progressBarType) {
snprintf(str, sizeof(str), "%i %s",
filesExtracted,
(filesExtracted == 1 ? (Lang::get("FILE_EXTRACTED")).c_str() :(Lang::get("FILES_EXTRACTED")).c_str())
);
} else {
// Downloading.
if (progressBarType == 0){
snprintf(str, sizeof(str), "%s / %s (%.2f%%)",
formatBytes(downloadNow).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();
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
C2D_TargetClear(Top, BLACK);
C2D_TargetClear(Bottom, BLACK);
GFX::DrawTop();
// Display this by all.
if (isScriptSelected == true) {
Gui::DrawStringCentered(0, 1, 0.7f, TextColor, progressBarMsg, 400);
} else {
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.
if (progressBarType == 0) {
if (isScriptSelected == true) {
@@ -917,6 +904,44 @@ void displayProgressBar() {
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();
C3D_FrameEnd(0);
gspWaitForVBlank();
+19 -14
View File
@@ -1,4 +1,4 @@
#include "cia.h"
#include "cia.hpp"
bool updatingSelf = false;
@@ -31,7 +31,7 @@ Result deletePrevious(u64 titleid, FS_MediaType media)
}
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);
if (R_FAILED(ret)) {
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;
}
// Variables.
u64 installSize = 0, installOffset = 0;
Result installCia(const char * ciaPath)
{
u64 size = 0;
u32 bytes;
Handle ciaHandle;
Handle fileHandle;
u32 bytes_read = 0, bytes_written;
installSize = 0, installOffset = 0; u64 size = 0;
Handle ciaHandle, fileHandle;
AM_TitleEntry info;
Result ret = 0;
FS_MediaType media = MEDIATYPE_SD;
ret = openFile(&fileHandle, ciaPath, false);
@@ -110,14 +110,19 @@ Result installCia(const char * ciaPath)
return ret;
}
u32 toRead = 0x20000;
u8 * cia_buffer = memalign(0x1000, toRead);
for (u64 startSize = size; size != 0; size -= toRead) {
if (size < toRead) toRead = size;
FSFILE_Read(fileHandle, &bytes, startSize-size, cia_buffer, toRead);
FSFILE_Write(ciaHandle, &bytes, startSize-size, cia_buffer, toRead, 0);
u32 toRead = 0x200000;
u8 *buf = new u8[toRead];
if(buf == nullptr) {
return -1;
}
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);
if (R_FAILED(ret)) {
+1 -2
View File
@@ -35,8 +35,7 @@ int filesExtracted = 0;
std::string extractingFile = "";
// That are our File Progressbar variable.
u64 extractSize = 0;
u64 writeOffset = 0;
u64 extractSize = 0, writeOffset = 0;
Result extractArchive(std::string archivePath, std::string wantedFile, std::string outputPath) {
extractSize = 0, writeOffset = 0, filesExtracted = 0;
+7 -6
View File
@@ -24,6 +24,7 @@
* reasonable ways as different from the original version.
*/
#include "cia.hpp"
#include "download.hpp"
#include "extract.hpp"
#include "fileBrowse.hpp"
@@ -35,12 +36,8 @@
#include <fstream>
#include <unistd.h>
extern "C" {
#include "cia.h"
}
extern bool showProgressBar;
extern bool progressBarType;
extern int progressBarType;
extern char progressBarMsg[128];
extern int filesExtracted;
@@ -110,8 +107,12 @@ Result ScriptHelper::removeFile(std::string file, std::string message) {
// Install a file.
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());
showProgressBar = false;
}
// Extract Files.