コード例 #1
0
ファイル: UtilStreams.cpp プロジェクト: jeeb/kirikiri2
tTVPLocalTempStorageHolder::tTVPLocalTempStorageHolder(const ttstr & name)
{
	// name must be normalized !!!

	FileMustBeDeleted = false;
	FolderMustBeDeleted = false;
	LocalName = TVPGetLocallyAccessibleName(name);
	if(LocalName.IsEmpty())
	{
		// file must be copied to local filesystem

		// note that the basename is much more important than the directory
		// which the file is to be in, so we create a temporary folder and
		// store the file in it.

		LocalFolder = TVPGetTemporaryName();
		LocalName = LocalFolder + TJS_W("/") + TVPExtractStorageName(name);
		TVPCreateFolders(LocalFolder); // create temporary folder
		FolderMustBeDeleted = true;
		FileMustBeDeleted = true;

		try
		{
			// copy to local file
			tTVPStreamHolder src(name);
			tTVPStreamHolder dest(LocalName, TJS_BS_WRITE);
			tjs_uint8 * buffer = new tjs_uint8[TVP_LOCAL_TEMP_COPY_BLOCK_SIZE];
			try
			{
				tjs_uint read;
				while(true)
				{
					read = src->Read(buffer, TVP_LOCAL_TEMP_COPY_BLOCK_SIZE);
					if(read == 0) break;
					dest->WriteBuffer(buffer, read);
				}
			}
			catch(...)
			{
				delete [] buffer;
				throw;
			}
			delete [] buffer;
		}
		catch(...)
		{
			if(FileMustBeDeleted) TVPRemoveFile(LocalName);
			if(FolderMustBeDeleted) TVPRemoveFolder(LocalFolder);
			throw;
		}
	}
}
コード例 #2
0
ファイル: SusieArchive.cpp プロジェクト: John-He-928/krkrz
//---------------------------------------------------------------------------
// TVPCheckSusieSupport : checks which plugin supports specified archive
//---------------------------------------------------------------------------
tTVPSusieArchivePlugin * TVPCheckSusieSupport(const ttstr &name, std::wstring &a_localname)
{
	if(TVPSusiePluginVector.size() == 0) return NULL;

	ttstr localname = TVPGetLocallyAccessibleName(name);
	tTVPLocalFileStream stream(name, localname, TJS_BS_READ);

	if(localname.GetLen() == 0) return NULL; // only local filesystem stream is supported

	a_localname = localname.AsStdString();

	std::vector<tTVPSusieArchivePlugin*>::iterator i;
	for(i = TVPSusiePluginVector.end() - 1; i >= TVPSusiePluginVector.begin(); i--)
	{
		stream.SetPosition(0);
		if((*i)->CheckSupported(&stream, localname.AsNarrowStdString()))
			return *i;
	}

	return NULL;
}