本文整理汇总了C++中FileSpecifier::Open方法的典型用法代码示例。如果您正苦于以下问题:C++ FileSpecifier::Open方法的具体用法?C++ FileSpecifier::Open怎么用?C++ FileSpecifier::Open使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileSpecifier
的用法示例。
在下文中一共展示了FileSpecifier::Open方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CopyContents
// Copy file contents
bool FileSpecifier::CopyContents(FileSpecifier &source_name)
{
err = 0;
OpenedFile src, dst;
if (source_name.Open(src)) {
Delete();
if (Open(dst, true)) {
const int BUFFER_SIZE = 1024;
uint8 buffer[BUFFER_SIZE];
int32 length = 0;
src.GetLength(length);
while (length && err == 0) {
int32 count = length > BUFFER_SIZE ? BUFFER_SIZE : length;
if (src.Read(count, buffer)) {
if (!dst.Write(count, buffer))
err = dst.GetError();
} else
err = src.GetError();
length -= count;
}
}
} else
err = source_name.GetError();
if (err)
Delete();
return err == 0;
}
示例2: ParseFile
bool XML_Loader_SDL::ParseFile(FileSpecifier &file_name)
{
// Open file
OpenedFile file;
if (file_name.Open(file)) {
printf ( "Parsing: %s\n", file_name.GetPath() );
// Get file size and allocate buffer
file.GetLength(data_size);
data = new char[data_size];
// In case there were errors...
file_name.GetName(FileName);
// Read and parse file
if (file.Read(data_size, data)) {
if (!DoParse()) {
fprintf(stderr, "There were parsing errors in configuration file %s\n",
FileName);
}
}
// Delete buffer
delete[] data;
data = NULL;
return true;
} else {
printf ( "Couldn't open: %s\n", file_name.GetPath() );
}
return false;
}
示例3: ParsePlugin
bool PluginLoader::ParsePlugin(FileSpecifier& file_name)
{
OpenedFile file;
if (file_name.Open(file)) {
int32 data_size;
file.GetLength(data_size);
m_data.resize(data_size);
if (file.Read(data_size, &m_data[0])) {
file_name.ToDirectory(current_plugin_directory);
char name[256];
current_plugin_directory.GetName(name);
m_name = name;
if (!DoParse()) {
logError1("There were parsing errors in %s Plugin.xml\n", m_name.c_str());
}
}
m_data.clear();
return true;
}
return false;
}
示例4: physics_file_is_m1
bool physics_file_is_m1(void)
{
bool m1_physics = false;
// check for M1 physics
OpenedFile PhysicsFile;
short SavedType, SavedError = get_game_error(&SavedType);
if (PhysicsFileSpec.Open(PhysicsFile))
{
uint32 tag = SDL_ReadBE32(PhysicsFile.GetRWops());
switch (tag)
{
case M1_MONSTER_PHYSICS_TAG:
case M1_EFFECTS_PHYSICS_TAG:
case M1_PROJECTILE_PHYSICS_TAG:
case M1_PHYSICS_PHYSICS_TAG:
case M1_WEAPONS_PHYSICS_TAG:
m1_physics = true;
break;
default:
break;
}
PhysicsFile.Close();
}
set_game_error(SavedType, SavedError);
return m1_physics;
}
示例5: rewind_recording
void rewind_recording(
void)
{
if(replay.game_is_being_recorded)
{
/* This is unnecessary, because it is called from reset_player_queues, */
/* which is always called from revert_game */
/*
FilmFile.SetLength(sizeof(recording_header));
FilmFile.SetPosition(sizeof(recording_header));
*/
// Alternative that does not use "SetLength", but instead creates and re-creates the file.
FilmFile.SetPosition(0);
byte Header[SIZEOF_recording_header];
FilmFile.Read(SIZEOF_recording_header,Header);
FilmFile.Close();
FilmFileSpec.Delete();
FilmFileSpec.Create(_typecode_film);
FilmFileSpec.Open(FilmFile,true);
FilmFile.Write(SIZEOF_recording_header,Header);
// Use the packed length here!!!
replay.header.length= SIZEOF_recording_header;
}
}
示例6: LoadModel_Studio
bool LoadModel_Studio(FileSpecifier& Spec, Model3D& Model)
{
ModelPtr = &Model;
Model.Clear();
if (DBOut)
{
// Name buffer
const int BufferSize = 256;
char Buffer[BufferSize];
Spec.GetName(Buffer);
fprintf(DBOut,"Loading 3D Studio Max model file %s\n",Buffer);
}
OpenedFile OFile;
if (!Spec.Open(OFile))
{
if (DBOut) fprintf(DBOut,"ERROR opening the file\n");
return false;
}
ChunkHeaderData ChunkHeader;
if (!ReadChunkHeader(OFile,ChunkHeader)) return false;
if (ChunkHeader.ID != MASTER)
{
if (DBOut) fprintf(DBOut,"ERROR: not a 3DS Max model file\n");
return false;
}
if (!ReadContainer(OFile,ChunkHeader,ReadMaster)) return false;
return (!Model.Positions.empty() && !Model.VertIndices.empty());
}
示例7: setup_for_replay_from_file
bool setup_for_replay_from_file(
FileSpecifier& File,
uint32 map_checksum,
bool prompt_to_export)
{
bool successful= false;
(void)(map_checksum);
FilmFileSpec = File;
if (FilmFileSpec.Open(FilmFile))
{
replay.valid= true;
replay.have_read_last_chunk = false;
replay.game_is_being_replayed = true;
assert(!replay.resource_data);
replay.resource_data= NULL;
replay.resource_data_size= 0l;
replay.film_resource_offset= NONE;
byte Header[SIZEOF_recording_header];
FilmFile.Read(SIZEOF_recording_header,Header);
unpack_recording_header(Header,&replay.header,1);
replay.header.game_information.cheat_flags = _allow_crosshair | _allow_tunnel_vision | _allow_behindview | _allow_overlay_map;
/* Set to the mapfile this replay came from.. */
if(use_map_file(replay.header.map_checksum))
{
replay.fsread_buffer= new char[DISK_CACHE_SIZE];
assert(replay.fsread_buffer);
replay.location_in_cache= NULL;
replay.bytes_in_cache= 0;
replay.replay_speed= 1;
#ifdef DEBUG_REPLAY
open_stream_file();
#endif
if (prompt_to_export)
Movie::instance()->PromptForRecording();
successful= true;
} else {
/* Tell them that this map wasn't found. They lose. */
alert_user(infoError, strERRORS, cantFindReplayMap, 0);
replay.valid= false;
replay.game_is_being_replayed= false;
FilmFile.Close();
}
}
return successful;
}
示例8: Open
bool SndfileDecoder::Open(FileSpecifier& File)
{
Close();
sfinfo.format = 0;
OpenedFile openedFile;
if (File.Open(openedFile)) {
rwops = openedFile.TakeRWops();
sndfile = sf_open_virtual(&sf_virtual, SFM_READ, &sfinfo, rwops);
}
return sndfile;
}
示例9: calculate_crc_for_file
/* -------------- Entry Point ----------- */
uint32 calculate_crc_for_file(FileSpecifier& File)
{
uint32 crc = 0;
OpenedFile OFile;
if (File.Open(OFile))
{
crc= calculate_crc_for_opened_file(OFile);
OFile.Close();
}
return crc;
}
示例10: header_stream
static void import_m1_physics_data()
{
OpenedFile PhysicsFile;
if (!PhysicsFileSpec.Open(PhysicsFile))
{
return;
}
int32 position = 0;
int32 length;
PhysicsFile.GetLength(length);
while (position < length)
{
std::vector<uint8> header(12);
PhysicsFile.Read(header.size(), &header[0]);
AIStreamBE header_stream(&header[0], header.size());
uint32 tag;
uint16 count;
uint16 size;
header_stream >> tag;
header_stream.ignore(4); // unused
header_stream >> count;
header_stream >> size;
std::vector<uint8> data(count * size);
PhysicsFile.Read(data.size(), &data[0]);
switch (tag)
{
case M1_MONSTER_PHYSICS_TAG:
unpack_m1_monster_definition(&data[0], count);
break;
case M1_EFFECTS_PHYSICS_TAG:
unpack_m1_effect_definition(&data[0], count);
break;
case M1_PROJECTILE_PHYSICS_TAG:
unpack_m1_projectile_definition(&data[0], count);
break;
case M1_PHYSICS_PHYSICS_TAG:
unpack_m1_physics_constants(&data[0], count);
break;
case M1_WEAPONS_PHYSICS_TAG:
unpack_m1_weapon_definition(&data[0], count);
break;
}
PhysicsFile.GetPosition(position);
}
}
示例11:
SDL_Surface *WadImageCache::image_from_name(std::string& name) const
{
FileSpecifier file;
file.SetToImageCacheDir();
file.AddPart(name);
OpenedFile of;
if (!file.Open(of))
return NULL;
#ifdef HAVE_SDL_IMAGE
SDL_Surface *img = IMG_Load_RW(of.GetRWops(), 0);
#else
SDL_Surface *img = SDL_LoadBMP_RW(of.GetRWops(), 0);
#endif
return img;
}
示例12: ParseQuickSave
bool QuickSaveLoader::ParseQuickSave(FileSpecifier& file_name)
{
struct wad_header header;
struct wad_data *wad;
OpenedFile file;
if (file_name.Open(file))
{
if (read_wad_header(file, &header))
{
wad = read_indexed_wad_from_file(file, &header, SAVE_GAME_METADATA_INDEX, true);
if (wad)
{
size_t data_length;
char *raw_metadata = (char *)extract_type_from_wad(wad, SAVE_META_TAG, &data_length);
std::string metadata = std::string(raw_metadata, data_length);
boost::property_tree::ptree pt;
std::istringstream strm(metadata);
try {
boost::property_tree::ini_parser::read_ini(strm, pt);
} catch (...) {
return false;
}
QuickSave Data = QuickSave();
Data.save_file = file_name;
Data.name = pt.get("name", Data.name);
Data.level_name = pt.get("level_name", Data.level_name);
Data.ticks = pt.get("ticks", Data.ticks);
Data.formatted_ticks = pt.get("ticks_formatted", Data.formatted_ticks);
Data.save_time = pt.get("time", Data.save_time);
Data.formatted_time = pt.get("time_formatted", Data.formatted_time);
Data.players = pt.get("players", Data.players);
QuickSaves::instance()->add(Data);
free_wad(wad);
}
}
return true;
}
return false;
}
示例13:
void *get_network_physics_buffer(
int32 *physics_length)
{
if (physics_file_is_m1())
{
bool success = false;
uint8 *data = NULL;
OpenedFile PhysicsFile;
if (PhysicsFileSpec.Open(PhysicsFile) &&
PhysicsFile.GetLength(*physics_length))
{
data = (uint8 *)malloc(*physics_length + 4);
SDL_RWops *ops = SDL_RWFromMem(data, *physics_length + 4);
success = SDL_WriteBE32(ops, uint32(M1_PHYSICS_MAGIC_COOKIE));
if (success)
success = SDL_WriteBE32(ops, uint32(*physics_length));
SDL_RWclose(ops);
if (success)
success = PhysicsFile.Read(*physics_length, &data[8]);
if (!success)
free(data);
}
if (!success)
{
*physics_length = 0;
return NULL;
}
return data;
}
short SavedType, SavedError = get_game_error(&SavedType);
void *data= get_flat_data(PhysicsFileSpec, false, 0);
set_game_error(SavedType, SavedError);
if(data)
{
*physics_length= get_flat_data_length(data);
} else {
*physics_length= 0;
}
return data;
}
示例14: Open
bool MADDecoder::Open(FileSpecifier &File)
{
if (!File.Open(file)) return false;
file_done = false;
if (DecodeFrame())
{
stereo = (MAD_NCHANNELS(&Frame.header) == 2);
bytes_per_frame = 2 * (stereo ? 2 : 1);
rate = Frame.header.samplerate;
sample = 0;
return true;
}
else
{
return false;
}
}
示例15: start_recording
/* Note that we _must_ set the header information before we start recording!! */
void start_recording(
void)
{
assert(!replay.valid);
replay.valid= true;
if(get_recording_filedesc(FilmFileSpec))
FilmFileSpec.Delete();
if (FilmFileSpec.Create(_typecode_film))
{
/* I debate the validity of fsCurPerm here, but Alain had it, and it has been working */
if (FilmFileSpec.Open(FilmFile,true))
{
replay.game_is_being_recorded= true;
// save a header containing information about the game.
byte Header[SIZEOF_recording_header];
pack_recording_header(Header,&replay.header,1);
FilmFile.Write(SIZEOF_recording_header,Header);
}
}
}