diff --git a/xtrn/ddfilelister/ddfilelister.js b/xtrn/ddfilelister/ddfilelister.js index b18221e6fdd6e83e4f1ea3118f138e07075d9d09..8f5da9e3974909ea6ce249d6cdceed507f55c940 100644 --- a/xtrn/ddfilelister/ddfilelister.js +++ b/xtrn/ddfilelister/ddfilelister.js @@ -47,6 +47,11 @@ * When extended file descriptions are enabled, the file * date is now shown with the file description on the last * line. + * 2022-12-02 Eric Oulashin Version 2.07 + * In a file's extended description, added the number of times + * downloaded and date/time last downloaded. Also, fixed a bug + * where some descriptions were blank in the Frame object because + * of a leading normal attribute (the fix may be a kludge though). */ "use strict"; @@ -104,8 +109,8 @@ if (system.version_num < 31900) } // Lister version information -var LISTER_VERSION = "2.06"; -var LISTER_DATE = "2022-04-13"; +var LISTER_VERSION = "2.07"; +var LISTER_DATE = "2022-12-02"; /////////////////////////////////////////////////////////////////////////////// @@ -566,8 +571,19 @@ function showFileInfo(pFileList, pFileListMenu) else fileDesc = fileMetadata.desc; // It's possible for fileDesc to be undefined (due to extDesc or desc being undefined), - // so make sure it's a string - if (typeof(fileDesc) !== "string") + // so make sure it's a string. + // Also, if it's a string, reformat certain types of strings that don't look good in a + // Frame object + if (typeof(fileDesc) === "string") + { + // Check to see if it starts with a normal attribute and remove if so, + // since that seems to cause problems with displaying the description in a Frame object. This + // may be a kludge, and perhaps there's a better solution.. + fileDesc = fileDesc.replace(/^\x01[nN]/, ""); + // Fix line endings if necessary + fileDesc = fixStrLineEndings(fileDesc); + } + else fileDesc = ""; // This might be overkill, but just in case, convert any non-Synchronet // attribute codes to Synchronet attribute codes in the description. @@ -583,10 +599,17 @@ function showFileInfo(pFileList, pFileListMenu) fileInfoStr += gColors.desc; if (fileDesc.length > 0) - fileInfoStr += "Description:\r\n" + fileDesc; + fileInfoStr += "Description:\r\n" + fileDesc; // Don't want to use strip_ctrl(fileDesc) else fileInfoStr += "No description available"; fileInfoStr += "\r\n"; + // # of times downloaded and last downloaded date/time + var fieldFormatStr = "\r\n\x01n\x01c\x01h%s\x01g:\x01n\x01c %s"; + var timesDownloaded = fileMetadata.hasOwnProperty("times_downloaded") ? fileMetadata.times_downloaded : 0; + fileInfoStr += format(fieldFormatStr, "Times downloaded", timesDownloaded); + if (fileMetadata.hasOwnProperty("last_downloaded")) + fileInfoStr += format(fieldFormatStr, "Last downloaded", strftime("%Y-%m-%d %H:%M", fileMetadata.last_downloaded)); + // Some more fields for the sysop if (user.is_sysop) { var sysopFields = [ "from", "cost", "added"]; @@ -598,11 +621,12 @@ function showFileInfo(pFileList, pFileListMenu) if (typeof(fileMetadata[prop]) === "string" && fileMetadata[prop].length == 0) continue; var propName = prop.charAt(0).toUpperCase() + prop.substr(1); - fileInfoStr += "\r\n\x01n\x01c\x01h" + propName + "\x01g:\x01n\x01c "; + var infoValue = ""; if (prop == "added") - fileInfoStr += strftime("%Y-%m-%d %H:%M:%S", fileMetadata.added); + infoValue = strftime("%Y-%m-%d %H:%M:%S", fileMetadata.added); else - fileInfoStr += fileMetadata[prop].toString().substr(0, frameInnerWidth); + infoValue = fileMetadata[prop].toString().substr(0, frameInnerWidth); + fileInfoStr += format(fieldFormatStr, propName, infoValue); fileInfoStr += "\x01n\x01w"; } } @@ -642,6 +666,48 @@ function showFileInfo(pFileList, pFileListMenu) return retObj; } +// Splits a string on a given string and then re-combines the string with \r\n (carriage return & newline) +// at the end of each line +// +// Parameters: +// pStr: The string to split & recombine +// pSplitStr: The string to split the first string on +// +// Return value: The string split on pSplitStr and re-combined with \r\n at the end of each line +function splitStrAndCombineWithRN(pStr, pSplitStr) +{ + if (typeof(pStr) !== "string") + return ""; + if (typeof(pSplitStr) !== "string") + return pStr; + + var newStr = ""; + var strs = pStr.split(pSplitStr); + if (strs.length > 0) + { + for (var i = 0; i < strs.length; ++i) + newStr += strs[i] + "\r\n"; + newStr = newStr.replace(/\r\n$/, ""); + } + else + newStr = pStr; + return newStr; +} + +// Fixes line endings in a string +function fixStrLineEndings(pStr) +{ + if (typeof(pStr) !== "string") + return ""; + + // If there's only a return or only a newline, split & recombine with \r\n + var newStr = pStr; + if (/[^\r]\n[^\r]/.test(newStr)) // Only a newline + newStr = splitStrAndCombineWithRN(newStr, "\n"); + else if (/[^\n]\r[^\n]/.test(newStr)) // Only a carriage return + newStr = splitStrAndCombineWithRN(newStr, "\r"); + return newStr; +} // Lets the user view a file. // @@ -3158,7 +3224,11 @@ function populateFileList(pSearchMode) { gFileList[i].dirCode = bbs.curdir_code; if (gFileList[i].hasOwnProperty("extdesc") && /\r\n$/.test(gFileList[i].extdesc)) + { gFileList[i].extdesc = gFileList[i].extdesc.substr(0, gFileList[i].extdesc.length-2); + // Fix line endings if necessary + gFileList[i].extdesc = fixStrLineEndings(gFileList[i].extdesc); + } } } else diff --git a/xtrn/ddfilelister/readme.txt b/xtrn/ddfilelister/readme.txt index 94eebff6b4923e30d824f8031b654cfd39b20081..f3bd4578857f6b038986840a3007427a6d4ce78a 100644 --- a/xtrn/ddfilelister/readme.txt +++ b/xtrn/ddfilelister/readme.txt @@ -1,6 +1,6 @@ Digital Distortion File Lister - Version 2.06 - Release date: 2022-04-13 + Version 2.07 + Release date: 2022-12-02 by diff --git a/xtrn/ddfilelister/revision_history.txt b/xtrn/ddfilelister/revision_history.txt index 262568367956a6df06cc109d04c4bff74a099b9a..807ee7ae3b77571cd8955c56e0d0d03a268e8e2e 100644 --- a/xtrn/ddfilelister/revision_history.txt +++ b/xtrn/ddfilelister/revision_history.txt @@ -5,6 +5,11 @@ Revision History (change log) ============================= Version Date Description ------- ---- ----------- +2.07 2022-12-02 In a file's extended description, added the number of + times downloaded and date/time last downloaded. Also, + fixed a bug where some descriptions were blank in the + extended description box because of a leading normal + attribute. 2.06 2022-04-13 When extended file descriptions are enabled, the file date is now shown with the file description on the last line. 2.05a 2022-03-13 Fix for "fileDesc is not defined" error when displaying @@ -33,4 +38,4 @@ Version Date Description info. Fixed command bar refreshing when pressing the hotkeys. Added an option to pause after viewing a file (defaults to true). -2.00 2022-02-06 Initial version. \ No newline at end of file +2.00 2022-02-06 Initial version.