本文整理汇总了C++中FileSpecifier::Exists方法的典型用法代码示例。如果您正苦于以下问题:C++ FileSpecifier::Exists方法的具体用法?C++ FileSpecifier::Exists怎么用?C++ FileSpecifier::Exists使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileSpecifier
的用法示例。
在下文中一共展示了FileSpecifier::Exists方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: confirm_save_choice
static bool confirm_save_choice(FileSpecifier & file)
{
// If the file doesn't exist, everything is alright
if (!file.Exists())
return true;
// Construct message
char name[256];
file.GetName(name);
char message[512];
sprintf(message, "'%s' already exists.", name);
// Create dialog
dialog d;
vertical_placer *placer = new vertical_placer;
placer->dual_add(new w_static_text(message), d);
placer->dual_add(new w_static_text("Ok to overwrite?"), d);
placer->add(new w_spacer(), true);
horizontal_placer *button_placer = new horizontal_placer;
w_button *default_button = new w_button("YES", dialog_ok, &d);
button_placer->dual_add(default_button, d);
button_placer->dual_add(new w_button("NO", dialog_cancel, &d), d);
placer->add(button_placer, true);
d.activate_widget(default_button);
d.set_widget_placer(placer);
// Run dialog
return d.run() == 0;
}
示例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: get_default_spec
static bool get_default_spec(FileSpecifier &file, const string &name)
{
vector<DirectorySpecifier>::const_iterator i = data_search_path.begin(), end = data_search_path.end();
while (i != end) {
file = *i + name;
if (file.Exists())
return true;
i++;
}
return false;
}
示例4: FileDialog
ReadFileDialog(FileSpecifier dir, Typecode type, const char* prompt) : FileDialog(), m_prompt(prompt) {
w_directory_browsing_list::SortOrder default_order = w_directory_browsing_list::sort_by_name;
if (!m_prompt)
{
switch(type)
{
case _typecode_savegame:
m_prompt = "CONTINUE SAVED GAME";
break;
case _typecode_film:
m_prompt = "REPLAY SAVED FILM";
break;
default:
m_prompt = "OPEN FILE";
break;
}
}
std::string filename;
switch (type)
{
case _typecode_savegame:
dir.SetToSavedGamesDir();
default_order = w_directory_browsing_list::sort_by_date;
break;
case _typecode_film:
dir.SetToRecordingsDir();
break;
case _typecode_scenario:
case _typecode_netscript:
{
// Go to most recently-used directory
DirectorySpecifier theDirectory;
dir.SplitPath(theDirectory, filename);
dir.FromDirectory(theDirectory);
if (!dir.Exists())
dir.SetToLocalDataDir();
}
break;
default:
dir.SetToLocalDataDir();
break;
}
Init(dir, default_order, filename);
m_list_w->file_selected = boost::bind(&ReadFileDialog::on_file_selected, this);
}
示例5: initialize_cache
void WadImageCache::initialize_cache()
{
FileSpecifier info;
info.SetToImageCacheDir();
info.AddPart("Cache.ini");
if (!info.Exists())
return;
InfoTree pt;
try {
pt = InfoTree::load_ini(info);
} catch (InfoTree::ini_error e) {
logError("Could not read image cache from %s (%s)", info.GetPath(), e.what());
}
for (InfoTree::iterator it = pt.begin(); it != pt.end(); ++it)
{
std::string name = it->first;
InfoTree ptc = it->second;
WadImageDescriptor desc;
std::string path;
ptc.read("path", path);
desc.file = FileSpecifier(path);
ptc.read("checksum", desc.checksum);
ptc.read("index", desc.index);
ptc.read("tag", desc.tag);
int width = 0;
ptc.read("width", width);
int height = 0;
ptc.read("height", height);
size_t filesize = 0;
ptc.read("filesize", filesize);
cache_key_t key = cache_key_t(desc, width, height);
cache_value_t val = cache_value_t(name, filesize);
m_used.push_front(cache_pair_t(key, val));
m_cacheinfo[key] = m_used.begin();
m_cachesize += filesize;
}
}
示例6: dump_screen
void dump_screen(void)
{
// Find suitable file name
FileSpecifier file;
int i = 0;
do {
char name[256];
const char* suffix;
#ifdef HAVE_PNG
suffix = "png";
#else
suffix = "bmp";
#endif
if (get_game_state() == _game_in_progress)
{
sprintf(name, "%s_%04d.%s", to_alnum(static_world->level_name).c_str(), i, suffix);
}
else
{
sprintf(name, "Screenshot_%04d.%s", i, suffix);
}
file = screenshots_dir + name;
i++;
} while (file.Exists());
#ifdef HAVE_PNG
// build some nice metadata
std::vector<IMG_PNG_text> texts;
std::map<std::string, std::string> metadata;
metadata["Source"] = expand_app_variables("$appName$ $appVersion$ ($appPlatform$)");
time_t rawtime;
time(&rawtime);
char time_string[32];
strftime(time_string, 32,"%d %b %Y %H:%M:%S +0000", gmtime(&rawtime));
metadata["Creation Time"] = time_string;
if (get_game_state() == _game_in_progress)
{
const float FLOAT_WORLD_ONE = float(WORLD_ONE);
const float AngleConvert = 360/float(FULL_CIRCLE);
metadata["Level"] = static_world->level_name;
char map_file_name[256];
FileSpecifier fs = environment_preferences->map_file;
fs.GetName(map_file_name);
metadata["Map File"] = map_file_name;
if (Scenario::instance()->GetName().size())
{
metadata["Scenario"] = Scenario::instance()->GetName();
}
metadata["Polygon"] = boost::lexical_cast<std::string>(world_view->origin_polygon_index);
metadata["X"] = boost::lexical_cast<std::string>(world_view->origin.x / FLOAT_WORLD_ONE);
metadata["Y"] = boost::lexical_cast<std::string>(world_view->origin.y / FLOAT_WORLD_ONE);
metadata["Z"] = boost::lexical_cast<std::string>(world_view->origin.z / FLOAT_WORLD_ONE);
metadata["Yaw"] = boost::lexical_cast<std::string>(world_view->yaw * AngleConvert);
short pitch = world_view->pitch;
if (pitch > HALF_CIRCLE) pitch -= HALF_CIRCLE;
metadata["Pitch"] = boost::lexical_cast<std::string>(pitch * AngleConvert);
}
for (std::map<std::string, std::string>::const_iterator it = metadata.begin(); it != metadata.end(); ++it)
{
IMG_PNG_text text;
text.key = const_cast<char*>(it->first.c_str());
text.value = const_cast<char*>(it->second.c_str());
texts.push_back(text);
}
IMG_PNG_text* textp = texts.size() ? &texts[0] : 0;
#endif
// Without OpenGL, dumping the screen is easy
if (!MainScreenIsOpenGL()) {
//#ifdef HAVE_PNG
// aoIMG_SavePNG(file.GetPath(), MainScreenSurface(), IMG_COMPRESS_DEFAULT, textp, texts.size());
#ifdef HAVE_SDL_IMAGE
IMG_SavePNG(MainScreenSurface(), file.GetPath());
#else
SDL_SaveBMP(MainScreenSurface(), file.GetPath());
#endif
return;
}
int video_w = MainScreenPixelWidth();
int video_h = MainScreenPixelHeight();
#ifdef HAVE_OPENGL
// Otherwise, allocate temporary surface...
SDL_Surface *t = SDL_CreateRGBSurface(SDL_SWSURFACE, video_w, video_h, 24,
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
0x000000ff, 0x0000ff00, 0x00ff0000, 0);
//.........这里部分代码省略.........
示例7: get_recording_filedesc
bool get_recording_filedesc(FileSpecifier &File)
{
File.SetToLocalDataDir();
File += getcstr(temporary, strFILENAMES, filenameMARATHON_RECORDING);
return File.Exists();
}