(3DS) Fix CIA installation issues (#14399)

- Fixes CIA installation failing
- Add CIA installation progress stats
This commit is contained in:
MrHuu 2022-09-11 02:57:31 +02:00 committed by GitHub
parent 14f4f35445
commit 422d2fcf12
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 36 deletions

View File

@ -1,12 +1,15 @@
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <math.h>
#include <sys/stat.h>
#include <3ds.h>
#include "ctr/ctr_debug.h"
#define FILE_CHUNK_SIZE 4096
PrintConsole debugConsoleTop;
typedef struct
{
u32 argc;
@ -60,6 +63,18 @@ static int isCiaInstalled(u64 titleId, u16 version)
return 0;
}
static int deleteCia(u64 TitleId)
{
u64 currTitleId = 0;
/* Do not delete if the titleid is currently running. */
if (R_FAILED(APT_GetAppletInfo((NS_APPID) envGetAptAppId(), &currTitleId, NULL, NULL, NULL, NULL)) || TitleId != currTitleId)
{
AM_DeleteTitle(MEDIATYPE_SD, TitleId);
AM_DeleteTicket(TitleId);
}
}
static int installCia(Handle ciaFile)
{
Handle outputHandle;
@ -91,15 +106,24 @@ static int installCia(Handle ciaFile)
}
failed = FSFILE_Write(outputHandle, &bytesWritten,
fileOffset, transferBuffer, bytesRead, 0);
fileOffset, transferBuffer, bytesRead, FS_WRITE_FLUSH);
if (R_FAILED(failed))
{
AM_CancelCIAInstall(outputHandle);
if (R_DESCRIPTION(failed) == RD_ALREADY_EXISTS)
return 1;
return -1;
}
printf(PRINTFPOS(27,0)" %llu / %llu\n\n", fileOffset, fileSize);
int progress = roundf(((float)fileOffset/(float)fileSize)*50);
for (int i = 0; i < progress; i++)
{
printf("#");
}
if (bytesWritten != bytesRead)
{
AM_CancelCIAInstall(outputHandle);
@ -121,6 +145,12 @@ int exec_cia(const char* path, const char** args)
struct stat sBuff;
bool fileExists;
bool inited;
#ifdef USE_CTRULIB_2
if (!gspHasGpuRight())
#endif
gfxInitDefault();
consoleInit(GFX_TOP, &debugConsoleTop);
if (!path || path[0] == '\0')
{
@ -175,10 +205,20 @@ int exec_cia(const char* path, const char** args)
}
else if (ciaInstalled == 0)
{
/* not installed */
/* titleid with version not installed. */
consoleSelect(&debugConsoleTop);
printf(PRINTFPOS(2,0)"Do not close RetroArch or turn off your console.");
printf(PRINTFPOS(5,0)"Installing core:\n%s\n", path);
/* Delete existing content of the pending titleid. */
deleteCia(ciaInfo.titleID);
int error = installCia(ciaFile);
if (error == -1)
error_and_quit("Cant install CIA.");
{
printf(PRINTFPOS(25,0)"CIA install failed.\n");
wait_for_input();
}
}
FSFILE_Close(ciaFile);

View File

@ -135,7 +135,6 @@ static void frontend_ctr_get_env(int* argc, char* argv[],
"logs", sizeof(g_defaults.dirs[DEFAULT_DIR_LOGS]));
fill_pathname_join(g_defaults.path_config, g_defaults.dirs[DEFAULT_DIR_PORT],
FILE_PATH_MAIN_CONFIG, sizeof(g_defaults.path_config));
fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_BOTTOM_ASSETS], g_defaults.dirs[DEFAULT_DIR_ASSETS],
"ctr", sizeof(g_defaults.dirs[DEFAULT_DIR_BOTTOM_ASSETS]));
@ -154,24 +153,6 @@ static void frontend_ctr_deinit(void* data)
(void)data;
#ifndef IS_SALAMANDER
/* Note: frontend_ctr_deinit() is normally called when
* forking to load new content. When this happens, the
* log messages generated in frontend_ctr_exec() *must*
* be printed to screen (provided bottom screen is not
* turned off...), since the 'first core launch' warning
* can prevent sdcard corruption. We therefore close any
* existing log file, enable verbose logging and revert
* to console output. (Normal logging will be resumed
* once retroarch.cfg has been re-read) */
retro_main_log_file_deinit();
verbosity_enable();
retro_main_log_file_init(NULL, false);
#ifdef CONSOLE_LOG
if (ctr_bottom_screen_enabled && (ctr_fork_mode == FRONTEND_FORK_NONE))
wait_for_input();
#endif
CFGU_GetModelNintendo2DS(&not_2DS);
if (not_2DS && srvGetServiceHandle(&lcd_handle, "gsp::Lcd") >= 0)
@ -259,23 +240,9 @@ static void frontend_ctr_exec(const char *path, bool should_load_game)
#endif
if (envIsHomebrew())
{
exec_3dsx_no_path_in_args(path, (const char**)arg_data);
}
else
{
RARCH_WARN("\n");
RARCH_WARN("\n");
RARCH_WARN("Warning:\n");
RARCH_WARN("First core launch may take 20\n");
RARCH_WARN("seconds! Do not force quit\n");
RARCH_WARN("before then or your memory\n");
RARCH_WARN("card may be corrupted!\n");
RARCH_WARN("\n");
RARCH_WARN("\n");
exec_cia(path, (const char**)arg_data);
}
/* couldnt launch new core, but context
is corrupt so we have to quit */