Пример #1
0
void PainterTest_App::OpenFileSpec(const ZFileSpec& inFileSpec)
	{
#if 0 // debugging. -ec 06.02.23
	ZAlert::sCautionAlert("Debugging OpenFileSpec()",
		"inFileSpec = '" + inFileSpec.AsString() + "'",
		"blah blah blah",
		60 * ZTicks::sPerSecond());
#endif

	// in this scenario, if inFileSpec has a PainterTest_Window that is already open for it, then simply bring that window to the front.
	// note that if the file described by inFileSpec has been modified, those modifications will *not* be reflected in window Ð and will
	// be lost if window is saved. -ec 06.02.21
	if (PainterTest_Window* theWindow = this->GetPainterWindow(inFileSpec))
		{
		theWindow->BringFront();
		theWindow->GetWindowLock().Release();
		return;
		}

	if (ZRef<ZStreamerRPos> theStreamerRPos = inFileSpec.OpenRPos(false))
		{
		string format;
		if (ZRef<NPaintDataRep> thePaintDataRep = sRead_NPaintDataRep(theStreamerRPos->GetStreamRPos(), format))
			{
			PainterTest_Window* theWindow = new PainterTest_Window(this, fAsset.GetChild("Windows").GetChild("Painter"), fPaintState, thePaintDataRep, inFileSpec, format);
			theWindow->Center();
			theWindow->BringFront();
			theWindow->GetWindowLock().Release();
			}
		}
	}
Пример #2
0
ZRef<ZStreamerRPos> ZAssetRep_FS::OpenRPos()
	{
	if (fData)
		return new StreamerMemory(this, fData, fDataSize);

	if (fComps.empty())
		return fSpec.OpenRPos();

	string leaf = fComps.back();
	if (leaf == "!binary" || leaf == "!string" || leaf == "!stringtable")
		{
		ZFileSpec branchSpec = fSpec.Trail(ZTrail(fComps.begin(), fComps.end() - 1));
		if (branchSpec.IsFile())
			{
			// And the branch is a file, so we pretend that our specially named leaf exists.
			return branchSpec.OpenRPos();
			}
		}

	return fSpec.Trail(ZTrail(fComps.begin(), fComps.end())).OpenRPos();
	}
Пример #3
0
/**
\fn ZRef<ZAssetTree> ZUtil_Asset::sGetAssetTreeFromFileSpec(const ZFileSpec&)

\brief Return a new ZAssetTree instance referencing the zao data in the
file referenced by \a iFileSpec.

It is important to recognize that each invocation of this method creates
a \em new instance of ZAssetTree. It may therefore load or map all the data contained in
the tree.  Your application will probably call this method indirectly by calling
ZUtil_Asset::sGetAssetRootFromFileSpec, but it should do so only once, keeping the asset
in a global static or in an instance variable of your application object (or equivalent).

\sa ZUtil_Asset::sGetAssetTreeNamesFromExecutable
*/
ZRef<ZAssetTree> ZUtil_Asset::sGetAssetTreeFromFileSpec(const ZFileSpec& iFileSpec)
	{
	ZRef<ZAssetTree> theAssetTree;

#if ZCONFIG_SPI_Enabled(Carbon)

	try
		{
		if (ZRef<ZStreamerRPos> theStreamer = iFileSpec.OpenRPos())
			theAssetTree = new ZAssetTree_Std_Streamer(new ZStreamerRPos_PageBuffered(8, 1024, theStreamer));
		}
	catch (...)
		{}

#elif ZCONFIG_SPI_Enabled(Win)

	try
		{
		string thePath = iFileSpec.AsString_Native();
		HANDLE theFileHANDLE;
		if (ZUtil_Win::sUseWAPI())
			{
			theFileHANDLE = ::CreateFileW(ZUnicode::sAsUTF16(thePath).c_str(), // the path
											GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
											nullptr, // No security attributes
											OPEN_EXISTING, // Open the file only if it exists
											FILE_ATTRIBUTE_NORMAL, // No special attributes
											nullptr);// No template file
			}
		else
			{
			theFileHANDLE = ::CreateFileA(thePath.c_str(), // the path
											GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
											nullptr, // No security attributes
											OPEN_EXISTING, // Open the file only if it exists
											FILE_ATTRIBUTE_NORMAL, // No special attributes
											nullptr);// No template file
			}

		if (theFileHANDLE != INVALID_HANDLE_VALUE)
			{
			DWORD sizeHigh;	
			DWORD sizeLow = ::GetFileSize(theFileHANDLE, &sizeHigh);
			theAssetTree = new ZAssetTree_Win_MemoryMapped(theFileHANDLE, true, 0, sizeLow);
			}
		}
	catch (...)
		{}

#elif ZCONFIG_SPI_Enabled(POSIX)

	try
		{
		int theFD = ::open(iFileSpec.AsString_Native().c_str(), O_RDONLY);
		if (theFD >= 0)
			{
			int theLength = ::lseek(theFD, 0, SEEK_END);
			theAssetTree = new ZAssetTree_POSIX_MemoryMapped(theFD, true, 0, theLength);
			}
		}
	catch (...)
		{}

#endif

	if (!theAssetTree)
		{
		// We failed to get the asset tree instantiated, either because we just fell through
		// to here directly (BeOS), or because an exception occurred.
		if (ZRef<ZStreamerRPos> theStreamer = iFileSpec.OpenRPos())
			{
			try
				{
				theAssetTree = new ZAssetTree_Std_Streamer(theStreamer);
				}
			catch (...)
				{}
			}
		}

	return theAssetTree;
	}