Merge pull request #130 from GabrielRavier/portableSupportPathsAboveFilenameMax

Support paths above PATH_MAX (for portable)
This commit is contained in:
Clownacy 2020-06-30 14:09:57 +01:00 committed by GitHub
commit 78da025796
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
25 changed files with 152 additions and 141 deletions

View file

@ -1,6 +1,7 @@
#include "ArmsItem.h" #include "ArmsItem.h"
#include <string.h> #include <string.h>
#include <string>
#include "WindowsWrapper.h" #include "WindowsWrapper.h"
@ -414,12 +415,12 @@ void PutCampObject(void)
int CampLoop(void) int CampLoop(void)
{ {
char old_script_path[MAX_PATH]; std::string old_script_path;
RECT rcView = {0, 0, WINDOW_WIDTH, WINDOW_HEIGHT}; RECT rcView = {0, 0, WINDOW_WIDTH, WINDOW_HEIGHT};
// Save the current script path (to restore it when we get out of the inventory) // Save the current script path (to restore it when we get out of the inventory)
GetTextScriptPath(old_script_path); old_script_path = GetTextScriptPath();
// Load the inventory script // Load the inventory script
LoadTextScript2("ArmsItem.tsc"); LoadTextScript2("ArmsItem.tsc");
@ -498,7 +499,7 @@ int CampLoop(void)
} }
// Resume original script // Resume original script
LoadTextScript_Stage(old_script_path); LoadTextScript_Stage(old_script_path.c_str());
gArmsEnergyX = 32; // Displays weapon rotation animation in case the weapon was changed gArmsEnergyX = 32; // Displays weapon rotation animation in case the weapon was changed
return enum_ESCRETURN_continue; // Go to game return enum_ESCRETURN_continue; // Go to game
} }

View file

@ -13,7 +13,6 @@
#ifdef __GNUC__ #ifdef __GNUC__
#define ATTRIBUTE_HOT __attribute__((hot)) #define ATTRIBUTE_HOT __attribute__((hot))
#define ATTRIBUTE_OPTIMIZE(optString) __attribute__((optimize(optString)))
#define LIKELY(condition) __builtin_expect((condition), 1) #define LIKELY(condition) __builtin_expect((condition), 1)
#define UNLIKELY(condition) __builtin_expect((condition), 0) #define UNLIKELY(condition) __builtin_expect((condition), 0)
#define PREFETCH(address, isWrite, locality) __builtin_prefetch((address), (isWrite), (locality)) #define PREFETCH(address, isWrite, locality) __builtin_prefetch((address), (isWrite), (locality))
@ -21,7 +20,6 @@
#else #else
#define ATTRIBUTE_HOT #define ATTRIBUTE_HOT
#define ATTRIBUTE_OPTIMIZE(optString)
#define LIKELY(condition) condition #define LIKELY(condition) condition
#define UNLIKELY(condition) condition #define UNLIKELY(condition) condition
#define PREFETCH(address, isWrite, locality) #define PREFETCH(address, isWrite, locality)

View file

@ -2,6 +2,7 @@
#include <stddef.h> #include <stddef.h>
#include <stdio.h> #include <stdio.h>
#include <string>
#include "WindowsWrapper.h" #include "WindowsWrapper.h"
@ -25,10 +26,9 @@ BOOL InitBack(const char *fName, int type)
color_black = GetCortBoxColor(RGB(0, 0, 0x10)); color_black = GetCortBoxColor(RGB(0, 0, 0x10));
// Get width and height // Get width and height
char path[MAX_PATH]; std::string path = gDataPath + '/' + fName + ".pbm";
sprintf(path, "%s/%s.pbm", gDataPath, fName);
FILE *fp = fopen(path, "rb"); FILE *fp = fopen(path.c_str(), "rb");
if (fp == NULL) if (fp == NULL)
return FALSE; return FALSE;

View file

@ -1,5 +1,7 @@
#pragma once #pragma once
#include <string>
#include "../Attributes.h" #include "../Attributes.h"
enum enum
@ -86,7 +88,7 @@ enum
bool Backend_Init(void); bool Backend_Init(void);
void Backend_Deinit(void); void Backend_Deinit(void);
void Backend_PostWindowCreation(void); void Backend_PostWindowCreation(void);
bool Backend_GetBasePath(char *string_buffer); bool Backend_GetBasePath(std::string *string_buffer);
void Backend_HideMouse(void); void Backend_HideMouse(void);
void Backend_SetWindowIcon(const unsigned char *rgb_pixels, unsigned int width, unsigned int height); void Backend_SetWindowIcon(const unsigned char *rgb_pixels, unsigned int width, unsigned int height);
void Backend_SetCursor(const unsigned char *rgb_pixels, unsigned int width, unsigned int height); void Backend_SetCursor(const unsigned char *rgb_pixels, unsigned int width, unsigned int height);

View file

@ -6,6 +6,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <string>
#include <thread> #include <thread>
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
@ -181,7 +182,7 @@ void Backend_PostWindowCreation(void)
glfwSetWindowSizeCallback(window, WindowSizeCallback); glfwSetWindowSizeCallback(window, WindowSizeCallback);
} }
bool Backend_GetBasePath(char *string_buffer) bool Backend_GetBasePath(std::string *string_buffer)
{ {
(void)string_buffer; (void)string_buffer;

View file

@ -1,5 +1,7 @@
#include "../Misc.h" #include "../Misc.h"
#include <string>
bool Backend_Init(void) bool Backend_Init(void)
{ {
return true; return true;
@ -15,7 +17,7 @@ void Backend_PostWindowCreation(void)
} }
bool Backend_GetBasePath(char *string_buffer) bool Backend_GetBasePath(std::string *string_buffer)
{ {
(void)string_buffer; (void)string_buffer;

View file

@ -84,13 +84,15 @@ void Backend_PostWindowCreation(void)
} }
bool Backend_GetBasePath(char *string_buffer) bool Backend_GetBasePath(std::string *string_buffer)
{ {
#ifdef _WIN32 #ifdef _WIN32
// SDL_GetBasePath returns a UTF-8 string, but Windows' fopen uses (extended?) ASCII. // SDL_GetBasePath returns a UTF-8 string, but Windows' fopen uses (extended?) ASCII.
// This is apparently a problem for accented characters, as they will make fopen fail. // This is apparently a problem for accented characters, as they will make fopen fail.
// So, instead, we rely on argv[0], as that will put the accented characters in a // So, instead, we rely on argv[0], as that will put the accented characters in a
// format Windows will understand. // format Windows will understand.
(void)string_buffer;
return false; return false;
#else #else
char *base_path = SDL_GetBasePath(); char *base_path = SDL_GetBasePath();
@ -100,7 +102,7 @@ bool Backend_GetBasePath(char *string_buffer)
// Trim the trailing '/' // Trim the trailing '/'
size_t base_path_length = strlen(base_path); size_t base_path_length = strlen(base_path);
base_path[base_path_length - 1] = '\0'; base_path[base_path_length - 1] = '\0';
strcpy(string_buffer, base_path); *string_buffer = base_path;
SDL_free(base_path); SDL_free(base_path);
return true; return true;

View file

@ -3,6 +3,7 @@
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <string>
#include <coreinit/thread.h> #include <coreinit/thread.h>
#include <padscore/kpad.h> #include <padscore/kpad.h>
@ -54,13 +55,13 @@ void Backend_PostWindowCreation(void)
} }
bool Backend_GetBasePath(char *string_buffer) bool Backend_GetBasePath(std::string *string_buffer)
{ {
strcpy(string_buffer, WHBGetSdCardMountPath()); *string_buffer = WHBGetSdCardMountPath();
#ifdef JAPANESE #ifdef JAPANESE
strcat(string_buffer, "/CSE2-portable-jp"); *string_buffer += "/CSE2-portable-jp";
#else #else
strcat(string_buffer, "/CSE2-portable-en"); *string_buffer += "/CSE2-portable-en";
#endif #endif
return true; return true;

View file

@ -1,6 +1,7 @@
#include <stddef.h> #include <stddef.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <string>
#include "WindowsWrapper.h" #include "WindowsWrapper.h"
@ -17,11 +18,10 @@ BOOL LoadConfigData(CONFIG *conf)
memset(conf, 0, sizeof(CONFIG)); memset(conf, 0, sizeof(CONFIG));
// Get path // Get path
char path[MAX_PATH]; std::string path = gModulePath + '/' + gConfigName;
sprintf(path, "%s/%s", gModulePath, gConfigName);
// Open file // Open file
FILE *fp = fopen(path, "rb"); FILE *fp = fopen(path.c_str(), "rb");
if (fp == NULL) if (fp == NULL)
return FALSE; return FALSE;

View file

@ -4,6 +4,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <string>
#include "WindowsWrapper.h" #include "WindowsWrapper.h"
@ -250,12 +251,11 @@ BOOL MakeSurface_Resource(const char *name, SurfaceID surf_no)
// TODO - Inaccurate stack frame // TODO - Inaccurate stack frame
BOOL MakeSurface_File(const char *name, SurfaceID surf_no) BOOL MakeSurface_File(const char *name, SurfaceID surf_no)
{ {
char path[MAX_PATH]; std::string path = gDataPath + '/' + name + ".pbm";
sprintf(path, "%s/%s.pbm", gDataPath, name);
if (!IsEnableBitmap(path)) if (!IsEnableBitmap(path.c_str()))
{ {
ErrorLog(path, 0); ErrorLog(path.c_str(), 0);
return FALSE; return FALSE;
} }
@ -276,11 +276,11 @@ BOOL MakeSurface_File(const char *name, SurfaceID surf_no)
} }
unsigned int width, height; unsigned int width, height;
unsigned char *image_buffer = DecodeBitmapFromFile(path, &width, &height); unsigned char *image_buffer = DecodeBitmapFromFile(path.c_str(), &width, &height);
if (image_buffer == NULL) if (image_buffer == NULL)
{ {
ErrorLog(path, 1); ErrorLog(path.c_str(), 1);
return FALSE; return FALSE;
} }
@ -341,12 +341,11 @@ BOOL ReloadBitmap_Resource(const char *name, SurfaceID surf_no)
// TODO - Inaccurate stack frame // TODO - Inaccurate stack frame
BOOL ReloadBitmap_File(const char *name, SurfaceID surf_no) BOOL ReloadBitmap_File(const char *name, SurfaceID surf_no)
{ {
char path[MAX_PATH]; std::string path = gDataPath + '/' + name + ".pbm";
sprintf(path, "%s/%s.pbm", gDataPath, name);
if (!IsEnableBitmap(path)) if (!IsEnableBitmap(path.c_str()))
{ {
ErrorLog(path, 0); ErrorLog(path.c_str(), 0);
return FALSE; return FALSE;
} }
@ -361,11 +360,11 @@ BOOL ReloadBitmap_File(const char *name, SurfaceID surf_no)
} }
unsigned int width, height; unsigned int width, height;
unsigned char *image_buffer = DecodeBitmapFromFile(path, &width, &height); unsigned char *image_buffer = DecodeBitmapFromFile(path.c_str(), &width, &height);
if (image_buffer == NULL) if (image_buffer == NULL)
{ {
ErrorLog(path, 1); ErrorLog(path.c_str(), 1);
return FALSE; return FALSE;
} }
@ -647,8 +646,7 @@ void InitTextObject(const char *name)
{ {
(void)name; // Unused in this branch (void)name; // Unused in this branch
char path[MAX_PATH]; std::string path = gDataPath + "/Font/font";
sprintf(path, "%s/Font/font", gDataPath);
// Get font size // Get font size
unsigned int width, height; unsigned int width, height;
@ -666,7 +664,7 @@ void InitTextObject(const char *name)
break; break;
} }
font = LoadFont(path, width, height); font = LoadFont(path.c_str(), width, height);
} }
void PutText(int x, int y, const char *text, unsigned long color) void PutText(int x, int y, const char *text, unsigned long color)

View file

@ -3,6 +3,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <string>
#include "WindowsWrapper.h" #include "WindowsWrapper.h"
@ -216,7 +217,7 @@ void ReleaseCreditScript(void)
BOOL StartCreditScript(void) BOOL StartCreditScript(void)
{ {
FILE *fp; FILE *fp;
char path[MAX_PATH]; std::string path;
// Clear previously existing credits data // Clear previously existing credits data
if (Credit.pData != NULL) if (Credit.pData != NULL)
@ -226,9 +227,9 @@ BOOL StartCreditScript(void)
} }
// Open file // Open file
sprintf(path, "%s/%s", gDataPath, credit_script); path = gDataPath + '/' + credit_script;
Credit.size = GetFileSizeLong(path); Credit.size = GetFileSizeLong(path.c_str());
if (Credit.size == -1) if (Credit.size == -1)
return FALSE; return FALSE;
@ -237,7 +238,7 @@ BOOL StartCreditScript(void)
if (Credit.pData == NULL) if (Credit.pData == NULL)
return FALSE; return FALSE;
fp = fopen(path, "rb"); fp = fopen(path.c_str(), "rb");
if (fp == NULL) if (fp == NULL)
{ {
free(Credit.pData); free(Credit.pData);

View file

@ -3,6 +3,7 @@
#include <stddef.h> #include <stddef.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string>
#include "WindowsWrapper.h" #include "WindowsWrapper.h"
@ -701,10 +702,9 @@ BOOL Game(void)
PlaySoundObject(7, -1); PlaySoundObject(7, -1);
char path[MAX_PATH]; std::string path = gDataPath + "/npc.tbl";
sprintf(path, "%s/npc.tbl", gDataPath);
if (!LoadNpcTable(path)) if (!LoadNpcTable(path.c_str()))
{ {
#ifdef JAPANESE #ifdef JAPANESE
Backend_ShowMessageBox("エラー", "NPCテーブルが読めない"); Backend_ShowMessageBox("エラー", "NPCテーブルが読めない");

View file

@ -3,6 +3,7 @@
#include <stddef.h> #include <stddef.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <string>
#include "WindowsWrapper.h" #include "WindowsWrapper.h"
@ -49,19 +50,19 @@ BOOL GetCompileVersion(int *v1, int *v2, int *v3, int *v4)
void DeleteLog(void) void DeleteLog(void)
{ {
char path[MAX_PATH]; std::string path;
sprintf(path, "%s/debug.txt", gModulePath); path = gModulePath + "/debug.txt";
remove(path); remove(path.c_str());
} }
BOOL WriteLog(const char *string, int value1, int value2, int value3) BOOL WriteLog(const char *string, int value1, int value2, int value3)
{ {
char path[MAX_PATH]; std::string path;
FILE *fp; FILE *fp;
sprintf(path, "%s/debug.txt", gModulePath); path = gModulePath + "/debug.txt";
fp = fopen(path, "a+"); fp = fopen(path.c_str(), "a+");
if (fp == NULL) if (fp == NULL)
return FALSE; return FALSE;
@ -73,11 +74,9 @@ BOOL WriteLog(const char *string, int value1, int value2, int value3)
BOOL IsKeyFile(const char *name) BOOL IsKeyFile(const char *name)
{ {
char path[MAX_PATH]; std::string path = gModulePath + '/' + name;
sprintf(path, "%s/%s", gModulePath, name); FILE *file = fopen(path.c_str(), "rb");
FILE *file = fopen(path, "rb");
if (file == NULL) if (file == NULL)
return FALSE; return FALSE;
@ -105,15 +104,15 @@ long GetFileSizeLong(const char *path)
BOOL ErrorLog(const char *string, int value) BOOL ErrorLog(const char *string, int value)
{ {
char path[MAX_PATH]; std::string path;
FILE *fp; FILE *fp;
sprintf(path, "%s/%s", gModulePath, "error.log"); path = gModulePath + "/error.log";
if (GetFileSizeLong(path) > 0x19000) // Purge the error log if it gets too big, I guess if (GetFileSizeLong(path.c_str()) > 0x19000) // Purge the error log if it gets too big, I guess
remove(path); remove(path.c_str());
fp = fopen(path, "a+"); fp = fopen(path.c_str(), "a+");
if (fp == NULL) if (fp == NULL)
return FALSE; return FALSE;

View file

@ -293,8 +293,9 @@ BOOL LoadGenericData(void)
pt_size += MakePixToneObject(&gPtpTable[137], 1, 6); pt_size += MakePixToneObject(&gPtpTable[137], 1, 6);
pt_size += MakePixToneObject(&gPtpTable[138], 1, 7); pt_size += MakePixToneObject(&gPtpTable[138], 1, 7);
char str[0x40]; // Commented-out, since ints *technically* have an undefined length
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 // There must have been some kind of console print function here or something
return TRUE; return TRUE;
} }

View file

@ -4,6 +4,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <string>
#include "WindowsWrapper.h" #include "WindowsWrapper.h"
@ -25,8 +26,8 @@
#include "Sound.h" #include "Sound.h"
#include "Triangle.h" #include "Triangle.h"
char gModulePath[MAX_PATH]; std::string gModulePath;
char gDataPath[MAX_PATH]; std::string gDataPath;
BOOL bFullscreen; BOOL bFullscreen;
BOOL gbUseJoystick = FALSE; BOOL gbUseJoystick = FALSE;
@ -93,24 +94,23 @@ int main(int argc, char *argv[])
return EXIT_FAILURE; return EXIT_FAILURE;
// Get executable's path // Get executable's path
if (!Backend_GetBasePath(gModulePath)) if (!Backend_GetBasePath(&gModulePath))
{ {
// Fall back on argv[0] if the backend cannot provide a path // Fall back on argv[0] if the backend cannot provide a path
strcpy(gModulePath, argv[0]); gModulePath = argv[0];
for (size_t i = strlen(gModulePath);; --i) for (size_t i = gModulePath.length();; --i)
{ {
if (i == 0 || gModulePath[i] == '\\' || gModulePath[i] == '/') if (i == 0 || gModulePath[i] == '\\' || gModulePath[i] == '/')
{ {
gModulePath[i] = '\0'; gModulePath.resize(i);
break; break;
} }
} }
} }
// Get path of the data folder // Get path of the data folder
strcpy(gDataPath, gModulePath); gDataPath = gModulePath + "/data";
strcat(gDataPath, "/data");
CONFIG conf; CONFIG conf;
if (!LoadConfigData(&conf)) if (!LoadConfigData(&conf))

View file

@ -1,9 +1,11 @@
#pragma once #pragma once
#include <string>
#include "WindowsWrapper.h" #include "WindowsWrapper.h"
extern char gModulePath[MAX_PATH]; extern std::string gModulePath;
extern char gDataPath[MAX_PATH]; extern std::string gDataPath;
extern BOOL bFullscreen; extern BOOL bFullscreen;
extern BOOL gbUseJoystick; extern BOOL gbUseJoystick;

View file

@ -4,6 +4,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <string>
#include "WindowsWrapper.h" #include "WindowsWrapper.h"
@ -29,13 +30,13 @@ BOOL LoadMapData2(const char *path_map)
{ {
FILE *fp; FILE *fp;
char check[3]; char check[3];
char path[MAX_PATH]; std::string path;
// Get path // Get path
sprintf(path, "%s/%s", gDataPath, path_map); path = gDataPath + '/' + path_map;
// Open file // Open file
fp = fopen(path, "rb"); fp = fopen(path.c_str(), "rb");
if (fp == NULL) if (fp == NULL)
return FALSE; return FALSE;
@ -69,12 +70,12 @@ BOOL LoadMapData2(const char *path_map)
BOOL LoadAttributeData(const char *path_atrb) BOOL LoadAttributeData(const char *path_atrb)
{ {
FILE *fp; FILE *fp;
char path[MAX_PATH]; std::string path;
// Open file // Open file
sprintf(path, "%s/%s", gDataPath, path_atrb); path = gDataPath + '/' + path_atrb;
fp = fopen(path, "rb"); fp = fopen(path.c_str(), "rb");
if (fp == NULL) if (fp == NULL)
return FALSE; return FALSE;

View file

@ -1,6 +1,7 @@
#include "MycParam.h" #include "MycParam.h"
#include <stdio.h> #include <stdio.h>
#include <string>
#include "WindowsWrapper.h" #include "WindowsWrapper.h"
@ -436,16 +437,16 @@ BOOL SaveTimeCounter(void)
unsigned char p[4]; unsigned char p[4];
REC rec; REC rec;
FILE *fp; FILE *fp;
char path[MAX_PATH]; std::string path;
// Quit if player doesn't have the Nikumaru Counter // Quit if player doesn't have the Nikumaru Counter
if (!(gMC.equip & EQUIP_NIKUMARU_COUNTER)) if (!(gMC.equip & EQUIP_NIKUMARU_COUNTER))
return TRUE; return TRUE;
// Get last time // Get last time
sprintf(path, "%s/290.rec", gModulePath); path = gModulePath + "/290.rec";
fp = fopen(path, "rb"); fp = fopen(path.c_str(), "rb");
if (fp != NULL) if (fp != NULL)
{ {
// Read data // Read data
@ -485,7 +486,7 @@ BOOL SaveTimeCounter(void)
rec.counter[i] = p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24); rec.counter[i] = p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24);
} }
fp = fopen(path, "wb"); fp = fopen(path.c_str(), "wb");
if (fp == NULL) if (fp == NULL)
return FALSE; return FALSE;
@ -508,12 +509,12 @@ int LoadTimeCounter(void)
unsigned char p[4]; unsigned char p[4];
REC rec; REC rec;
FILE *fp; FILE *fp;
char path[MAX_PATH]; std::string path;
// Open file // Open file
sprintf(path, "%s/290.rec", gModulePath); path = gModulePath + "/290.rec";
fp = fopen(path, "rb"); fp = fopen(path.c_str(), "rb");
if (fp == NULL) if (fp == NULL)
return 0; return 0;

View file

@ -3,6 +3,7 @@
#include <stddef.h> #include <stddef.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <string>
#include "WindowsWrapper.h" #include "WindowsWrapper.h"
@ -59,10 +60,9 @@ BOOL LoadEvent(const char *path_event)
char code[4]; char code[4];
EVENT eve; EVENT eve;
char path[MAX_PATH]; std::string path = gDataPath + '/' + path_event;
sprintf(path, "%s/%s", gDataPath, path_event);
fp = fopen(path, "rb"); fp = fopen(path.c_str(), "rb");
if (fp == NULL) if (fp == NULL)
return FALSE; return FALSE;

View file

@ -3,6 +3,7 @@
#include <stddef.h> #include <stddef.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <string>
#include "WindowsWrapper.h" #include "WindowsWrapper.h"
@ -28,10 +29,9 @@ const char* const gProfileCode = "Do041220";
BOOL IsProfile(void) BOOL IsProfile(void)
{ {
char path[MAX_PATH]; std::string path = gModulePath + '/' + gDefaultName;
sprintf(path, "%s/%s", gModulePath, gDefaultName);
FILE *file = fopen(path, "rb"); FILE *file = fopen(path.c_str(), "rb");
if (file == NULL) if (file == NULL)
return FALSE; return FALSE;
@ -45,16 +45,16 @@ BOOL SaveProfile(const char *name)
PROFILE profile; PROFILE profile;
const char *FLAG = "FLAG"; const char *FLAG = "FLAG";
char path[MAX_PATH]; std::string path;
// Get path // Get path
if (name != NULL) if (name != NULL)
sprintf(path, "%s/%s", gModulePath, name); path = gModulePath + '/' + name;
else else
sprintf(path, "%s/%s", gModulePath, gDefaultName); path = gModulePath + '/' + gDefaultName;
// Open file // Open file
fp = fopen(path, "wb"); fp = fopen(path.c_str(), "wb");
if (fp == NULL) if (fp == NULL)
return FALSE; return FALSE;
@ -124,16 +124,16 @@ BOOL LoadProfile(const char *name)
{ {
FILE *fp; FILE *fp;
PROFILE profile; PROFILE profile;
char path[MAX_PATH]; std::string path;
// Get path // Get path
if (name != NULL) if (name != NULL)
sprintf(path, "%s", name); path = name;
else else
sprintf(path, "%s/%s", gModulePath, gDefaultName); path = gModulePath + '/' + gDefaultName;
// Open file // Open file
fp = fopen(path, "rb"); fp = fopen(path.c_str(), "rb");
if (fp == NULL) if (fp == NULL)
return FALSE; return FALSE;

View file

@ -1,6 +1,7 @@
#include "SelStage.h" #include "SelStage.h"
#include <string.h> #include <string.h>
#include <string>
#include "WindowsWrapper.h" #include "WindowsWrapper.h"
@ -156,13 +157,13 @@ void PutStageSelectObject(void)
int StageSelectLoop(int *p_event) int StageSelectLoop(int *p_event)
{ {
char old_script_path[MAX_PATH]; std::string old_script_path;
RECT rcView = {0, 0, WINDOW_WIDTH, WINDOW_HEIGHT}; RECT rcView = {0, 0, WINDOW_WIDTH, WINDOW_HEIGHT};
gSelectedStage = 0; gSelectedStage = 0;
BackupSurface(SURFACE_ID_SCREEN_GRAB, &grcFull); BackupSurface(SURFACE_ID_SCREEN_GRAB, &grcFull);
GetTextScriptPath(old_script_path); old_script_path = GetTextScriptPath();
LoadTextScript2("StageSelect.tsc"); LoadTextScript2("StageSelect.tsc");
gStageSelectTitleY = (WINDOW_HEIGHT / 2) - 66; gStageSelectTitleY = (WINDOW_HEIGHT / 2) - 66;
StartTextScript(gPermitStage[gSelectedStage].index + 1000); StartTextScript(gPermitStage[gSelectedStage].index + 1000);
@ -211,7 +212,7 @@ int StageSelectLoop(int *p_event)
else if (gKeyTrg & gKeyCancel) else if (gKeyTrg & gKeyCancel)
{ {
StopTextScript(); StopTextScript();
LoadTextScript_Stage(old_script_path); LoadTextScript_Stage(old_script_path.c_str());
*p_event = 0; *p_event = 0;
return enum_ESCRETURN_continue; return enum_ESCRETURN_continue;
} }
@ -222,7 +223,7 @@ int StageSelectLoop(int *p_event)
return enum_ESCRETURN_exit; return enum_ESCRETURN_exit;
} }
LoadTextScript_Stage(old_script_path); LoadTextScript_Stage(old_script_path.c_str());
*p_event = gPermitStage[gSelectedStage].event; *p_event = gPermitStage[gSelectedStage].event;
return enum_ESCRETURN_continue; return enum_ESCRETURN_continue;
} }

View file

@ -2,6 +2,7 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <string>
#include "WindowsWrapper.h" #include "WindowsWrapper.h"
@ -131,8 +132,8 @@ const STAGE_TABLE gTMT[95] = {
BOOL TransferStage(int no, int w, int x, int y) BOOL TransferStage(int no, int w, int x, int y)
{ {
char path[MAX_PATH]; std::string path;
char path_dir[20]; std::string path_dir;
BOOL bError; BOOL bError;
// Move character // Move character
@ -141,47 +142,47 @@ BOOL TransferStage(int no, int w, int x, int y)
bError = FALSE; bError = FALSE;
// Get path // Get path
strcpy(path_dir, "Stage"); path_dir = "Stage";
// Load tileset // Load tileset
sprintf(path, "%s/Prt%s", path_dir, gTMT[no].parts); path = path_dir + "/Prt" + gTMT[no].parts;
if (!ReloadBitmap_File(path, SURFACE_ID_LEVEL_TILESET)) if (!ReloadBitmap_File(path.c_str(), SURFACE_ID_LEVEL_TILESET))
bError = TRUE; bError = TRUE;
sprintf(path, "%s/%s.pxa", path_dir, gTMT[no].parts); path = path_dir + '/' + gTMT[no].parts + ".pxa";
if (!LoadAttributeData(path)) if (!LoadAttributeData(path.c_str()))
bError = TRUE; bError = TRUE;
// Load tilemap // Load tilemap
sprintf(path, "%s/%s.pxm", path_dir, gTMT[no].map); path = path_dir + '/' + gTMT[no].map + ".pxm";
if (!LoadMapData2(path)) if (!LoadMapData2(path.c_str()))
bError = TRUE; bError = TRUE;
// Load NPCs // Load NPCs
sprintf(path, "%s/%s.pxe", path_dir, gTMT[no].map); path = path_dir + '/' + gTMT[no].map + ".pxe";
if (!LoadEvent(path)) if (!LoadEvent(path.c_str()))
bError = TRUE; bError = TRUE;
// Load script // Load script
sprintf(path, "%s/%s.tsc", path_dir, gTMT[no].map); path = path_dir + '/' + gTMT[no].map + ".tsc";
if (!LoadTextScript_Stage(path)) if (!LoadTextScript_Stage(path.c_str()))
bError = TRUE; bError = TRUE;
// Load background // Load background
sprintf(path, "%s", gTMT[no].back); path = gTMT[no].back;
if (!InitBack(path, gTMT[no].bkType)) if (!InitBack(path.c_str(), gTMT[no].bkType))
bError = TRUE; bError = TRUE;
// Get path // Get path
strcpy(path_dir, "Npc"); path_dir = "Npc";
// Load NPC sprite sheets // Load NPC sprite sheets
sprintf(path, "%s/Npc%s", path_dir, gTMT[no].npc); path = path_dir + "/Npc" + gTMT[no].npc;
if (!ReloadBitmap_File(path, SURFACE_ID_LEVEL_SPRITESET_1)) if (!ReloadBitmap_File(path.c_str(), SURFACE_ID_LEVEL_SPRITESET_1))
bError = TRUE; bError = TRUE;
sprintf(path, "%s/Npc%s", path_dir, gTMT[no].boss); path = path_dir + "/Npc" + gTMT[no].boss;
if (!ReloadBitmap_File(path, SURFACE_ID_LEVEL_SPRITESET_2)) if (!ReloadBitmap_File(path.c_str(), SURFACE_ID_LEVEL_SPRITESET_2))
bError = TRUE; bError = TRUE;
if (bError) if (bError)

View file

@ -3,6 +3,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <string>
#include "WindowsWrapper.h" #include "WindowsWrapper.h"
@ -124,17 +125,17 @@ void EncryptionBinaryData2(unsigned char *pData, long size)
BOOL LoadTextScript2(const char *name) BOOL LoadTextScript2(const char *name)
{ {
FILE *fp; FILE *fp;
char path[MAX_PATH]; std::string path;
// Get path // Get path
sprintf(path, "%s/%s", gDataPath, name); path = gDataPath + '/' + name;
gTS.size = GetFileSizeLong(path); gTS.size = GetFileSizeLong(path.c_str());
if (gTS.size == -1) if (gTS.size == -1)
return FALSE; return FALSE;
// Open file // Open file
fp = fopen(path, "rb"); fp = fopen(path.c_str(), "rb");
if (fp == NULL) if (fp == NULL)
return FALSE; return FALSE;
@ -144,7 +145,7 @@ BOOL LoadTextScript2(const char *name)
fclose(fp); fclose(fp);
// Set path // Set path
strcpy(gTS.path, name); gTS.path = name;
// Decrypt data // Decrypt data
EncryptionBinaryData2((unsigned char*)gTS.data, gTS.size); EncryptionBinaryData2((unsigned char*)gTS.data, gTS.size);
@ -156,18 +157,18 @@ BOOL LoadTextScript2(const char *name)
BOOL LoadTextScript_Stage(const char *name) BOOL LoadTextScript_Stage(const char *name)
{ {
FILE *fp; FILE *fp;
char path[MAX_PATH]; std::string path;
long head_size; long head_size;
long body_size; long body_size;
// Open Head.tsc // Open Head.tsc
sprintf(path, "%s/%s", gDataPath, "Head.tsc"); path = gDataPath + "/Head.tsc";
head_size = GetFileSizeLong(path); head_size = GetFileSizeLong(path.c_str());
if (head_size == -1) if (head_size == -1)
return FALSE; return FALSE;
fp = fopen(path, "rb"); fp = fopen(path.c_str(), "rb");
if (fp == NULL) if (fp == NULL)
return FALSE; return FALSE;
@ -178,13 +179,13 @@ BOOL LoadTextScript_Stage(const char *name)
fclose(fp); fclose(fp);
// Open stage's .tsc // Open stage's .tsc
sprintf(path, "%s/%s", gDataPath, name); path = gDataPath + '/' + name;
body_size = GetFileSizeLong(path); body_size = GetFileSizeLong(path.c_str());
if (body_size == -1) if (body_size == -1)
return FALSE; return FALSE;
fp = fopen(path, "rb"); fp = fopen(path.c_str(), "rb");
if (fp == NULL) if (fp == NULL)
return FALSE; return FALSE;
@ -196,15 +197,15 @@ BOOL LoadTextScript_Stage(const char *name)
// Set parameters // Set parameters
gTS.size = head_size + body_size; gTS.size = head_size + body_size;
strcpy(gTS.path, name); gTS.path = name;
return TRUE; return TRUE;
} }
// Get current path // Get current path
void GetTextScriptPath(char *path) std::string GetTextScriptPath(void)
{ {
strcpy(path, gTS.path); return gTS.path;
} }
// Get 4 digit number from TSC data // Get 4 digit number from TSC data

View file

@ -1,11 +1,13 @@
#pragma once #pragma once
#include <string>
#include "WindowsWrapper.h" #include "WindowsWrapper.h"
typedef struct TEXT_SCRIPT typedef struct TEXT_SCRIPT
{ {
// Path (reload when exit teleporter menu/inventory) // Path (reload when exit teleporter menu/inventory)
char path[MAX_PATH]; std::string path;
// Script buffer // Script buffer
long size; long size;
@ -62,7 +64,7 @@ void EndTextScript(void);
void EncryptionBinaryData2(unsigned char *pData, long size); void EncryptionBinaryData2(unsigned char *pData, long size);
BOOL LoadTextScript2(const char *name); BOOL LoadTextScript2(const char *name);
BOOL LoadTextScript_Stage(const char *name); BOOL LoadTextScript_Stage(const char *name);
void GetTextScriptPath(char *path); std::string GetTextScriptPath(void);
BOOL StartTextScript(int no); BOOL StartTextScript(int no);
void StopTextScript(void); void StopTextScript(void);
void PutTextScript(void); void PutTextScript(void);

View file

@ -6,8 +6,6 @@
#undef FindResource #undef FindResource
#else #else
#include <stdio.h>
#define RGB(r,g,b) ((r) | ((g) << 8) | ((b) << 16)) #define RGB(r,g,b) ((r) | ((g) << 8) | ((b) << 16))
typedef bool BOOL; typedef bool BOOL;
@ -23,6 +21,4 @@ struct RECT
long bottom; long bottom;
}; };
#define MAX_PATH FILENAME_MAX
#endif #endif