• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ PHYSFS_getLastError函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中PHYSFS_getLastError函数的典型用法代码示例。如果您正苦于以下问题:C++ PHYSFS_getLastError函数的具体用法?C++ PHYSFS_getLastError怎么用?C++ PHYSFS_getLastError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了PHYSFS_getLastError函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: addSearchPath

bool FileSystem::awake(pugi::xml_node &node)
{
	bool ret = true;

	for (pugi::xml_node path = node.child("path"); path ; path = path.next_sibling("path"))
		addSearchPath(path.child_value());

	char *write_dir = SDL_GetPrefPath("Carlos", "Game_development");

	if (PHYSFS_setWriteDir(write_dir) == 0)
	{
		LOG("%s,%s","Error on setting Write Dir. Error:", PHYSFS_getLastError());
		ret = false;
	}
	else
	{
		LOG("%s %s", "Write directory is ", write_dir);
		addSearchPath(write_dir, getSaveDirectory());
	}

	SDL_free(write_dir);
	
	return ret;
}
开发者ID:N4bi,项目名称:Research-Particle_system,代码行数:24,代码来源:FileSystem.cpp


示例2: addToSearchPath

void addToSearchPath(const char* directory, bool append)
{
    if(!PHYSFS_addToSearchPath(directory, append))
        throw Exception("Couldn't add '%s' to searchpath: %s", directory,
                        PHYSFS_getLastError());
}
开发者ID:BackupTheBerlios,项目名称:netpanzer-svn,代码行数:6,代码来源:FileSystem.cpp


示例3: getPlatformUserDir

static void getPlatformUserDir(char * const tmpstr, size_t const size)
{
#if defined(WZ_OS_WIN)
//  When WZ_PORTABLE is passed, that means we want the config directory at the same location as the program file
	DWORD dwRet;
	wchar_t tmpWStr[MAX_PATH];
#ifndef WZ_PORTABLE
	if ( SUCCEEDED( SHGetFolderPathW( NULL, CSIDL_PERSONAL|CSIDL_FLAG_CREATE, NULL, SHGFP_TYPE_CURRENT, tmpWStr ) ) )
	{
#else
	if (dwRet = GetCurrentDirectoryW(MAX_PATH, tmpWStr))
	{
		if(dwRet > MAX_PATH)
		{
			debug(LOG_FATAL, "Buffer exceeds maximum path to create directory. Exiting.");
			exit(1);
		}
#endif
		if (WideCharToMultiByte(CP_UTF8, 0, tmpWStr, -1, tmpstr, size, NULL, NULL) == 0)
		{
			debug(LOG_FATAL, "Config directory encoding conversion error.");
			exit(1);
		}
		strlcat(tmpstr, PHYSFS_getDirSeparator(), size);
	}
	else
#elif defined(WZ_OS_MAC)
	FSRef fsref;
	OSErr error = FSFindFolder(kUserDomain, kApplicationSupportFolderType, false, &fsref);
	if (!error)
		error = FSRefMakePath(&fsref, (UInt8 *) tmpstr, size);
	if (!error)
		strlcat(tmpstr, PHYSFS_getDirSeparator(), size);
	else
#endif
	if (PHYSFS_getUserDir())
	{
		strlcpy(tmpstr, PHYSFS_getUserDir(), size); // Use PhysFS supplied UserDir (As fallback on Windows / Mac, default on Linux)
	}
	// If PhysicsFS fails (might happen if environment variable HOME is unset or wrong) then use the current working directory
	else if (getCurrentDir(tmpstr, size))
	{
		strlcat(tmpstr, PHYSFS_getDirSeparator(), size);
	}
	else
	{
		debug(LOG_FATAL, "Can't get UserDir?");
		abort();
	}
}


static void initialize_ConfigDir(void)
{
	char tmpstr[PATH_MAX] = { '\0' };

	if (strlen(configdir) == 0)
	{
		getPlatformUserDir(tmpstr, sizeof(tmpstr));

		if (!PHYSFS_setWriteDir(tmpstr)) // Workaround for PhysFS not creating the writedir as expected.
		{
			debug(LOG_FATAL, "Error setting write directory to \"%s\": %s",
			      tmpstr, PHYSFS_getLastError());
			exit(1);
		}

		if (!PHYSFS_mkdir(WZ_WRITEDIR)) // s.a.
		{
			debug(LOG_FATAL, "Error creating directory \"%s\": %s",
			      WZ_WRITEDIR, PHYSFS_getLastError());
			exit(1);
		}

		// Append the Warzone subdir
		sstrcat(tmpstr, WZ_WRITEDIR);
		sstrcat(tmpstr, PHYSFS_getDirSeparator());

		if (!PHYSFS_setWriteDir(tmpstr))
		{
			debug( LOG_FATAL, "Error setting write directory to \"%s\": %s",
			tmpstr, PHYSFS_getLastError() );
			exit(1);
		}
	}
	else
	{
		sstrcpy(tmpstr, configdir);

		// Make sure that we have a directory separator at the end of the string
		if (tmpstr[strlen(tmpstr) - 1] != PHYSFS_getDirSeparator()[0])
			sstrcat(tmpstr, PHYSFS_getDirSeparator());

		debug(LOG_WZ, "Using custom configuration directory: %s", tmpstr);

		if (!PHYSFS_setWriteDir(tmpstr)) // Workaround for PhysFS not creating the writedir as expected.
		{
			debug(LOG_FATAL, "Error setting write directory to \"%s\": %s",
			      tmpstr, PHYSFS_getLastError());
			exit(1);
//.........这里部分代码省略.........
开发者ID:GhostKing,项目名称:warzone2100,代码行数:101,代码来源:main.cpp


示例4: PHYSFSX_init

// Initialise PhysicsFS, set up basic search paths and add arguments from .ini file.
// The .ini file can be in either the user directory or the same directory as the program.
// The user directory is searched first.
void PHYSFSX_init(int argc, char *argv[])
{
#if defined(__unix__)
	const char *path = NULL;
#endif
#ifdef macintosh	// Mac OS 9
	char base_dir[PATH_MAX];
	int bundle = 0;
#else
#define base_dir PHYSFS_getBaseDir()
#endif
	
	PHYSFS_init(argv[0]);
	atexit(PHYSFSX_deinit);
	PHYSFS_permitSymbolicLinks(1);
	
#ifdef macintosh
	strcpy(base_dir, PHYSFS_getBaseDir());
	if (strstr(base_dir, ".app:Contents:MacOSClassic"))	// the Mac OS 9 program is still in the .app bundle
	{
		char *p;
		
		bundle = 1;
		if (base_dir[strlen(base_dir) - 1] == ':')
			base_dir[strlen(base_dir) - 1] = '\0';
		p = strrchr(base_dir, ':'); *p = '\0';	// path to 'Contents'
		p = strrchr(base_dir, ':'); *p = '\0';	// path to bundle
		p = strrchr(base_dir, ':'); *p = '\0';	// path to directory containing bundle
	}
#endif
	
#if (defined(__APPLE__) && defined(__MACH__))	// others?
	chdir(base_dir);	// make sure relative hogdir paths work
#endif
	
#if defined(__unix__)
	char fullPath[PATH_MAX + 5];
# if !(defined(__APPLE__) && defined(__MACH__))
	path = "~/.d2x-rebirth/";
# else
	path = "~/Library/Preferences/D2X Rebirth/";
# endif
	
	if (path[0] == '~') // yes, this tilde can be put before non-unix paths.
	{
		const char *home = PHYSFS_getUserDir();
		
		strcpy(fullPath, home); // prepend home to the path
		path++;
		if (*path == *PHYSFS_getDirSeparator())
			path++;
		strncat(fullPath, path, PATH_MAX + 5 - strlen(home));
	}
	else
		strncpy(fullPath, path, PATH_MAX + 5);
	
	PHYSFS_setWriteDir(fullPath);
	if (!PHYSFS_getWriteDir())
	{                                               // need to make it
		char *p;
		char ancestor[PATH_MAX + 5];    // the directory which actually exists
		char child[PATH_MAX + 5];               // the directory relative to the above we're trying to make
		
		strcpy(ancestor, fullPath);
		while (!PHYSFS_getWriteDir() && ((p = strrchr(ancestor, *PHYSFS_getDirSeparator()))))
		{
			if (p[1] == 0)
			{                                       // separator at the end (intended here, for safety)
				*p = 0;                 // kill this separator
				if (!((p = strrchr(ancestor, *PHYSFS_getDirSeparator()))))
					break;          // give up, this is (usually) the root directory
			}
			
			p[1] = 0;                       // go to parent
			PHYSFS_setWriteDir(ancestor);
		}
		
		strcpy(child, fullPath + strlen(ancestor));
		for (p = child; (p = strchr(p, *PHYSFS_getDirSeparator())); p++)
			*p = '/';
		PHYSFS_mkdir(child);
		PHYSFS_setWriteDir(fullPath);
	}
	
	PHYSFS_addToSearchPath(PHYSFS_getWriteDir(), 1);
#endif
	
	PHYSFS_addToSearchPath(base_dir, 1);
	InitArgs( argc,argv );
	PHYSFS_removeFromSearchPath(base_dir);
	
	if (!PHYSFS_getWriteDir())
	{
		PHYSFS_setWriteDir(base_dir);
		if (!PHYSFS_getWriteDir())
			Error("can't set write dir: %s\n", PHYSFS_getLastError());
		else
//.........这里部分代码省略.........
开发者ID:Pickle,项目名称:dxx-rebirth,代码行数:101,代码来源:physfsx.cpp


示例5: GetLogger

bool CResourceManager::SetSaveLocation(const std::string &location)
{
    if (!PHYSFS_setWriteDir(location.c_str()))
    {
        GetLogger()->Error("Error while setting save location to \"%s\": %s\n", location.c_str(), PHYSFS_getLastError());
        return false;
    }

    return true;
}
开发者ID:2asoft,项目名称:colobot,代码行数:10,代码来源:resourcemanager.cpp


示例6: physfsrwops_seek

static int physfsrwops_seek(SDL_RWops *rw, int offset, int whence)
#endif
{
    PHYSFS_File *handle = (PHYSFS_File *) rw->hidden.unknown.data1;
    PHYSFS_sint64 pos = 0;

    if (whence == RW_SEEK_SET)
        pos = (PHYSFS_sint64) offset;

    else if (whence == RW_SEEK_CUR)
    {
        const PHYSFS_sint64 current = PHYSFS_tell(handle);
        if (current == -1)
        {
            SDL_SetError("Can't find position in file: %s",
                          PHYSFS_getLastError());
            return -1;
        } /* if */

        if (offset == 0)  /* this is a "tell" call. We're done. */
        {
            #if TARGET_SDL2
            return (Sint64) current;
            #else
            return (int) current;
            #endif
        } /* if */

        pos = current + ((PHYSFS_sint64) offset);
    } /* else if */

    else if (whence == RW_SEEK_END)
    {
        const PHYSFS_sint64 len = PHYSFS_fileLength(handle);
        if (len == -1)
        {
            SDL_SetError("Can't find end of file: %s", PHYSFS_getLastError());
            return -1;
        } /* if */

        pos = len + ((PHYSFS_sint64) offset);
    } /* else if */

    else
    {
        SDL_SetError("Invalid 'whence' parameter.");
        return -1;
    } /* else */

    if ( pos < 0 )
    {
        SDL_SetError("Attempt to seek past start of file.");
        return -1;
    } /* if */
    
    if (!PHYSFS_seek(handle, (PHYSFS_uint64) pos))
    {
        SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError());
        return -1;
    } /* if */

    #if TARGET_SDL2
    return (Sint64) pos;
    #else
    return (int) pos;
    #endif
} /* physfsrwops_seek */
开发者ID:ryanshow,项目名称:EngineMk1,代码行数:67,代码来源:physfsrwops.c


示例7: PHYSFS_getLastError

const char *fs_error(void)
{
    return PHYSFS_getLastError();
}
开发者ID:L0rdK,项目名称:neverball-sdl2,代码行数:4,代码来源:fs_physfs.c


示例8: deleteSaveGame

/***************************************************************************
	Delete a savegame.  saveGameName should be a .gam extension save game
	filename reference.  We delete this file, any .es file with the same
	name, and any files in the directory with the same name.
***************************************************************************/
void deleteSaveGame(char* saveGameName)
{
	char **files, **i;

	ASSERT( strlen(saveGameName) < MAX_STR_LENGTH,"deleteSaveGame; save game name too long" );

	PHYSFS_delete(saveGameName);
	saveGameName[strlen(saveGameName)-4] = '\0';// strip extension

	strcat(saveGameName,".es");					// remove script data if it exists.
	PHYSFS_delete(saveGameName);
	saveGameName[strlen(saveGameName)-3] = '\0';// strip extension

	// check for a directory and remove that too.
	files = PHYSFS_enumerateFiles(saveGameName);
	for (i = files; *i != NULL; ++i)
	{
		char del_file[PATH_MAX];

		// Construct the full path to the file by appending the
		// filename to the directory it is in.
		snprintf(del_file, sizeof(del_file), "%s/%s", saveGameName, *i);

		debug(LOG_SAVE, "Deleting [%s].", del_file);

		// Delete the file
		if (!PHYSFS_delete(del_file))
		{
			debug(LOG_ERROR, "Warning [%s] could not be deleted due to PhysicsFS error: %s", del_file, PHYSFS_getLastError());
		}
	}
	PHYSFS_freeList(files);

	if (!PHYSFS_delete(saveGameName))		// now (should be)empty directory
	{
		debug(LOG_ERROR, "Warning directory[%s] could not be deleted because %s", saveGameName,PHYSFS_getLastError());
	}
	
	return;
}
开发者ID:Cjkjvfnby,项目名称:warzone2100,代码行数:45,代码来源:loadsave.cpp


示例9: cdAudio_OpenTrack

static bool cdAudio_OpenTrack(const char *filename)
{
	if (!music_initialized)
	{
		return false;
	}

	debug(LOG_SOUND, "called(%s)", filename);
	cdAudio_Stop();

	if (strncasecmp(filename + strlen(filename) - 4, ".ogg", 4) == 0)
	{
		PHYSFS_file *music_file = PHYSFS_openRead(filename);

		debug(LOG_WZ, "Reading...[directory: %s] %s", PHYSFS_getRealDir(filename), filename);
		if (music_file == NULL)
		{
			debug(LOG_ERROR, "Failed opening file [directory: %s] %s, with error %s", PHYSFS_getRealDir(filename), filename, PHYSFS_getLastError());
			return false;
		}

		cdStream = sound_PlayStreamWithBuf(music_file, music_volume, cdAudio_TrackFinished, (char *)filename, bufferSize, buffer_count);
		if (cdStream == NULL)
		{
			PHYSFS_close(music_file);
			debug(LOG_ERROR, "Failed creating audio stream for %s", filename);
			return false;
		}

		debug(LOG_SOUND, "successful(%s)", filename);
		stopping = false;
		return true;
	}

	return false; // unhandled
}
开发者ID:GhostKing,项目名称:warzone2100,代码行数:36,代码来源:cdaudio.cpp


示例10: buildMapList

bool buildMapList()
{
	if (!loadLevFile("gamedesc.lev", mod_campaign, false, NULL))
	{
		return false;
	}
	loadLevFile("addon.lev", mod_multiplay, false, NULL);
	WZ_Maps.clear();
	MapFileList realFileNames = listMapFiles();
	for (MapFileList::iterator realFileName = realFileNames.begin(); realFileName != realFileNames.end(); ++realFileName)
	{
		bool mapmod = false;
		struct WZmaps CurrentMap;
		std::string realFilePathAndName = PHYSFS_getRealDir(realFileName->c_str()) + *realFileName;

		PHYSFS_addToSearchPath(realFilePathAndName.c_str(), PHYSFS_APPEND);

		char **filelist = PHYSFS_enumerateFiles("");
		for (char **file = filelist; *file != NULL; ++file)
		{
			std::string checkfile = *file;
			size_t len = strlen(*file);
			if (len > 10 && !strcasecmp(*file + (len - 10), ".addon.lev"))  // Do not add addon.lev again
			{
				loadLevFile(*file, mod_multiplay, true, realFileName->c_str());
			}
			// add support for X player maps using a new name to prevent conflicts.
			if (len > 13 && !strcasecmp(*file + (len - 13), ".xplayers.lev"))
			{
				loadLevFile(*file, mod_multiplay, true, realFileName->c_str());
			}
		}
		PHYSFS_freeList(filelist);

		if (PHYSFS_removeFromSearchPath(realFilePathAndName.c_str()) == 0)
		{
			debug(LOG_ERROR, "Could not unmount %s", PHYSFS_getLastError());
		}
		// check what kind of map it is
		if (!PHYSFS_mount(realFilePathAndName.c_str(), "WZMap", PHYSFS_APPEND))
		{
			debug(LOG_FATAL, "Could not mount %s, because: %s. Please delete the file, and run the game again. Game will now exit.", realFilePathAndName.c_str(), PHYSFS_getLastError());
			exit(-1);
		}

		filelist = PHYSFS_enumerateFiles("WZMap");
		for (char **file = filelist; *file != NULL; ++file)
		{
			if (PHYSFS_isDirectory(*file))
			{
				std::string checkfile = *file;
				if (checkfile.compare("wrf")==0 || checkfile.compare("stats")==0 ||checkfile.compare("components")==0
					|| checkfile.compare("anims")==0 || checkfile.compare("effects")==0 ||checkfile.compare("messages")==0
					|| checkfile.compare("audio")==0 || checkfile.compare("sequenceaudio")==0 ||checkfile.compare("misc")==0
					|| checkfile.compare("features")==0 || checkfile.compare("script")==0 ||checkfile.compare("structs")==0
					|| checkfile.compare("tileset")==0 || checkfile.compare("images")==0 || checkfile.compare("texpages")==0 )
				{
					mapmod = true;
					break;
				}
			}
		}
		PHYSFS_freeList(filelist);

		CurrentMap.MapName = realFileName->c_str();
		CurrentMap.isMapMod = mapmod;
		WZ_Maps.push_back(CurrentMap);

		if (PHYSFS_removeFromSearchPath(realFilePathAndName.c_str()) == 0)
		{
			debug(LOG_ERROR, "Could not unmount %s", PHYSFS_getLastError());
		}
	}

	return true;
}
开发者ID:TomCN7,项目名称:warzone2100,代码行数:76,代码来源:init.cpp


示例11: listMapFiles

static MapFileList listMapFiles()
{
	MapFileList ret, filtered, oldSearchPath;

	char **subdirlist = PHYSFS_enumerateFiles("maps");

	for (char **i = subdirlist; *i != NULL; ++i)
	{
		std::string wzfile = *i;
		if (*i[0] == '.' || wzfile.substr(wzfile.find_last_of(".")+1) != "wz")
		{
			continue;
		}

		std::string realFileName = std::string("maps/") + *i;
		ret.push_back(realFileName);
	}
	PHYSFS_freeList(subdirlist);
	// save our current search path(s)
	debug(LOG_WZ, "Map search paths:");
	char **searchPath = PHYSFS_getSearchPath();
	for (char **i = searchPath; *i != NULL; i++)
	{
		debug(LOG_WZ, "    [%s]", *i);
		oldSearchPath.push_back(*i);
		PHYSFS_removeFromSearchPath(*i);
	}
	PHYSFS_freeList(searchPath);

	for (MapFileList::iterator realFileName = ret.begin(); realFileName != ret.end(); ++realFileName)
	{
		std::string realFilePathAndName = PHYSFS_getWriteDir() + *realFileName;
		if (PHYSFS_addToSearchPath(realFilePathAndName.c_str(), PHYSFS_APPEND))
		{
			int unsafe = 0;
			char **filelist = PHYSFS_enumerateFiles("multiplay/maps");

			for (char **file = filelist; *file != NULL; ++file)
			{
				std::string isDir = std::string("multiplay/maps/") + *file;
				if (PHYSFS_isDirectory(isDir.c_str()))
					continue;
				std::string checkfile = *file;
				debug(LOG_WZ,"checking ... %s", *file);
				if (checkfile.substr(checkfile.find_last_of(".")+ 1) == "gam")
				{
					if (unsafe++ > 1)
					{
						debug(LOG_ERROR, "Map packs are not supported! %s NOT added.", realFilePathAndName.c_str());
						break;
					}
				}
			}
			PHYSFS_freeList(filelist);
			if (unsafe < 2)
			{
				filtered.push_back(realFileName->c_str());
			}
			PHYSFS_removeFromSearchPath(realFilePathAndName.c_str());
		}
		else
		{
			debug(LOG_POPUP, "Could not mount %s, because: %s.\nPlease delete or move the file specified.", realFilePathAndName.c_str(), PHYSFS_getLastError());
		}
	}

	// restore our search path(s) again
	for (MapFileList::iterator restorePaths = oldSearchPath.begin(); restorePaths != oldSearchPath.end(); ++restorePaths)
	{
		PHYSFS_addToSearchPath(restorePaths->c_str(), PHYSFS_APPEND);
	}
	debug(LOG_WZ, "Search paths restored");
	printSearchPath();

	return filtered;
}
开发者ID:TomCN7,项目名称:warzone2100,代码行数:76,代码来源:init.cpp


示例12: sdl_log_write

void sdl_log_write(Uint32 level, char* fmt, ...)
{
	PHYSFS_file* h_file;
	va_list	args;
	char	timestring[255];
	char	logstr[MAX_PATH_LEN];
	char	logline[MAX_PATH_LEN];
	char	typestr[32];
	cptr    prev_write_dir;

	errlvl = level;

	// label the log informational level correctly
	switch (errlvl)
	{
		case ERRLVL_CRITICAL:
			sprintf(typestr, "ERROR");
			break;

		case ERRLVL_WARNING:
			sprintf(typestr, "WARNING");
			break;

		case ERRLVL_NO_ERR:
			sprintf(typestr, "INFO");
			break;

		case LOG_START:
			sprintf(typestr, "START");
			break;

		case LOG_STOP:
			sprintf(typestr, "STOP");
			break;

		default:
			/* we don't like undefined behaviour */
			errlvl = ERRLVL_CRITICAL;
			sprintf(typestr, "UNDEFINED");
			break;
	}

	sdl_utl_get_datetime(timestring);

	if (timestring[0])
	{
		// move the the time-stamped log entry to a temporary buffer
		va_start(args, fmt);
		vsprintf(logstr, fmt, args);
		va_end(args);

		// formulate the log text
		snprintf(logline, MAX_PATH_LEN, "%s [%s] %s\n", timestring, typestr, logstr);

		// push the current write path, if any, just in case and set our new one
		prev_write_dir = string_make(PHYSFS_getWriteDir());	
		PHYSFS_setWriteDir(SDL_LOG_DIR);				
		
		// open the log file and write the entry
		h_file = my_fopen(SDL_LOG_FILE, "a");
		
		if (h_file)
		{
			my_fprintf(h_file, "%s", logline);
			my_fclose(h_file);
		}
		else
		{
			printf("Log error - open file: %s (%s)\n", PHYSFS_getLastError(), SDL_LOG_FILE);
		}		 
		errlvl &= ~(LOG_START | LOG_STOP);

		// pop the previous write path
		if (!PHYSFS_setWriteDir(prev_write_dir))
		{
			printf("Log error - restore write dir: %s\n", PHYSFS_getLastError());
		}
	}
}
开发者ID:jcubic,项目名称:ToME,代码行数:79,代码来源:sdl-log.c


示例13: main

int main(int argc, char **argv)
{
    int i;
    int portnum = DEFAULT_PORTNUM;

    setbuf(stdout, NULL);
    setbuf(stderr, NULL);

#ifndef LACKING_SIGNALS
    /* I'm not sure if this qualifies as a cheap trick... */
    signal(SIGTERM, exit);
    signal(SIGINT, exit);
    signal(SIGFPE, exit);
    signal(SIGSEGV, exit);
    signal(SIGPIPE, exit);
    signal(SIGILL, exit);
#endif

    if (argc == 1)
    {
        printf("USAGE: %s <archive1> [archive2 [... archiveN]]\n", argv[0]);
        return(42);
    } /* if */

    if (!PHYSFS_init(argv[0]))
    {
        printf("PHYSFS_init() failed: %s\n", PHYSFS_getLastError());
        return(42);
    } /* if */

    /* normally, this is bad practice, but oh well. */
    atexit(at_exit_cleanup);

    for (i = 1; i < argc; i++)
    {
        if (!PHYSFS_addToSearchPath(argv[i], 1))
            printf(" WARNING: failed to add [%s] to search path.\n", argv[i]);
    } /* else */

    listensocket = create_listen_socket(portnum);
    if (listensocket < 0)
    {
        printf("listen socket failed to create.\n");
        return(42);
    } /* if */

    while (1)  /* infinite loop for now. */
    {
        struct sockaddr addr;
        socklen_t len;
        int s = accept(listensocket, &addr, &len);
        if (s < 0)
        {
            printf("accept() failed: %s\n", strerror(errno));
            close(listensocket);
            return(42);
        } /* if */

        serve_http_request(s, &addr, len);
    } /* while */

    return(0);
} /* main */
开发者ID:EgoIncarnate,项目名称:Infinity,代码行数:63,代码来源:physfshttpd.c


示例14: read_player_file


//.........这里部分代码省略.........

	if (shareware_file == -1) {
		nm_messagebox(TXT_ERROR, 1, TXT_OK, "Error invalid or unknown\nplayerfile-size");
		PHYSFS_close(file);
		return -1;
	}

	if (saved_game_version <= 5) {

		//deal with old-style highest level info

		PlayerCfg.HighestLevels[0].Shortname[0] = 0;							//no name for mission 0
		PlayerCfg.HighestLevels[0].LevelNum = PlayerCfg.NHighestLevels;	//was highest level in old struct

		//This hack allows the player to start on level 8 if he's made it to
		//level 7 on the shareware.  We do this because the shareware didn't
		//save the information that the player finished level 7, so the most
		//we know is that he made it to level 7.
		if (PlayerCfg.NHighestLevels==7)
			PlayerCfg.HighestLevels[0].LevelNum = 8;
		
	}
	else {	//read new highest level info
		if (PHYSFS_read(file,PlayerCfg.HighestLevels,sizeof(hli),PlayerCfg.NHighestLevels) != PlayerCfg.NHighestLevels)
			goto read_player_file_failed;
	}

	if ( saved_game_version != 7 ) {	// Read old & SW saved games.
		if (PHYSFS_read(file,saved_games,sizeof(saved_games),1) != 1)
			goto read_player_file_failed;
	}

	//read taunt macros
	{
		int i;
		int len = shareware_file? 25:35;

		#ifdef NETWORK
		for (i = 0; i < 4; i++)
			if (PHYSFS_read(file, PlayerCfg.NetworkMessageMacro[i], len, 1) != 1)
				goto read_player_file_failed;
		#else
		i = 0;
		PHYSFS_seek( file, PHYSFS_tell(file)+4*len );
		#endif
	}

	//read kconfig data
	{
		ubyte dummy_joy_sens;

		if (PHYSFS_read(file, &PlayerCfg.KeySettings[0], sizeof(PlayerCfg.KeySettings[0]),1)!=1)
			goto read_player_file_failed;
		if (PHYSFS_read(file, &PlayerCfg.KeySettings[1], sizeof(PlayerCfg.KeySettings[1]),1)!=1)
			goto read_player_file_failed;
		PHYSFS_seek( file, PHYSFS_tell(file)+(sizeof(ubyte)*MAX_CONTROLS*3) ); // Skip obsolete Flightstick/Thrustmaster/Gravis map fields
		if (PHYSFS_read(file, &PlayerCfg.KeySettings[2], sizeof(PlayerCfg.KeySettings[2]),1)!=1)
			goto read_player_file_failed;
		PHYSFS_seek( file, PHYSFS_tell(file)+(sizeof(ubyte)*MAX_CONTROLS) ); // Skip obsolete Cyberman map field
		if (PHYSFS_read(file, &PlayerCfg.ControlType, sizeof(ubyte), 1 )!=1)
			goto read_player_file_failed;
		else if (PHYSFS_read(file, &dummy_joy_sens, sizeof(ubyte), 1 )!=1)
			goto read_player_file_failed;
	}

	if ( saved_game_version != 7 ) 	{
		int i, found=0;
		
		Assert( N_SAVE_SLOTS == 10 );

		for (i=0; i<N_SAVE_SLOTS; i++ )	{
			if ( saved_games[i].name[0] )	{
				state_save_old_game(i, saved_games[i].name, &saved_games[i].sg_player, saved_games[i].difficulty_level, saved_games[i].primary_weapon, saved_games[i].secondary_weapon, saved_games[i].next_level_num );
				// make sure we do not do this again, which would possibly overwrite
				// a new newstyle savegame
				saved_games[i].name[0] = 0;
				found++;
			}
		}
		if (found)
			write_player_file();
	}

	if (!PHYSFS_close(file))
		goto read_player_file_failed;

	filename[strlen(filename) - 4] = 0;
	strcat(filename, ".plx");
	read_player_d1x(filename);
	kc_set_controls();

	return EZERO;

 read_player_file_failed:
	nm_messagebox(TXT_ERROR, 1, TXT_OK, "%s\n\n%s", "Error reading PLR file", PHYSFS_getLastError());
	if (file)
		PHYSFS_close(file);

	return -1;
}
开发者ID:Garog,项目名称:d1x-rebirth-ovr,代码行数:101,代码来源:playsave.c


示例15: flubPhysfsInit

int flubPhysfsInit(const char *appPath) {
    char working_dir[512];
    int k;

    if(_physfsCtx.init) {
        warning("Ignoring attempt to re-initialize physfs.");
        return 1;
    }

    if(!logValid()) {
        // The logger has not been initiated!
        return 0;
    }

    logDebugRegister("file", DBG_FILE, "general", DBG_FILE_DTL_GENERAL);

    debug(DBG_FILE, DBG_FILE_DTL_GENERAL, "Initializing PHYSFS");

    if(!PHYSFS_init(appPath)) {
        fatal("Failed to initialize the virtual file system.");
        return 0;
    } else {
        if(!PHYSFS_mount(getcwd(working_dir, sizeof(working_dir)), NULL, 1)) {
            fatalf("Failed to mount the current working directory (%s).", working_dir);
            return 0;
        } else {
            infof("Mounted current working directory: %s", working_dir);
        }
        if(!PHYSFS_mount(PHYSFS_getBaseDir(), NULL, 1)) {
            fatalf("Failed to mount the application's base dir (%s).",
                   PHYSFS_getBaseDir());
            return 0;
        } else {
            infof("Mounted base directory: %s", PHYSFS_getBaseDir());
        }
        if(appDefaults.archiveFile != NULL) {
            infof("Mounting app archive file \"%s\".", appDefaults.archiveFile);
            if(!PHYSFS_mount(appDefaults.archiveFile, NULL, 1)) {
                fatalf("Failed to mount the application's archive file: %s", PHYSFS_getLastError());
                return 0;
            }
        } else {
            debug(DBG_FILE, DBG_FILE_DTL_GENERAL, "No application archive file specified.");
        }
        for(k = 0; _flubMemfileResources[k].name != NULL; k++) {
            if(!PHYSFS_mount(PHYSFS_getMemfileName(_flubMemfileResources[k].memfile), NULL, 1)) {
                errorf("Failed to mount %s", _flubMemfileResources[k].name);
            } else {
                debugf(DBG_FILE, DBG_FILE_DTL_GENERAL, "Mounted flub resource file image [%s].", _flubMemfileResources[k].name);
            }
        }
        if(appDefaults.resources != NULL) {
            for(k = 0; appDefaults.resources[k].name != NULL; k++) {
                if(!PHYSFS_mount(PHYSFS_getMemfileName(appDefaults.resources[k].memfile), NULL, 1)) {
                    errorf("Failed to mount %s", appDefaults.resources[k].name);
                } else {
                    debugf(DBG_FILE, DBG_FILE_DTL_GENERAL, "Mounted application resource file image [%s].", appDefaults.resources[k].name);
                }
            }
        } else {
            debugf(DBG_FILE, DBG_FILE_DTL_GENERAL, "No application resource file images specified.");
        }
        debug(DBG_FILE, DBG_FILE_DTL_GENERAL, "Virtual file system started.");
    }

    _physfsCtx.init = 1;

    return 1;
}
开发者ID:Mojofreem,项目名称:flub,代码行数:69,代码来源:physfsutil.c


示例16: luaL_newstate

bange::box::box(const char *config, int argc, char *argv[]){
    error = false;
    window = NULL;
    this->escapekey = sf::Keyboard::Escape;
    mouseDelta = 0;
    JoystickConnected = -1;
    JoystickDisconnected = -1;
    mouseEntered = false;
    windowFocus = false;
    vm = luaL_newstate();
    bange::PrepareVM(vm);
    //Create a lua table with arguments
    lua_createtable(vm, argc, 0);
    for (int i = 0; i < argc; i += 1){
        lua_pushstring(vm, argv[i]);
        lua_rawseti(vm, -2, i+1);
    }
    lua_setglobal(vm, "Args");
    //---
    if (luaL_dofile(vm, config)){
        std::cout << "bange(lua): Error reading config file \"" << config << "\": " << lua_tostring(vm, -1) << std::endl;
        error = true;
        return;
    }
    //Get Window dimensions
    sf::VideoMode videomode(640, 480);
    lua_Number wh = 0;
    if (vm::GetNumber(vm, "Width", wh)){
        videomode.Width = wh;}
    if (vm::GetNumber(vm, "Height", wh)){
        videomode.Height = wh;}
    //Get Title
    char title[128] = "BAN Game Engine";
    vm::GetString(vm, "Title", title, 128);
    //Set styles (fullscreen, close, resize, titlebar, none)
    unsigned long windowstyle = sf::Style::Close;
    //Set Window settings
    sf::ContextSettings contextsettings;
    //Create window
    window = new sf::RenderWindow(videomode, title, windowstyle, contextsettings);
    //Set FPS
    lua_Number FPS = 60;
    vm::GetNumber(vm, "FPS", FPS);
    window->SetFramerateLimit( static_cast<unsigned int>(FPS) );
    //Set KeyRepeat
    int keyrepeat = 0;
    vm::GetBoolean(vm, "KeyRepeat", keyrepeat);
    window->EnableKeyRepeat((bool)keyrepeat);
    //Set VerticalSync
    int verticalsync = 0;
    vm::GetBoolean(vm, "VerticalSync", verticalsync);
    window->EnableVerticalSync((bool)verticalsync);
    //Set EscapeKey
    lua_Number escapekey = 0;
    if (vm::GetNumber(vm, "EscapeKey", escapekey)){
        this->escapekey = static_cast<sf::Keyboard::Key>(escapekey);}
    //Store in lua environment this box
    lua_pushlightuserdata(vm, this);
    lua_setfield(vm, LUA_REGISTRYINDEX, "bange::box");
    //Store in lua environment box's window
    lua_pushlightuserdata(vm, this->window);
    lua_setfield(vm, LUA_REGISTRYINDEX, "bange::box::window");
    //Add packages
    if (bange::vm::GetTable(vm, "Packages")){
        lua_pushnil(vm);
        while(lua_next(vm, -2)){
            if (!lua_isstring(vm, -1)){
                lua_pop(vm, 1);
                continue;
            }
            if (PHYSFS_addToSearchPath(lua_tostring(vm, -1), 0) == 0){
                std::cout << "bange(physfs): " << lua_tostring(vm, -1) << ": " << PHYSFS_getLastError() << std::endl;
            }
            //next
            lua_pop(vm, 1);
        }
        lua_pop(vm, 1);
    }
    //Execute the run file
    char runfile[128] = "run.lua";
    vm::GetString(vm, "Run", runfile, 128);
    luaL_openlibs(vm);
    if (luaL_dofile(vm, runfile)){
        std::cout << "bange(lua): Error reading run file \"" << runfile << "\": " << lua_tostring(vm, -1) << std::endl;
        error = true;
        return;
    }
    std::cout << "Texture maximum size: " << sf::Texture::GetMaximumSize() << std::endl;
}
开发者ID:teritriano,项目名称:bangameengine,代码行数:89,代码来源:box.cpp


示例17: strresLoad

/* Load a string resource file */
bool strresLoad(STR_RES* psRes, const char* fileName)
{
	bool retval;
	lexerinput_t input;

	input.type = LEXINPUT_PHYSFS;
	input.input.physfsfile = PHYSFS_openRead(fileName);
	debug(LOG_WZ, "Reading...[directory %s] %s", PHYSFS_getRealDir(fileName), fileName);
	if (!input.input.physfsfile)
	{
		debug(LOG_ERROR, "strresLoadFile: PHYSFS_openRead(\"%s\") failed with error: %s\n", fileName, PHYSFS_getLastError());
		return false;
	}

	strres_set_extra(&input);
	retval = (strres_parse(psRes) == 0);

	strres_lex_destroy();
	PHYSFS_close(input.input.physfsfile);

	return retval;
}
开发者ID:cybersphinx,项目名称:wzgraphicsmods,代码行数:23,代码来源:strres.c


示例18: main

int main(int argc, char **argv)
{
    int rc;
    char buf[128];
    PHYSFS_File *f;

    if (!PHYSFS_init(argv[0]))
    {
        fprintf(stderr, "PHYSFS_init(): %s\n", PHYSFS_getLastError());
        return 1;
    } /* if */

    if (!PHYSFS_addToSearchPath(".", 1))
    {
        fprintf(stderr, "PHYSFS_addToSearchPath(): %s\n", PHYSFS_getLastError());
        PHYSFS_deinit();
        return 1;
    } /* if */

    if (!PHYSFS_setWriteDir("."))
    {
        fprintf(stderr, "PHYSFS_setWriteDir(): %s\n", PHYSFS_getLastError());
        PHYSFS_deinit();
        return 1;
    } /* if */

    if (!PHYSFS_mkdir("/a/b/c"))
    {
        fprintf(stderr, "PHYSFS_mkdir(): %s\n", PHYSFS_getLastError());
        PHYSFS_deinit();
        return 1;
    } /* if */

    if (!PHYSFS_mkdir("/a/b/C"))
    {
        fprintf(stderr, "PHYSFS_mkdir(): %s\n", PHYSFS_getLastError());
        PHYSFS_deinit();
        return 1;
    } /* if */

    f = PHYSFS_openWrite("/a/b/c/x.txt");
    PHYSFS_close(f);
    if (f == NULL)
    {
        fprintf(stderr, "PHYSFS_openWrite(): %s\n", PHYSFS_getLastError());
        PHYSFS_deinit();
        return 1;
    } /* if */

    f = PHYSFS_openWrite("/a/b/C/X.txt");
    PHYSFS_close(f);
    if (f == NULL)
    {
        fprintf(stderr, "PHYSFS_openWrite(): %s\n", PHYSFS_getLastError());
        PHYSFS_deinit();
        return 1;
    } /* if */

    strcpy(buf, "/a/b/c/x.txt");
    rc = PHYSFSEXT_locateCorrectCase(buf);
    if ((rc != 0) || (strcmp(buf, "/a/b/c/x.txt") != 0))
        printf("test 1 failed\n");

    strcpy(buf, "/a/B/c/x.txt");
    rc = PHYSFSEXT_locateCorrectCase(buf);
    if ((rc != 0) || (strcmp(buf, "/a/b/c/x.txt") != 0))
        printf("test 2 failed\n");

    strcpy(buf, "/a/b/C/x.txt");
    rc = PHYSFSEXT_locateCorrectCase(buf);
    if ((rc != 0) || (strcmp(buf, "/a/b/C/X.txt") != 0))
        printf("test 3 failed\n");

    strcpy(buf, "/a/b/c/X.txt");
    rc = PHYSFSEXT_locateCorrectCase(buf);
    if ((rc != 0) || (strcmp(buf, "/a/b/c/x.txt") != 0))
        printf("test 4 failed\n");

    strcpy(buf, "/a/b/c/z.txt");
    rc = PHYSFSEXT_locateCorrectCase(buf);
    if ((rc != -1) || (strcmp(buf, "/a/b/c/z.txt") != 0))
        printf("test 5 failed\n");

    strcpy(buf, "/A/B/Z/z.txt");
    rc = PHYSFSEXT_locateCorrectCase(buf);
    if ((rc != -2) || (strcmp(buf, "/a/b/Z/z.txt") != 0))
        printf("test 6 failed\n");

    printf("Testing completed.\n");
    printf("  If no errors were reported, you're good to go.\n");

    PHYSFS_delete("/a/b/c/x.txt");
    PHYSFS_delete("/a/b/C/X.txt");
    PHYSFS_delete("/a/b/c");
    PHYSFS_delete("/a/b/C");
    PHYSFS_delete("/a/b");
    PHYSFS_delete("/a");
    PHYSFS_deinit();
    return 0;
} /* main */
开发者ID:AndroidAppList,项目名称:Android-Supertux,代码行数:100,代码来源:ignorecase.c


示例19: FS_Init

void FS_Init(lua_State *L, char *argv[], char **pFilename) {
	#ifdef __MACOSX__
		char *ch = NULL;
		const char *basedir;
	#endif
	FILE *fh;
	char magic[4] = "000"; /* array for the magic bytes used to recognize a zip archive */
	char *dir = NULL;
	char *base = NULL;
	char appdata[4096];
//	char **search_path = NULL;
//	char **copy;

	/* initialize PhysFS */
	if (PHYSFS_init(argv[0]) ==0) {
		error(L, "Error: Could not initialize PhysFS: %s.", PHYSFS_getLastError());
	}

	/* allow symlinks */
	PHYSFS_permitSymbolicLinks(1);

	/*	on Mac OS X applications are packed inside a folder with the ending .app;
		try to set the search path to this folder;
		if a file is not found in the base dir (the dir containing the app bundle)
		it is searched inside the bundle */
	#ifdef __MACOSX__
		ch = strstr(argv[0], "/Contents/MacOS");
		if (ch != NULL) {
			/* substite the 'C' of 'Contents/MacOS' with a string terminator */
			*(ch+1) = '\0';
			if (*pFilename == NULL) {
				/* if no filename was selected */
				chdir(argv[0]);
			}
			/* append app folder to search path */
			if (PHYSFS_addToSearchPath(argv[0], 1) == 0) {
				error(L,	"Error: Could not add application folder"
							"to search path: %s.", PHYSFS_getLastError());
			}
			*(ch+1) = 'C';
		} else {
			basedir = PHYSFS_getBaseDir();
			if (*pFilename == NULL) {
				chdir(basedir);
			}
			if (PHYSFS_addToSearchPath(basedir, 1) == 0) {
				error(L, "Error: Could not add base dir to search path: %s.", PHYSFS_getLastError());
			}
		}
	#else
		/* check whether we are on Linux or Unix */
		#ifndef __WIN32__
			/* on Linux or Unix: Try to append the share directory */
			#ifdef SHARE_DIR
			PHYSFS_addToSearchPath(SHARE_DIR, 1);
			#endif

		#endif
		/* on every system but OS X, prepend base dir to search path */
		if (PHYSFS_addToSearchPath(PHYSFS_getBaseDir(), 0) == 0) {
			error(L, "Error: Could not add base dir to search path: %s.", PHYSFS_getLastError());
		}
	#endif

	/*
	 * if a Lua file is given, try to mount the parent directory and change
	 * the working directory
	 * if an archive or directory is given, try to mount it
	 */
	if (*pFilename == NULL) {
		*pFilename = (char *)DEFAULT_FILE;
		if (PHYSFS_exists(*pFilename) == 0) {
			/* if default file not exists */
			if (PHYSFS_exists(DEFAULT_ARCHIVE) != 0) {
				/* if default archive exists, prepend to search path */
				if (PHYSFS_addToSearchPath(DEFAULT_ARCHIVE, 0) == 0) {
					error(L,	"Error: Could not add default archive '"
								DEFAULT_ARCHIVE "' to search path: %s",
								PHYSFS_getLastError());
				}
			} else {
				error(L,	"Error: "
							"Neither the default Lua file '" DEFAULT_FILE
							"' nor the default archive '" DEFAULT_ARCHIVE
							"' could be found.");
			}
		}
	} else {
		/* try to change the working directory (only successful if directory is given) */
		if (chdir(*pFilename) == 0) {
			/* prepend the new working directory to the search path */
			if (PHYSFS_addToSearchPath(".", 0) == 0) {
				error(L, "Error: Could not add directory '%s' to search path: %s", argv[1], PHYSFS_getLastError());
			}
			*pFilename = (char *)DEFAULT_FILE;
		} else {
			/* chdir was unsuccessful -> archive or Lua file was probably given on command line */
			splitPath(*pFilename, &dir, &base);
			/* change the working directory to the directory with the archive or the Lua file */
			chdir(dir);
//.........这里部分代码省略.........
开发者ID:scriptum,项目名称:Engine,代码行数:101,代码来源:FileIO.c


示例20: NETstopLogging


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ PHYSFS_getRealDir函数代码示例发布时间:2022-05-30
下一篇:
C++ PHYSFS_getDirSeparator函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap