// ChooseColumnAttributes, Julianon April 2017, V1.0 // Script for Directory Opus. For development information see: // https://resource.dopus.com/t/a-script-add-in-to-configure-the-attribute-column/25617 // ********** CHECK THE USER-CONFIGURATIONS IN A–D BELOW ********************** // A. NAME THE NEW ATTRIBUTES COLUMN: var sColumnHeader = "Att" // The even shorter "At" requires only 24 pixels width. // WARNING: If this is changed at a later stage, adjustments will need // to be made in all formats, tab groups and layouts. // B. SPECIFY THE COLUMN WIDTH IN NUMBER OF PIXELS: var nColumnWidth = 28 // Roughly 8 per letter - 28 is needed for the heading "Att". // C. TO DISPLAY OR HIDE AN ATTRIBUTE, ASSIGN THE VALUE true OR false RESPECTIVELY. var bAttrReadOnly = true // true displays the attribute. var bAttrArchive = false // false hides the attribute. var bAttrHidden = true var bAttrSystem = true var bAttrNonIndexed = false var bAttrCompressed = false var bAttrOffline = false var bAttrEncrypted = false // D. IF OTHER ATTRIBUTES ARE REQUIRED, ADD APPROPRIATE LINES HERE AND IN PART C: // Attributes are specified by a single 32-digit binary number. Common masks are: // 2^0="r", 2^1="h", 2^2="s", 2^5="a", 2^11="c", 2^12="o", 2^13= "i", 2^14= "e" var aAttr = new Array for (nN = 0; nN < 32; nN++) // Allowing up to 32 places (see URL below) aAttr [nN] = 0 // Zero is the default value for unlisted masks. aAttr [0] = new Array (bAttrReadOnly, "r") // Indexed by the power-of-2 index. aAttr [1] = new Array (bAttrHidden, "h") aAttr [2] = new Array (bAttrSystem, "s") aAttr [5] = new Array (bAttrArchive, "a") aAttr [11] = new Array (bAttrCompressed, "c") aAttr [12] = new Array (bAttrOffline, "o") aAttr [13] = new Array (bAttrNonIndexed, "i") aAttr [14] = new Array (bAttrEncrypted, "e") // For details of the available attributes, see: https://msdn.microsoft.com/en-us/library/windows/desktop/gg258117%28v=vs.85%29.aspx // ********** END OF USER CONFIGURATION *************************************** // ********** THE OnInit FUNCTION IMITIALISES THE COLUMNS FUNCTION ************ function OnInit (initData) { var url = "https://resource.dopus.com/t/a-script-add-in-to-configure-the-attribute-column/25617" UID = "7EC514AB-7DCF-44D4-8229-F7C5CA2536E6" initData.name = "ChooseColumnAttributes" initData.desc = "Save real estate by choosing only some attributes" initData.copyright = "(c) Julianon March 2017" initData.version = "1.0" initData.default_enable = true // ********** A column to display the status of project files ***************** var cmd = initData.AddColumn () cmd.name = sColumnHeader // Column header can be edited above. cmd.method = "onAttColumn" cmd.label = sColumnHeader cmd.defwidth = nColumnWidth.toString () + "px" // Column width can be edited above. cmd.defsort = 1 cmd.autogroup = true cmd.autorefresh = 2 // Refreshes the display even on change of attribute. cmd.justify = "left" } // End of the OnInit function // ********** THIS IS THE FUNCTION THAT POPULATES THE Att COLUMN ************** function onAttColumn (scriptColData) { var oFile = scriptColData.item // File whose attribute string is being computed. var sBin = doToBinary (oFile.attr) // Convert attr number to binary. while (sBin.length < 32) // Buffer to length 32. sBin = "0" + sBin sBin = doReverseString (sBin) // Make it littleendian. var sCodes = "" // This string of attribute letters will be the final column entry. for (nN = 0; nN < 32; nN++) { // Allowing up to 32 places. if (aAttr [nN]) { // If the attribute is on the list (that is, aAttr [nN] is non-zero), if (aAttr [nN] [0]) { // and if display of the attribute is required, if (sBin.charAt (nN) == "1") // and if the particular file's attribute has been set, sCodes = sCodes + aAttr [nN] [1] // then add the attribute letter, else sCodes = sCodes + "-" // or add a hyphen if the attribute has not been set. } } } scriptColData.value = sCodes // Write the string codes into the column. } // **************************************************************************** // ********** THREE HELPER FUNCTIONS ****************************************** // **************************************************************************** // ********** Convert a number to a bigendian binary string ******************* function doToBinary (nNumber) { // nNumber is any integer var sBinary = "" // nNumber = 0 returns an empty string. var nQuotient = nNumber while (nQuotient > 0) { var oDivision = new doDivision (nQuotient, 2) sBinary = oDivision.r.toString () + sBinary // Bigendian form nQuotient = oDivision.q } return sBinary } // Called: doDivision // ********** Division with a chosen least remainder ************************** function doDivision (nDividend, nDivisor) { // Intended only for integers. // No return, so usage is: var oDivisor = new doDivision (nDividend, 15, 4) this.n = nDividend this.d = nDivisor this.r = (nDividend) % nDivisor // Note: The % operator often returns a negative integer. if (this.r < 0) this.r = this.r + Math.abs (nDivisor) // Remainder is 0 or +ve, and is less that nDividend. this.q = (nDividend - this.r) / nDivisor // This is the quotient. } // ********** Reverse the characters of a string ****************************** function doReverseString (sString) { sString = String (sString) var sReverse = "" var nN = 0 for (nN = 0; nN < sString.length; nN++) sReverse = sString.charAt (nN) + sReverse return sReverse }