Skip to content

Commit

Permalink
unpacking file selection and dropoff location added as well as packag…
Browse files Browse the repository at this point in the history
…e.json version and lock
  • Loading branch information
ghostboats committed May 23, 2024
1 parent dbaf936 commit 00437de
Show file tree
Hide file tree
Showing 6 changed files with 51 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
4 changes: 2 additions & 2 deletions support_files/conversion_junction.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ function convert(convertPath, targetExt = path.extname(getDynamicPath(convertPat
console.log(rootModPath);
convert(rootModPath, xml);
convert(rootModPath, lsx);
processPak(rootModPath, modName_);
processPak(rootModPath, modName_, 'n/a');
}
else if (fs.statSync(convertPath).isFile()) {
processPak(convertPath, modName_);
processPak(convertPath, modName_, 'n/a');
}
}
else if (Array.isArray(convertPath)) {
Expand Down
6 changes: 3 additions & 3 deletions support_files/process_pak.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ 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 = '') {
console.log('check')

var build = new LSLIB.PackageBuildData();
Expand All @@ -64,12 +64,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 00437de

Please sign in to comment.