From beedc7513c114b25d0aff2c7a41b085f6e794690 Mon Sep 17 00:00:00 2001 From: Maschell Date: Wed, 2 Feb 2022 19:57:14 +0100 Subject: [PATCH] Format the code via clang-format (#3) --- .clang-format | 66 ++++++++++++++++++++++++++++++++++++++ .github/workflows/ci.yml | 16 ++++----- .github/workflows/pr.yml | 15 +++++---- README.md | 5 +++ source/ACTAccountInfo.h | 3 ++ source/BootUtils.cpp | 30 ++++++++--------- source/DrawUtils.cpp | 10 +++--- source/MenuUtils.cpp | 36 ++++++++++----------- source/MenuUtils.h | 22 +++++++------ source/QuickStartUtils.cpp | 16 ++++----- source/StorageUtils.cpp | 8 ++--- source/logger.cpp | 6 ++-- source/logger.h | 13 ++++---- source/main.cpp | 12 +++---- 14 files changed, 168 insertions(+), 90 deletions(-) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..92399ef --- /dev/null +++ b/.clang-format @@ -0,0 +1,66 @@ +# Generated from CLion C/C++ Code Style settings +BasedOnStyle: LLVM +AccessModifierOffset: -4 +AlignAfterOpenBracket: Align +AlignConsecutiveAssignments: None +AlignOperands: Align +AllowAllArgumentsOnNextLine: false +AllowAllConstructorInitializersOnNextLine: false +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortBlocksOnASingleLine: Always +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: All +AllowShortIfStatementsOnASingleLine: Always +AllowShortLambdasOnASingleLine: All +AllowShortLoopsOnASingleLine: true +AlwaysBreakAfterReturnType: None +AlwaysBreakTemplateDeclarations: Yes +BreakBeforeBraces: Custom +BraceWrapping: + AfterCaseLabel: false + AfterClass: false + AfterControlStatement: Never + AfterEnum: false + AfterFunction: false + AfterNamespace: false + AfterUnion: false + BeforeCatch: false + BeforeElse: false + IndentBraces: false + SplitEmptyFunction: false + SplitEmptyRecord: true +BreakBeforeBinaryOperators: None +BreakBeforeTernaryOperators: true +BreakConstructorInitializers: BeforeColon +BreakInheritanceList: BeforeColon +ColumnLimit: 0 +CompactNamespaces: false +ContinuationIndentWidth: 8 +IndentCaseLabels: true +IndentPPDirectives: None +IndentWidth: 4 +KeepEmptyLinesAtTheStartOfBlocks: true +MaxEmptyLinesToKeep: 2 +NamespaceIndentation: All +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PointerAlignment: Right +ReflowComments: false +SpaceAfterCStyleCast: true +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: false +SpaceBeforeAssignmentOperators: true +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatements +SpaceBeforeRangeBasedForLoopColon: true +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 0 +SpacesInAngles: false +SpacesInCStyleCastParentheses: false +SpacesInContainerLiterals: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +TabWidth: 4 +UseTab: Never diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5e1837e..08e214a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,18 +6,18 @@ on: - main jobs: - - build-binary: + clang-format: runs-on: ubuntu-18.04 steps: - uses: actions/checkout@v2 - - name: Checkout submodules using a PAT + - name: clang-format run: | - git config --file .gitmodules --get-regexp url | while read url; do - git config --file=.gitmodules $(echo "$url" | sed -E "s/git@github.com:|https:\/\/github.com\//https:\/\/${{ secrets.CI_PAT }}:${{ secrets.CI_PAT }}@github.com\//") - done - git submodule sync - git submodule update --init --recursive + docker run --rm -v ${PWD}:/src wiiuenv/clang-format:13.0.0-2 -r ./source + build-binary: + runs-on: ubuntu-18.04 + needs: clang-format + steps: + - uses: actions/checkout@v2 - name: build binary run: | docker build . -t builder diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 8e28a5f..7464b72 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -3,17 +3,18 @@ name: CI-PR on: [pull_request] jobs: - build-binary: + clang-format: runs-on: ubuntu-18.04 steps: - uses: actions/checkout@v2 - - name: Checkout submodules using a PAT + - name: clang-format run: | - git config --file .gitmodules --get-regexp url | while read url; do - git config --file=.gitmodules $(echo "$url" | sed -E "s/git@github.com:|https:\/\/github.com\//https:\/\/${{ secrets.CI_PAT }}:${{ secrets.CI_PAT }}@github.com\//") - done - git submodule sync - git submodule update --init --recursive + docker run --rm -v ${PWD}:/src wiiuenv/clang-format:13.0.0-2 -r ./source + build-binary: + runs-on: ubuntu-18.04 + needs: clang-format + steps: + - uses: actions/checkout@v2 - name: build binary run: | docker build . -t builder diff --git a/README.md b/README.md index 7c613e0..d845234 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,4 @@ +[![CI-Release](https://github.com/wiiu-env/AutobootModule/actions/workflows/ci.yml/badge.svg)](https://github.com/wiiu-env/AutobootModule/actions/workflows/ci.yml) # AutobootModule This is a bootmenu targetted to be loaded with the [EnvironmentLoader](https://github.com/wiiu-env/EnvironmentLoader). It allows you to boot into the Wii U Menu, Homebrew Channel, vWii System Menu or vWii Homebrew Channel. @@ -33,6 +34,10 @@ docker run -it --rm -v ${PWD}:/project autobootmodule-builder make docker run -it --rm -v ${PWD}:/project autobootmodule-builder make clean ``` +## Format the code via docker + +`docker run --rm -v ${PWD}:/src wiiuenv/clang-format:13.0.0-2 -r ./source -i` + ## Credits - GaryOderNichts - Maschell \ No newline at end of file diff --git a/source/ACTAccountInfo.h b/source/ACTAccountInfo.h index a43b31d..a32ad11 100644 --- a/source/ACTAccountInfo.h +++ b/source/ACTAccountInfo.h @@ -1,4 +1,7 @@ #pragma once +#include +#include +#include class AccountInfo { public: diff --git a/source/BootUtils.cpp b/source/BootUtils.cpp index 178db92..386b57a 100644 --- a/source/BootUtils.cpp +++ b/source/BootUtils.cpp @@ -1,26 +1,26 @@ -#include -#include -#include -#include -#include #include +#include +#include +#include #include +#include +#include +#include "ACTAccountInfo.h" #include "BootUtils.h" -#include "logger.h" #include "DrawUtils.h" #include "MenuUtils.h" -#include "ACTAccountInfo.h" +#include "logger.h" #include #include -#include +#include #include +#include +#include #include #include -#include #include -#include #include @@ -32,9 +32,9 @@ void bootWiiUMenu() { nn::act::SlotNo defaultSlot = nn::act::GetDefaultAccount(); nn::act::Finalize(); - if (defaultSlot) { //normal menu boot + if (defaultSlot) {//normal menu boot SYSLaunchMenu(); - } else { //show mii select + } else {//show mii select _SYSLaunchMenuWithCheckingAccount(slot); } } @@ -50,7 +50,7 @@ void handleAccountSelection() { nn::act::Initialize(); nn::act::SlotNo defaultSlot = nn::act::GetDefaultAccount(); - if (!defaultSlot) { // No default account is set. + if (!defaultSlot) {// No default account is set. std::vector> accountInfoList; for (int32_t i = 0; i < 13; i++) { if (!nn::act::IsSlotOccupied(i)) { @@ -134,9 +134,9 @@ void bootHomebrewChannel() { // test if the OHBC or HBC is installed if (IOSUHAX_FSA_GetStat(fsaFd, "/vol/storage_slccmpt01/title/00010001/4f484243/content/00000000.app", &stat) >= 0) { - titleId = 0x000100014F484243L; // 'OHBC' + titleId = 0x000100014F484243L;// 'OHBC' } else if (IOSUHAX_FSA_GetStat(fsaFd, "/vol/storage_slccmpt01/title/00010001/4c554c5a/content/00000000.app", &stat) >= 0) { - titleId = 0x000100014C554C5AL; // 'LULZ' + titleId = 0x000100014C554C5AL;// 'LULZ' } else { DEBUG_FUNCTION_LINE("Cannot find HBC, booting vWii System Menu"); } diff --git a/source/DrawUtils.cpp b/source/DrawUtils.cpp index 2637c67..0aad4de 100644 --- a/source/DrawUtils.cpp +++ b/source/DrawUtils.cpp @@ -2,11 +2,11 @@ #include #include +#include #include #include -#include -#include #include +#include #include FT_FREETYPE_H #include "MenuUtils.h" @@ -266,7 +266,8 @@ void DrawUtils::print(uint32_t x, uint32_t y, const char *string, bool alignRigh buffer[num] = 0; } else { wchar_t *tmp = buffer; - while ((*tmp++ = *string++)); + while ((*tmp++ = *string++)) + ; } print(x, y, buffer, alignRight); @@ -306,7 +307,8 @@ uint32_t DrawUtils::getTextWidth(const char *string) { buffer[num] = 0; } else { wchar_t *tmp = buffer; - while ((*tmp++ = *string++)); + while ((*tmp++ = *string++)) + ; } uint32_t width = getTextWidth(buffer); diff --git a/source/MenuUtils.cpp b/source/MenuUtils.cpp index c049a48..5066b30 100644 --- a/source/MenuUtils.cpp +++ b/source/MenuUtils.cpp @@ -1,20 +1,20 @@ -#include -#include -#include -#include -#include #include "MenuUtils.h" #include "DrawUtils.h" +#include +#include +#include +#include +#include -#include #include -#include +#include #include -#include #include +#include +#include -#include "icon_png.h" #include "ACTAccountInfo.h" +#include "icon_png.h" #include "logger.h" const char *menu_options[] = { @@ -31,13 +31,13 @@ const char *autoboot_config_strings[] = { "vwii_homebrew_channel", }; -template -std::string string_format(const std::string &format, Args ... args) { - int size_s = std::snprintf(nullptr, 0, format.c_str(), args ...) + 1; // Extra space for '\0' - auto size = static_cast( size_s ); +template +std::string string_format(const std::string &format, Args... args) { + int size_s = std::snprintf(nullptr, 0, format.c_str(), args...) + 1;// Extra space for '\0' + auto size = static_cast(size_s); auto buf = std::make_unique(size); - std::snprintf(buf.get(), size, format.c_str(), args ...); - return std::string(buf.get(), buf.get() + size - 1); // We don't want the '\0' inside + std::snprintf(buf.get(), size, format.c_str(), args...); + return std::string(buf.get(), buf.get() + size - 1);// We don't want the '\0' inside } int32_t readAutobootOption(std::string &configPath) { @@ -220,9 +220,9 @@ nn::act::SlotNo handleAccountSelectScreen(const std::vectormiiImageBuffer[col + 1])[0]; - if (colVal == 0x00808080) { // Remove the green background. + if (colVal == 0x00808080) {// Remove the green background. DrawUtils::drawPixel(x + xOffset, y + yOffset, COLOR_BACKGROUND.r, COLOR_BACKGROUND.g, COLOR_BACKGROUND.b, COLOR_BACKGROUND.a); } else { DrawUtils::drawPixel(x + xOffset, y + yOffset, val->miiImageBuffer[col + 1], val->miiImageBuffer[col + 2], val->miiImageBuffer[col + 3], val->miiImageBuffer[col]); @@ -289,7 +289,7 @@ nn::act::SlotNo handleAccountSelectScreen(const std::vectorslot; } diff --git a/source/MenuUtils.h b/source/MenuUtils.h index 0dab2ef..a0527b3 100644 --- a/source/MenuUtils.h +++ b/source/MenuUtils.h @@ -1,20 +1,22 @@ #pragma once +#include "ACTAccountInfo.h" #include -#include #include #include +#include #include -#include "ACTAccountInfo.h" -#define COLOR_WHITE Color(0xffffffff) -#define COLOR_BLACK Color(0, 0, 0, 255) -#define COLOR_BACKGROUND COLOR_BLACK -#define COLOR_TEXT COLOR_WHITE -#define COLOR_TEXT2 Color(0xB3ffffff) -#define COLOR_AUTOBOOT Color(0xaeea00ff) -#define COLOR_BORDER Color(204, 204, 204, 255) -#define COLOR_BORDER_HIGHLIGHTED Color(0x3478e4ff) +// clang-format off +#define COLOR_WHITE Color(0xffffffff) +#define COLOR_BLACK Color(0, 0, 0, 255) +#define COLOR_BACKGROUND COLOR_BLACK +#define COLOR_TEXT COLOR_WHITE +#define COLOR_TEXT2 Color(0xB3ffffff) +#define COLOR_AUTOBOOT Color(0xaeea00ff) +#define COLOR_BORDER Color(204, 204, 204, 255) +#define COLOR_BORDER_HIGHLIGHTED Color(0x3478e4ff) +// clang-format on enum { BOOT_OPTION_WII_U_MENU, diff --git a/source/QuickStartUtils.cpp b/source/QuickStartUtils.cpp index ee10278..7eefae7 100644 --- a/source/QuickStartUtils.cpp +++ b/source/QuickStartUtils.cpp @@ -1,20 +1,20 @@ #include +#include "BootUtils.h" #include "QuickStartUtils.h" #include "logger.h" -#include "BootUtils.h" #include -#include -#include #include +#include +#include #include #include #include #include -#include -#include #include +#include +#include extern "C" void __fini_wut(); @@ -87,7 +87,7 @@ bool getQuickBoot() { if (bootCheck == 0) { nn::sl::Initialize(MEMAllocFromDefaultHeapEx, MEMFreeToDefaultHeap); char path[0x80]; - nn::sl::GetDefaultDatabasePath(path, 0x80, 0x0005001010066000); // ECO process + nn::sl::GetDefaultDatabasePath(path, 0x80, 0x0005001010066000);// ECO process FSCmdBlock cmdBlock; FSInitCmdBlock(&cmdBlock); @@ -101,7 +101,7 @@ bool getQuickBoot() { auto database = new nn::sl::LaunchInfoDatabase; database->Load(fileStream, nn::sl::REGION_EUR); - CCRAppLaunchParam data; // load sys caffeine data + CCRAppLaunchParam data;// load sys caffeine data // load app launch param CCRSysCaffeineGetAppLaunchParam(&data); @@ -197,7 +197,7 @@ bool getQuickBoot() { return true; } - if (info.titleId == 0x0005001010004000L) { // OSv0 + if (info.titleId == 0x0005001010004000L) {// OSv0 DEBUG_FUNCTION_LINE("Launching vWii System Menu"); bootvWiiMenu(); diff --git a/source/StorageUtils.cpp b/source/StorageUtils.cpp index 2e20636..38e69af 100644 --- a/source/StorageUtils.cpp +++ b/source/StorageUtils.cpp @@ -6,8 +6,8 @@ #include #include -#include #include +#include #include #include @@ -56,8 +56,7 @@ static int numberUSBStorageDevicesConnected() { UhsInterfaceProfile profiles[10]; UhsInterfaceFilter filter = { - .match_params = MATCH_ANY - }; + .match_params = MATCH_ANY}; UHSStatus result; if ((result = UhsQueryInterfaces(handle, &filter, profiles, 10)) <= UHS_STATUS_OK) { @@ -106,7 +105,7 @@ void initExternalStorage() { int tries = 0; bool found = false; - while (tries < 1200) { // Wait up to 20 seconds, like the Wii U Menu + while (tries < 1200) {// Wait up to 20 seconds, like the Wii U Menu int32_t numItems = nn::spm::GetStorageList(items, 0x20); DEBUG_FUNCTION_LINE("Number of items: %d", numItems); @@ -141,4 +140,3 @@ void initExternalStorage() { nn::spm::Finalize(); } - diff --git a/source/logger.cpp b/source/logger.cpp index 3169c74..05d2661 100644 --- a/source/logger.cpp +++ b/source/logger.cpp @@ -3,8 +3,8 @@ #ifdef DEBUG #include #include -#include #include +#include uint32_t moduleLogInit = false; uint32_t cafeLogInit = false; @@ -17,7 +17,7 @@ void initLogging() { cafeLogInit = WHBLogCafeInit(); udpLogInit = WHBLogUdpInit(); } -#endif // DEBUG +#endif// DEBUG } void deinitLogging() { @@ -34,5 +34,5 @@ void deinitLogging() { WHBLogUdpDeinit(); udpLogInit = false; } -#endif // DEBUG +#endif// DEBUG } \ No newline at end of file diff --git a/source/logger.h b/source/logger.h index 5b1bd51..c6b5e29 100644 --- a/source/logger.h +++ b/source/logger.h @@ -1,7 +1,7 @@ #pragma once -#include #include +#include #ifdef __cplusplus extern "C" { @@ -12,12 +12,14 @@ extern "C" { #define __FILENAME_X__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__) #define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILENAME_X__) -#define DEBUG_FUNCTION_LINE(FMT, ARGS...)do { \ - WHBLogPrintf("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \ +#define DEBUG_FUNCTION_LINE(FMT, ARGS...) \ + do { \ + WHBLogPrintf("[%23s]%30s@L%04d: " FMT "", __FILENAME__, __FUNCTION__, __LINE__, ##ARGS); \ } while (0) -#define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...)do { \ - WHBLogWritef("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \ +#define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...) \ + do { \ + WHBLogWritef("[%23s]%30s@L%04d: " FMT "", __FILENAME__, __FUNCTION__, __LINE__, ##ARGS); \ } while (0) #else @@ -35,4 +37,3 @@ void deinitLogging(); #ifdef __cplusplus } #endif - diff --git a/source/main.cpp b/source/main.cpp index 2f443c8..b476194 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -1,12 +1,12 @@ +#include "DrawUtils.h" +#include "QuickStartUtils.h" +#include "StorageUtils.h" +#include "logger.h" +#include +#include #include #include #include -#include -#include -#include "StorageUtils.h" -#include "QuickStartUtils.h" -#include "DrawUtils.h" -#include "logger.h" #include "BootUtils.h" #include "MenuUtils.h"