/* Download Client - DMS - April 2002 - by Bob Le Gob */ /* Rev. 1.1 - February 2003 - by Bob Le Gob */ /******************************************************************************* Variables *******************************************************************************/ typeof lRcvd = [[S r1] r1];; /* List of files to download, with their sizes */ /* [[filename [filesize _]] r1] */ var filesCount = 0;; /* Number of files to download */ var totalBytes = 0;; /* Number of bytes to download */ var dwnldBytes = 0;; /* Number of downloaded bytes */ /******************************************************************************* Functions *******************************************************************************/ /******************************************************************************* Functions: Downloading files *******************************************************************************/ /******************************************************************************* GetFileSize() - Retrieves the size of a file in lRcvd. str -> S : File name l -> [[S r1] r1] : lRcvd <- I : File size *******************************************************************************/ fun GetFileSize(str, l) = if !strcmp str hd hd l then atoi hd tl hd l else GetFileSize str tl l;; /******************************************************************************* cbFileDownloaded() - Callback called each time a file has been downloaded file -> S : File name <- I : Not used *******************************************************************************/ fun cbFileDownloaded(file)= set filesCount = filesCount + 1; set dwnldBytes = dwnldBytes + GetFileSize file lRcvd; _DMSevent this "registerFile" (itoa GetFileSize file lRcvd) nil; if filesCount == sizelist lRcvd then _DMSevent this "downloadCompleted" nil nil else 0; 0;; /******************************************************************************* DownloadFiles() - Starts the download of files in lRcvd l -> [[S r1] r1] : lRcvd <- [[S r1] r1] : Not used *******************************************************************************/ fun DownloadFiles(l) = if l == nil then l else ( _RSCdownload this hd hd l hd hd l @cbFileDownloaded 1; DownloadFiles tl l; );; /******************************************************************************* ComputeTotalSize() - Computes the sum of all lRcvd files sizes l -> [[S r1] r1] : lRcvd n -> I : Current sum <- I : Computed sum *******************************************************************************/ fun ComputeTotalSize(l, n) = if l == nil then n else ( let hd tl hd l -> size in set n = n + atoi size; ComputeTotalSize tl l n; );; /******************************************************************************* StartDownload() - Initiates lRcvd files download l -> [[S r1] r1] : lRcvd <- I : Not used *******************************************************************************/ fun StartDownload(l) = set filesCount = 0; set totalBytes = ComputeTotalSize lRcvd 0; set dwnldBytes = 0; _DMSevent this "downloadStarted" nil nil; _DMSevent this "registerDownload" (itoa totalBytes) nil; DownloadFiles l; 0;; /******************************************************************************* Functions: Module instanciation *******************************************************************************/ /******************************************************************************* Standard IniDMI param -> S : Parameter from server - List of files to download - strbuild format <- I : Not used *******************************************************************************/ fun IniDMI(param)= set lRcvd = strextr param; StartDownload lRcvd; 0;;