Skip to content

Commit

Permalink
add normalization logic to config.js so excluded files work correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
khbsd committed May 14, 2024
1 parent 20731e8 commit 233e806
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 37 deletions.
14 changes: 13 additions & 1 deletion support_files/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 };
57 changes: 27 additions & 30 deletions support_files/conversion_junction.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
}
}

Expand Down
9 changes: 3 additions & 6 deletions support_files/lslib_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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();

Expand All @@ -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);
Expand All @@ -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;
}
}
Expand Down

0 comments on commit 233e806

Please sign in to comment.