diff --git a/Dockerfile b/Dockerfile index 38ecc0c..8d21833 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,5 @@ FROM wiiuenv/devkitppc:20221228 +COPY --from=wiiuenv/libmocha:20220919 /artifacts $DEVKITPRO + WORKDIR /project diff --git a/Makefile b/Makefile index 36c8d89..1533826 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/source/UpdaterCheckEnvironment.cpp b/source/UpdaterCheckEnvironment.cpp new file mode 100644 index 0000000..bd7d0f4 --- /dev/null +++ b/source/UpdaterCheckEnvironment.cpp @@ -0,0 +1,70 @@ +#include "UpdaterState.h" +#include "utils/logger.h" +#include + +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"); + } +} diff --git a/source/UpdaterState.cpp b/source/UpdaterState.cpp index 1ee9c1b..71504ac 100644 --- a/source/UpdaterState.cpp +++ b/source/UpdaterState.cpp @@ -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"; -} +} \ No newline at end of file diff --git a/source/UpdaterState.h b/source/UpdaterState.h index ceac0a3..d6b2d07 100644 --- a/source/UpdaterState.h +++ b/source/UpdaterState.h @@ -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 mCurFile = {}; + std::string mCurEnvironmentPath = {}; + std::mutex mVersionInfoLock; std::thread *mCheckFilesThread = nullptr; std::thread *mDownloadInfoThread = nullptr; diff --git a/source/UpdaterStateCheckVersions.cpp b/source/UpdaterStateCheckVersions.cpp index 818c1fd..21d53c5 100644 --- a/source/UpdaterStateCheckVersions.cpp +++ b/source/UpdaterStateCheckVersions.cpp @@ -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; } diff --git a/source/common.h b/source/common.h index 3f9a9af..4865cd3 100644 --- a/source/common.h +++ b/source/common.h @@ -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 \ No newline at end of file +#define UPDATER_VERSION "v0.1" +#define UPDATER_VERSION_FULL UPDATER_VERSION UPDATER_VERSION_EXTRA \ No newline at end of file diff --git a/source/main.cpp b/source/main.cpp index 02be9f5..4bc46c4 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -7,6 +7,7 @@ #include "utils/logger.h" #include #include +#include #include #include @@ -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();