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


C++ FileStream::Init方法代码示例

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


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

示例1: rename

Stream *HostOpenSaveGameStream(int nGame, bool fDelete)
{
	char szT[PATH_MAX];
	if (!FindSaveGame(nGame, szT, sizeof(szT)))
		return NULL;

	// rename to a temporary file before opening

	char szTFull[PATH_MAX];
	PrependSavesDirectory(szT, szTFull);
	char szTempNameFull[PATH_MAX];
	PrependSavesDirectory(kszTempName, szTempNameFull);
    rename(szTFull, szTempNameFull);

	// Get stream over temp file

	FileStream *pstm = new FileStream();
	if (pstm == NULL)
		return NULL;

	// If load is successful, and fDelete is True  szTempName will be deleted
	// if fDelete is false szTempName will be renamed to szSaveGame

	if (!pstm->Init("rb", szTempNameFull, fDelete ? szTempNameFull : NULL, fDelete ? NULL : szTFull)) {
		delete pstm;
		return NULL;
	}

	return (Stream *)pstm;
}
开发者ID:aelzohry,项目名称:hostile-takeover,代码行数:30,代码来源:savegame.cpp

示例2: strchr

Stream *HostNewSaveGameStream(int nGame, char *pszName)
{
	// Get the old file name - we'll delete this if successful

	char szOld[PATH_MAX];
	char szOldFull[PATH_MAX];
	if (!FindSaveGame(nGame, szOld, sizeof(szOld))) {
		szOldFull[0] = 0;
	} else {
		PrependSavesDirectory(szOld, szOldFull);
	}

	// New file name

	char szNew[PATH_MAX];
	sprintf(szNew, "htsave%d_%s.bin", nGame, pszName);

	// windows disallows ':' in a filename, so sub those out

	char *pchInvalid = szNew;
	do {
		pchInvalid = strchr(pchInvalid, ':');
		if (pchInvalid != 0)
			*pchInvalid = '#';
	} while (pchInvalid != 0);

	char szNewFull[PATH_MAX];
	PrependSavesDirectory(szNew, szNewFull);

	// Get stream over temp file

	FileStream *pstm = new FileStream();
	if (pstm == NULL)
		return NULL;

	// If save is successful, szOld will be deleted and httempsave.bin
	// will be renamed to szNew

	char szTempSaveFull[PATH_MAX];
	PrependSavesDirectory("httempsave.bin", szTempSaveFull);

	if (!pstm->Init("wb", szTempSaveFull, szOldFull, szNewFull)) {
		delete pstm;
		return NULL;
	}

	return (Stream *)pstm;
}
开发者ID:aelzohry,项目名称:hostile-takeover,代码行数:48,代码来源:savegame.cpp


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