From ed30792980b4f2e4891a39829951a0661485259e Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 27 Jun 2024 17:12:40 +0300 Subject: fixes #4482 (New option: set cloud file creation date = event date) --- src/mir_app/src/file.h | 8 ++++++++ src/mir_app/src/fileexistsdlg.cpp | 26 ++++++++++++++++---------- src/mir_app/src/srmm_util.cpp | 1 + 3 files changed, 25 insertions(+), 10 deletions(-) (limited to 'src/mir_app') diff --git a/src/mir_app/src/file.h b/src/mir_app/src/file.h index 677222615e..c2a451e022 100644 --- a/src/mir_app/src/file.h +++ b/src/mir_app/src/file.h @@ -132,6 +132,7 @@ MFilePath FindUniqueFileName(const wchar_t *pszOriginalFile); int GetRegValue(HKEY hKeyBase, const wchar_t *szSubKey, const wchar_t *szValue, wchar_t *szOutput, int cbOutput); void GetSensiblyFormattedSize(__int64 size, wchar_t *szOut, int cchOut, int unitsOverride, int appendUnits, int *unitsUsed); +void UnixTimeToFileTime(int unixTime, FILETIME *ft); // downloads or launches cloud file @@ -153,6 +154,13 @@ struct OFD_Download : public OFD_Callback { void Invoke(const OFDTHREAD &ofd) override { + FILETIME ft; + UnixTimeToFileTime(ofd.dwTimestamp, &ft); + if (HANDLE hFile = CreateFileW(ofd.wszPath, GENERIC_WRITE, FILE_SHARE_READ, nullptr, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr)) { + SetFileTime(hFile, &ft, &ft, &ft); + CloseHandle(hFile); + } + if (ofd.bOpen) ShellExecuteW(nullptr, L"open", ofd.wszPath, nullptr, nullptr, SW_SHOWDEFAULT); } diff --git a/src/mir_app/src/fileexistsdlg.cpp b/src/mir_app/src/fileexistsdlg.cpp index 7170674eb5..623e610268 100644 --- a/src/mir_app/src/fileexistsdlg.cpp +++ b/src/mir_app/src/fileexistsdlg.cpp @@ -24,21 +24,27 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "stdafx.h" #include "file.h" -static void SetControlToUnixTime(HWND hwndDlg, UINT idCtrl, time_t unixTime) +void UnixTimeToFileTime(int unixTime, FILETIME *ft) { LARGE_INTEGER liFiletime; + liFiletime.QuadPart = (11644473600ll + (__int64)unixTime) * 10000000; + ft->dwHighDateTime = liFiletime.HighPart; + ft->dwLowDateTime = liFiletime.LowPart; +} + +static void SetControlToUnixTime(HWND hwndDlg, UINT idCtrl, time_t unixTime) +{ FILETIME filetime; - SYSTEMTIME st; - char szTime[64], szDate[64], szOutput[128]; + UnixTimeToFileTime(unixTime, &filetime); - liFiletime.QuadPart = (11644473600ll + (__int64)unixTime) * 10000000; - filetime.dwHighDateTime = liFiletime.HighPart; - filetime.dwLowDateTime = liFiletime.LowPart; + SYSTEMTIME st; FileTimeToSystemTime(&filetime, &st); - GetTimeFormatA(LOCALE_USER_DEFAULT, 0, &st, NULL, szTime, _countof(szTime)); - GetDateFormatA(LOCALE_USER_DEFAULT, DATE_SHORTDATE, &st, NULL, szDate, _countof(szDate)); - mir_snprintf(szOutput, "%s %s", szDate, szTime); - SetDlgItemTextA(hwndDlg, idCtrl, szOutput); + + wchar_t szTime[64], szDate[64], szOutput[128]; + GetTimeFormatW(LOCALE_USER_DEFAULT, 0, &st, NULL, szTime, _countof(szTime)); + GetDateFormatW(LOCALE_USER_DEFAULT, DATE_SHORTDATE, &st, NULL, szDate, _countof(szDate)); + mir_snwprintf(szOutput, L"%s %s", szDate, szTime); + SetDlgItemTextW(hwndDlg, idCtrl, szOutput); } #define C_CONTEXTMENU 0 diff --git a/src/mir_app/src/srmm_util.cpp b/src/mir_app/src/srmm_util.cpp index 46726b478a..884f19e7eb 100644 --- a/src/mir_app/src/srmm_util.cpp +++ b/src/mir_app/src/srmm_util.cpp @@ -233,6 +233,7 @@ void DownloadOfflineFile(MCONTACT hContact, MEVENT hDbEvent, DB::EventInfo &dbei OFDTHREAD *ofd = new OFDTHREAD(hDbEvent, blob.getLocalName(), iCommand); ofd->bLocked = true; + ofd->dwTimestamp = dbei.timestamp; ofd->pCallback = callback.release(); CallProtoService(dbei.szModule, PS_OFFLINEFILE, (WPARAM)ofd); } -- cgit v1.2.3