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