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);
} }
+12 -9
View File
@@ -1,9 +1,12 @@
#pragma once #ifndef CIA_HPP
#define CIA_HPP
#include "common.hpp"
#include "common.hpp"
#include <3ds.h>
#include <3ds.h>
Result CIA_LaunchTitle(u64 titleId, FS_MediaType mediaType);
Result deletePrevious(u64 titleid, FS_MediaType media); Result CIA_LaunchTitle(u64 titleId, FS_MediaType mediaType);
Result installCia(const char * ciaPath); 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) { 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();
+142 -137
View File
@@ -1,138 +1,143 @@
#include "cia.h" #include "cia.hpp"
bool updatingSelf = false; bool updatingSelf = false;
Result CIA_LaunchTitle(u64 titleId, FS_MediaType mediaType) { Result CIA_LaunchTitle(u64 titleId, FS_MediaType mediaType) {
Result ret = 0; Result ret = 0;
u8 param[0x300]; u8 param[0x300];
u8 hmac[0x20]; u8 hmac[0x20];
if (R_FAILED(ret = APT_PrepareToDoApplicationJump(0, titleId, mediaType))) { if (R_FAILED(ret = APT_PrepareToDoApplicationJump(0, titleId, mediaType))) {
printf("Error In:\nAPT_PrepareToDoApplicationJump"); printf("Error In:\nAPT_PrepareToDoApplicationJump");
return ret; return ret;
} }
if (R_FAILED(ret = APT_DoApplicationJump(param, sizeof(param), hmac))) { if (R_FAILED(ret = APT_DoApplicationJump(param, sizeof(param), hmac))) {
printf("Error In:\nAPT_DoApplicationJump"); printf("Error In:\nAPT_DoApplicationJump");
return ret; return ret;
} }
return 0; return 0;
} }
Result deletePrevious(u64 titleid, FS_MediaType media) Result deletePrevious(u64 titleid, FS_MediaType media)
{ {
Result ret = 0; Result ret = 0;
u32 titles_amount = 0; u32 titles_amount = 0;
ret = AM_GetTitleCount(media, &titles_amount); ret = AM_GetTitleCount(media, &titles_amount);
if (R_FAILED(ret)) { if (R_FAILED(ret)) {
printf("Error in:\nAM_GetTitleCount\n"); printf("Error in:\nAM_GetTitleCount\n");
return ret; return ret;
} }
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);
printf("Error in:\nAM_GetTitleList\n"); printf("Error in:\nAM_GetTitleList\n");
return ret; return ret;
} }
for (u32 i = 0; i < read_titles; i++) { for (u32 i = 0; i < read_titles; i++) {
if (titleIDs[i] == titleid) { if (titleIDs[i] == titleid) {
ret = AM_DeleteAppTitle(media, titleid); ret = AM_DeleteAppTitle(media, titleid);
break; break;
} }
} }
free(titleIDs); free(titleIDs);
if (R_FAILED(ret)) { if (R_FAILED(ret)) {
printf("Error in:\nAM_DeleteAppTitle\n"); printf("Error in:\nAM_DeleteAppTitle\n");
return ret; return ret;
} }
return 0; return 0;
} }
FS_MediaType getTitleDestination(u64 titleId) { FS_MediaType getTitleDestination(u64 titleId) {
u16 platform = (u16) ((titleId >> 48) & 0xFFFF); u16 platform = (u16) ((titleId >> 48) & 0xFFFF);
u16 category = (u16) ((titleId >> 32) & 0xFFFF); u16 category = (u16) ((titleId >> 32) & 0xFFFF);
u8 variation = (u8) (titleId & 0xFF); u8 variation = (u8) (titleId & 0xFF);
// DSiWare 3DS DSiWare, System, DLP Application System Title // DSiWare 3DS DSiWare, System, DLP Application System Title
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.
Result installCia(const char * ciaPath) u64 installSize = 0, installOffset = 0;
{
u64 size = 0; Result installCia(const char * ciaPath)
u32 bytes; {
Handle ciaHandle; u32 bytes_read = 0, bytes_written;
Handle fileHandle; installSize = 0, installOffset = 0; u64 size = 0;
AM_TitleEntry info; Handle ciaHandle, fileHandle;
Result ret = 0; AM_TitleEntry info;
Result ret = 0;
FS_MediaType media = MEDIATYPE_SD; FS_MediaType media = MEDIATYPE_SD;
ret = openFile(&fileHandle, ciaPath, false); ret = openFile(&fileHandle, ciaPath, false);
if (R_FAILED(ret)) { if (R_FAILED(ret)) {
printf("Error in:\nopenFile\n"); printf("Error in:\nopenFile\n");
return ret; return ret;
} }
ret = AM_GetCiaFileInfo(media, &info, fileHandle); ret = AM_GetCiaFileInfo(media, &info, fileHandle);
if (R_FAILED(ret)) { if (R_FAILED(ret)) {
printf("Error in:\nAM_GetCiaFileInfo\n"); printf("Error in:\nAM_GetCiaFileInfo\n");
return ret; return ret;
} }
media = getTitleDestination(info.titleID); media = getTitleDestination(info.titleID);
if (info.titleID == 0x0004000004391700) { if (info.titleID == 0x0004000004391700) {
updatingSelf = true; updatingSelf = true;
} }
if (!updatingSelf) { if (!updatingSelf) {
ret = deletePrevious(info.titleID, media); ret = deletePrevious(info.titleID, media);
if (R_FAILED(ret)) if (R_FAILED(ret))
return ret; return ret;
} }
ret = FSFILE_GetSize(fileHandle, &size); ret = FSFILE_GetSize(fileHandle, &size);
if (R_FAILED(ret)) { if (R_FAILED(ret)) {
printf("Error in:\nFSFILE_GetSize\n"); printf("Error in:\nFSFILE_GetSize\n");
return ret; return ret;
} }
ret = AM_StartCiaInstall(media, &ciaHandle); ret = AM_StartCiaInstall(media, &ciaHandle);
if (R_FAILED(ret)) { if (R_FAILED(ret)) {
printf("Error in:\nAM_StartCiaInstall\n"); printf("Error in:\nAM_StartCiaInstall\n");
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);
} installSize = size;
free(cia_buffer); do {
FSFILE_Read(fileHandle, &bytes_read, installOffset, buf, toRead);
ret = AM_FinishCiaInstall(ciaHandle); FSFILE_Write(ciaHandle, &bytes_written, installOffset, buf, toRead, FS_WRITE_FLUSH);
if (R_FAILED(ret)) { installOffset += bytes_read;
printf("Error in:\nAM_FinishCiaInstall\n"); } while(installOffset < installSize);
return ret; delete[] buf;
}
ret = FSFILE_Close(fileHandle); ret = AM_FinishCiaInstall(ciaHandle);
if (R_FAILED(ret)) { if (R_FAILED(ret)) {
printf("Error in:\nFSFILE_Close\n"); printf("Error in:\nAM_FinishCiaInstall\n");
return ret; return ret;
} }
ret = FSFILE_Close(fileHandle);
if (updatingSelf) { if (R_FAILED(ret)) {
if (R_FAILED(ret = CIA_LaunchTitle(info.titleID, MEDIATYPE_SD))) printf("Error in:\nFSFILE_Close\n");
return ret; return ret;
} }
return 0;
if (updatingSelf) {
if (R_FAILED(ret = CIA_LaunchTitle(info.titleID, MEDIATYPE_SD)))
return ret;
}
return 0;
} }
+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.