diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..56cc685 --- /dev/null +++ b/.clang-format @@ -0,0 +1,67 @@ +# Generated from CLion C/C++ Code Style settings +BasedOnStyle: LLVM +AccessModifierOffset: -4 +AlignAfterOpenBracket: Align +AlignConsecutiveAssignments: Consecutive +AlignConsecutiveMacros: AcrossEmptyLinesAndComments +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: 1 +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 9f222b8..b988ac3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,8 +6,16 @@ on: - main jobs: + clang-format: + runs-on: ubuntu-18.04 + steps: + - uses: actions/checkout@v2 + - name: clang-format + run: | + docker run --rm -v ${PWD}:/src wiiuenv/clang-format:13.0.0-2 -r ./src build-binary: runs-on: ubuntu-18.04 + needs: clang-format steps: - uses: actions/checkout@v2 - name: build binary @@ -26,7 +34,7 @@ jobs: id: get_repository_name run: | echo REPOSITORY_NAME=$(echo "$GITHUB_REPOSITORY" | awk -F / '{print $2}' | sed -e "s/:refs//") >> $GITHUB_ENV - echo DATETIME=$(echo $(date '+%Y%m%d-%H%M%S')) >> $GITHUB_ENV + echo DATETIME=$(echo $(date '+%Y%m%d-%H%M%S')) >> $GITHUB_ENV - uses: actions/download-artifact@master with: name: binary diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index f21e109..423702f 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -3,8 +3,16 @@ name: CI-PR on: [pull_request] jobs: + clang-format: + runs-on: ubuntu-18.04 + steps: + - uses: actions/checkout@v2 + - name: clang-format + run: | + docker run --rm -v ${PWD}:/src wiiuenv/clang-format:13.0.0-2 -r ./src build-binary: runs-on: ubuntu-18.04 + needs: clang-format steps: - uses: actions/checkout@v2 - name: build binary diff --git a/README.md b/README.md index 29ef6e7..69502c3 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +[![CI-Release](https://github.com/wiiu-env/sdcafiine_plugin/actions/workflows/ci.yml/badge.svg)](https://github.com/wiiu-env/sdcafiine_plugin/actions/workflows/ci.yml) + # SDCafiine Plugin ## What is SDCafiine @@ -58,3 +60,7 @@ docker run -it --rm -v ${PWD}:/project sdcafiineplugin-builder make # make clean docker run -it --rm -v ${PWD}:/project sdcafiineplugin-builder make clean ``` + +## Format the code via docker + +`docker run --rm -v ${PWD}:/src wiiuenv/clang-format:13.0.0-2 -r ./src -i` \ No newline at end of file diff --git a/src/fs/DirList.cpp b/src/fs/DirList.cpp index b92437f..244af27 100644 --- a/src/fs/DirList.cpp +++ b/src/fs/DirList.cpp @@ -24,22 +24,22 @@ * DirList Class * for WiiXplorer 2010 ***************************************************************************/ +#include #include #include #include #include #include -#include -#include #include +#include #include #include DirList::DirList() { - Flags = 0; + Flags = 0; Filter = 0; - Depth = 0; + Depth = 0; } DirList::DirList(const std::string &path, const char *filter, uint32_t flags, uint32_t maxDepth) { @@ -54,9 +54,9 @@ DirList::~DirList() { BOOL DirList::LoadPath(const std::string &folder, const char *filter, uint32_t flags, uint32_t maxDepth) { if (folder.empty()) return false; - Flags = flags; + Flags = flags; Filter = filter; - Depth = maxDepth; + Depth = maxDepth; std::string folderpath(folder); uint32_t length = folderpath.size(); @@ -81,14 +81,14 @@ BOOL DirList::InternalLoadPath(std::string &folderpath) { return false; struct dirent *dirent = NULL; - DIR *dir = NULL; + DIR *dir = NULL; dir = opendir(folderpath.c_str()); if (dir == NULL) return false; while ((dirent = readdir(dir)) != 0) { - BOOL isDir = dirent->d_type & DT_DIR; + BOOL isDir = dirent->d_type & DT_DIR; const char *filename = dirent->d_name; if (isDir) { diff --git a/src/fs/DirList.h b/src/fs/DirList.h index ed36f97..c2dbaee 100644 --- a/src/fs/DirList.h +++ b/src/fs/DirList.h @@ -27,8 +27,8 @@ #ifndef ___DIRLIST_H_ #define ___DIRLIST_H_ -#include #include +#include #include typedef struct { @@ -60,7 +60,8 @@ public: //!\param list index const char *GetFilepath(int32_t index) const { if (!valid(index)) return ""; - else return FileInfo[index].FilePath; + else + return FileInfo[index].FilePath; } //! Get the a filesize of the list @@ -90,10 +91,11 @@ public: //! Enum for search/filter flags enum { - Files = 0x01, - Dirs = 0x02, + Files = 0x01, + Dirs = 0x02, CheckSubfolders = 0x08, }; + protected: // Internal parser BOOL InternalLoadPath(std::string &path); diff --git a/src/main.cpp b/src/main.cpp index 61a7499..aa05036 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,7 +1,7 @@ -#include -#include "utils/logger.h" #include "modpackSelector.h" +#include "utils/logger.h" #include +#include WUPS_PLUGIN_NAME("SDCafiine"); WUPS_PLUGIN_DESCRIPTION("Wiiload Server"); @@ -16,6 +16,6 @@ ON_APPLICATION_START() { initLogging(); HandleMultiModPacks(OSGetTitleID()); } -ON_APPLICATION_ENDS(){ +ON_APPLICATION_ENDS() { deinitLogging(); } \ No newline at end of file diff --git a/src/main.h b/src/main.h index 67b89ad..dbecffb 100644 --- a/src/main.h +++ b/src/main.h @@ -4,8 +4,8 @@ #ifdef __cplusplus extern "C" { #endif -#include #include +#include #ifdef __cplusplus diff --git a/src/modpackSelector.cpp b/src/modpackSelector.cpp index c9200b0..ff3c3eb 100644 --- a/src/modpackSelector.cpp +++ b/src/modpackSelector.cpp @@ -1,22 +1,22 @@ -#include -#include -#include -#include +#include "modpackSelector.h" #include #include +#include +#include #include -#include "modpackSelector.h" +#include +#include #include #include -#include -#include #include -#include +#include #include +#include +#include -#define TEXT_SEL(x, text1, text2) ((x) ? (text1) : (text2)) +#define TEXT_SEL(x, text1, text2) ((x) ? (text1) : (text2)) void ReplaceContent(const std::string &basePath); @@ -42,7 +42,7 @@ void HandleMultiModPacks(uint64_t titleID) { continue; } - std::string packageName = curFile; + std::string packageName = curFile; modTitlePath[packageName] = modTitleIDPath + "/" + curFile; DEBUG_FUNCTION_LINE("found %s", packageName.c_str()); } @@ -51,16 +51,15 @@ void HandleMultiModPacks(uint64_t titleID) { return; } - int selected = 0; + int selected = 0; int initScreen = 1; - int x_offset = -2; + int x_offset = -2; // Init screen and screen buffers OSScreenInit(); uint32_t screen_buf0_size = OSScreenGetBufferSizeEx(SCREEN_TV); uint32_t screen_buf1_size = OSScreenGetBufferSizeEx(SCREEN_DRC); - uint8_t *screenBuffer = (uint8_t *) MEMAllocFromMappedMemoryForGX2Ex(screen_buf0_size + screen_buf1_size, 0x100 - ); + uint8_t *screenBuffer = (uint8_t *) MEMAllocFromMappedMemoryForGX2Ex(screen_buf0_size + screen_buf1_size, 0x100); if (screenBuffer == nullptr) { DEBUG_FUNCTION_LINE("Failed to alloc"); return; @@ -82,9 +81,9 @@ void HandleMultiModPacks(uint64_t titleID) { VPADReadError error; int wantToExit = 0; - int page = 0; - int per_page = 13; - int max_pages = (modTitlePath.size() / per_page) + 1; + int page = 0; + int per_page = 13; + int max_pages = (modTitlePath.size() / per_page) + 1; while (true) { @@ -122,10 +121,10 @@ void HandleMultiModPacks(uint64_t titleID) { console_print_pos(x_offset, 1, "Select your options and press A to launch."); console_print_pos(x_offset, 2, "Press B to launch without mods"); int y_offset = 4; - int cur_ = 0; + int cur_ = 0; for (auto &it : modTitlePath) { - std::string key = it.first; + std::string key = it.first; std::string value = it.second; if (wantToExit && cur_ == selected) { @@ -189,7 +188,6 @@ void console_print_pos(int x, int y, const char *format, ...) { OSScreenPutFontEx(SCREEN_TV, x, y, tmp); OSScreenPutFontEx(SCREEN_DRC, x, y, tmp); - } va_end(va); diff --git a/src/modpackSelector.h b/src/modpackSelector.h index bb4763f..486155c 100644 --- a/src/modpackSelector.h +++ b/src/modpackSelector.h @@ -1,15 +1,14 @@ -#ifndef _MODPACK_SELECTOR_H_ -#define _MODPACK_SELECTOR_H_ +#pragma once + +#include #ifdef __cplusplus extern "C" { #endif -void HandleMultiModPacks(uint64_t titleid/*,bool showMenu = true*/); +void HandleMultiModPacks(uint64_t titleid /*,bool showMenu = true*/); void console_print_pos(int x, int y, const char *format, ...); #ifdef __cplusplus } -#endif - -#endif //_MODPACK_SELECTOR_H_ +#endif \ No newline at end of file diff --git a/src/utils/StringTools.cpp b/src/utils/StringTools.cpp index 39a5273..8cd2de3 100644 --- a/src/utils/StringTools.cpp +++ b/src/utils/StringTools.cpp @@ -23,17 +23,16 @@ * * for WiiXplorer 2010 ***************************************************************************/ -#include -#include -#include #include +#include #include -#include -#include +#include +#include #include -#include -#include #include +#include +#include +#include BOOL StringTools::EndsWith(const std::string &a, const std::string &b) { @@ -84,7 +83,7 @@ const wchar_t *StringTools::wfmt(const char *format, ...) { static char tmp[512]; static wchar_t strWChar[512]; strWChar[0] = 0; - tmp[0] = 0; + tmp[0] = 0; if (!format) return (const wchar_t *) strWChar; @@ -97,7 +96,7 @@ const wchar_t *StringTools::wfmt(const char *format, ...) { if ((vsprintf(tmp, format, va) >= 0)) { int bt; int32_t strlength = strlen(tmp); - bt = mbstowcs(strWChar, tmp, (strlength < 512) ? strlength : 512); + bt = mbstowcs(strWChar, tmp, (strlength < 512) ? strlength : 512); if (bt > 0) { strWChar[bt] = 0; @@ -111,13 +110,13 @@ const wchar_t *StringTools::wfmt(const char *format, ...) { int32_t StringTools::strprintf(std::string &str, const char *format, ...) { static char tmp[512]; - tmp[0] = 0; + tmp[0] = 0; int32_t result = 0; va_list va; va_start(va, format); if ((vsprintf(tmp, format, va) >= 0)) { - str = tmp; + str = tmp; result = str.size(); } va_end(va); diff --git a/src/utils/StringTools.h b/src/utils/StringTools.h index 5d9f2c4..fa53b7f 100644 --- a/src/utils/StringTools.h +++ b/src/utils/StringTools.h @@ -26,8 +26,8 @@ #ifndef __STRING_TOOLS_H #define __STRING_TOOLS_H -#include #include +#include #include class StringTools { @@ -55,7 +55,7 @@ public: static const char *FullpathToFilename(const char *path) { if (!path) return path; - const char *ptr = path; + const char *ptr = path; const char *Filename = ptr; while (*ptr != '\0') { @@ -85,4 +85,3 @@ public: }; #endif /* __STRING_TOOLS_H */ - diff --git a/src/utils/logger.c b/src/utils/logger.c index 0411db7..f700806 100644 --- a/src/utils/logger.c +++ b/src/utils/logger.c @@ -1,19 +1,19 @@ #ifdef DEBUG #include -#include #include #include +#include uint32_t moduleLogInit = false; -uint32_t cafeLogInit = false; -uint32_t udpLogInit = false; +uint32_t cafeLogInit = false; +uint32_t udpLogInit = false; #endif // DEBUG void initLogging() { #ifdef DEBUG if (!(moduleLogInit = WHBLogModuleInit())) { cafeLogInit = WHBLogCafeInit(); - udpLogInit = WHBLogUdpInit(); + udpLogInit = WHBLogUdpInit(); } #endif // DEBUG } diff --git a/src/utils/logger.h b/src/utils/logger.h index 6ff5ae2..061d52e 100644 --- a/src/utils/logger.h +++ b/src/utils/logger.h @@ -1,7 +1,7 @@ #pragma once -#include #include +#include #ifdef __cplusplus extern "C" { @@ -9,26 +9,28 @@ extern "C" { #ifdef DEBUG -#define __FILENAME_X__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__) -#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILENAME_X__) +#define __FILENAME_X__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__) +#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILENAME_X__) #define DEBUG_FUNCTION_LINE_VERBOSE(FMT, ARGS...) while (0) -#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 #define DEBUG_FUNCTION_LINE_VERBOSE(FMT, ARGS...) while (0) -#define DEBUG_FUNCTION_LINE(FMT, ARGS...) while (0) +#define DEBUG_FUNCTION_LINE(FMT, ARGS...) while (0) -#define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...) while (0) +#define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...) while (0) #endif @@ -39,4 +41,3 @@ void deinitLogging(); #ifdef __cplusplus } #endif -