tahoma2d/toonz/sources/include/tsystem.h

289 lines
9.7 KiB
C
Raw Normal View History

2016-05-17 03:04:11 +12:00
#pragma once
2016-03-19 06:57:51 +13:00
#ifndef TSYSTEM_INCLUDED
#define TSYSTEM_INCLUDED
//#include "texception.h"
2016-04-15 17:11:23 +12:00
#ifndef _WIN32
2016-03-19 06:57:51 +13:00
#include <sys/stat.h>
#endif
#undef DVAPI
#undef DVVAR
#ifdef TSYSTEM_EXPORTS
#define DVAPI DV_EXPORT_API
#define DVVAR DV_EXPORT_VAR
#else
#define DVAPI DV_IMPORT_API
#define DVVAR DV_IMPORT_VAR
#endif
//=============================================================================
#include "tfilepath.h"
// tutte le info ritornate da stat e access
// piu' info 'toonzesche' : cos'e': directory, livello, immagine, testo, ecc.
#ifndef TNZCORE_LIGHT
2016-03-27 13:30:32 +13:00
#include <QDateTime>
2016-03-19 06:57:51 +13:00
DVAPI std::ostream &operator<<(std::ostream &out, const QDateTime &t);
2016-03-19 06:57:51 +13:00
#include <QFileInfo>
2016-06-15 18:43:10 +12:00
class DVAPI TFileStatus {
bool m_exist;
QFileInfo m_fileInfo;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
TFileStatus(const TFilePath &path);
QString getGroup() const;
QString getUser() const;
TINT64 getSize() const;
QDateTime getLastAccessTime() const;
QDateTime getLastModificationTime() const;
QDateTime getCreationTime() const;
bool isDirectory() const;
bool isLink() const;
QFile::Permissions getPermissions() const;
bool doesExist() const { return m_exist; }
bool isWritable() const { return (getPermissions() & QFile::WriteUser) != 0; }
bool isReadable() const {
return m_exist && (getPermissions() & QFile::ReadUser) != 0;
}
bool isWritableDir() const {
return doesExist() && isDirectory() && isWritable();
};
2016-03-19 06:57:51 +13:00
};
#endif
class DVAPI TSystemException final : public TException {
2016-06-15 18:43:10 +12:00
TFilePath m_fname;
int m_err;
TString m_msg;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
TSystemException() {}
TSystemException(const TFilePath &, int);
TSystemException(const TFilePath &, const std::string &);
TSystemException(const TFilePath &, const std::wstring &);
TSystemException(const std::string &);
TSystemException(const std::wstring &msg);
~TSystemException() {}
2016-06-19 20:06:29 +12:00
TString getMessage() const override;
2016-03-19 06:57:51 +13:00
};
// DVAPI ostream&operator<<(ostream&out, const TSystemException &e);
2016-06-15 18:43:10 +12:00
namespace TSystem {
// cambiare i nomi. Niente T (c'e' gia' in TSystem). Usiamo la convenzione
// solita per
// i nomi composti (maiuscole e non '_'). Facciamo tutto minuscolo con
// l'iniziale maiuscola
2016-03-19 06:57:51 +13:00
// es. MaxPathLen;
2016-06-15 18:43:10 +12:00
extern const int MaxPathLen; // Maximum length of full path
extern const int MaxFNameLen; // Maximum length of filename component
extern const int MaxHostNameLen; // Maximum length of the host name ==64
2016-03-19 06:57:51 +13:00
DVAPI bool doHaveMainLoop();
DVAPI void hasMainLoop(bool state);
2016-06-15 18:43:10 +12:00
// DVAPI void enableFrameGrouping(bool on);
// DVAPI bool isFrameGroupingEnabled();
2016-03-19 06:57:51 +13:00
// aggiungono (in coda) a set
2016-06-15 18:43:10 +12:00
DVAPI void readDirectory(TFilePathSet &fpset, const QDir &dir,
bool groupFrames = true);
DVAPI void readDirectory(TFilePathSet &fpset, const TFilePath &path,
bool groupFrames = true, bool onlyFiles = false,
bool getHiddenFiles = false);
DVAPI void readDirectory(TFilePathSet &fpset, const TFilePathSet &pathSet,
bool groupFrames = true, bool onlyFiles = false,
bool getHiddenFiles = false);
DVAPI void readDirectoryTree(TFilePathSet &fpset, const TFilePath &path,
bool groupFrames = true, bool onlyFiles = false);
DVAPI void readDirectoryTree(TFilePathSet &fpset, const TFilePathSet &pathSet,
bool groupFrames = true, bool onlyFiles = false);
// to retrieve the both lists with groupFrames option = on and off.
DVAPI void readDirectory(TFilePathSet &groupFpSet, TFilePathSet &allFpSet,
const TFilePath &path);
2019-05-22 19:30:39 +12:00
// return the folder path list which is readable and executable
2016-03-19 06:57:51 +13:00
DVAPI void readDirectory_Dir_ReadExe(TFilePathSet &dst, const TFilePath &path);
2019-05-22 19:30:39 +12:00
// return the folder item list which is readable and executable (only names)
DVAPI void readDirectory_DirItems(QStringList &dst, const TFilePath &path);
2016-03-19 06:57:51 +13:00
// creano un set nuovo
2016-06-15 18:43:10 +12:00
DVAPI TFilePathSet readDirectory(const TFilePath &path, bool groupFrames = true,
bool onlyFiles = false,
bool getHiddenFiles = false);
DVAPI TFilePathSet readDirectory(const TFilePathSet &pathSet,
bool groupFrames = true,
bool onlyFiles = false,
bool getHiddenFiles = false);
DVAPI TFilePathSet readDirectoryTree(const TFilePath &path,
bool groupFrames = true,
bool onlyFiles = false);
DVAPI TFilePathSet readDirectoryTree(const TFilePathSet &pathSet,
bool groupFrames = true,
bool onlyFiles = false);
2016-03-19 06:57:51 +13:00
//
DVAPI TFilePathSet packLevelNames(const TFilePathSet &);
DVAPI TFilePath getHomeDirectory();
DVAPI TFilePath getTempDir();
DVAPI TFilePath getTestDir(std::string name = "verify_tnzcore");
2016-03-19 06:57:51 +13:00
DVAPI TFilePath getBinDir();
DVAPI TFilePath getDllDir();
/*!Returns the process id of the current process*/
DVAPI int getProcessId();
// n.b. queste possono buttare eccezioni!
2016-06-15 18:43:10 +12:00
// mkdir crea anche il parent se non esiste
2016-03-19 06:57:51 +13:00
DVAPI void mkDir(const TFilePath &path);
DVAPI void rmDir(const TFilePath &path);
DVAPI void rmDirTree(const TFilePath &path);
DVAPI void copyDir(const TFilePath &dst, const TFilePath &src,
bool overwrite = false);
2016-03-19 06:57:51 +13:00
DVAPI bool touchParentDir(const TFilePath &fp);
DVAPI void touchFile(const TFilePath &path);
2016-06-15 18:43:10 +12:00
DVAPI void copyFile(const TFilePath &dst, const TFilePath &src,
bool overwrite = true);
DVAPI void renameFile(const TFilePath &dst, const TFilePath &src,
bool overwrite = true);
2016-03-19 06:57:51 +13:00
DVAPI void deleteFile(const TFilePath &dst);
DVAPI void hideFile(const TFilePath &dst);
DVAPI void moveFileToRecycleBin(const TFilePath &fp);
DVAPI void copyFileOrLevel_throw(const TFilePath &dst, const TFilePath &src);
2016-06-15 18:43:10 +12:00
DVAPI void renameFileOrLevel_throw(const TFilePath &dst, const TFilePath &src,
bool renamePalette = false);
2016-03-19 06:57:51 +13:00
DVAPI void removeFileOrLevel_throw(const TFilePath &fp);
DVAPI void hideFileOrLevel_throw(const TFilePath &fp);
DVAPI void moveFileOrLevelToRecycleBin_throw(const TFilePath &fp);
DVAPI bool doesExistFileOrLevel(const TFilePath &fp);
DVAPI bool copyFileOrLevel(const TFilePath &dst, const TFilePath &src);
2016-06-15 18:43:10 +12:00
DVAPI bool renameFileOrLevel(const TFilePath &dst, const TFilePath &src,
bool renamePalette = false);
2016-03-19 06:57:51 +13:00
DVAPI bool removeFileOrLevel(const TFilePath &fp);
DVAPI bool hideFileOrLevel(const TFilePath &fp);
DVAPI bool moveFileOrLevelToRecycleBin(const TFilePath &fp);
DVAPI void sleep(TINT64 delay);
inline void sleep(int ms) { sleep((TINT64)ms); }
DVAPI TFilePathSet getDisks();
/*! returns disk size in Kbytes */
DVAPI TINT64 getDiskSize(const TFilePath &);
/* returns free disk size in Kbytes */
DVAPI TINT64 getFreeDiskSize(const TFilePath &);
2016-06-15 18:43:10 +12:00
/*! returns available physical (+ virtual mem if boolean=true) memory in KBytes
*/
2016-03-19 06:57:51 +13:00
DVAPI TINT64 getFreeMemorySize(bool onlyPhisicalMemory);
/*! return total physical (+ virtual mem if boolean=true) memory in kbytes */
DVAPI TINT64 getMemorySize(bool onlyPhisicalMemory);
/*! return true if not enough memory. It can happen for 2 reasons:
1) free phisical memory is close to 0;
2016-06-15 18:43:10 +12:00
2) the calling process has allocated the maximum amount of memory allowed
for a single process(tipically, for a 32 bits machine, 2GB)*/
2016-03-19 06:57:51 +13:00
DVAPI bool memoryShortage();
/*! run di un extern viewer */
2016-06-15 18:43:10 +12:00
// DVAPI void showDocument(const TFilePath &dst);
2016-03-19 06:57:51 +13:00
DVAPI int getProcessorCount();
enum CPUExtensions {
2016-06-15 18:43:10 +12:00
CPUExtensionsNone = 0x00000000L,
// CpuSupportsCpuId = 0x00000001L,
// CpuSupportsFpu = 0x00000002L,
// CpuSupportsMmx = 0x00000004L,
// CpuSupportsIntegerSse = 0x00000008L,
CpuSupportsSse = 0x00000010L,
CpuSupportsSse2 = 0x00000020L,
// CpuSupports3DNow = 0x00000040L,
// CpuSupports3DNowExt = 0x00000080L
2016-03-19 06:57:51 +13:00
};
/*! returns a bit mask containing the CPU extensions supported */
DVAPI long getCPUExtensions();
/*! enables/disables the CPU extensions, if available*/
2016-06-15 18:43:10 +12:00
// DVAPI void enableCPUExtensions(bool on);
2016-03-19 06:57:51 +13:00
// cosette da fare:
// un po' di studio sui file memory mapped
// indagare
DVAPI std::iostream openTemporaryFile();
2016-03-19 06:57:51 +13:00
// un'altra idea e' avere un TQualcosaP che ritorna un UniqueFileName
// e che sul distruttore cancella il file
// pensare a:
// DVAPI void setFileProtection(const TFilePath &path, ???);
void DVAPI outputDebug(std::string s);
2016-03-19 06:57:51 +13:00
DVAPI bool isUNC(const TFilePath &fp);
2016-06-15 18:43:10 +12:00
//! Returns the filepath in UNC format
2016-03-19 06:57:51 +13:00
// ex.: TFilePath("O:\\temp").toUNC() == TFilePath("\\\\vega\\PERSONALI\\temp")
// if "\\\\vega\\PERSONALI\\" is mounted as "O:\\" on the local host
2016-06-15 18:43:10 +12:00
// A TException is thrown if the the conversion is not possible
2016-03-19 06:57:51 +13:00
DVAPI TFilePath toUNC(const TFilePath &fp);
/*!Returns the filepath in a format that refers to the local host
2016-06-15 18:43:10 +12:00
ex.: TFilePath("\\\\dell530\\discoD\\temp").toLocalPath() ==
TFilePath("C:\\temp")
2016-03-19 06:57:51 +13:00
if the local host is "dell530"
No conversion is done if the filepath already refers to the local host
A TException is thrown if the the conversion is not possible
*/
DVAPI TFilePath toLocalPath(const TFilePath &fp);
DVAPI bool showDocument(const TFilePath &fp);
DVAPI QString findFileLocation(QStringList folderList, QString fileName);
2016-03-19 06:57:51 +13:00
#ifndef TNZCORE_LIGHT
DVAPI QDateTime getFileTime(const TFilePath &path);
DVAPI QString getHostName();
DVAPI QString getUserName();
DVAPI QString getSystemValue(const TFilePath &name);
DVAPI TFilePath getUniqueFile(QString field = "");
#endif
}
//
// Esempio di lettura di una directory:
// TFilePathSet dirContent = TSystem::readDirectory("C:\\temp");
2016-06-15 18:43:10 +12:00
// for(TFilePathSet::Iterator it = dirContent.begin(); it != dirContent.end();
// it++)
2016-03-19 06:57:51 +13:00
// {
// TFilePath fp = *it;
// cout << fp << endl;
// }
//
#endif