mirror of
https://github.com/DarkMatterCore/nxdumptool.git
synced 2024-11-23 02:36:41 +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:
parent
dbbc5c7ebd
commit
841fd73fbf
6 changed files with 57 additions and 26 deletions
|
@ -85,8 +85,9 @@ FsStorage *utilsGetEmmcBisSystemPartitionStorage(void);
|
||||||
/// Enables/disables CPU/MEM overclocking.
|
/// Enables/disables CPU/MEM overclocking.
|
||||||
void utilsOverclockSystem(bool overclock);
|
void utilsOverclockSystem(bool overclock);
|
||||||
|
|
||||||
/// (Un)blocks HOME button presses.
|
/// (Un)blocks HOME button presses and (un)sets screen dimming and auto sleep.
|
||||||
void utilsChangeHomeButtonBlockStatus(bool block);
|
/// Must be called before starting long-running processes.
|
||||||
|
void utilsSetLongRunningProcessState(bool state);
|
||||||
|
|
||||||
/// Thread management functions.
|
/// Thread management functions.
|
||||||
bool utilsCreateThread(Thread *out_thread, ThreadFunc func, void *arg, int cpu_id);
|
bool utilsCreateThread(Thread *out_thread, ThreadFunc func, void *arg, int cpu_id);
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
|
|
||||||
#include <borealis.hpp>
|
#include <borealis.hpp>
|
||||||
|
|
||||||
#include "defines.h"
|
#include "core/nxdt_utils.h"
|
||||||
#include "async_task.hpp"
|
#include "async_task.hpp"
|
||||||
|
|
||||||
namespace nxdt::tasks
|
namespace nxdt::tasks
|
||||||
|
@ -177,6 +177,9 @@ namespace nxdt::tasks
|
||||||
|
|
||||||
/* Pause task handler. */
|
/* Pause task handler. */
|
||||||
this->task_handler->pause();
|
this->task_handler->pause();
|
||||||
|
|
||||||
|
/* Unset long running process state. */
|
||||||
|
utilsSetLongRunningProcessState(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Result, typename... Params>
|
template<typename Result, typename... Params>
|
||||||
|
@ -190,11 +193,17 @@ namespace nxdt::tasks
|
||||||
|
|
||||||
/* Update progress one last time. */
|
/* Update progress one last time. */
|
||||||
this->onProgressUpdate(this->getProgress());
|
this->onProgressUpdate(this->getProgress());
|
||||||
|
|
||||||
|
/* Unset long running process state. */
|
||||||
|
utilsSetLongRunningProcessState(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Result, typename... Params>
|
template<typename Result, typename... Params>
|
||||||
void DownloadTask<Result, Params...>::onPreExecute(void)
|
void DownloadTask<Result, Params...>::onPreExecute(void)
|
||||||
{
|
{
|
||||||
|
/* Set long running process state. */
|
||||||
|
utilsSetLongRunningProcessState(true);
|
||||||
|
|
||||||
/* Start task handler. */
|
/* Start task handler. */
|
||||||
this->task_handler->start();
|
this->task_handler->start();
|
||||||
|
|
||||||
|
|
|
@ -209,6 +209,9 @@ bool httpDownloadFile(const char *path, const char *url, bool force_https, HttpP
|
||||||
/* Delete output file if the request failed. */
|
/* Delete output file if the request failed. */
|
||||||
if (!ret) remove(path);
|
if (!ret) remove(path);
|
||||||
|
|
||||||
|
/* Commit SD card filesystem changes. */
|
||||||
|
utilsCommitSdCardFileSystemChanges();
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -168,7 +168,13 @@ bool bfsarInitialize(void)
|
||||||
ret = g_bfsarInterfaceInit = true;
|
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);
|
if (bfsar_data) free(bfsar_data);
|
||||||
|
|
||||||
|
|
|
@ -55,7 +55,7 @@ static FATFS *g_emmcBisSystemPartitionFatFsObj = NULL;
|
||||||
|
|
||||||
static AppletHookCookie g_systemOverclockCookie = {0};
|
static AppletHookCookie g_systemOverclockCookie = {0};
|
||||||
|
|
||||||
static bool g_homeButtonBlocked = false;
|
static bool g_longRunningProcess = false;
|
||||||
|
|
||||||
static int g_nxLinkSocketFd = -1;
|
static int g_nxLinkSocketFd = -1;
|
||||||
|
|
||||||
|
@ -94,6 +94,8 @@ static void utilsUnmountEmmcBisSystemPartitionStorage(void);
|
||||||
|
|
||||||
static void utilsOverclockSystemAppletHook(AppletHookType hook, void *param);
|
static void utilsOverclockSystemAppletHook(AppletHookType hook, void *param);
|
||||||
|
|
||||||
|
static void utilsChangeHomeButtonBlockStatus(bool block);
|
||||||
|
|
||||||
static void utilsPrintConsoleError(void);
|
static void utilsPrintConsoleError(void);
|
||||||
|
|
||||||
static size_t utilsGetUtf8CodepointCount(const char *str, size_t str_size, size_t cp_limit, size_t *last_cp_pos);
|
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();
|
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. */
|
/* Redirect stdout and stderr over network to nxlink. */
|
||||||
g_nxLinkSocketFd = nxlinkConnectToHost(true, true);
|
g_nxLinkSocketFd = nxlinkConnectToHost(true, true);
|
||||||
|
|
||||||
|
@ -237,12 +235,8 @@ void utilsCloseResources(void)
|
||||||
g_nxLinkSocketFd = -1;
|
g_nxLinkSocketFd = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Enable screen dimming and auto sleep. */
|
/* Unset long running process state. */
|
||||||
/* TODO: only use this function while dealing with a dump process - make sure to handle power button presses as well. */
|
utilsSetLongRunningProcessState(false);
|
||||||
appletSetMediaPlaybackState(false);
|
|
||||||
|
|
||||||
/* Unblock HOME button presses. */
|
|
||||||
utilsChangeHomeButtonBlockStatus(false);
|
|
||||||
|
|
||||||
/* Unset our overclock applet hook. */
|
/* Unset our overclock applet hook. */
|
||||||
appletUnhook(&g_systemOverclockCookie);
|
appletUnhook(&g_systemOverclockCookie);
|
||||||
|
@ -335,21 +329,21 @@ void utilsOverclockSystem(bool overclock)
|
||||||
servicesChangeHardwareClockRates(cpu_rate, mem_rate);
|
servicesChangeHardwareClockRates(cpu_rate, mem_rate);
|
||||||
}
|
}
|
||||||
|
|
||||||
void utilsChangeHomeButtonBlockStatus(bool block)
|
void utilsSetLongRunningProcessState(bool state)
|
||||||
{
|
{
|
||||||
SCOPED_LOCK(&g_resourcesMutex)
|
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. */
|
/* Don't proceed if the requested state matches the current one. */
|
||||||
if (_utilsAppletModeCheck() || block == g_homeButtonBlocked) break;
|
if (state == g_longRunningProcess) break;
|
||||||
|
|
||||||
if (block)
|
/* Change HOME button block status. */
|
||||||
{
|
utilsChangeHomeButtonBlockStatus(state);
|
||||||
appletBeginBlockingHomeButtonShortAndLongPressed(0);
|
|
||||||
} else {
|
|
||||||
appletEndBlockingHomeButtonShortAndLongPressed();
|
|
||||||
}
|
|
||||||
|
|
||||||
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"));
|
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)
|
static void utilsPrintConsoleError(void)
|
||||||
{
|
{
|
||||||
PadState pad = {0};
|
PadState pad = {0};
|
||||||
|
|
|
@ -1770,7 +1770,12 @@ save_ctx_t *save_open_savefile(const char *path, u32 action)
|
||||||
f_rewind(save_fd);
|
f_rewind(save_fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fd) fclose(fd);
|
if (fd)
|
||||||
|
{
|
||||||
|
fclose(fd);
|
||||||
|
utilsCommitSdCardFileSystemChanges();
|
||||||
|
}
|
||||||
|
|
||||||
if (buf) free(buf);*/
|
if (buf) free(buf);*/
|
||||||
|
|
||||||
save_ctx = calloc(1, sizeof(save_ctx_t));
|
save_ctx = calloc(1, sizeof(save_ctx_t));
|
||||||
|
|
Loading…
Reference in a new issue