mIRC Home    About    Download    Register    News    Help

Print Thread
#39238 01/08/03 11:03 PM
Joined: Dec 2002
Posts: 5
M
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
M
Joined: Dec 2002
Posts: 5
I'm actually expanding some things in my dll and want to convert the size of an file listing (findfirst + findnext).
I get an FILETIME struct (from MSDN: "The FILETIME structure is a 64-bit value representing the number of 100-nanosecond intervals since January 1, 1601 (UTC).") from WIN32_FIND_DATA containing the times (one for creation, one for last access, one for last modified) and want to convert it to a format mIRC can handle (time_t i think, like the return of $ctime in mIRC), so it can be formatted with $asctime() by mirc or the asctime() function of my dll. (asctime is defined in time.h i think).

My problem is, that i tried to convert it, but nearly all values were wrong. Even a converting by a given function like FileTimeToSystemTime() is incorrect. (although the difference seems to be constante 2 hours, maybe something with timezones?)

Does anyone know how to convert the size correctly? (with code would be nice wink)
I tried to "turn around" MSDN example , this returned sometimes a nearly correct time (3 secs more or less than mIRC), but sometimes one day and 3 secs more / less.

Joined: Dec 2002
Posts: 2,809
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 2,809
Seeing as how you're saying the difference is a constant 2 hours, that makes it sound like thats a result of a timezone. The text you have there is in UTC (which is the same as GMT). My guess is your timezone is either +/- 2 hours from GMT. If you could paste the actual C/C++ code, it would probably be easier to find the solution.

Think I might have figured out what you need to do. After you call GetFileTime, call FileTimeToLocalFileTime, then call FileTimeToSystemTime.

Last edited by codemastr; 01/08/03 11:17 PM.
Joined: Dec 2002
Posts: 5
M
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
M
Joined: Dec 2002
Posts: 5
I think I know now the reason why the difference is two hours. One hour cause of GMT +1 (germany), but i was confused why two and not one, but I think the reason is, that we've (in germany) another time in winter and summer (to compensate the "shorter days" in winter... or whatever).

The code I use is:

char * file_name = data->cFileName;
FILETIME file_time = data->ftCreationTime;
SYSTEMTIME system_time;
FileTimeToSystemTime(&file_time, &system_time);

char temp[1000];
sprintf(temp, "%s - %d:%d:%d (%d) %d.%d.%d", file_name, system_time.wHour, system_time.wMinute, system_time.wSecond, system_time.wMilliseconds, system_time.wDay, system_time.wMonth, system_time.wYear);

MessageBox(mirc, temp, "", MB_OK);


But what I want is code like $ctime (to use $asctime) if possible, so I tried to use this:

char * file_name = data->cFileName;
UINT64 utc = UInt32x32To64((data->ftCreationTime).dwHighDateTime, MAXDWORD);
utc += (UINT64) (data->ftCreationTime).dwLowDateTime;
UINT64 utc_secs = (UINT64)(utc / (UINT64) 10000000);
DWORD mirc_secs = (DWORD)(utc_secs - (UINT64) 11644473600);
char temp[1000];
sprintf(temp, "%u", mirc_secs);
MessageBox(mirc, temp, "", MB_OK);

The code is based on the example I gave (btw php seems to use somethink similiar to this way). I find it confusing, that the time seams to be correct on most files (no problem with the +1 or 2 hours), but on some files, the date is incorrect, for example

explorer: 22.03.2003 12:54:26 (day.month.year hour:minute:seconds)

my code: Sat Mar 22 11:54:23 2003

There is a difference of 23 hours and three seconds, and I don't know why. btw, EVERY file has the difference of 3 seconds. don't ask me why.

Joined: Dec 2002
Posts: 2,809
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 2,809
To be honest, I think the best way to do this is to abandon WinAPI. I say, use the standard C function, you'll make two function calls, instead of that huge ugly code you have there. If you are using MSVC++, I think it calls the function _stat(), if you are using another compiler it is probably stat().

#include <sys/types.h>
#include <sys/stat.h>
struct _stat sb;

_stat("path/to/the/file.extension", &sb);
sprintf(temp, "%u", sb.st_ctime);

That will do the same thing as all that ugly code you have to have to work with a FILETIME.

Edit:
MSVC++ also calls the struct _stat, other compilers call it stat.

Last edited by codemastr; 02/08/03 03:41 AM.
Joined: Dec 2002
Posts: 5
M
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
M
Joined: Dec 2002
Posts: 5
thx, I'll use this code.
Do you know if it will work on non-NTFS drives? for example $file().ctime in mirc also works on FAT drives, but i can't try it (all my drives are NTFS)

Joined: Dec 2002
Posts: 2,809
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 2,809
Yes it works fine on FAT32, thats what I use and it works fine for me smile


Link Copied to Clipboard