From 56d66a4c07709e259653083dbf13c1ef26b134e9 Mon Sep 17 00:00:00 2001 From: ghostboats <106226990+ghostboats@users.noreply.github.com> Date: Thu, 9 May 2024 17:17:33 -0500 Subject: [PATCH] working, fixed ocnerter probs too --- commands/openConverter.js | 11 ++- support_files/conversion_junction.js | 121 +++++++++++---------------- 2 files changed, 54 insertions(+), 78 deletions(-) diff --git a/commands/openConverter.js b/commands/openConverter.js index 1006203d..2b438463 100644 --- a/commands/openConverter.js +++ b/commands/openConverter.js @@ -1,7 +1,10 @@ const vscode = require('vscode'); const { convert } = require('../support_files/conversion_junction.js'); +const { CREATE_LOGGER, raiseError } = require('../support_files/log_utils.js'); +const bg3mh_logger = CREATE_LOGGER(); + let openConverterCommand = vscode.commands.registerCommand('bg3-mod-helper.openConverter', async function () { - console.log('‾‾openConverterCommand‾‾'); + bg3mh_logger.info('‾‾openConverterCommand‾‾'); const panel = vscode.window.createWebviewPanel( 'converterView', 'Converter', @@ -17,7 +20,7 @@ let openConverterCommand = vscode.commands.registerCommand('bg3-mod-helper.openC panel.webview.html = getWebviewContent(lsxFiles, lsfFiles, xmlFiles, locaFiles); panel.webview.onDidReceiveMessage( (message) => { - console.log('Received message:', message); + bg3mh_logger.info('Received message:', message); try { switch (message.command) { case 'convertSelected': @@ -32,12 +35,12 @@ let openConverterCommand = vscode.commands.registerCommand('bg3-mod-helper.openC } } catch (err) { panel.webview.postMessage({ command: 'alert', text: 'Error during conversion: ' + err.message }); - console.error('Error during message processing:', err); + raiseError("Error during message processing: " + err, false); } } ); - console.log('__openConverterCommand__'); + bg3mh_logger.info('__openConverterCommand__'); }); function normalizePath(path) { diff --git a/support_files/conversion_junction.js b/support_files/conversion_junction.js index 03574949..b15cf72b 100644 --- a/support_files/conversion_junction.js +++ b/support_files/conversion_junction.js @@ -6,7 +6,7 @@ const vscode = require('vscode'); const { FIND_FILES, getFormats } = require('./lslib_utils'); const { lsx, xml, pak } = getFormats(); -const { raiseError } = require('./log_utils'); +const { raiseError, raiseInfo } = require('./log_utils'); const { getConfig } = require('./config.js'); const { rootModPath, modName, modDestPath, excludedFiles } = getConfig(); @@ -21,94 +21,67 @@ function getActiveTabPath() { } +function getDynamicPath(filePath) { + let temp_path; + if (Array.isArray(filePath)) { + temp_path = filePath[0]; + } + else if (typeof(filePath) == 'string') { + temp_path = filePath; + } + else { + temp_path = getActiveTabPath(); + } + + return temp_path; +} + + // this should be refactored in next release -function convert(convertPath = getActiveTabPath(), targetExt = path.extname(convertPath)) { +function convert(convertPath, targetExt = path.extname(getDynamicPath(convertPath))) { const { excludedFiles } = getConfig(); - convertPath = convertPath.toString(); + console.log(convertPath); + //convertPath = convertPath.toString(); + //bg3mh_logger.info(`Excluded Files: ${JSON.stringify(excludedFiles, null, 2)}`); //console.log(`Excluded Files: ${JSON.stringify(excludedFiles, null, 2)}`); - try { - if (Array.isArray(convertPath) && targetExt == "arr") { - for (var i = 0; i < convertPath.length; i++) { - convert(convertPath[i], path.extname(convertPath[i])); - } - } - else if (targetExt == pak) { - prepareTempDir(); - convert(rootModPath, xml); - convert(rootModPath, lsx); - processPak(rootModPath); + if (targetExt == pak) { + prepareTempDir(); + + convert(rootModPath, xml); + convert(rootModPath, lsx); + processPak(rootModPath); + } + else if (Array.isArray(convertPath)) { + for (var i = 0; i < convertPath.length; i++) { + convert(convertPath[i], path.extname(convertPath[i])); } - else if (isLoca(targetExt)) { - if (fs.statSync(convertPath).isDirectory()) { - var filesToConvert = FIND_FILES(convertPath, targetExt); - - for (var i = 0; i < filesToConvert.length; i++) { - try { - processLoca(filesToConvert[i], targetExt); - } - catch (Error) { - raiseError(Error); - return; - } - } - } - else if (fs.statSync(convertPath).isFile()) { - try { - processLoca(convertPath, targetExt); - - if (!Error) { - vscode.window.showInformationMessage(`Exported ${getLocaOutputPath(convertPath)} correctly.`); - } - } - catch (Error) { - raiseError(Error); - return; - } + } + else if (fs.statSync(convertPath).isDirectory()) { + console.log("finding %s files in %s directory", targetExt, convertPath) + convert(FIND_FILES(convertPath, targetExt)); + } + else if (fs.statSync(convertPath).isFile()) { + if (isLoca(targetExt)) { + try { + processLoca(convertPath, targetExt); } - else { - raiseError(convertPath + " is not a recognized directory or loca file.", false); - vscode.window.showErrorMessage(`${convertPath} is not a recognized directory or loca file.`); + catch (Error) { + raiseError(Error); return; } } else if (isLsf(targetExt)) { - if (fs.statSync(convertPath).isDirectory()) { - var filesToConvert = FIND_FILES(convertPath, targetExt); - - for (var i = 0; i < filesToConvert.length; i++) { - try { - processLsf(filesToConvert[i], targetExt); - } - catch (Error) { - raiseError(Error); - return; - } - } - } - else if (fs.statSync(convertPath).isFile()) { - try { - processLsf(convertPath, targetExt); - - if (!Error) { - vscode.window.showInformationMessage(`Exported ${getLsfOutputPath(convertPath)} correctly.`); - } - } - catch (Error) { - raiseError(Error); - return; - } + try { + processLsf(convertPath, targetExt); } - else { - raiseError(convertPath + " is not a recognized directory or lsf file.", false); - vscode.window.showErrorMessage(`${convertPath} is not a recognized directory or lsf file.`); + catch (Error) { + raiseError(Error); return; } } - } - catch (error) { - raiseError(error); + } }