Support updating when not running in aroma environment

This commit is contained in:
Maschell 2023-01-19 13:05:56 +01:00
parent afcaeb32f6
commit 2784ec4c7f
8 changed files with 119 additions and 13 deletions

View File

@ -1,3 +1,5 @@
FROM wiiuenv/devkitppc:20221228
COPY --from=wiiuenv/libmocha:20220919 /artifacts $DEVKITPRO
WORKDIR /project

View File

@ -19,6 +19,8 @@ APP_AUTHOR := Maschell
include $(DEVKITPRO)/wut/share/wut_rules
WUMS_ROOT := $(DEVKITPRO)/wums
#-------------------------------------------------------------------------------
# TARGET is the name of the output
# BUILD is the directory where object files & intermediate files will be placed
@ -61,13 +63,13 @@ CXXFLAGS += -DDEBUG -DVERBOSE_DEBUG -g
CFLAGS += -DDEBUG -DVERBOSE_DEBUG -g
endif
LIBS :=-lcurl -lmbedtls -lmbedx509 -lmbedcrypto -lz -lwut
LIBS :=-lcurl -lmbedtls -lmbedx509 -lmbedcrypto -lz -lmocha -lwut
#-------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level
# containing include and lib
#-------------------------------------------------------------------------------
LIBDIRS := $(PORTLIBS) $(WUT_ROOT)
LIBDIRS := $(PORTLIBS) $(WUT_ROOT) $(WUT_ROOT)/usr $(WUMS_ROOT)
#-------------------------------------------------------------------------------
# no real need to edit anything past this point unless you need to add additional

View File

@ -0,0 +1,70 @@
#include "UpdaterState.h"
#include "utils/logger.h"
#include <mocha/mocha.h>
ApplicationState::eSubState UpdaterState::UpdateGetEnvironmentDirectory(Input *input) {
char environmentPathBuffer[0x100];
MochaUtilsStatus status;
if ((status = Mocha_GetEnvironmentPath(environmentPathBuffer, sizeof(environmentPathBuffer))) == MOCHA_RESULT_SUCCESS) {
this->mCurEnvironmentPath = environmentPathBuffer;
DEBUG_FUNCTION_LINE("The environment path is %s", this->mCurEnvironmentPath.c_str());
} else {
DEBUG_FUNCTION_LINE_ERR("Failed to get the environment path. %s", Mocha_GetStatusStr(status));
this->mCurEnvironmentPath = {};
}
this->mState = STATE_CHECK_ENVIRONMENT_DIRECTORY;
return SUBSTATE_RUNNING;
}
ApplicationState::eSubState UpdaterState::UpdateCheckEnvironmentDirectory(Input *input) {
if (this->mCurEnvironmentPath == DEFAULT_AROMA_ENVIRONMENT_SD_PATH) {
this->mState = STATE_CHECK_VERSIONS;
}
if (buttonPressed(input, Input::BUTTON_A)) {
std::string sNeedle = DEFAULT_AROMA_ENVIRONMENT_PATH;
std::string sReplace = this->mCurEnvironmentPath;
if (sReplace.starts_with(SD_PATH)) {
sReplace = sReplace.substr(strlen(SD_PATH));
}
for (auto &base : mVersionInfo) {
for (auto &cat : base.getMutableCategory()) {
for (auto &package : cat.getMutablePackages()) {
for (auto &repo : package.getMutableRepositories()) {
for (auto &file : repo.getMutableFiles()) {
if (file.getPath().find(sNeedle) != std::string::npos) {
try {
file.getMutablePath().replace(file.getMutablePath().find(sNeedle), sNeedle.size(), sReplace);
} catch (std::exception &e) {
DEBUG_FUNCTION_LINE_WARN("%s", e.what());
}
}
}
}
}
}
}
this->mState = STATE_CHECK_VERSIONS;
} else if (buttonPressed(input, Input::BUTTON_X) || buttonPressed(input, Input::BUTTON_1)) {
this->mState = STATE_CHECK_VERSIONS;
}
return SUBSTATE_RUNNING;
}
void UpdaterState::RenderCheckEnvironmentDirectory() {
if (this->mCurEnvironmentPath != DEFAULT_AROMA_ENVIRONMENT_PATH) {
DrawUtils::setFontColor(COLOR_RED);
DrawUtils::setFontSize(30);
DrawUtils::print(16, 90, "Warning");
DrawUtils::setFontColor(COLOR_WHITE);
DrawUtils::setFontSize(20);
std::string curEnvironmentDir = std::filesystem::path(this->mCurEnvironmentPath).filename();
DrawUtils::print(16, 140, "By default the \"aroma\" environment will be updated, but the updater was launched");
DrawUtils::printf(16, 160, false, "in the \"%s\" environment.", curEnvironmentDir.c_str());
DrawUtils::printf(16, 220, false, "Press \ue042 to update the \"%s\" environment", curEnvironmentDir.c_str());
DrawUtils::printf(16, 240, false, "Press \ue04e/\ue047 to update the \"aroma\" environment");
}
}

View File

@ -46,6 +46,12 @@ ApplicationState::eSubState UpdaterState::update(Input *input) {
case STATE_PARSE_VERSIONS: {
return UpdaterState::UpdateParseVersions(input);
}
case STATE_GET_ENVIRONMENT_DIRECTORY: {
return UpdaterState::UpdateGetEnvironmentDirectory(input);
}
case STATE_CHECK_ENVIRONMENT_DIRECTORY: {
return UpdaterState::UpdateCheckEnvironmentDirectory(input);
}
case STATE_CHECK_VERSIONS: {
return UpdaterState::UpdateCheckVersions(input);
}
@ -181,6 +187,13 @@ void UpdaterState::render() {
DrawUtils::print(16, 80, "Parsing the latest versions...");
break;
}
case STATE_GET_ENVIRONMENT_DIRECTORY: {
break;
};
case STATE_CHECK_ENVIRONMENT_DIRECTORY: {
UpdaterState::RenderCheckEnvironmentDirectory();
break;
};
case STATE_CHECK_VERSIONS: {
DrawUtils::setFontColor(COLOR_WHITE);
DrawUtils::setFontSize(20);
@ -322,4 +335,4 @@ const char *UpdaterState::ErrorDescription() const {
return "ERROR_FAILED_TO_CREATE_DIR";
}
return "UNKNOWN_ERROR";
}
}

View File

@ -61,6 +61,8 @@ public:
STATE_ERROR,
STATE_DOWNLOAD_VERSIONS,
STATE_PARSE_VERSIONS,
STATE_GET_ENVIRONMENT_DIRECTORY,
STATE_CHECK_ENVIRONMENT_DIRECTORY,
STATE_CHECK_VERSIONS,
STATE_SHOW_VERSIONS,
STATE_SELECTED_PACKAGES_EMPTY,
@ -106,6 +108,7 @@ public:
void RenderError();
void RenderDownloadVersions();
void RenderCheckEnvironmentDirectory();
void RenderShowVersions();
void RenderConfirmPackages();
void RenderCheckIndividualFile();
@ -113,6 +116,8 @@ public:
ApplicationState::eSubState UpdateProcessDownloadFiles(Input *input);
ApplicationState::eSubState UpdateDownloadVersions(Input *input);
ApplicationState::eSubState UpdateGetEnvironmentDirectory(Input *input);
ApplicationState::eSubState UpdateCheckEnvironmentDirectory(Input *input);
ApplicationState::eSubState UpdateParseVersions(Input *input);
ApplicationState::eSubState UpdateCheckVersions(Input *input);
ApplicationState::eSubState UpdateShowVersionsMenu(Input *input);
@ -150,6 +155,8 @@ public:
std::optional<VersionCheck::RepositoryFile> mCurFile = {};
std::string mCurEnvironmentPath = {};
std::mutex mVersionInfoLock;
std::thread *mCheckFilesThread = nullptr;
std::thread *mDownloadInfoThread = nullptr;

View File

@ -77,7 +77,7 @@ ApplicationState::eSubState UpdaterState::UpdateParseVersions(Input *input) {
this->setError(ERROR_FAILED_TO_PARSE_VERSIONS);
return SUBSTATE_RUNNING;
}
this->mState = STATE_CHECK_VERSIONS;
this->mState = STATE_GET_ENVIRONMENT_DIRECTORY;
return SUBSTATE_RUNNING;
}

View File

@ -1,13 +1,15 @@
#pragma once
#define BACKGROUND_COLOR COLOR_BLACK
#define BACKGROUND_COLOR COLOR_BLACK
#define AROMA_DOWNLOAD_URL "https://aroma.foryour.cafe/"
#define UPDATE_SERVER_URL "https://aroma.foryour.cafe"
#define CERT_FILE_LOCATION "fs:/vol/content/cacert.pem"
#define SD_PATH "fs:/vol/external01/"
#define UPDATE_OLD_SUFFIX ".update.old"
#define UPDATE_TEMP_SUFFIX ".update.temp"
#define AROMA_DOWNLOAD_URL "https://aroma.foryour.cafe/"
#define UPDATE_SERVER_URL "https://aroma.foryour.cafe"
#define CERT_FILE_LOCATION "fs:/vol/content/cacert.pem"
#define SD_PATH "fs:/vol/external01/"
#define DEFAULT_AROMA_ENVIRONMENT_PATH "wiiu/environments/aroma"
#define DEFAULT_AROMA_ENVIRONMENT_SD_PATH SD_PATH DEFAULT_AROMA_ENVIRONMENT_PATH
#define UPDATE_OLD_SUFFIX ".update.old"
#define UPDATE_TEMP_SUFFIX ".update.temp"
#define UPDATER_VERSION "v0.1"
#define UPDATER_VERSION_FULL UPDATER_VERSION UPDATER_VERSION_EXTRA
#define UPDATER_VERSION "v0.1"
#define UPDATER_VERSION_FULL UPDATER_VERSION UPDATER_VERSION_EXTRA

View File

@ -7,6 +7,7 @@
#include "utils/logger.h"
#include <coreinit/energysaver.h>
#include <filesystem>
#include <mocha/mocha.h>
#include <sndcore2/core.h>
#include <whb/proc.h>
@ -53,6 +54,11 @@ int main() {
OSFatal("Failed to init DownloadUtils");
}
int mochaInitResult;
if ((mochaInitResult = Mocha_InitLibrary()) != MOCHA_RESULT_SUCCESS) {
DEBUG_FUNCTION_LINE_ERR("Mocha_InitLibrary() failed %d", mochaInitResult);
}
uint32_t isAPDEnabled;
IMIsAPDEnabled(&isAPDEnabled);
@ -68,6 +74,10 @@ int main() {
IMEnableAPD();
}
if (mochaInitResult == MOCHA_RESULT_SUCCESS) {
Mocha_DeInitLibrary();
}
DownloadUtils::Deinit();
WPADInput::close();