1/****************************************************************************************
2
3 Copyright (C) 2015 Autodesk, Inc.
4 All rights reserved.
5
6 Use of this software is subject to the terms of the Autodesk license agreement
7 provided at the time of installation or download, or which otherwise accompanies
8 this software in either electronic or hard copy form.
9
10****************************************************************************************/
11
12//! \file fbxutils.h
13#ifndef _FBXSDK_CORE_BASE_UTILITIES_H_
14#define _FBXSDK_CORE_BASE_UTILITIES_H_
15
16#include <fbxsdk/fbxsdk_def.h>
17
18#include <fbxsdk/core/base/fbxstring.h>
19#include <fbxsdk/core/base/fbxstatus.h>
20
21#include <fbxsdk/fbxsdk_nsbegin.h>
22
23#ifndef FBXSDK_ENV_WINSTORE
24 /** Retrieve the environment variable value.
25 * \return A new string containing the environment variable value. */
26 FBXSDK_DLL FbxString FbxGetEnv(const char* pEnvVar);
27
28 /** Get the application directory
29 * \return The application directory. */
30 FBXSDK_DLL FbxString FbxGetApplicationDirectory();
31#endif
32
33/** Retrieve the system temporary folder path name.
34* \return A new string containing the system temporary folder path name. */
35FBXSDK_DLL FbxString FbxGetSystemTempPath();
36
37/** Override the system temporary folder path name.
38* \param pPathUTF8 The system temporary folder to use for override. */
39FBXSDK_DLL void FbxSetSystemTempPath(const char* pPathUTF8);
40
41/** Retrieve the working directory of the system in UTF8 format.
42* \return A string that contain the current working directory of the system. */
43FBXSDK_DLL FbxString FbxGetCurrentWorkPath();
44
45/** Change the working directory of the system. */
46FBXSDK_DLL void FbxSetCurrentWorkPath(const char* pPath_UTF8);
47
48class FBXSDK_DLL FbxPathUtils
49{
50public:
51 /** Bind together a root path with a file path.
52 * \param pRootPath The root path that will get binded to the file path.
53 * \param pFilePath The file path to bind to the root path.
54 * \param pCleanPath If true, the resulting path will be cleaned via FbxPathUtils::Clean().
55 * \return Both paths binded together forming a new file path.
56 * \remark If the file path is already a full valid path, pFilePath is returned.
57 */
58 static FbxString Bind(const char* pRootPath, const char* pFilePath, bool pCleanPath=true);
59
60 /** Extract the folder name from the given file path.
61 * \param pFilePath The given file path.
62 * \return The folder name. If there isn't any '\\' or '/' in the given file path, it will return pFilePath.
63 */
64 static FbxString GetFolderName(const char* pFilePath);
65
66 /** Extract file name from the given file path.
67 * \param pFilePath The given file path.
68 * \param pWithExtension Decide the file name with extension or without extension.
69 * If it is true, return the file name with extension;
70 * if it is false, return the file name without extension.
71 */
72 static FbxString GetFileName(const char* pFilePath, bool pWithExtension=true);
73
74 /** Extract the file extension in the given file path.
75 * \param pFilePath The file path to extract the extension.
76 * \return The file extension without the '.' character.
77 * \remark Return empty string if the file path doesn't contain a valid extension.
78 */
79 static FbxString GetExtensionName(const char* pFilePath);
80
81 /** Change or append a file extension to the specified file path.
82 * \param pFilePath The file path to change the file extension
83 * \param pExtension The extension to change or append to the file path.
84 * \return The file path with the file extension changed/added.
85 * \remark If the file path doesn't end with a valid file name, pFilePath is returned.
86 */
87 static FbxString ChangeExtension(const char* pFilePath, const char* pExtension);
88
89 //! Test if the given path is relative path, if it is return true.
90 static bool IsRelative(const char* pPath);
91
92 /** Get the given new path's relative path to the given root path.
93 * \param pRootPath The given root path
94 * \param pNewPath The given new path. If it is only file name, the default directory is work directory.
95 * \return The relative path.
96 * \remarks If the given two paths have the same drive, the function will turn '\\' in the relative path to '/'.
97 */
98 static FbxString GetRelativePath(const char* pRootPath, const char* pNewPath);
99
100 //! Get the given new path's relative path to the given root path.
101 static FbxString GetRelativeFilePath(const char* pRootPath, const char* pNewFilePath);
102
103 /** Get the full path of given path (if the given path is relative path,
104 * it will take current directory as default root path.)
105 */
106 static FbxString Resolve(const char* pRelPath);
107
108 //! Clean the redundant and useless denotations in given path name.
109 static FbxString Clean(const char* pPath);
110
111 /** Generate full safe file path name you can use to create new file.
112 * \param pFolder The folder where the file name should be attempted to be created.
113 * \param pPrefix The prefix of generated file name.
114 * \return A valid file path that can safely be used to create a new file.
115 */
116 static FbxString GenerateFileName(const char* pFolder, const char* pPrefix);
117
118 /** Verify if the specified folder path exist.
119 * \param pFolderPathUTF8 The folder path to test its existance.
120 * \return True if the folder path exist, false otherwise.
121 * \remark This function work for relative paths. It will search from the current work path. */
122 static bool Exist(const char* pFolderPathUTF8);
123
124 /** Create the specified folder path if it doesn't exist.
125 * \param pFolderPathUTF8 The folder path to create, in UTF8 encoding.
126 * \return True if folder path already exist, or if it was successfully created, false otherwise.
127 * \remark This function will create multiple folders if needed, and it also work for relative paths. */
128 static bool Create(const char* pFolderPathUTF8);
129
130 /** Delete the specified folder path and all its content recursively.
131 * \param pFolderPathUTF8 The folder path to delete, in UTF8 encoding.
132 * \return True if folder path was successfully deleted, false otherwise.
133 * \remark This function work for relative paths. It will search from the current work path. */
134 static bool Delete(const char* pFolderPathUTF8);
135
136#ifndef FBXSDK_ENV_WINSTORE
137 /** Verify if the folder contains items or not.
138 * \param pFolderPath_UTF8 The folder path to test if it contains items.
139 * \return True if the folder contain any kind of entry type. */
140 static bool IsEmpty(const char* pFolderPath_UTF8);
141#endif
142};
143
144/** Global accessor to an FbxStatus object.
145* This object is not used internally by the FBX SDK. It is provided for convenience and its usage is shown in the custom reader/writers samples. */
146class FBXSDK_DLL FbxStatusGlobal
147{
148public:
149 static FbxStatus& GetRef()
150 {
151 if( !mStatusPtr )
152 {
153 mStatusPtr = FbxNew<FbxStatus>();
154 }
155 return *mStatusPtr;
156 }
157
158private:
159 FbxStatusGlobal(){ mStatusPtr = NULL; }
160 ~FbxStatusGlobal(){ FbxDelete<FbxStatus>(mStatusPtr); }
161 static FbxStatusGlobal sgFbxStatusGlobal;
162 static FbxStatus* mStatusPtr;
163};
164
165
166#include <fbxsdk/fbxsdk_nsend.h>
167
168#endif /* _FBXSDK_CORE_BASE_UTILITIES_H_ */
169