Skip to content

Commit

Permalink
implemented FILTER_PATHS
Browse files Browse the repository at this point in the history
  • Loading branch information
khbsd committed May 13, 2024
1 parent 8c28780 commit ff2a16c
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 29 deletions.
13 changes: 12 additions & 1 deletion commands/debug.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
const vscode = require('vscode');

const { CREATE_LOGGER } = require('../support_files/log_utils');
const { FILTER_PATHS, FIND_FILES, getFormats } = require('../support_files/lslib_utils');
const { xml, lsx } = getFormats();

const { rootModPath } = require('../support_files/config.js').getConfig();

const { CREATE_LOGGER, raiseInfo } = require('../support_files/log_utils');
var bg3mh_logger = CREATE_LOGGER();

var test_paths;

let debugCommand = vscode.commands.registerCommand('bg3-mod-helper.debugCommand', async function () { // Made the function async
console.log('‾‾debugCommand‾‾');
vscode.window.showWarningMessage(
'cmon dude i said no :('
)

test_paths = FIND_FILES(rootModPath, lsx);
raiseInfo(test_paths, false);

console.log('__debugCommand__');
});

Expand Down
22 changes: 15 additions & 7 deletions support_files/conversion_junction.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,25 @@ function convert(convertPath, targetExt = path.extname(getDynamicPath(convertPat
convert(rootModPath, xml);
convert(rootModPath, lsx);
processPak(rootModPath);
} else if (Array.isArray(convertPath)) {
}
else if (Array.isArray(convertPath)) {
for (let i = 0; i < convertPath.length; i++) {
if (!isExcluded(convertPath[i])) {
convert(convertPath[i], path.extname(convertPath[i]));
} else {
}
else {
bg3mh_logger.info(`Excluded: ${convertPath[i]}`);
}
}
} else if (fs.statSync(convertPath).isDirectory()) {
}
else if (fs.statSync(convertPath).isDirectory()) {
const filesToConvert = FIND_FILES(convertPath, targetExt);
const filteredFiles = filesToConvert.filter(file => !isExcluded(file));

bg3mh_logger.info(`Files to convert (after exclusion): ${JSON.stringify(filteredFiles, null, 2)}`);
convert(filteredFiles);
} else if (fs.statSync(convertPath).isFile() && !(convertPath == [])) {
}
else if (fs.statSync(convertPath).isFile() && !(convertPath == [])) {
if (!isExcluded(convertPath)) {
if (isLoca(targetExt)) {
try {
Expand All @@ -86,15 +91,18 @@ function convert(convertPath, targetExt = path.extname(getDynamicPath(convertPat
raiseError(Error);
return;
}
} if (isLsf(targetExt)) {
}
if (isLsf(targetExt)) {
try {
processLsf(convertPath, targetExt);
} catch (Error) {
}
catch (Error) {
raiseError(Error);
return;
}
}
} else {
}
else {
raiseInfo(`Excluded: ${convertPath}`, false);
}
}
Expand Down
43 changes: 22 additions & 21 deletions support_files/lslib_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ const { lslibPath, excludedFiles } = getConfig();
const compatRootModPath = path.join(getConfig().rootModPath + "\\");
const lslibToolsPath = path.join(getConfig().lslibPath, TOOL_SUBDIR);

// separated for future use
const elasticDlls = ['Elastic.Transport.dll', 'Elastic.Clients.Elasticsearch.dll'];
const storyCompilerDll = ['StoryCompiler.dll', 'StoryDecompiler.dll'];
const storyCompilerDlls = ['StoryCompiler.dll', 'StoryDecompiler.dll'];
const converterAppDll = ['ConverterApp.dll'];
const illegalDlls = [].concat(elasticDlls, storyCompilerDlls, converterAppDll);

// the list of directories that need lsx > lsf conversion
const convertDirs = ["[PAK]", "RootTemplates", "MultiEffectInfos", "UI", "GUI", "Effects"];
const convertDirs = ["[PAK]", "RootTemplates", "MultiEffectInfos", "UI", "GUI", "Effects", "LevelMapValues"];

var DLLS = [];
var DLL_PATHS = [];
Expand Down Expand Up @@ -106,10 +108,8 @@ function loadDlls() {
}
*/

if (!converterAppDll.includes(temp_name) && !storyCompilerDll.includes(temp_name) && !elasticDlls.includes(temp_name)) {
dotnet.load(DLLS[i]);
bg3mh_logger.info("%s loaded.", DLLS[i]);
}
dotnet.load(DLLS[i]);
bg3mh_logger.info("%s loaded.", DLLS[i]);
}
catch (Error) {
raiseError(Error);
Expand All @@ -128,7 +128,7 @@ function LOAD_LSLIB() {
}
else {
raiseError("LSLib.dll not found at " + lslibPath + ".", false);
vscode.window.showErrorMessage(`LSLib.dll not found at ${lslibPath}. Are you sure you arent using the legacy option using divine.exe?`)
vscode.window.showErrorMessage(`LSLib.dll not found at ${lslibPath}. Are you sure you aren't using the legacy option using divine.exe?`);
return null;
}

Expand Down Expand Up @@ -157,35 +157,36 @@ function FIND_FILES(filesPath, targetExt = getFormats().lsf, isRecursive = true)
const temp = filesList[i].toString();

if (path.extname(temp) === targetExt) {
const fullPath = path.join(filesPath, filesList[i].toString());

if (!excludedFiles.includes(fullPath)) {
bg3mh_logger.info(`Included: ${fullPath}`);
filesToConvert.push(fullPath);
}
else {
bg3mh_logger.info(`Excluded: ${fullPath}`);
}
filesToConvert.push(path.join(filesPath, temp));
}
}
return filesToConvert;

return FILTER_PATHS(filesToConvert);

}


function FILTER_PATHS(filesPath) {
//raiseInfo(excludedFiles);
if (Array.isArray(filesPath)) {
let filteredPaths = [];

for (let i = 0; i < filesPath.length; i++) {
filteredPaths.push(FILTER_PATHS(filesPath[i]));
let temp_path = FILTER_PATHS(filesPath[i]);

if (temp_path) {
filteredPaths.push(temp_path);
}
}
return filteredPaths;
}
else if (typeof(filesPath == 'string')) {
else if (typeof(filesPath) == 'string') {
let temp_path = filesPath.split(path.sep);
let temp_ext = path.extname(filesPath);

for (let i = 0; i < temp_path.length; i++) {
if (!excludedFiles.includes(temp_path[i]) && convertDirs.includes(temp_path[i])) {
if ((!excludedFiles.includes(filesPath) && convertDirs.includes(temp_path[i])) || (temp_ext === getFormats().dll && !illegalDlls.includes(path.basename(filesPath)))) {
bg3mh_logger.info(`${filesPath} included`);
return filesPath;
}
}
Expand Down Expand Up @@ -221,4 +222,4 @@ function moveFileAcrossDevices(sourcePath, destPath, raiseError) {

const LSLIB = LOAD_LSLIB();

module.exports = { LSLIB, FIND_FILES, getFormats, moveFileAcrossDevices, baseNamePath, dirSeparator, compatRootModPath };
module.exports = { LSLIB, FIND_FILES, FILTER_PATHS, getFormats, moveFileAcrossDevices, baseNamePath, dirSeparator, compatRootModPath };

0 comments on commit ff2a16c

Please sign in to comment.