From 771b944d1719cefbfeaced882a8d73cf9a556e04 Mon Sep 17 00:00:00 2001 From: Gabriel Ravier Date: Mon, 29 Jun 2020 18:52:04 +0200 Subject: [PATCH] src: Some cleanup for the MAX_PATH std::string PR Signed-off-by: Gabriel Ravier --- src/ArmsItem.cpp | 3 +-- src/Backends/Platform/WiiU.cpp | 2 -- src/Draw.cpp | 4 ++-- src/Ending.cpp | 2 +- src/Game.cpp | 4 +--- src/Generic.cpp | 3 +-- src/GenericLoad.cpp | 4 ++-- src/Main.cpp | 16 +++++++++++++++- src/MycParam.cpp | 2 +- src/SelStage.cpp | 3 +-- src/Stage.cpp | 2 +- src/TextScr.cpp | 4 ++-- 12 files changed, 28 insertions(+), 21 deletions(-) diff --git a/src/ArmsItem.cpp b/src/ArmsItem.cpp index a1062f00..f6dbf214 100644 --- a/src/ArmsItem.cpp +++ b/src/ArmsItem.cpp @@ -1,6 +1,5 @@ #include "ArmsItem.h" -#include #include #include "WindowsWrapper.h" @@ -418,7 +417,7 @@ int CampLoop(void) RECT rcView = {0, 0, WINDOW_WIDTH, WINDOW_HEIGHT}; // Save the current script path (to restore it when we get out of the inventory) - std::string old_script_path = GetTextScriptPath(); + auto old_script_path = GetTextScriptPath(); // Load the inventory script LoadTextScript2("ArmsItem.tsc"); diff --git a/src/Backends/Platform/WiiU.cpp b/src/Backends/Platform/WiiU.cpp index 0c89684d..af727ad4 100644 --- a/src/Backends/Platform/WiiU.cpp +++ b/src/Backends/Platform/WiiU.cpp @@ -12,8 +12,6 @@ #include #include -#include "../../Helpers/Asprintf.h" - static unsigned long ticks_per_second; bool Backend_Init(void) diff --git a/src/Draw.cpp b/src/Draw.cpp index 212f87c2..91333b9b 100644 --- a/src/Draw.cpp +++ b/src/Draw.cpp @@ -250,7 +250,7 @@ BOOL MakeSurface_Resource(const char *name, SurfaceID surf_no) // TODO - Inaccurate stack frame BOOL MakeSurface_File(const char *name, SurfaceID surf_no) { - std::string path = gDataPath + '/' + name + ".pbm"; + auto path = gDataPath + '/' + name + ".pbm"; if (!IsEnableBitmap(path.c_str())) { @@ -340,7 +340,7 @@ BOOL ReloadBitmap_Resource(const char *name, SurfaceID surf_no) // TODO - Inaccurate stack frame BOOL ReloadBitmap_File(const char *name, SurfaceID surf_no) { - std::string path = gDataPath + '/' + name + ".pbm"; + auto path = gDataPath + '/' + name + ".pbm"; if (!IsEnableBitmap(path.c_str())) { diff --git a/src/Ending.cpp b/src/Ending.cpp index cc1cfc50..9314664e 100644 --- a/src/Ending.cpp +++ b/src/Ending.cpp @@ -225,7 +225,7 @@ BOOL StartCreditScript(void) } // Open file - std::string path = gDataPath + '/' + credit_script; + auto path = gDataPath + '/' + credit_script; Credit.size = GetFileSizeLong(path.c_str()); if (Credit.size == -1) return FALSE; diff --git a/src/Game.cpp b/src/Game.cpp index 63c9acc5..9914e669 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -701,9 +701,7 @@ BOOL Game(void) PlaySoundObject(7, -1); - std::string path = gDataPath + "/npc.tbl"; - - if (!LoadNpcTable(path.c_str())) + if (!LoadNpcTable((gDataPath + "/npc.tbl").c_str())) { #ifdef JAPANESE Backend_ShowMessageBox("エラー", "NPCテーブルが読めない"); diff --git a/src/Generic.cpp b/src/Generic.cpp index 66223b6e..c62e8c57 100644 --- a/src/Generic.cpp +++ b/src/Generic.cpp @@ -2,7 +2,6 @@ #include #include -#include #include #include "WindowsWrapper.h" @@ -94,7 +93,7 @@ long GetFileSizeLong(const char *path) BOOL ErrorLog(const char *string, int value) { - std::string path = gModulePath + "/error.log"; + auto path = gModulePath + "/error.log"; if (GetFileSizeLong(path.c_str()) > 0x19000) // Purge the error log if it gets too big, I guess remove(path.c_str()); diff --git a/src/GenericLoad.cpp b/src/GenericLoad.cpp index 29343894..5eaad31d 100644 --- a/src/GenericLoad.cpp +++ b/src/GenericLoad.cpp @@ -294,8 +294,8 @@ BOOL LoadGenericData(void) pt_size += MakePixToneObject(&gPtpTable[138], 1, 7); /* - * char str[0x40]; - * sprintf(str, "PixTone = %d byte", pt_size); + * char str[0x40]; + * sprintf(str, "PixTone = %d byte", pt_size); * // There must have been some kind of console print function here or something */ return TRUE; diff --git a/src/Main.cpp b/src/Main.cpp index 7f78cf71..8bbd7375 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -222,12 +222,18 @@ int main(int argc, char *argv[]) if (conf.display_mode == 1) { if (!StartDirectDraw(lpWindowName, windowWidth, windowHeight, 0)) + { + Backend_Deinit(); return EXIT_FAILURE; + } } else { if (!StartDirectDraw(lpWindowName, windowWidth, windowHeight, 1)) + { + Backend_Deinit(); return EXIT_FAILURE; + } } #else // Doesn't handle StartDirectDraw failing @@ -248,7 +254,10 @@ int main(int argc, char *argv[]) #ifdef FIX_BUGS if (!StartDirectDraw(lpWindowName, windowWidth, windowHeight, 2)) + { + Backend_Deinit(); return EXIT_FAILURE; + } #else // Doesn't handle StartDirectDraw failing StartDirectDraw(lpWindowName, windowWidth, windowHeight, 2); @@ -316,7 +325,10 @@ int main(int argc, char *argv[]) // Draw to screen if (!Flip_SystemTask()) - return EXIT_SUCCESS; + { + Backend_Deinit(); + return EXIT_FAILURE; + } // Initialize sound InitDirectSound(); @@ -340,6 +352,8 @@ int main(int argc, char *argv[]) EndDirectSound(); EndDirectDraw(); + Backend_Deinit(); + return EXIT_SUCCESS; } diff --git a/src/MycParam.cpp b/src/MycParam.cpp index 9764f417..8d3119f2 100644 --- a/src/MycParam.cpp +++ b/src/MycParam.cpp @@ -441,7 +441,7 @@ BOOL SaveTimeCounter(void) return TRUE; // Get last time - std::string path = gModulePath + "/290.rec"; + auto path = gModulePath + "/290.rec"; FILE *fp = fopen(path.c_str(), "rb"); if (fp != NULL) diff --git a/src/SelStage.cpp b/src/SelStage.cpp index 4e229ed7..8686fb8e 100644 --- a/src/SelStage.cpp +++ b/src/SelStage.cpp @@ -1,6 +1,5 @@ #include "SelStage.h" -#include #include #include "WindowsWrapper.h" @@ -161,7 +160,7 @@ int StageSelectLoop(int *p_event) gSelectedStage = 0; BackupSurface(SURFACE_ID_SCREEN_GRAB, &grcFull); - std::string old_script_path = GetTextScriptPath(); + auto old_script_path = GetTextScriptPath(); LoadTextScript2("StageSelect.tsc"); gStageSelectTitleY = (WINDOW_HEIGHT / 2) - 66; StartTextScript(gPermitStage[gSelectedStage].index + 1000); diff --git a/src/Stage.cpp b/src/Stage.cpp index 4e3bf9fa..c2caf013 100644 --- a/src/Stage.cpp +++ b/src/Stage.cpp @@ -139,7 +139,7 @@ BOOL TransferStage(int no, int w, int x, int y) bError = FALSE; // Load tileset - std::string path = std::string{"Stage/Prt"} + gTMT[no].parts; + auto path = std::string{"Stage/Prt"} + gTMT[no].parts; if (!ReloadBitmap_File(path.c_str(), SURFACE_ID_LEVEL_TILESET)) bError = TRUE; diff --git a/src/TextScr.cpp b/src/TextScr.cpp index 2c305411..e0fd8150 100644 --- a/src/TextScr.cpp +++ b/src/TextScr.cpp @@ -126,7 +126,7 @@ BOOL LoadTextScript2(const char *name) FILE *fp; // Get path - std::string path = gDataPath + '/' + name; + auto path = gDataPath + '/' + name; gTS.size = GetFileSizeLong(path.c_str()); if (gTS.size == -1) @@ -159,7 +159,7 @@ BOOL LoadTextScript_Stage(const char *name) long body_size; // Open Head.tsc - std::string path = gDataPath + "/Head.tsc"; + auto path = gDataPath + "/Head.tsc"; head_size = GetFileSizeLong(path.c_str()); if (head_size == -1) return FALSE;