mirror of
https://github.com/DarkMatterCore/nxdumptool.git
synced 2024-11-22 18:26:39 +00:00
Fixed "Please wait" message hang up.
This commit is contained in:
parent
01a3ebe477
commit
7a94da0a5c
4 changed files with 151 additions and 142 deletions
|
@ -435,7 +435,7 @@ bool dumpGameCartridge(FsDeviceOperator* fsOperator, bool isFat32, bool dumpCert
|
|||
u8 progress = 0;
|
||||
u32 crc1 = 0, crc2 = 0;
|
||||
|
||||
time_t start, now, remainingTime;
|
||||
u64 start, now, remainingTime;
|
||||
struct tm *timeinfo;
|
||||
char etaInfo[32] = {'\0'};
|
||||
double lastSpeed = 0.0, averageSpeed = 0.0;
|
||||
|
@ -535,7 +535,7 @@ bool dumpGameCartridge(FsDeviceOperator* fsOperator, bool isFat32, bool dumpCert
|
|||
uiDrawString(strbuf, 0, breaks * 8, 255, 255, 255);
|
||||
breaks += 2;
|
||||
|
||||
time(&start);
|
||||
timeGetCurrentTime(TimeType_LocalSystemClock, &start);
|
||||
|
||||
for(partition = 0; partition < ISTORAGE_PARTITION_CNT; partition++)
|
||||
{
|
||||
|
@ -658,14 +658,14 @@ bool dumpGameCartridge(FsDeviceOperator* fsOperator, bool isFat32, bool dumpCert
|
|||
}
|
||||
}
|
||||
|
||||
time(&now);
|
||||
timeGetCurrentTime(TimeType_LocalSystemClock, &now);
|
||||
|
||||
lastSpeed = ((double)((fileOffset + n) / DUMP_BUFFER_SIZE) / difftime(now, start));
|
||||
lastSpeed = (((double)(fileOffset + n) / (double)DUMP_BUFFER_SIZE) / difftime((time_t)now, (time_t)start));
|
||||
averageSpeed = ((SMOOTHING_FACTOR * lastSpeed) + ((1 - SMOOTHING_FACTOR) * averageSpeed));
|
||||
if (!isnormal(averageSpeed)) averageSpeed = 0.00; // Very low values
|
||||
|
||||
remainingTime = (time_t)((double)((totalSize - (fileOffset + n)) / DUMP_BUFFER_SIZE) / averageSpeed);
|
||||
timeinfo = localtime(&remainingTime);
|
||||
remainingTime = (u64)(((double)(totalSize - (fileOffset + n)) / (double)DUMP_BUFFER_SIZE) / averageSpeed);
|
||||
timeinfo = localtime((time_t*)&remainingTime);
|
||||
strftime(etaInfo, sizeof(etaInfo) / sizeof(etaInfo[0]), "%HH%MM%SS", timeinfo);
|
||||
|
||||
progress = (u8)(((fileOffset + n) * 100) / totalSize);
|
||||
|
@ -749,7 +749,7 @@ bool dumpGameCartridge(FsDeviceOperator* fsOperator, bool isFat32, bool dumpCert
|
|||
breaks += 7;
|
||||
|
||||
now -= start;
|
||||
timeinfo = localtime(&now);
|
||||
timeinfo = localtime((time_t*)&now);
|
||||
strftime(etaInfo, sizeof(etaInfo) / sizeof(etaInfo[0]), "%HH%MM%SS", timeinfo);
|
||||
snprintf(strbuf, sizeof(strbuf) / sizeof(strbuf[0]), "Process successfully completed after %s!", etaInfo);
|
||||
uiDrawString(strbuf, 0, breaks * 8, 0, 255, 0);
|
||||
|
@ -828,7 +828,7 @@ bool dumpRawPartition(FsDeviceOperator* fsOperator, u32 partition, bool doSplitt
|
|||
FILE *outFile = NULL;
|
||||
u8 splitIndex = 0;
|
||||
|
||||
time_t start, now, remainingTime;
|
||||
u64 start, now, remainingTime;
|
||||
struct tm *timeinfo;
|
||||
char etaInfo[32] = {'\0'};
|
||||
double lastSpeed = 0.0, averageSpeed = 0.0;
|
||||
|
@ -888,7 +888,7 @@ bool dumpRawPartition(FsDeviceOperator* fsOperator, u32 partition, bool doSplitt
|
|||
|
||||
syncDisplay();
|
||||
|
||||
time(&start);
|
||||
timeGetCurrentTime(TimeType_LocalSystemClock, &start);
|
||||
|
||||
for (off = 0; off < size; off += n)
|
||||
{
|
||||
|
@ -947,14 +947,14 @@ bool dumpRawPartition(FsDeviceOperator* fsOperator, u32 partition, bool doSplitt
|
|||
}
|
||||
}
|
||||
|
||||
time(&now);
|
||||
timeGetCurrentTime(TimeType_LocalSystemClock, &now);
|
||||
|
||||
lastSpeed = ((double)((off + n) / DUMP_BUFFER_SIZE) / difftime(now, start));
|
||||
lastSpeed = (((double)(off + n) / (double)DUMP_BUFFER_SIZE) / difftime((time_t)now, (time_t)start));
|
||||
averageSpeed = ((SMOOTHING_FACTOR * lastSpeed) + ((1 - SMOOTHING_FACTOR) * averageSpeed));
|
||||
if (!isnormal(averageSpeed)) averageSpeed = 0.00; // Very low values
|
||||
|
||||
remainingTime = (time_t)((double)((size - (off + n)) / DUMP_BUFFER_SIZE) / averageSpeed);
|
||||
timeinfo = localtime(&remainingTime);
|
||||
remainingTime = (u64)(((double)(size - (off + n)) / (double)DUMP_BUFFER_SIZE) / averageSpeed);
|
||||
timeinfo = localtime((time_t*)&remainingTime);
|
||||
strftime(etaInfo, sizeof(etaInfo) / sizeof(etaInfo[0]), "%HH%MM%SS", timeinfo);
|
||||
|
||||
progress = (u8)(((off + n) * 100) / size);
|
||||
|
@ -1004,7 +1004,7 @@ bool dumpRawPartition(FsDeviceOperator* fsOperator, u32 partition, bool doSplitt
|
|||
if (success)
|
||||
{
|
||||
now -= start;
|
||||
timeinfo = localtime(&now);
|
||||
timeinfo = localtime((time_t*)&now);
|
||||
strftime(etaInfo, sizeof(etaInfo) / sizeof(etaInfo[0]), "%HH%MM%SS", timeinfo);
|
||||
snprintf(strbuf, sizeof(strbuf) / sizeof(strbuf[0]), "Process successfully completed after %s!", etaInfo);
|
||||
uiDrawString(strbuf, 0, (breaks + 4) * 8, 0, 255, 0);
|
||||
|
@ -1104,7 +1104,7 @@ bool copyFile(const char* source, const char* dest, bool doSplitting, bool calcE
|
|||
u8 progress = 0;
|
||||
char totalSizeStr[32] = {'\0'}, curSizeStr[32] = {'\0'};
|
||||
|
||||
time_t start, now, remainingTime;
|
||||
u64 start, now, remainingTime;
|
||||
struct tm *timeinfo;
|
||||
char etaInfo[32] = {'\0'};
|
||||
double lastSpeed = 0.0, averageSpeed = 0.0;
|
||||
|
@ -1134,7 +1134,7 @@ bool copyFile(const char* source, const char* dest, bool doSplitting, bool calcE
|
|||
buf = (char*)malloc(DUMP_BUFFER_SIZE);
|
||||
if (buf)
|
||||
{
|
||||
if (calcEta) time(&start);
|
||||
if (calcEta) timeGetCurrentTime(TimeType_LocalSystemClock, &start);
|
||||
|
||||
for (off = 0; off < size; off += n)
|
||||
{
|
||||
|
@ -1195,14 +1195,14 @@ bool copyFile(const char* source, const char* dest, bool doSplitting, bool calcE
|
|||
|
||||
if (calcEta)
|
||||
{
|
||||
time(&now);
|
||||
timeGetCurrentTime(TimeType_LocalSystemClock, &now);
|
||||
|
||||
lastSpeed = ((double)((off + n) / DUMP_BUFFER_SIZE) / difftime(now, start));
|
||||
lastSpeed = (((double)(off + n) / (double)DUMP_BUFFER_SIZE) / difftime((time_t)now, (time_t)start));
|
||||
averageSpeed = ((SMOOTHING_FACTOR * lastSpeed) + ((1 - SMOOTHING_FACTOR) * averageSpeed));
|
||||
if (!isnormal(averageSpeed)) averageSpeed = 0.00; // Very low values
|
||||
|
||||
remainingTime = (time_t)((double)((size - (off + n)) / DUMP_BUFFER_SIZE) / averageSpeed);
|
||||
timeinfo = localtime(&remainingTime);
|
||||
remainingTime = (u64)(((double)(size - (off + n)) / (double)DUMP_BUFFER_SIZE) / averageSpeed);
|
||||
timeinfo = localtime((time_t*)&remainingTime);
|
||||
strftime(etaInfo, sizeof(etaInfo) / sizeof(etaInfo[0]), "%HH%MM%SS", timeinfo);
|
||||
|
||||
uiFill(0, ((breaks + 3) * 8) + 4, (currentFBWidth / 4) - 8, 8, 50, 50, 50);
|
||||
|
@ -1271,7 +1271,7 @@ bool copyFile(const char* source, const char* dest, bool doSplitting, bool calcE
|
|||
breaks += 7;
|
||||
|
||||
now -= start;
|
||||
timeinfo = localtime(&now);
|
||||
timeinfo = localtime((time_t*)&now);
|
||||
strftime(etaInfo, sizeof(etaInfo) / sizeof(etaInfo[0]), "%HH%MM%SS", timeinfo);
|
||||
snprintf(strbuf, sizeof(strbuf) / sizeof(strbuf[0]), "Process successfully completed after %s!", etaInfo);
|
||||
uiDrawString(strbuf, 0, breaks * 8, 0, 255, 0);
|
||||
|
|
|
@ -60,7 +60,7 @@
|
|||
#define bswap_32(a) ((((a) << 24) & 0xff000000) | (((a) << 8) & 0xff0000) | (((a) >> 8) & 0xff00) | (((a) >> 24) & 0xff))
|
||||
#define round_up(x, y) ((x) + (((y) - ((x) % (y))) % (y))) // Aligns 'x' bytes to a 'y' bytes boundary
|
||||
|
||||
#define SMOOTHING_FACTOR (double)0.05
|
||||
#define SMOOTHING_FACTOR (double)0.01
|
||||
|
||||
typedef struct
|
||||
{
|
||||
|
|
242
source/main.c
242
source/main.c
|
@ -54,136 +54,146 @@ int main(int argc, char **argv)
|
|||
{
|
||||
if (R_SUCCEEDED(result = nsInitialize()))
|
||||
{
|
||||
bool exitLoop = false;
|
||||
|
||||
while(appletMainLoop())
|
||||
if (R_SUCCEEDED(result = timeInitialize()))
|
||||
{
|
||||
currentFB = gfxGetFramebuffer(¤tFBWidth, ¤tFBHeight);
|
||||
bool exitLoop = false;
|
||||
|
||||
uiPrintHeadline();
|
||||
|
||||
gameCardInserted = isGameCardInserted(&fsOperatorInstance);
|
||||
|
||||
if (gameCardInserted)
|
||||
while(appletMainLoop())
|
||||
{
|
||||
if (hfs0_header == NULL)
|
||||
currentFB = gfxGetFramebuffer(¤tFBWidth, ¤tFBHeight);
|
||||
|
||||
uiPrintHeadline();
|
||||
|
||||
gameCardInserted = isGameCardInserted(&fsOperatorInstance);
|
||||
|
||||
if (gameCardInserted)
|
||||
{
|
||||
// Don't access the gamecard immediately to avoid conflicts with the fsp-srv, ncm and ns services
|
||||
uiPleaseWait();
|
||||
|
||||
if (getRootHfs0Header(&fsOperatorInstance))
|
||||
if (hfs0_header == NULL)
|
||||
{
|
||||
if (getGameCardTitleIDAndVersion(&gameCardTitleID, &gameCardVersion))
|
||||
// Don't access the gamecard immediately to avoid conflicts with the fsp-srv, ncm and ns services
|
||||
uiPleaseWait();
|
||||
|
||||
if (getRootHfs0Header(&fsOperatorInstance))
|
||||
{
|
||||
convertTitleVersionToDecimal(gameCardVersion, gameCardVersionStr, sizeof(gameCardVersionStr));
|
||||
getGameCardControlNacp(gameCardTitleID, gameCardName, sizeof(gameCardName), gameCardAuthor, sizeof(gameCardAuthor));
|
||||
strtrim(gameCardName);
|
||||
|
||||
if (strlen(gameCardName))
|
||||
if (getGameCardTitleIDAndVersion(&gameCardTitleID, &gameCardVersion))
|
||||
{
|
||||
snprintf(fixedGameCardName, sizeof(fixedGameCardName) / sizeof(fixedGameCardName[0]), "%s", gameCardName);
|
||||
removeIllegalCharacters(fixedGameCardName);
|
||||
convertTitleVersionToDecimal(gameCardVersion, gameCardVersionStr, sizeof(gameCardVersionStr));
|
||||
getGameCardControlNacp(gameCardTitleID, gameCardName, sizeof(gameCardName), gameCardAuthor, sizeof(gameCardAuthor));
|
||||
strtrim(gameCardName);
|
||||
|
||||
if (strlen(gameCardName))
|
||||
{
|
||||
snprintf(fixedGameCardName, sizeof(fixedGameCardName) / sizeof(fixedGameCardName[0]), "%s", gameCardName);
|
||||
removeIllegalCharacters(fixedGameCardName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uiPrintHeadline();
|
||||
uiUpdateStatusMsg();
|
||||
}
|
||||
|
||||
uiPrintHeadline();
|
||||
uiUpdateStatusMsg();
|
||||
}
|
||||
} else {
|
||||
if (hfs0_header != NULL)
|
||||
{
|
||||
gameCardSize = 0;
|
||||
memset(gameCardSizeStr, 0, sizeof(gameCardSizeStr));
|
||||
|
||||
trimmedCardSize = 0;
|
||||
memset(trimmedCardSizeStr, 0, sizeof(trimmedCardSizeStr));
|
||||
|
||||
free(hfs0_header);
|
||||
hfs0_header = NULL;
|
||||
hfs0_offset = hfs0_size = 0;
|
||||
hfs0_partition_cnt = 0;
|
||||
|
||||
/*if (partitionHfs0Header != NULL)
|
||||
} else {
|
||||
if (hfs0_header != NULL)
|
||||
{
|
||||
free(partitionHfs0Header);
|
||||
partitionHfs0Header = NULL;
|
||||
partitionHfs0HeaderSize = 0;
|
||||
}*/
|
||||
|
||||
gameCardTitleID = 0;
|
||||
gameCardVersion = 0;
|
||||
|
||||
memset(gameCardName, 0, sizeof(gameCardName));
|
||||
memset(fixedGameCardName, 0, sizeof(fixedGameCardName));
|
||||
memset(gameCardAuthor, 0, sizeof(gameCardAuthor));
|
||||
memset(gameCardVersionStr, 0, sizeof(gameCardVersionStr));
|
||||
|
||||
gameCardUpdateTitleID = 0;
|
||||
gameCardUpdateVersion = 0;
|
||||
|
||||
memset(gameCardUpdateVersionStr, 0, sizeof(gameCardUpdateVersionStr));
|
||||
gameCardSize = 0;
|
||||
memset(gameCardSizeStr, 0, sizeof(gameCardSizeStr));
|
||||
|
||||
trimmedCardSize = 0;
|
||||
memset(trimmedCardSizeStr, 0, sizeof(trimmedCardSizeStr));
|
||||
|
||||
free(hfs0_header);
|
||||
hfs0_header = NULL;
|
||||
hfs0_offset = hfs0_size = 0;
|
||||
hfs0_partition_cnt = 0;
|
||||
|
||||
/*if (partitionHfs0Header != NULL)
|
||||
{
|
||||
free(partitionHfs0Header);
|
||||
partitionHfs0Header = NULL;
|
||||
partitionHfs0HeaderSize = 0;
|
||||
}*/
|
||||
|
||||
gameCardTitleID = 0;
|
||||
gameCardVersion = 0;
|
||||
|
||||
memset(gameCardName, 0, sizeof(gameCardName));
|
||||
memset(fixedGameCardName, 0, sizeof(fixedGameCardName));
|
||||
memset(gameCardAuthor, 0, sizeof(gameCardAuthor));
|
||||
memset(gameCardVersionStr, 0, sizeof(gameCardVersionStr));
|
||||
|
||||
gameCardUpdateTitleID = 0;
|
||||
gameCardUpdateVersion = 0;
|
||||
|
||||
memset(gameCardUpdateVersionStr, 0, sizeof(gameCardUpdateVersionStr));
|
||||
}
|
||||
}
|
||||
|
||||
hidScanInput();
|
||||
u32 keysDown = hidKeysDown(CONTROLLER_P1_AUTO);
|
||||
|
||||
UIResult result = uiLoop(keysDown);
|
||||
switch(result)
|
||||
{
|
||||
case resultShowMainMenu:
|
||||
uiSetState(stateMainMenu);
|
||||
break;
|
||||
case resultShowXciDumpMenu:
|
||||
uiSetState(stateXciDumpMenu);
|
||||
break;
|
||||
case resultDumpXci:
|
||||
uiSetState(stateDumpXci);
|
||||
break;
|
||||
case resultShowRawPartitionDumpMenu:
|
||||
uiSetState(stateRawPartitionDumpMenu);
|
||||
break;
|
||||
case resultDumpRawPartition:
|
||||
uiSetState(stateDumpRawPartition);
|
||||
break;
|
||||
case resultShowPartitionDataDumpMenu:
|
||||
uiSetState(statePartitionDataDumpMenu);
|
||||
break;
|
||||
case resultDumpPartitionData:
|
||||
uiSetState(stateDumpPartitionData);
|
||||
break;
|
||||
case resultShowViewGameCardFsMenu:
|
||||
uiSetState(stateViewGameCardFsMenu);
|
||||
break;
|
||||
case resultShowViewGameCardFsGetList:
|
||||
uiSetState(stateViewGameCardFsGetList);
|
||||
break;
|
||||
case resultShowViewGameCardFsBrowser:
|
||||
uiSetState(stateViewGameCardFsBrowser);
|
||||
break;
|
||||
case resultViewGameCardFsBrowserCopyFile:
|
||||
uiSetState(stateViewGameCardFsBrowserCopyFile);
|
||||
break;
|
||||
case resultDumpGameCardCertificate:
|
||||
uiSetState(stateDumpGameCardCertificate);
|
||||
break;
|
||||
case resultUpdateNSWDBXml:
|
||||
uiSetState(stateUpdateNSWDBXml);
|
||||
break;
|
||||
case resultUpdateApplication:
|
||||
uiSetState(stateUpdateApplication);
|
||||
break;
|
||||
case resultExit:
|
||||
exitLoop = true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (exitLoop) break;
|
||||
|
||||
syncDisplay();
|
||||
}
|
||||
|
||||
hidScanInput();
|
||||
u32 keysDown = hidKeysDown(CONTROLLER_P1_AUTO);
|
||||
|
||||
UIResult result = uiLoop(keysDown);
|
||||
switch(result)
|
||||
{
|
||||
case resultShowMainMenu:
|
||||
uiSetState(stateMainMenu);
|
||||
break;
|
||||
case resultShowXciDumpMenu:
|
||||
uiSetState(stateXciDumpMenu);
|
||||
break;
|
||||
case resultDumpXci:
|
||||
uiSetState(stateDumpXci);
|
||||
break;
|
||||
case resultShowRawPartitionDumpMenu:
|
||||
uiSetState(stateRawPartitionDumpMenu);
|
||||
break;
|
||||
case resultDumpRawPartition:
|
||||
uiSetState(stateDumpRawPartition);
|
||||
break;
|
||||
case resultShowPartitionDataDumpMenu:
|
||||
uiSetState(statePartitionDataDumpMenu);
|
||||
break;
|
||||
case resultDumpPartitionData:
|
||||
uiSetState(stateDumpPartitionData);
|
||||
break;
|
||||
case resultShowViewGameCardFsMenu:
|
||||
uiSetState(stateViewGameCardFsMenu);
|
||||
break;
|
||||
case resultShowViewGameCardFsGetList:
|
||||
uiSetState(stateViewGameCardFsGetList);
|
||||
break;
|
||||
case resultShowViewGameCardFsBrowser:
|
||||
uiSetState(stateViewGameCardFsBrowser);
|
||||
break;
|
||||
case resultViewGameCardFsBrowserCopyFile:
|
||||
uiSetState(stateViewGameCardFsBrowserCopyFile);
|
||||
break;
|
||||
case resultDumpGameCardCertificate:
|
||||
uiSetState(stateDumpGameCardCertificate);
|
||||
break;
|
||||
case resultUpdateNSWDBXml:
|
||||
uiSetState(stateUpdateNSWDBXml);
|
||||
break;
|
||||
case resultUpdateApplication:
|
||||
uiSetState(stateUpdateApplication);
|
||||
break;
|
||||
case resultExit:
|
||||
exitLoop = true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (exitLoop) break;
|
||||
|
||||
syncDisplay();
|
||||
timeExit();
|
||||
} else {
|
||||
snprintf(strbuf, sizeof(strbuf) / sizeof(strbuf[0]), "Failed to initialize the time service! (0x%08X)", result);
|
||||
uiDrawString(strbuf, 0, 0, 255, 255, 255);
|
||||
delay(5);
|
||||
ret = -5;
|
||||
}
|
||||
|
||||
nsExit();
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <math.h>
|
||||
#include <time.h>
|
||||
#include <dirent.h>
|
||||
#include <ctype.h>
|
||||
#include <sys/stat.h>
|
||||
|
@ -66,10 +65,10 @@ void delay(u8 seconds)
|
|||
{
|
||||
if (!seconds) return;
|
||||
|
||||
time_t timer;
|
||||
time(&timer);
|
||||
u64 nanoseconds = seconds * (u64)1000000000;
|
||||
svcSleepThread(nanoseconds);
|
||||
|
||||
while(time(NULL) < (timer + seconds)) syncDisplay();
|
||||
syncDisplay();
|
||||
}
|
||||
|
||||
bool getGameCardTitleIDAndVersion(u64 *titleID, u32 *version)
|
||||
|
|
Loading…
Reference in a new issue