本文整理汇总了C++中MemChunk::importFile方法的典型用法代码示例。如果您正苦于以下问题:C++ MemChunk::importFile方法的具体用法?C++ MemChunk::importFile怎么用?C++ MemChunk::importFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MemChunk
的用法示例。
在下文中一共展示了MemChunk::importFile方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: open
/* Archive::open
* Reads an archive from disk
* Returns true if successful, false otherwise
*******************************************************************/
bool Archive::open(string filename)
{
// Read the file into a MemChunk
MemChunk mc;
if (!mc.importFile(filename))
{
Global::error = "Unable to open file. Make sure it isn't in use by another program.";
return false;
}
// Update filename before opening
string backupname = this->filename;
this->filename = filename;
// Load from MemChunk
sf::Clock timer;
if (open(mc))
{
LOG_MESSAGE(2, "Archive::open took %dms", timer.getElapsedTime().asMilliseconds());
this->on_disk = true;
return true;
}
else
{
this->filename = backupname;
return false;
}
}
示例2: updateEntry
void updateEntry()
{
// Read file
MemChunk data;
data.importFile(filename);
// Read image
SImage image;
image.open(data, 0, "png");
image.convertPaletted(&palette);
// Convert image to entry gfx format
SIFormat* format = SIFormat::getFormat(gfx_format);
if (format)
{
MemChunk conv_data;
if (format->saveImage(image, conv_data, &palette))
{
// Update entry data
entry->importMemChunk(conv_data);
EntryOperations::setGfxOffsets(entry, offsets.x, offsets.y);
}
else
{
LOG_MESSAGE(1, "Unable to convert external png to %s", format->getName());
}
}
}
示例3: loadCustomPalettes
/* PaletteManager::loadCustomPalettes
* Loads any files in the '<userdir>/palettes' directory as palettes,
* with names from the files (minus the file extension)
*******************************************************************/
bool PaletteManager::loadCustomPalettes()
{
// If the directory doesn't exist create it
if (!wxDirExists(appPath("palettes", DIR_USER)))
wxMkdir(appPath("palettes", DIR_USER));
// Open the custom palettes directory
wxDir res_dir;
res_dir.Open(appPath("palettes", DIR_USER));
// Go through each file in the directory
string filename = wxEmptyString;
bool files = res_dir.GetFirst(&filename, wxEmptyString, wxDIR_FILES);
while (files)
{
// Load palette data
Palette8bit* pal = new Palette8bit();
MemChunk mc;
mc.importFile(res_dir.GetName() + "/" + filename);
pal->loadMem(mc);
// Add the palette
wxFileName fn(filename);
addPalette(pal, fn.GetName());
// Next file
files = res_dir.GetNext(&filename);
}
return true;
}
示例4: open
// -----------------------------------------------------------------------------
// Reads an archive from disk
// Returns true if successful, false otherwise
// -----------------------------------------------------------------------------
bool Archive::open(string_view filename)
{
// Read the file into a MemChunk
MemChunk mc;
if (!mc.importFile(filename))
{
Global::error = "Unable to open file. Make sure it isn't in use by another program.";
return false;
}
// Update filename before opening
auto backupname = filename_;
filename_ = filename;
// Load from MemChunk
sf::Clock timer;
if (open(mc))
{
Log::info(2, "Archive::open took {}ms", timer.getElapsedTime().asMilliseconds());
on_disk_ = true;
return true;
}
else
{
filename_ = backupname;
return false;
}
}
示例5: init
/* ColourConfiguration::init
* Initialises the colour configuration
*******************************************************************/
bool ColourConfiguration::init()
{
// Load default configuration
loadDefaults();
// Check for saved colour configuration
if (wxFileExists(appPath("colours.cfg", DIR_USER)))
{
MemChunk ccfg;
ccfg.importFile(appPath("colours.cfg", DIR_USER));
readConfiguration(ccfg);
}
return true;
}
示例6: init
// -----------------------------------------------------------------------------
// Initialises the colour configuration
// -----------------------------------------------------------------------------
bool ColourConfiguration::init()
{
// Load default configuration
loadDefaults();
// Check for saved colour configuration
if (wxFileExists(App::path("colours.cfg", App::Dir::User)))
{
MemChunk ccfg;
ccfg.importFile(App::path("colours.cfg", App::Dir::User));
readConfiguration(ccfg);
}
return true;
}
示例7: init
/* Executables::init
* Reads all executable definitions from the program resource
* and user dir
*******************************************************************/
void Executables::init()
{
// Load from pk3
Archive* res_archive = theArchiveManager->programResourceArchive();
ArchiveEntry* entry = res_archive->entryAtPath("config/executables.cfg");
if (!entry)
return;
// Parse base executables config
Parser p;
p.parseText(entry->getMCData(), "slade.pk3 - executables.cfg");
parse(&p, false);
// Parse user executables config
Parser p2;
MemChunk mc;
if (mc.importFile(App::path("executables.cfg", App::Dir::User)))
{
p2.parseText(mc, "user execuatbles.cfg");
parse(&p2, true);
}
}
示例8: loadEntryTypes
/* EntryType::loadEntryTypes
* Loads all built-in and custom user entry types
*******************************************************************/
bool EntryType::loadEntryTypes()
{
EntryDataFormat* fmt_any = EntryDataFormat::anyFormat();
// Setup unknown type
etype_unknown.format = fmt_any;
etype_unknown.icon = "e_unknown";
etype_unknown.detectable = false;
etype_unknown.reliability = 0;
etype_unknown.addToList();
// Setup folder type
etype_folder.format = fmt_any;
etype_folder.icon = "e_folder";
etype_folder.name = "Folder";
etype_folder.detectable = false;
etype_folder.addToList();
// Setup marker type
etype_marker.format = fmt_any;
etype_marker.icon = "e_marker";
etype_marker.name = "Marker";
etype_marker.detectable = false;
etype_marker.category = ""; // No category, markers only appear when 'All' categories shown
etype_marker.addToList();
// Setup map marker type
etype_map.format = fmt_any;
etype_map.icon = "e_map";
etype_map.name = "Map Marker";
etype_map.category = "Maps"; // Should appear with maps
etype_map.detectable = false;
etype_map.colour = rgba_t(0, 255, 0);
etype_map.addToList();
// -------- READ BUILT-IN TYPES ---------
// Get builtin entry types from resource archive
Archive* res_archive = theArchiveManager->programResourceArchive();
// Check resource archive exists
if (!res_archive)
{
wxLogMessage("Error: No resource archive open!");
return false;
}
// Get entry types directory
ArchiveTreeNode* et_dir = res_archive->getDir("config/entry_types/");
// Check it exists
if (!et_dir)
{
wxLogMessage("Error: config/entry_types does not exist in slade.pk3");
return false;
}
// Read in each file in the directory
bool etypes_read = false;
for (unsigned a = 0; a < et_dir->numEntries(); a++)
{
if (readEntryTypeDefinition(et_dir->getEntry(a)->getMCData()))
etypes_read = true;
}
// Warn if no types were read (this shouldn't happen unless the resource archive is corrupted)
if (!etypes_read)
wxLogMessage("Warning: No built-in entry types could be loaded from slade.pk3");
// -------- READ CUSTOM TYPES ---------
// If the directory doesn't exist create it
if (!wxDirExists(appPath("entry_types", DIR_USER)))
wxMkdir(appPath("entry_types", DIR_USER));
// Open the custom palettes directory
wxDir res_dir;
res_dir.Open(appPath("entry_types", DIR_USER));
// Go through each file in the directory
string filename = wxEmptyString;
bool files = res_dir.GetFirst(&filename, wxEmptyString, wxDIR_FILES);
while (files)
{
// Load file data
MemChunk mc;
mc.importFile(res_dir.GetName() + "/" + filename);
// Parse file
readEntryTypeDefinition(mc);
// Next file
files = res_dir.GetNext(&filename);
}
return true;
}
示例9: init
// -----------------------------------------------------------------------------
// Game related initialisation (read basic definitions, etc.)
// -----------------------------------------------------------------------------
void Game::init()
{
// Init static ThingTypes
ThingType::initGlobal();
// Init static ActionSpecials
ActionSpecial::initGlobal();
// Add game configurations from user dir
wxArrayString allfiles;
wxDir::GetAllFiles(App::path("games", App::Dir::User), &allfiles);
for (unsigned a = 0; a < allfiles.size(); a++)
{
// Read config info
MemChunk mc;
mc.importFile(allfiles[a]);
// Add to list if valid
GameDef gdef;
if (gdef.parse(mc))
{
gdef.filename = wxFileName(allfiles[a]).GetName();
gdef.user = true;
game_defs[gdef.name] = gdef;
}
}
// Add port configurations from user dir
allfiles.clear();
wxDir::GetAllFiles(App::path("ports", App::Dir::User), &allfiles);
for (unsigned a = 0; a < allfiles.size(); a++)
{
// Read config info
MemChunk mc;
mc.importFile(allfiles[a]);
// Add to list if valid
PortDef pdef;
if (pdef.parse(mc))
{
pdef.filename = wxFileName(allfiles[a]).GetName();
pdef.user = true;
port_defs[pdef.name] = pdef;
}
}
// Add game configurations from program resource
auto dir = App::archiveManager().programResourceArchive()->getDir("config/games");
if (dir)
{
for (auto& entry : dir->entries())
{
// Read config info
GameDef conf;
if (!conf.parse(entry.get()->getMCData()))
continue; // Ignore if invalid
// Add to list if it doesn't already exist
if (game_defs.find(conf.name) == game_defs.end())
{
conf.filename = entry.get()->getName(true);
conf.user = false;
game_defs[conf.name] = conf;
}
}
}
// Add port configurations from program resource
dir = App::archiveManager().programResourceArchive()->getDir("config/ports");
if (dir)
{
for (auto& entry : dir->entries())
{
// Read config info
PortDef conf;
if (!conf.parse(entry.get()->getMCData()))
continue; // Ignore if invalid
// Add to list if it doesn't already exist
if (port_defs.find(conf.name) == port_defs.end())
{
conf.filename = entry.get()->getName(true);
conf.user = false;
port_defs[conf.name] = conf;
}
}
}
// Load last configuration if any
if (game_configuration != "")
config_current.openConfig(game_configuration, port_configuration);
// Load custom special presets
if (!loadCustomSpecialPresets())
Log::warning("An error occurred loading user special_presets.cfg");
// Load zdoom.pk3 stuff
//.........这里部分代码省略.........