//v0.1 //- initial version //////////////////////////////////////////////////////////////////////////////// function OnInit(data){ //uid added via script wizard (do not change after publishing this script) var uid = "B6FA1242-3AA3-46C1-B50F-62FDEF30509F"; //resource center url added via script wizard (required for updating) var url = "http://resource.dopus.com/viewtopic.php?f=35&t=23856"; data.name = "Column.Folder: Link2Volume"; data.desc = "A column set providing volume data for linked folders."; data.copyright = "tbone"; data.version = "0.1"; data.default_enable = true; data.min_version = "11.5.1" /////////////////////////////////////////////////////////////////////////// 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("Log.ToConsole", true). des("Enable output to 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", false). des("Enable output to log file."); cfg.add("Log.ToFile.Path", "/dopusdata\\logs\\Link2Volume.log.txt"). des("Log file path."); var col = data.AddColumn(); col.multicol = true; col.name = "Target1"; col.header = "Target 1"; col.label = "L2V.Target 1"; col.method = "Column_Link2Volume"; col.type = "text"; col.justify = "left"; col.defwidth = "150px"; var col = data.AddColumn(); col.multicol = true; col.name = "Target2"; col.header = "Target 2"; col.label = "L2V.Target 2"; col.method = "Column_Link2Volume"; col.type = "text"; col.justify = "left"; col.defwidth = "150px"; var col = data.AddColumn(); col.multicol = true; col.name = "Target3"; col.header = "Target 3"; col.label = "L2V.Target 3"; col.method = "Column_Link2Volume"; col.type = "text"; col.justify = "left"; col.defwidth = "150px"; var col = data.AddColumn(); col.multicol = true; col.name = "Target4"; col.header = "Target 4"; col.label = "L2V.Target 4"; col.method = "Column_Link2Volume"; col.type = "text"; col.justify = "left"; col.defwidth = "150px"; var col = data.AddColumn(); col.multicol = true; col.name = "Target5"; col.header = "Target 5"; col.label = "L2V.Target 5"; col.method = "Column_Link2Volume"; col.type = "text"; col.justify = "left"; col.defwidth = "150px"; var col = data.AddColumn(); col.multicol = true; col.name = "Label"; col.header = "Label"; col.label = "L2V.Label"; col.method = "Column_Link2Volume"; col.type = "text"; col.justify = "left"; col.defwidth = "75px"; var col = data.AddColumn(); col.multicol = true; col.name = "Name"; col.header = "Name"; col.label = "L2V.Name"; col.method = "Column_Link2Volume"; col.type = "text"; col.justify = "left"; col.defwidth = "100px"; var col = data.AddColumn(); col.multicol = true; col.name = "PercentFree"; col.header = "Percent Free"; col.label = "L2V.Percent Free"; col.method = "Column_Link2Volume"; col.type = "igraph"; col.justify = "right"; col.defwidth = "75px"; var col = data.AddColumn(); col.multicol = true; col.name = "PercentFull"; col.header = "Percent Full"; col.label = "L2V.Percent Full"; col.method = "Column_Link2Volume"; col.type = "graph"; col.justify = "right"; col.defwidth = "75px"; var col = data.AddColumn(); col.multicol = true; col.name = "Size"; col.header = "Size"; col.label = "L2V.Size"; col.method = "Column_Link2Volume"; col.type = "size"; col.justify = "right"; col.defwidth = "60px"; var col = data.AddColumn(); col.multicol = true; col.name = "FreeSpace"; col.header = "Free Space"; col.label = "L2V.Free Space"; col.method = "Column_Link2Volume"; col.type = "size"; col.justify = "right"; col.defwidth = "60px"; var col = data.AddColumn(); col.multicol = true; col.name = "UsedSpace"; col.header = "Used Space"; col.label = "L2V.Used Space"; col.method = "Column_Link2Volume"; col.type = "size"; col.justify = "right"; col.defwidth = "60px"; var col = data.AddColumn(); col.multicol = true; col.name = "Filesystem"; col.header = "Filesystem"; col.label = "L2V.Filesystem"; col.method = "Column_Link2Volume"; col.type = "text"; col.justify = "left"; col.defwidth = "65px"; var col = data.AddColumn(); col.multicol = true; col.name = "Type"; col.header = "Type"; col.label = "L2V.Type"; col.method = "Column_Link2Volume"; col.type = "text"; col.justify = "left"; col.defwidth = "65px"; var col = data.AddColumn(); col.multicol = true; col.name = "Letter"; col.header = "Letter"; col.label = "L2V.Letter"; col.method = "Column_Link2Volume"; col.type = "text"; col.justify = "left"; col.defwidth = "45px"; var col = data.AddColumn(); col.multicol = true; col.name = "ID"; col.header = "ID"; col.label = "L2V.ID"; col.method = "Column_Link2Volume"; col.type = "text"; col.justify = "left"; col.defwidth = "150px"; } /////////////////////////////////////////////////////////////////////////////// try { var out = new DebugOutput().mute(); //mute until used if (Script); //will fail here on script (re)load once out.level( Script.config["Log.Level"] ).console(Script.config["Log.ToConsole"]).buffer(true); //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! " + e); } /////////////////////////////////////////////////////////////////////////////// var DM = new DriveMagic(); var SM = new ShellMagic(); var FM = new FSMagic(); //////////////////////////////////////////////////////////////////////////////// function Column_Link2Volume(data){ //any non linking file or directory? if (data.item.is_dir === false && (new String(data.item.ext).toLowerCase() != ".lnk")){ //set "" for all columns to prevent further invokations SetAllColumns("", data); return; } //quick switch to disable directories if (0 && data.item.is_dir){ SetAllColumns("", data); return; } out.mute(false); out.put("Column_Link2Volume(): ["+data.item.name+"]",1); var volume = null; var con = new Connection( from = new Location( new String(data.item.realpath) ) ); if (con.Type){ //out.dmp("Connection Type: " + con.Type); var volume = con.GetTargetVolume(); //DumpObject(volume, "Volume for "+data.item.name); } else { out.put("No link of any kind"); } if (!volume){ SetAllColumns("", data); out.inf("No volume data available"); out.put("",-1); return; } out.dmp("Volume found: " + volume.Path); for(var t=1;t (new String(b.name.toLowerCase())).length) return -1; if ((new String(a.name.toLowerCase())).length < (new String(b.name.toLowerCase())).length) return 1; return 0; }); //DumpObject(this.Shares[computer], "this.Shares["+computer+"]"); out.trc("",-1); return shares; } /////////////////////////////////////////////////////////////////////////// this.ResolveUNCToLocalDrive = function ( uncPath, computer ){ out.trc("ResolveUNCToLocalDrive():",1); uncPath = new String(uncPath); out.dmp("UNCPath IN: " + uncPath); out.dmp("Computer IN: " + computer); var matches = null; if (matches = /\\\\.*?\\(.*)/.exec(uncPath)){ uncPath = matches[1].toLowerCase(); } out.dmp("Host removed: " + uncPath); if (!this.Shares[computer]){ this.Shares[computer] = this.GetShares( computer ); } var matches = null; var drive = null; for(var s=0;s"'+tmpFileStdout+'" 2>"'+tmpFileStderr+'""'; var result = {}; result.cmd = cmd; //Debug(" CMD: "+cmd); if (exe.match(/^([A-z]:\\.+|\\\\(.*?)\\.+)$/)){ //test path to exe if given if (!fso.FileExists(exe)){ var msg = "E Executable not found ["+exe+"]"; DOpus.Output(msg); throw msg; } } result.returncode = shell.Run( cmd, 0, true); //DOpus.Output(" Return: "+result.returncode); result.stdout = FM.ReadFile(tmpFileStdout, fso); fso.DeleteFile(tmpFileStdout); result.stderr = FM.ReadFile(tmpFileStderr, fso); fso.DeleteFile(tmpFileStderr); return result; } } /////////////////////////////////////////////////////////////////////////////// function FSMagic(){ this.version = 0.2; this.fso = new ActiveXObject("Scripting.FileSystemObject"); /////////////////////////////////////////////////////////////////////////// this.GetTmpFileName = function(prefix, extension) { var tFolder = this.fso.GetSpecialFolder(2); //2 = temp folder var tFile = this.fso.GetTempName(); if (prefix!=undefined) tFile=prefix+tFile; if (extension!=undefined) tFile+=extension; return { path : tFolder.Path, name : tFile, fullname: tFolder.Path+'\\'+tFile }; } /////////////////////////////////////////////////////////////////////////////// this.ReadFile = function ( path, fso ){ fso = fso || new ActiveXObject("Scripting.FilesystemObject"); var content = ""; if (!fso.FileExists(path)){ //Debug("ReadFile(), file ["+path+"] not found."); return content; } //Debug("ReadFile(), opening ["+path+"].."); var file = fso.OpenTextFile( path, 1, -2); // Read, UseDefaultEncoding if (!file.AtEndOfStream) content = file.ReadAll(); file.Close(); return content; } /////////////////////////////////////////////////////////////////////////// this.CreatePath = function(fullPath){ //version = 0.5.1; fullPath = new String(fullPath); if (this.fso.FolderExists(fullPath)) return true; var drive = fullPath.substring(0,3); var dirs = fullPath.split("\\"); var path = "" for(var i=1;i "" } } //symbolic link (Symbolic Link Reparse Data Buffer) //https://msdn.microsoft.com/en-us/library/cc232006.aspx if (result.stdout.indexOf(": 0xa000000c")!=-1) { var dataStart = null; for(var i=0;i maxLen) maxLen = prop.length; for(prop in o) { var pad = ""; while (pad.length+prop.length"); 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; } } /////////////////////////////////////////////////////////////////////////////// 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+'"'); } //MD5 = "3beb3005ce1c3c47fc21a91acf908f1f"; DATE = "2015.01.26 - 02:34:05"