mirror of
https://github.com/wiiu-env/AromaBasePlugin.git
synced 2024-11-23 20:19:15 +01:00
Migrate AromaUpdater to sub directory on console boot
This commit is contained in:
parent
174ff9c81c
commit
cc04c1ae96
@ -16,6 +16,7 @@
|
||||
#include <vpad/input.h>
|
||||
#include <wups/function_patching.h>
|
||||
|
||||
static std::string sAromaUpdaterPath = AROMA_UPDATER_NEW_PATH_FULL;
|
||||
static NotificationModuleHandle sAromaUpdateHandle = 0;
|
||||
std::unique_ptr<std::thread> sCheckUpdateThread;
|
||||
static bool sShutdownUpdateThread = false;
|
||||
@ -109,17 +110,22 @@ void UpdateCheckThreadEntry() {
|
||||
void ShowUpdateNotification() {
|
||||
struct stat st {};
|
||||
// Check if the Aroma Updater is on the sd card
|
||||
if (stat(AROMA_UPDATER_PATH_FULL, &st) >= 0 && S_ISREG(st.st_mode)) {
|
||||
NotificationModuleStatus err;
|
||||
if ((err = NotificationModule_AddDynamicNotification("A new Aroma Update is available. "
|
||||
"Hold \ue045 to launch the Aroma Updater, press \ue046 to hide this message",
|
||||
&sAromaUpdateHandle)) != NOTIFICATION_MODULE_RESULT_SUCCESS) {
|
||||
DEBUG_FUNCTION_LINE_ERR("Failed to add update notification. %s", NotificationModule_GetStatusStr(err));
|
||||
sAromaUpdateHandle = 0;
|
||||
}
|
||||
if (stat(AROMA_UPDATER_OLD_PATH_FULL, &st) >= 0 && S_ISREG(st.st_mode)) {
|
||||
sAromaUpdaterPath = AROMA_UPDATER_OLD_PATH;
|
||||
} else if (stat(AROMA_UPDATER_NEW_PATH_FULL, &st) >= 0 && S_ISREG(st.st_mode)) {
|
||||
sAromaUpdaterPath = AROMA_UPDATER_NEW_PATH;
|
||||
} else {
|
||||
NotificationModule_SetDefaultValue(NOTIFICATION_MODULE_NOTIFICATION_TYPE_INFO, NOTIFICATION_MODULE_DEFAULT_OPTION_DURATION_BEFORE_FADE_OUT, 15.0f);
|
||||
NotificationModule_AddInfoNotification("A new Aroma Update is available. Please launch the Aroma Updater!");
|
||||
return;
|
||||
}
|
||||
|
||||
NotificationModuleStatus err;
|
||||
if ((err = NotificationModule_AddDynamicNotification("A new Aroma Update is available. "
|
||||
"Hold \ue045 to launch the Aroma Updater, press \ue046 to hide this message",
|
||||
&sAromaUpdateHandle)) != NOTIFICATION_MODULE_RESULT_SUCCESS) {
|
||||
DEBUG_FUNCTION_LINE_ERR("Failed to add update notification. %s", NotificationModule_GetStatusStr(err));
|
||||
sAromaUpdateHandle = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@ -136,15 +142,16 @@ bool CheckForButtonCombo(uint32_t trigger, uint32_t hold, uint32_t &holdForXFram
|
||||
}
|
||||
if (hold == LAUNCH_AROMA_UPDATER_VPAD_COMBO) {
|
||||
if (++holdForXFrames > holdForFramesTarget) {
|
||||
NotificationModule_FinishDynamicNotification(sAromaUpdateHandle, 0.5f);
|
||||
sAromaUpdateHandle = 0;
|
||||
RPXLoaderStatus err;
|
||||
if ((err = RPXLoader_LaunchHomebrew(AROMA_UPDATER_PATH)) == RPX_LOADER_RESULT_SUCCESS) {
|
||||
NotificationModule_FinishDynamicNotification(sAromaUpdateHandle, 2.0f);
|
||||
sAromaUpdateHandle = 0;
|
||||
updaterLaunched = true;
|
||||
return true;
|
||||
if ((err = RPXLoader_LaunchHomebrew(sAromaUpdaterPath.c_str())) == RPX_LOADER_RESULT_SUCCESS) {
|
||||
updaterLaunched = true;
|
||||
} else {
|
||||
DEBUG_FUNCTION_LINE_ERR("RPXLoader_LaunchHomebrew failed: %s", RPXLoader_GetStatusStr(err));
|
||||
NotificationModule_AddErrorNotification("Failed to launch Aroma Updater");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
holdForXFrames = 0;
|
||||
|
12
src/common.h
12
src/common.h
@ -1,5 +1,9 @@
|
||||
#pragma once
|
||||
#define SD_CARD_PATH "fs:/vol/external01/"
|
||||
#define AROMA_UPDATER_PATH "wiiu/apps/AromaUpdater.wuhb"
|
||||
#define AROMA_UPDATER_PATH_FULL SD_CARD_PATH AROMA_UPDATER_PATH
|
||||
#define AROMA_UPDATER_LAST_UPDATE_URL "https://aroma.foryour.cafe/api/latest_version"
|
||||
#define SD_CARD_PATH "fs:/vol/external01/"
|
||||
#define AROMA_UPDATER_OLD_PATH "wiiu/apps/AromaUpdater.wuhb"
|
||||
#define AROMA_UPDATER_NEW_DIRECTORY "wiiu/apps/AromaUpdater"
|
||||
#define AROMA_UPDATER_NEW_PATH AROMA_UPDATER_NEW_DIRECTORY "/AromaUpdater.wuhb"
|
||||
#define AROMA_UPDATER_OLD_PATH_FULL SD_CARD_PATH AROMA_UPDATER_OLD_PATH
|
||||
#define AROMA_UPDATER_NEW_PATH_FULL SD_CARD_PATH AROMA_UPDATER_NEW_PATH
|
||||
#define AROMA_UPDATER_NEW_DIRECTORY_FULL SD_CARD_PATH AROMA_UPDATER_NEW_DIRECTORY
|
||||
#define AROMA_UPDATER_LAST_UPDATE_URL "https://aroma.foryour.cafe/api/latest_version"
|
42
src/main.cpp
42
src/main.cpp
@ -1,6 +1,7 @@
|
||||
#include "main.h"
|
||||
#include "Hints.h"
|
||||
#include "UpdaterCheck.h"
|
||||
#include "common.h"
|
||||
#include "utils/DownloadUtils.h"
|
||||
#include "utils/LatestVersion.h"
|
||||
#include "utils/config.h"
|
||||
@ -71,6 +72,45 @@ bool InitConfigValuesFromStorage() {
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* Migrates wiiu/apps/AromaUpdater.wuhb to wiiu/apps/AromaUpdater/AromaUpdater.wuhb
|
||||
*/
|
||||
void MigrateAromaUpdater() {
|
||||
struct stat st {};
|
||||
bool oldExists = false;
|
||||
bool newExists = false;
|
||||
if (stat(AROMA_UPDATER_NEW_PATH_FULL, &st) >= 0 && S_ISREG(st.st_mode)) {
|
||||
DEBUG_FUNCTION_LINE_VERBOSE("\"%s\" exists", AROMA_UPDATER_NEW_PATH_FULL);
|
||||
newExists = true;
|
||||
}
|
||||
st = {};
|
||||
if (stat(AROMA_UPDATER_OLD_PATH_FULL, &st) >= 0 && S_ISREG(st.st_mode)) {
|
||||
DEBUG_FUNCTION_LINE_VERBOSE("\"%s\" exists", AROMA_UPDATER_OLD_PATH_FULL);
|
||||
oldExists = true;
|
||||
}
|
||||
if (newExists) {
|
||||
if (oldExists) {
|
||||
if (remove(AROMA_UPDATER_OLD_PATH_FULL) < 0) {
|
||||
DEBUG_FUNCTION_LINE_WARN("Failed to remove old Aroma Updater: %d", errno);
|
||||
}
|
||||
} else {
|
||||
DEBUG_FUNCTION_LINE_VERBOSE("Only new AromaUpdater.wuhb exists");
|
||||
}
|
||||
return;
|
||||
} else if (oldExists) {
|
||||
if (stat(AROMA_UPDATER_NEW_DIRECTORY_FULL, &st) < 0 || !S_ISDIR(st.st_mode)) {
|
||||
if (mkdir(AROMA_UPDATER_NEW_DIRECTORY_FULL, 0777) < 0) {
|
||||
DEBUG_FUNCTION_LINE_WARN("Failed to create: \"%s\"", AROMA_UPDATER_NEW_DIRECTORY_FULL);
|
||||
}
|
||||
}
|
||||
if (rename(AROMA_UPDATER_OLD_PATH_FULL, AROMA_UPDATER_NEW_PATH_FULL) < 0) {
|
||||
DEBUG_FUNCTION_LINE_WARN("Failed to move Aroma Updater to new path");
|
||||
}
|
||||
} else {
|
||||
DEBUG_FUNCTION_LINE_VERBOSE("No AromaUpdater.wuhb exists");
|
||||
}
|
||||
}
|
||||
|
||||
INITIALIZE_PLUGIN() {
|
||||
initLogging();
|
||||
if (NotificationModule_InitLibrary() != NOTIFICATION_MODULE_RESULT_SUCCESS) {
|
||||
@ -86,6 +126,8 @@ INITIALIZE_PLUGIN() {
|
||||
InitConfigValuesFromStorage();
|
||||
|
||||
InitConfigMenu();
|
||||
|
||||
MigrateAromaUpdater();
|
||||
}
|
||||
|
||||
ON_APPLICATION_START() {
|
||||
|
Loading…
Reference in New Issue
Block a user