Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/ghostboats/bg3_mod_helper in…
Browse files Browse the repository at this point in the history
…to khbsd_dev
  • Loading branch information
khbsd committed May 23, 2024
2 parents 596e372 + 00437de commit e1f1314
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 28 deletions.
61 changes: 42 additions & 19 deletions commands/unpackMod.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,48 @@
const vscode = require('vscode');
const path = require('path');
const fs = require('fs');
const util = require('util');

const { exec } = require('child_process')
const execAsync = util.promisify(require('child_process').exec);

const { convert } = require('../support_files/conversion_junction.js');

const { getFormats } = require('../support_files/lslib_utils.js');
const { pak } = getFormats();
const { getConfig } = require('../support_files/config');
const { rootModPath } = getConfig();

const { convert } = require('../support_files/conversion_junction.js');
const { processPak } = require('../support_files/process_pak.js')

const unpackModCommand = vscode.commands.registerCommand('bg3-mod-helper.unpackMod', async function () {
const { getModName } = require('../support_files/helper_functions');
let modName = await getModName();

console.log(`Unpacking mod ${modName}.`)

convert(path.join(rootModPath, modName + pak));

});
const pakFileUri = await vscode.window.showOpenDialog({
canSelectFiles: true,
canSelectFolders: false,
canSelectMany: false,
filters: { 'PAK Files': ['pak'] },
title: 'Select a .pak file to unpack'
});

if (!pakFileUri) {
vscode.window.showInformationMessage('No file selected.');
return;
}

const outputFolderUri = await vscode.window.showOpenDialog({
canSelectFiles: false,
canSelectFolders: true,
canSelectMany: false,
title: 'Select a folder to unpack the .pak file into'
});

if (!outputFolderUri) {
vscode.window.showInformationMessage('No folder selected.');
return;
}

const pakFilePath = pakFileUri[0].fsPath;
const baseOutputFolderPath = outputFolderUri[0].fsPath;
const pakFileName = path.basename(pakFilePath, path.extname(pakFilePath));

// Create a unique folder for the unpacked contents
const outputFolderPath = path.join(baseOutputFolderPath, `${pakFileName}_unpacked`);

try {
await fs.promises.mkdir(outputFolderPath, { recursive: true });
await processPak(pakFilePath, 'n/a', outputFolderPath);
vscode.window.showInformationMessage(`Successfully unpacked ${path.basename(pakFilePath)} to ${outputFolderPath}`);
} catch (error) {
vscode.window.showErrorMessage(`Failed to unpack .pak file: ${error.message}`);
}
});
2 changes: 1 addition & 1 deletion node_modules/.package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"displayName": "bg3_mod_helper",
"publisher": "ghostboats",
"description": "This extension is designed to help you make mods in Baldur's Gate 3 by creating UUIDs and handles for you, as well as updating your .loca.xml files as well should they exist. And more to come in the future.",
"version": "2.2.0",
"version": "2.2.1",
"icon": "media/marketplace_icon.png",
"engines": {
"vscode": "^1.86.0"
Expand Down
2 changes: 1 addition & 1 deletion support_files/conversion_junction.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ async function convert(convertPath, targetExt = path.extname(getDynamicPath(conv
processPak(rootModPath, modName_);
}
else if (fs.statSync(convertPath).isFile()) {
processPak(convertPath, modName_);
processPak(convertPath, modName_, 'n/a');
}
}
else if (Array.isArray(convertPath)) {
Expand Down
7 changes: 3 additions & 4 deletions support_files/process_pak.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@ function prepareTempDir(movedPak = false) {


// btw, sometimes this will log things before others because it's async.
async function processPak(modPath, modName_) {
async function processPak(modPath, modName_, unpackLocation = '') {
const LSLIB = await require('./lslib_utils').LOAD_LSLIB();
//console.log('check')

var build = new LSLIB.PackageBuildData();
var Packager = new LSLIB.Packager();
Expand All @@ -63,12 +62,12 @@ async function processPak(modPath, modName_) {
try {
if (path.extname(modPath) === pak && fs.statSync(modPath).isFile()) {
try {
await Packager.UncompressPackage(modPath, temp_path);
await Packager.UncompressPackage(modPath, unpackLocation);
}
catch (Error) {
raiseError(Error);
}
raiseInfo(`Mod ${path.basename(modPath)} unpacked to ${temp_path}`)
raiseInfo(`Mod ${path.basename(modPath)} unpacked to ${unpackLocation}`)
return;
}
// i'd like to refactor xml code into its own file for next release
Expand Down

0 comments on commit e1f1314

Please sign in to comment.