当前位置: 首页>>代码示例>>C++>>正文


C++ FileSpecifier::FromDirectory方法代码示例

本文整理汇总了C++中FileSpecifier::FromDirectory方法的典型用法代码示例。如果您正苦于以下问题:C++ FileSpecifier::FromDirectory方法的具体用法?C++ FileSpecifier::FromDirectory怎么用?C++ FileSpecifier::FromDirectory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FileSpecifier的用法示例。


在下文中一共展示了FileSpecifier::FromDirectory方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: 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;
}
开发者ID:Aleph-One-Marathon,项目名称:alephone-dingoo,代码行数:62,代码来源:preprocess_map_shared.cpp

示例2: 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;
}
开发者ID:Aleph-One-Marathon,项目名称:alephone-dingoo,代码行数:61,代码来源:preprocess_map_shared.cpp

示例3: 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);
	}
开发者ID:logue,项目名称:alephone_jp,代码行数:49,代码来源:FileHandler.cpp


注:本文中的FileSpecifier::FromDirectory方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。