]> git.lyx.org Git - features.git/blobdiff - src/support/FileName.h
more use of support::FileName.
[features.git] / src / support / FileName.h
index 1d4420b61ee1474e1cce91fcf4fe49d5b3419e62..a2b1c3c48d6fe3b7ca19cfd611109dab28fb063b 100644 (file)
 #ifndef FILENAME_H
 #define FILENAME_H
 
+#include "strfwd.h"
+
 #include <string>
+#include <ctime>
 
 
 namespace lyx {
@@ -27,7 +30,7 @@ namespace support {
 class FileName {
 public:
        /// Constructor for empty filenames
-       FileName();
+       FileName() {}
        /** Constructor for nonempty filenames.
         * explicit because we don't want implicit conversion of relative
         * paths in function arguments (e.g. of unlink).
@@ -35,7 +38,7 @@ public:
         * Encoding is always UTF-8.
         */
        explicit FileName(std::string const & abs_filename);
-       virtual ~FileName();
+       virtual ~FileName() {}
        /** Set a new filename.
         * \param filename the file in question. Must have an absolute path.
         * Encoding is always UTF-8.
@@ -50,14 +53,65 @@ public:
         * Get the file name in the encoding used by the file system.
         * Only use this for accessing the file, e.g. with an fstream.
         */
-       std::string const toFilesystemEncoding() const;
+       std::string toFilesystemEncoding() const;
+
+       /// returns true if the file exists
+       bool exists() const;
+       /// returns time of last write access
+       std::time_t lastModified() const;
+       /// return true when file is readable but not writabel
+       bool isReadOnly() const;
+       /// return true when it names a directory
+       bool isDirectory() const;
+       /// return true when file/directory is readable
+       bool isReadable() const;
+       /// return true when it is a file and readable
+       bool isFileReadable() const;
+       /// return true when file/directory is writable
+       bool isWritable() const;
+       /// return true when file/directory is writable (write test file)
+       bool isDirWritable() const;
+       
+       /// return true when file/directory is writable (write test file)
+       bool copyTo(FileName const & target, bool noclobber) const;
+
+       /// remove directory and all contents, returns true on success
+       bool destroyDirectory() const;
+       /// Creates directory. Returns true on success
+       bool createDirectory(int permissions) const;
+
+       /// Get the contents of a file as a huge std::string
+       std::string fileContents() const;
        /**
         * Get a FileName from \p name in the encoding used by the file system.
         * Only use this for filenames you got directly from the file system,
         * e.g. from reading a directory.
         * \p name must have an absolute path.
         */
-       static FileName const fromFilesystemEncoding(std::string const & name);
+
+       /** Guess the file format name (as in Format::name()) from contents.
+        Normally you don't want to use this directly, but rather
+        Formats::getFormatFromFile().
+        */
+       std::string guessFormatFromContents() const;
+
+       /// check for zipped file
+       bool isZippedFile() const;
+
+       static FileName fromFilesystemEncoding(std::string const & name);
+       /// (securely) create a temporary file in the given dir with the given mask
+       /// \p mask must be in filesystem encoding
+       static FileName tempName(FileName const & dir = FileName(),
+                                               std::string const & mask = std::string());
+
+       /// filename without path
+       std::string onlyFileName() const;
+       /// path without file name
+       std::string onlyPath() const;
+       /// used for display in the Gui
+       docstring displayName(int threshold = 1000) const;
+
+
 protected:
        /// The absolute file name.
        /// The encoding is currently unspecified, anything else than ASCII
@@ -102,7 +156,7 @@ public:
        std::string const relFilename(std::string const & buffer_path = std::string()) const;
        /// \param buf_path if empty, uses `pwd`
        std::string const outputFilename(std::string const & buf_path = std::string()) const;
-
+       
        /** @returns a mangled representation of the absolute file name
         *  suitable for use in the temp dir when, for example, converting
         *  an image file to another format.