/* (C) 2003-2007 Willem Jan Hengeveld * Web: http://www.xs4all.nl/~itsme/ * http://wiki.xda-developers.com/ * * $Id$ * * to start this util automatically each time a device is cradled: * * [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows CE Services\AutoStartOnConnect] * "psynctime"="c:\\path-to\\psynctime.exe" * * todo: better algorithm: * pct0 pc -> [pct0] * -> dev dvt0 * [dvt0] <- dev * pct1 pc <- * pc -> [pct1] * -> dev dvt1 * {pct0,dvt0,pct1} {pct0,dvt0,pct1,dvt1} * * determines when the systemtime is updated */ #include #include #include #include #include #include "debug.h" #include "args.h" #include "itsutils.h" #include "dllversion.h" bool ITSetSystemTime(bool bSetLocal, bool bSetSystem, bool bSetTz, SYSTEMTIME *time, TIME_ZONE_INFORMATION *tzinfo); bool ITGetSystemTime(bool bGetLocal, SYSTEMTIME *time, TIME_ZONE_INFORMATION *tzinfo, DWORD *ptzid); int64_t calcftdiff(const FILETIME& t0, const FILETIME& t1) { return (*(uint64_t*)&t0) - (*(uint64_t*)&t1); } void ftadd(FILETIME& ft, int64_t off) { *(uint64_t*)&ft += off; } void writetdiff(int64_t tdiff) { char sign= ' '; if (tdiff<0) { sign= '-'; tdiff=-tdiff; } debug("difference: %c%I64d.%07d sec\n", sign, tdiff/10000000LL, (int)(tdiff%10000000LL)); } void usage() { printf("(C) 2003-2008 Willem jan Hengeveld itsme@xs4all.nl\n"); printf("Usage: psynctime [-l | -s] [-t] [-v]\n"); printf(" -l : set local time\n"); printf(" -s : set system time\n"); printf(" -t : set timezone\n"); printf(" -v : verbose\n"); printf(" -q : query only\n"); } int main( int argc, char *argv[]) { DebugStdOut(); bool bAdjustsyst= false; bool bSetLocal= false; bool bSetSystem= true; // bool bUseRapicall= false; bool bSetTz= true; bool bVerbose= false; int nRepeat=5; for (int i=1 ; itime), sizeof(SYSTEMTIME)); memcpy(tzinfo, &(outbuf->tzinfo), sizeof(TIME_ZONE_INFORMATION)); *ptzid= outbuf->tzid; RapiFree(outbuf); } return res==0; }