🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.readers
Article #145749

[dialog] script: compact database reminder

#145749
From: matija
Date: Sun, 04 Apr 2004 16:52
163 lines
7733 bytes
here's a new script. it's not on wiki, since wiki is a demonic spawn
which won't easily let me add a page (either that, or i'm an idiot,
which i highly doubt; i don't think i've ever seen a content management
system that was less intuitive than this wiki sh*t).


-----


// an onShutDown script that reminds you to compact your database :)
// written by matija krnic (matija.krnic -at- zg.htnet.hr)

// this script only works properly on NTFS file systems, as FAT doesn't
// have the "last created" date/time, just the "last modified" one.
// there's a workaround, but it'll fail each time you set the default
// group options. if you don't touch them (which is, i guess, what most
// people do since you don't need to alter them after you've configured
// them once), the script works normally.


program OnShutdown;


const
  // the path to the 'default.ini' file in your dialog's data folder
  myDialogDataINI = 'c:\program files\40tude dialog\data\default.ini';

  // set this to true if dialog's installed on a FAT partition
  hackFAT = false;
  
  // the time that needs to pass between the last compaction date and
  // the current time. the number is specified in days and defaults to 7,
  // but fractions are possible: 7.5 would warn you if seven and a half
  // days passed since the last time the database was compacted.
  remindAfter = 7;

  // the text in the message box that pops up when it's time to compact.
  // the '%days%' variable will contain the number specified above.  
  // the '%lastcompact%' variable will contain the date and time
  // the database was last compacted on.
  mbReminderWarning = 'Your database was last compacted on %lastcompact% and it''s already been more than %days% day(s) since. Compact now?';
  
  // message box caption
  mbCaption = 'Compact database reminder';



// ----------------------------------------------------------------------
// nothing to change down below, go away! ;)
// ----------------------------------------------------------------------


type
  // this holds the date and time for a file
  tFileTime = record
    dwLowDateTime: integer;
    dwHighDateTime: integer;
  end;

  // and this holds the actual, readable stuff
  tSystemTime = record
    wYear: Word;
    wMonth: Word;
    wDayOfWeek: Word;
    wDay: Word;
    wHour: Word;
    wMinute: Word;
    wSecond: Word;
    wMilliseconds: Word;
  end;


const
  // createFile() constants
  GENERIC_READ = $80000000;
  FILE_SHARE_READ = $00000001;
  FILE_ATTRIBUTE_NORMAL = $00000080;
  OPEN_EXISTING = 3;

  // message box constants
  MB_YESNO = 4; 
  IDYES = 6;
  IDNO = 7;

  
var
  // holds the file handle
  fHandle : integer;      

  // tFileTime variables; we only use the creation time in this script
  myCreationTime, myLastAccessTime, myLastWriteTime : tFileTime;
  
  // the original file date and time
  myUTCSystemTime : tSystemTime;
  
  // file date and time with time zone compensation
  mySystemTime : tSystemTime;
  
  // these will hold the date and time values in pascal-usable form
  myFileDate, myFileTime, myFileDateTime : tDateTime;
  
  // the final messagebox string
  myReminderWarning : string;


// imported functions. god bless delphi's RTL source and the wonders of copy and paste.
function CreateFile(lpFileName: PChar; dwDesiredAccess, dwShareMode: integer; lpSecurityAttributes: pchar; dwCreationDisposition, dwFlagsAndAttributes: integer; hTemplateFile: THandle): THandle; external 'CreateFileA@kernel32.dll stdcall';
function CloseHandle(hObject: THandle): boolean; external 'CloseHandle@kernel32.dll stdcall';
function GetFileTime(hFile: integer; var lpCreationTime, lpLastAccessTime, lpLastWriteTime: tFileTime): boolean; external 'GetFileTime@kernel32.dll stdcall';
function FileTimeToSystemTime(lpFileTime: TFileTime; var lpSystemTime: TSystemTime): boolean; external 'FileTimeToSystemTime@kernel32.dll stdcall';
function SystemTimeToTzSpecificLocalTime(lpTimeZoneInformation: pchar; var lpUniversalTime, lpLocalTime: TSystemTime): boolean; external 'SystemTimeToTzSpecificLocalTime@kernel32.dll stdcall';
function MessageBox(hWnd: longword; lpText, lpCaption: PChar; uType: longword): Integer; external 'MessageBoxA@user32.dll stdcall';


procedure OnShutdown;
Begin
  // we need a special file handle, normal ones won't do
  fHandle := createFile(myDialogDataINI, GENERIC_READ, FILE_SHARE_READ, null, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, null);

  // obtain the file creation, access and modified times
  getFileTime(fHandle, myCreationTime, myLastAccessTime, myLastWriteTime);
  closeHandle(fHandle); 
  
  // FAT file system "workaround"
  if hackFAT
    // transform last modified file time into system time
    then fileTimeToSystemTime(myLastWriteTime, myUTCSystemTime)
    // transform creation file time into system time
    else fileTimeToSystemTime(myCreationTime, myUTCSystemTime);
  
  // compensate for the local time zone
  systemTimeToTzSpecificLocalTime(null, myUTCSystemTime, mySystemTime);

  // encode the system time into two tDateTime structures and merge them  
  myFileDate := encodeDate(mySystemTime.wYear, mySystemTime.wMonth, mySystemTime.wDay);
  myFileTime := encodeTime(mySystemTime.wHour, mySystemTime.wMinute, mySystemTime.wSecond, mySystemTime.wMilliseconds);
  myFileDateTime := myFileDate + myFileTime;

  // check the number of days that have passed between the current date/time
  // and the last compact date
  if (now - myFileDateTime) >= remindAfter then
  begin
    // replace the '%date%' in the reminder warning text with the actual number
    // and the '%lastcompact%' with the string-formatted last compact date
    myReminderWarning := stringReplace(mbReminderWarning, '%days%', floatToStrF(remindAfter, ffGeneral, 15, 1), [rfReplaceAll]);
    myReminderWarning := stringReplace(myReminderWarning, '%lastcompact%', dateTimeToStr(myFileDateTime), [rfReplaceAll]);

    // pop up a message box and see if the user wants to compact
    if (MessageBox(null, myReminderWarning, mbCaption, MB_YESNO) = IDYES) then ADo('CompactDatabase');     
  end;    

End; // procedure onShutDown


begin
end.


-- 
there is a cheer. the gnomes have learned a new way to say hooray.   [-shpongle]

address is scrambled - remove the superfluous "x" marks to reply
Technical Details
Message-ID: <1jnckibgz1cn$.dlg@shpongle.604>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.readers.20140922.mbox.gz!number1.nntp.ash.giganews.com!internal1.nntp.sjc.giganews.com!border2.nntp.sjc.giganews.com!border1.nntp.sjc.giganews.com!nntp.giganews.com!peer01.cox.net!cox.net!fu-berlin.de!CARNet.hr!not-for-mail

Show Full Headers
Complete Article Headers
Message-ID: <1jnckibgz1cn$.dlg@shpongle.604>
Subject: [dialog] script: compact database reminder
Date: Sun, 4 Apr 2004 18:52:13 +0200
From: matija <xmkrnicx@xpublicx.xsrcex.hr>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.readers.20140922.mbox.gz!number1.nntp.ash.giganews.com!internal1.nntp.sjc.giganews.com!border2.nntp.sjc.giganews.com!border1.nntp.sjc.giganews.com!nntp.giganews.com!peer01.cox.net!cox.net!fu-berlin.de!CARNet.hr!not-for-mail
Newsgroups: news.software.readers
Organization: 604
Lines: 163
NNTP-Posting-Host: cmung2765.cmu.carnet.hr
Mime-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
X-Trace: bagan.srce.hr 1081097522 14531 193.198.138.225 (4 Apr 2004 16:52:02
 GMT)
X-Complaints-To: abuse@carnet.hr
NNTP-Posting-Date: Sun, 4 Apr 2004 16:52:02 +0000 (UTC)
User-Agent: 40tude_Dialog/2.0.9.1hr (c371ced3.431.17)
X-Afraid-Of: spiders
X-Face: "wB!^cgWZ=;
 q%#:6lkzMWJ-O*>}<FSIu#HEqp5P2E#=mTGgQ-\^YM|Vt(j_|:*GI8?,7A9Z
 mkgCj|$f)nB@*>(B14sXotbL/"G.Z0u$]5\GcxnO4')%FUE\48H!!$rCLV.`
X-Mastered: the art of pizza making
X-Searching-For: GMT soundtrack (guy sigsworth)