Skip to content

Commit

Permalink
babrebones mod unpacking
Browse files Browse the repository at this point in the history
  • Loading branch information
khbsd committed May 21, 2024
1 parent 6e1813c commit dbaf936
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 13 deletions.
25 changes: 25 additions & 0 deletions commands/unpackMod.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
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 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));

});
1 change: 1 addition & 0 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const { v4: uuidv4 } = require('uuid');
const fs = require('fs');
const { setConfig, getConfig } = require('./support_files/config');
const packModImport = require('./commands/packMod');
const unpackModCommand = require('./commands/unpackMod');
const launchGameImport = require('./commands/launchGame');
const createAtlasImport = require('./commands/createAtlas');
const insertHandleUUIDImport = require('./commands/insertHandleUUID');
Expand Down
27 changes: 18 additions & 9 deletions support_files/conversion_junction.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const bg3mh_logger = CREATE_LOGGER();

const { getConfig } = require('./config.js');

const { getModName } = require('./helper_functions.js');

const { isLoca, processLoca, getLocaOutputPath } = require('./loca_convert');
const { isLsf, processLsf, getLsfOutputPath } = require('./lsf_convert');
const { processPak, prepareTempDir } = require('./process_pak');
Expand Down Expand Up @@ -42,8 +44,9 @@ function getDynamicPath(filePath) {


function convert(convertPath, targetExt = path.extname(getDynamicPath(convertPath)), modName_ = '') {
console.log('targetExt:' + targetExt)
const { rootModPath } = getConfig();

console.log('targetExt:' + targetExt);
if (targetExt === "empty") {
return;
}
Expand All @@ -60,15 +63,21 @@ function convert(convertPath, targetExt = path.extname(getDynamicPath(convertPat
return normalizedExcludedFiles.includes(normalizedFile);
};
*/
console.log('test10')
console.log('test10');

if (targetExt === pak) {
prepareTempDir();
console.log('past prepare temp')
// changed these back, hope that's okay
console.log(rootModPath);
convert(rootModPath, xml);
convert(rootModPath, lsx);
processPak(rootModPath, modName_);
if (fs.statSync(convertPath).isDirectory()) {
prepareTempDir();
console.log('past prepare temp')
// changed these back, hope that's okay
console.log(rootModPath);
convert(rootModPath, xml);
convert(rootModPath, lsx);
processPak(rootModPath, modName_);
}
else if (fs.statSync(convertPath).isFile()) {
processPak(convertPath, modName_);
}
}
else if (Array.isArray(convertPath)) {
console.log('array1')
Expand Down
19 changes: 15 additions & 4 deletions support_files/process_pak.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const temp_folder = "\\temp_folder";
// const temp_path = path.join(rootParentPath, temp_folder);


// this function is going away next release.
// this function is getting redone for next release
function prepareTempDir(movedPak = false) {
const { rootModPath } = getConfig();
const rootParentPath = path.dirname(rootModPath);
Expand Down Expand Up @@ -47,20 +47,31 @@ function prepareTempDir(movedPak = false) {
// btw, sometimes this will log things before others because it's async.
async function processPak(modPath, modName_) {
console.log('check')
const { rootModPath, modDestPath } = getConfig();

var build = new LSLIB.PackageBuildData();
var Packager = new LSLIB.Packager();

const { rootModPath, modDestPath } = getConfig();

const lastFolderName = path.basename(rootModPath);
const rootParentPath = path.dirname(rootModPath);
const temp_path = path.join(rootParentPath, temp_folder);

const modFinalDestPath = path.join(modDestPath, lastFolderName + pak);
const modTempDestPath = path.join(temp_path, lastFolderName + pak);

const metaPath = path.join(rootModPath, 'Mods', modName_, 'meta.lsx');


try {
if (path.extname(modPath) === pak && fs.statSync(modPath).isFile()) {
try {
await Packager.UncompressPackage(modPath, temp_path);
}
catch (Error) {
raiseError(Error);
}
raiseInfo(`Mod ${path.basename(modPath)} unpacked to ${temp_path}`)
return;
}
// i'd like to refactor xml code into its own file for next release

// Read the XML content
Expand Down

0 comments on commit dbaf936

Please sign in to comment.