25#include "../../kernel.hpp"
26#include "../utils/datetimetools.hpp"
38 sValidExtensions =
";.dat;.txt;.tmp;.def;.nscr;.png;.gif;.eps;.bps;.svg;.tex;.labx;.csv;.cache;.ndat;.nprc;.nlng;.nlyt;.log;.plugins;.hlpidx;.nhlp;.jdx;.dx;.jcm;.ibw;.ndb;.ods;.jpg;.bmp;.tga;.bps;.prc;.obj;.xyz;.stl;.json;.off;.pdf;.wav;.wave;.xls;.xlsx;.chm;.h;.hpp;.cxx;.cpp;.c;.m;.tif;.tiff;.ini;.xml;.yaml;.yml;.nsi;";
40 for (
int i = 0; i < 7; i++)
62 for (
int i = 0; i < 7; i++)
87 if (sFilePath[0] ==
'<')
89 for (
int i = 0; i < 7; i++)
93 if (sFilePath[
sTokens[i][0].length()] !=
'/')
94 sFilePath =
sTokens[i][1] +
"/" + sFilePath.substr(
sTokens[i][0].length());
96 sFilePath =
sTokens[i][1] + sFilePath.substr(
sTokens[i][0].length());
102 if (sFilePath.substr(0,6) ==
"<this>")
104 if (sFilePath[6] !=
'/')
105 sFilePath =
sTokens[0][1] +
"/" + sFilePath.substr(6);
107 sFilePath =
sTokens[0][1] + sFilePath.substr(6);
114 const std::string sINVALID_CHARS =
"\"#%&<>|";
116 for (
unsigned int i = 0; i < sFilePath.length(); i++)
118 if (sFilePath[i] == (
char)142)
120 else if (sFilePath[i] == (
char)132)
122 else if (sFilePath[i] == (
char)153)
124 else if (sFilePath[i] == (
char)148)
126 else if (sFilePath[i] == (
char)154)
128 else if (sFilePath[i] == (
char)129)
130 else if (sFilePath[i] == (
char)225)
132 else if (sFilePath[i] ==
'~')
134 NumeReKernel::issueWarning(
"INTERNAL ISSUE: Replaced a tilde character in \"" + sFilePath +
"\" with a slash. This should not happen. Consider informing the development team about this warning and how to recreate it. Thank you.");
137 else if (sINVALID_CHARS.find(sFilePath[i]) != std::string::npos)
139 NumeReKernel::issueWarning(
"Replaced an invalid character in \"" + sFilePath +
"\" with an underscore. This should not happen. Consider informing the development team about this warning and how to recreate it. Thank you.");
161 if (_sFileName.find_first_of(
"*?") != std::string::npos)
163 WIN32_FIND_DATA FindFileData;
164 HANDLE hFind = INVALID_HANDLE_VALUE;
165 hFind = FindFirstFile(_sFileName.c_str(), &FindFileData);
166 std::string sNewFileName =
"";
170 if (!
isFile && FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
172 sNewFileName = FindFileData.cFileName;
175 else if (
isFile && FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
178 sNewFileName = FindFileData.cFileName;
180 if (sNewFileName.length() > 4
181 && sNewFileName.find(
'.') != std::string::npos
182 && (!checkExtension ||
sValidExtensions.find(
";"+
toLowerCase(sNewFileName.substr(sNewFileName.rfind(
'.')))+
";") != std::string::npos))
184 else if (sNewFileName.find(
'.') != std::string::npos)
187 sNewFileName +=
".*";
189 while (FindNextFile(hFind, &FindFileData) != 0);
193 if (sNewFileName.length() > 4)
195 std::string sPathTemp = _sFileName;
197 if (sPathTemp.rfind(
'/') != std::string::npos && sPathTemp.rfind(
'\\') != std::string::npos)
199 if (sPathTemp.rfind(
'/') < sPathTemp.rfind(
'\\'))
200 sPathTemp = sPathTemp.substr(0, sPathTemp.rfind(
'\\'));
202 sPathTemp = sPathTemp.substr(0, sPathTemp.rfind(
'/'));
204 else if (sPathTemp.rfind(
'/') != std::string::npos)
206 sPathTemp = sPathTemp.substr(0, sPathTemp.rfind(
'/'));
208 else if (sPathTemp.rfind(
'\\') != std::string::npos)
210 sPathTemp = sPathTemp.substr(0, sPathTemp.rfind(
'\\'));
217 if (sPathTemp.length())
218 _sFileName = sPathTemp +
"/" + sNewFileName;
220 _sFileName = sNewFileName;
238 if (CreateDirectory(_sPath.c_str(),
nullptr))
245 if (GetLastError() == ERROR_PATH_NOT_FOUND)
247 for (
unsigned int i = 0; i < _sPath.length(); i++)
249 if (_sPath[i] ==
'/' || _sPath[i] ==
'\\')
251 CreateDirectory(_sPath.substr(0,i).c_str(),
nullptr);
255 CreateDirectory(_sPath.c_str(),
nullptr);
259 if (GetLastError() == ERROR_ALREADY_EXISTS)
282 std::string sValid =
"";
285 _sFileName =
cleanPath(_sFileName, doCleanPath);
289 unsigned int nPos = _sFileName.find_last_of(
':');
293 if (nPos == std::string::npos)
295 if (_sFileName.substr(0, 2) !=
"//")
296 _sFileName =
sPath.substr(1,
sPath.length()-2) +
"/" + _sFileName;
303 nPos = _sFileName.find_last_of(
".");
310 if (nPos == std::string::npos
311 || (nPos == 0 || nPos == 1)
312 || (_sFileName.find(
'/', nPos) != std::string::npos || _sFileName.find(
'\\', nPos) != std::string::npos))
313 sValid = _sFileName + sExtension;
314 else if (checkExtension && sExtension.length())
318 sValid = _sFileName.substr(nPos);
322 if (sValid.back() ==
'"')
335 sValid = _sFileName.substr(0,nPos);
348 for (
unsigned int i = 0; i < sValid.length(); i++)
350 if (sValid[i] ==
'\\')
371 _sFileName =
cleanPath(_sFileName, doCleanPath);
375 unsigned int nPos = _sFileName.find_last_of(
':');
379 if (nPos == std::string::npos)
381 if (_sFileName.substr(0,2) !=
"//")
382 _sFileName =
sPath.substr(1,
sPath.length()-2) +
"/" + _sFileName;
390 if (_sFileName.find_first_of(
"*?") != std::string::npos)
394 for (
unsigned int i = 0; i < _sFileName.length(); i++)
396 if (_sFileName[i] ==
'\\')
405 if (appendTrailingSeparator && _sFileName.back() !=
'/')
407 else if (!appendTrailingSeparator && _sFileName.back() ==
'/')
408 _sFileName.pop_back();
426 std::string sValid =
ValidFileName(_sFileName, sExtension, sExtension.length());
456 if (
sPath.find(
'<') != std::string::npos)
458 for (
unsigned int i = 0; i < 6; i++)
465 if (
sPath.find(
'~') != std::string::npos)
467 for (
unsigned int i = 0; i <
sPath.length(); i++)
474 while (
sPath.find(
'\\') != std::string::npos)
477 if (
sPath.find(
':') == std::string::npos)
479 if (
sPath.length() > 3 &&
sPath.substr(0,3) !=
"..\\" &&
sPath.substr(0,3) !=
"../" &&
sPath.substr(0,2) !=
".\\" &&
sPath.substr(0,2) !=
"./")
481 else if (
sPath.length() > 2 && (
sPath.substr(0,2) ==
".\\" ||
sPath.substr(0,2) ==
"./"))
483 else if (
sPath.length() > 3 && (
sPath.substr(0,3) ==
"..\\" ||
sPath.substr(0,3) ==
"../"))
485 while (
sPath.length() > 3 && (
sPath.substr(0,3) ==
"..\\" ||
sPath.substr(0,3) ==
"../"))
534 std::string sRevisionsPath =
sPath.substr(1,
sPath.length()-2) +
"/.revisions";
536 SetFileAttributesA(sRevisionsPath.c_str(), FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_NOT_CONTENT_INDEXED);
568 std::vector<std::string> vFileParts;
570 std::string sValidName = sFilePath;
579 if (sValidName[1] ==
':')
581 vFileParts.push_back(sValidName.substr(0, 1));
584 if (sValidName.length() > 2)
585 vFileParts.push_back(sValidName.substr(3, sValidName.rfind(
'/') - 3));
589 vFileParts.push_back(
"");
590 vFileParts.push_back(sValidName.substr(0, sValidName.rfind(
'/')));
594 if (sValidName.find(
'.') != std::string::npos && sValidName.rfind(
'/')+1 < sValidName.rfind(
'.'))
597 vFileParts.push_back(sValidName.substr(sValidName.rfind(
'/')+1, sValidName.rfind(
'.') - sValidName.rfind(
'/')-1));
598 vFileParts.push_back(sValidName.substr(sValidName.rfind(
'.')+1));
603 vFileParts.push_back(sValidName.substr(sValidName.rfind(
'/')+1));
604 vFileParts.push_back(
"");
626 timeStamp.
m_hours = std::chrono::hours(stUTC.wHour);
627 timeStamp.
m_minutes = std::chrono::minutes(stUTC.wMinute);
628 timeStamp.
m_seconds = std::chrono::seconds(stUTC.wSecond);
645 std::vector<std::string> vFileParts =
getFileParts(sFilePath);
648 fInfo.
drive = vFileParts[0];
649 fInfo.
path = vFileParts[1];
650 fInfo.
name = vFileParts[2];
651 fInfo.
ext = vFileParts[3];
653 WIN32_FIND_DATA FindFileData;
654 HANDLE hFind = INVALID_HANDLE_VALUE;
657 hFind = FindFirstFile(
ValidFileName(sFilePath,
".dat",
false).c_str(), &FindFileData);
659 hFind = FindFirstFile(
ValidFolderName(sFilePath,
true,
false).c_str(), &FindFileData);
663 if (hFind != INVALID_HANDLE_VALUE)
666 LARGE_INTEGER fileSize;
667 fileSize.LowPart = FindFileData.nFileSizeLow;
668 fileSize.HighPart = FindFileData.nFileSizeHigh;
669 fInfo.
filesize = size_t(fileSize.QuadPart);
672 FileTimeToSystemTime(&FindFileData.ftCreationTime, &stUTC);
674 FileTimeToSystemTime(&FindFileData.ftLastWriteTime, &stUTC);
696 for (
int i = 0; i < 7; i++)
698 sTokens[i][0] = _sTokens.substr(0,_sTokens.find(
'='));
699 sTokens[i][1] = _sTokens.substr(_sTokens.find(
'=')+1, _sTokens.find(
';')-1-_sTokens.find(
'='));
700 _sTokens = _sTokens.substr(_sTokens.find(
';')+1);
702 if (!_sTokens.length())
721 if (_sPath.rfind(
'.') != std::string::npos)
723 std::string sExt = _sPath.substr(_sPath.rfind(
'.'));
728 if (sExt.find(
'/') != std::string::npos || sExt.find(
'\\') != std::string::npos)
731 if (sExt.length() < 6 || sExt ==
".*")
734 if (_sPath.find_last_of(
"\\/", _sPath.length() - sExt.length()) != std::string::npos)
std::string toLowerCase(const std::string &)
Converts uppercase to lowercase letters.
This class implements the basic input/ output file system and provides functionalities to work with f...
std::string ValidFolderName(std::string _sFileName, bool doCleanPath=true, bool appendTrailingSeparator=true) const
This member function evaluates, whether the passed foldername is a valid foldername.
std::string ValidizeAndPrepareName(const std::string &_sFileName, const std::string &sExtension=".dat") const
This member function validizes the passed file name and creates the needed folders on-the-fly.
std::string cleanPath(std::string sFilePath, bool checkInvalidChars) const
This function cleans the passed file path, i.e. replaces the character encoding of umlauts,...
std::string sExecutablePath
FileSystem & assign(const FileSystem &_fSys)
Assignment member function to copy the settings from another FileSystem instance.
std::vector< std::string > getFileParts(const std::string &sFilePath) const
This member function separates all path parts into single strings: the drive letter,...
void initializeFromKernel()
Member function to remote-initialize the class from the kernel. Cannot be used during kernel start-up...
FileInfo getFileInfo(const std::string &sFilePath) const
Return the file information about the passed file path.
std::string getPath() const
Returns the default path of this FileSystem instance.
void resolveWildCards(std::string &_sFileName, bool isFile, bool checkExtension=true) const
This member function resolves all wildcards, which may be found in the passed filename.
std::string ValidFileName(std::string _sFileName, const std::string sExtension=".dat", bool checkExtension=true, bool doCleanPath=true) const
This member function evaluates, whether the passed filename is a valid filename. One may supply a pre...
FileSystem()
Default constructor.
void setTokens(std::string _sTokens)
This member function may be used to update the path placeholders of the current FileSystem instance.
void createRevisionsFolder()
This member function creates the hidden revisions folders for the version control system.
std::string sTokens[7][2]
std::string sValidExtensions
bool isFile(const std::string &_sPath) const
This function determines, whether a path name indicates a file or a folder.
int createFolders(const std::string &_sPath) const
This member function creates all missing directories in the passed path.
int setPath(std::string _sPath, bool bMkDir, std::string _sExePath)
This member function may be used to set the preferred file path of the current FileSystem instance.
This class provides the interface to the core of NumeRe. It provides all functionalities,...
static NumeReKernel * getInstance()
This static member function returns a a pointer to the singleton instance of the kernel.
FileSystem & getFileSystem()
static void issueWarning(std::string sWarningMessage)
This static function may be used to issue a warning to the user. The warning will be printed by the t...
Common exception class for all exceptions thrown in NumeRe.
static bool checkInvalidChars(std::string sPathname)
This function checks for the invalid chars that can not appear in a valid directory name.
static double windowSystemTimeToDouble(SYSTEMTIME stUTC)
Static function to convert Windows UTC system time to a double.
std::string removeQuotationMarks(const std::string &sString)
This function simply removes the surrounding quotation marks.
std::string fromSystemCodePage(std::string)
Transforms the system code page to the internal one.
std::string replacePathSeparator(const std::string &)
This function replaces the Windows style path sparators to UNIX style.
bool fileExists(const string &)
This function checks, whether the file with the passed file name exists.
void StripSpaces(std::string &)
Removes leading and trailing white spaces and tabulator characters.
This structure contains all relevant information about a file path.
This structure defines all fields necessary to create a time stamp or a formatted date.
date::year_month_day m_ymd
std::chrono::minutes m_minutes
std::chrono::seconds m_seconds
std::chrono::hours m_hours