Skip to content

Commit

Permalink
fixed error on filteredFiles being empty
Browse files Browse the repository at this point in the history
  • Loading branch information
khbsd committed May 10, 2024
1 parent 2f0884d commit 420c257
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions support_files/conversion_junction.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ const vscode = require('vscode');
const { FIND_FILES, getFormats } = require('./lslib_utils');
const { lsx, xml, pak } = getFormats();

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

const { getConfig } = require('./config.js');
const { rootModPath, modName, modDestPath, excludedFiles } = getConfig();
Expand All @@ -16,14 +17,17 @@ const { isLsf, processLsf, getLsfOutputPath } = require('./lsf_convert');
const { processPak, prepareTempDir } = require('./pack_mod');




function getActiveTabPath() {
return vscode.window.activeTextEditor.document.fileName;
}


function getDynamicPath(filePath) {
let temp_path;
if (Array.isArray(filePath)) {

if (Array.isArray(filePath) && filePath != []) {
temp_path = filePath[0];
}
else if (typeof(filePath) == 'string') {
Expand All @@ -33,42 +37,49 @@ function getDynamicPath(filePath) {
temp_path = getActiveTabPath();
}

if (temp_path === undefined) {
return "null.empty";
}
return temp_path;
}


// this should be refactored in next release
function convert(convertPath, targetExt = path.extname(getDynamicPath(convertPath))) {
if (targetExt === "empty") {
return;
}

const { excludedFiles } = getConfig();
const normalizedExcludedFiles = excludedFiles.map(file => path.normalize(file).replace(/^([a-zA-Z]):/, (match, drive) => drive.toUpperCase() + ':'));

console.log(`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') {
if (targetExt === pak) {
prepareTempDir();

convert(rootModPath, '.xml');
convert(rootModPath, '.lsx');
// changed these back, hope that's okay
convert(rootModPath, xml);
convert(rootModPath, lsx);
processPak(rootModPath);
} 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 {
console.log(`Excluded: ${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));
console.log(`Files to convert (after exclusion): ${JSON.stringify(filteredFiles, null, 2)}`);
bg3mh_logger.info(`Files to convert (after exclusion): ${JSON.stringify(filteredFiles, null, 2)}`);
convert(filteredFiles);
} else if (fs.statSync(convertPath).isFile()) {
} else if (fs.statSync(convertPath).isFile() && !(convertPath == [])) {
if (!isExcluded(convertPath)) {
if (isLoca(targetExt)) {
try {
Expand All @@ -77,7 +88,7 @@ function convert(convertPath, targetExt = path.extname(getDynamicPath(convertPat
raiseError(Error);
return;
}
} else if (isLsf(targetExt)) {
} if (isLsf(targetExt)) {
try {
processLsf(convertPath, targetExt);
} catch (Error) {
Expand All @@ -86,7 +97,7 @@ function convert(convertPath, targetExt = path.extname(getDynamicPath(convertPat
}
}
} else {
console.log(`Excluded: ${convertPath}`);
raiseInfo(`Excluded: ${convertPath}`, false);
}
}
}
Expand Down

0 comments on commit 420c257

Please sign in to comment.