Example #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();
			}
		}
	}
Example #2
0
ZQ<ZFileSpec> sQEnsureBranch(const ZFileSpec& iFS)
	{
	if (iFS.IsDir())
		return iFS;
	
	if (ZQ<ZFileSpec> newParentQ = sQEnsureBranch(iFS.Parent()))
		{
		if (const ZFileSpec theFS = newParentQ->Child(iFS.Name()).CreateDir())
			return theFS;
		}

	return null;
	}
Example #3
0
void ZASParser::ParseHandler_Prettify::EnterInclude(const ZFileSpec& iFileSpec)
	{
	sWriteIndent(fStrimW, fIndent);
	fStrimW.Write("// -----> enter file \"");
	string fileAsString = iFileSpec.AsString();
	sWriteEscapifiedString(fStrimW, fileAsString);
	fStrimW.Write("\"\n");

	fIncludes.push_back(fileAsString);
	}
Example #4
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();
	}
Example #5
0
// Utility function in place of ZFileSpec::operator==(const ZFileSpec& iOther).
static bool sFileSpec_Equal(const ZFileSpec& iFS1, const ZFileSpec& iFS2)
	{
	return ZUnicode::sToLower(iFS1.AsString()) == ZUnicode::sToLower(iFS2.AsString());
	}
Example #6
0
bool sDeleteTree(const ZFileSpec& iFS)
	{
	for (ZFileIter iter = iFS; iter; iter.Advance())
		sDeleteTree(iter.Current());
	return iFS.Delete();
	}
Example #7
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;
	}
Example #8
0
ZRef<ZAssetRep> ZAssetRep_FS::ResolvePath(const char* iPath)
	{
	const char* pathStart = iPath;

	if (pathStart == nullptr || pathStart[0] == 0)
		{
		// An empty path means us.
		return this;
		}

	vector<string> newComps;

	if (pathStart[0] == '|')
		{
		// A | prefix means we want our root, which is fSpec with an empty component vector.
		++pathStart;
		}
	else
		{
		newComps = fComps;
		}
		
	const char* iter = pathStart;
	for (;;)
		{		
		switch (*iter)
			{
			case 0:
			case '^':
			case '|':
				{
				if (iter > pathStart)
					newComps.push_back(string(pathStart, iter - pathStart));
				pathStart = iter + 1;
		
				if (*iter == '^')
					{
					if (newComps.empty())
						{
						// We're trying to get the parent of the root,
						// which is an illegal asset reference.
						return ZRef<ZAssetRep>();
						}
					newComps.pop_back();
					}
				}
			}

		if (*iter == 0)
			break;

		++iter;
		}

	if (newComps.empty())
		{
		if (fSpec.Exists())
			return new ZAssetRep_FS(fSpec);
		return ZRef<ZAssetRep>();
		}

	ZFileSpec branchSpec = fSpec.Trail(ZTrail(newComps.begin(), newComps.end() - 1));
	if (!branchSpec.Exists())
		{
		// The branch doesn't exist, so neither can the full path.
		return ZRef<ZAssetRep>();
		}

	// We know the branch exists.
	string leaf = newComps.back();
	if (leaf == "!binary" || leaf == "!string" || leaf == "!stringtable")
		{
		// We've got a leaf with a special name.
		if (branchSpec.IsFile())
			{
			// And the branch is a file, so we pretend that our specially named leaf exists.
			return new ZAssetRep_FS(fSpec, newComps);
			}
		}

	if (fSpec.Trail(ZTrail(newComps.begin(), newComps.end())).Exists())
		{
		// Our spec plus the new components is an extant entity.
		return new ZAssetRep_FS(fSpec, newComps);
		}

	return ZRef<ZAssetRep>();
	}