Shinya Kitaoka 810553
#pragma once
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
Shinya Kitaoka 9f5a1b
#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
Shinya Kitaoka 3bfa54
DVAPI std::ostream &operator<<(std::ostream &out, const QDateTime &t);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include <qfileinfo></qfileinfo>
Shinya Kitaoka 120a6e
class DVAPI TFileStatus {
Shinya Kitaoka 120a6e
  bool m_exist;
Shinya Kitaoka 120a6e
  QFileInfo m_fileInfo;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  TFileStatus(const TFilePath &path);
Shinya Kitaoka 120a6e
  QString getGroup() const;
Shinya Kitaoka 120a6e
  QString getUser() const;
Shinya Kitaoka 120a6e
  TINT64 getSize() const;
Shinya Kitaoka 120a6e
  QDateTime getLastAccessTime() const;
Shinya Kitaoka 120a6e
  QDateTime getLastModificationTime() const;
Shinya Kitaoka 120a6e
  QDateTime getCreationTime() const;
Shinya Kitaoka 120a6e
  bool isDirectory() const;
Shinya Kitaoka 120a6e
  bool isLink() const;
Shinya Kitaoka 120a6e
  QFile::Permissions getPermissions() const;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  bool doesExist() const { return m_exist; }
Shinya Kitaoka 120a6e
  bool isWritable() const { return (getPermissions() & QFile::WriteUser) != 0; }
Shinya Kitaoka 120a6e
  bool isReadable() const {
Shinya Kitaoka 120a6e
    return m_exist && (getPermissions() & QFile::ReadUser) != 0;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  bool isWritableDir() const {
Shinya Kitaoka 120a6e
    return doesExist() && isDirectory() && isWritable();
Shinya Kitaoka 120a6e
  };
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class DVAPI TSystemException final : public TException {
Shinya Kitaoka 120a6e
  TFilePath m_fname;
Shinya Kitaoka 120a6e
  int m_err;
Shinya Kitaoka 120a6e
  TString m_msg;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  TSystemException() {}
Shinya Kitaoka 120a6e
  TSystemException(const TFilePath &, int);
Shinya Kitaoka 120a6e
  TSystemException(const TFilePath &, const std::string &);
Shinya Kitaoka 120a6e
  TSystemException(const TFilePath &, const std::wstring &);
Shinya Kitaoka 120a6e
  TSystemException(const std::string &);
Shinya Kitaoka 120a6e
  TSystemException(const std::wstring &msg);
Shinya Kitaoka 120a6e
  ~TSystemException() {}
Shinya Kitaoka 473e70
  TString getMessage() const override;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// DVAPI ostream&operator<<(ostream&out, const TSystemException &e);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
namespace TSystem {
Shinya Kitaoka 120a6e
// cambiare i nomi. Niente T (c'e' gia' in TSystem). Usiamo la convenzione
Shinya Kitaoka 120a6e
// solita per
Shinya Kitaoka 120a6e
// i nomi composti (maiuscole e non '_'). Facciamo tutto minuscolo con
Shinya Kitaoka 120a6e
// l'iniziale maiuscola
Toshihiro Shimizu 890ddd
// es. MaxPathLen;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
extern const int MaxPathLen;      // Maximum length of full path
Shinya Kitaoka 120a6e
extern const int MaxFNameLen;     // Maximum length of filename component
Shinya Kitaoka 120a6e
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);
Shinya Kitaoka 120a6e
// DVAPI void enableFrameGrouping(bool on);
Shinya Kitaoka 120a6e
// DVAPI bool isFrameGroupingEnabled();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// aggiungono (in coda) a set
Shinya Kitaoka 120a6e
DVAPI void readDirectory(TFilePathSet &fpset, const QDir &dir,
Shinya Kitaoka 120a6e
                         bool groupFrames = true);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
DVAPI void readDirectory(TFilePathSet &fpset, const TFilePath &path,
Shinya Kitaoka 120a6e
                         bool groupFrames = true, bool onlyFiles = false,
Shinya Kitaoka 120a6e
                         bool getHiddenFiles = false);
Shinya Kitaoka 120a6e
DVAPI void readDirectory(TFilePathSet &fpset, const TFilePathSet &pathSet,
Shinya Kitaoka 120a6e
                         bool groupFrames = true, bool onlyFiles = false,
Shinya Kitaoka 120a6e
                         bool getHiddenFiles = false);
Shinya Kitaoka 120a6e
DVAPI void readDirectoryTree(TFilePathSet &fpset, const TFilePath &path,
Shinya Kitaoka 120a6e
                             bool groupFrames = true, bool onlyFiles = false);
Shinya Kitaoka 120a6e
DVAPI void readDirectoryTree(TFilePathSet &fpset, const TFilePathSet &pathSet,
Shinya Kitaoka 120a6e
                             bool groupFrames = true, bool onlyFiles = false);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
// to retrieve the both lists with groupFrames option = on and off.
Shinya Kitaoka 120a6e
DVAPI void readDirectory(TFilePathSet &groupFpSet, TFilePathSet &allFpSet,
Shinya Kitaoka 120a6e
                         const TFilePath &path);
Shinya Kitaoka 120a6e
shun_iwasawa f5f4af
// return the folder path list which is readable and executable
Toshihiro Shimizu 890ddd
DVAPI void readDirectory_Dir_ReadExe(TFilePathSet &dst, const TFilePath &path);
Toshihiro Shimizu 890ddd
shun_iwasawa f5f4af
// return the folder item list which is readable and executable (only names)
shun_iwasawa f5f4af
DVAPI void readDirectory_DirItems(QStringList &dst, const TFilePath &path);
shun_iwasawa f5f4af
Toshihiro Shimizu 890ddd
// creano un set nuovo
Shinya Kitaoka 120a6e
DVAPI TFilePathSet readDirectory(const TFilePath &path, bool groupFrames = true,
Shinya Kitaoka 120a6e
                                 bool onlyFiles      = false,
Shinya Kitaoka 120a6e
                                 bool getHiddenFiles = false);
Shinya Kitaoka 120a6e
DVAPI TFilePathSet readDirectory(const TFilePathSet &pathSet,
Shinya Kitaoka 120a6e
                                 bool groupFrames    = true,
Shinya Kitaoka 120a6e
                                 bool onlyFiles      = false,
Shinya Kitaoka 120a6e
                                 bool getHiddenFiles = false);
Shinya Kitaoka 120a6e
DVAPI TFilePathSet readDirectoryTree(const TFilePath &path,
Shinya Kitaoka 120a6e
                                     bool groupFrames = true,
Shinya Kitaoka 120a6e
                                     bool onlyFiles   = false);
Shinya Kitaoka 120a6e
DVAPI TFilePathSet readDirectoryTree(const TFilePathSet &pathSet,
Shinya Kitaoka 120a6e
                                     bool groupFrames = true,
Shinya Kitaoka 120a6e
                                     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();
Shinya Kitaoka 3bfa54
DVAPI TFilePath getTestDir(std::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!
Shinya Kitaoka 120a6e
// 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);
Shinya Kitaoka 120a6e
DVAPI void copyFile(const TFilePath &dst, const TFilePath &src,
Shinya Kitaoka 120a6e
                    bool overwrite = true);
Shinya Kitaoka 120a6e
DVAPI void renameFile(const TFilePath &dst, const TFilePath &src,
Shinya Kitaoka 120a6e
                      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);
Shinya Kitaoka 120a6e
DVAPI void renameFileOrLevel_throw(const TFilePath &dst, const TFilePath &src,
Shinya Kitaoka 120a6e
                                   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);
Shinya Kitaoka 120a6e
DVAPI bool renameFileOrLevel(const TFilePath &dst, const TFilePath &src,
Shinya Kitaoka 120a6e
                             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
Shinya Kitaoka 120a6e
/*! returns available physical (+ virtual mem if boolean=true)  memory in KBytes
Shinya Kitaoka 120a6e
 */
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;
Shinya Kitaoka 120a6e
      2) the calling process has allocated the maximum amount of memory  allowed
Shinya Kitaoka 120a6e
   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 */
Shinya Kitaoka 120a6e
// DVAPI void showDocument(const TFilePath &dst);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
DVAPI int getProcessorCount();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
enum CPUExtensions {
Shinya Kitaoka 120a6e
  CPUExtensionsNone = 0x00000000L,
Shinya Kitaoka 120a6e
  // CpuSupportsCpuId      = 0x00000001L,
Shinya Kitaoka 120a6e
  // CpuSupportsFpu        = 0x00000002L,
Shinya Kitaoka 120a6e
  // CpuSupportsMmx        = 0x00000004L,
Shinya Kitaoka 120a6e
  // CpuSupportsIntegerSse = 0x00000008L,
Shinya Kitaoka 120a6e
  CpuSupportsSse  = 0x00000010L,
Shinya Kitaoka 120a6e
  CpuSupportsSse2 = 0x00000020L,
Shinya Kitaoka 120a6e
  // CpuSupports3DNow      = 0x00000040L,
Shinya Kitaoka 120a6e
  // 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*/
Shinya Kitaoka 120a6e
// 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
Shinya Kitaoka 3bfa54
DVAPI std::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
Shinya Kitaoka 3bfa54
void DVAPI outputDebug(std::string s);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
DVAPI bool isUNC(const TFilePath &fp);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
//! 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
Shinya Kitaoka 120a6e
// 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
Shinya Kitaoka 120a6e
            ex.: TFilePath("\\\\dell530\\discoD\\temp").toLocalPath() ==
Shinya Kitaoka 120a6e
   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");
Shinya Kitaoka 120a6e
// for(TFilePathSet::Iterator it = dirContent.begin(); it != dirContent.end();
Shinya Kitaoka 120a6e
// 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