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 24, 2024
2 parents f295278 + 90c27e1 commit 849fddf
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 53 deletions.
9 changes: 5 additions & 4 deletions commands/folderShortcuts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
29 changes: 4 additions & 25 deletions commands/packMod.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down Expand Up @@ -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')
Expand All @@ -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')
});

Expand Down
40 changes: 23 additions & 17 deletions commands/unpackMod.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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 {
Expand All @@ -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}`);
}
});
});
6 changes: 3 additions & 3 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
Expand All @@ -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([
Expand Down
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.

7 changes: 6 additions & 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.2",
"version": "2.2.3",
"icon": "media/marketplace_icon.png",
"engines": {
"vscode": "^1.86.0"
Expand Down Expand Up @@ -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": [
Expand Down

0 comments on commit 849fddf

Please sign in to comment.