diff options
Diffstat (limited to 'api/logic/FileSystem.cpp')
-rw-r--r-- | api/logic/FileSystem.cpp | 64 |
1 files changed, 30 insertions, 34 deletions
diff --git a/api/logic/FileSystem.cpp b/api/logic/FileSystem.cpp index b3115988..4b47f415 100644 --- a/api/logic/FileSystem.cpp +++ b/api/logic/FileSystem.cpp @@ -3,11 +3,27 @@ #include "FileSystem.h" #include <QDir> +#include <QFile> #include <QSaveFile> #include <QFileInfo> #include <QDebug> #include <QUrl> #include <QStandardPaths> +#include <QTextStream> + +#if defined Q_OS_WIN32 + #include <windows.h> + #include <string> + #include <sys/utime.h> + #include <winnls.h> + #include <shobjidl.h> + #include <objbase.h> + #include <objidl.h> + #include <shlguid.h> + #include <shlobj.h> +#else + #include <utime.h> +#endif namespace FS { @@ -62,21 +78,13 @@ QByteArray read(const QString &filename) bool updateTimestamp(const QString& filename) { - QFile file(filename); - if (!file.exists()) - { - return false; - } - if (!file.open(QIODevice::ReadWrite)) - { - return false; - } - const quint64 size = file.size(); - file.seek(size); - file.write( QByteArray(1, '0') ); - file.resize(size); - return true; - +#ifdef Q_OS_WIN32 + std::wstring filename_utf_16 = filename.toStdWString(); + return (_wutime64(filename_utf_16.c_str(), nullptr) == 0); +#else + QByteArray filenameBA = QFile::encodeName(filename); + return (utime(filenameBA.data(), nullptr) == 0); +#endif } bool ensureFilePathExists(QString filenamepath) @@ -163,11 +171,6 @@ bool copy::operator()(const QString &offset) return true; } - -#if defined Q_OS_WIN32 -#include <windows.h> -#include <string> -#endif bool deletePath(QString path) { bool OK = true; @@ -225,7 +228,7 @@ bool deletePath(QString path) } -QString PathCombine(QString path1, QString path2) +QString PathCombine(const QString & path1, const QString & path2) { if(!path1.size()) return path2; @@ -234,11 +237,16 @@ QString PathCombine(QString path1, QString path2) return QDir::cleanPath(path1 + QDir::separator() + path2); } -QString PathCombine(QString path1, QString path2, QString path3) +QString PathCombine(const QString & path1, const QString & path2, const QString & path3) { return PathCombine(PathCombine(path1, path2), path3); } +QString PathCombine(const QString & path1, const QString & path2, const QString & path3, const QString & path4) +{ + return PathCombine(PathCombine(path1, path2, path3), path4); +} + QString AbsolutePath(QString path) { return QFileInfo(path).absolutePath(); @@ -332,21 +340,9 @@ bool checkProblemticPathJava(QDir folder) return pathfoldername.contains("!", Qt::CaseInsensitive); } -#include <QStandardPaths> -#include <QFile> -#include <QTextStream> - // Win32 crap #if defined Q_OS_WIN -#include <windows.h> -#include <winnls.h> -#include <shobjidl.h> -#include <objbase.h> -#include <objidl.h> -#include <shlguid.h> -#include <shlobj.h> - bool called_coinit = false; HRESULT CreateLink(LPCSTR linkPath, LPCSTR targetPath, LPCSTR args) |