Android ADB-FS plugin development, filetime issue - TC BUG?

Discuss and announce Total Commander plugins, addons and other useful tools here, both their usage and their development.

Moderators: white, Hacker, petermad, Stefan2

Post Reply
Aleq
Junior Member
Junior Member
Posts: 55
Joined: 2006-06-07, 07:24 UTC
Location: CZ, EU

Android ADB-FS plugin development, filetime issue - TC BUG?

Post by *Aleq »

Hi Everybody.
I'm fixing and enhancing Sztupy's ADB-FS plugin accessing android device using ADB protocol. I'm tearing my hair off now because I can't get the time and date correctly. I have tried so many ways of converting FILETIME, unix timestamp, SYSTEMTIME, ...

I have narrowed the issue down to this:

Code: Select all

UnixTimeToFileTime(fd->modificationTime, (LPFILETIME) FieldValue);
which is implemented:

Code: Select all

 void UnixTimeToFileTime(time_t t, LPFILETIME pft) {
	long long ll;
	ll = Int32x32To64(t, 10000000) + 116444736000000000;
	pft->dwLowDateTime = (DWORD) ll;
	pft->dwHighDateTime = ll >> 32;
}
I even tried to get the time from http://www.epochconverter.com/ and inject it into the variable while debugging to see the result. It was off by several minutes and few hours again. Or I tried to construct the SYSTEMTIME and then used Microsoft's methods to convert that to FILETIME. Again, the same difference - few hours and some minutes off.

I would understand the hours (timezone) but minutes?

I'm desperate, so any information is welcome. Tested with latest TC7.57a and 8.0. VS C++ 2010 Express.

Thanks,
A.
Last edited by Aleq on 2012-04-26, 08:34 UTC, edited 1 time in total.
Aleq
Junior Member
Junior Member
Posts: 55
Joined: 2006-06-07, 07:24 UTC
Location: CZ, EU

Post by *Aleq »

Debugging...
http://img.ctrlv.in/4f98ff4797b6e.jpg
http://img.ctrlv.in/4f98ff32f2e9a.jpg

I'm currently in GMT+3 timezone, so this would explain those hours and I would be ok with that. I would convert the time. But what about those minutes:?: Am I missing something?
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48021
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

I have written an ADB plugin myself (private use, not really ready for release), and I'm also experiencing problems with time zones. At least the seconds are correct. I'm using the following code:

Code: Select all

BOOL UnixTimeToLocalTime(long* mtime,LPFILETIME ft)
{
	if (*mtime==0)
		return false;
    struct tm* fttm=localtime(mtime);  // apparently Android returns local time
	if (fttm==NULL)
		return false;
    SYSTEMTIME st;

    st.wYear=fttm->tm_year;
    if (st.wYear<200)
        st.wYear+=1900;
    st.wMonth=fttm->tm_mon+1;  // 0-11 in struct tm*
    st.wDay=fttm->tm_mday;
    st.wHour=fttm->tm_hour;
    st.wMinute=fttm->tm_min;
    st.wSecond=fttm->tm_sec;
    st.wDayOfWeek=0;
    st.wMilliseconds=0;
    return SystemTimeToFileTime(&st,ft);
}
I tried with localtime(mtime) and gmtime(mtime), but got mixed results - some file times are off by 1 hour, some by two. In the end, I didn't release my ADB plugin because of this timestamp problem.
Author of Total Commander
https://www.ghisler.com
Aleq
Junior Member
Junior Member
Posts: 55
Joined: 2006-06-07, 07:24 UTC
Location: CZ, EU

Post by *Aleq »

Hello Christian,
thank you for your answer. I tried your function but the minutes were off again. I have narrowed down how to simulate it now as even if I enter fixed/manual value, I don't get it correctly in the TC.

This is what I have in [face=courier]int __stdcall FsContentGetValueT(BOOL unicode,WCHAR* FileName,int FieldIndex,int UnitIndex,void* FieldValue,int maxlen,int flags)[/face]:

Code: Select all

long mtime = (long) fd->modificationTime;
GhislersUnixTimeToLocalTime(&mtime, (LPFILETIME) FieldValue);
the function narrowed down to:

Code: Select all

BOOL GhislersUnixTimeToLocalTime(long* mtime,LPFILETIME ft)
{
	SYSTEMTIME st;

	st.wYear=2012;
	st.wMonth=5;
	st.wDay=10;
	st.wHour=13;
	st.wMinute=30;
	st.wSecond=0;
	st.wDayOfWeek=0;
	st.wMilliseconds=0;
	return SystemTimeToFileTime(&st,ft);
}
but I get:
Image: http://img.ctrlv.in/4f997775e39f2.jpg
i.e. 10.05.2012 16:22

I still see this is a fault in TC or...? I'm confused.

Thanks!
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48021
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

What are you comparing the minutes to? I compared them with the minutes shown by Total Commander for Android, and they were the same.

Btw, you are using some strange custom columns view, what fields are you using? Can you try "Full" view instead?
Author of Total Commander
https://www.ghisler.com
Post Reply