Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
BusterBrown1218 committed Jul 12, 2024
2 parents a2b1023 + ce7b102 commit 41bac6d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
2 changes: 1 addition & 1 deletion gui/LoadActionGUI.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ function readFiles() {
renderItemIcons = [];
if (Settings.toggleFileExplorer && !show) return;
try {
files = readDir(`./config/ChatTriggers/modules/HTSL/imports/${subDir.replace("\\", "/")}`, false).filter(n => n.endsWith(".htsl") || n.endsWith(".json") || !n.includes("."));
files = readDir(`./config/ChatTriggers/modules/HTSL/imports/${subDir.replace(/\\+/g, "/")}`, false).filter(n => n.endsWith(".htsl") || n.endsWith(".json") || !n.includes("."));
files.sort().sort((a, b) => {
let isDirA = a.endsWith('\\');
let isDirB = b.endsWith('\\');
Expand Down
34 changes: 28 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,23 +117,45 @@ register("command", ...args => {
* Obtains a list of file names from a directory.
* @param {string} path The path to the directory to walk.
* @param {boolean} walk `true` if the function should walk deeper into directories.
* @returns
* @returns
*/
function readDir(path, walk) {
let files = new java.io.File(path).listFiles();
let fileNames = [];
let regex = new RegExp(path.replace(/\//g, "\\\\") + "(.*)");

files.forEach(file => {
if (file.isDirectory()) {
if (walk) {
readDir(path + file.getName() + "/").forEach(newFile => fileNames.push((file.toString() + "\\" + newFile.toString()).match(regex)[1]));
readDir(path + file.getName() + "/", false).forEach(newFile => {
const fileName = getMatchedFileName(path, `${file}\\${newFile}`);

if (fileName) fileNames.push(fileName);
});
} else {
fileNames.push(file.toString().match(regex)[1] + "\\");
const fileName = getMatchedFileName(path, file.toString());

if (fileName) fileNames.push(`${fileName}\\`);
}
} else {
let match = file.toString().match(regex);
if (match) fileNames.push(match[1]);
const fileName = getMatchedFileName(path, file.toString());

if (fileName) fileNames.push(fileName);
}
});
return fileNames;
}

function getMatchedFileName(path, filePath) {
const formattedPath = path.replace(/\//g, "\\\\");
const fileFormattedMatchRegexp = new RegExp(`${formattedPath}(.*)`);
const formattedPathMatchArray = filePath.match(fileFormattedMatchRegexp);

if (formattedPathMatchArray) return formattedPathMatchArray[1];

const fileMatchRegexp = new RegExp(`${path}(.*)`);
const pathMatchArray = filePath.match(fileMatchRegexp);

if (pathMatchArray) return pathMatchArray[1];

return null;
}

0 comments on commit 41bac6d

Please sign in to comment.