diff --git a/Makefile b/Makefile index a80ef2dfe..0597f8870 100644 --- a/Makefile +++ b/Makefile @@ -209,7 +209,7 @@ clean: $(ENAME): $(BUILD_DIR) $(OBJECTS) - $(CC) $(LDFLAGS) -o $@$(OEXT) $(OBJECTS) $(EXTRALIBS) $(LIBS) + $(CC) $(LDFLAGS) -o $@$(OEXT) $(OBJECTS) $(EXTRA_LIBS) $(LIBS) $(BUILD_DIR): mkdir -p $(BUILD_DIR) @@ -222,21 +222,21 @@ DEPFILES := $(patsubst $(SOURCE_DIR)/%.c, $(BUILD_DIR)/%.d, $(C_SOURCES)) $(DEPFILES): $(C_OBJECTS): $(BUILD_DIR)/%.o : $(SOURCE_DIR)/%.c $(BUILD_DIR)/%.d - $(CC) $(CFLAGS) $(EXTRAFLAGS) $(DEPFLAGS) -c $< -o $@ + $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(DEPFLAGS) -c $< -o $@ include $(wildcard $(DEPFILES)) # === Compiling WITHOUT dependency tracking === else $(C_OBJECTS): $(BUILD_DIR)/%.o : $(SOURCE_DIR)/%.c - $(CC) $(CFLAGS) $(EXTRAFLAGS) -c $< -o $@ + $(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c $< -o $@ endif # === Platform specific file compiling === $(BUILD_DIR)/%.o: $(SOURCE_DIR)/%.m - $(CC) $(CFLAGS) $(EXTRAFLAGS) -c $< -o $@ + $(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c $< -o $@ $(BUILD_DIR)/%.o: $(SOURCE_DIR)/%.cpp - $(CC) $(CFLAGS) $(EXTRAFLAGS) -c $< -o $@ + $(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c $< -o $@ -# EXTRAFLAGS and EXTRALIBS are not defined in the makefile intentionally - +# EXTRA_CFLAGS and EXTRA_LIBS are not defined in the makefile intentionally - # define them on the command line as a simple way of adding CFLAGS/LIBS diff --git a/src/Menus.c b/src/Menus.c index 69cd207d6..2ba2d6c13 100644 --- a/src/Menus.c +++ b/src/Menus.c @@ -1396,6 +1396,7 @@ static void SaveLevelScreen_Save(void* screen, void* widget) { struct ButtonWidget* btn = (struct ButtonWidget*)widget; cc_string path; char pathBuffer[FILENAME_SIZE]; cc_string file = s->input.base.text; + cc_filepath str; cc_result res; if (!file.length) { @@ -1407,7 +1408,8 @@ static void SaveLevelScreen_Save(void* screen, void* widget) { String_Format1(&path, "maps/%s.cw", &file); String_Copy(&World.Name, &file); - if (File_Exists(&path) && !btn->optName) { + Platform_EncodePath(&str, &path); + if (File_Exists(&str) && !btn->optName) { btn->optName = ""; SaveLevelScreen_UpdateSave(s); return; diff --git a/src/Platform.h b/src/Platform.h index 3ada2642f..f73f6ea44 100644 --- a/src/Platform.h +++ b/src/Platform.h @@ -197,7 +197,7 @@ typedef void (*Directory_EnumCallback)(const cc_string* filename, void* obj, int /* Invokes a callback function on all filenames in the given directory (and its sub-directories) */ CC_API cc_result Directory_Enum(const cc_string* path, void* obj, Directory_EnumCallback callback); /* Returns non-zero if the given file exists. */ -CC_API int File_Exists(const cc_string* path); +int File_Exists(const cc_filepath* path); void Directory_GetCachePath(cc_string* path); /* Attempts to create a new (or overwrite) file for writing. */ diff --git a/src/Platform_3DS.c b/src/Platform_3DS.c index a62322246..cef6b0fc7 100644 --- a/src/Platform_3DS.c +++ b/src/Platform_3DS.c @@ -102,12 +102,9 @@ cc_result Directory_Create(const cc_filepath* path) { return mkdir(path->buffer, 0666) == -1 ? errno : 0; // FS has no permissions anyways } -int File_Exists(const cc_string* path) { - cc_filepath str; +int File_Exists(const cc_filepath* path) { struct stat sb; - Platform_EncodePath(&str, path); - - return stat(str.buffer, &sb) == 0 && S_ISREG(sb.st_mode); + return stat(path->buffer, &sb) == 0 && S_ISREG(sb.st_mode); } cc_result Directory_Enum(const cc_string* dirPath, void* obj, Directory_EnumCallback callback) { diff --git a/src/Platform_Dreamcast.c b/src/Platform_Dreamcast.c index efd590aa3..088ba0e78 100644 --- a/src/Platform_Dreamcast.c +++ b/src/Platform_Dreamcast.c @@ -208,11 +208,9 @@ cc_result Directory_Create(const cc_filepath* path) { return err; } -int File_Exists(const cc_string* path) { - cc_filepath str;; +int File_Exists(const cc_filepath* path) { struct stat sb; - Platform_EncodePath(&str, path); - return fs_stat(str.buffer, &sb, 0) == 0 && S_ISREG(sb.st_mode); + return fs_stat(path->buffer, &sb, 0) == 0 && S_ISREG(sb.st_mode); } cc_result Directory_Enum(const cc_string* dirPath, void* obj, Directory_EnumCallback callback) { diff --git a/src/Platform_GCWii.c b/src/Platform_GCWii.c index 21cdf3b47..c1ed74685 100644 --- a/src/Platform_GCWii.c +++ b/src/Platform_GCWii.c @@ -133,13 +133,11 @@ cc_result Directory_Create(const cc_filepath* path) { return mkdir(path->buffer, 0) == -1 ? errno : 0; } -int File_Exists(const cc_string* path) { +int File_Exists(const cc_filepath* path) { if (!fat_available) return false; - cc_filepath str; struct stat sb; - Platform_EncodePath(&str, path); - return stat(str.buffer, &sb) == 0 && S_ISREG(sb.st_mode); + return stat(path->buffer, &sb) == 0 && S_ISREG(sb.st_mode); } cc_result Directory_Enum(const cc_string* dirPath, void* obj, Directory_EnumCallback callback) { diff --git a/src/Platform_MacClassic.c b/src/Platform_MacClassic.c index 7b418ff6a..01978b60f 100644 --- a/src/Platform_MacClassic.c +++ b/src/Platform_MacClassic.c @@ -236,11 +236,8 @@ cc_result Directory_Create(const cc_filepath* path) { return DoCreateFolder(path->buffer); } -int File_Exists(const cc_string* path) { - cc_filepath str; - Platform_EncodePath(&str, path); - - return 0; +int File_Exists(const cc_filepath* path) { + return false; // TODO } cc_result Directory_Enum(const cc_string* dirPath, void* obj, Directory_EnumCallback callback) { diff --git a/src/Platform_N64.c b/src/Platform_N64.c index 3341ac563..2a8b3c6e0 100644 --- a/src/Platform_N64.c +++ b/src/Platform_N64.c @@ -86,7 +86,7 @@ cc_result Directory_Create(const cc_filepath* path) { return ERR_NOT_SUPPORTED; } -int File_Exists(const cc_string* path) { +int File_Exists(const cc_filepath* path) { return false; } diff --git a/src/Platform_NDS.c b/src/Platform_NDS.c index 97c735265..549a5afea 100644 --- a/src/Platform_NDS.c +++ b/src/Platform_NDS.c @@ -118,19 +118,16 @@ void Platform_EncodePath(cc_filepath* dst, const cc_string* path) { cc_result Directory_Create(const cc_filepath* path) { if (!fat_available) return 0; - Platform_Log1("mkdir %c", path->buffer); + Platform_Log1("mkdir %c", path->buffer); return mkdir(path->buffer, 0) == -1 ? errno : 0; } -int File_Exists(const cc_string* path) { +int File_Exists(const cc_filepath* path) { if (!fat_available) return false; - - cc_filepath str; struct stat sb; - Platform_EncodePath(&str, path); - Platform_Log1("Check %c", str.buffer); - - return stat(str.buffer, &sb) == 0 && S_ISREG(sb.st_mode); + + Platform_Log1("Check %c", path->buffer); + return stat(path->buffer, &sb) == 0 && S_ISREG(sb.st_mode); } cc_result Directory_Enum(const cc_string* dirPath, void* obj, Directory_EnumCallback callback) { diff --git a/src/Platform_PS1.c b/src/Platform_PS1.c index ccc5028f0..f23905a8d 100644 --- a/src/Platform_PS1.c +++ b/src/Platform_PS1.c @@ -98,8 +98,8 @@ cc_result Directory_Create(const cc_filepath* path) { return ERR_NOT_SUPPORTED; } -int File_Exists(const cc_string* path) { - return ERR_NOT_SUPPORTED; +int File_Exists(const cc_filepath* path) { + return false; } cc_result Directory_Enum(const cc_string* dirPath, void* obj, Directory_EnumCallback callback) { diff --git a/src/Platform_PS2.c b/src/Platform_PS2.c index 7bdc2378b..b8fa83788 100644 --- a/src/Platform_PS2.c +++ b/src/Platform_PS2.c @@ -116,11 +116,9 @@ cc_result Directory_Create(const cc_filepath* path) { return fioMkdir(path->buffer); } -int File_Exists(const cc_string* path) { - cc_filepath str; +int File_Exists(const cc_filepath* path) { io_stat_t sb; - Platform_EncodePath(&str, path); - return fioGetstat(str.buffer, &sb) >= 0 && (sb.mode & FIO_SO_IFREG); + return fioGetstat(path->buffer, &sb) >= 0 && (sb.mode & FIO_SO_IFREG); } // For some reason fioDread seems to be returning a iox_dirent_t, instead of a io_dirent_t diff --git a/src/Platform_PS3.c b/src/Platform_PS3.c index 5d8d69ae4..22ec956e8 100644 --- a/src/Platform_PS3.c +++ b/src/Platform_PS3.c @@ -108,11 +108,9 @@ cc_result Directory_Create(const cc_filepath* path) { return sysLv2FsMkdir(path->buffer, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); } -int File_Exists(const cc_string* path) { - cc_filepath str; +int File_Exists(const cc_filepath* path) { sysFSStat sb; - Platform_EncodePath(&str, path); - return sysLv2FsStat(str.buffer, &sb) == 0 && S_ISREG(sb.st_mode); + return sysLv2FsStat(path->buffer, &sb) == 0 && S_ISREG(sb.st_mode); } cc_result Directory_Enum(const cc_string* dirPath, void* obj, Directory_EnumCallback callback) { diff --git a/src/Platform_PSP.c b/src/Platform_PSP.c index 3313953ab..8501902c7 100644 --- a/src/Platform_PSP.c +++ b/src/Platform_PSP.c @@ -100,11 +100,9 @@ cc_result Directory_Create(const cc_filepath* path) { return GetSCEResult(result); } -int File_Exists(const cc_string* path) { - cc_filepath str; +int File_Exists(const cc_filepath* path) { SceIoStat sb; - Platform_EncodePath(&str, path); - return sceIoGetstat(str.buffer, &sb) == 0 && (sb.st_attr & FIO_SO_IFREG) != 0; + return sceIoGetstat(path->buffer, &sb) == 0 && (sb.st_attr & FIO_SO_IFREG) != 0; } cc_result Directory_Enum(const cc_string* dirPath, void* obj, Directory_EnumCallback callback) { diff --git a/src/Platform_PSVita.c b/src/Platform_PSVita.c index 6d4e72e8c..30236b0e8 100644 --- a/src/Platform_PSVita.c +++ b/src/Platform_PSVita.c @@ -83,11 +83,9 @@ cc_result Directory_Create(const cc_filepath* path) { return GetSCEResult(result); } -int File_Exists(const cc_string* path) { - cc_filepath str;; +int File_Exists(const cc_filepath* path) { SceIoStat sb; - Platform_EncodePath(&str, path); - return sceIoGetstat(str.buffer, &sb) == 0 && SCE_S_ISREG(sb.st_mode) != 0; + return sceIoGetstat(path->buffer, &sb) == 0 && SCE_S_ISREG(sb.st_mode) != 0; } cc_result Directory_Enum(const cc_string* dirPath, void* obj, Directory_EnumCallback callback) { diff --git a/src/Platform_Posix.c b/src/Platform_Posix.c index e49652814..4b265b5b5 100644 --- a/src/Platform_Posix.c +++ b/src/Platform_Posix.c @@ -211,12 +211,9 @@ cc_result Directory_Create(const cc_filepath* path) { return mkdir(path->buffer, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) == -1 ? errno : 0; } -int File_Exists(const cc_string* path) { +int File_Exists(const cc_filepath* path) { struct stat sb; - cc_filepath str; - Platform_EncodePath(&str, path); - - return stat(str.buffer, &sb) == 0 && S_ISREG(sb.st_mode); + return stat(path->buffer, &sb) == 0 && S_ISREG(sb.st_mode); } cc_result Directory_Enum(const cc_string* dirPath, void* obj, Directory_EnumCallback callback) { diff --git a/src/Platform_Saturn.c b/src/Platform_Saturn.c index ad67a4a10..a7eee8e7e 100644 --- a/src/Platform_Saturn.c +++ b/src/Platform_Saturn.c @@ -94,8 +94,8 @@ cc_result Directory_Create(const cc_filepath* path) { return ReturnCode_DirectoryExists; } -int File_Exists(const cc_string* path) { - return ERR_NOT_SUPPORTED; +int File_Exists(const cc_filepath* path) { + return false; } cc_result Directory_Enum(const cc_string* dirPath, void* obj, Directory_EnumCallback callback) { diff --git a/src/Platform_Switch.c b/src/Platform_Switch.c index 82b8d4fb9..c638b5791 100644 --- a/src/Platform_Switch.c +++ b/src/Platform_Switch.c @@ -120,11 +120,9 @@ cc_result Directory_Create(const cc_filepath* path) { return mkdir(path->buffer, 0) == -1 ? errno : 0; } -int File_Exists(const cc_string* path) { - cc_filepath str; +int File_Exists(const cc_filepath* path) { struct stat sb; - Platform_EncodePath(&str, path); - return stat(str.buffer, &sb) == 0 && S_ISREG(sb.st_mode); + return stat(path->buffer, &sb) == 0 && S_ISREG(sb.st_mode); } cc_result Directory_Enum(const cc_string* dirPath, void* obj, Directory_EnumCallback callback) { diff --git a/src/Platform_Web.c b/src/Platform_Web.c index 4688b60fe..872c29f0e 100644 --- a/src/Platform_Web.c +++ b/src/Platform_Web.c @@ -114,10 +114,8 @@ cc_result Directory_Create(const cc_filepath* path) { } extern int interop_FileExists(const char* path); -int File_Exists(const cc_string* path) { - cc_filepath str; - Platform_EncodePath(&str, path); - return interop_FileExists(str.buffer); +int File_Exists(const cc_filepath* path) { + return interop_FileExists(path->buffer); } static void* enum_obj; diff --git a/src/Platform_WiiU.c b/src/Platform_WiiU.c index 27759801b..f8f305506 100644 --- a/src/Platform_WiiU.c +++ b/src/Platform_WiiU.c @@ -116,11 +116,9 @@ cc_result Directory_Create(const cc_filepath* path) { return mkdir(path->buffer, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) == -1 ? errno : 0; } -int File_Exists(const cc_string* path) { - cc_filepath str; +int File_Exists(const cc_filepath* path) { struct stat sb; - Platform_EncodePath(&str, path); - return stat(str.buffer, &sb) == 0 && S_ISREG(sb.st_mode); + return stat(path->buffer, &sb) == 0 && S_ISREG(sb.st_mode); } cc_result Directory_Enum(const cc_string* dirPath, void* obj, Directory_EnumCallback callback) { diff --git a/src/Platform_Windows.c b/src/Platform_Windows.c index 0bce43a7c..1716c1088 100644 --- a/src/Platform_Windows.c +++ b/src/Platform_Windows.c @@ -193,12 +193,11 @@ cc_result Directory_Create(const cc_filepath* path) { return CreateDirectoryA(path->ansi, NULL) ? 0 : GetLastError(); } -int File_Exists(const cc_string* path) { - cc_filepath str; - DWORD attribs; - - Platform_EncodePath(&str, path); - attribs = GetFileAttributesW(str.uni); +int File_Exists(const cc_filepath* path) { + DWORD attribs = GetFileAttributesW(path->uni); + + if (attribs == INVALID_FILE_ATTRIBUTES) + attribs = GetFileAttributesA(path->ansi); return attribs != INVALID_FILE_ATTRIBUTES && !(attribs & FILE_ATTRIBUTE_DIRECTORY); } diff --git a/src/Platform_Xbox.c b/src/Platform_Xbox.c index 9066427f1..87eb3ab14 100644 --- a/src/Platform_Xbox.c +++ b/src/Platform_Xbox.c @@ -107,15 +107,10 @@ cc_result Directory_Create(const cc_filepath* path) { return CreateDirectoryA(path->buffer, NULL) ? 0 : GetLastError(); } -int File_Exists(const cc_string* path) { +int File_Exists(const cc_filepath* path) { if (!hdd_mounted) return 0; - cc_filepath str; - DWORD attribs; - - Platform_EncodePath(&str, path); - attribs = GetFileAttributesA(str.buffer); - + DWORD attribs = GetFileAttributesA(path->buffer); return attribs != INVALID_FILE_ATTRIBUTES && !(attribs & FILE_ATTRIBUTE_DIRECTORY); } diff --git a/src/Platform_Xbox360.c b/src/Platform_Xbox360.c index bac9afe1f..3eba6885c 100644 --- a/src/Platform_Xbox360.c +++ b/src/Platform_Xbox360.c @@ -89,11 +89,9 @@ cc_result Directory_Create(const cc_filepath* path) { return mkdir(path->buffer, 0) == -1 ? errno : 0; } -int File_Exists(const cc_string* path) { - cc_filepath str; +int File_Exists(const cc_filepath* path) { struct stat sb; - Platform_EncodePath(&str, path); - return stat(str.buffer, &sb) == 0 && S_ISREG(sb.st_mode); + return stat(path->buffer, &sb) == 0 && S_ISREG(sb.st_mode); } cc_result Directory_Enum(const cc_string* dirPath, void* obj, Directory_EnumCallback callback) { diff --git a/src/Resources.c b/src/Resources.c index 4040634aa..237a3c1e3 100644 --- a/src/Resources.c +++ b/src/Resources.c @@ -399,6 +399,7 @@ static struct MusicAsset { static void MusicAssets_CheckExistence(void) { cc_string path; char pathBuffer[FILENAME_SIZE]; + cc_filepath str; int i; String_InitArray(path, pathBuffer); @@ -407,7 +408,8 @@ static void MusicAssets_CheckExistence(void) { path.length = 0; String_Format1(&path, "audio/%c", musicAssets[i].name); - musicAssets[i].downloaded = File_Exists(&path); + Platform_EncodePath(&str, &path); + musicAssets[i].downloaded = File_Exists(&str); } } @@ -679,7 +681,10 @@ static cc_bool ccTexturesExist, ccTexturesDownloaded; static int ccTexturesReqID; static void CCTextures_CheckExistence(void) { - ccTexturesExist = File_Exists(&ccTexPack); + cc_filepath path; + Platform_EncodePath(&path, &ccTexPack); + + ccTexturesExist = File_Exists(&path); } static void CCTextures_CountMissing(void) { diff --git a/src/TexturePack.c b/src/TexturePack.c index 354fc4da8..4ebdbeb36 100644 --- a/src/TexturePack.c +++ b/src/TexturePack.c @@ -336,11 +336,16 @@ CC_NOINLINE static void MakeCachePath(cc_string* mainPath, cc_string* altPath, c static int IsCached(const cc_string* url) { cc_string mainPath; char mainBuffer[FILENAME_SIZE]; cc_string altPath; char altBuffer[FILENAME_SIZE]; + cc_filepath mainStr, altStr; + String_InitArray(mainPath, mainBuffer); String_InitArray(altPath, altBuffer); MakeCachePath(&mainPath, &altPath, url); - return File_Exists(&mainPath) || (altPath.length && File_Exists(&altPath)); + Platform_EncodePath(&mainStr, &mainPath); + Platform_EncodePath(&altStr, &altPath); + + return File_Exists(&mainStr) || (altPath.length && File_Exists(&altStr)); } /* Attempts to open the cached data stream for the given url */ diff --git a/src/main.c b/src/main.c index 591147f0c..9f88e26db 100644 --- a/src/main.c +++ b/src/main.c @@ -69,7 +69,14 @@ static void SetupProgram(int argc, char** argv) { String_InitArray(Server.Address, ipBuffer); } -#define SP_HasDir(path) (String_IndexOf(&path, '/') >= 0 || String_IndexOf(&path, '\\') >= 0) +#define SP_HasDir(path) (String_IndexOf(path, '/') >= 0 || String_IndexOf(path, '\\') >= 0) +static cc_bool IsOpenableFile(const cc_string* path) { + cc_filepath str; + if (!SP_HasDir(path)) return false; + + Platform_EncodePath(&str, path); + return File_Exists(&str); +} static int RunProgram(int argc, char** argv) { cc_string args[GAME_MAX_CMDARGS]; @@ -93,7 +100,7 @@ static int RunProgram(int argc, char** argv) { String_Copy(&Launcher_AutoHash, &args[0]); Launcher_Run(); /* File path to auto load a map in singleplayer */ - } else if (argsCount == 1 && SP_HasDir(args[0]) && File_Exists(&args[0])) { + } else if (argsCount == 1 && IsOpenableFile(&args[0])) { Options_Get(LOPT_USERNAME, &Game_Username, DEFAULT_USERNAME); String_Copy(&SP_AutoloadMap, &args[0]); /* TODO: don't copy args? */ RunGame();