本文整理汇总了C++中FileSpecifier::ToDirectory方法的典型用法代码示例。如果您正苦于以下问题:C++ FileSpecifier::ToDirectory方法的具体用法?C++ FileSpecifier::ToDirectory怎么用?C++ FileSpecifier::ToDirectory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileSpecifier
的用法示例。
在下文中一共展示了FileSpecifier::ToDirectory方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: strlen
// This tries to find a filename (in the same directory as inBaseName) based on 'inBaseName' but that is not yet used.
// The current logic tries inBaseName first, then 'inBaseName 2', then 'inBaseName 3', and so on.
// The resulting name will have no more than inMaxNameLength actual characters.
// Returns whether it was successful (the current logic either returns true or loops forever; fortunately, the
// probability of looping forever is really, REALLY tiny; the directory would have to contain every possible variant).
static bool
make_nonconflicting_filename_variant(/*const*/ FileSpecifier& inBaseName, FileSpecifier& outNonconflictingName, size_t inMaxNameLength) {
FileSpecifier theNameToTry;
DirectorySpecifier theDirectory;
inBaseName.ToDirectory(theDirectory);
char theBaseNameString[256]; // XXX I don't like this, but the SDL code already imposes this maxlen throughout.
inBaseName.GetName(theBaseNameString);
size_t theBaseNameLength = strlen(theBaseNameString);
char theNameToTryString[256];
char theVariantSuffix[32]; // way more than enough
unsigned int theVariant = 0;
size_t theSuffixLength;
size_t theBaseNameLengthToUse;
bool theVariantIsAcceptable = false;
while(!theVariantIsAcceptable) {
theVariant++;
if(theVariant == 1) {
theVariantSuffix[0] = '\0';
theSuffixLength = 0;
}
else {
theSuffixLength = sprintf(theVariantSuffix, " %d", theVariant);
}
assert(theSuffixLength <= inMaxNameLength);
if(theSuffixLength + theBaseNameLength > inMaxNameLength)
theBaseNameLengthToUse = inMaxNameLength - theSuffixLength;
else
theBaseNameLengthToUse = theBaseNameLength;
sprintf(theNameToTryString, "%.*s%s", (int) theBaseNameLengthToUse, theBaseNameString, theVariantSuffix);
theNameToTry.FromDirectory(theDirectory);
#if defined(mac) || defined(SDL_RFORK_HACK)
// Note: SetName() currently ignores the 'type' argument, so I feel
// little compulsion to try to figure it out.
theNameToTry.SetName(theNameToTryString,NONE);
#else
theNameToTry.AddPart(theNameToTryString);
#endif
if(!theNameToTry.Exists())
theVariantIsAcceptable = true;
}
if(theVariantIsAcceptable) {
outNonconflictingName = theNameToTry;
}
return theVariantIsAcceptable;
}
示例3: strcpy
// Analogous to 'save_game()', but does not present any dialog to the user, and reports the results
// using screen_printf(). If inOverwriteRecent is set, it will save over the most recently saved
// or restored game (if possible). If inOverwriteRecent is not set, or if there is no recent game
// to save over, it will pick a new, nonconflicting filename and save to it.
// Returns whether save was successful.
bool
save_game_full_auto(bool inOverwriteRecent) {
bool createNewFile = !inOverwriteRecent;
FileSpecifier theRecentSavedGame;
get_current_saved_game_name(theRecentSavedGame);
char theSavedGameName[256]; // XXX
// If we're supposed to overwrite, change our minds if we seem to have no 'existing file'.
if(!createNewFile) {
theRecentSavedGame.GetName(theSavedGameName);
if(strcmp(theSavedGameName, TS_GetCString(strFILENAMES, filenameDEFAULT_SAVE_GAME)) == 0)
createNewFile = true;
}
// Make up a filename (currently based on level name)
if(createNewFile) {
if(strncpy_filename_friendly(theSavedGameName, static_world->level_name, kMaxFilenameChars) <= 0)
strcpy(theSavedGameName, "Automatic Save");
DirectorySpecifier theDirectory;
theRecentSavedGame.ToDirectory(theDirectory);
theRecentSavedGame.FromDirectory(theDirectory);
#if defined(mac) || defined(SDL_RFORK_HACK)
// Note: SetName() currently ignores the 'type' argument, so I feel
// little compulsion to try to figure it out.
theRecentSavedGame.SetName(theSavedGameName,NONE);
#else
theRecentSavedGame.AddPart(theSavedGameName);
#endif
}
FileSpecifier theOutputFile;
if(createNewFile)
make_nonconflicting_filename_variant(theRecentSavedGame, theOutputFile, kMaxFilenameChars);
else
theOutputFile = theRecentSavedGame;
bool successfulSave = save_game_file(theOutputFile);
theOutputFile.GetName(theSavedGameName);
if(successfulSave) {
screen_printf("%s saved game '%s'", createNewFile ? "Created new" : "Replaced existing", theSavedGameName);
// play a sound?
}
else {
screen_printf("Unable to save game as '%s'", theSavedGameName);
// play a sound?
}
return successfulSave;
}
示例4: LoadLevelScripts
// Loads all those in resource 128 in a map file (or some appropriate equivalent)
void LoadLevelScripts(FileSpecifier& MapFile)
{
// Because all the files are to live in the map file's parent directory
MapFile.ToDirectory(MapParentDir);
// Get rid of the previous level script
// ghs: unless it's the first time, in which case we would be clearing
// any external level scripts, so don't
static bool FirstTime = true;
if (FirstTime) {
FirstTime = false;
}
else{
LevelScripts.clear();
}
// Set these to their defaults before trying to change them
EndScreenIndex = 99;
NumEndScreens = 1;
// Lazy setup of XML parsing definitions
SetupLSParseTree();
LSXML_Loader.CurrentElement = &LSRootParser;
// OpenedResourceFile OFile;
// if (!MapFile.Open(OFile)) return;
// The script is stored at a special resource ID;
// simply quit if it could not be found
LoadedResource ScriptRsrc;
// if (!OFile.Get('T','E','X','T',128,ScriptRsrc)) return;
if (!get_text_resource_from_scenario(128,ScriptRsrc)) {
return;
}
// Load the script
LSXML_Loader.SourceName = "[Map Script]";
LSXML_Loader.ParseData((char *)ScriptRsrc.GetPointer(),ScriptRsrc.GetLength());
}