Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

working, fixed ocnerter probs too #36

Merged
merged 1 commit into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions commands/openConverter.js
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -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':
Expand All @@ -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) {
Expand Down
121 changes: 47 additions & 74 deletions support_files/conversion_junction.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);

}
}

Expand Down
Loading