36 #include <osgDB/FileUtils> 37 #include <osgDB/FileNameUtils> 40 #include <AvailabilityMacros.h> 41 #include <Foundation/Foundation.h> 63 if (SUCCEEDED(SHGetFolderPathA(
nullptr, CSIDL_PROFILE,
nullptr, 0, path))) {
67 int maxSize = sysconf(_SC_GETPW_R_SIZE_MAX);
68 char* buffer =
new char[maxSize];
69 struct passwd pw, *resultOut = NULL;
70 int rc = getpwuid_r(getuid(), &pw, buffer, maxSize, &resultOut);
71 if (rc == 0 && resultOut != NULL)
199 result = GetBundleResourcesPath();
230 if (SUCCEEDED(SHGetFolderPathA(
nullptr, CSIDL_MYDOCUMENTS,
nullptr, 0, path)))
244 OpenThreads::ScopedLock<OpenThreads::Mutex> lock(gDatapathMutex);
246 std::string modpath = pathList;
247 std::string::size_type pathLength = pathList.size();
248 for (std::string::size_type i = 0; i < pathLength; ++i)
257 if (modpath.at(i) ==
':' && (i + 1 >= pathLength || modpath.at(i + 1) !=
'\\'))
262 catch (std::out_of_range &myexcept)
264 LOG_W(myexcept.what());
267 if (modpath[i] ==
';')
273 osgDB::setDataFilePathList(modpath);
279 OpenThreads::ScopedLock<OpenThreads::Mutex> lock(gDatapathMutex);
281 osgDB::FilePathList pathList = osgDB::getDataFilePathList();
283 std::string pathString =
"";
285 using StringDeque = std::deque<std::string>;
286 for (StringDeque::iterator itr = pathList.begin(); itr != pathList.end(); ++itr)
290 StringDeque::iterator next = itr + 1;
if (next != pathList.end())
306 OpenThreads::ScopedLock<OpenThreads::Mutex> lock(gDatapathMutex);
308 std::string filePath = osgDB::findDataFile(fileName, osgDB::CASE_INSENSITIVE);
313 if (!filePath.empty())
315 filePath = osgDB::getRealPath(filePath);
323 std::string
FindFile(
const std::string& fileName, std::vector<std::string> pathList,
bool caseInsensitive)
325 std::vector<std::string>::const_iterator itor;
329 for (itor = pathList.begin(); itor != pathList.end(); ++itor)
333 if (path[path.length() - 1] ==
'/' || path[path.length() - 1] ==
'\\')
334 path = path.substr(0, path.length() - 1);
343 return std::string();
350 const size_t bufferSize = 32767;
351 TCHAR buffer[bufferSize], buffer2[bufferSize];
352 size_t sizeOut1 = GetEnvironmentVariable(env.c_str(), buffer, bufferSize);
353 size_t sizeOut2 = ExpandEnvironmentStrings(buffer, buffer2, bufferSize);
354 if (sizeOut1 <= bufferSize && sizeOut2 <= bufferSize && sizeOut1 > 0 && sizeOut2 > 0)
359 char* ptr = getenv(env.c_str());
362 return std::string(ptr);
366 return std::string(
"./");
375 SetEnvironmentVariable(name.c_str(), value.c_str());
376 _putenv_s(name.c_str(), value.c_str());
378 setenv(name.c_str(), value.c_str(),
true);
383 std::string GetBundleResourcesPath()
392 NSAutoreleasePool* mypool = [[NSAutoreleasePool alloc] init];
395 NSString* resourcePathNS = [[NSBundle mainBundle] resourcePath];
398 std::string result = std::string([resourcePathNS UTF8String]);
406 std::string GetBundlePlugInsPath()
414 NSAutoreleasePool* mypool = [[NSAutoreleasePool alloc] init];
417 NSString* resourcePathNS = [[NSBundle mainBundle] builtInPlugInsPath];
420 std::string result = std::string([resourcePathNS UTF8String]);
428 std::string GetBundlePath()
436 NSAutoreleasePool* mypool = [[NSAutoreleasePool alloc] init];
439 NSString* resourcePathNS = [[NSBundle mainBundle] bundlePath];
442 std::string result = std::string([resourcePathNS UTF8String]);
452 static std::string osxPSN(
"-psn_");
453 for (
int i = 0; i < argc; ++i)
455 if (std::string(argv[i]).compare(0, osxPSN.length(), osxPSN) == 0)
457 for (
int j = i; j < argc; ++j)
465 argv[j] = argv[j + 1];
477 if (getenv(env.c_str()))
static const std::string TEXTURES_PATH("/Textures")
TR_UTIL_EXPORT std::string GetUserGUIPath()
Gets user graphical user interface path.
TR_UTIL_EXPORT std::string GetSkeletalMeshesPath()
Gets skeletal meshes path.
static const std::string SHADERS_PATH("/Shaders")
TR_UTIL_EXPORT std::string GetSoundsPath()
Gets sounds path.
This is the exception class used throughout the engine.
TR_UTIL_EXPORT std::string GetDataPath()
Get the TR Data file path.
static const std::string DEFAULT_TR_FOLDER("/.trueReality")
TR_UTIL_EXPORT std::string GetDataFilePathList()
Get the list of data file paths.
TR_UTIL_EXPORT void SetDataFilePathList(const std::string &pathList)
Set the list of data file paths.
TR_UTIL_EXPORT std::string GetRootPath()
Get the root path to the engine (equivalent to the TR_ROOT environment) If the TR_ROOT environment is...
Singleton class implementing basic file operations.
const struct FileInfo GetFileInfo(const std::string &strFile, bool caseInsensitive=false) const
struct holding information about a file.
TR_UTIL_EXPORT std::string GetUserStaticMeshesPath()
Gets user static meshes path.
TR_UTIL_EXPORT std::string GetShadersPath()
Gets shaders path.
static const std::string STR_BLANK("")
Constant value for a blank String.
TR_UTIL_EXPORT void CreateDataPathTree()
Creates all the folders in the Data (TR_DATA) folder, that includes Maps, GUI, Shaders, StaticMeshes, etc etc.
TR_UTIL_EXPORT void CreateUserDataPathTree()
Creates all the folders in the Data (TR_USER_DATA) folder, that includes Maps, GUI, Shaders, StaticMeshes, etc etc.
TR_UTIL_EXPORT std::string GetUserDataPath()
Get the folder where TR will save and store User data files It is MyDocuments on Windows and the same...
#define LOG_W(msg)
Log a WARNING message.
static const std::string GUI_PATH("/GUI")
static const std::string TR_LOG_PATH
Environmental Variable holds the path of the custom Log folder.
TR_UTIL_EXPORT std::string GetGUIPath()
Gets graphical user interface path.
static OpenThreads::Mutex gDatapathMutex
void LogException(trUtil::Logging::LogLevel level=trUtil::Logging::LogLevel::LOG_ERROR) const
Logs the exception to the default logger.
TR_UTIL_EXPORT bool IsEnvironment(const std::string &env)
Is the supplied environment variable defined?
TR_UTIL_EXPORT std::string GetUserConfigPath()
Gets user configuration path.
TR_UTIL_EXPORT std::string GetStaticMeshesPath()
Gets static meshes path.
TR_UTIL_EXPORT std::string GetEnvironment(const std::string &env)
Convenience method to get the supplied environment variable.
TR_UTIL_EXPORT std::string GetTerrainsPath()
Gets terrain path.
static const std::string STATIC_MESHES_PATH("/StaticMeshes")
TR_UTIL_EXPORT std::string GetConfigPath()
Gets configuration path.
FileType fileType
The enum value specifying the type of file.
static const std::string TR_USER_DATA
Environmental Variable that points to the User Data folder of the engine The Data folder should have ...
TR_UTIL_EXPORT std::string GetUserParticlesPath()
Gets user particles path.
TR_UTIL_EXPORT std::string GetUserSoundsPath()
Gets user sounds path.
static std::string mDataPath
TR_UTIL_EXPORT std::string GetLogPath()
Get the folder where TR will save and store the log files It is the same as GetUserDataPath() by defa...
static const std::string SOUNDS_PATH("/Sounds")
static FileUtils & GetInstance()
Character separating the parts of a file path.
void RemovePSNCommandLineOption(int &, char **&)
Removes the psn command line option.
TR_UTIL_EXPORT std::string GetParticlesPath()
Gets particles path.
TR_UTIL_EXPORT std::string GetUserTexturesPath()
Gets user textures path.
static const std::string TR_DATA
Environmental Variable that points to the Data folder of the engine The Data folder should have gener...
TR_UTIL_EXPORT void SetEnvironment(const std::string &name, const std::string &value)
Sets an environment variable.
std::string fileName
the file name with full path
static const std::string PARTICLES_PATH("/Particles")
TR_UTIL_EXPORT void SetDataPath(std::string &path)
Overwrites the Data path.
static const std::string TERRAINS_PATH("/Terrains")
TR_UTIL_EXPORT std::string GetUserHomeDirectory()
Get the USER Home directory.
static const std::string DATA_PATH_DEFAULT("/Data")
void MakeDirectoryEX(std::string strDir)
A more powerful version of the standard mkdir.
TR_UTIL_EXPORT std::string GetTexturesPath()
Gets textures path.
static const char PATH_SEPARATOR
static const std::string TR_ROOT
Environmental Variable that points to the Root folder of the engine.
static const std::string SKELETAL_MESHES_PATH("/SkeletalMeshes")
TR_UTIL_EXPORT std::string GetUserShadersPath()
Gets user shaders path.
TR_UTIL_EXPORT std::string FindFile(const std::string &fileName)
Searches for a file in the list of paths found by calling GetDataFilePathList()
TR_UTIL_EXPORT void CreateDataPathTrees()
Convenience function that calls CreateDataPathTree() and CreateUserDataPathTree();.
TR_UTIL_EXPORT std::string GetUserTerrainsPath()
Gets user terrain path.
TR_UTIL_EXPORT std::string GetUserSkeletalMeshesPath()
Gets user skeletal meshes path.
static const std::string CONFIG_PATH("/Config")