diff --git a/commands/folderShortcuts.js b/commands/folderShortcuts.js index 154e1aa4..928ee2ff 100644 --- a/commands/folderShortcuts.js +++ b/commands/folderShortcuts.js @@ -5,13 +5,14 @@ const fs = require('fs').promises; const openModsFolderCommand = vscode.commands.registerCommand('bg3-mod-helper.openModsFolder', () => { - const modsFolderPath = path.join(getConfig().rootModPath, 'Mods'); - vscode.env.openExternal(vscode.Uri.file(modsFolderPath)); + const { modDestPath } = getConfig(); + vscode.env.openExternal(vscode.Uri.file(modDestPath)); }); const openGameFolderCommand = vscode.commands.registerCommand('bg3-mod-helper.openGameFolder', () => { - const gameFolderPath = getConfig().gameInstallLocation; - vscode.env.openExternal(vscode.Uri.file(gameFolderPath)); + const { gameInstallLocation } = getConfig(); + const dataFolderPath = path.join(gameInstallLocation, 'Data'); + vscode.env.openExternal(vscode.Uri.file(dataFolderPath)); }); const openLogsFolderCommand = vscode.commands.registerCommand('bg3-mod-helper.openLogsFolder', async () => { diff --git a/commands/packMod.js b/commands/packMod.js index 35c285c6..7089273c 100644 --- a/commands/packMod.js +++ b/commands/packMod.js @@ -50,30 +50,6 @@ const packModCommand = vscode.commands.registerCommand('bg3-mod-helper.packMod', bg3mh_logger.info("Grabbed mod name %s from %s.", modName, rootModPath); -/* - let modName = ''; - - // Check if Mods directory exists and get the first subfolder name - if (fs.existsSync(modsDirPath) && fs.lstatSync(modsDirPath).isDirectory()) { - const subfolders = fs.readdirSync(modsDirPath).filter(file => { - const filePath = path.join(modsDirPath, file); - return fs.lstatSync(filePath).isDirectory(); - }); - - if (subfolders.length > 0) { - // Assuming we need the first subfolder. Modify as needed. - modName = subfolders[0]; - console.log(`Mod name determined from subfolder: ${modName}`); - } else { - vscode.window.showErrorMessage('No subfolders found in Mods directory to get a modName variable or get correct meta location.'); - return; - } - } else { - vscode.window.showErrorMessage('Mods directory not found.'); - return; - } -*/ - if (!fs.existsSync(metaPath)) { const shouldCreateMeta = await vscode.window.showInformationMessage('meta.lsx not found in ' + metaPath + '. Do you want to create one?', 'Create Meta', 'Close'); if (shouldCreateMeta === 'Create Meta') { @@ -124,7 +100,7 @@ const packModCommand = vscode.commands.registerCommand('bg3-mod-helper.packMod', // console.log('test2') } // send the directory to the convert() function, and let it know it's a pak - convert(rootModPath, pak, modName); + await convert(rootModPath, pak, modName); if (settingsContent) { // console.log('test3') @@ -135,6 +111,9 @@ const packModCommand = vscode.commands.registerCommand('bg3-mod-helper.packMod', fs.writeFileSync(settingsFilePath, settingsContent, 'utf8'); // console.log('test5') } + if (autoLaunchOnPack) { + vscode.commands.executeCommand('bg3-mod-helper.launchGame'); + } // console.log('test6') }); diff --git a/commands/unpackMod.js b/commands/unpackMod.js index 566693d2..a9ebe30c 100644 --- a/commands/unpackMod.js +++ b/commands/unpackMod.js @@ -2,21 +2,30 @@ const vscode = require('vscode'); const path = require('path'); const fs = require('fs'); const { getConfig } = require('../support_files/config'); -const { convert } = require('../support_files/conversion_junction.js'); -const { processPak } = require('../support_files/process_pak.js') +const { processPak } = require('../support_files/process_pak.js'); -const unpackModCommand = vscode.commands.registerCommand('bg3-mod-helper.unpackMod', async function () { - const pakFileUri = await vscode.window.showOpenDialog({ - canSelectFiles: true, - canSelectFolders: false, - canSelectMany: false, - filters: { 'PAK Files': ['pak'] }, - title: 'Select a .pak file to unpack' - }); +const unpackModCommand = vscode.commands.registerCommand('bg3-mod-helper.unpackMod', async function (fileUri) { + let pakFilePath; - if (!pakFileUri) { - vscode.window.showInformationMessage('No file selected.'); - return; + // If the command is triggered via the context menu, use the provided URI. + if (fileUri && fileUri.scheme === 'file') { + pakFilePath = fileUri.fsPath; + } else { + // Show open dialog if not triggered via context menu + 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 || pakFileUri.length === 0) { + vscode.window.showInformationMessage('No file selected.'); + return; + } + + pakFilePath = pakFileUri[0].fsPath; } const outputFolderUri = await vscode.window.showOpenDialog({ @@ -31,11 +40,8 @@ const unpackModCommand = vscode.commands.registerCommand('bg3-mod-helper.unpackM 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 { @@ -45,4 +51,4 @@ const unpackModCommand = vscode.commands.registerCommand('bg3-mod-helper.unpackM } catch (error) { vscode.window.showErrorMessage(`Failed to unpack .pak file: ${error.message}`); } -}); \ No newline at end of file +}); diff --git a/extension.js b/extension.js index 2af2b107..f8d85fa6 100644 --- a/extension.js +++ b/extension.js @@ -185,7 +185,7 @@ function aSimpleDataProvider() { getChildren: (element) => { if (!element) { return Promise.resolve([ - { label: 'Pack/Unpacking Tool (Click arrow for quick actions, or text to open the tool)', command: 'bg3-mod-helper.openPacker', id: 'packer' }, + { label: 'Pack/Unpacking Tool (Click arrow for quick actions, or text to open the tool[tool is in development])', id: 'packer' }, { label: 'Conversion Tool (Click arrow for quick actions, or text to open the tool)', command: 'bg3-mod-helper.openConverter', id: 'conversion' }, { label: 'Launch Game', command: 'bg3-mod-helper.launchGame' }, { label: 'Generate Folder Structure', command: 'bg3-mod-helper.createModTemplate' }, @@ -196,12 +196,12 @@ function aSimpleDataProvider() { { label: 'Add Dependencies to Meta via modsettings.lsx', command: 'bg3-mod-helper.addDependencies'}, { label: 'Debug Command', command: 'bg3-mod-helper.debugCommand' }, { label: 'Debug2 Command', command: 'bg3-mod-helper.debug2Command' }, - { label: 'Folder Shortcuts', command: 'bg3-mod-helper.folderShortcuts', id: 'folderShortcuts' } + { label: 'Folder Shortcuts', id: 'folderShortcuts' } ]); } else if (element.id === 'packer') { return Promise.resolve([ { label: 'Pack Mod', command: 'bg3-mod-helper.packMod' }, - { label: 'Unpack Mod (in development)', command: 'bg3-mod-helper.unpackMod' } + { label: 'Unpack Mod', command: 'bg3-mod-helper.unpackMod' } ]); } else if (element.id === 'conversion') { return Promise.resolve([ diff --git a/node_modules/.package-lock.json b/node_modules/.package-lock.json index cc7a7a50..906bb9e3 100644 --- a/node_modules/.package-lock.json +++ b/node_modules/.package-lock.json @@ -1,6 +1,6 @@ { "name": "bg3-mod-helper", - "version": "2.2.2", + "version": "2.2.3", "lockfileVersion": 3, "requires": true, "packages": { diff --git a/package-lock.json b/package-lock.json index b0fad742..a56ea4df 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "bg3-mod-helper", - "version": "2.2.2", + "version": "2.2.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "bg3-mod-helper", - "version": "2.2.2", + "version": "2.2.3", "license": "LGPL-3.0-or-later", "dependencies": { "log4js": "^6.9.1", diff --git a/package.json b/package.json index 5dd6adb4..566d1590 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.2", + "version": "2.2.3", "icon": "media/marketplace_icon.png", "engines": { "vscode": "^1.86.0" @@ -345,6 +345,11 @@ "when": "resourceExtname == .lsx || resourceExtname == .loca || resourceExtname == .xml || resourceExtname == .lsf && isExcluded", "command": "bg3-mod-helper.removeFromExcludeList", "group": "navigation" + }, + { + "when": "resourceExtname == .pak", + "command": "bg3-mod-helper.unpackMod", + "group": "navigation" } ], "editor/context": [