//v0.4.1 - 11/2o14 //- min version added //- lots of new stuff //v0.4.2 - 11/2o14 //- added resource center urls for some commands //- added support for german h&p directory opus forum //- added experimental caching of column data (do not enable for regular use) //v0.4.3 - 11/2o14 //- MD5 hash creation bugfix //- german forum download bugfix //- upload prepared files will be automatically converted to unicode (utf16) //- downloads always treated binary //v.0.5 - 12/2o14 //- ul/li tags filtered to prevent thread-parsing error //- column cache activated by default //- winXP error-dialog fix on initialization //- about-dialog error fix for multiple or no listers //todo //- enhance progress dialog handling /////////////////////////////////////////////////////////////////////////////// function OnInit(data){ var uid = "D4072BDA-B049-4A11-8B40-266E083D6F2D"; var url = "http://resource.dopus.com/viewtopic.php?f=35&t=23179"; data.name = "Command.Generic: ScriptWizard"; data.desc = "Helps to maintain, handle and update scripting resources"; data.copyright = "tbone"; data.version = "0.5"; data.default_enable = true; data.min_version = "11.7.1"; if (DOpus.Version.AtLeast("11.8.2")) data.log_prefix = "SW"; var cmd = data.AddCommand(); cmd.name = "ScriptAbout" cmd.method = "Command_ScriptAbout"; cmd.desc = "Multifunctional about dailog for scripting resources"; cmd.template = "FILE/K,WIN/K"; var cmd = data.AddCommand(); cmd.name = "ScriptWizard" cmd.method = "Command_ScriptWizard"; cmd.desc = data.desc; cmd.template = "ABOUT/S,UPDATE/S,ARCHIVE/S,VISIT/S,OPENLOG/S,ALL/S,FILE/K,FOLDER/K,CHECK/S,FORCE/S,INTERACTIVE/S,SHOWRESULTS/S,UPDATEOFFER/S,PREPAREUPLOAD/S,UPDATEHASH/S,PROGRESS/S,WIN/K"; /////////////////////////////////////////////////////////////////////////// function ConfigHelper(data){ this.data=data; this.descriptions=null; this.last=null; this.add = function(name, val, description){ this.data.config[name]=val; this.last=[this.data.config[name],name]; if (description!=undefined) this.des(description); return this;} this.des = function(description){ if (!(description && DOpus.version.AtLeast("11.6.1"))) return this; if (!this.descriptions){ this.descriptions=DOpus.NewMap(); data.config._descriptions=this.descriptions; } this.descriptions(this.last[1])=description; return this;} this.val = function(val){ if (typeof this.last[0]=="object") this.last[0].push_back(val); else this.last[0]=val; return this;} } /////////////////////////////////////////////////////////////////////////// var cfg = new ConfigHelper(data); cfg.add("Archive.Path", "/dopusdata\\script addins\\archive"). des("Folder path where to store archived scripts."); cfg.add("Log.ToConsole", true). des("Enable update output in the script console."); cfg.add("Log.Level", DOpus.Create.Vector()). des("Log level, 'normal' is the recommended setting. Use 'trace' or 'dump' for extended troubleshooting."). val(4).val("Exceptions").val("Errors").val("Warning").val("Info").val("Normal").val("Trace").val("Dump"); cfg.add("Log.ToFile", true). des("Enable output to log file."); cfg.add("Log.ToFile.Path", "/dopusdata\\logs\\ScriptWizard.log.txt"). des("Log file path."); cfg.add("Columns.Cache", true). des("Enable caching of script detail columns."); } /////////////////////////////////////////////////////////////////////////////// var COMMAND_ABORTED = true; var COMMAND_SUCCEEDED = false; var FSMagic = new FSMagic(); var ResParser = new DOResourceParser(); //////////////////////////////////////// /////////////////////////////////////// try { var deprecatedScriptPath = "Command.Generic_ScriptHelper.js"; deprecatedScriptPath = DOpus.FSUtil.Resolve("/dopusdata\\script addins")+ "\\"+deprecatedScriptPath; if (ResParser.fso.FileExists(deprecatedScriptPath)) ResParser.fso.DeleteFile(deprecatedScriptPath); if (ResParser.fso.FileExists(deprecatedScriptPath+'.txt')) ResParser.fso.DeleteFile(deprecatedScriptPath+'.txt'); if (Script); //will fail here on script (re)load once var out = new DebugOutput(). level( Script.config["Log.Level"] ). //set debug level from script config console(Script.config["Log.ToConsole"]). buffer(true). mute(); //mute until used //out._keepInds = true; if (Script.config["Log.ToFile"] && Script.config["Log.ToFile.Path"]) out.append(DOpus.FSUtil.Resolve(Script.config["Log.ToFile.Path"])); } catch(e){ //DOpus.Output("Loaded successfully!"); } /////////////////////////////////////////////////////////////////////////////// function Command_ScriptAbout(data){ //deprecated, do not use! out.mute(false); data.func.command.ClearFiles(); out.trc("ScriptAbout():",1); var p = { file : GetParameter(data, "FILE", null, ""), win : GetParameter(data, "WIN", null, "") } var ad = new AboutDialog( p.file, p.win); ad.Init(); ad.Show(); out.reset(); } /////////////////////////////////////////////////////////////////////////////// function Command_ScriptWizard(data){ out.mute(false); out.trc("ScriptWizard():",1); data.func.command.ClearFiles(); var result = COMMAND_SUCCEEDED; var p = { about : GetParameter(data, "ABOUT", null, false), update : GetParameter(data, "UPDATE", null, false), archive : GetParameter(data, "ARCHIVE", null, false), visit : GetParameter(data, "VISIT", null, false), openLog : GetParameter(data, "OPENLOG", null, false), all : GetParameter(data, "ALL", null, false), file : GetParameter(data, "FILE", null, ""), folder : GetParameter(data, "FOLDER", null, ""), check : GetParameter(data, "CHECK", null, false), updateOffer : GetParameter(data, "UPDATEOFFER", null, false), updateHash : GetParameter(data, "UPDATEHASH", null, false), prepScript : GetParameter(data, "PREPAREUPLOAD", null, false), force : GetParameter(data, "FORCE", null, false), interactive : GetParameter(data, "INTERACTIVE", null, false), showResults : GetParameter(data, "SHOWRESULTS", null, false), progress : GetParameter(data, "PROGRESS", null, false), win : GetParameter(data, "WIN", null, null) } if (!p.win) p.win = data.func.sourcetab.lister; var resUp = new DOResourceUpdater(); resUp.interactive = p.interactive; resUp.progress = p.progress; resUp.showResults = p.showResults; resUp.win = p.win; resUp.force = p.force; resUp.updateOffer = p.updateOffer function GetFiles(data){ try{ var files = data.func.sourcetab.selected_files; return { enumerator:new Enumerator(files), count:files.count}; } catch(e){ return {enumerator:null, count:0}; } } var resultTmp = true; var files = {enumerator:null, count:0}; if (!p.folder) p.folder = DOpus.FSUtil.Resolve("/dopusdata/script addins"); var file = ""; if (p.file) file = p.file; else { files = GetFiles(data); if (files.count) file = files.enumerator.item().realpath; } /////////////////////////////////////////////////////// if (0){} else if (p.about && file){ var ad = new AboutDialog( file, p.win); ad.Init(); ad.Show(); } /////////////////////////////////////////////////////// else if (p.visit && file){ resultTmp = resUp.Visit(file); } /////////////////////////////////////////////////////// else if (p.archive){ out.put("Archive.."); if (p.file) resultTmp = resUp.ArchiveScript(String(p.file)); else if (p.all){ var fEnum = new Enumerator(data.func.sourcetab.files); while (!fEnum.atEnd()) { var file = fEnum.item().realpath; fEnum.moveNext(); resUp.ArchiveScript(String(file)); } } else if (files.count){ var fEnum = files.enumerator; while (!fEnum.atEnd()) { var file = fEnum.item().realpath; fEnum.moveNext(); resUp.ArchiveScript(String(file)); } } else out.put("Bad params. No scripts given/selected."); } /////////////////////////////////////////////////////// else if (p.openLog){ out.put("OpenLog.."); resultTmp = !resUp.OpenLog(); } /////////////////////////////////////////////////////// else if (p.check){ out.put("Check.."); if (p.all) resultTmp = resUp.UpdateCheckAll(p.folder); else if (p.file) resultTmp = resUp.UpdateCheck(p.file); else if (files.count){ var fEnum = files.enumerator; while (!fEnum.atEnd()) { var file = fEnum.item().realpath; fEnum.moveNext(); resUp.UpdateCheck(file); } } else out.put("Bad params. No scripts given/selected."); } /////////////////////////////////////////////////////// else if (p.update){ out.put("Update.."); if (p.all) resultTmp = resUp.UpdateAll(p.folder); else if (p.file) resultTmp = resUp.Update(p.file); else if (files.count){ var fEnum = files.enumerator; while (!fEnum.atEnd()) { var file = fEnum.item().realpath; fEnum.moveNext(); resUp.Update(file); } } else out.put("Bad params. No scripts given/selected."); } /////////////////////////////////////////////////////// else if (p.updateHash && file){ out.put("UpdateHash.."); var preparer = new UploadPreparer(); preparer.UpdateMD5(file); } /////////////////////////////////////////////////////// else if (p.prepScript && file){ out.put("PrepScript.."); var preparer = new UploadPreparer(); preparer.win = p.win; preparer.PrepareScript(file); } /////////////////////////////////////////////////////// else { out.put("Bad params. Bad command or no script given/selected."); result = COMMAND_ABORTED; } if (!resultTmp) result = COMMAND_ABORTED; out.reset(); return result; } /////////////////////////////////////////////////////////////////////////////// function OnAboutScript(data){ //v0.1 var cmd = DOpus.Create.Command(); if (!cmd.Commandlist('s').exists("ScriptWizard")){ if (DOpus.Dlg.Request("The 'ScriptWizard' add-in has not been found.\n\n"+ "Install 'ScriptWizard' from [resource.dopus.com].\nThe add-in enables this dialog and also offers "+ "easy updating of scripts and many more.","Yes, take me there!|Cancel", "No About.. ", data.window)) cmd.RunCommand('http://resource.dopus.com/viewtopic.php?f=35&t=23179');} else cmd.RunCommand('ScriptWizard ABOUT WIN='+data.window+' FILE="'+Script.File+'"'); } /////////////////////////////////////////////////////////////////////////////// function AboutDialog( file, win){ this.res = null; this.file = file; this.win = win; this.buttons = "Visit Forum|"+ "Check Version+Update+Update all Scripts+Open LogFile|"+ "Prepare Upload+Update MD5+Show Details|"+ "Archive+Rename+Delete|"+ "Exit"; this.abuttons = this.buttons.replace(/\+/g,"|").split("|"); this.cmd = DOpus.Create.Command(); this.confirm = 1; /////////////////////////////////////////////////////////////////////////// this.Show = function(){ out.trc("ShowAbout():",1); var dlg = DOpus.Dlg; dlg.window = (this.win?this.win:null); dlg.message = this.GetText(); dlg.title = "ScriptAbout: "+this.res.name; dlg.buttons = this.buttons; dlg.icon = "info"; dlg.max = 512; dlg["default"] = this.file; var label = "Confirm operations"; for(var len=0;len<120;len++) label+=" ";label+="\t"; dlg.options(0).label = label; dlg.options(0).state = this.confirm; var result = dlg.Show(); this.confirm = dlg.options(0).state; switch (result){ case this.BtnID("Visit Forum"): this.Button_VisitForum(); break; case this.BtnID("Check Version"): this.Button_UpdateCheck(); break; case this.BtnID("Update"): this.Button_Update(); break; case this.BtnID("Update all Scripts"): this.Button_UpdateAll(); break; case this.BtnID("Open LogFile"): this.Button_OpenLog(); break; case this.BtnID("Show Details"): this.Button_ShowDetails(); break; case this.BtnID("Prepare Upload"): this.Button_PrepareUpload(); break; case this.BtnID("Archive"): this.Button_Archive(); break; case this.BtnID("Update MD5"): this.Button_UpdateMD5(); break; case this.BtnID("Delete"): this.Button_Delete(); break; case this.BtnID("Rename"): this.Button_Rename(dlg.input); break; case this.BtnID("Exit"): break; } out.trc("",-1); return COMMAND_SUCCEEDED; } /////////////////////////////////////////////////////////////////////////// this.Button_VisitForum = function(){ this.cmd.RunCommand('ScriptWizard VISIT INTERACTIVE FILE="'+this.file+'" WIN='+this.win); this.Show(); } /////////////////////////////////////////////////////////////////////////// this.Button_Rename = function(newFileNamePath){ var doPath = DOpus.FSUtil.NewPath(this.file); var newName = newFileNamePath.getFilePart(); var newNamePath = doPath.pathpart+"\\"+newName; if (this.confirm && !Request("Really rename the script ["+this.res.name+"]?", "Ok|Cancel","Rename Script","question",this.win)){ } else { if (!newName || DOpus.FSUtil.Exists(newNamePath)){ Request("Rename failed!\n\nNo proper name given or the file already exists.", "Ok","Rename Script","error",this.win); } else { this.cmd.RunCommand('Rename FROM="'+this.file+'" TO="'+newName+'"'); this.file = newNamePath; this.Init(); } } this.Show(); } /////////////////////////////////////////////////////////////////////////// this.Button_Delete = function(){ if (!Request("Really delete this script?\n\n"+ "Name:\n "+this.res.name+"\n"+ "File:\n "+this.res.filePath.getFilePart(), "Ok|Cancel","Delete Script","question",this.win)){ this.Show(); } else this.cmd.RunCommand('Delete QUIET FORCE FILE="'+this.file+'"'); } /////////////////////////////////////////////////////////////////////////// this.Button_UpdateCheck = function(){ this.cmd.RunCommand('ScriptWizard CHECK UPDATEOFFER INTERACTIVE PROGRESS WIN='+ this.win+' FILE="'+this.file+'"'); this.Show(); } /////////////////////////////////////////////////////////////////////////// this.Button_Update = function(){ if (this.confirm && !Request("Really update the script ["+this.res.name+"]?", "Ok|Cancel","Update Script","question",this.win)){ } else this.cmd.RunCommand('ScriptWizard UPDATE INTERACTIVE PROGRESS WIN='+ this.win+' FILE="'+this.file+'"'); //Request("This is available soon!","Ok","Update","info",dlg.window); this.Show(); } /////////////////////////////////////////////////////////////////////////// this.Button_UpdateAll = function(){ if (this.confirm && !Request("You're about to update all scripts.\n\n"+ "Don't worry, you'll be safe! Any script you changed or modified, "+ "will not be updated automatically.\nScript configurations will be preserved as well.", "Ok|Cancel","Update Scripts","question",this.win)){ } else this.cmd.RunCommand('ScriptWizard UPDATE ALL PROGRESS SHOWRESULTS WIN='+this.win); this.Show(); } /////////////////////////////////////////////////////////////////////////// this.Button_OpenLog = function(){ this.cmd.RunCommand('ScriptWizard OPENLOG'); this.Show(); } /////////////////////////////////////////////////////////////////////////// this.Button_ShowDetails = function(){ var details = ""; for(prop in this.res){ if (prop.substring(0,1)=="_") continue; details += prop.toUpperCase()+":\n "+this.res[prop]+"\n"; } Request(details,"Ok","Script Details","info",this.win); this.Show(); } /////////////////////////////////////////////////////////////////////////// this.Button_Archive = function(){ if (!this.cmd.RunCommand('ScriptWizard ARCHIVE FILE="'+this.file+'"')) Request("Archiving of script ["+this.res.name+"] failed!", "Ok","Archive Script - Error","error",this.win); else Request("Archiving of script ["+this.res.name+"] succeeded!", "Ok","Archive Script","info",this.win); this.Show(); } /////////////////////////////////////////////////////////////////////////// this.Button_UpdateMD5 = function(){ if (this.confirm && !Request("Really update the MD5 of script ["+this.res.name+"]?", "Ok|Cancel","Update Hash","question",this.win)){ } else { if (!this.cmd.RunCommand('ScriptWizard UPDATEHASH FILE="'+this.file+'"')) Request("Updating MD5 hash of script ["+this.res.name+"] failed!", "Ok","Update Hash - Error","error",this.win); else Request("Updating MD5 hash of script ["+this.res.name+"] succeeded!", "Ok","Update Hash","info",this.win); } this.Show(); } /////////////////////////////////////////////////////////////////////////// this.Button_PrepareUpload = function(){ if (!this.cmd.RunCommand('ScriptWizard PREPAREUPLOAD FILE="'+this.file+'" WIN='+this.win)) Request("Preparing upload of script ["+this.res.name+"] failed!", "Ok","Prepare ScriptUpload - Error","error",this.win); else Request("Preparing upload of script ["+this.res.name+"] succeeded!", "Ok","Prepare ScriptUpload","info",this.win); this.Show(); } /////////////////////////////////////////////////////////////////////////// this.GetText = function(){ var text = ""; text += "Name:\n "+this.res.name; if (this.res.uid) text+=" - (id: "+this.res.uid+")"; if (this.res.desc) text+="\n\nDescription:\n "+this.res.desc; //if (props.copyright) text+="\n\nCopyright:\n "+this.res.copyright; if (this.res.version) text+="\n\nVersion, modified:\n "+this.res.version+", "; if (this.res.modified===null) text +="unknown"; else text+=(this.res.modified?"*** modified ***":"not modified"); //if (this.res.min_version) text+="\n\nMinVersion:\n "+props.min_version; text+="\n\nResource Url:\n "+(this.res.url?this.res.url:""); return text; } /////////////////////////////////////////////////////////////////////////// this.BtnID = function(label){ for(var b=0;b200){ (tmpMsg="Failure: "+e.message) && out.err(tmpMsg) && (msg+=tmpMsg+"!\n"); status.code = RES_STATUS_FAILED; } else if (e.number>100){ (tmpMsg="Unsupported: "+e.message) && out.err(tmpMsg) && (msg+=tmpMsg+"!\n"); //DOpus.Output("UNsupported message:" +e.message); status.code = RES_UPDATE_UNSUPPORTED; } else{ (tmpMsg="Unknown error: "+e.message) && out.err(tmpMsg) && (msg+=tmpMsg+"!\n"); throw e; } status.msg = msg; if (interactive){ this.progress && this.progress.SetStatus("Waiting for user input.."); msg="Scriptfile:\n "+resFileName+"\n\nResult:\n"+msg; Request(msg,"Ok","ScriptWizard - Check - Error","error",this.win); } out.trc("",-1); return status; } } /////////////////////////////////////////////////////////////////////////// this.GetStatusRaw = function( resFilePath ){ out.trc("GetStatusRaw():",1); resFilePath = new String(resFilePath); var status = {code:RES_UNKNOWN, curRes:null, versions:[]}; try{ if (!this.fso.FileExists(resFilePath)) throw new Error(ERR_FILE_NOT_FOUND, ERRMSGS[ERR_FILE_NOT_FOUND]); var res = ResParser.Load(resFilePath) //todo status.curRes = res; if (!res.url) throw new Error(ERR_RES_NORESURL, ERRMSGS[ERR_RES_NORESURL]); if (!res.version) throw new Error(ERR_RES_NOVERSION, ERRMSGS[ERR_RES_NOVERSION]); this.progress && this.progress.SetStatus("Searching for updates.."); var versions = this.GetAvailableVersions(res); if (!versions.length) throw new Error(ERR_RES_NOVERSIONS, ERRMSGS[ERR_RES_NOVERSIONS]); status.versions = versions; out.dmp("Script version: "+status.curRes.version); out.dmp("Latest version: "+status.versions[0].version); if (status.versions[0].version == 0) throw new Error(ERR_RES_NOVERSIONDOWN, ERRMSGS[ERR_RES_NOVERSIONDOWN]); switch (ResParser.Compare(status.curRes.version, status.versions[0].version)){ case 1: //curRes lower status.code += RES_UPDATE_FOUND; break; case 0: //equal status.code += RES_UPTODATE; break; case -1: //curRes more recent status.code += RES_MORERECENT; break; } if (res.modified) status.code += RES_MODIFIED; } catch(e){ out.trc("",-1); throw e; } out.trc("",-1); return status; } /////////////////////////////////////////////////////////////////////////// this.UpdateCheckAll = function( scriptsFolderPath ){ this.PrintHeader("ScriptWizard - Check ALL"); out.put("UpdateCheckAll():",1); var scriptsFolder = this.fso.GetFolder(scriptsFolderPath); var fEnum = new Enumerator(scriptsFolder.files); if (this.progress) this.progress = this.OpenProgressDialog(this.win, "ScriptWizard Check - All", scriptsFolder.files.count); var results = { updateable:0, uptodate:0, updated:0, unsupported:0, morerecent:0, failed:0, na:0}; for (var count=0; !fEnum.atEnd(); fEnum.moveNext()){ if (!ResParser.ValidateExtension(fEnum.item(), false)){ this.progress && this.progress.StepFiles(1); continue; } count++; var status = this.UpdateCheck(fEnum.item(), false); this.CountResults(results, status); this.progress && this.progress.StepFiles(1); } out.put("").put("",-1); this.PrintResults(results, count); this.progress && this.progress.Hide(); return COMMAND_SUCCEEDED; } /////////////////////////////////////////////////////////////////////////// this.UpdateAll = function( scriptsFolderPath ){ this.PrintHeader("ScriptWizard - ALL"); out.put("UpdateAll():",1); var scriptsFolder = this.fso.GetFolder(scriptsFolderPath); if (this.progress) this.progress = this.OpenProgressDialog(this.win, "ScriptWizard - All", scriptsFolder.files.count); var fEnum = new Enumerator(scriptsFolder.files); var results = { updateable:0, uptodate:0, updated:0, unsupported:0, morerecent:0, failed:0, na:0}; for (var count=0; !fEnum.atEnd(); fEnum.moveNext()){ if (!ResParser.ValidateExtension(fEnum.item(), false)){ this.progress && this.progress.StepFiles(1); continue; } count++; var status = this.Update(fEnum.item(), false); this.CountResults(results, status); this.progress && this.progress.StepFiles(1); } out.put("").put("",-1); this.PrintResults(results, count); this.progress && this.progress.Hide(); return COMMAND_SUCCEEDED; } /////////////////////////////////////////////////////////////////////////// this.PrintHeader = function(text){ out.put("--------------------------------------------------------------------------------"); out.put(text + " - " + new Date().formatDate()+ " " + new Date().formatTime()); out.put("--------------------------------------------------------------------------------"); } /////////////////////////////////////////////////////////////////////////// this.CountResults = function(results, status){ if (status.code & RES_UPDATE_FOUND) results.updateable++; else if (status.code & RES_UPTODATE) results.uptodate++; else if (status.code & RES_MORERECENT) results.morerecent++; else if (status.code & RES_UPDATED) results.updated++; else if (status.code == RES_UPDATE_UNSUPPORTED) results.unsupported++; else if (status.code == RES_STATUS_FAILED) results.failed++; else { results.na++; } } /////////////////////////////////////////////////////////////////////////// this.PrintResults = function(results, count){ out.put("Results ("+count+" scripts in total):",1); out.put("Updateable : " + results.updateable); out.put("Uptodate : " + results.uptodate); out.put("MoreRecent : " + results.morerecent); out.put("Updated : " + results.updated); out.put("Unsupported : " + results.unsupported); out.put("Failed : " + results.failed); out.put("? : " + results.na); out.put("").put("",-1); if (this.showResults){ var msg = "Results:\n\n"+ " Updateable : " + results.updateable+"\n (intentionally skipped, these were modified e.g.)\n"+ " Uptodate : " + results.uptodate+"\n (no later versions found for these)\n"+ " Updated : " + results.updated+"\n (updated scripts)\n"+ " Unsupported : " + results.unsupported+"\n (scripts not supporting updates)\n"+ " Failed : " + results.failed+"\n (scripts which possibly can be updated, but failed)\n"+ " Unknown : " + results.na+"\n (unknown errors while updating)\n\n"+ "Scripts in total: "+count; Request(msg,"Ok","ScriptWizard - All","info",this.win); } } /////////////////////////////////////////////////////////////////////////// this.GetAvailableVersions = function( resource ){ out.trc("GetAvailableVersions():",1); try{ var down = this.Download(resource.url); var doRTP = new DOResourceThreadParser(); var versions = doRTP.GetResourceDownloads(down.content, resource); out.trc("",-1); return versions; } catch(e){ out.trc("",-1); throw e; } } /////////////////////////////////////////////////////////////////////////// this.Download = function(url, binary){ out.trc("Download():",1) if (!binary) binary = false; var result = { status:200, content:""}; var versions = ['MSXML2.XMLHTTP', 'Microsoft.XMLHTTP','MSXML.XMLHTTP', 'Msxml2.XMLHTTP.7.0', 'Msxml2.XMLHTTP.6.0','Msxml2.XMLHTTP.5.0', 'Msxml2.XMLHTTP.4.0','MSXML2.XMLHTTP.3.0','MSXML2.XMLHTTP','Microsoft.XMLHTTP', 'WinHttp.WinHttpRequest','WinHttp.WinHttpRequest.5.1','MSXML2.ServerXMLHTTP']; try{ for (var i=0;i 1){ out.dmp("Sorting resources for best match"); resourcesIndexed = resourcesIndexed.sort( function(a,b){ return b.distance - a.distance; } ); bestMatchRes = resourcesIndexed[0]; } var resVersions = []; if (bestMatchRes){ if (resourcesIndexed.length > 1 && bestMatchRes.distance < 0.8){ out.inf("Best matching resource name is too different, name ["+ bestMatchRes.versions[0].fileName+"], distance ["+bestMatchRes.distance+"]"); //DumpObject(bestMatchRes); //DumpObject(bestMatchRes.versions[0]); } else { if (resourcesIndexed.length == 1 && bestMatchRes.distance < 0.8) out.wrn("Resource name is very different, name ["+ bestMatchRes.versions[0].fileName+"], distance ["+bestMatchRes.distance+"]"); resVersions = bestMatchRes.versions; out.dmp("Best matching resource name: " + resVersions[0].fileName); //sort sub resource versions out.dmp("Versions found: " + resVersions.length); resVersions.versions = resVersions.sort( function(a,b){ return ResParser.Compare(a.version, b.version); } ); } } else { out.dmp("No matching resource found"); } return resVersions; } /////////////////////////////////////////////////////////////////////////// this.GetResourcesFromXMLDoc = function(xmlDoc, cleanFileNameOfResource2Update){ var resources = []; var resourcesFound = 0; var ScriptVersion = function(){}; var fileNodes = xmlDoc.selectNodes("(//div[@class='postbody'])[1]//dl[@class='file']/dt/a[@class='postlink']/../.."); out.dmp("Downloads found: " + fileNodes.length,1); for(var f=0;f/,""); //get rid of dtd xmlText = xmlText.replace(//,""); //get rid of namespacing xmlText = xmlText.replace(/\&bull\;/g,''); //get rid of some entities xmlText = xmlText.replace(/\»\;/g,''); xmlText = xmlText.replace(/\ \;/g,''); xmlText = xmlText.replace(/\®\;/g,''); xmlText = xmlText.replace(/\©\;/g,''); xmlText = xmlText.replace(/\ü\;/g,'ü'); xmlText = xmlText.replace(/\ä\;/g,'ä'); xmlText = xmlText.replace(/\ö\;/g,'ö'); xmlText = xmlText.replace(/\·\;/g,'.'); //remove li and ul tags as they often don't match and site cannot be parsed xmlText = xmlText.replace(//g,''); xmlText = xmlText.replace(/<\/li>/g,''); xmlText = xmlText.replace(//g,''); xmlText = xmlText.replace(/<\/ul>/g,''); //fix iframe attribute with no value //.. allowfullscreen> .. xmlText = xmlText.replace(/allowfullscreen\>/g,'allowfullscreen="">'); //xmlText = '' + xmlText; return xmlText; } /////////////////////////////////////////////////////////////////////////// this.ParseSize = function(str){ var re = new RegExp("\(\\d{1,3}\.?\\d{1,3}?\\s..?\)",'gi'); var match = re.exec(str); if (match) return match[1]; return ""; } /////////////////////////////////////////////////////////////////////////// this.ParseVersion = function(str){ var re = new RegExp("(\\d{1,3}(?:\\.\\d{1,3})?(?:\\.\\d{1,6})?)",'gi'); var match = re.exec(str); if (match) return match[1]; return "0"; } /////////////////////////////////////////////////////////////////////////// this.GetXMLDoc = function(){ out.trc("GetXMLDoc():",1); try { var xmlDoc = new ActiveXObject("MSXML2.DOMDocument.6.0"); xmlDoc.async = false; xmlDoc.validateOnParse = true; xmlDoc.resolveExternals = false; } catch (e) { out.trc("",-1); throw e; } out.trc("",-1); return xmlDoc; } /////////////////////////////////////////////////////////////////////////// this.Distance = function(str1, str2) { var levenshtein = function(str1, str2) { var current = [], prev, value; for (var i = 0; i <= str2.length; i++) for (var j = 0; j <= str1.length; j++) { if (i && j) if (str1.charAt(j - 1) === str2.charAt(i - 1)) value = prev; else value = Math.min(current[j], current[j - 1], prev) + 1; else value = i + j; prev = current[j]; current[j] = value; } return current.pop(); }; if (str1 === null && str2 === null) throw 'Trying to compare two null values'; if (str1 === null || str2 === null) return 0; str1 = String(str1); str2 = String(str2); var distance = levenshtein(str1, str2); if (str1.length > str2.length) { return 1 - distance / str1.length; } else { return 1 - distance / str2.length; } } } /////////////////////////////////////////////////////////////////////////////// function DOResourceOutline(){ this.type = "script"; //script this.package = false; this.fileName = ""; //filename only this.extension = ""; //js, vbs, pyt or osp this.md5 = ""; //md5 internally stored this.desc = ""; //script internal or download description this.version = "0"; //version this.url = ""; //resource center thread url this.details = ""; //resource center download details this.sizeFriendly = ""; //resource center download size } /////////////////////////////////////////////////////////////////////////////// function DOResource(){ this.type = "script"; this.package = false; this.filePath = ""; //path to resource including filename this.fileName = ""; //filename only this.scriptName = ""; //diff. from filename if package this._content = ""; //file content this._onAbout = false; //has onabout function this.extension = ""; //js, vbs, pyt or osp this.md5 = ""; //md5 internally stored this.md5Fresh = ""; //md5 determined this.modified = null; //md5 different from internal md5 this.enabled = null; this.name = ""; //do script/resource name this.desc = ""; //internal or download description this.copyright = ""; //internal this.version = "0"; //version this.minVersion = ""; //do min version this.uid = ""; //internal unique id this.doID = ""; //do internal script id this.url = ""; //resource center thread url this._urlInternal = false; //url provided by resource this.details = ""; //resource center download details this.size = 0; //file size this.sizeFriendly = ""; //resource center download size } /////////////////////////////////////////////////////////////////////////////// function PackageHelper( filePath){ this.filePath = filePath; this.fileName = this.filePath.getFilePart(); this.tmpPath = ""; this.fso = FSMagic.fso; /////////////////////////////////////////////////////////////////////////// this.Extract = function(){ out.trc("Extract():",1); var cmd = DOpus.Create.Command; var tmpPath = FSMagic.GetTmpFileName(); if(!FSMagic.CreatePath(tmpPath.fullname)){ out.trc("",-1); throw "Creating tmp folder failed ["+tmpPath.fullname+"]"; } this.tmpPath = tmpPath.fullname; cmd.RunCommand('Copy EXTRACT FILE="'+this.filePath+'" TO="'+this.tmpPath+'"'); out.trc("",-1); return this; } /////////////////////////////////////////////////////////////////////////// this.FindMainScriptResource = function(){ out.trc("FindMainScriptResource():",1); var folder = this.fso.GetFolder( this.tmpPath ); var fEnum = new Enumerator(folder.files); var file = null; var res = null; for (; !fEnum.atEnd(); fEnum.moveNext()){ file = fEnum.item(); if (!ResParser.ValidateExtension(file.Name, false)){ out.dmp("No valid resource ["+file.Name+"]"); continue; } res = ResParser.Load(this.tmpPath+"\\"+file.Name); if (res.package) continue; if (res.url && res._urlInternal || res.uid){ out.dmp("Using package file ["+res.fileName+"]"); break; } } out.trc("",-1); return res; } /////////////////////////////////////////////////////////////////////////// this.CleanUp = function(){ out.trc("CleanUp():",1); this.fso.DeleteFolder(this.tmpPath); out.trc("",-1); } } /////////////////////////////////////////////////////////////////////////////// function DOResourceParser(){ this.reMD5 = "(?://|'|#)MD5\\s*=\\s*[\"'](.*?)[\"']"; this.fso = new ActiveXObject("Scripting.FileSystemObject"); this.comment = {js:"//", vbs:"'", pyt:"#"}; /////////////////////////////////////////////////////////////////////////// this.ValidateExtension = function(file, throwEx){ out.trc("ValidateExtension(): ["+file+"]",1); if (throwEx==undefined) throwEx=true; var typeMatch = new RegExp("(?:.*?)\\.(js|vbs|pyt|osp)(?:\\.txt)?$","gi").exec(file); if (typeMatch==null || typeMatch.length!=2){ out.dmp("INVALID"); out.trc("",-1); if (throwEx) throw new Error(ERR_BAD_FILETYPE, ERRMSGS[ERR_BAD_FILETYPE]); return false; } out.dmp("Valid"); out.trc("",-1); return typeMatch[1].toLowerCase(); } /////////////////////////////////////////////////////////////////////////// this.Load = function(filePath){ out.trc("Load():",1); out.dmp("File:"+filePath); filePath = new String(filePath); if (!filePath) throw "No file given"; var content = ""; var reMD5 = new RegExp(this.reMD5,"gi"); var res = new DOResource(); var parent = filePath.getParentPart(); if (!this.fso.FolderExists(parent)){ out.xit("Script in archive not supported ["+parent+"]"); out.trc("",-1); throw "Script in archive not supported ["+parent+"]"; } res.filePath = filePath; res.fileName = filePath.getFilePart(); res.scriptName = res.fileName; res.extension = this.ValidateExtension(res.filePath); res.package = this.IsPackage(res.filePath); res.size = this.fso.GetFile(res.filePath).Size; var doScriptConfigDetails = this.GetDOScriptConfigDetails(res.filePath); res.doID = doScriptConfigDetails.id; res.enabled = doScriptConfigDetails.enabled; if (res.package){ var ph = new PackageHelper( res.filePath ); var pRes = ph.Extract().FindMainScriptResource(); ph.CleanUp(); if (pRes){ pRes.filePath = res.filePath; pRes.scriptName = pRes.fileName; pRes.fileName = res.fileName; pRes.package = res.package; pRes.size = res.size; out.trc("",-1); return pRes; } throw "No script found in package"; } out.dmp("Opening and reading file"); var file = this.fso.OpenTextFile( res.filePath, 1, false, -2); while(!file.AtEndOfStream){ var line = file.ReadLine(); if (line=="") continue; var md5Match = reMD5.exec(line); if (!md5Match) //skip the hash line content += line; else res.md5 = md5Match[1]; } out.dmp("Closing file"); file.Close(); res.md5Fresh = MD5(content); res._content = content; if (res.md5!="") res.modified = (res.md5+""!=""+res.md5Fresh); out.dmp("Getting properties"); res.name = this._GetName(res); res.desc = this._GetDesc(res); res.copyright = this._GetCopyright(res); res.version = this._GetVersion(res); //DOpus.Output(res.version); res.minVersion = this._GetMinVersion(res); res.uid = this._GetUID(res); res.url = this._GetUrl(res); res._onAbout = this._GetOnAbout(res); out.dmp("done"); out.trc("",-1); return res; } /////////////////////////////////////////////////////////////////////////// this.IsPackage = function(filePath){ out.trc("IsPackage(): ["+filePath+"]",1); if (filePath && filePath.match( new RegExp( "\\.osp$", "gi"))){ out.trc("YES",-1); return true; } out.trc("NO",-1); return false; } /////////////////////////////////////////////////////////////////////////// this.Compare = function(verStrA,verStrB){ verStrA = this.CleanVer(verStrA); verStrB = this.CleanVer(verStrB); if (verStrA > verStrB) return -1; if (verStrA == verStrB) return 0; if (verStrA < verStrB) return 1; } /////////////////////////////////////////////////////////////////////////// this.GetDOScriptConfigDetails = function( filePath ){ out.trc("GetDOScriptConfigDetails():",1); filePath = new String(filePath); var id = ""; var enabled = null; var scriptFileName = filePath.getFilePart(); var doScriptConfig = ""+DOpus.FSUtil.Resolve("/dopusdata/configfiles/scriptconfig.oxc"); var xmlDoc = new ActiveXObject("MSXML2.DOMDocument.6.0"); out.dmp("DO config path: " + doScriptConfig); out.dmp("Script path: " + filePath); out.dmp("Script file: " + scriptFileName); xmlDoc.async = false; xmlDoc.validateOnParse = true; xmlDoc.resolveExternals = false; out.dmp("Loading config"); xmlDoc.load(doScriptConfig); if (xmlDoc.parseError.errorCode != 0) { var myErr = xmlDoc.parseError; out.err("Parser error: " + myErr.reason); out.trc("",-1); return {id:id, enabled: enabled}; } out.dmp("Looking for nodes"); var attNode = xmlDoc.selectSingleNode("//script[@path='"+scriptFileName+"']/@id"); if (!attNode){ var msg = "Script ["+scriptFileName+"] not found in DOs script configuration data"; out.inf(msg); //get guid and remove curly brackets id = new ActiveXObject("Scriptlet.TypeLib").Guid.replace(/\{/gi,"").replace(/}.*/,""); } else id = attNode.text; var attNode = xmlDoc.selectSingleNode("//script[@path='"+scriptFileName+"']/@disable"); if (!attNode){ var msg = "Script ["+scriptFileName+"] not found in DOs script configuration data (2)"; out.inf(msg); } else enabled = (attNode.text=="no"?true:false); out.dmp("done"); out.trc("",-1); return {id:id, enabled: enabled}; } /////////////////////////////////////////////////////////////////////////// this.CleanVer = function(verString){ var vTmp = ""; while (vTmp != verString){ vTmp = verString; verString = verString.replace(/\.0*$/,""); } return verString; } /////////////////////////////////////////////////////////////////////////// this._ParseOnInitProperty = function(res, regEx, resultIndex ){ var reOnInit = "(?:function\\s+OnInit[\\s\\S]*?)"; var reOnInit = "(?:function\\s+OnInit.*?)"; str = res._content; var re = new RegExp(reOnInit+regEx,"gim"); var result = re.exec(res._content); if (result != null){ //for (var i=0;i"); if (steps==undefined) steps=1; this._indent+=steps; return this; } /////////////////////////////////////////////////////////////////////////// this.dec = function(steps){ //DOpus.Output("<"); if (steps==undefined) steps=1; this._indent-=steps; if (this._indent<0) this._indent=0; return this; } /////////////////////////////////////////////////////////////////////////// this.reset = function(){ this._indent=0; this.buffer = new Array(); return this; } /////////////////////////////////////////////////////////////////////////// this._ind = function(indent){ if (indent==undefined) return; if (indent>0) this.inc(); if (indent<0) this.dec(); } /////////////////////////////////////////////////////////////////////////// this._pad = function( length) { var str = ""; while (str.length < length) str+=this._indentChar; return str; } /////////////////////////////////////////////////////////////////////////// this.level = function(level){ if (level==undefined) level=4; if (level>-1) this._level=level; if (level>6) this._level=6; return this; } /////////////////////////////////////////////////////////////////////////// this._conOut = function(txt){ if (this._inDOP && !this._muted) DOpus.Output(txt); if (this._inWSH && !this._muted) WScript.Echo(txt); } /////////////////////////////////////////////////////////////////////////// this.out = function(txt, indent, type){ if (indent==undefined) indent=0; if (type==undefined) type=""; var indTmp = this._indent; if (type!="" && indTmp==0) indTmp=1; if (this._level>0 && (txt!="" || indent==0)){ var output = type+ this._pad(indTmp*this._indentWidth-type.length) +txt; this.outRaw(output); } this._ind(indent); return this; } /////////////////////////////////////////////////////////////////////////// this.outRaw = function(output){ if (this._buffered) this.outBuffer[this.outBuffer.length]=output; if (this._console) this._conOut(this._prepLine(output,this._lineConsole)); if (this._file) this._fileOut(this._prepLine(output,this._lineFile)); } /////////////////////////////////////////////////////////////////////////// this._fileOut = function(txt){ if (this._save && this._fso.FileExists(this._filePath)) this._fso.DeleteFile(this._filePath); this._save = false; try{ var file = this._fso.OpenTextFile(this._filePath, 8, true, -1); try{file.WriteLine(txt);}catch(e){ txt = txt.replace(/[^ -~]/ig,''); //printable chars only file.WriteLine(txt) } file.Close(); } catch(e){ if (this._fileError == undefined) this.err("FAILED TO OPEN LOGFILE ["+this._filePath+"]"); this._fileError = true; } } /////////////////////////////////////////////////////////////////////////// this.append = function(filepath){ if (filepath==undefined) throw "No filepath given."; try{ this._fso = fso; } catch(e){ this._fso = new ActiveXObject("Scripting.FileSystemObject");} this._filePath = filepath; this._file = true; return this; } /////////////////////////////////////////////////////////////////////////// this.save = function(filepath ){ this._save = true; return this.append(filepath); } /////////////////////////////////////////////////////////////////////////// this.dmp = function(txt, indent){ if (this._level+1>6||(this._keepInds&&indent)) this.out(txt, indent); return this; } /////////////////////////////////////////////////////////////////////////// this.trc = function(txt, indent){ if (this._level+1>5||(this._keepInds&&indent)) this.out(txt, indent); return this; } /////////////////////////////////////////////////////////////////////////// this.put = function(txt, indent){ if (this._level+1>4||(this._keepInds&&indent)) this.out(txt, indent); return this; } /////////////////////////////////////////////////////////////////////////// this.inf = function(txt, indent){ if (this._level+1>3||(this._keepInds&&indent)) this.out(txt, indent, "I"); return this; } /////////////////////////////////////////////////////////////////////////// this.wrn = function(txt, indent){ if (this._level+1>2||(this._keepInds&&indent)) this.out(txt, indent, "W"); return this; } /////////////////////////////////////////////////////////////////////////// this.err = function(txt, indent){ if (this._level+1>1||(this._keepInds&&indent)) this.out(txt, indent, "E"); return this; } /////////////////////////////////////////////////////////////////////////// this.xit = function(txt, indent){ if (this._level+1>0||(this._keepInds&&indent)) this.out(txt, indent, "X"); return this; } } /////////////////////////////////////////////////////////////////////////////// var MD5 = function(string) { /////////////////////////////////////////////////////////////////////////// function RotateLeft(lValue, iShiftBits) { return (lValue << iShiftBits) | (lValue >>> (32 - iShiftBits)); } /////////////////////////////////////////////////////////////////////////// function AddUnsigned(lX, lY) { var lX4, lY4, lX8, lY8, lResult; lX8 = (lX & 0x80000000); lY8 = (lY & 0x80000000); lX4 = (lX & 0x40000000); lY4 = (lY & 0x40000000); lResult = (lX & 0x3FFFFFFF) + (lY & 0x3FFFFFFF); if (lX4 & lY4) return (lResult ^ 0x80000000 ^ lX8 ^ lY8); if (lX4 | lY4) { if (lResult & 0x40000000) return (lResult ^ 0xC0000000 ^ lX8 ^ lY8); else return (lResult ^ 0x40000000 ^ lX8 ^ lY8); } else return (lResult ^ lX8 ^ lY8); } /////////////////////////////////////////////////////////////////////////// function F(x, y, z) { return (x & y) | ((~x) & z); } /////////////////////////////////////////////////////////////////////////// function G(x, y, z) { return (x & z) | (y & (~z)); } /////////////////////////////////////////////////////////////////////////// function H(x, y, z) { return (x ^ y ^ z); } /////////////////////////////////////////////////////////////////////////// function I(x, y, z) { return (y ^ (x | (~z))); } /////////////////////////////////////////////////////////////////////////// function FF(a, b, c, d, x, s, ac) { a = AddUnsigned(a, AddUnsigned(AddUnsigned(F(b, c, d), x), ac)); return AddUnsigned(RotateLeft(a, s), b); }; /////////////////////////////////////////////////////////////////////////// function GG(a, b, c, d, x, s, ac) { a = AddUnsigned(a, AddUnsigned(AddUnsigned(G(b, c, d), x), ac)); return AddUnsigned(RotateLeft(a, s), b); }; /////////////////////////////////////////////////////////////////////////// function HH(a, b, c, d, x, s, ac) { a = AddUnsigned(a, AddUnsigned(AddUnsigned(H(b, c, d), x), ac)); return AddUnsigned(RotateLeft(a, s), b); }; /////////////////////////////////////////////////////////////////////////// function II(a, b, c, d, x, s, ac) { a = AddUnsigned(a, AddUnsigned(AddUnsigned(I(b, c, d), x), ac)); return AddUnsigned(RotateLeft(a, s), b); }; /////////////////////////////////////////////////////////////////////////// function ConvertToWordArray(string) { var lWordCount; var lMessageLength = string.length; var lNumberOfWords_temp1 = lMessageLength + 8; var lNumberOfWords_temp2 = (lNumberOfWords_temp1 - (lNumberOfWords_temp1 % 64)) / 64; var lNumberOfWords = (lNumberOfWords_temp2 + 1) * 16; var lWordArray = Array(lNumberOfWords - 1); var lBytePosition = 0; var lByteCount = 0; while (lByteCount < lMessageLength) { lWordCount = (lByteCount - (lByteCount % 4)) / 4; lBytePosition = (lByteCount % 4) * 8; lWordArray[lWordCount] = (lWordArray[lWordCount] | (string.charCodeAt(lByteCount) << lBytePosition)); lByteCount++; } lWordCount = (lByteCount - (lByteCount % 4)) / 4; lBytePosition = (lByteCount % 4) * 8; lWordArray[lWordCount] = lWordArray[lWordCount] | (0x80 << lBytePosition); lWordArray[lNumberOfWords - 2] = lMessageLength << 3; lWordArray[lNumberOfWords - 1] = lMessageLength >>> 29; return lWordArray; }; /////////////////////////////////////////////////////////////////////////// function WordToHex(lValue) { var WordToHexValue = "", WordToHexValue_temp = "", lByte, lCount; for (lCount = 0; lCount <= 3; lCount++) { lByte = (lValue >>> (lCount * 8)) & 255; WordToHexValue_temp = "0" + lByte.toString(16); WordToHexValue = WordToHexValue + WordToHexValue_temp.substr(WordToHexValue_temp.length - 2, 2); } return WordToHexValue; }; /////////////////////////////////////////////////////////////////////////// function Utf8Encode(string) { string = string.replace(/\r\n/g, "\n"); var utftext = ""; for (var n = 0; n < string.length; n++) { var c = string.charCodeAt(n); if (c < 128) { utftext += String.fromCharCode(c); } else if ((c > 127) && (c < 2048)) { utftext += String.fromCharCode((c >> 6) | 192); utftext += String.fromCharCode((c & 63) | 128); } else { utftext += String.fromCharCode((c >> 12) | 224); utftext += String.fromCharCode(((c >> 6) & 63) | 128); utftext += String.fromCharCode((c & 63) | 128); } } return utftext; }; /////////////////////////////////////////////////////////////////////////// var x = Array(); var k, AA, BB, CC, DD, a, b, c, d; var S11 = 7, S12 = 12, S13 = 17, S14 = 22, S21 = 5, S22 = 9, S23 = 14, S24 = 20; var S31 = 4, S32 = 11, S33 = 16, S34 = 23, S41 = 6, S42 = 10, S43 = 15, S44 = 21; string = Utf8Encode(string); x = ConvertToWordArray(string); a = 0x67452301; b = 0xEFCDAB89; c = 0x98BADCFE; d = 0x10325476; for (k = 0; k < x.length; k += 16) { AA = a; BB = b; CC = c; DD = d; a = FF(a, b, c, d, x[k + 0], S11, 0xD76AA478); d = FF(d, a, b, c, x[k + 1], S12, 0xE8C7B756); c = FF(c, d, a, b, x[k + 2], S13, 0x242070DB); b = FF(b, c, d, a, x[k + 3], S14, 0xC1BDCEEE); a = FF(a, b, c, d, x[k + 4], S11, 0xF57C0FAF); d = FF(d, a, b, c, x[k + 5], S12, 0x4787C62A); c = FF(c, d, a, b, x[k + 6], S13, 0xA8304613); b = FF(b, c, d, a, x[k + 7], S14, 0xFD469501); a = FF(a, b, c, d, x[k + 8], S11, 0x698098D8); d = FF(d, a, b, c, x[k + 9], S12, 0x8B44F7AF); c = FF(c, d, a, b, x[k + 10], S13, 0xFFFF5BB1); b = FF(b, c, d, a, x[k + 11], S14, 0x895CD7BE); a = FF(a, b, c, d, x[k + 12], S11, 0x6B901122); d = FF(d, a, b, c, x[k + 13], S12, 0xFD987193); c = FF(c, d, a, b, x[k + 14], S13, 0xA679438E); b = FF(b, c, d, a, x[k + 15], S14, 0x49B40821); a = GG(a, b, c, d, x[k + 1], S21, 0xF61E2562); d = GG(d, a, b, c, x[k + 6], S22, 0xC040B340); c = GG(c, d, a, b, x[k + 11], S23, 0x265E5A51); b = GG(b, c, d, a, x[k + 0], S24, 0xE9B6C7AA); a = GG(a, b, c, d, x[k + 5], S21, 0xD62F105D); d = GG(d, a, b, c, x[k + 10], S22, 0x2441453); c = GG(c, d, a, b, x[k + 15], S23, 0xD8A1E681); b = GG(b, c, d, a, x[k + 4], S24, 0xE7D3FBC8); a = GG(a, b, c, d, x[k + 9], S21, 0x21E1CDE6); d = GG(d, a, b, c, x[k + 14], S22, 0xC33707D6); c = GG(c, d, a, b, x[k + 3], S23, 0xF4D50D87); b = GG(b, c, d, a, x[k + 8], S24, 0x455A14ED); a = GG(a, b, c, d, x[k + 13], S21, 0xA9E3E905); d = GG(d, a, b, c, x[k + 2], S22, 0xFCEFA3F8); c = GG(c, d, a, b, x[k + 7], S23, 0x676F02D9); b = GG(b, c, d, a, x[k + 12], S24, 0x8D2A4C8A); a = HH(a, b, c, d, x[k + 5], S31, 0xFFFA3942); d = HH(d, a, b, c, x[k + 8], S32, 0x8771F681); c = HH(c, d, a, b, x[k + 11], S33, 0x6D9D6122); b = HH(b, c, d, a, x[k + 14], S34, 0xFDE5380C); a = HH(a, b, c, d, x[k + 1], S31, 0xA4BEEA44); d = HH(d, a, b, c, x[k + 4], S32, 0x4BDECFA9); c = HH(c, d, a, b, x[k + 7], S33, 0xF6BB4B60); b = HH(b, c, d, a, x[k + 10], S34, 0xBEBFBC70); a = HH(a, b, c, d, x[k + 13], S31, 0x289B7EC6); d = HH(d, a, b, c, x[k + 0], S32, 0xEAA127FA); c = HH(c, d, a, b, x[k + 3], S33, 0xD4EF3085); b = HH(b, c, d, a, x[k + 6], S34, 0x4881D05); a = HH(a, b, c, d, x[k + 9], S31, 0xD9D4D039); d = HH(d, a, b, c, x[k + 12], S32, 0xE6DB99E5); c = HH(c, d, a, b, x[k + 15], S33, 0x1FA27CF8); b = HH(b, c, d, a, x[k + 2], S34, 0xC4AC5665); a = II(a, b, c, d, x[k + 0], S41, 0xF4292244); d = II(d, a, b, c, x[k + 7], S42, 0x432AFF97); c = II(c, d, a, b, x[k + 14], S43, 0xAB9423A7); b = II(b, c, d, a, x[k + 5], S44, 0xFC93A039); a = II(a, b, c, d, x[k + 12], S41, 0x655B59C3); d = II(d, a, b, c, x[k + 3], S42, 0x8F0CCC92); c = II(c, d, a, b, x[k + 10], S43, 0xFFEFF47D); b = II(b, c, d, a, x[k + 1], S44, 0x85845DD1); a = II(a, b, c, d, x[k + 8], S41, 0x6FA87E4F); d = II(d, a, b, c, x[k + 15], S42, 0xFE2CE6E0); c = II(c, d, a, b, x[k + 6], S43, 0xA3014314); b = II(b, c, d, a, x[k + 13], S44, 0x4E0811A1); a = II(a, b, c, d, x[k + 4], S41, 0xF7537E82); d = II(d, a, b, c, x[k + 11], S42, 0xBD3AF235); c = II(c, d, a, b, x[k + 2], S43, 0x2AD7D2BB); b = II(b, c, d, a, x[k + 9], S44, 0xEB86D391); a = AddUnsigned(a, AA); b = AddUnsigned(b, BB); c = AddUnsigned(c, CC); d = AddUnsigned(d, DD); } var temp = WordToHex(a) + WordToHex(b) + WordToHex(c) + WordToHex(d); return temp.toLowerCase(); } /////////////////////////////////////////////////////////////////////////////// function OnAddColumns(data){ var cmd = data.AddColumn(); cmd.multicol = true; cmd.name = "Name"; cmd.header = "Name"; cmd.label = "SWizard.Name"; cmd.method = "Column_ScriptWizard"; cmd.autorefresh = true; cmd.namerefresh = true; cmd.justify = "left"; cmd.defwidth = "175px"; var cmd = data.AddColumn(); cmd.multicol = true; cmd.name = "Description"; cmd.header = "Description"; cmd.label = "SWizard.Description"; cmd.method = "Column_ScriptWizard"; cmd.autorefresh = true; cmd.namerefresh = true; cmd.justify = "left"; cmd.defwidth = "175px"; var cmd = data.AddColumn(); cmd.multicol = true; cmd.name = "Copyright"; cmd.header = "Copyright"; cmd.label = "SWizard.Copyright"; cmd.method = "Column_ScriptWizard"; cmd.autorefresh = true; cmd.namerefresh = true; cmd.justify = "left"; cmd.defwidth = "175px"; var cmd = data.AddColumn(); cmd.multicol = true; cmd.name = "Enabled"; cmd.header = "Enabled"; cmd.label = "SWizard.Enabled"; cmd.method = "Column_ScriptWizard"; cmd.autorefresh = true; cmd.namerefresh = true; cmd.justify = "right"; cmd.defwidth = "50px"; var cmd = data.AddColumn(); cmd.multicol = true; cmd.name = "Version"; cmd.header = "Ver"; cmd.label = "SWizard.Version"; cmd.method = "Column_ScriptWizard"; cmd.autorefresh = true; cmd.namerefresh = true; cmd.justify = "left"; cmd.defwidth = "45px"; var cmd = data.AddColumn(); cmd.multicol = true; cmd.name = "MinVersion"; cmd.header = "MinVer"; cmd.label = "SWizard.MinVersion"; cmd.method = "Column_ScriptWizard"; cmd.autorefresh = true; cmd.namerefresh = true; cmd.justify = "left"; cmd.defwidth = "45px"; var cmd = data.AddColumn(); cmd.multicol = true; cmd.name = "Status"; cmd.header = "Status"; cmd.label = "SWizard.Status"; cmd.method = "Column_ScriptWizard"; cmd.autorefresh = true; cmd.namerefresh = true; cmd.justify = "right"; cmd.defwidth = "80px"; var cmd = data.AddColumn(); cmd.multicol = true; cmd.name = "Modified"; cmd.header = "Modified"; cmd.label = "SWizard.Modified"; cmd.method = "Column_ScriptWizard"; cmd.autorefresh = true; cmd.namerefresh = true; cmd.justify = "right"; cmd.defwidth = "50px"; var cmd = data.AddColumn(); cmd.multicol = true; cmd.name = "Url"; cmd.header = "Url"; cmd.label = "SWizard.Url"; cmd.method = "Column_ScriptWizard"; cmd.autorefresh = true; cmd.namerefresh = true; cmd.justify = "left"; cmd.defwidth = "300px"; var cmd = data.AddColumn(); cmd.multicol = true; cmd.name = "Reason"; cmd.header = "Reason"; cmd.label = "SWizard.Reason"; cmd.method = "Column_ScriptWizard"; cmd.autorefresh = true; cmd.namerefresh = true; cmd.justify = "left"; cmd.defwidth = "300px"; } /////////////////////////////////////////////////////////////////////////////// function Column_ScriptWizard(data) { out.mute(false); if (data.item.is_dir) return; out.trc("Column_ScriptWizard()",1); var useCache = Script.Config["Columns.Cache"]; ColCache.Init(data, useCache); var cachedItem = ColCache.DoTheCacheMagic(data); if (cachedItem){ out.dmp("Cached item found"); if (!cachedItem.isModified){ out.dmp("Cached item was not modified, using column values"); out.trc("",-1); return; } else { out.dmp("Cached item was modified, ignoring values"); out.dmp("CacheItem.dateModified: " + cachedItem.dateModified); out.dmp("DataItem.modify_utc : " + data.item.modify_utc); } } /* var cachedColumns = ColCache.GetColumnsForItem( data.item ); if (cachedColumns){ //out.inf("Item ["+data.item.name+"] found!"); ColCache.FillColumnMapFromCachedColumns(data.columns, cachedColumns); out.trc("",-1); return; } else { //out.inf("Item ["+data.item.name+"] not in cache"); }*/ data.columns("Name").value = ""; data.columns("Description").value = ""; data.columns("Copyright").value = ""; data.columns("Version").value = ""; data.columns("Modified").value = ""; data.columns("Url").value = ""; data.columns("Enabled").value = ""; data.columns("Status").value = "?"; data.columns("MinVersion").value = ""; data.columns("Reason").value = ""; var extension = ResParser.ValidateExtension(data.item.name, false); if (!extension){ out.trc("",-1); return; } try{ var res = ResParser.Load(data.item.realpath); } catch(e){ out.err(e); out.trc("",-1); return; } //DOpus.Output(" Uni:"+(res._content.substring(0,3)=="ÿþ/") ); if (res.name) data.columns("Name").value = res.name; if (res.desc) data.columns("Description").value = res.desc; if (res.copyright) data.columns("Copyright").value = res.copyright; if (res.version) data.columns("Version").value = res.version; if (res.minVersion) data.columns("MinVersion").value = res.minVersion; if (res.modified===false) data.columns("Modified").value = "no"; if (res.modified===true) data.columns("Modified").value = "yes"; if (res.modified===null) data.columns("Modified").value = ""; if (res.url) data.columns("Url").value = res.url; if (res.enabled) data.columns("Enabled").value = "yes"; var resUp = new DOResourceUpdater(); resUp.interactive = false; resUp.progress = false; resUp.showResults = false; resUp.win = null; var statusTxt = ""; var status = resUp.UpdateCheck(data.item, true); if (!res._urlInternal) data.columns("Reason").value = ERRMSGS[ERR_RES_NORESURL].replace("Unsupported: ","")+"!"; if (status.code & RES_UPDATE_FOUND) statusTxt="older"; else if (status.code & RES_UPTODATE) statusTxt="uptodate"; else if (status.code & RES_MORERECENT) statusTxt="newer"; //else if (status.code & RES_UPDATED) results.updated++; else if (status.code == RES_UPDATE_UNSUPPORTED){ statusTxt="-"; /*if (status.msg.indexOf(ERRMSGS[ERR_RES_NORESURL])!=-1) statusTxt="no url"; if (status.msg.indexOf(ERRMSGS[ERR_RES_NOVERSION])!=-1) statusTxt="no version"; if (status.msg.indexOf(ERRMSGS[ERR_RES_NOVERSIONS])!=-1) statusTxt="no downloads"; if (status.msg.indexOf(ERRMSGS[ERR_RES_NOVERSIONDOWN])!=-1) statusTxt="bad details"; */ data.columns("Reason").value = status.msg.replace("Unsupported: ",""); } else if (status.code == RES_STATUS_FAILED){ statusTxt="error"; data.columns("Reason").value = status.msg; } else { statusTxt="?"; } data.columns("Status").value = statusTxt; ColCache.SaveColumns( cachedItem, data); out.trc("",-1); } var ColCache = new ColumnCache("ScriptDetails", 1000*60); /////////////////////////////////////////////////////////////////////////////// function ColumnCache(id, msTTL){ this.enabled = false; this.initialized = false; this.persistent = true; this.id = id; this.msTTL = msTTL; this.columnNames = []; this.columnNamesIdx = []; this.ITEM_ID = 0; this.ITEM_DATEMODIFIED = 1; this.ITEM_TIMESTAMP = 2; this.ITEM_COLVALUES = 3; /////////////////////////////////////////////////////////////////////////// this.DoTheCacheMagic = function (data){ if (!this.enabled) return null; out.trc("DoTheCacheMagic(): ["+data.item.name+"]",1); var cacheItem = this._GetCacheItemFromCache(data.item); if (cacheItem){ this.FillColumnMapFromCachedColumns(data.columns, cacheItem.colValues); out.dmp("succeeded"); out.trc("",-1); return cacheItem; } out.dmp("failed"); out.trc("",-1); return null; } /////////////////////////////////////////////////////////////////////////// this._GetCacheItemFromCache = function( item ){ var itemID = String(item.realpath); out.trc("_GetCacheItemFromCache(): ["+itemID+"]",1); for (var v=0;vthis.msTTL, dateModified: cacheItem(this.ITEM_DATEMODIFIED), isModified : cacheItem(this.ITEM_DATEMODIFIED)+""!=""+item.modify_utc } } } out.dmp("not found"); out.trc("",-1); return null; } /////////////////////////////////////////////////////////////////////////// this.FillColumnMapFromCachedColumns = function( columnMap, cachedColumns){ if (!this.enabled) return null; out.trc("FillColumnMapFromCachedColumns():",1); var i=0; for(columnName in this.columnNames){ //out.dmp("Fillin columPutting column ["+columnName+"] into item.colValues("+i+")"); columnMap(columnName).value = cachedColumns(i++); } out.trc("",-1); } /////////////////////////////////////////////////////////////////////////// this.SaveColumns = function( cachedItem, data ){ if (!this.enabled) return null; out.trc("SaveColumns():",1); var i=0; if (!cachedItem){ cachedItem = { index : null, id : String(data.item.realpath), timestamp : ""+Date(), colValues : null, dateModified : "", expired : null}; } cachedItem.dateModified = ""+data.item.modify_utc; cachedItem.colValues = DOpus.Create.Vector(); for(columnName in this.columnNames){ out.dmp("Putting column ["+columnName+"] into cachedItem.colValues("+(i++)+")"); out.dmp(" Value: " + data.columns(columnName).value); cachedItem.colValues.push_back(data.columns(columnName).value); } this._PutCacheItemIntoCache(cachedItem); out.trc("",-1); } /////////////////////////////////////////////////////////////////////////// this._PutCacheItemIntoCache = function( cachedItem ){ out.trc("_PutCacheItemIntoCache():",1); out.dmp("doCache length: " + this.doCache.length); if (cachedItem.index!==null){ out.dmp("Reusing cachedItem index: " + cachedItem.index); var index = cachedItem.index; } else { var index = this.doCache.length; out.dmp("New item index: " + index); this.doCache(index) = DOpus.Create.Vector(); this.doCache(index)(this.ITEM_ID) = cachedItem.id; } this.doCache(index)(this.ITEM_TIMESTAMP) = cachedItem.timestamp; this.doCache(index)(this.ITEM_COLVALUES) = cachedItem.colValues; this.doCache(index)(this.ITEM_DATEMODIFIED) = cachedItem.dateModified; out.trc("",-1); } /////////////////////////////////////////////////////////////////////////// this._GetColumnNames = function( data ){ out.trc("_GetColumnNames():",1); var colEnum = new Enumerator(data.columns); for (;!colEnum.atEnd(); colEnum.moveNext()){ var col = colEnum.item(); this.columnNamesIdx[this.columnNamesIdx.length] = col; this.columnNames[col] = ""; } out.trc("",-1); } /////////////////////////////////////////////////////////////////////////// this.Init = function( data, cacheEnabled){ out.trc("Init():",1); if (cacheEnabled != undefined){ this.enabled = cacheEnabled; } if (this.initialized){ out.dmp("already initialized"); out.trc("",-1); return; } var varName = "Script.ColumnCache."+this.id; if (!DOpus.Vars.Exists(varName)){ var rootCacheVector = DOpus.Create.Vector(); DOpus.Vars.Set(varName, rootCacheVector); } var doCache = DOpus.Vars(varName); doCache.persist = this.persistent && DOpus.Version.AtLeast("11.8.2"); this.doCache = doCache.value; this._GetColumnNames(data); DumpObject(this.columnNames); this.initialized = true; out.dmp("fresh"); out.trc("",-1); } } /////////////////////////////////////////////////////////////////////////////// function DumpObject(o){ var maxLen = 0; for(prop in o) if (prop.length > maxLen) maxLen = prop.length; for(prop in o){ var pad = ""; while (pad.length+prop.length