From 00437deea2961a88f19e6ef91f0a7949b62b365e Mon Sep 17 00:00:00 2001 From: ghostboats <106226990+ghostboats@users.noreply.github.com> Date: Wed, 22 May 2024 21:30:24 -0500 Subject: [PATCH] unpacking file selection and dropoff location added as well as package.json version and lock --- commands/unpackMod.js | 61 +++++++++++++++++++--------- node_modules/.package-lock.json | 2 +- package-lock.json | 4 +- package.json | 2 +- support_files/conversion_junction.js | 4 +- support_files/process_pak.js | 6 +-- 6 files changed, 51 insertions(+), 28 deletions(-) diff --git a/commands/unpackMod.js b/commands/unpackMod.js index aae378d6..566693d2 100644 --- a/commands/unpackMod.js +++ b/commands/unpackMod.js @@ -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}`); + } +}); \ No newline at end of file diff --git a/node_modules/.package-lock.json b/node_modules/.package-lock.json index 1cf9e348..9662e56a 100644 --- a/node_modules/.package-lock.json +++ b/node_modules/.package-lock.json @@ -1,6 +1,6 @@ { "name": "bg3-mod-helper", - "version": "2.2.0", + "version": "2.2.1", "lockfileVersion": 3, "requires": true, "packages": { diff --git a/package-lock.json b/package-lock.json index b90624f9..104fae2d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "bg3-mod-helper", - "version": "2.2.0", + "version": "2.2.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "bg3-mod-helper", - "version": "2.2.0", + "version": "2.2.1", "license": "LGPL-3.0-or-later", "dependencies": { "log4js": "^6.9.1", diff --git a/package.json b/package.json index 82a772eb..31890877 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/support_files/conversion_junction.js b/support_files/conversion_junction.js index e63fe49f..3bbf69ce 100644 --- a/support_files/conversion_junction.js +++ b/support_files/conversion_junction.js @@ -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)) { diff --git a/support_files/process_pak.js b/support_files/process_pak.js index f1cb59bd..d8faf2fb 100644 --- a/support_files/process_pak.js +++ b/support_files/process_pak.js @@ -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(); @@ -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