1
0
Fork 0
mirror of https://github.com/DarkMatterCore/nxdumptool.git synced 2024-11-26 12:12:02 +00:00

utils: implement utilsSetLongRunningProcessState().

Other changes include:

* DownloadTask: use utilsSetLongRunningProcessState() to control HOME button block status, screen dimming and auto sleep.
* Add missing utilsCommitSdCardFileSystemChanges() calls throughout the codebase.
This commit is contained in:
Pablo Curiel 2021-07-29 12:48:32 -04:00
parent dbbc5c7ebd
commit 841fd73fbf
6 changed files with 57 additions and 26 deletions

View file

@ -85,8 +85,9 @@ FsStorage *utilsGetEmmcBisSystemPartitionStorage(void);
/// Enables/disables CPU/MEM overclocking.
void utilsOverclockSystem(bool overclock);
/// (Un)blocks HOME button presses.
void utilsChangeHomeButtonBlockStatus(bool block);
/// (Un)blocks HOME button presses and (un)sets screen dimming and auto sleep.
/// Must be called before starting long-running processes.
void utilsSetLongRunningProcessState(bool state);
/// Thread management functions.
bool utilsCreateThread(Thread *out_thread, ThreadFunc func, void *arg, int cpu_id);

View file

@ -26,7 +26,7 @@
#include <borealis.hpp>
#include "defines.h"
#include "core/nxdt_utils.h"
#include "async_task.hpp"
namespace nxdt::tasks
@ -177,6 +177,9 @@ namespace nxdt::tasks
/* Pause task handler. */
this->task_handler->pause();
/* Unset long running process state. */
utilsSetLongRunningProcessState(false);
}
template<typename Result, typename... Params>
@ -190,11 +193,17 @@ namespace nxdt::tasks
/* Update progress one last time. */
this->onProgressUpdate(this->getProgress());
/* Unset long running process state. */
utilsSetLongRunningProcessState(false);
}
template<typename Result, typename... Params>
void DownloadTask<Result, Params...>::onPreExecute(void)
{
/* Set long running process state. */
utilsSetLongRunningProcessState(true);
/* Start task handler. */
this->task_handler->start();

View file

@ -209,6 +209,9 @@ bool httpDownloadFile(const char *path, const char *url, bool force_https, HttpP
/* Delete output file if the request failed. */
if (!ret) remove(path);
/* Commit SD card filesystem changes. */
utilsCommitSdCardFileSystemChanges();
return ret;
}

View file

@ -168,7 +168,13 @@ bool bfsarInitialize(void)
ret = g_bfsarInterfaceInit = true;
}
if (bfsar_file) fclose(bfsar_file);
if (bfsar_file)
{
fclose(bfsar_file);
/* Commit SD card filesystem changes. */
utilsCommitSdCardFileSystemChanges();
}
if (bfsar_data) free(bfsar_data);

View file

@ -55,7 +55,7 @@ static FATFS *g_emmcBisSystemPartitionFatFsObj = NULL;
static AppletHookCookie g_systemOverclockCookie = {0};
static bool g_homeButtonBlocked = false;
static bool g_longRunningProcess = false;
static int g_nxLinkSocketFd = -1;
@ -94,6 +94,8 @@ static void utilsUnmountEmmcBisSystemPartitionStorage(void);
static void utilsOverclockSystemAppletHook(AppletHookType hook, void *param);
static void utilsChangeHomeButtonBlockStatus(bool block);
static void utilsPrintConsoleError(void);
static size_t utilsGetUtf8CodepointCount(const char *str, size_t str_size, size_t cp_limit, size_t *last_cp_pos);
@ -210,10 +212,6 @@ bool utilsInitializeResources(const int program_argc, const char **program_argv)
if (R_SUCCEEDED(rc) && flag) appletInitializeGamePlayRecording();
}
/* Disable screen dimming and auto sleep. */
/* TODO: only use this function while dealing with a dump process - make sure to handle power button presses as well. */
appletSetMediaPlaybackState(true);
/* Redirect stdout and stderr over network to nxlink. */
g_nxLinkSocketFd = nxlinkConnectToHost(true, true);
@ -237,12 +235,8 @@ void utilsCloseResources(void)
g_nxLinkSocketFd = -1;
}
/* Enable screen dimming and auto sleep. */
/* TODO: only use this function while dealing with a dump process - make sure to handle power button presses as well. */
appletSetMediaPlaybackState(false);
/* Unblock HOME button presses. */
utilsChangeHomeButtonBlockStatus(false);
/* Unset long running process state. */
utilsSetLongRunningProcessState(false);
/* Unset our overclock applet hook. */
appletUnhook(&g_systemOverclockCookie);
@ -335,21 +329,21 @@ void utilsOverclockSystem(bool overclock)
servicesChangeHardwareClockRates(cpu_rate, mem_rate);
}
void utilsChangeHomeButtonBlockStatus(bool block)
void utilsSetLongRunningProcessState(bool state)
{
SCOPED_LOCK(&g_resourcesMutex)
{
/* Only change HOME button blocking status if we're running as a regular application or a system application, and if its current blocking status is different than the requested one. */
if (_utilsAppletModeCheck() || block == g_homeButtonBlocked) break;
/* Don't proceed if the requested state matches the current one. */
if (state == g_longRunningProcess) break;
if (block)
{
appletBeginBlockingHomeButtonShortAndLongPressed(0);
} else {
appletEndBlockingHomeButtonShortAndLongPressed();
}
/* Change HOME button block status. */
utilsChangeHomeButtonBlockStatus(state);
g_homeButtonBlocked = block;
/* (Un)set screen dimming and auto sleep. */
appletSetMediaPlaybackState(state);
/* Update flag. */
g_longRunningProcess = state;
}
}
@ -906,6 +900,19 @@ static void utilsOverclockSystemAppletHook(AppletHookType hook, void *param)
utilsOverclockSystem(configGetBoolean("overclock"));
}
static void utilsChangeHomeButtonBlockStatus(bool block)
{
/* Only change HOME button blocking status if we're running as a regular application or a system application. */
if (_utilsAppletModeCheck()) return;
if (block)
{
appletBeginBlockingHomeButtonShortAndLongPressed(0);
} else {
appletEndBlockingHomeButtonShortAndLongPressed();
}
}
static void utilsPrintConsoleError(void)
{
PadState pad = {0};

View file

@ -1770,7 +1770,12 @@ save_ctx_t *save_open_savefile(const char *path, u32 action)
f_rewind(save_fd);
}
if (fd) fclose(fd);
if (fd)
{
fclose(fd);
utilsCommitSdCardFileSystemChanges();
}
if (buf) free(buf);*/
save_ctx = calloc(1, sizeof(save_ctx_t));