本文整理汇总了C++中PHYSFS_openWrite函数的典型用法代码示例。如果您正苦于以下问题:C++ PHYSFS_openWrite函数的具体用法?C++ PHYSFS_openWrite怎么用?C++ PHYSFS_openWrite使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PHYSFS_openWrite函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: PHYSFS_openWrite
// Save a whole buffer to disk
//QUE: Optimize size!!!!!!!!!!!!!!!!!!!!!!!
unsigned int j1FileSystem::Save(const char* file, const char* buffer, unsigned int size) const
{
unsigned int ret = 0;
//PHYSFS_addToSearchPath(file, 1);
//PHYSFS_setWriteDir("Dev_class3_handout/Game/data_files.xml");
PHYSFS_file* fs_file = PHYSFS_openWrite(file);
if(fs_file != NULL)
{
PHYSFS_file* debug2 = PHYSFS_openWrite("data_files.xml");
PHYSFS_sint64 written = PHYSFS_write(fs_file, (const void*)buffer, 1, size);
if(written != size)
LOG("File System error while writing to file %s: %s\n", file, PHYSFS_getLastError());
else
ret = (uint) written;
if(PHYSFS_close(fs_file) == 0)
LOG("File System error while closing file %s: %s\n", file, PHYSFS_getLastError());
}
else
LOG("File System error while opening file %s: %s\n", file, PHYSFS_getLastError());
return ret;
}
示例2: 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;
}
示例3: 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 );
}
}
示例4: PHYSFS_openRead
static void *file_phys_fopen(const char *filename, const char *mode)
{
PHYSFS_file *phys;
ALLEGRO_FILE_PHYSFS *fp;
/* XXX handle '+' modes */
/* It might be worth adding a function to parse mode strings, to be
* shared amongst these kinds of addons.
*/
if (streq(mode, "r") || streq(mode, "rb"))
phys = PHYSFS_openRead(filename);
else if (streq(mode, "w") || streq(mode, "wb"))
phys = PHYSFS_openWrite(filename);
else if (streq(mode, "a") || streq(mode, "ab"))
phys = PHYSFS_openAppend(filename);
else
phys = NULL;
if (!phys) {
phys_set_errno(NULL);
return NULL;
}
fp = al_malloc(sizeof(*fp));
if (!fp) {
al_set_errno(ENOMEM);
PHYSFS_close(phys);
return NULL;
}
fp->phys = phys;
fp->error_indicator = false;
return fp;
}
示例5: fs_open
fs_file fs_open(const char *path, const char *mode)
{
fs_file fh;
assert((mode[0] == 'r' && !mode[1]) ||
(mode[0] == 'w' && (!mode[1] || mode[1] == '+')));
if ((fh = malloc(sizeof (*fh))))
{
switch (mode[0])
{
case 'r':
fh->handle = PHYSFS_openRead(path);
break;
case 'w':
fh->handle = (mode[1] == '+' ?
PHYSFS_openAppend(path) :
PHYSFS_openWrite(path));
break;
}
if (fh->handle)
{
PHYSFS_setBuffer(fh->handle, 0x2000);
}
else
{
free(fh);
fh = NULL;
}
}
return fh;
}
示例6: switch
Lux::Core::OpenedFile* Lux::Core::FileHandler::OpenFile(const String a_File, FileOpenMode a_OpenMode)
{
OpenedFile* retFile = nullptr;
switch (a_OpenMode)
{
case Lux::Core::FileHandler::FILE_OPEN_READ:
retFile = PHYSFS_openRead(a_File.c_str());
break;
case Lux::Core::FileHandler::FILE_OPEN_WRITE:
retFile = PHYSFS_openWrite(a_File.c_str());
break;
case Lux::Core::FileHandler::FILE_OPEN_APPEND:
retFile = PHYSFS_openAppend(a_File.c_str());
break;
default:
Utility::ThrowError("Unsupported file open mode.");
break;
}
if (retFile == nullptr)
{
Utility::ThrowError("Could not open specified file: " + a_File + " . " + PHYSFS_getLastError());
}
return retFile;
}
示例7: NETstartLogging
bool NETstartLogging(void)
{
time_t aclock;
struct tm *newtime;
char buf[256];
static char filename[256] = {'\0'};
int i;
for (i = 0; i < NUM_GAME_PACKETS; i++)
{
packetcount[0][i] = 0;
packetsize[0][i] = 0;
packetcount[1][i] = 0;
packetsize[1][i] = 0;
}
time( &aclock ); /* Get time in seconds */
newtime = localtime( &aclock ); /* Convert time to struct */
snprintf(filename, sizeof(filename), "logs/netplay-%04d%02d%02d_%02d%02d%02d.log", newtime->tm_year + 1900, newtime->tm_mon + 1, newtime->tm_mday, newtime->tm_hour, newtime->tm_min, newtime->tm_sec);
pFileHandle = PHYSFS_openWrite( filename ); // open the file
if (!pFileHandle)
{
debug(LOG_ERROR, "Could not create net log %s: %s", filename,
PHYSFS_getLastError());
return false;
}
snprintf(buf, sizeof(buf), "NETPLAY log: %s\n", asctime(newtime));
PHYSFS_write( pFileHandle, buf, strlen( buf ), 1 );
return true;
}
示例8: PHYSFS_openWrite
FileStreamPtr ResourceManager::createFile(const std::string& fileName)
{
PHYSFS_File* file = PHYSFS_openWrite(fileName.c_str());
if(!file)
stdext::throw_exception(stdext::format("failed to create file '%s': %s", fileName, PHYSFS_getLastError()));
return FileStreamPtr(new FileStream(fileName, file, true));
}
示例9: assert
void File::open(const std::string& filename, OpenMode mode, bool no_override)
{
// check that we don't have anything opened!
/// \todo maybe we could just close the old file here... but
/// then, this could also lead to errors...
assert(mHandle == 0);
// open depending on mode
if( mode == OPEN_WRITE )
{
if(no_override && FileSystem::getSingleton().exists(filename))
{
BOOST_THROW_EXCEPTION(FileAlreadyExistsException(filename));
}
mHandle = PHYSFS_openWrite(filename.c_str());
}
else
{
mHandle = PHYSFS_openRead(filename.c_str());
}
if (!mHandle)
{
BOOST_THROW_EXCEPTION(FileLoadException(filename));
}
mFileName = filename;
}
示例10: impl
File::File(const MountedFilePath& mountedFilePath, DataStream::OpenMode openMode)
: impl(std::make_unique<File_Impl>()), mountedFilePath(mountedFilePath)
{
const char* path = mountedFilePath.path.c_str();
int fileExists = PHYSFS_exists(path);
if (fileExists == 0)
{
throw Exception(std::string("File ") + path + " does not exist in the search path");
}
switch (openMode)
{
case OpenMode::Read:
impl->physfsFileHandle = PHYSFS_openRead(path);
break;
case OpenMode::Write:
impl->physfsFileHandle = PHYSFS_openWrite(path);
break;
case OpenMode::Append:
impl->physfsFileHandle = PHYSFS_openAppend(path);
break;
}
if (impl->physfsFileHandle == nullptr)
{
throw Exception(std::string("Failed to open file ") + path + "\n" + PHYSFS_getLastError());
}
}
示例11: int
void
Downloader::download(const std::string& url, const std::string& filename)
{
log_info << "download: " << url << " to " << filename << std::endl;
std::unique_ptr<PHYSFS_file, int(*)(PHYSFS_File*)> fout(PHYSFS_openWrite(filename.c_str()),
PHYSFS_close);
download(url, my_curl_physfs_write, fout.get());
}
示例12: PHYSFS_openWrite
ResourceWO * Resources::RetrieveWrite(PString & filename) {
PHYSFS_file* file = PHYSFS_openWrite(filename);
if(!file) {
PError << "couldn't open file '" << filename << "' for writing: " << PHYSFS_getLastError() << endl;
return NULL;
};
return new ResourceWO(file);
}
示例13: openWrite
WriteFile* openWrite(const char* filename)
{
PHYSFS_file* file = PHYSFS_openWrite(filename);
if(!file)
throw Exception("couldn't open file '%s' for writing: %s", filename,
PHYSFS_getLastError());
return new WriteFile(file);
}
示例14: s_log_error
stream_t *file_open(const char *path, stream_mode_t mode, allocator_t *alloc)
{
PHYSFS_File *file = NULL;
stream_t *stream = NULL;
char *pathcopy;
size_t pathsize;
if (!alloc)
alloc = g_default_allocator;
if (!path) {
s_log_error("NULL path for file.");
return NULL;
}
stream = stream_alloc(mode, alloc);
if (stream) {
switch (mode) {
case STREAM_READ:
file = PHYSFS_openRead(path);
break;
case STREAM_WRITE:
file = PHYSFS_openWrite(path);
break;
case STREAM_APPEND:
file = PHYSFS_openAppend(path);
break;
default: /* cannot reach */ break;
}
// if r+ failed because the file doesn't exist, open again with w
if (file == NULL) {
s_log_error("Failed to open file '%s' with mode %d. Error: %s.",
path, mode, pfs_get_error());
stream_close(stream);
return NULL;
}
stream->read = file_read;
stream->write = file_write;
stream->seek = file_seek;
stream->eof = file_eof;
stream->close = file_close;
// copy path string
pathsize = strlen(path) + 1;
pathcopy = com_malloc(alloc, pathsize);
strncpy(pathcopy, path, pathsize);
stream->context.pfs.file = file;
stream->context.pfs.file_path = pathcopy;
}
return stream;
}
示例15: openWithMode
PHYSFS_File* openWithMode(char const * filename, mode openMode) {
switch (openMode) {
case WRITE:
return PHYSFS_openWrite(filename);
case APPEND:
return PHYSFS_openAppend(filename);
case READ:
return PHYSFS_openRead(filename);
}
}