LOC_SET_TIMES_1, // 12504
LOC_MAKE_DIR_1, // 12505
LOC_MAKE_DIR_2, // 12506
+ LOC_SET_TIMES_2, // 12507
};
QDateTime ReFileUtils::m_undefinedTime;
*/
QString ReFileUtils::copy(const QString& source, const QString& target,
const QFileInfo* sourceInfo, QByteArray& buffer){
- QString rc;
+ QString rc;
+#if defined _WIN32
+ const ushort* src = source.utf16();
+ const ushort* trg = target.utf16();
+ if (! CopyFile(reinterpret_cast<const WCHAR*>(src),
+ reinterpret_cast<const WCHAR*>(trg), false))
+ rc = QObject::tr("copy file failed (%1): %2")
+ .arg(GetLastError()).arg(target);
+#else
QByteArray source2 = I18N::s2b(source);
QByteArray target2 = I18N::s2b(target);
QFileInfo sourceInfo2;
fclose(fpSource);
}
}
+#endif
return rc;
}
vals[1].tv_usec = millisec % 1000 * 1000;
if (utimes(filename, vals) != 0) {
if (logger != NULL)
- logger->logv(LOG_ERROR, LOC_SET_TIMES_1,
- "cannot change times (%d): $s", errno, filename);
+ logger->logv(LOG_ERROR, LOC_SET_TIMES_1,
+ "cannot change times (%d): %s", errno, filename);
rc = false;
}
+#elif defined _WIN32
+ // utime does not work with VS10-32-bit
+ FILETIME accessed2 = unixTimeToFileTime(accessed.toMSecsSinceEpoch());
+ FILETIME modified2 = unixTimeToFileTime(modified.toMSecsSinceEpoch());
+
+ HANDLE handle = CreateFileA(filename, GENERIC_WRITE, FILE_SHARE_WRITE,
+ NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
+ if (handle == INVALID_HANDLE_VALUE){
+ if (logger != NULL)
+ logger->logv(LOG_ERROR, LOC_SET_TIMES_2,
+ "cannot open file for time change (%d): %s", GetLastError(), filename);
+ rc = false;
+ } else if (! SetFileTime(handle, NULL, &accessed2, &modified2)){
+ rc = false;
+ if (logger != NULL)
+ logger->logv(LOG_ERROR, LOC_SET_TIMES_1,
+ "cannot change times (%d): %s", errno, filename);
+ CloseHandle(handle);
+ }
#else
- // ANSII-C:
+ // QT solution:
+ QString filename2(filename);
+ QDir info(filename2);
+ if (info.set
struct utimbuf times;
times.actime = time_t(accessed.currentMSecsSinceEpoch() / 1000);
times.modtime = time_t(modified.currentMSecsSinceEpoch() / 1000);
return rc;
}
+#if defined _WIN32
+/**
+ * Converts the unix time (milliseconds from 1.1.1970) to the WIN32 filetime.
+ *
+ * @param milliSecFromEpoche time as milliseconds from 1.1.1970
+ * @return time as WIN32 filetime
+ */
+FILETIME ReFileUtils::unixTimeToFileTime(qint64 milliSecFromEpoche)
+{
+ FILETIME fileTime;
+ // ll = Int32x32To64(t, 10000000) + 116444736000000000;
+ LONGLONG value = milliSecFromEpoche * 10000LL + 116444736000000000LL;
+ fileTime.dwLowDateTime = (DWORD) value;
+ fileTime.dwHighDateTime = DWORD (value >> 32);
+ return fileTime;
+}
+#endif
+
/**
* Writes a string into a given file.
*