/* Download Editor - DMS - April 2002 - by Bob Le Gob */ /* Rev. 1.1 - February 2003 - by Bob Le Gob */ /******************************************************************************* Variables *******************************************************************************/ typeof winEditor = ObjWin;; /* Editor window */ typeof txtFilesReg = ObjText;; /* 2D Objects used for _RSregister part */ typeof butAddReg = ObjButton;; /* Label, Add & delete files buttons .. */ typeof butDelReg = ObjButton;; /* .. List of files, Switch & Apply .. */ typeof lstFilesReg = ObjList;; /* .. buttons */ typeof butSwiReg = ObjButton;; typeof butAppReg = ObjButton;; typeof txtFilesRegF = ObjText;; /* 2D Objects used for _RSregisterF part */ typeof butAddRegF = ObjButton;; /* Same as _RSregister part */ typeof butDelRegF = ObjButton;; typeof lstFilesRegF = ObjList;; typeof butSwiRegF = ObjButton;; typeof butAppRegF = ObjButton;; typeof butGenReport = ObjButton;; /* Button used to generate files info report */ /* InfoFile structure */ struct InfoFile = [sNam:S, /* File name */ sExt:S, /* Lowercase file extension */ iSiz:I, /* File size (KBytes) */ iZip:I, /* Zipped file size (% of file size) */ iReg:I] mkInfoFile;; /* Registration mode: 0-Memory 1-Disk */ typeof lFiles = [InfoFile r1];; /* List of InfoFiles */ typeof tabObjList = tab ObjList;; /* Table used to simplify calls to the 2 existing ObjList objects */ var KW_LOGNAM = "";; /* Variables used for localization of log report */ var KW_LOGSIZ = "";; /* File name, file size and zipped size messages */ var KW_LOGZIP = "";; /******************************************************************************* Functions *******************************************************************************/ /******************************************************************************* GetFileExtension() - Getting extension of file name str -> S : File name, or sub part of file name <- S : File extension *******************************************************************************/ fun GetFileExtension(str) = let strfind "." str 0 -> dotFound in if (dotFound == nil) then strlowercase str else GetFileExtension substr str (dotFound + 1) ((strlen str) - dotFound - 1);; /******************************************************************************* SwitchRegistrationMode2() - Switches the registration mode of a file l -> [InfoFile r1] : List of InfoFiles str -> S : File name p -> I : 0-"reg", 1-"regF" / Source ObjList index for switch <- I : Not used, switch performed *******************************************************************************/ fun SwitchRegistrationMode2(l, str, p) = let hd l -> elt in if !strcmp elt.sNam str then ( _ADDlist tabObjList.(1 - p) 0 str; _SDELlist tabObjList.p str; set elt.iReg = 1 - elt.iReg; ) else SwitchRegistrationMode2 tl l str p;; /******************************************************************************* SwitchRegistrationMode() - Switches the registration mode of a list of files l1 -> [InfoFile r1] : List of InfoFiles l2 -> [[I S] r1] : List of files to switch, selected from the ObjList object p -> I : 0-"reg", 1-"regF" / Source ObjList index for switch <- I : Not used, switches performed *******************************************************************************/ fun SwitchRegistrationMode(l1, l2, p) = if (l2 == nil) then 0 else let hd l2 -> [_ str] in ( SwitchRegistrationMode2 l1 str p; SwitchRegistrationMode l1 tl l2 p; );; /******************************************************************************* RemoveFileFromList() - Removing a file from the lFiles list l -> [InfoFile r1] : List of InfoFiles str -> S : Name of file to be removed <- [InfoFile r1] : Updated list of InfoFiles *******************************************************************************/ fun RemoveFileFromList(l, str) = let hd l -> elt in if !strcmp elt.sNam str then tl l else elt::(RemoveFileFromList tl l str);; /******************************************************************************* cbAddFiles() - Adding files to the lFiles list (Through files selection box) box -> OpenBoxMulti : Files selection dialog box p -> I : 0-"reg" button, 1-"regF" button / Button triggering file selection l -> [P r1] : List of selected files <- I : Not used *******************************************************************************/ fun cbAddFiles(box, p, l) = if l == nil then 0 else ( let _PtoScol hd l -> str in if ((_POSlist tabObjList.p str) == nil) then if ((_POSlist tabObjList.(1 - p) str) == nil) then ( _ADDlist tabObjList.p 0 str; let _getpack hd l -> fileContent in let strlen fileContent -> fileSize in let zip fileContent -> zipContent in let ((100 * (strlen zipContent)) / fileSize) -> zipSize in let mkInfoFile [str (GetFileExtension str) (fileSize / 1024) zipSize p] -> newInfoFile in set lFiles = newInfoFile::lFiles; 0; ) else ( SwitchRegistrationMode2 lFiles str (1 - p); 0; ) else 0; cbAddFiles box p tl l; );; /******************************************************************************* AddFile() - Adding file to the lFiles list (When loading module parameters) str -> S : File name p -> I : 0-"reg" , 1-"regF" / Type of file registration <- I : Not used This function is needed because of a bug in the _checkpack() function which turns in some way a file path to its lowercase value. So using the previous (cbAddFiles) function doesn't work properly if feeding the P type through a _checkpack() instead of a file selection box. Testing bug: _fooS _PtoScol _checkpack "test1.test2.TXT"; *******************************************************************************/ fun AddFile(str, p) = if ((_POSlist tabObjList.p str) == nil) then if ((_POSlist tabObjList.(1 - p) str) == nil) then ( _ADDlist tabObjList.p 0 str; let _getpack _checkpack str -> fileContent in let strlen fileContent -> fileSize in let zip fileContent -> zipContent in let ((100 * (strlen zipContent)) / fileSize) -> zipSize in let mkInfoFile [str (GetFileExtension str) (fileSize / 1024) zipSize p] -> newInfoFile in set lFiles = newInfoFile::lFiles; 0; ) else ( SwitchRegistrationMode2 lFiles str (1 - p); 0; ) else 0;; /******************************************************************************* DelFiles() - Deleting files from the lFiles list l -> [[I S] r1] : List of files to delete, selected from the ObjList object p -> I : 0-"reg" button, 1-"regF" button / Button triggering file deletion -> I : Not used *******************************************************************************/ fun DelFiles(l, p) = if l == nil then 0 else ( let hd l -> [_ str] in ( _SDELlist tabObjList.p str; set lFiles = RemoveFileFromList lFiles str; ); DelFiles tl l p; );; /******************************************************************************* ApplyFilesExt2() - Applying registration mode to files with specific extension l -> [InfoFile r1] : List of InfoFiles str -> S : Source file extension p -> I : 0-"reg", 1-"regF" / Source ObjList index for apply <- I : Not used, processing performed *******************************************************************************/ fun ApplyFilesExt2(l, str, p) = if (l == nil) then 0 else let hd l -> elt in if ((!strcmp elt.sExt str) && (elt.iReg != p)) then ( SwitchRegistrationMode2 lFiles elt.sNam (1 - p); ApplyFilesExt2 tl l str p; ) else ApplyFilesExt2 tl l str p;; /******************************************************************************* ApplyFilesExt() - Applying registration mode to files with same extensions l1 -> [InfoFile r1] : List of InfoFiles l2 -> [[I S] r1] : List of files to process, selected from the ObjList object p -> I : 0-"reg", 1-"regF" / Source ObjList index for apply <- I : Not used, processing performed *******************************************************************************/ fun ApplyFilesExt(l1, l2, p) = if (l2 == nil) then 0 else let hd l2 -> [_ str] in ( ApplyFilesExt2 l1 (GetFileExtension str) p; ApplyFilesExt l1 tl l2 p; );; /******************************************************************************* GenerateFilesInformationReport() - Generates files information in log l1 -> [InfoFile r1] : List of InfoFiles <- S : Not used *******************************************************************************/ fun GenerateFilesInformationReport(l) = if (l == nil) then "" else let hd l -> elt in ( _fooS strcatn KW_LOGNAM::elt.sNam::KW_LOGSIZ::(itoa elt.iSiz)::KW_LOGZIP::(itoa elt.iZip)::"%"::nil; GenerateFilesInformationReport tl l; );; /******************************************************************************* SaveSupplementalData() - Saving supplemental DMI data l -> [InfoFile r1] : List of InfoFiles <- [[S r1] r1] : Supplemental data *******************************************************************************/ fun SaveSupplementalData(l) = if (l == nil) then nil else let hd l -> elt in if (elt.iReg == 0) then ("fd_reg"::(elt.sNam)::nil)::(SaveSupplementalData tl l) else ("fd_regF"::(elt.sNam)::nil)::(SaveSupplementalData tl l);; /******************************************************************************* Editor's main callbacks *******************************************************************************/ /******************************************************************************* cbRflSizewinEditor() - Editor's window resize callback win -> ObjWin : Editor's window p -> u0 : Not used w -> I : Window width h -> I : Window height <- I : Not used *******************************************************************************/ fun cbRflSizewinEditor (win, p, w, h)= let ((w / 2) - 4) -> tmpW in let ((w / 2) + 2) -> tmpX in let (h - 136) -> tmpH in ( _SIZEtext txtFilesReg tmpW 20 2 2; _SIZEbutton butAddReg tmpW 20 2 24; _SIZEbutton butDelReg tmpW 20 2 46; _SIZElist lstFilesReg tmpW tmpH 2 68; _SIZEbutton butSwiReg tmpW 20 2 (h - 66); _SIZEbutton butAppReg tmpW 20 2 (h - 44); _SIZEtext txtFilesRegF tmpW 20 tmpX 2; _SIZEbutton butAddRegF tmpW 20 tmpX 24; _SIZEbutton butDelRegF tmpW 20 tmpX 46; _SIZElist lstFilesRegF tmpW tmpH tmpX 68; _SIZEbutton butSwiRegF tmpW 20 tmpX (h - 66); _SIZEbutton butAppRegF tmpW 20 tmpX (h - 44); _SIZEbutton butGenReport (w - 4) 20 2 (h - 22); ); 0;; /******************************************************************************* cbClick_butAdd() - "Adding files" button click callback but -> ObjButton : Clicked button (but button is in fact identified through p) p -> I : 0-"reg" button, 1-"regF" button <- I : Not used *******************************************************************************/ fun cbClick_butAdd(but, p) = _DLGrflopenMulti (_DLGOpenFileMulti _channel nil nil nil nil) @cbAddFiles p; 0;; /******************************************************************************* cbClick_butDel() - "Deleting files" button click callback but -> ObjButton : Clicked button (but button is in fact identified through p) p -> I : 0-"reg" button, 1-"regF" button <- I : Not used *******************************************************************************/ fun cbClick_butDel(but, p) = DelFiles _GETlistMSel tabObjList.p p; 0;; /******************************************************************************* cbClick_butSwi() - "Switching files registration mode" button click callback but -> ObjButton : Clicked button (but button is in fact identified through p) p -> I : 0-"reg" button, 1-"regF" button <- I : Not used *******************************************************************************/ fun cbClick_butSwi(but, p) = SwitchRegistrationMode lFiles _GETlistMSel tabObjList.p p; 0;; /******************************************************************************* cbClick_butApp() - "Applying files registration mode" button click callback but -> ObjButton : Clicked button (but button is in fact identified through p) p -> I : 0-"reg" button, 1-"regF" button <- I : Not used *******************************************************************************/ fun cbClick_butApp(but, p) = ApplyFilesExt lFiles _GETlistMSel tabObjList.p p; 0;; /******************************************************************************* cbClick_butGen() - "Generating files information report" button click callback but -> ObjButton : Clicked button (but button is in fact identified through p) p -> I : 0-"reg" button, 1-"regF" button <- I : Not used *******************************************************************************/ fun cbClick_butGen(but, p) = _fooS "*****************************************************"; _fooS _locEditor "KW_REPSTA" nil; GenerateFilesInformationReport lFiles; _fooS _locEditor "KW_REPEND" nil; _fooS "*****************************************************"; 0;; /******************************************************************************* cbSave() - Standard callback - Saving parameters filename -> S : Not used n -> S : Not used <- [[S r1] r1] : DMI block *******************************************************************************/ fun cbSave(filename, n)= ("action"::"start"::nil):: ("action"::"destroy"::nil):: ("event"::"started"::nil):: ("event"::"destroyed"::nil):: ("event"::"ended"::nil):: ("eventC"::"downloadStarted"::nil):: ("eventC"::"downloadCompleted"::nil):: ("eventC"::"registerDownload"::nil):: ("eventC"::"registerFile"::nil):: SaveSupplementalData lFiles;; /******************************************************************************* cbLoad() - Standard callback - Loading parameters l -> [[S r1] r1] : DMI block <- I : Not used *******************************************************************************/ fun cbLoad(l)= if (l == nil) then 0 else let hd l -> [h t] in if !strcmp h "fd_reg" then ( if ((_checkpack hd t) != nil) then ( AddFile hd t 0; 0; ) else ( _DLGMessageBox _channel nil (_locEditor "KW_REGERR" nil) (hd t) 0; 0; ); cbLoad tl l; ) else if !strcmp h "fd_regF" then ( if ((_checkpack hd t) != nil) then ( AddFile hd t 1; 0; ) else ( _DLGMessageBox _channel nil (_locEditor "KW_REGERR" nil) (hd t) 0; 0; ); cbLoad tl l; ) else cbLoad tl l;; /******************************************************************************* Editor's main function *******************************************************************************/ /******************************************************************************* IniEditor() - Standard IniEditor function param -> S : Not used <- I : Not used *******************************************************************************/ fun IniEditor(param)= let [640 288] -> [w h] in let ((w / 2) - 4) -> tmpW in let ((w / 2) + 2) -> tmpX in let (h - 136) -> tmpH in let startEditor _channel nil 0 0 w h WN_MENU EDITOR_NORMAL nil nil nil nil @cbLoad @cbSave nil -> ed in ( set lFiles = nil; set winEditor = getEditWin ed; set txtFilesReg = _CRtext _channel winEditor 2 2 tmpW 20 ET_ALIGN_CENTER|ET_BORDER _locEditor "KW_REG" nil; set butAddReg = _CRbutton _channel winEditor 2 24 tmpW 20 0 _locEditor "KW_ADD" nil; set butDelReg = _CRbutton _channel winEditor 2 46 tmpW 20 0 _locEditor "KW_DELETE" nil; set lstFilesReg = _CRlist _channel winEditor 2 68 tmpW tmpH LB_VSCROLL|LB_BORDER|LB_MULTIPLE; set butSwiReg = _CRbutton _channel winEditor 2 (h - 66) tmpW 20 0 _locEditor "KW_SWITCH" nil; set butAppReg = _CRbutton _channel winEditor 2 (h - 44) tmpW 20 0 _locEditor "KW_APPLY" nil; _CBbutton butAddReg @cbClick_butAdd 0; _CBbutton butDelReg @cbClick_butDel 0; _CBbutton butSwiReg @cbClick_butSwi 0; _CBbutton butAppReg @cbClick_butApp 0; set txtFilesRegF = _CRtext _channel winEditor tmpX 2 tmpW 20 ET_ALIGN_CENTER|ET_BORDER _locEditor "KW_REGF" nil; set butAddRegF = _CRbutton _channel winEditor tmpX 24 tmpW 20 0 _locEditor "KW_ADD" nil; set butDelRegF = _CRbutton _channel winEditor tmpX 46 tmpW 20 0 _locEditor "KW_DELETE" nil; set lstFilesRegF = _CRlist _channel winEditor tmpX 68 tmpW tmpH LB_VSCROLL|LB_BORDER|LB_MULTIPLE; set butSwiRegF = _CRbutton _channel winEditor tmpX (h - 66) tmpW 20 0 _locEditor "KW_SWITCH" nil; set butAppRegF = _CRbutton _channel winEditor tmpX (h - 44) tmpW 20 0 _locEditor "KW_APPLY" nil; _CBbutton butAddRegF @cbClick_butAdd 1; _CBbutton butDelRegF @cbClick_butDel 1; _CBbutton butSwiRegF @cbClick_butSwi 1; _CBbutton butAppRegF @cbClick_butApp 1; set butGenReport = _CRbutton _channel winEditor 2 (h - 22) (w - 4) 20 0 _locEditor "KW_REPORT" nil; _CBbutton butGenReport @cbClick_butGen nil; set tabObjList = mktab 2 nil; set tabObjList.0 = lstFilesReg; set tabObjList.1 = lstFilesRegF; set KW_LOGNAM = _locEditor "KW_LOGNAM" nil; set KW_LOGSIZ = _locEditor "KW_LOGSIZ" nil; set KW_LOGZIP = _locEditor "KW_LOGZIP" nil; _CBwinSize winEditor @cbRflSizewinEditor 0; openDMI ed; ); 0;;