KVIrc  4.9.2
DeveloperAPIs
KviFileUtils.h
Go to the documentation of this file.
1 #ifndef _KVI_FILEUTILS_H_
2 #define _KVI_FILEUTILS_H_
3 //=============================================================================
4 //
5 // File : KviFileUtils.h
6 // Creation date : Fri Dec 25 1998 18:27:04 by Szymon Stefanek
7 //
8 // This file is part of the KVIrc IRC client distribution
9 // Copyright (C) 1998-2010 Szymon Stefanek (pragma at kvirc dot net)
10 //
11 // This program is FREE software. You can redistribute it and/or
12 // modify it under the terms of the GNU General Public License
13 // as published by the Free Software Foundation; either version 2
14 // of the License, or (at your option) any later version.
15 //
16 // This program is distributed in the HOPE that it will be USEFUL,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19 // See the GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with this program. If not, write to the Free Software Foundation,
23 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 //
25 //=============================================================================
26 
36 #include "kvi_settings.h"
37 #include "KviCString.h"
38 
39 #include <QFile>
40 #include <QStringList>
41 
42 #include <time.h>
43 
44 #if defined(COMPILE_ON_WINDOWS) || defined(COMPILE_ON_MINGW)
45 #define KVI_PATH_SEPARATOR "\\"
46 #define KVI_PATH_SEPARATOR_CHAR '\\'
47 #else
48 #define KVI_PATH_SEPARATOR "/"
49 #define KVI_PATH_SEPARATOR_CHAR '/'
50 #endif
51 
52 // #warning "Add kvi_trashFile(const char * path) ? - is it needed in the whole app"
53 // #warning "or should it be available only for dirbrowser module?"
58 namespace KviFileUtils
59 {
60  //KVILIB_API bool readLine(QFile * f,QString &szBuffer,bool bClearBuffer = true);
61  //KVILIB_API bool loadFileStripCR(const QString &szPath,QString &szBuffer);
62 
70  KVILIB_API bool loadFile(const QString & szPath, QString & szBuffer, bool bUtf8 = true);
71 
77  KVILIB_API void adjustFilePath(QString & szPath);
78 
84  KVILIB_API bool directoryExists(const QString & szPath);
85 
91  inline bool fileExists(const QString & szPath) { return QFile::exists(szPath); }
92 
98  KVILIB_API bool removeFile(const QString & szPath);
99 
105  KVILIB_API bool removeFile(const char * pcPath);
106 
112  KVILIB_API bool removeDir(const QString & szPath);
113 
119  KVILIB_API bool removeDir(const char * pcPath);
120 
126  KVILIB_API bool deleteDir(const QString & szPath);
127 
135  KVILIB_API bool writeFile(const QString & szPath, const QByteArray & oData, bool bAppend = false);
136 
144  KVILIB_API bool writeFile(const QString & szPath, const QString & szData, bool bAppend = false);
145 
153  KVILIB_API bool writeFile(const char * pcPath, const QString & szData, bool bAppend = false);
154 
162  KVILIB_API bool writeFileLocal8Bit(const QString & szPath, const QString & szData, bool bAppend = false);
163 
171  KVILIB_API bool writeFileLocal8Bit(const char * pcPath, const QString & szData, bool bAppend = false);
172 
182  KVILIB_API bool readFile(const QString & szPath, QString & szBuffer, unsigned int uMaxSize = 65535);
183 
193  KVILIB_API bool readFile(const char * pcPath, QString & szBuffer, unsigned int uMaxSize = 65535);
194 
206  KVILIB_API QString extractFileName(const QString & szFileNameWithPath, bool bAllowEmpty = true);
207 
213  KVILIB_API QString extractFilePath(const QString & szFileNameWithPath);
214 
221  KVILIB_API bool copyFile(const QString & szSrc, const QString & szDst);
222 
229  KVILIB_API bool copyFile(const char * pcSrc, const char * pcDst);
230 
237  KVILIB_API bool renameFile(const QString & szSrc, const QString & szDst);
238 
245  KVILIB_API bool renameFile(const char * pcSrc, const char * pcDst);
246 
252  KVILIB_API bool makeDir(const QString & szPath);
253 
259  KVILIB_API bool makeDir(const char * pcPath);
260 
268  KVILIB_API bool readLine(QFile * pFile, QString & szBuffer, bool bUtf8 = true);
269 
279  KVILIB_API bool readLines(QFile * pFile, QStringList & buffer, int iStartLine = 0, int iCount = -1, bool bUtf8 = true);
280 
286  KVILIB_API bool isReadable(const QString & szFname);
287 
293  KVILIB_API bool isAbsolutePath(const QString & szPath);
294 
303  KVILIB_API void encodeFileName(QString & szPath);
304 
313  KVILIB_API void cleanFileName(QString & szPath);
314 
318  KVILIB_API QStringList getFileListing(const QString & szPath);
319 }
320 
321 #endif //_KVI_FILEUTILS_H
bool readLine(QFile *pFile, QString &szBuffer, bool bUtf8)
Reads a text line, returns false if EOF is reached.
Definition: KviFileUtils.cpp:328
void encodeFileName(QString &szPath)
Translates ANY string into a valid filename (with no path!)
Definition: KviFileUtils.cpp:392
bool directoryExists(const QString &szPath)
Returns true if szPath points to an existing directory.
Definition: KviFileUtils.cpp:368
bool copyFile(const QString &szSrc, const QString &szDst)
Copy the file (cp -f)
Definition: KviFileUtils.cpp:95
bool writeFile(const QString &szPath, const QByteArray &oData, bool bAppend)
Writes a complete file (UTF-8 version)
Definition: KviFileUtils.cpp:230
bool removeFile(const QString &szPath)
Removes a file.
Definition: KviFileUtils.cpp:171
bool isAbsolutePath(const QString &szPath)
Returns true if the path is absolute, false otherwise.
Definition: KviFileUtils.cpp:386
bool removeDir(const QString &szPath)
Removes a dir (must be empty)
Definition: KviFileUtils.cpp:183
bool renameFile(const QString &szSrc, const QString &szDst)
Rename or move the file (mv)
Definition: KviFileUtils.cpp:82
QString extractFilePath(const QString &szFileNameWithPath)
Extracts the filename from a complete path (strips leading path)
Definition: KviFileUtils.cpp:323
bool writeFileLocal8Bit(const QString &szPath, const QString &szData, bool bAppend)
Writes a complete file (local 8 bit version)
Definition: KviFileUtils.cpp:261
QString extractFileName(const QString &szFileNameWithPath, bool bAllowEmpty)
Extracts the filename from a complete path (strips leading path)
Definition: KviFileUtils.cpp:313
QStringList getFileListing(const QString &szPath)
Definition: KviFileUtils.cpp:470
void adjustFilePath(QString &szPath)
Adjusts the file path to the current platform.
Definition: KviFileUtils.cpp:148
bool makeDir(const QString &szPath)
Create a directory (mkdir)
Definition: KviFileUtils.cpp:42
void cleanFileName(QString &szPath)
Removes any unusable character from a filename (with no path!)
Definition: KviFileUtils.cpp:422
bool readLines(QFile *pFile, QStringList &buffer, int iStartLine, int iCount, bool bUtf8)
Reads text lines, returns false if EOF is reached.
Definition: KviFileUtils.cpp:343
bool deleteDir(const QString &szPath)
Removes a dir recursively.
Definition: KviFileUtils.cpp:195
char szBuffer[4096]
Definition: winamp.cpp:77
bool isReadable(const QString &szFname)
Returns true if the file is readable, false otherwise.
Definition: KviFileUtils.cpp:374
This file contains compile time settings.
bool fileExists(const QString &szPath)
Returns true if szPath points to an existing file.
Definition: KviFileUtils.h:91
#define KVILIB_API
Definition: kvi_settings.h:125
bool loadFile(const QString &szPath, QString &szBuffer, bool bUtf8)
Loads the file at szPath to szBuffer eventually converting from UTF-8.
Definition: KviFileUtils.cpp:130
bool readFile(const QString &szPath, QString &szBuffer, unsigned int uMaxSize)
Reads a complete file and puts it in the string szBuffer.
Definition: KviFileUtils.cpp:280