当前位置: 首页>>代码示例>>C++>>正文


C++ PHYSFS_close函数代码示例

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


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

示例1: PHYSFS_openRead

bool ResourceManager::copyFile(const std::string &src, const std::string &dst)
{
    PHYSFS_file *srcFile = PHYSFS_openRead(src.c_str());
    if (!srcFile)
    {
        logger->log("Read error: %s", PHYSFS_getLastError());
        return false;
    }
    PHYSFS_file *dstFile = PHYSFS_openWrite(dst.c_str());
    if (!dstFile)
    {
        logger->log("Write error: %s", PHYSFS_getLastError());
        PHYSFS_close(srcFile);
        return false;
    }

    int fileSize = PHYSFS_fileLength(srcFile);
    void *buf = malloc(fileSize);
    PHYSFS_read(srcFile, buf, 1, fileSize);
    PHYSFS_write(dstFile, buf, 1, fileSize);

    PHYSFS_close(srcFile);
    PHYSFS_close(dstFile);
    free(buf);
    return true;
}
开发者ID:Ablu,项目名称:invertika,代码行数:26,代码来源:resourcemanager.cpp

示例2: state_get_game_id

int state_get_game_id(char *filename)
{
	int version;
	PHYSFS_file *fp;
	int between_levels;
	char mission[16];
	char desc[DESC_LENGTH+1];
	char id[5];
	int dumbint;

mprintf((0, "Restoring multigame from [%s]\n", filename));

	fp = PHYSFS_openRead(filename);
	if (!fp) return 0;

//Read id
	//FIXME: check for swapped file, react accordingly...
	PHYSFS_read(fp, id, sizeof(char) * 4, 1);
	if ( memcmp( id, dgss_id, 4 )) {
		PHYSFS_close(fp);
		return 0;
	}

//Read version
	PHYSFS_read(fp, &version, sizeof(int), 1);
	if (version < STATE_COMPATIBLE_VERSION)	{
		PHYSFS_close(fp);
		return 0;
	}

// Read description
	PHYSFS_read(fp, desc, sizeof(char) * DESC_LENGTH, 1);

// Skip the current screen shot...
	PHYSFS_seek(fp, PHYSFS_tell(fp) + THUMBNAIL_W * THUMBNAIL_H);

// And now...skip the palette stuff that somebody forgot to add
	PHYSFS_seek(fp, PHYSFS_tell(fp) + 768);

// Read the Between levels flag...
	PHYSFS_read(fp, &between_levels, sizeof(int), 1);

	Assert(between_levels == 0);	//between levels save ripped out

// Read the mission info...
	PHYSFS_read(fp, mission, sizeof(char) * 9, 1);
//Read level info
	PHYSFS_read(fp, &dumbint, sizeof(int), 1);
	PHYSFS_read(fp, &dumbint, sizeof(int), 1);

//Restore GameTime
	PHYSFS_read(fp, &dumbint, sizeof(fix), 1);

	PHYSFS_read(fp, &state_game_id, sizeof(int), 1);

	return (state_game_id);
 }
开发者ID:btb,项目名称:d2x,代码行数:57,代码来源:state.c

示例3: cmd_cat

static int cmd_cat(char *args)
{
    PHYSFS_File *f;

    if (*args == '\"')
    {
        args++;
        args[strlen(args) - 1] = '\0';
    } /* if */

    f = PHYSFS_openRead(args);
    if (f == NULL)
        printf("failed to open. Reason: [%s].\n", PHYSFS_getLastError());
    else
    {
        if (do_buffer_size)
        {
            if (!PHYSFS_setBuffer(f, do_buffer_size))
            {
                printf("failed to set file buffer. Reason: [%s].\n",
                        PHYSFS_getLastError());
                PHYSFS_close(f);
                return(1);
            } /* if */
        } /* if */

        while (1)
        {
            char buffer[128];
            PHYSFS_sint64 rc;
            PHYSFS_sint64 i;
            rc = PHYSFS_read(f, buffer, 1, sizeof (buffer));

            for (i = 0; i < rc; i++)
                fputc((int) buffer[i], stdout);

            if (rc < (int)sizeof (buffer))
            {
                printf("\n\n");
                if (!PHYSFS_eof(f))
                {
                    printf("\n (Error condition in reading. Reason: [%s])\n\n",
                           PHYSFS_getLastError());
                } /* if */
                PHYSFS_close(f);
                return(1);
            } /* if */
        } /* while */
    } /* else */

    return(1);
} /* cmd_cat */
开发者ID:Gokulakrishnansr,项目名称:cdogs-sdl,代码行数:52,代码来源:test_physfs.c

示例4: LoadInputs

void LoadInputs()
{
  Sint64 size;
  char *buffer;
  char buf[512];
  char input[16];
  int s;
  PHYSFS_File *PSfile;
  FILE *file;
  PSfile = PHYSFS_openRead("system/controls.cfg");
  if(PSfile == NULL)
  {
    fprintf(stderr,"Unable to open control configuration file!\n");
    return;
  }
  size = PHYSFS_fileLength(PSfile);
  buffer = (char *)malloc(size);
  if(buffer == NULL)
  {
    fprintf(stderr,"Unable to allocate space for control configuration file\n");
    PHYSFS_close(PSfile);
    return;
  }
  NumInputs = 0;
  PHYSFS_read(PSfile, buffer, size, 1);
  file = fmemopen (buffer, size, "r");
  while(fscanf(file, "%s", buf) != EOF)
  {
    if(strcmp(buf,"#") ==0)
    {
      fgets(buf, sizeof(buf), file);
      continue;/*ignore the rest of the line.*/
    }
    if(strcmp(buf,"<input>") ==0)
    {
      fscanf(file, "%s %s %s",InputList[NumInputs].name,InputList[NumInputs].type,input);
      s = ParseInput(InputList[NumInputs].type,input);
      if(s != -1)
      {
        InputList[NumInputs].id = s;
        NumInputs++;
      }
      continue;
    }
    
  }
  fclose(file);
  PHYSFS_close(PSfile);
  free(buffer);
}
开发者ID:engineerOfLies,项目名称:project-dark,代码行数:50,代码来源:controls.c

示例5: copy_file

//	-----------------------------------------------------------------------------------
//	Imagine if C had a function to copy a file...
int copy_file(char *old_file, char *new_file)
{
	sbyte   *buf = NULL;
	int		buf_size;
	PHYSFS_file *in_file, *out_file;

	out_file = PHYSFS_openWrite(new_file);

	if (out_file == NULL)
		return -1;

	in_file = PHYSFS_openRead(old_file);

	if (in_file == NULL)
		return -2;

	buf_size = (int)PHYSFS_fileLength(in_file);
	while (buf_size && !(buf = d_malloc(buf_size)))
		buf_size /= 2;
	if (buf_size == 0)
		return -5;	// likely to be an empty file

	while (!PHYSFS_eof(in_file))
	{
		int bytes_read;

		bytes_read = (int)PHYSFS_read(in_file, buf, 1, buf_size);
		if (bytes_read < 0)
			Error("Cannot read from file <%s>: %s", old_file, PHYSFS_getLastError());

		Assert(bytes_read == buf_size || PHYSFS_eof(in_file));

		if (PHYSFS_write(out_file, buf, 1, bytes_read) < bytes_read)
			Error("Cannot write to file <%s>: %s", new_file, PHYSFS_getLastError());
	}

	d_free(buf);

	if (!PHYSFS_close(in_file))
	{
		PHYSFS_close(out_file);
		return -3;
	}

	if (!PHYSFS_close(out_file))
		return -4;

	return 0;
}
开发者ID:btb,项目名称:d2x,代码行数:51,代码来源:state.c

示例6: writeSurfaces

static void writeSurfaces( const char *filename, std::vector< RenderSurface > &surfaces )
{
	uint64_t hashedName = HashedString( 0, filename );
	char outfile[256];
	PHYSFS_mkdir( "static_models/" );
	sprintf( outfile, "static_models/%08x_%08x.sm", (uint32_t)(hashedName>>32), (uint32_t)(hashedName&0xffffffff) );
	PHYSFS_File *model = PHYSFS_openWrite( outfile );
	if ( model )
	{
		PHYSFS_writeULE32( model, 0x090 );
		PHYSFS_writeULE32( model, surfaces.size() );
		for ( uint32_t i=0; i<surfaces.size(); i++ )
		{
			RenderSurface const &surf = surfaces[i];
			PHYSFS_writeCStr( model, surf.name.c_str() );
			PHYSFS_writeCStr( model, surf.mat->Name() );
			const ModelGeometry *geom = surf.geom;
			PHYSFS_writeSLE32( model, geom->m_numIndices );
			PHYSFS_writeSLE32( model, geom->m_numVerts );
			PHYSFS_write( model, geom->m_indices, sizeof(uint16_t)*geom->m_numIndices, 1 );
			PHYSFS_write( model, geom->m_verts, sizeof(geom->m_verts[0])*geom->m_numVerts, 1 );
		}
		PHYSFS_close( model );
	}
}
开发者ID:mikearmstrong001,项目名称:script,代码行数:25,代码来源:model_static.cpp

示例7: NETstopLogging

bool NETstopLogging(void)
{
    static const char dash_line[] = "-----------------------------------------------------------\n";
    char buf[256];
    int i;
    UDWORD totalBytessent = 0, totalBytesrecv = 0, totalPacketsent = 0, totalPacketrecv = 0;

    if (!pFileHandle)
    {
        return false;
    }

    /* Output stats */
    for (i = 0; i < NUM_GAME_PACKETS; i++)
    {
        snprintf(buf, sizeof(buf), "%-24s:\t received %u times, %u bytes; sent %u times, %u bytes\n", messageTypeToString(i),
                 packetcount[1][i], packetsize[1][i], packetcount[0][i], packetsize[0][i]);
        PHYSFS_write(pFileHandle, buf, strlen(buf), 1);
        totalBytessent += packetsize[0][i];
        totalBytesrecv += packetsize[1][i];
        totalPacketsent += packetcount[0][i];
        totalPacketrecv += packetcount[1][i];
    }
    snprintf(buf, sizeof(buf), "== Total bytes sent %u, Total bytes received %u ==\n", totalBytessent, totalBytesrecv);
    PHYSFS_write(pFileHandle, buf, strlen(buf), 1);
    snprintf(buf, sizeof(buf), "== Total packets sent %u, recv %u ==\n", totalPacketsent, totalPacketrecv);
    PHYSFS_write(pFileHandle, buf, strlen(buf), 1);
    snprintf(buf, sizeof(buf), "\n-Sync statistics -\n");
    PHYSFS_write(pFileHandle, buf, strlen(buf), 1);
    PHYSFS_write(pFileHandle, dash_line, strlen(dash_line), 1);
    snprintf(buf, sizeof(buf), "joins: %hhu, kicks: %hhu, drops: %hhu, left %hhu\n", sync_counter.joins, sync_counter.kicks, sync_counter.drops, sync_counter.left );
    PHYSFS_write(pFileHandle, buf, strlen(buf), 1);
    snprintf(buf, sizeof(buf), "banned: %hhu, cantjoin: %hhu, rejected: %hhu\n", sync_counter.banned, sync_counter.cantjoin, sync_counter.rejected );
    PHYSFS_write(pFileHandle, buf, strlen(buf), 1);
    if (sync_counter.banned && IPlist)
    {
        snprintf(buf, sizeof(buf), "Banned list:\n");
        PHYSFS_write(pFileHandle, buf, strlen(buf), 1);
        for (i = 0; i < MAX_BANS; i++)
        {
            if (IPlist[i].IPAddress[0] != '\0')
            {
                snprintf(buf, sizeof(buf), "player %s, IP: %s\n", IPlist[i].pname, IPlist[i].IPAddress);
                PHYSFS_write(pFileHandle, buf, strlen(buf), 1);
            }
        }

    }
    PHYSFS_write(pFileHandle, dash_line, strlen(dash_line), 1);
    PHYSFS_write(pFileHandle, dash_line, strlen(dash_line), 1);

    if (!PHYSFS_close(pFileHandle))
    {
        debug(LOG_ERROR, "Could not close net log: %s", PHYSFS_getLastError());
        return false;
    }
    pFileHandle = NULL;

    return true;
}
开发者ID:BG1,项目名称:warzone2100,代码行数:60,代码来源:netlog.cpp

示例8: piggy_close_file

void piggy_close_file()
{
	if ( Piggy_fp )	{
		PHYSFS_close( Piggy_fp );
		Piggy_fp	= NULL;
	}
}
开发者ID:Garog,项目名称:d1x-rebirth-ovr,代码行数:7,代码来源:piggy.c

示例9: strcpy

bool physfsDrive::FileOpen(DOS_File * * file,const char * name,Bit32u flags) {
	char newname[CROSS_LEN];
	strcpy(newname,basedir);
	strcat(newname,name);
	CROSS_FILENAME(newname);
	dirCache.ExpandName(newname);
	normalize(newname,basedir);

	PHYSFS_file * hand;
	
	if (!PHYSFS_exists(newname)) return false;
	if ((flags&0xf) == OPEN_READ) {
		hand = PHYSFS_openRead(newname);
	} else {

		/* open for reading, deal with writing later */
		hand = PHYSFS_openRead(newname);
	}

	if (!hand) { 
		if((flags&0xf) != OPEN_READ) {
			PHYSFS_file *hmm = PHYSFS_openRead(newname);
			if (hmm) {
				PHYSFS_close(hmm);
				LOG_MSG("Warning: file %s exists and failed to open in write mode.\nPlease mount a write directory (see docs).",newname);
			}
		}
		return false;
	}
   
	*file=new physfsFile(name,hand,0x202,newname,false);
	(*file)->flags=flags;  //for the inheritance flag and maybe check for others.
	return true;
}
开发者ID:Cliff-F,项目名称:Boxer,代码行数:34,代码来源:drive_physfs.cpp

示例10: dataAudioCfgLoad

/* Load an audio file */
static bool dataAudioCfgLoad(const char* fileName, void **ppData)
{
	bool success;
	PHYSFS_file* fileHandle;

	*ppData = NULL;

	if (audio_Disabled())
	{
		return true;
	}
	debug(LOG_WZ, "Reading...[directory: %s] %s", PHYSFS_getRealDir(fileName), fileName);
	fileHandle = PHYSFS_openRead(fileName);

	if (fileHandle == NULL)
	{
		return false;
	}

	success = ParseResourceFile(fileHandle);

	PHYSFS_close(fileHandle);

	return success;
}
开发者ID:Rimbok,项目名称:warzone2100,代码行数:26,代码来源:data.cpp

示例11: PHYSFS_close

sf::PhysFSStream::~PhysFSStream()
{
	if (file != NULL)
	{
		PHYSFS_close(file);
	}
}
开发者ID:mewbak,项目名称:DGEngine,代码行数:7,代码来源:PhysFSStream.cpp

示例12: PHYSFS_openRead

void Technique::Load( const char *filename )
{
	char buffer[512];
	PHYSFS_File *f = PHYSFS_openRead( fs::MakeCanonicalForm( buffer, filename ) );
	if ( f )
	{
		char line[512];
		while ( PHYSFS_gets( line, sizeof(line), f ) )
		{
			char str[256];
			if ( sscanf( line, "pass %s", str ) == 1 )
			{
				TechniquePass pass;
				if ( ParsePass( pass, f, str ) )
				{
					passes.push_back( pass );
				}
			}
		}
		PHYSFS_close(f);
	} else
	{
		TechniquePass pass;
		pass.pass = RP_Opaque;
		pass.shader = shaderManager()->Load( "_default" );
		pass.blendSrc = hw::BLEND_ONE;
		pass.blendDst = hw::BLEND_ZERO;
		passes.push_back( pass );
	}
}
开发者ID:mikearmstrong001,项目名称:script,代码行数:30,代码来源:technique.cpp

示例13: SetWindowIcon

void SetWindowIcon(photon_window &window, const std::string &filename){
    if(PHYSFS_exists(filename.c_str())){
        auto fp = PHYSFS_openRead(filename.c_str());
        intmax_t length = PHYSFS_fileLength(fp);
        if(length > 0){
            uint8_t *buffer = new uint8_t[length];

            PHYSFS_read(fp, buffer, 1, length);

            PHYSFS_close(fp);

            SDL_RWops *rw = SDL_RWFromMem(buffer, length);
            SDL_Surface *icon = IMG_Load_RW(rw, 1);

            if(icon == nullptr){
                PrintToLog("ERROR: icon loading failed! %s", IMG_GetError());
            }

            SDL_SetWindowIcon(window.window_SDL, icon);

            SDL_FreeSurface(icon);
            delete[] buffer;
        }else{
            PrintToLog("ERROR: Unable to open image file \"%s\"!");
        }
    }else{
        PrintToLog("ERROR: Image file \"%s\" does not exist!", filename.c_str());
    }
}
开发者ID:chipgw,项目名称:photon-legacy,代码行数:29,代码来源:window_managment.cpp

示例14: AppendIniArgs

void AppendIniArgs(void)
{
	PHYSFS_file *f;
	char *line, *token;
	char separator[] = " ";

	f = PHYSFSX_openReadBuffered(INI_FILENAME);

	if(f) {
		while(!PHYSFS_eof(f) && Num_args < MAX_ARGS)
		{
			line=fgets_unlimited(f);

			token = strtok(line, separator);        /* first token in current line */
			if (token)
				Args[Num_args++] = d_strdup(token);
			while( token != NULL )
			{
				token = strtok(NULL, separator);        /* next tokens in current line */
				if (token)
					Args[Num_args++] = d_strdup(token);
			}

			d_free(line);
		}
		PHYSFS_close(f);
	}
}
开发者ID:CDarrow,项目名称:DXX-Retro,代码行数:28,代码来源:args.c

示例15: readSurfaces

static bool readSurfaces( const char *filename, std::vector< RenderSurface > &surfaces )
{
	uint64_t hashedName = HashedString( 0, filename );
	char outfile[256];
	PHYSFS_mkdir( "static_models/" );
	sprintf( outfile, "static_models/%08x_%08x.sm", (uint32_t)(hashedName>>32), (uint32_t)(hashedName&0xffffffff) );
	PHYSFS_File *model = PHYSFS_openRead( outfile );
	if ( model )
	{
		unsigned int ver, numSurf;
		PHYSFS_readULE32( model, &ver );
		PHYSFS_readULE32( model, &numSurf );
		surfaces.resize( numSurf );
		for ( uint32_t i=0; i<surfaces.size(); i++ )
		{
			RenderSurface &surf = surfaces[i];
			PHYSFS_readCStr( model, surf.name );
			std::string mat;
			PHYSFS_readCStr( model, mat );
			surf.mat = materialManager()->Load( mat.c_str() );

			ModelGeometry *geom = new ModelGeometry;
			surf.geom = geom;
			PHYSFS_readSLE32( model, &geom->m_numIndices );
			PHYSFS_readSLE32( model, &geom->m_numVerts );
			geom->m_indices = new unsigned short[geom->m_numIndices];
			geom->m_verts = new ModelVert[geom->m_numVerts];
			PHYSFS_read( model, geom->m_indices, sizeof(uint16_t)*geom->m_numIndices, 1 );
			PHYSFS_read( model, geom->m_verts, sizeof(geom->m_verts[0])*geom->m_numVerts, 1 );
		}
		PHYSFS_close( model );
		return true;
	}
	return false;
}
开发者ID:mikearmstrong001,项目名称:script,代码行数:35,代码来源:model_static.cpp


注:本文中的PHYSFS_close函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。