00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
#include <fstream>
00013
#include <qstring.h>
00014
#include <qfile.h>
00015
#include <qdir.h>
00016
#include <qlibrary.h>
00017
00018
00019
00020
#include "fileTools.h"
00021
00022
00023
00024
00025
00026
#ifdef Q_OS_WIN
00027
00028
#include <shlobj.h>
00029
00030
#ifndef CSIDL_APPDATA
00031
#define CSIDL_APPDATA 0x001a
00032
#endif
00033
00034
#ifndef CSIDL_LOCAL_APPDATA
00035
#define CSIDL_LOCAL_APPDATA 0x001c
00036
#endif
00037
00038
#endif //Q_OS_WIN
00039
00040 bool moveFile( QString oldName, QString newName)
00041 {
00042 QDir rootDir;
00043
00044
00045
if(!rootDir.rename( oldName, newName))
00046 {
00047
00048
00049
00050
if(!
copyFile(oldName, newName))
00051
return false;
00052
00053
00054 rootDir.remove(oldName);
00055 }
00056
00057
00058
return true;
00059 }
00060
00061 bool copyFile(QString oldFilePath, QString newFilePath)
00062 {
00063
00064
if(oldFilePath.compare(newFilePath) == 0)
00065
return true;
00066
00067
00068 QFile oldFile(oldFilePath);
00069 QFile newFile(newFilePath);
00070
bool openOld = oldFile.open( IO_ReadOnly );
00071
bool openNew = newFile.open( IO_WriteOnly );
00072
00073
00074
if(!openOld || !openNew) {
return false; }
00075
00076
00077 uint BUFFER_SIZE = 16000;
00078
char*
buffer =
new char[BUFFER_SIZE];
00079
while(!oldFile.atEnd())
00080 {
00081 Q_ULONG len = oldFile.readBlock(
buffer, BUFFER_SIZE );
00082 newFile.writeBlock(
buffer, len );
00083 }
00084
00085
00086
delete[]
buffer;
00087
buffer = NULL;
00088
return true;
00089 }
00090
00091
00092
#ifdef Q_OS_WIN
00093
bool getWindowsFolderLocation(FOLDER_TYPE type, QString& path)
00094 {
00095
00096
int folder;
00097
switch(type)
00098 {
00099
case APPLICATION_DATA:
00100 folder = CSIDL_APPDATA;
break;
00101
case LOCAL_SETTINGS_APPLICATION_DATA:
00102 folder = CSIDL_LOCAL_APPDATA;
break;
00103
00104
default:
00105
return false;
00106 }
00107
00108
00109
bool success =
true;
00110 QT_WA(
00111 {
00112
00113
unsigned short folderPath[MAX_PATH];
00114
if( SHGetSpecialFolderPathW(0, folderPath, folder,
false) )
00115 path = QString::fromUcs2( (ushort*)folderPath );
00116
else
00117 success =
false;
00118 },
00119 {
00120
00121
char folderPath[MAX_PATH];
00122
if( SHGetSpecialFolderPathA( 0, folderPath, folder,
false ) )
00123 path = QString::fromLocal8Bit( folderPath );
00124
else
00125 success =
false;
00126 });
00127
00128
00129
00130
if( (!success) && (type == LOCAL_SETTINGS_APPLICATION_DATA) )
00131
return getWindowsFolderLocation( APPLICATION_DATA, path );
00132
else
00133
return success;
00134 }
00135
#endif //Q_OS_WIN
00136
00137 QString
fixFilename( QString filename )
00138 {
00139 filename.replace( QChar(
' '),
"_" );
00140 filename.replace(
"<",
"" );
00141 filename.replace(
">",
"" );
00142 filename.replace(
"&",
"and" );
00143 filename.replace(
"\"",
"" );
00144 filename.replace(
"\'",
"" );
00145 filename.replace(
"?",
"" );
00146
return filename;
00147 }
00148