From 233e806221dcb213a11ddeddd6c5ed473b140f96 Mon Sep 17 00:00:00 2001 From: Ken Bynell Date: Tue, 14 May 2024 13:23:53 -0500 Subject: [PATCH] add normalization logic to config.js so excluded files work correctly --- support_files/config.js | 14 ++++++- support_files/conversion_junction.js | 57 +++++++++++++--------------- support_files/lslib_utils.js | 9 ++--- 3 files changed, 43 insertions(+), 37 deletions(-) diff --git a/support_files/config.js b/support_files/config.js index 90ebbda6..c3d95ecf 100644 --- a/support_files/config.js +++ b/support_files/config.js @@ -8,6 +8,18 @@ function setConfig(newConfig) { } +function normalizeExcludedFiles(excludedFiles) { + + if (Array.isArray(excludedFiles)) { + let normalizeExcludedFiles = excludedFiles.map((temp_file) => path.normalize(temp_file)); + return normalizeExcludedFiles; + } + else { + return path.normalize(excludedFiles); + } +} + + function getConfig() { const config = vscode.workspace.getConfiguration('bg3ModHelper'); return { @@ -20,7 +32,7 @@ function getConfig() { lslibPath: path.normalize(config.get('lslibPath')), autoLaunchOnPack: config.get('autoLaunchOnPack'), launchContinueGame: config.get('launchContinueGame'), - excludedFiles: config.get('excludedFiles') || [] + excludedFiles: normalizeExcludedFiles(config.get('excludedFiles')) }; } module.exports = { setConfig, getConfig }; diff --git a/support_files/conversion_junction.js b/support_files/conversion_junction.js index 9cc1e3ac..763ca428 100644 --- a/support_files/conversion_junction.js +++ b/support_files/conversion_junction.js @@ -43,19 +43,22 @@ function getDynamicPath(filePath) { function convert(convertPath, targetExt = path.extname(getDynamicPath(convertPath))) { - let { excludedFiles } = getConfig(); if (targetExt === "empty") { return; } - + // we can leave this here for the moment, might be a good logic bit to keep in the future. + /* + // changed this to a const so nothing bothers it while the conversion is taking place + const { excludedFiles } = getConfig(); const normalizedExcludedFiles = excludedFiles.map(file => path.normalize(file).replace(/^([a-zA-Z]):/, (match, drive) => drive.toUpperCase() + ':')); - // bg3mh_logger.info(`Normalized Excluded Files: ${JSON.stringify(normalizedExcludedFiles, null, 2)}`); - + bg3mh_logger.info(`Normalized Excluded Files: ${JSON.stringify(normalizedExcludedFiles, null, 2)}`); + const isExcluded = (file) => { const normalizedFile = path.normalize(file).replace(/^([a-zA-Z]):/, (match, drive) => drive.toUpperCase() + ':'); return normalizedExcludedFiles.includes(normalizedFile); }; + */ if (targetExt === pak) { prepareTempDir(); @@ -67,41 +70,35 @@ function convert(convertPath, targetExt = path.extname(getDynamicPath(convertPat } 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 { - bg3mh_logger.info(`Excluded: ${convertPath[i]}`); - } + convert(convertPath[i], path.extname(convertPath[i])); + bg3mh_logger.info(`Excluded: ${convertPath[i]}`); } } 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); + convert(filesToConvert); } else if (fs.statSync(convertPath).isFile()) { - if (!isExcluded(convertPath)) { - if (isLoca(targetExt)) { - try { - processLoca(convertPath, targetExt); - } catch (Error) { - raiseError(Error); - return; - } + if (isLoca(targetExt)) { + try { + processLoca(convertPath, targetExt); + } catch (Error) { + raiseError(Error); + return; + } + } + if (isLsf(targetExt)) { + try { + processLsf(convertPath, targetExt); } - if (isLsf(targetExt)) { - try { - processLsf(convertPath, targetExt); - } - catch (Error) { - raiseError(Error); - return; - } + catch (Error) { + raiseError(Error); + return; } - } else { - raiseInfo(`Excluded: ${convertPath}`, false); } + } + else { + raiseInfo(`Excluded: ${convertPath}`, false); } } diff --git a/support_files/lslib_utils.js b/support_files/lslib_utils.js index bcc7c503..f28a171a 100644 --- a/support_files/lslib_utils.js +++ b/support_files/lslib_utils.js @@ -22,7 +22,7 @@ const { CREATE_LOGGER, raiseError, raiseInfo } = require('./log_utils.js') const bg3mh_logger = CREATE_LOGGER(); const { getConfig } = require('./config.js'); -const { lslibPath, excludedFiles } = getConfig(); +const { lslibPath } = getConfig(); const compatRootModPath = path.join(getConfig().rootModPath + "\\"); const lslibToolsPath = path.join(getConfig().lslibPath, TOOL_SUBDIR); @@ -149,8 +149,6 @@ function FIND_FILES(filesPath, targetExt = getFormats().lsf, isRecursive = true) recursive: isRecursive }); - bg3mh_logger.info(`Excluded Files: ${excludedFiles}`); - for (let i = 0; i < filesList.length; i++) { const temp = filesList[i].toString(); @@ -164,12 +162,12 @@ function FIND_FILES(filesPath, targetExt = getFormats().lsf, isRecursive = true) function FILTER_PATHS(filesPath) { - //raiseInfo(excludedFiles); + let excludedFiles = getConfig().excludedFiles; if (Array.isArray(filesPath)) { let filteredPaths = []; for (let i = 0; i < filesPath.length; i++) { - let temp_path = FILTER_PATHS(filesPath[i]); + let temp_path = FILTER_PATHS(path.normalize(filesPath[i])); if (temp_path) { filteredPaths.push(temp_path); @@ -183,7 +181,6 @@ function FILTER_PATHS(filesPath) { for (let i = 0; i < temp_path.length; 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; } }