diff options
author | George Hazan <george.hazan@gmail.com> | 2024-06-27 17:12:40 +0300 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2024-06-27 17:12:40 +0300 |
commit | ed30792980b4f2e4891a39829951a0661485259e (patch) | |
tree | 862089679b47152fcefad3df2131867ca9cca682 | |
parent | 3d031d4565cad76687b5c1765bc6733f8bd4270c (diff) |
fixes #4482 (New option: set cloud file creation date = event date)
-rw-r--r-- | include/m_protosvc.h | 1 | ||||
-rw-r--r-- | src/mir_app/src/file.h | 8 | ||||
-rw-r--r-- | src/mir_app/src/fileexistsdlg.cpp | 26 | ||||
-rw-r--r-- | src/mir_app/src/srmm_util.cpp | 1 |
4 files changed, 26 insertions, 10 deletions
diff --git a/include/m_protosvc.h b/include/m_protosvc.h index 40537d2209..797201b131 100644 --- a/include/m_protosvc.h +++ b/include/m_protosvc.h @@ -732,6 +732,7 @@ struct MIR_APP_EXPORT OFDTHREAD : public MNonCopyable MEVENT hDbEvent;
MFilePath wszPath;
struct OFD_Callback *pCallback = nullptr;
+ uint32_t dwTimestamp = 0;
bool bOpen = false, bCopy = false, bLocked = false;
};
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);
}
|