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 6459e92..c7a722a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,10 +6,25 @@ on: - main jobs: - build-binary: - runs-on: ubuntu-18.04 + clang-format: + runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 + - name: clang-format + run: | + docker run --rm -v ${PWD}:/src ghcr.io/wiiu-env/clang-format:13.0.0-2 -r ./src + build-binary: + runs-on: ubuntu-22.04 + needs: clang-format + steps: + - uses: actions/checkout@v3 + - name: create version.h + run: | + git_hash=$(git rev-parse --short "$GITHUB_SHA") + cat < ./src/version.h + #pragma once + #define VERSION_EXTRA " (nightly-$git_hash)" + EOF - name: build binary run: | docker build . -t builder @@ -20,7 +35,7 @@ jobs: path: "*.wps" deploy-binary: needs: build-binary - runs-on: ubuntu-18.04 + runs-on: ubuntu-22.04 steps: - name: Get environment variables id: get_repository_name @@ -30,29 +45,15 @@ jobs: - uses: actions/download-artifact@master with: name: binary - path: wiiu/plugins - name: zip artifact - run: zip -r ${{ env.REPOSITORY_NAME }}_${{ env.DATETIME }}.zip wiiu + run: zip -r ${{ env.REPOSITORY_NAME }}_${{ env.DATETIME }}.zip *.wps - name: Create Release - id: create_release - uses: actions/create-release@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + uses: "softprops/action-gh-release@v1" with: tag_name: ${{ env.REPOSITORY_NAME }}-${{ env.DATETIME }} - release_name: Nightly-${{ env.REPOSITORY_NAME }}-${{ env.DATETIME }} draft: false prerelease: true - body: | - Not a stable release: - ${{ github.event.head_commit.message }} - - name: Upload Release Asset - id: upload-release-asset - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps - asset_path: ./${{ env.REPOSITORY_NAME }}_${{ env.DATETIME }}.zip - asset_name: ${{ env.REPOSITORY_NAME }}_${{ env.DATETIME }}.zip - asset_content_type: application/unknown \ No newline at end of file + generate_release_notes: true + name: Nightly-${{ env.REPOSITORY_NAME }}-${{ env.DATETIME }} + files: | + ./${{ env.REPOSITORY_NAME }}_${{ env.DATETIME }}.zip \ No newline at end of file diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index f21e109..481c44c 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -3,10 +3,36 @@ name: CI-PR on: [pull_request] jobs: - build-binary: - runs-on: ubuntu-18.04 + clang-format: + runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 + - name: clang-format + run: | + docker run --rm -v ${PWD}:/src ghcr.io/wiiu-env/clang-format:13.0.0-2 -r ./src + check-build-with-logging: + runs-on: ubuntu-22.04 + needs: clang-format + steps: + - uses: actions/checkout@v3 + - name: build binary with logging + run: | + docker build . -t builder + docker run --rm -v ${PWD}:/project builder make DEBUG=VERBOSE + docker run --rm -v ${PWD}:/project builder make clean + docker run --rm -v ${PWD}:/project builder make DEBUG=1 + build-binary: + runs-on: ubuntu-22.04 + needs: clang-format + steps: + - uses: actions/checkout@v3 + - name: create version.h + run: | + git_hash=$(git rev-parse --short "${{ github.event.pull_request.head.sha }}") + cat < ./src/version.h + #pragma once + #define VERSION_EXTRA " (nightly-$git_hash)" + EOF - name: build binary run: | docker build . -t builder diff --git a/src/ConfigHooks.cpp b/src/ConfigHooks.cpp index 30ea04e..3833104 100644 --- a/src/ConfigHooks.cpp +++ b/src/ConfigHooks.cpp @@ -15,36 +15,36 @@ * along with this program. If not, see . ****************************************************************************/ +#include "WUPSConfigItemPadMapping.h" +#include "utils/StringTools.h" +#include "utils/logger.h" +#include #include #include #include -#include -#include "utils/logger.h" -#include "utils/StringTools.h" -#include "WUPSConfigItemPadMapping.h" bool runNetworkClient = true; -void loadMapping(std::string& persistedValue, UController_Type type); +void loadMapping(std::string &persistedValue, UController_Type type); void ConfigLoad() { WUPS_OpenStorage(); bool rumble = 0; - if(WUPS_GetBool(nullptr, "rumble", &rumble) == WUPS_STORAGE_ERROR_SUCCESS){ + if (WUPS_GetBool(nullptr, "rumble", &rumble) == WUPS_STORAGE_ERROR_SUCCESS) { ControllerPatcher::setRumbleActivated(rumble); - }else{ + } else { WUPS_StoreBool(nullptr, "rumble", ControllerPatcher::isRumbleActivated()); } - if(WUPS_GetBool(nullptr, "networkclient", &runNetworkClient) != WUPS_STORAGE_ERROR_SUCCESS){ + if (WUPS_GetBool(nullptr, "networkclient", &runNetworkClient) != WUPS_STORAGE_ERROR_SUCCESS) { WUPS_StoreBool(nullptr, "networkclient", runNetworkClient); } char buffer[512]; - if(WUPS_GetString(nullptr, "gamepadmapping", buffer, sizeof(buffer)) == WUPS_STORAGE_ERROR_SUCCESS){ + if (WUPS_GetString(nullptr, "gamepadmapping", buffer, sizeof(buffer)) == WUPS_STORAGE_ERROR_SUCCESS) { std::string stringWrapper = buffer; loadMapping(stringWrapper, UController_Type_Gamepad); } @@ -52,36 +52,36 @@ void ConfigLoad() { WUPS_CloseStorage(); } -void loadMapping(std::string &persistedValue, UController_Type controllerType){ - if(persistedValue.empty()) { +void loadMapping(std::string &persistedValue, UController_Type controllerType) { + if (persistedValue.empty()) { // No device mapped. return; } std::vector result = StringTools::stringSplit(persistedValue, ","); - if(result.size() != 4) { + if (result.size() != 4) { return; } ControllerMappingPADInfo mappedPadInfo; mappedPadInfo.vidpid.vid = atoi(result.at(0).c_str()); mappedPadInfo.vidpid.pid = atoi(result.at(1).c_str()); - mappedPadInfo.pad = atoi(result.at(2).c_str()); - mappedPadInfo.type = CM_Type_Controller; //atoi(result.at(3).c_str()); + mappedPadInfo.pad = atoi(result.at(2).c_str()); + mappedPadInfo.type = CM_Type_Controller; //atoi(result.at(3).c_str()); ControllerPatcher::resetControllerMapping(controllerType); - ControllerPatcher::addControllerMapping(controllerType,mappedPadInfo); + ControllerPatcher::addControllerMapping(controllerType, mappedPadInfo); } -void rumbleChanged(ConfigItemBoolean * item, bool newValue) { - DEBUG_FUNCTION_LINE("rumbleChanged %d ",newValue); +void rumbleChanged(ConfigItemBoolean *item, bool newValue) { + DEBUG_FUNCTION_LINE("rumbleChanged %d ", newValue); ControllerPatcher::setRumbleActivated(newValue); WUPS_StoreInt(nullptr, "rumble", newValue); } -void networkClientChanged(ConfigItemBoolean * item, bool newValue) { - DEBUG_FUNCTION_LINE("Trigger network %d",newValue); +void networkClientChanged(ConfigItemBoolean *item, bool newValue) { + DEBUG_FUNCTION_LINE("Trigger network %d", newValue); ControllerPatcher::setNetworkControllerActivated(newValue); - if(newValue) { + if (newValue) { ControllerPatcher::startNetworkServer(); } else { ControllerPatcher::stopNetworkServer(); @@ -89,9 +89,9 @@ void networkClientChanged(ConfigItemBoolean * item, bool newValue) { WUPS_StoreInt(nullptr, "networkclient", newValue); } -void PadMappingUpdated(ConfigItemPadMapping * item) { - if(item->mappedPadInfo.active && item->mappedPadInfo.type == CM_Type_Controller){ - auto res = StringTools::strfmt("%d,%d,%d,%d",item->mappedPadInfo.vidpid.vid,item->mappedPadInfo.vidpid.pid,item->mappedPadInfo.pad,item->mappedPadInfo.type); +void PadMappingUpdated(ConfigItemPadMapping *item) { + if (item->mappedPadInfo.active && item->mappedPadInfo.type == CM_Type_Controller) { + auto res = StringTools::strfmt("%d,%d,%d,%d", item->mappedPadInfo.vidpid.vid, item->mappedPadInfo.vidpid.pid, item->mappedPadInfo.pad, item->mappedPadInfo.type); WUPS_StoreString(nullptr, item->configId, res.c_str()); } else { WUPS_StoreString(nullptr, item->configId, ""); @@ -99,26 +99,26 @@ void PadMappingUpdated(ConfigItemPadMapping * item) { } -WUPS_CONFIG_CLOSED(){ +WUPS_CONFIG_CLOSED() { WUPS_CloseStorage(); } -#define CONFIG_AddCategoryByName(config, name, callback) \ +#define CONFIG_AddCategoryByName(config, name, callback) \ if (WUPSConfig_AddCategoryByName(config, name, callback) < 0) { \ - WUPSConfig_Destroy(config); \ - return 0; \ + WUPSConfig_Destroy(config); \ + return 0; \ } - -#define CONFIG_Boolean_AddToCategoryEx(category, config_id, display_name, default_value, callback, true_value, false_value) \ - if (!WUPSConfigItemBoolean_AddToCategoryEx(category, config_id, display_name, default_value, callback, true_value, false_value)) { \ - WUPSConfig_Destroy(config); \ - return 0; \ - } -#define CONFIG_PadMapping_AddToCategory(category, config_id, display_name, controller_type, callback) \ +#define CONFIG_Boolean_AddToCategoryEx(category, config_id, display_name, default_value, callback, true_value, false_value) \ + if (!WUPSConfigItemBoolean_AddToCategoryEx(category, config_id, display_name, default_value, callback, true_value, false_value)) { \ + WUPSConfig_Destroy(config); \ + return 0; \ + } + +#define CONFIG_PadMapping_AddToCategory(category, config_id, display_name, controller_type, callback) \ if (!WUPSConfigItemPadMapping_AddToCategory(category, config_id, display_name, controller_type, callback)) { \ - WUPSConfig_Destroy(config); \ - return 0; \ + WUPSConfig_Destroy(config); \ + return 0; \ } @@ -129,10 +129,10 @@ WUPS_GET_CONFIG() { if (WUPSConfig_Create(&config, "HID to VPAD") < 0) { return 0; } - + WUPSConfigCategoryHandle catMapping; WUPSConfigCategoryHandle catOther; - + CONFIG_AddCategoryByName(config, "Mapping", &catMapping); CONFIG_AddCategoryByName(config, "Other", &catOther); diff --git a/src/FunctionPatches.cpp b/src/FunctionPatches.cpp index 2ec4d14..3fb2a21 100644 --- a/src/FunctionPatches.cpp +++ b/src/FunctionPatches.cpp @@ -26,100 +26,100 @@ DECL_FUNCTION(int32_t, VPADRead, VPADChan chan, VPADStatus *buffer, uint32_t buf bool do_callback = (result > 0 && (buffer[0].hold & VPAD_BUTTON_TV)); ControllerPatcher::handleCallbackData(do_callback); - if(ControllerPatcher::areControllersConnected() && buffer_size > 0) { - ControllerPatcher::setRumble(UController_Type_Gamepad,!!VPADBASEGetMotorOnRemainingCount(VPAD_CHAN_0)); + if (ControllerPatcher::areControllersConnected() && buffer_size > 0) { + ControllerPatcher::setRumble(UController_Type_Gamepad, !!VPADBASEGetMotorOnRemainingCount(VPAD_CHAN_0)); - if(ControllerPatcher::setControllerDataFromHID(buffer) == CONTROLLER_PATCHER_ERROR_NONE) { + if (ControllerPatcher::setControllerDataFromHID(buffer) == CONTROLLER_PATCHER_ERROR_NONE) { - if(buffer[0].hold & VPAD_BUTTON_HOME) { + if (buffer[0].hold & VPAD_BUTTON_HOME) { //You can open the home menu this way, but not close it. Need a proper way to close it using the same button... //OSSendAppSwitchRequest(5,0,0); //Open the home menu! } - if(error != nullptr) { + if (error != nullptr) { *error = VPAD_READ_SUCCESS; } result = 1; // We want the WiiU to ignore everything else. } } - if(ControllerPatcher::isButtonRemappingDone()) { - ControllerPatcher::buttonRemapping(buffer,result); + if (ControllerPatcher::isButtonRemappingDone()) { + ControllerPatcher::buttonRemapping(buffer, result); //ControllerPatcher::printVPADButtons(buffer); //Leads to random crashes on app transitions. } return result; } -DECL_FUNCTION(int32_t, WPADProbe, WPADChan chan, uint32_t * result ) { - if( (chan == WPAD_CHAN_0 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro1)) || - (chan == WPAD_CHAN_1 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro2)) || - (chan == WPAD_CHAN_2 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro3)) || - (chan == WPAD_CHAN_3 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro4))) { - if(result != nullptr) { +DECL_FUNCTION(int32_t, WPADProbe, WPADChan chan, uint32_t *result) { + if ((chan == WPAD_CHAN_0 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro1)) || + (chan == WPAD_CHAN_1 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro2)) || + (chan == WPAD_CHAN_2 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro3)) || + (chan == WPAD_CHAN_3 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro4))) { + if (result != nullptr) { *result = WPAD_EXT_PRO_CONTROLLER; } return 0; } - return real_WPADProbe(chan,result); + return real_WPADProbe(chan, result); } -DECL_FUNCTION(WPADConnectCallback,WPADSetConnectCallback,WPADChan chan, WPADConnectCallback callback ) { +DECL_FUNCTION(WPADConnectCallback, WPADSetConnectCallback, WPADChan chan, WPADConnectCallback callback) { //log_printf("WPADSetConnectCallback chan %d %08X",chan,callback); - ControllerPatcher::setWPADConnectCallback(chan,callback); + ControllerPatcher::setWPADConnectCallback(chan, callback); - if( (chan == WPAD_CHAN_0 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro1)) || - (chan == WPAD_CHAN_1 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro2)) || - (chan == WPAD_CHAN_2 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro3)) || - (chan == WPAD_CHAN_3 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro4))) { - if(callback != nullptr) { - callback(chan,0); + if ((chan == WPAD_CHAN_0 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro1)) || + (chan == WPAD_CHAN_1 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro2)) || + (chan == WPAD_CHAN_2 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro3)) || + (chan == WPAD_CHAN_3 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro4))) { + if (callback != nullptr) { + callback(chan, 0); } } - return real_WPADSetConnectCallback(chan,callback); + return real_WPADSetConnectCallback(chan, callback); } -DECL_FUNCTION(WPADExtensionCallback,WPADSetExtensionCallback,WPADChan chan, WPADExtensionCallback callback ) { +DECL_FUNCTION(WPADExtensionCallback, WPADSetExtensionCallback, WPADChan chan, WPADExtensionCallback callback) { //log_printf("WPADSetExtensionCallback chan %d %08X",chan,callback); - ControllerPatcher::setKPADExtensionCallback(chan,callback); + ControllerPatcher::setKPADExtensionCallback(chan, callback); - if((chan == WPAD_CHAN_0 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro1)) || - (chan == WPAD_CHAN_1 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro2)) || - (chan == WPAD_CHAN_2 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro3)) || - (chan == WPAD_CHAN_3 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro4))) { - if(callback != nullptr) { - callback(chan,WPAD_EXT_PRO_CONTROLLER); + if ((chan == WPAD_CHAN_0 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro1)) || + (chan == WPAD_CHAN_1 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro2)) || + (chan == WPAD_CHAN_2 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro3)) || + (chan == WPAD_CHAN_3 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro4))) { + if (callback != nullptr) { + callback(chan, WPAD_EXT_PRO_CONTROLLER); } } - return real_WPADSetExtensionCallback(chan,callback); + return real_WPADSetExtensionCallback(chan, callback); } -DECL_FUNCTION(WPADConnectCallback,KPADSetConnectCallback,WPADChan chan, WPADConnectCallback callback ) { +DECL_FUNCTION(WPADConnectCallback, KPADSetConnectCallback, WPADChan chan, WPADConnectCallback callback) { //log_printf("KPADSetConnectCallback chan %d %08X",chan,callback); - ControllerPatcher::setKPADConnectedCallback(chan,callback); + ControllerPatcher::setKPADConnectedCallback(chan, callback); - if( (chan == WPAD_CHAN_0 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro1)) || - (chan == WPAD_CHAN_1 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro2)) || - (chan == WPAD_CHAN_2 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro3)) || - (chan == WPAD_CHAN_3 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro4))) { - if(callback != nullptr) { - callback(chan,0); + if ((chan == WPAD_CHAN_0 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro1)) || + (chan == WPAD_CHAN_1 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro2)) || + (chan == WPAD_CHAN_2 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro3)) || + (chan == WPAD_CHAN_3 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro4))) { + if (callback != nullptr) { + callback(chan, 0); } } - return real_KPADSetConnectCallback(chan,callback); + return real_KPADSetConnectCallback(chan, callback); } DECL_FUNCTION(uint8_t, WPADGetBatteryLevel, WPADChan chan) { uint8_t result = real_WPADGetBatteryLevel(chan); - if( (chan == WPAD_CHAN_0 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro1)) || - (chan == WPAD_CHAN_1 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro2)) || - (chan == WPAD_CHAN_2 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro3)) || - (chan == WPAD_CHAN_3 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro4))) { + if ((chan == WPAD_CHAN_0 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro1)) || + (chan == WPAD_CHAN_1 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro2)) || + (chan == WPAD_CHAN_2 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro3)) || + (chan == WPAD_CHAN_3 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro4))) { result = 4; // Full battery } return result; @@ -128,10 +128,10 @@ DECL_FUNCTION(uint8_t, WPADGetBatteryLevel, WPADChan chan) { //In case a game relies on this... DECL_FUNCTION(uint32_t, WPADGetDataFormat, WPADChan chan) { //log_printf("WPADGetDataFormat chan: %d result: %d",chan,result); - if((chan == WPAD_CHAN_0 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro1)) || - (chan == WPAD_CHAN_1 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro2)) || - (chan == WPAD_CHAN_2 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro3)) || - (chan == WPAD_CHAN_3 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro4))) { + if ((chan == WPAD_CHAN_0 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro1)) || + (chan == WPAD_CHAN_1 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro2)) || + (chan == WPAD_CHAN_2 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro3)) || + (chan == WPAD_CHAN_3 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro4))) { return WPAD_FMT_PRO_CONTROLLER; } return real_WPADGetDataFormat(chan); @@ -139,49 +139,48 @@ DECL_FUNCTION(uint32_t, WPADGetDataFormat, WPADChan chan) { DECL_FUNCTION(int32_t, WPADSetDataFormat, WPADChan chan, WPADDataFormat fmt) { int32_t result = -1; - if((chan == WPAD_CHAN_0 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro1)) || - (chan == WPAD_CHAN_1 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro2)) || - (chan == WPAD_CHAN_2 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro3)) || - (chan == WPAD_CHAN_3 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro4))) { - real_WPADSetDataFormat(chan,WPAD_FMT_PRO_CONTROLLER); + if ((chan == WPAD_CHAN_0 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro1)) || + (chan == WPAD_CHAN_1 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro2)) || + (chan == WPAD_CHAN_2 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro3)) || + (chan == WPAD_CHAN_3 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro4))) { + real_WPADSetDataFormat(chan, WPAD_FMT_PRO_CONTROLLER); result = 0; } - result = real_WPADSetDataFormat(chan,fmt); + result = real_WPADSetDataFormat(chan, fmt); return result; } -DECL_FUNCTION(void,WPADRead,WPADChan chan, WPADStatusProController *data ) { - if((chan == WPAD_CHAN_0 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro1)) || - (chan == WPAD_CHAN_1 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro2)) || - (chan == WPAD_CHAN_2 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro3)) || - (chan == WPAD_CHAN_3 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro4))) { - ControllerPatcher::setProControllerDataFromHID((void*)data,chan,PRO_CONTROLLER_MODE_WPADReadData); +DECL_FUNCTION(void, WPADRead, WPADChan chan, WPADStatusProController *data) { + if ((chan == WPAD_CHAN_0 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro1)) || + (chan == WPAD_CHAN_1 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro2)) || + (chan == WPAD_CHAN_2 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro3)) || + (chan == WPAD_CHAN_3 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro4))) { + ControllerPatcher::setProControllerDataFromHID((void *) data, chan, PRO_CONTROLLER_MODE_WPADReadData); } else { - real_WPADRead(chan,data); - + real_WPADRead(chan, data); } } -DECL_FUNCTION(void,WPADControlMotor, WPADChan chan, uint32_t status ) { - if(chan == WPAD_CHAN_0 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro1)) { - ControllerPatcher::setRumble(UController_Type_Pro1,status); - } else if(chan == WPAD_CHAN_1 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro2)) { - ControllerPatcher::setRumble(UController_Type_Pro2,status); - } else if(chan == WPAD_CHAN_2 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro3)) { - ControllerPatcher::setRumble(UController_Type_Pro3,status); - } else if(chan == WPAD_CHAN_3 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro4)) { - ControllerPatcher::setRumble(UController_Type_Pro4,status); +DECL_FUNCTION(void, WPADControlMotor, WPADChan chan, uint32_t status) { + if (chan == WPAD_CHAN_0 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro1)) { + ControllerPatcher::setRumble(UController_Type_Pro1, status); + } else if (chan == WPAD_CHAN_1 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro2)) { + ControllerPatcher::setRumble(UController_Type_Pro2, status); + } else if (chan == WPAD_CHAN_2 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro3)) { + ControllerPatcher::setRumble(UController_Type_Pro3, status); + } else if (chan == WPAD_CHAN_3 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro4)) { + ControllerPatcher::setRumble(UController_Type_Pro4, status); } - real_WPADControlMotor(chan,status); + real_WPADControlMotor(chan, status); } -WUPS_MUST_REPLACE(VPADRead, WUPS_LOADER_LIBRARY_VPAD, VPADRead); -WUPS_MUST_REPLACE(WPADGetBatteryLevel, WUPS_LOADER_LIBRARY_PADSCORE, WPADGetBatteryLevel); -WUPS_MUST_REPLACE(KPADSetConnectCallback, WUPS_LOADER_LIBRARY_PADSCORE, KPADSetConnectCallback); -WUPS_MUST_REPLACE(WPADSetConnectCallback, WUPS_LOADER_LIBRARY_PADSCORE, WPADSetConnectCallback); -WUPS_MUST_REPLACE(WPADSetExtensionCallback, WUPS_LOADER_LIBRARY_PADSCORE, WPADSetExtensionCallback); -WUPS_MUST_REPLACE(WPADRead, WUPS_LOADER_LIBRARY_PADSCORE, WPADRead); -WUPS_MUST_REPLACE(WPADGetDataFormat, WUPS_LOADER_LIBRARY_PADSCORE, WPADGetDataFormat); -WUPS_MUST_REPLACE(WPADSetDataFormat, WUPS_LOADER_LIBRARY_PADSCORE, WPADSetDataFormat); -WUPS_MUST_REPLACE(WPADControlMotor, WUPS_LOADER_LIBRARY_PADSCORE, WPADControlMotor); -WUPS_MUST_REPLACE(WPADProbe, WUPS_LOADER_LIBRARY_PADSCORE, WPADProbe); +WUPS_MUST_REPLACE(VPADRead, WUPS_LOADER_LIBRARY_VPAD, VPADRead); +WUPS_MUST_REPLACE(WPADGetBatteryLevel, WUPS_LOADER_LIBRARY_PADSCORE, WPADGetBatteryLevel); +WUPS_MUST_REPLACE(KPADSetConnectCallback, WUPS_LOADER_LIBRARY_PADSCORE, KPADSetConnectCallback); +WUPS_MUST_REPLACE(WPADSetConnectCallback, WUPS_LOADER_LIBRARY_PADSCORE, WPADSetConnectCallback); +WUPS_MUST_REPLACE(WPADSetExtensionCallback, WUPS_LOADER_LIBRARY_PADSCORE, WPADSetExtensionCallback); +WUPS_MUST_REPLACE(WPADRead, WUPS_LOADER_LIBRARY_PADSCORE, WPADRead); +WUPS_MUST_REPLACE(WPADGetDataFormat, WUPS_LOADER_LIBRARY_PADSCORE, WPADGetDataFormat); +WUPS_MUST_REPLACE(WPADSetDataFormat, WUPS_LOADER_LIBRARY_PADSCORE, WPADSetDataFormat); +WUPS_MUST_REPLACE(WPADControlMotor, WUPS_LOADER_LIBRARY_PADSCORE, WPADControlMotor); +WUPS_MUST_REPLACE(WPADProbe, WUPS_LOADER_LIBRARY_PADSCORE, WPADProbe); diff --git a/src/WUPSConfigItemPadMapping.cpp b/src/WUPSConfigItemPadMapping.cpp index 2cc48a6..52be366 100644 --- a/src/WUPSConfigItemPadMapping.cpp +++ b/src/WUPSConfigItemPadMapping.cpp @@ -17,16 +17,16 @@ #include "WUPSConfigItemPadMapping.h" #include -#include +#include #include #include -#include -#include -#include #include +#include +#include +#include // At this point the VPADRead function is already patched. But we want to use the original function (note: this could be patched by a different plugin) -typedef int32_t (*VPADReadFunction) (VPADChan chan, VPADStatus *buffer, uint32_t buffer_size, VPADReadError *error); +typedef int32_t (*VPADReadFunction)(VPADChan chan, VPADStatus *buffer, uint32_t buffer_size, VPADReadError *error); extern VPADReadFunction real_VPADRead; bool WUPSConfigItemPadMapping_callCallback(void *context) { @@ -40,15 +40,15 @@ bool WUPSConfigItemPadMapping_callCallback(void *context) { void restoreDefault(void *context) { auto *item = (ConfigItemPadMapping *) context; - memset(&item->mappedPadInfo,0,sizeof(item->mappedPadInfo)); + memset(&item->mappedPadInfo, 0, sizeof(item->mappedPadInfo)); } bool updatePadInfo(ConfigItemPadMapping *item) { int32_t found = ControllerPatcher::getActiveMappingSlot(item->controllerType); - if(found != -1) { - ControllerMappingPADInfo * info = ControllerPatcher::getControllerMappingInfo(item->controllerType,found); - if(info != nullptr) { - memcpy(&item->mappedPadInfo,info,sizeof(item->mappedPadInfo)); + if (found != -1) { + ControllerMappingPADInfo *info = ControllerPatcher::getControllerMappingInfo(item->controllerType, found); + if (info != nullptr) { + memcpy(&item->mappedPadInfo, info, sizeof(item->mappedPadInfo)); return true; } } else { @@ -60,31 +60,31 @@ bool updatePadInfo(ConfigItemPadMapping *item) { int32_t WUPSConfigItemPadMapping_getCurrentValueDisplay(void *context, char *out_buf, int32_t out_size) { auto *item = (ConfigItemPadMapping *) context; - if(!updatePadInfo(item)) { + if (!updatePadInfo(item)) { snprintf(out_buf, out_size, "No Device"); return 0; } std::string name; std::string isConnectedString = "attached"; - if(!ControllerPatcher::isControllerConnectedAndActive(item->controllerType)) { + if (!ControllerPatcher::isControllerConnectedAndActive(item->controllerType)) { isConnectedString = "detached"; } - ControllerMappingPADInfo * info = &item->mappedPadInfo; + ControllerMappingPADInfo *info = &item->mappedPadInfo; - if(info->type == CM_Type_Controller) { - std::string titleString = ControllerPatcher::getIdentifierByVIDPID(info->vidpid.vid,info->vidpid.pid); + if (info->type == CM_Type_Controller) { + std::string titleString = ControllerPatcher::getIdentifierByVIDPID(info->vidpid.vid, info->vidpid.pid); std::vector result = StringTools::stringSplit(titleString, "\n"); - if(result.size() == 1) { + if (result.size() == 1) { name = titleString; - } else if(result.size() == 2) { - name = StringTools::strfmt("0x%04X / 0x%04X(%d) %s",info->vidpid.vid, info->vidpid.pid, info->pad, isConnectedString.c_str()); + } else if (result.size() == 2) { + name = StringTools::strfmt("0x%04X / 0x%04X(%d) %s", info->vidpid.vid, info->vidpid.pid, info->pad, isConnectedString.c_str()); } - } else if(info->type == CM_Type_RealController) { + } else if (info->type == CM_Type_RealController) { // currently this case can't happen. name = "Real (Pro) Controller"; - } else if(info->type == CM_Type_Mouse || info->type == CM_Type_Keyboard) { + } else if (info->type == CM_Type_Mouse || info->type == CM_Type_Keyboard) { // currently this case can't happen. name = "Mouse / Keyboard"; } @@ -96,51 +96,51 @@ int32_t WUPSConfigItemPadMapping_getCurrentValueDisplay(void *context, char *out void checkForInput(ConfigItemPadMapping *item) { int32_t inputsize = gHIDMaxDevices; - auto * hiddata = (InputData * ) malloc(sizeof(InputData)*inputsize); - memset(hiddata,0,sizeof(InputData)*inputsize); + auto *hiddata = (InputData *) malloc(sizeof(InputData) * inputsize); + memset(hiddata, 0, sizeof(InputData) * inputsize); ControllerMappingPADInfo pad_result; - memset(&pad_result,0,sizeof(ControllerMappingPADInfo)); + memset(&pad_result, 0, sizeof(ControllerMappingPADInfo)); bool gotPress = false; VPADStatus vpad_data; VPADReadError error; - while(!gotPress) { + while (!gotPress) { real_VPADRead(VPAD_CHAN_0, &vpad_data, 1, &error); - if(error != VPAD_READ_SUCCESS) { - if(vpad_data.hold == VPAD_BUTTON_B || vpad_data.hold == VPAD_BUTTON_HOME) { + if (error != VPAD_READ_SUCCESS) { + if (vpad_data.hold == VPAD_BUTTON_B || vpad_data.hold == VPAD_BUTTON_HOME) { break; } } - int32_t result = ControllerPatcher::gettingInputAllDevices(hiddata,inputsize); - if(result > 0) { + int32_t result = ControllerPatcher::gettingInputAllDevices(hiddata, inputsize); + if (result > 0) { //log_printf("got %d results",result); - for(int32_t i =0; icontrollerType,pad_result); + if (gotPress) { + ControllerPatcher::addControllerMapping(item->controllerType, pad_result); updatePadInfo(item); WUPSConfigItemPadMapping_callCallback(item); } @@ -150,7 +150,7 @@ void checkForInput(ConfigItemPadMapping *item) { void WUPSConfigItemPadMapping_onButtonPressed(void *context, WUPSConfigButtons buttons) { auto *item = (ConfigItemPadMapping *) context; - if(buttons & WUPS_CONFIG_BUTTON_A) { + if (buttons & WUPS_CONFIG_BUTTON_A) { // Lets remove the old mapping. ControllerPatcher::resetControllerMapping(item->controllerType); @@ -179,19 +179,18 @@ extern "C" bool WUPSConfigItemPadMapping_AddToCategory(WUPSConfigCategoryHandle strncpy(item->configId, configID, sizeof(item->configId)); item->controllerType = controllerType; - item->callback = (void *) callback; - memset(&item->mappedPadInfo,0, sizeof(item->mappedPadInfo)); + item->callback = (void *) callback; + memset(&item->mappedPadInfo, 0, sizeof(item->mappedPadInfo)); WUPSConfigCallbacks_t callbacks = { - .getCurrentValueDisplay = &WUPSConfigItemPadMapping_getCurrentValueDisplay, + .getCurrentValueDisplay = &WUPSConfigItemPadMapping_getCurrentValueDisplay, .getCurrentValueSelectedDisplay = &WUPSConfigItemPadMapping_getCurrentValueDisplay, - .onSelected = nullptr, - .restoreDefault = &restoreDefault, - .isMovementAllowed = &WUPSConfigItemPadMapping_isMovementAllowed, - .callCallback = nullptr, - .onButtonPressed = &WUPSConfigItemPadMapping_onButtonPressed, - .onDelete = &WUPSConfigItemPadMapping_onDelete - }; + .onSelected = nullptr, + .restoreDefault = &restoreDefault, + .isMovementAllowed = &WUPSConfigItemPadMapping_isMovementAllowed, + .callCallback = nullptr, + .onButtonPressed = &WUPSConfigItemPadMapping_onButtonPressed, + .onDelete = &WUPSConfigItemPadMapping_onDelete}; if (WUPSConfigItem_Create(&item->handle, configID, displayName, callbacks, item) < 0) { free(item); diff --git a/src/WUPSConfigItemPadMapping.h b/src/WUPSConfigItemPadMapping.h index 4d7a77f..b79c00d 100644 --- a/src/WUPSConfigItemPadMapping.h +++ b/src/WUPSConfigItemPadMapping.h @@ -15,8 +15,8 @@ * along with this program. If not, see . ****************************************************************************/ -#include #include +#include #ifdef __cplusplus extern "C" { @@ -27,7 +27,7 @@ typedef struct ConfigItemPadMapping { char configId[32]; UController_Type controllerType; ControllerMappingPADInfo mappedPadInfo; - void* callback; + void *callback; } ConfigItemPadMapping; typedef void (*ConfigItemPadMappingChangedCallback)(ConfigItemPadMapping *); diff --git a/src/main.cpp b/src/main.cpp index 55345cc..ca736c1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -17,8 +17,8 @@ #include -#include #include +#include #include @@ -31,10 +31,10 @@ WUPS_PLUGIN_LICENSE("GPL"); WUPS_USE_WUT_DEVOPTAB(); WUPS_USE_STORAGE("hid_to_vpad"); -#define SD_PATH "fs:/vol/external01" -#define WIIU_PATH "/wiiu" -#define DEFAULT_HID_TO_VPAD_PATH SD_PATH WIIU_PATH "/apps/hidtovpad" -#define DEFAULT_CONTROLLER_PATCHER_PATCH SD_PATH WIIU_PATH "/controller" +#define SD_PATH "fs:/vol/external01" +#define WIIU_PATH "/wiiu" +#define DEFAULT_HID_TO_VPAD_PATH SD_PATH WIIU_PATH "/apps/hidtovpad" +#define DEFAULT_CONTROLLER_PATCHER_PATCH SD_PATH WIIU_PATH "/controller" extern int32_t runNetworkClient; @@ -48,14 +48,14 @@ ON_APPLICATION_START() { ConfigLoad(); - if (runNetworkClient){ + if (runNetworkClient) { DEBUG_FUNCTION_LINE("Starting HID to VPAD network server"); ControllerPatcher::startNetworkServer(); } ControllerPatcher::disableWiiUEnergySetting(); } -INITIALIZE_PLUGIN(){ +INITIALIZE_PLUGIN() { WHBLogUdpInit(); } diff --git a/src/utils/StringTools.cpp b/src/utils/StringTools.cpp index 23b87fa..c75a0b4 100644 --- a/src/utils/StringTools.cpp +++ b/src/utils/StringTools.cpp @@ -23,25 +23,24 @@ * * 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) { +BOOL StringTools::EndsWith(const std::string &a, const std::string &b) { if (b.size() > a.size()) return false; return std::equal(a.begin() + a.size() - b.size(), a.end(), b.begin()); } -const char * StringTools::byte_to_binary(int32_t x) { +const char *StringTools::byte_to_binary(int32_t x) { static char b[9]; b[0] = '\0'; @@ -53,25 +52,25 @@ const char * StringTools::byte_to_binary(int32_t x) { return b; } -std::string StringTools::removeCharFromString(std::string& input,char toBeRemoved) { +std::string StringTools::removeCharFromString(std::string &input, char toBeRemoved) { std::string output = input; size_t position; - while(1) { + while (1) { position = output.find(toBeRemoved); - if(position == std::string::npos) + if (position == std::string::npos) break; output.erase(position, 1); } return output; } -const char * StringTools::fmt(const char * format, ...) { +const char *StringTools::fmt(const char *format, ...) { static char strChar[512]; strChar[0] = 0; va_list va; va_start(va, format); - if((vsprintf(strChar, format, va) >= 0)) { + if ((vsprintf(strChar, format, va) >= 0)) { va_end(va); return (const char *) strChar; } @@ -80,26 +79,26 @@ const char * StringTools::fmt(const char * format, ...) { return NULL; } -const wchar_t * StringTools::wfmt(const char * format, ...) { +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) + if (!format) return (const wchar_t *) strWChar; - if(strcmp(format, "") == 0) + if (strcmp(format, "") == 0) return (const wchar_t *) strWChar; va_list va; va_start(va, format); - if((vsprintf(tmp, format, va) >= 0)) { - int bt; + 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) { + if (bt > 0) { strWChar[bt] = 0; return (const wchar_t *) strWChar; } @@ -109,15 +108,15 @@ const wchar_t * StringTools::wfmt(const char * format, ...) { return NULL; } -int32_t StringTools::strprintf(std::string &str, 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; + if ((vsprintf(tmp, format, va) >= 0)) { + str = tmp; result = str.size(); } va_end(va); @@ -125,14 +124,14 @@ int32_t StringTools::strprintf(std::string &str, const char * format, ...) { return result; } -std::string StringTools::strfmt(const char * format, ...) { +std::string StringTools::strfmt(const char *format, ...) { std::string str; static char tmp[512]; tmp[0] = 0; va_list va; va_start(va, format); - if((vsprintf(tmp, format, va) >= 0)) { + if ((vsprintf(tmp, format, va) >= 0)) { str = tmp; } va_end(va); @@ -140,11 +139,11 @@ std::string StringTools::strfmt(const char * format, ...) { return str; } -BOOL StringTools::char2wchar_t(const char * strChar, wchar_t * dest) { - if(!strChar || !dest) +BOOL StringTools::char2wchar_t(const char *strChar, wchar_t *dest) { + if (!strChar || !dest) return false; - int bt; + int bt; bt = mbstowcs(dest, strChar, strlen(strChar)); if (bt > 0) { dest[bt] = 0; @@ -154,39 +153,39 @@ BOOL StringTools::char2wchar_t(const char * strChar, wchar_t * dest) { return false; } -int32_t StringTools::strtokcmp(const char * string, const char * compare, const char * separator) { - if(!string || !compare) +int32_t StringTools::strtokcmp(const char *string, const char *compare, const char *separator) { + if (!string || !compare) return -1; char TokCopy[512]; strncpy(TokCopy, compare, sizeof(TokCopy)); TokCopy[511] = '\0'; - char * strTok = strtok(TokCopy, separator); + char *strTok = strtok(TokCopy, separator); while (strTok != NULL) { if (strcasecmp(string, strTok) == 0) { return 0; } - strTok = strtok(NULL,separator); + strTok = strtok(NULL, separator); } return -1; } -int32_t StringTools::strextcmp(const char * string, const char * extension, char seperator) { - if(!string || !extension) +int32_t StringTools::strextcmp(const char *string, const char *extension, char seperator) { + if (!string || !extension) return -1; char *ptr = strrchr(string, seperator); - if(!ptr) + if (!ptr) return -1; return strcasecmp(ptr + 1, extension); } -std::vector StringTools::stringSplit(const std::string & inValue, const std::string & splitter) { +std::vector StringTools::stringSplit(const std::string &inValue, const std::string &splitter) { std::string value = inValue; std::vector result; while (true) { @@ -201,7 +200,7 @@ std::vector StringTools::stringSplit(const std::string & inValue, c result.push_back(""); break; } - if(index + splitter.size() > value.length()) { + if (index + splitter.size() > value.length()) { break; } value = value.substr(index + splitter.size(), value.length()); diff --git a/src/utils/StringTools.h b/src/utils/StringTools.h index e7c8527..78fbec5 100644 --- a/src/utils/StringTools.h +++ b/src/utils/StringTools.h @@ -26,56 +26,53 @@ #ifndef __STRING_TOOLS_H #define __STRING_TOOLS_H -#include #include +#include #include -class StringTools{ - public: - static BOOL EndsWith(const std::string& a, const std::string& b); - static const char * byte_to_binary(int32_t x); - static std::string removeCharFromString(std::string& input,char toBeRemoved); - static const char * fmt(const char * format, ...); - static const wchar_t * wfmt(const char * format, ...); - static int32_t strprintf(std::string &str, const char * format, ...); - static std::string strfmt(const char * format, ...); - static BOOL char2wchar_t(const char * src, wchar_t * dest); - static int32_t strtokcmp(const char * string, const char * compare, const char * separator); - static int32_t strextcmp(const char * string, const char * extension, char seperator); +class StringTools { +public: + static BOOL EndsWith(const std::string &a, const std::string &b); + static const char *byte_to_binary(int32_t x); + static std::string removeCharFromString(std::string &input, char toBeRemoved); + static const char *fmt(const char *format, ...); + static const wchar_t *wfmt(const char *format, ...); + static int32_t strprintf(std::string &str, const char *format, ...); + static std::string strfmt(const char *format, ...); + static BOOL char2wchar_t(const char *src, wchar_t *dest); + static int32_t strtokcmp(const char *string, const char *compare, const char *separator); + static int32_t strextcmp(const char *string, const char *extension, char seperator); - static const char * FullpathToFilename(const char *path){ - if(!path) return path; + static const char *FullpathToFilename(const char *path) { + if (!path) return path; - const char * ptr = path; - const char * Filename = ptr; + const char *ptr = path; + const char *Filename = ptr; - while(*ptr != '\0') - { - if(ptr[0] == '/' && ptr[1] != '\0') - Filename = ptr+1; + while (*ptr != '\0') { + if (ptr[0] == '/' && ptr[1] != '\0') + Filename = ptr + 1; - ++ptr; - } - - return Filename; + ++ptr; } - static void RemoveDoubleSlashs(std::string &str){ - uint32_t length = str.size(); + return Filename; + } - //! clear path of double slashes - for(uint32_t i = 1; i < length; ++i) - { - if(str[i-1] == '/' && str[i] == '/') - { - str.erase(i, 1); - i--; - length--; - } + static void RemoveDoubleSlashs(std::string &str) { + uint32_t length = str.size(); + + //! clear path of double slashes + for (uint32_t i = 1; i < length; ++i) { + if (str[i - 1] == '/' && str[i] == '/') { + str.erase(i, 1); + i--; + length--; } } + } - static std::vector stringSplit(const std::string & value, const std::string & splitter); + static std::vector stringSplit(const std::string &value, const std::string &splitter); }; #endif /* __STRING_TOOLS_H */ diff --git a/src/utils/logger.h b/src/utils/logger.h index dd0b0d4..f699cd1 100644 --- a/src/utils/logger.h +++ b/src/utils/logger.h @@ -9,14 +9,16 @@ extern "C" { #include #define __FILENAME_X__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__) -#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILENAME_X__) +#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); #ifdef __cplusplus