diff --git a/desktop_version/CONTRIBUTORS.txt b/desktop_version/CONTRIBUTORS.txt index 782d57ca2d..349f92f952 100644 --- a/desktop_version/CONTRIBUTORS.txt +++ b/desktop_version/CONTRIBUTORS.txt @@ -18,4 +18,5 @@ Contributors * Emmanuel Vadot (@evadot) * RĂ©mi Verschelde (@akien-mga) * viri (viri.me) +* Jannik Vogel (@JayFoxRox) * Wouter (Xesxen) diff --git a/desktop_version/Makefile.nxdk b/desktop_version/Makefile.nxdk new file mode 100644 index 0000000000..46b3567368 --- /dev/null +++ b/desktop_version/Makefile.nxdk @@ -0,0 +1,103 @@ +XBE_TITLE = VVVVVV +GEN_XISO = $(XBE_TITLE).iso + +CXXFLAGS=-I$(CURDIR)/src \ + -I$(CURDIR)/../third_party/tinyxml \ + -I$(CURDIR)/../third_party/physfs \ + -I$(CURDIR)/../third_party/lodepng \ + -DBLOBCACHE=1 \ + -Wall + +CFLAGS=-DPHYSFS_NO_CDROM_SUPPORT=1 \ + -DPHYSFS_SUPPORTS_ZIP=0 \ + -DPHYSFS_SUPPORTS_7Z=0 \ + -DPHYSFS_SUPPORTS_GRP=0 \ + -DPHYSFS_SUPPORTS_HOG=0 \ + -DPHYSFS_SUPPORTS_MVL=0 \ + -DPHYSFS_SUPPORTS_WAD=0 \ + -DPHYSFS_SUPPORTS_QPAK=0 \ + -DPHYSFS_SUPPORTS_SLB=0 \ + -DPHYSFS_SUPPORTS_ISO9660=0 \ + -DPHYSFS_SUPPORTS_VDF=0 \ + -Wall + +# Source Lists +VVV_SRC=\ + src/BinaryBlob.cpp \ + src/BlockV.cpp \ + src/editor.cpp \ + src/Ent.cpp \ + src/Entity.cpp \ + src/FileSystemUtils.cpp \ + src/Finalclass.cpp \ + src/Game.cpp \ + src/Graphics.cpp \ + src/GraphicsResources.cpp \ + src/GraphicsUtil.cpp \ + src/Input.cpp \ + src/KeyPoll.cpp \ + src/Labclass.cpp \ + src/Logic.cpp \ + src/Map.cpp \ + src/Music.cpp \ + src/Otherlevel.cpp \ + src/preloader.cpp \ + src/Screen.cpp \ + src/Script.cpp \ + src/Scripts.cpp \ + src/SoundSystem.cpp \ + src/Spacestation2.cpp \ + src/TerminalScripts.cpp \ + src/Textbox.cpp \ + src/titlerender.cpp \ + src/Tower.cpp \ + src/UtilityClass.cpp \ + src/WarpClass.cpp \ + src/main.cpp \ + src/Network.c \ + src/SteamNetwork.c \ + src/GOGNetwork.c + +XML_SRC=\ + ../third_party/tinyxml/tinystr.cpp \ + ../third_party/tinyxml/tinyxml.cpp \ + ../third_party/tinyxml/tinyxmlerror.cpp \ + ../third_party/tinyxml/tinyxmlparser.cpp + +PFS_SRC=\ + ../third_party/physfs/physfs.c \ + ../third_party/physfs/physfs_archiver_dir.c \ + ../third_party/physfs/physfs_archiver_unpacked.c \ + ../third_party/physfs/physfs_archiver_zip.c \ + ../third_party/physfs/physfs_byteorder.c \ + ../third_party/physfs/physfs_unicode.c \ + ../third_party/physfs/physfs_platform_posix.c \ + ../third_party/physfs/physfs_platform_unix.c \ + ../third_party/physfs/physfs_platform_windows.c + +PNG_SRC=../third_party/lodepng/lodepng.c + +SRCS += $(VVV_SRC) $(XML_SRC) $(PFS_SRC) $(PNG_SRC) +SRCS := $(addprefix $(CURDIR)/, $(SRCS)) + +NXDK_SDL = y +NXDK_CXX = y + +NXDK_STACKSIZE = 131072 + +all_local: all + +include $(NXDK_DIR)/Makefile + +download_data: $(OUTPUT_DIR)/data.zip + +# You need data.zip from https://thelettervsixtim.es/makeandplay/ +$(OUTPUT_DIR)/data.zip: + @mkdir -p $(OUTPUT_DIR) + wget -N https://thelettervsixtim.es/makeandplay/data.zip -O $(OUTPUT_DIR)/data.zip + +install_data: $(OUTPUT_DIR)/data.zip + @mkdir -p $(OUTPUT_DIR)/VVVVVV + unzip -o $(OUTPUT_DIR)/data.zip -d $(OUTPUT_DIR)/VVVVVV; true + rm -f $(OUTPUT_DIR)/VVVVVV/vvvvvvmusic.vvv + rm -f $(OUTPUT_DIR)/data.zip diff --git a/desktop_version/src/FileSystemUtils.cpp b/desktop_version/src/FileSystemUtils.cpp index 7f37a70ed6..886b306dc2 100644 --- a/desktop_version/src/FileSystemUtils.cpp +++ b/desktop_version/src/FileSystemUtils.cpp @@ -14,6 +14,7 @@ #if defined(_WIN32) #include +#if !defined(XBOX) #include int mkdir(char* path, int mode) { @@ -21,6 +22,9 @@ int mkdir(char* path, int mode) MultiByteToWideChar(CP_UTF8, 0, path, -1, utf16_path, MAX_PATH); return CreateDirectoryW(utf16_path, NULL); } +#else +#define mkdir(a, b) CreateDirectory(a, NULL) +#endif #define VNEEDS_MIGRATION (mkdirResult != 0) #elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__HAIKU__) #include @@ -194,11 +198,17 @@ std::vector FILESYSTEM_getLevelDirFileNames() void PLATFORM_getOSDirectory(char* output) { #ifdef _WIN32 +#if !defined(XBOX) /* This block is here for compatibility, do not touch it! */ WCHAR utf16_path[MAX_PATH]; SHGetFolderPathW(NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT, utf16_path); WideCharToMultiByte(CP_UTF8, 0, utf16_path, -1, output, MAX_PATH, NULL, NULL); strcat(output, "\\VVVVVV\\"); +#else + //FIXME: strcpy(output, "T:\\UDATA"); ? + strcpy(output, "D:"); + strcat(output, "\\VVVVVV\\"); +#endif #else strcpy(output, PHYSFS_getPrefDir("distractionware", "VVVVVV")); #endif diff --git a/desktop_version/src/Game.cpp b/desktop_version/src/Game.cpp index e3cd908579..8e4f8e5bf1 100644 --- a/desktop_version/src/Game.cpp +++ b/desktop_version/src/Game.cpp @@ -21,7 +21,11 @@ // lol, Win32 -flibit #ifdef _WIN32 +#ifndef XBOX #define strcasecmp stricmp +#else +#define strcasecmp strcmp //FIXME: !!! +#endif #endif //TODO: Non Urgent code cleanup @@ -190,7 +194,7 @@ Game::Game(void): slowdown = 30; gameframerate=34; - fullscreen = false;// true; //Assumed true at first unless overwritten at some point! + fullscreen = false; //true; //Assumed true at first unless overwritten at some point! stretchMode = 0; useLinearFilter = false; advanced_mode = false; @@ -7042,6 +7046,18 @@ void Game::createmenu( std::string t ) menuxoff = 20; menuyoff = 64; } +#ifdef XBOX + else if (t == "credits2X") + { + menuoptions[0] = "next page"; + menuoptionsactive[0] = true; + menuoptions[1] = "return"; + menuoptionsactive[1] = true; + nummenuoptions = 2; + menuxoff = 20; + menuyoff = 64; + } +#endif else if (t == "credits25") { menuoptions[0] = "next page"; diff --git a/desktop_version/src/Input.cpp b/desktop_version/src/Input.cpp index a97e614deb..5dbf15fc1e 100644 --- a/desktop_version/src/Input.cpp +++ b/desktop_version/src/Input.cpp @@ -1049,6 +1049,28 @@ SDL_assert(0 && "Remove open level dir"); { //next page music.playef(11, 10); +#ifndef XBOX + game.createmenu("credits2"); +#else + game.createmenu("credits2X"); +#endif + map.nexttowercolour(); + } + else + { + //back + music.playef(11, 10); + game.createmenu("mainmenu"); + map.nexttowercolour(); + } + } +#ifdef XBOX + else if (game.currentmenuname == "credits2X") + { + if (game.currentmenuoption == 0) + { + //next page + music.playef(11, 10); game.createmenu("credits25"); map.nexttowercolour(); } @@ -1060,6 +1082,7 @@ SDL_assert(0 && "Remove open level dir"); map.nexttowercolour(); } } +#endif else if (game.currentmenuname == "credits25") { if (game.currentmenuoption == 0) diff --git a/desktop_version/src/SoundSystem.cpp b/desktop_version/src/SoundSystem.cpp index ff7f4272de..937f1ae11f 100644 --- a/desktop_version/src/SoundSystem.cpp +++ b/desktop_version/src/SoundSystem.cpp @@ -2,6 +2,8 @@ #include "SoundSystem.h" #include "FileSystemUtils.h" +#include + MusicTrack::MusicTrack(const char* fileName) { m_music = Mix_LoadMUS(fileName); @@ -32,7 +34,9 @@ SoundTrack::SoundTrack(const char* fileName) size_t length = 0; FILESYSTEM_loadFileToMemory(fileName, &mem, &length); SDL_RWops *fileIn = SDL_RWFromMem(mem, length); +debugPrint("Loading sound %p %p\n", fileIn, mem); sound = Mix_LoadWAV_RW(fileIn, 1); +debugPrint("Loaded sound %p\n", sound); if (length) { FILESYSTEM_freeMemory(&mem); @@ -44,18 +48,47 @@ SoundTrack::SoundTrack(const char* fileName) } } +#include + + +extern "C" { + extern int nextCol; + extern int nextRow; +} + SoundSystem::SoundSystem() { int audio_rate = 44100; Uint16 audio_format = AUDIO_S16SYS; int audio_channels = 2; int audio_buffers = 1024; - +#if 0 if (Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers) != 0) { fprintf(stderr, "Unable to initialize audio: %s\n", Mix_GetError()); SDL_assert(0 && "Unable to initialize audio!"); } +debugPrint("Okay!\n"); + +nextCol = 25; +nextRow = 300; + + debugPrint(" Memory statistics:\n"); + MM_STATISTICS ms; + ms.Length = sizeof(MM_STATISTICS); + MmQueryStatistics(&ms); + #define PRINT(stat) debugPrint(" - " #stat ": %d\n", ms.stat); + PRINT(TotalPhysicalPages) + PRINT(AvailablePages) + PRINT(VirtualMemoryBytesCommitted) + PRINT(VirtualMemoryBytesReserved) + PRINT(CachePagesCommitted) + PRINT(PoolPagesCommitted) + PRINT(StackPagesCommitted) + PRINT(ImagePagesCommitted) + #undef PRINT + +#endif } void SoundSystem::playMusic(MusicTrack* music) diff --git a/desktop_version/src/main.cpp b/desktop_version/src/main.cpp index 7922facbd3..6184643a40 100644 --- a/desktop_version/src/main.cpp +++ b/desktop_version/src/main.cpp @@ -29,6 +29,19 @@ #include #include +#include +#include +#include + +extern "C" { + extern int nextCol; + extern int nextRow; +} + +extern "C" { + extern uint8_t* _fb; +} + scriptclass script; edentities edentity[3000]; @@ -36,6 +49,23 @@ scriptclass script; int main(int argc, char *argv[]) { + char* args[] = {"D:\\VVVVVV"}; + argv = args; + + XVideoSetMode(640, 480, 16, REFRESH_DEFAULT); + +#if 1 + // We consume a lot of memory, so we need to claim the framebuffer + size_t fb_size = 640 * 480 * 2; + _fb = (uint8_t*)MmAllocateContiguousMemoryEx(fb_size, 0, 0xFFFFFFFF, 0x1000, PAGE_READWRITE | PAGE_WRITECOMBINE); + memset(_fb, 0x00, fb_size); +#define _PCRTC_START 0xFD600800 + *(unsigned int*)(_PCRTC_START) = (unsigned int)_fb & 0x03FFFFFF; + debugPrint("FB: 0x%X\n", _fb); +#endif + + SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1"); + if(!FILESYSTEM_init(argv[0])) { return 1; @@ -53,9 +83,13 @@ int main(int argc, char *argv[]) SDL_SetHintWithPriority(SDL_HINT_RENDER_DRIVER, argv[2], SDL_HINT_OVERRIDE); } +debugPrint("\n\n\n\n"); +debugPrint("Initializing network\n"); NETWORK_init(); +debugPrint("Initialization mostly complete\n"); Screen gameScreen; +debugPrint("Created gameScreen\n"); printf("\t\t\n"); printf("\t\t\n"); @@ -90,23 +124,27 @@ int main(int argc, char *argv[]) - UtilityClass help; +debugPrint("Created help\n"); // Load Ini Graphics graphics; - +debugPrint("Created graphics\n"); musicclass music; +debugPrint("Created music\n"); + Game game; +debugPrint("Created game\n"); game.infocus = true; graphics.MakeTileArray(); graphics.MakeSpriteArray(); graphics.maketelearray(); +debugPrint("Created graphics arrays\n"); graphics.images.push_back(graphics.grphx.im_image0); graphics.images.push_back(graphics.grphx.im_image1); @@ -142,7 +180,7 @@ int main(int argc, char *argv[]) graphics.tempBuffer = SDL_CreateRGBSurface(SDL_SWSURFACE ,320 ,240 ,fmt->BitsPerPixel,fmt->Rmask,fmt->Gmask,fmt->Bmask,fmt->Amask ); SDL_SetSurfaceBlendMode(graphics.tempBuffer, SDL_BLENDMODE_NONE); - +debugPrint("Created SDL surfaces\n"); //Make a temporary rectangle to hold the offsets // SDL_Rect offset; //Give the offsets to the rectangle @@ -244,6 +282,7 @@ int main(int argc, char *argv[]) game.infocus = true; key.isActive = true; +debugPrint("Entering mainloop\n"); while(!key.quitProgram) { //gameScreen.ClearScreen(0x00); @@ -526,6 +565,25 @@ int main(int argc, char *argv[]) game.gameclock(); gameScreen.FlipScreen(); +nextCol = 25; +nextRow = 300; + + debugPrint(" Memory statistics:\n"); + MM_STATISTICS ms; + ms.Length = sizeof(MM_STATISTICS); + MmQueryStatistics(&ms); + #define PRINT(stat) debugPrint(" - " #stat ": %d\n", ms.stat); + PRINT(TotalPhysicalPages) + PRINT(AvailablePages) + PRINT(VirtualMemoryBytesCommitted) + PRINT(VirtualMemoryBytesReserved) + PRINT(CachePagesCommitted) + PRINT(PoolPagesCommitted) + PRINT(StackPagesCommitted) + PRINT(ImagePagesCommitted) + #undef PRINT +debugPrint("%d\n", (int)GetTickCount()); + //SDL_FillRect( SDL_GetVideoSurface(), NULL, 0 ); } diff --git a/desktop_version/src/titlerender.cpp b/desktop_version/src/titlerender.cpp index 2320d95ba3..476f1a2bf7 100644 --- a/desktop_version/src/titlerender.cpp +++ b/desktop_version/src/titlerender.cpp @@ -50,7 +50,11 @@ void titlerender(Graphics& dwgfx, mapclass& map, Game& game, entityclass& obj, U #endif dwgfx.Print(5, 175, "[ Press ACTION to Start ]", tr, tg, tb, true); +#ifndef XBOX dwgfx.Print(5, 195, "ACTION = Space, Z, or V", int(tr*0.5f), int(tg*0.5f), int(tb*0.5f), true); +#else + dwgfx.Print(5, 195, "ACTION = FIXME titlerender.cpp:56", int(tr*0.5f), int(tg*0.5f), int(tb*0.5f), true); +#endif //dwgfx.Print(5, 215, "Press CTRL-F for Fullscreen", tr, tg, tb, true); @@ -255,6 +259,17 @@ void titlerender(Graphics& dwgfx, mapclass& map, Game& game, entityclass& obj, U dwgfx.bigprint( 40, 145, "Ethan Lee", tr, tg, tb, true); //dwgfx.drawimagecol(11, -1, 156, tr*0.75, tg *0.75, tb *0.75, true); } +#ifdef XBOX + else if (game.currentmenuname == "credits2X") + { + dwgfx.Print( -1, 40+10, "Original Xbox version by", tr, tg, tb, true); + dwgfx.bigprint( 40, 55+10, "Jannik Vogel", tr, tg, tb, true); + //dwgfx.Print( 40, 75+10, "http://www.jannikvogel.de", tr, tg, tb, true); + dwgfx.Print( -1, 130-10, "Original Xbox tools by", tr, tg, tb, true); + dwgfx.bigprint( 40, 145-10, "XboxDev Community", tr, tg, tb, true); + //dwgfx.Print( 40, 165-10, "http://www.xboxdev.org", tr, tg, tb, true); + } +#endif else if (game.currentmenuname == "credits25") { dwgfx.Print( -1, 40, "Beta Testing by", tr, tg, tb, true); diff --git a/third_party/physfs/physfs.c b/third_party/physfs/physfs.c index fdb1405d5f..9b29a0c1a2 100644 --- a/third_party/physfs/physfs.c +++ b/third_party/physfs/physfs.c @@ -8,11 +8,15 @@ * This file written by Ryan C. Gordon. */ +#include +#include +#include + #define __PHYSICSFS_INTERNAL__ #include "physfs_internal.h" #if defined(_MSC_VER) -#include +#include /* this code came from https://stackoverflow.com/a/8712996 */ int __PHYSFS_msvc_vsnprintf(char *outBuf, size_t size, const char *format, va_list ap) @@ -877,35 +881,43 @@ static DirHandle *openDirectory(PHYSFS_Io *io, const char *d, int forWriting) assert((io != NULL) || (d != NULL)); +debugPrint("%s:%d\n", __FILE__, __LINE__); if (io == NULL) { +debugPrint("%s:%d\n", __FILE__, __LINE__); /* file doesn't exist, etc? Just fail out. */ PHYSFS_Stat statbuf; BAIL_IF_ERRPASS(!__PHYSFS_platformStat(d, &statbuf, 1), NULL); +debugPrint("%s:%d\n", __FILE__, __LINE__); /* DIR gets first shot (unlike the rest, it doesn't deal with files). */ if (statbuf.filetype == PHYSFS_FILETYPE_DIRECTORY) { +debugPrint("%s:%d\n", __FILE__, __LINE__); retval = tryOpenDir(io, &__PHYSFS_Archiver_DIR, d, forWriting, &claimed); +debugPrint("%s:%d\n", __FILE__, __LINE__); if (retval || claimed) return retval; } /* if */ +debugPrint("%s:%d\n", __FILE__, __LINE__); io = __PHYSFS_createNativeIo(d, forWriting ? 'w' : 'r'); +debugPrint("%s:%d\n", __FILE__, __LINE__); BAIL_IF_ERRPASS(!io, NULL); created_io = 1; } /* if */ - +debugPrint("%s:%d\n", __FILE__, __LINE__); ext = find_filename_extension(d); if (ext != NULL) { +debugPrint("%s:%d\n", __FILE__, __LINE__); /* Look for archivers with matching file extensions first... */ for (i = archivers; (*i != NULL) && (retval == NULL) && !claimed; i++) { if (PHYSFS_utf8stricmp(ext, (*i)->info.extension) == 0) retval = tryOpenDir(io, *i, d, forWriting, &claimed); } /* for */ - +debugPrint("%s:%d\n", __FILE__, __LINE__); /* failing an exact file extension match, try all the others... */ for (i = archivers; (*i != NULL) && (retval == NULL) && !claimed; i++) { @@ -916,6 +928,7 @@ static DirHandle *openDirectory(PHYSFS_Io *io, const char *d, int forWriting) else /* no extension? Try them all. */ { +debugPrint("%s:%d\n", __FILE__, __LINE__); for (i = archivers; (*i != NULL) && (retval == NULL) && !claimed; i++) retval = tryOpenDir(io, *i, d, forWriting, &claimed); } /* else */ @@ -925,7 +938,9 @@ static DirHandle *openDirectory(PHYSFS_Io *io, const char *d, int forWriting) if ((!retval) && (created_io)) io->destroy(io); +debugPrint("%s:%d\n", __FILE__, __LINE__); BAIL_IF(!retval, claimed ? errcode : PHYSFS_ERR_UNSUPPORTED, NULL); +debugPrint("%s:%d\n", __FILE__, __LINE__); return retval; } /* openDirectory */ @@ -1024,7 +1039,7 @@ static DirHandle *createDirHandle(PHYSFS_Io *io, const char *newDir, char *tmpmntpnt = NULL; assert(newDir != NULL); /* should have caught this higher up. */ - +debugPrint("%s:%d\n", __FILE__, __LINE__); if (mountPoint != NULL) { const size_t len = strlen(mountPoint) + 1; @@ -1034,10 +1049,11 @@ static DirHandle *createDirHandle(PHYSFS_Io *io, const char *newDir, goto badDirHandle; mountPoint = tmpmntpnt; /* sanitized version. */ } /* if */ - +debugPrint("%s:%d\n", __FILE__, __LINE__); dirHandle = openDirectory(io, newDir, forWriting); +debugPrint("%s:%d\n", __FILE__, __LINE__); GOTO_IF_ERRPASS(!dirHandle, badDirHandle); - +debugPrint("%s:%d\n", __FILE__, __LINE__); dirHandle->dirName = (char *) allocator.Malloc(strlen(newDir) + 1); GOTO_IF(!dirHandle->dirName, PHYSFS_ERR_OUT_OF_MEMORY, badDirHandle); strcpy(dirHandle->dirName, newDir); @@ -1050,7 +1066,7 @@ static DirHandle *createDirHandle(PHYSFS_Io *io, const char *newDir, strcpy(dirHandle->mountPoint, mountPoint); strcat(dirHandle->mountPoint, "/"); } /* if */ - +debugPrint("%s:%d\n", __FILE__, __LINE__); __PHYSFS_smallFree(tmpmntpnt); return dirHandle; @@ -1119,17 +1135,20 @@ static char *calculateBaseDir(const char *argv0) static int initializeMutexes(void) { +debugPrint("%s:%d\n", __FILE__, __LINE__); errorLock = __PHYSFS_platformCreateMutex(); if (errorLock == NULL) goto initializeMutexes_failed; +debugPrint("%s:%d\n", __FILE__, __LINE__); stateLock = __PHYSFS_platformCreateMutex(); if (stateLock == NULL) goto initializeMutexes_failed; - +debugPrint("%s:%d\n", __FILE__, __LINE__); return 1; /* success. */ initializeMutexes_failed: +debugPrint("%s:%d\n", __FILE__, __LINE__); if (errorLock != NULL) __PHYSFS_platformDestroyMutex(errorLock); @@ -1194,34 +1213,44 @@ static int doDeinit(void); int PHYSFS_init(const char *argv0) { +debugPrint("%s:%d\n", __FILE__, __LINE__); BAIL_IF(initialized, PHYSFS_ERR_IS_INITIALIZED, 0); - +debugPrint("%s:%d\n", __FILE__, __LINE__); if (!externalAllocator) setDefaultAllocator(); - +debugPrint("%s:%d\n", __FILE__, __LINE__); if ((allocator.Init != NULL) && (!allocator.Init())) return 0; +debugPrint("%s:%d\n", __FILE__, __LINE__); if (!__PHYSFS_platformInit()) { +assert(0); +debugPrint("%s:%d\n", __FILE__, __LINE__); if (allocator.Deinit != NULL) allocator.Deinit(); +debugPrint("%s:%d\n", __FILE__, __LINE__); return 0; } /* if */ - +debugPrint("%s:%d\n", __FILE__, __LINE__); /* everything below here can be cleaned up safely by doDeinit(). */ if (!initializeMutexes()) goto initFailed; - +debugPrint("%s:%d\n", __FILE__, __LINE__); baseDir = calculateBaseDir(argv0); - if (!baseDir) goto initFailed; + if (!baseDir) { +assert(0); + goto initFailed; +} +debugPrint("%s:%d [%s]\n", __FILE__, __LINE__, baseDir); userDir = __PHYSFS_platformCalcUserDir(); if (!userDir) goto initFailed; - +debugPrint("%s:%d [%s]\n", __FILE__, __LINE__, userDir); /* Platform layer is required to append a dirsep. */ assert(baseDir[strlen(baseDir) - 1] == __PHYSFS_platformDirSeparator); assert(userDir[strlen(userDir) - 1] == __PHYSFS_platformDirSeparator); if (!initStaticArchivers()) goto initFailed; +debugPrint("%s:%d\n", __FILE__, __LINE__); initialized = 1; @@ -1690,14 +1719,14 @@ static int doMount(PHYSFS_Io *io, const char *fname, DirHandle *dh; DirHandle *prev = NULL; DirHandle *i; - +debugPrint("%s:%d\n", __FILE__, __LINE__); BAIL_IF(!fname, PHYSFS_ERR_INVALID_ARGUMENT, 0); - +debugPrint("%s:%d\n", __FILE__, __LINE__); if (mountPoint == NULL) mountPoint = "/"; - +debugPrint("%s:%d\n", __FILE__, __LINE__); __PHYSFS_platformGrabMutex(stateLock); - +debugPrint("%s:%d\n", __FILE__, __LINE__); for (i = searchPath; i != NULL; i = i->next) { /* already in search path? */ @@ -1705,10 +1734,11 @@ static int doMount(PHYSFS_Io *io, const char *fname, BAIL_MUTEX_ERRPASS(stateLock, 1); prev = i; } /* for */ - +debugPrint("%s:%d\n", __FILE__, __LINE__); dh = createDirHandle(io, fname, mountPoint, 0); +debugPrint("%s:%d\n", __FILE__, __LINE__); BAIL_IF_MUTEX_ERRPASS(!dh, stateLock, 0); - +debugPrint("%s:%d\n", __FILE__, __LINE__); if (appendToPath) { if (prev == NULL) @@ -1721,7 +1751,7 @@ static int doMount(PHYSFS_Io *io, const char *fname, dh->next = searchPath; searchPath = dh; } /* else */ - +debugPrint("%s:%d\n", __FILE__, __LINE__); __PHYSFS_platformReleaseMutex(stateLock); return 1; } /* doMount */ @@ -1787,7 +1817,9 @@ int PHYSFS_mountHandle(PHYSFS_File *file, const char *fname, int PHYSFS_mount(const char *newDir, const char *mountPoint, int appendToPath) { +debugPrint("%s:%d\n", __FILE__, __LINE__); BAIL_IF(!newDir, PHYSFS_ERR_INVALID_ARGUMENT, 0); +debugPrint("%s:%d\n", __FILE__, __LINE__); return doMount(NULL, newDir, mountPoint, appendToPath); } /* PHYSFS_mount */ @@ -2012,21 +2044,26 @@ static int verifyPath(DirHandle *h, char **_fname, int allowMissing) int retval = 1; char *start; char *end; - +debugPrint("MORE %d\n", __LINE__); if (*fname == '\0') /* quick rejection. */ return 1; - +debugPrint("MORE %d\n", __LINE__); /* !!! FIXME: This codeblock sucks. */ if (h->mountPoint != NULL) /* NULL mountpoint means "/". */ { +debugPrint("null mountpoint path\n"); size_t mntpntlen = strlen(h->mountPoint); size_t len = strlen(fname); +debugPrint("strlen done\n"); assert(mntpntlen > 1); /* root mount points should be NULL. */ /* not under the mountpoint, so skip this archive. */ BAIL_IF(len < mntpntlen-1, PHYSFS_ERR_NOT_FOUND, 0); +debugPrint("MORE %d\n", __LINE__); /* !!! FIXME: Case insensitive? */ retval = strncmp(h->mountPoint, fname, mntpntlen-1); +debugPrint("MORE %d\n", __LINE__); BAIL_IF(retval != 0, PHYSFS_ERR_NOT_FOUND, 0); +debugPrint("MORE %d\n", __LINE__); if (len > mntpntlen-1) /* corner case... */ BAIL_IF(fname[mntpntlen-1]!='/', PHYSFS_ERR_NOT_FOUND, 0); fname += mntpntlen-1; /* move to start of actual archive path. */ @@ -2035,31 +2072,36 @@ static int verifyPath(DirHandle *h, char **_fname, int allowMissing) *_fname = fname; /* skip mountpoint for later use. */ retval = 1; /* may be reset, below. */ } /* if */ - +debugPrint("MORE %d\n", __LINE__); start = fname; if (!allowSymLinks) { +debugPrint("MORE %d\n", __LINE__); while (1) { +debugPrint("MORE %d\n", __LINE__); PHYSFS_Stat statbuf; int rc = 0; end = strchr(start, '/'); - +debugPrint("MORE %d\n", __LINE__); if (end != NULL) *end = '\0'; +debugPrint("MORE %d\n", __LINE__); rc = h->funcs->stat(h->opaque, fname, &statbuf); +debugPrint("MORE %d\n", __LINE__); if (rc) rc = (statbuf.filetype == PHYSFS_FILETYPE_SYMLINK); else if (currentErrorCode() == PHYSFS_ERR_NOT_FOUND) retval = 0; - +debugPrint("MORE %d\n", __LINE__); if (end != NULL) *end = '/'; - +debugPrint("MORE %d\n", __LINE__); /* insecure path (has a disallowed symlink in it)? */ BAIL_IF(rc, PHYSFS_ERR_SYMLINK_FORBIDDEN, 0); - +debugPrint("MORE %d\n", __LINE__); /* break out early if path element is missing. */ if (!retval) { +debugPrint("MORE %d\n", __LINE__); /* * We need to clear it if it's the last element of the path, * since this might be a non-existant file we're opening @@ -2069,10 +2111,10 @@ static int verifyPath(DirHandle *h, char **_fname, int allowMissing) retval = 1; break; } /* if */ - +debugPrint("MORE %d\n", __LINE__); if (end == NULL) break; - +debugPrint("MORE %d\n", __LINE__); start = end + 1; } /* while */ } /* if */ @@ -2614,14 +2656,15 @@ PHYSFS_File *PHYSFS_openRead(const char *_fname) FileHandle *fh = NULL; char *fname; size_t len; - +debugPrint("\n\n\n\n"); BAIL_IF(!_fname, PHYSFS_ERR_INVALID_ARGUMENT, 0); len = strlen(_fname) + 1; fname = (char *) __PHYSFS_smallAlloc(len); BAIL_IF(!fname, PHYSFS_ERR_OUT_OF_MEMORY, 0); - +debugPrint("Looking for %s\n", _fname); if (sanitizePlatformIndependentPath(_fname, fname)) { +debugPrint("Looking for %s for %s\n", fname, _fname); DirHandle *i = NULL; PHYSFS_Io *io = NULL; @@ -2631,15 +2674,18 @@ PHYSFS_File *PHYSFS_openRead(const char *_fname) for (i = searchPath; i != NULL; i = i->next) { +debugPrint("Checking in search path %p\n", i); char *arcfname = fname; if (verifyPath(i, &arcfname, 0)) { +debugPrint("Verified\n"); io = i->funcs->openRead(i->opaque, arcfname); if (io) break; } /* if */ +debugPrint("Not Verified\n"); } /* for */ - +debugPrint("Maybe found?\n"); GOTO_IF_ERRPASS(!io, openReadEnd); fh = (FileHandle *) allocator.Malloc(sizeof (FileHandle)); diff --git a/third_party/physfs/physfs_archiver_zip.c b/third_party/physfs/physfs_archiver_zip.c index 9972628fd9..1b1c7cd242 100644 --- a/third_party/physfs/physfs_archiver_zip.c +++ b/third_party/physfs/physfs_archiver_zip.c @@ -7,6 +7,9 @@ * by Gilles Vollant. */ +#include + + #define __PHYSICSFS_INTERNAL__ #include "physfs_internal.h" @@ -374,6 +377,7 @@ static PHYSFS_sint64 ZIP_tell(PHYSFS_Io *io) static int ZIP_seek(PHYSFS_Io *_io, PHYSFS_uint64 offset) { +debugPrint("ZIP %d seek %lld\n", __LINE__, (long long int)offset); ZIPfileinfo *finfo = (ZIPfileinfo *) _io->opaque; ZIPentry *entry = finfo->entry; PHYSFS_Io *io = finfo->io; @@ -828,18 +832,26 @@ static int zip_parse_local(PHYSFS_Io *io, ZIPentry *entry) /* !!! FIXME: apparently these are zero if general purpose bit 3 is set, !!! FIXME: which is probably true for Jar files, fwiw, but we don't !!! FIXME: care about these values anyhow. */ - +debugPrint("ZIP %d %d\n", __LINE__, entry->offset); BAIL_IF_ERRPASS(!io->seek(io, entry->offset), 0); +debugPrint("ZIP %d\n", __LINE__); BAIL_IF_ERRPASS(!readui32(io, &ui32), 0); +debugPrint("ZIP %d\n", __LINE__); BAIL_IF(ui32 != ZIP_LOCAL_FILE_SIG, PHYSFS_ERR_CORRUPT, 0); +debugPrint("ZIP %d\n", __LINE__); BAIL_IF_ERRPASS(!readui16(io, &ui16), 0); +debugPrint("ZIP %d\n", __LINE__); BAIL_IF(ui16 != entry->version_needed, PHYSFS_ERR_CORRUPT, 0); +debugPrint("ZIP %d\n", __LINE__); BAIL_IF_ERRPASS(!readui16(io, &ui16), 0); /* general bits. */ BAIL_IF_ERRPASS(!readui16(io, &ui16), 0); +debugPrint("ZIP %d\n", __LINE__); BAIL_IF(ui16 != entry->compression_method, PHYSFS_ERR_CORRUPT, 0); +debugPrint("ZIP %d\n", __LINE__); BAIL_IF_ERRPASS(!readui32(io, &ui32), 0); /* date/time */ BAIL_IF_ERRPASS(!readui32(io, &ui32), 0); BAIL_IF(ui32 && (ui32 != entry->crc), PHYSFS_ERR_CORRUPT, 0); +debugPrint("ZIP %d\n", __LINE__); BAIL_IF_ERRPASS(!readui32(io, &ui32), 0); BAIL_IF(ui32 && (ui32 != 0xFFFFFFFF) && @@ -848,11 +860,12 @@ static int zip_parse_local(PHYSFS_Io *io, ZIPentry *entry) BAIL_IF_ERRPASS(!readui32(io, &ui32), 0); BAIL_IF(ui32 && (ui32 != 0xFFFFFFFF) && (ui32 != entry->uncompressed_size), PHYSFS_ERR_CORRUPT, 0); - +debugPrint("ZIP %d\n", __LINE__); BAIL_IF_ERRPASS(!readui16(io, &fnamelen), 0); BAIL_IF_ERRPASS(!readui16(io, &extralen), 0); entry->offset += fnamelen + extralen + 30; +debugPrint("ZIP %d\n", __LINE__); return 1; } /* zip_parse_local */ @@ -861,7 +874,7 @@ static int zip_resolve(PHYSFS_Io *io, ZIPinfo *info, ZIPentry *entry) { int retval = 1; const ZipResolveType resolve_type = entry->resolved; - +debugPrint("ZIP %d\n", __LINE__); if (resolve_type == ZIP_DIRECTORY) return 1; /* we're good. */ @@ -886,8 +899,9 @@ static int zip_resolve(PHYSFS_Io *io, ZIPinfo *info, ZIPentry *entry) entry->resolved = ZIP_DIRECTORY; return 1; } /* if */ - +debugPrint("ZIP %d\n", __LINE__); retval = zip_parse_local(io, entry); +debugPrint("ZIP %d\n", __LINE__); if (retval) { /* @@ -895,8 +909,10 @@ static int zip_resolve(PHYSFS_Io *io, ZIPinfo *info, ZIPentry *entry) * resolution of other entries (other symlinks and, eventually, * the real file) if all goes well. */ +debugPrint("ZIP %d\n", __LINE__); if (resolve_type == ZIP_UNRESOLVED_SYMLINK) retval = zip_resolve_symlink(io, info, entry); +debugPrint("ZIP %d\n", __LINE__); } /* if */ if (resolve_type == ZIP_UNRESOLVED_SYMLINK) @@ -904,7 +920,7 @@ static int zip_resolve(PHYSFS_Io *io, ZIPinfo *info, ZIPentry *entry) else if (resolve_type == ZIP_UNRESOLVED_FILE) entry->resolved = ((retval) ? ZIP_RESOLVED : ZIP_BROKEN_FILE); } /* if */ - +debugPrint("ZIP %d\n", __LINE__); return retval; } /* zip_resolve */ @@ -1647,9 +1663,10 @@ static int ZIP_mkdir(void *opaque, const char *name) static int ZIP_stat(void *opaque, const char *filename, PHYSFS_Stat *stat) { +debugPrint("ZIP %d %s\n", __LINE__, filename); ZIPinfo *info = (ZIPinfo *) opaque; ZIPentry *entry = zip_find_entry(info, filename); - +debugPrint("ZIP %d %s\n", __LINE__, filename); if (entry == NULL) return 0; @@ -1660,24 +1677,28 @@ static int ZIP_stat(void *opaque, const char *filename, PHYSFS_Stat *stat) { stat->filesize = 0; stat->filetype = PHYSFS_FILETYPE_DIRECTORY; +debugPrint("ZIP %d %s\n", __LINE__, filename); } /* if */ else if (zip_entry_is_symlink(entry)) { stat->filesize = 0; stat->filetype = PHYSFS_FILETYPE_SYMLINK; +debugPrint("ZIP %d %s\n", __LINE__, filename); } /* else if */ else { stat->filesize = (PHYSFS_sint64) entry->uncompressed_size; stat->filetype = PHYSFS_FILETYPE_REGULAR; +debugPrint("ZIP %d %s\n", __LINE__, filename); } /* else */ stat->modtime = ((entry) ? entry->last_mod_time : 0); stat->createtime = stat->modtime; stat->accesstime = -1; stat->readonly = 1; /* .zip files are always read only */ +debugPrint("ZIP %d %s\n", __LINE__, filename); return 1; } /* ZIP_stat */ diff --git a/third_party/physfs/physfs_internal.h b/third_party/physfs/physfs_internal.h index 29126234ad..3485b54cbe 100644 --- a/third_party/physfs/physfs_internal.h +++ b/third_party/physfs/physfs_internal.h @@ -7,6 +7,8 @@ * This file written by Ryan C. Gordon. */ +#undef _MSC_VER + #ifndef _INCLUDE_PHYSFS_INTERNAL_H_ #define _INCLUDE_PHYSFS_INTERNAL_H_ @@ -33,10 +35,14 @@ #define __PHYSFS_COMPILE_TIME_ASSERT(name, x) \ typedef int __PHYSFS_compile_time_assert_##name[(x) * 2 - 1] +#if defined(XBOX) +#define alloca(a) __builtin_alloca(a) +#else /* !!! FIXME: remove this when revamping stack allocation code... */ #if defined(_MSC_VER) || defined(__MINGW32__) || defined(__WATCOMC__) #include #endif +#endif #ifdef PHYSFS_PLATFORM_SOLARIS #include diff --git a/third_party/physfs/physfs_platform_windows.c b/third_party/physfs/physfs_platform_windows.c index c92e98d070..b08429b62c 100644 --- a/third_party/physfs/physfs_platform_windows.c +++ b/third_party/physfs/physfs_platform_windows.c @@ -5,7 +5,7 @@ * * This file written by Ryan C. Gordon, and made sane by Gregory S. Read. */ - +#include #define __PHYSICSFS_INTERNAL__ #include "physfs_platforms.h" @@ -16,6 +16,11 @@ #undef UNICODE #endif +#ifdef XBOX +#include +#define FlushFileBuffers(a) 1 +#endif + #if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS) #define _CRT_SECURE_NO_WARNINGS 1 #endif @@ -23,7 +28,7 @@ #define WIN32_LEAN_AND_MEAN 1 #include -#ifndef PHYSFS_PLATFORM_WINRT +#if !defined(PHYSFS_PLATFORM_WINRT) && !defined(XBOX) #include #include #endif @@ -61,15 +66,15 @@ if (str == NULL) \ w_assignto = NULL; \ else { \ - const size_t len = (PHYSFS_uint64) ((strlen(str) + 1) * 2); \ - w_assignto = (WCHAR *) __PHYSFS_smallAlloc(len); \ + const size_t len = (PHYSFS_uint64) ((strlen(str) + 1)); \ + w_assignto = (CHAR *) __PHYSFS_smallAlloc(len); \ if (w_assignto != NULL) \ - PHYSFS_utf8ToUtf16(str, (PHYSFS_uint16 *) w_assignto, len); \ + memcpy(w_assignto, str, len); \ } \ } \ -/* Note this counts WCHARs, not codepoints! */ -static PHYSFS_uint64 wStrLen(const WCHAR *wstr) +/* Note this counts CHARs, not codepoints! */ +static PHYSFS_uint64 wStrLen(const CHAR *wstr) { PHYSFS_uint64 len = 0; while (*(wstr++)) @@ -77,19 +82,16 @@ static PHYSFS_uint64 wStrLen(const WCHAR *wstr) return len; } /* wStrLen */ -static char *unicodeToUtf8Heap(const WCHAR *w_str) +static char *unicodeToUtf8Heap(const CHAR *w_str) { char *retval = NULL; if (w_str != NULL) { void *ptr = NULL; - const PHYSFS_uint64 len = (wStrLen(w_str) * 4) + 1; + const PHYSFS_uint64 len = wStrLen(w_str) + 1; retval = allocator.Malloc(len); BAIL_IF(!retval, PHYSFS_ERR_OUT_OF_MEMORY, NULL); - PHYSFS_utf8FromUtf16((const PHYSFS_uint16 *) w_str, retval, len); - ptr = allocator.Realloc(retval, strlen(retval) + 1); /* shrink. */ - if (ptr != NULL) - retval = (char *) ptr; + memcpy(retval, w_str, len); } /* if */ return retval; } /* unicodeToUtf8Heap */ @@ -99,15 +101,15 @@ static char *unicodeToUtf8Heap(const WCHAR *w_str) Since non-WinRT might not have the "Ex" version, we tapdance to use the perfectly-fine-and-available-even-on-Win95 API on non-WinRT targets. */ -static inline HANDLE winFindFirstFileW(const WCHAR *path, LPWIN32_FIND_DATAW d) +static inline HANDLE winFindFirstFile(const CHAR *path, LPWIN32_FIND_DATA d) { #ifdef PHYSFS_PLATFORM_WINRT return FindFirstFileExW(path, FindExInfoStandard, d, FindExSearchNameMatch, NULL, 0); #else - return FindFirstFileW(path, d); + return FindFirstFile(path, d); #endif -} /* winFindFirstFileW */ +} /* winFindFirstFile */ static inline BOOL winInitializeCriticalSection(LPCRITICAL_SECTION lpcs) { @@ -119,17 +121,18 @@ static inline BOOL winInitializeCriticalSection(LPCRITICAL_SECTION lpcs) #endif } /* winInitializeCriticalSection */ -static inline HANDLE winCreateFileW(const WCHAR *wfname, const DWORD mode, +static inline HANDLE winCreateFile(const CHAR *wfname, const DWORD mode, const DWORD creation) { +debugPrint("Trying to open '%s'\n", wfname); const DWORD share = FILE_SHARE_READ | FILE_SHARE_WRITE; #ifdef PHYSFS_PLATFORM_WINRT return CreateFile2(wfname, mode, share, creation, NULL); #else - return CreateFileW(wfname, mode, share, NULL, creation, + return CreateFile(wfname, mode, share, NULL, creation, FILE_ATTRIBUTE_NORMAL, NULL); #endif -} /* winCreateFileW */ +} /* winCreateFile */ static BOOL winSetFilePointer(HANDLE h, const PHYSFS_sint64 pos, PHYSFS_sint64 *_newpos, const DWORD whence) @@ -422,7 +425,7 @@ void __PHYSFS_platformDetectAvailableCDs(PHYSFS_StringCallback cb, void *data) } /* __PHYSFS_platformDetectAvailableCDs */ #ifdef PHYSFS_PLATFORM_WINRT -static char *calcDirAppendSep(const WCHAR *wdir) +static char *calcDirAppendSep(const CHAR *wdir) { size_t len; void *ptr; @@ -447,8 +450,9 @@ static char *calcDirAppendSep(const WCHAR *wdir) char *__PHYSFS_platformCalcBaseDir(const char *argv0) { #ifdef PHYSFS_PLATFORM_WINRT - return calcDirAppendSep((const WCHAR *) __PHYSFS_winrtCalcBaseDir()); + return calcDirAppendSep((const CHAR *) __PHYSFS_winrtCalcBaseDir()); #else +#ifndef XBOX char *retval = NULL; DWORD buflen = 64; LPWSTR modpath = NULL; @@ -458,7 +462,7 @@ char *__PHYSFS_platformCalcBaseDir(const char *argv0) DWORD rc; void *ptr; - if ( (ptr = allocator.Realloc(modpath, buflen*sizeof(WCHAR))) == NULL ) + if ( (ptr = allocator.Realloc(modpath, buflen*sizeof(CHAR))) == NULL ) { allocator.Free(modpath); BAIL(PHYSFS_ERR_OUT_OF_MEMORY, NULL); @@ -483,7 +487,7 @@ char *__PHYSFS_platformCalcBaseDir(const char *argv0) if (buflen > 0) /* just in case... */ { - WCHAR *ptr = (modpath + buflen) - 1; + CHAR *ptr = (modpath + buflen) - 1; while (ptr != modpath) { if (*ptr == '\\') @@ -502,6 +506,9 @@ char *__PHYSFS_platformCalcBaseDir(const char *argv0) allocator.Free(modpath); return retval; /* w00t. */ +#else + return "D:\\"; //FIXME +#endif #endif } /* __PHYSFS_platformCalcBaseDir */ @@ -509,7 +516,7 @@ char *__PHYSFS_platformCalcBaseDir(const char *argv0) char *__PHYSFS_platformCalcPrefDir(const char *org, const char *app) { #ifdef PHYSFS_PLATFORM_WINRT - return calcDirAppendSep((const WCHAR *) __PHYSFS_winrtCalcPrefDir()); + return calcDirAppendSep((const CHAR *) __PHYSFS_winrtCalcPrefDir()); #else /* * Vista and later has a new API for this, but SHGetFolderPath works there, @@ -519,16 +526,20 @@ char *__PHYSFS_platformCalcPrefDir(const char *org, const char *app) * NULL, &wszPath); */ - WCHAR path[MAX_PATH]; + CHAR path[MAX_PATH]; char *utf8 = NULL; size_t len = 0; char *retval = NULL; +#ifndef XBOX if (!SUCCEEDED(SHGetFolderPathW(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, path))) BAIL(PHYSFS_ERR_OS_ERROR, NULL); utf8 = unicodeToUtf8Heap(path); +#else + utf8 = strdup(path); +#endif BAIL_IF_ERRPASS(!utf8, NULL); len = strlen(utf8) + strlen(org) + strlen(app) + 4; retval = allocator.Malloc(len); @@ -548,8 +559,9 @@ char *__PHYSFS_platformCalcPrefDir(const char *org, const char *app) char *__PHYSFS_platformCalcUserDir(void) { #ifdef PHYSFS_PLATFORM_WINRT - return calcDirAppendSep((const WCHAR *) __PHYSFS_winrtCalcPrefDir()); + return calcDirAppendSep((const CHAR *) __PHYSFS_winrtCalcPrefDir()); #else +#ifndef XBOX typedef BOOL (WINAPI *fnGetUserProfDirW)(HANDLE, LPWSTR, LPDWORD); fnGetUserProfDirW pGetDir = NULL; HANDLE lib = NULL; @@ -580,14 +592,14 @@ char *__PHYSFS_platformCalcUserDir(void) if (psize == 0) /* probably on Windows XP, try a different way. */ { - WCHAR x = 0; + CHAR x = 0; rc = pGetDir(accessToken, &x, &psize); GOTO_IF(rc, PHYSFS_ERR_OS_ERROR, done); /* should have failed! */ GOTO_IF(!psize, PHYSFS_ERR_OS_ERROR, done); /* Uhoh... */ } /* if */ /* Allocate memory for the profile directory */ - wstr = (LPWSTR) __PHYSFS_smallAlloc((psize + 1) * sizeof (WCHAR)); + wstr = (LPWSTR) __PHYSFS_smallAlloc((psize + 1) * sizeof (CHAR)); if (wstr != NULL) { if (pGetDir(accessToken, wstr, &psize)) @@ -609,6 +621,9 @@ char *__PHYSFS_platformCalcUserDir(void) CloseHandle(accessToken); FreeLibrary(lib); return retval; /* We made it: hit the showers. */ +#else + return "D:\\"; //FIXME +#endif #endif } /* __PHYSFS_platformCalcUserDir */ @@ -637,10 +652,10 @@ PHYSFS_EnumerateCallbackResult __PHYSFS_platformEnumerate(const char *dirname, { PHYSFS_EnumerateCallbackResult retval = PHYSFS_ENUM_OK; HANDLE dir = INVALID_HANDLE_VALUE; - WIN32_FIND_DATAW entw; + WIN32_FIND_DATA entw; size_t len = strlen(dirname); char *searchPath = NULL; - WCHAR *wSearchPath = NULL; + CHAR *wSearchPath = NULL; /* Allocate a new string for path, maybe '\\', "*", and NULL terminator */ searchPath = (char *) __PHYSFS_smallAlloc(len + 3); @@ -663,13 +678,13 @@ PHYSFS_EnumerateCallbackResult __PHYSFS_platformEnumerate(const char *dirname, __PHYSFS_smallFree(searchPath); BAIL_IF_ERRPASS(!wSearchPath, PHYSFS_ENUM_ERROR); - dir = winFindFirstFileW(wSearchPath, &entw); + dir = winFindFirstFile(wSearchPath, &entw); __PHYSFS_smallFree(wSearchPath); BAIL_IF(dir==INVALID_HANDLE_VALUE, errcodeFromWinApi(), PHYSFS_ENUM_ERROR); do { - const WCHAR *fn = entw.cFileName; + const CHAR *fn = entw.cFileName; char *utf8; if (fn[0] == '.') /* ignore "." and ".." */ @@ -688,7 +703,7 @@ PHYSFS_EnumerateCallbackResult __PHYSFS_platformEnumerate(const char *dirname, if (retval == PHYSFS_ENUM_ERROR) PHYSFS_setErrorCode(PHYSFS_ERR_APP_CALLBACK); } /* else */ - } while ((retval == PHYSFS_ENUM_OK) && (FindNextFileW(dir, &entw) != 0)); + } while ((retval == PHYSFS_ENUM_OK) && (FindNextFile(dir, &entw) != 0)); FindClose(dir); @@ -698,10 +713,10 @@ PHYSFS_EnumerateCallbackResult __PHYSFS_platformEnumerate(const char *dirname, int __PHYSFS_platformMkDir(const char *path) { - WCHAR *wpath; + CHAR *wpath; DWORD rc; UTF8_TO_UNICODE_STACK(wpath, path); - rc = CreateDirectoryW(wpath, NULL); + rc = CreateDirectory(wpath, NULL); __PHYSFS_smallFree(wpath); BAIL_IF(rc == 0, errcodeFromWinApi(), 0); return 1; @@ -711,17 +726,21 @@ int __PHYSFS_platformMkDir(const char *path) static HANDLE doOpen(const char *fname, DWORD mode, DWORD creation) { HANDLE fileh; - WCHAR *wfname; + CHAR *wfname; UTF8_TO_UNICODE_STACK(wfname, fname); BAIL_IF(!wfname, PHYSFS_ERR_OUT_OF_MEMORY, NULL); - fileh = winCreateFileW(wfname, mode, creation); + debugPrint("Opening '%s'\n", fname); + fileh = winCreateFile(wfname, mode, creation); __PHYSFS_smallFree(wfname); - if (fileh == INVALID_HANDLE_VALUE) + if (fileh == INVALID_HANDLE_VALUE) { + debugPrint("fuck failed '%s'\n", fname); BAIL(errcodeFromWinApi(), INVALID_HANDLE_VALUE); + } + debugPrint("ok ok '%s'\n", fname); return fileh; } /* doOpen */ @@ -767,9 +786,13 @@ PHYSFS_sint64 __PHYSFS_platformRead(void *opaque, void *buf, PHYSFS_uint64 len) while (len > 0) { const DWORD thislen = (len > 0xFFFFFFFF) ? 0xFFFFFFFF : (DWORD) len; +debugPrint("Reading %lld from file %p to %p\n", (long long int)thislen, h, buf); DWORD numRead = 0; - if (!ReadFile(h, buf, thislen, &numRead, NULL)) + if (!ReadFile(h, buf, thislen, &numRead, NULL)) { +debugPrint("Reading failed %lld\n", (long long int)numRead); BAIL(errcodeFromWinApi(), -1); + } +debugPrint("Reading done %lld\n", (long long int)numRead); len -= (PHYSFS_uint64) numRead; totalRead += (PHYSFS_sint64) numRead; if (numRead != thislen) @@ -847,8 +870,9 @@ void __PHYSFS_platformClose(void *opaque) } /* __PHYSFS_platformClose */ -static int doPlatformDelete(LPWSTR wpath) +static int doPlatformDelete(LPSTR wpath) { +#ifndef XBOX WIN32_FILE_ATTRIBUTE_DATA info; if (!GetFileAttributesExW(wpath, GetFileExInfoStandard, &info)) BAIL(errcodeFromWinApi(), 0); @@ -859,13 +883,16 @@ static int doPlatformDelete(LPWSTR wpath) BAIL_IF(!rc, errcodeFromWinApi(), 0); } /* else */ return 1; /* if you made it here, it worked. */ +#else + return 0; +#endif } /* doPlatformDelete */ int __PHYSFS_platformDelete(const char *path) { int retval = 0; - LPWSTR wpath = NULL; + LPSTR wpath = NULL; UTF8_TO_UNICODE_STACK(wpath, path); BAIL_IF(!wpath, PHYSFS_ERR_OUT_OF_MEMORY, 0); retval = doPlatformDelete(wpath); @@ -912,6 +939,7 @@ void __PHYSFS_platformReleaseMutex(void *mutex) static PHYSFS_sint64 FileTimeToPhysfsTime(const FILETIME *ft) { +#ifndef XBOX SYSTEMTIME st_utc; SYSTEMTIME st_localtz; TIME_ZONE_INFORMATION tzi; @@ -941,6 +969,9 @@ static PHYSFS_sint64 FileTimeToPhysfsTime(const FILETIME *ft) retval = (PHYSFS_sint64) mktime(&tm); BAIL_IF(retval == -1, PHYSFS_ERR_OS_ERROR, -1); return retval; +#else + return -1; +#endif } /* FileTimeToPhysfsTime */ @@ -951,15 +982,15 @@ static PHYSFS_sint64 FileTimeToPhysfsTime(const FILETIME *ft) NTFS symlinks are a form of "reparse point" (junction, volume mount, etc), so if the REPARSE_POINT attribute is set, check for the symlink tag thereafter. This assumes you already read in the file attributes. */ -static int isSymlink(const WCHAR *wpath, const DWORD attr) +static int isSymlink(const CHAR *wpath, const DWORD attr) { - WIN32_FIND_DATAW w32dw; + WIN32_FIND_DATAA w32dw; HANDLE h; if ((attr & PHYSFS_FILE_ATTRIBUTE_REPARSE_POINT) == 0) return 0; /* not a reparse point? Definitely not a symlink. */ - h = winFindFirstFileW(wpath, &w32dw); + h = winFindFirstFile(wpath, &w32dw); if (h == INVALID_HANDLE_VALUE) return 0; /* ...maybe the file just vanished...? */ @@ -970,8 +1001,9 @@ static int isSymlink(const WCHAR *wpath, const DWORD attr) int __PHYSFS_platformStat(const char *filename, PHYSFS_Stat *st, const int follow) { +#ifndef XBOX WIN32_FILE_ATTRIBUTE_DATA winstat; - WCHAR *wstr = NULL; + CHAR *wstr = NULL; DWORD err = 0; BOOL rc = 0; int issymlink = 0; @@ -1019,6 +1051,20 @@ int __PHYSFS_platformStat(const char *filename, PHYSFS_Stat *st, const int follo st->readonly = ((winstat.dwFileAttributes & FILE_ATTRIBUTE_READONLY) != 0); return 1; +#else + FILE* f = fopen(filename, "rb"); + if (f != NULL) { + fseek(f, 0, SEEK_END); + st->filesize = ftell(f); + fclose(f); + st->filetype = PHYSFS_FILETYPE_REGULAR; + st->readonly = 0; + } else { + st->filetype = PHYSFS_FILETYPE_DIRECTORY; + st->filesize = 0; + } + return 1; +#endif } /* __PHYSFS_platformStat */ #endif /* PHYSFS_PLATFORM_WINDOWS */ diff --git a/third_party/tinyxml/tinyxml.cpp b/third_party/tinyxml/tinyxml.cpp index 9c161dfcb9..1e491b94c5 100644 --- a/third_party/tinyxml/tinyxml.cpp +++ b/third_party/tinyxml/tinyxml.cpp @@ -22,6 +22,8 @@ must not be misrepresented as being the original software. distribution. */ +#undef _MSC_VER + #include #ifdef TIXML_USE_STL @@ -1276,7 +1278,11 @@ int TiXmlAttribute::IntValue() const double TiXmlAttribute::DoubleValue() const { +#ifndef XBOX return atof (value.c_str ()); +#else + return 0.0f; +#endif }