#Time/Date restore after Battery replacement (if backup cap/battery is empty) # # By Avi Halachmi (http://smoothwheel.mozdev.org, avihpit [at] yahoo [dot] com) # Version 0.1, 2009-04-07 # # License: GPL V2 # #- Usage: # 1. Place This script on your internal drive (not COMPACFLASH/SD), # 2. Place a shortcut to this script on \WINDOWS\Startup # #- Uninstall: delete this script and the shortcut on the startup folder and reboot (or kill the mortscript task with a task manager) # #- It will automatically restore the time/date after a restart if the date was reset #- (Requires mortscript installed: http://www.sto-helit.de/) # # How it works: # - The script updates a small file with the current date/time every 30s # - On invocation (after reboot): restore previous time if detects a time reset # # - Tested on Dell Axim x51v, but should work on any platform where mortscript is supported # logfile= SystemPath("ScriptPath")\SystemPath("ScriptName")&".log" stampfile=SystemPath("ScriptPath")\SystemPath("ScriptName")&".timestamp" resolution=30 lastKnown = FileModifyTime(stampFile) now = TimeStamp() Call ("Log", "Starting. last=" & lastKnown) If (lastKnown > 0) If (lastKnown > now + 24*60*60) Call ("RestoreTime") Call ("Log", "Reset detected. Time restored") Else Call ("Log", "OK - no restore needed") EndIf Else Call ("Log", "First time run"); Endif Call ("Log", "", TRUE) While (TRUE) Call ("TouchTimestamp"); Sleep(resolution*1000); EndWhile #Call ("Log" , data [,]) Sub Log prefix=FormatTime("Y-m-d H:i:s") & ": " if (argv[2]) prefix="" EndIf WriteFile(logFile, prefix & argv[1] & "^NL^", TRUE) EndSub Sub TouchTimestamp WriteFile(stampfile, TimeStamp()) dummy4flush=ReadFile(stampfile) EndSub Sub RestoreTime r = 15 + resolution/2 + FormatTime("s", now) + 60*FormatTime("i", now) Call ("Log", "Adding " & r & "s to last valid time") r = r + lastKnown SetTime( FormatTime("H", r), FormatTime("i", r), FormatTime("d", r), FormatTime("d", r), FormatTime("m", r), FormatTime("Y", r) ) EndSub