Skip to content

Commit

Permalink
async batch unpak is kind of functional
Browse files Browse the repository at this point in the history
  • Loading branch information
khbsd committed May 25, 2024
1 parent 849fddf commit 27b8d40
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 12 deletions.
3 changes: 1 addition & 2 deletions commands/createAtlas.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ const path = require('path');
const fs = require('fs');
const { Magick, MagickCore } = require('magickwand.js');
const xmlbuilder = require('xmlbuilder');
const { getConfig, setConfig } = require('../support_files/config');
const { getModName } = require('../support_files/helper_functions.js');
const { getConfig, setConfig, getModName } = require('../support_files/config');
const { v4: uuidv4 } = require('uuid');

const truncate = (number, digits) => {
Expand Down
4 changes: 2 additions & 2 deletions commands/createFileFromTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ const vscode = require('vscode');
const path = require('path');
const fs = require('fs');

const { insertText, getModName } = require('../support_files/helper_functions');
const { getConfig } = require('../support_files/config');
const { insertText } = require('../support_files/helper_functions');
const { getConfig, getModName } = require('../support_files/config');
const templates = require('../support_files/templates/skeleton_files');

const locales = [
Expand Down
33 changes: 29 additions & 4 deletions commands/debug2.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,42 @@ const LSLIB_DLL = 'LSLib.dll';
const TOOL_SUBDIR = 'Tools\\';

const { getConfig } = require('../support_files/config');
const { lslibPath, rootModPath } = getConfig();
const { lslibPath, rootModPath, gameInstallLocation } = getConfig();
const compatRootModPath = path.join(rootModPath + "\\");
const lslibToolsPath = path.join(lslibPath, TOOL_SUBDIR);

const { raiseInfo } = require('../support_files/log_utils');
const { CREATE_LOGGER, raiseError, raiseInfo } = require('../support_files/log_utils');
var bg3mh_logger = CREATE_LOGGER();

const { FIND_FILES, getFormats, dirSeparator } = require('../support_files/lslib_utils.js');
const { pak } = getFormats();
const { processPak } = require('../support_files/process_pak.js');

const { LSLIB } = require('../support_files/lslib_utils.js');

const debug2 = vscode.commands.registerCommand('bg3-mod-helper.debug2Command', async function () {
raiseInfo("hi dipshit! 💩");
// raiseInfo("hi dipshit! 💩");
// let test_dir = path.join(rootModPath, 'unpacking_test\\test_paks');
let test_dir = path.join(gameInstallLocation, 'Data');
let unpackDest = "W:\\Libraries\\Documents\\Baldur's Gate 3 Mods\\unpacked_game_data";
let unpackList = await FIND_FILES(pak, test_dir);

console.log(test_dir);

raiseInfo(unpackList);

// for (let i = 0; i < unpackList.length; i++) {
for await (const pakPath of unpackList) {
//let pakPath = dirSeparator(unpackList[i]);
//let pakPath = unpackList[i];
let modName = path.basename(pakPath, pak);
console.log(modName)
//let unpackDest = dirSeparator(path.join(path.dirname(pakPath), modName));
console.log(unpackDest);

raiseInfo(`${modName} unpacking started`);
processPak(pakPath, modName, unpackDest);
raiseInfo(`${modName} unpacking ended`);
}

});

Expand Down
3 changes: 1 addition & 2 deletions commands/versionGenerator.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
const vscode = require('vscode');
const fs = require('fs');
const path = require('path');
const { getConfig } = require('../support_files/config');
const { getConfig, getModName } = require('../support_files/config');
const { CREATE_LOGGER } = require('../support_files/log_utils.js');
const { getModName } = require('../support_files/helper_functions.js');


const bg3mh_logger = CREATE_LOGGER();
Expand Down
16 changes: 15 additions & 1 deletion support_files/lslib_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,25 @@ async function FIND_FILES(targetExt = getFormats().lsf, filesPath = '**/*') {

if (targetExt === getFormats().dll) {
let dllDir = new vscode.RelativePattern(filesPath, '*' + targetExt);
console.log(dllDir);
filesList = (await findFiles(dllDir)).map(file => file.path);
}
else if (targetExt === getFormats().pak) {
let dllDir = new vscode.RelativePattern(filesPath, '**/*' + targetExt);
console.log(dllDir);
filesList = (await findFiles(dllDir)).map(file => dirSeparator(file.path));
}
else {
filesList = (await findFiles(filesPath + targetExt)).map(file => file.path);
}
return FILTER_PATHS(filesList);

if (targetExt === getFormats().pak) {
// filesList.map(file => dirSeparator(file));
return filesList;
}
else {
return FILTER_PATHS(filesList);
}
}


Expand All @@ -189,6 +202,7 @@ function FILTER_PATHS(filesPath) {
let temp_ext = path.extname(filesPath);

for (let i = 0; i < temp_path.length; i++) {
// these statements could technically be combined, but that doesn't make it very readable.
if (temp_ext === getFormats().dll && !illegalDlls.includes(path.basename(filesPath))) {
return filesPath;
}
Expand Down
2 changes: 1 addition & 1 deletion support_files/process_pak.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function prepareTempDir(movedPak = false) {


// btw, sometimes this will log things before others because it's async.
async function processPak(modPath, modName_, unpackLocation = '') {
async function processPak(modPath, modName_, unpackLocation = '') {
var build = new LSLIB.PackageBuildData();
var Packager = new LSLIB.Packager();

Expand Down

0 comments on commit 27b8d40

Please sign in to comment.