本文整理汇总了C++中Url::GetRoot方法的典型用法代码示例。如果您正苦于以下问题:C++ Url::GetRoot方法的具体用法?C++ Url::GetRoot怎么用?C++ Url::GetRoot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Url
的用法示例。
在下文中一共展示了Url::GetRoot方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LoadResource
/**
* @brief
* Loads a resource which type has to be evaluated internally
*/
bool Application::LoadResource(const String &sFilename, const String &sType)
{
bool bResult = false; // Error by default
// Clear the scene, after calling this method the scene is empty
ClearScene();
// Destroy the currently used script
DestroyScript();
// Backup the filename of the current resource
m_sResourceFilename = sFilename;
// Is there anything to load in?
if (sFilename.GetLength()) {
{ // Make the directory of the scene to load in to the current directory
// Ok, the next thing is tricky, and every solution will end up in being a hack due to lack of information.
// Within materials, meshes etc. there are usually relative paths provided, no absolute (not just true for PixelLight file formats).
// Further, those paths are usually relative to a project root resulting e.g. within a default directory layout like
// - Root
// - Data
// - Meshes
// - Materials
// For "normal" projects this is no issue because everything is usually relative to the root project directory...
// ... but this viewer must be able to pick out e.g. a mesh out of nowhere and must still be able to locate the required
// other resources like materials. So, in here, we can only work with heuristics... this can and will of course go from
// time to time horribly wrong...
// First try: Find the first "Data" occurrence with the given filename and hope that it's the project root directory
// Get filename as clean URL
Url cUrl = Url(sFilename);
cUrl.Collapse();
// Get the first part of the path, and then look for "Data"
uint32 nPathPos = 0;
String sPart = cUrl.GetFirstPath(nPathPos);
while (sPart != "Data" && sPart.GetLength())
sPart = cUrl.GetNextPath(nPathPos);
if (sPart == "Data") {
// Set the base directory of the application
SetBaseDirectory(cUrl.GetRoot() + cUrl.GetPath().GetSubstring(0, nPathPos - 5)); // -5 = Remove "Data/"
} else {
// Second try: Cut of "/Data/Scenes/" and hope that it's the project root directory.
// If it's not there, take the directory the given resource is in.
// Validate path
const String sDirectory = cUrl.CutFilename();
// Search for "/Data/Scenes/" and get the prefix of that, in case it's not there just use directly the scene directory
const int nIndex = sDirectory.IndexOf("/Data/Scenes/");
// Set the base directory of the application
SetBaseDirectory("file://" + ((nIndex >= 0) ? sDirectory.GetSubstring(0, nIndex) : sDirectory) + '/');
}
}