Skip to content

Commit

Permalink
ehhhhhhhh
Browse files Browse the repository at this point in the history
  • Loading branch information
khbsd committed May 24, 2024
1 parent 837fd0f commit db713ff
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 34 deletions.
21 changes: 18 additions & 3 deletions commands/debug2.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,27 @@ const compatRootModPath = path.join(rootModPath + "\\");
const lslibToolsPath = path.join(lslibPath, TOOL_SUBDIR);

const { raiseInfo } = require('../support_files/log_utils');


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

const { parentPort, isMainThread, Worker } = require('node:worker_threads');

const debug2 = vscode.commands.registerCommand('bg3-mod-helper.debug2Command', async function () {
raiseInfo("hi dipshit! 💩");
// raiseInfo("hi dipshit! 💩");

if (isMainThread) {
let halfCoreCount = os.availableParallelism() / 2;
let workerArray = [];

for (let i = 0; i < halfCoreCount; i++) {
workerArray.push(new Worker(path.join(__dirname, './worker_test.js')));

workerArray[i].once('message', (message) => {
console.log(message);
});

workerArray[i].postMessage(`hi from worker ${workerArray[i].threadId}`);
}
}

});

Expand Down
10 changes: 8 additions & 2 deletions commands/worker_test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
// const { CREATE_LOGGER, raiseError, raiseInfo } = require('../support_files/log_utils.js');
// const bg3mh_logger = CREATE_LOGGER();
const { parentPort, isMainThread, Worker } = require('node:worker_threads');
const { processLoca } = require('../support_files/loca_convert');
// const vscode = require('vscode');


parentPort.once('message', (message) => {
parentPort.postMessage(message);
});

19 changes: 14 additions & 5 deletions support_files/loca_convert.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
const { isMainThread } = require('node:worker_threads');

const path = require('path');
const vscode = require('vscode');

const { getFormats, baseNamePath, LOAD_LSLIB } = require('./lslib_utils');
const { CREATE_LOGGER, raiseError, raiseInfo } = require('./log_utils');
const bg3mh_logger = CREATE_LOGGER();

const { xml, loca } = getFormats();

var to_loca;
var LSLIB;
var bg3mh_logger;

if (isMainThread) {
const { CREATE_LOGGER, raiseError, raiseInfo } = require('./log_utils');
bg3mh_logger = CREATE_LOGGER();
}
else {
bg3mh_logger = console;
}

async function lslib_load() {
LSLIB = await LOAD_LSLIB();
Expand Down Expand Up @@ -49,10 +57,11 @@ async function processLoca(file, targetExt) {
temp_loca = LocaUtils.Load(file);

LocaUtils.Save(temp_loca, file_output);
raiseInfo(`Exported ${to_loca} file: ${file_output}`)

// raiseInfo(`Exported ${to_loca} file: ${file_output}`)
}
catch (Error) {
raiseError(Error);
// raiseError(Error);
}
}

Expand Down
72 changes: 48 additions & 24 deletions support_files/lslib_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
*/
const path = require('path');
const fs = require('fs');
const vscode = require('vscode');
const findFiles = vscode.workspace.findFiles;
const parse = vscode.Uri.parse;
var vscode;
var findFiles;

const { isMainThread, parentPort } = require('node:worker_threads');


// loads the api
Expand All @@ -20,8 +21,6 @@ const dotnet = require('node-api-dotnet/net8.0');

const LSLIB_DLL = 'LSLib.dll';
const TOOL_SUBDIR = 'Tools\\';
const { CREATE_LOGGER, raiseError, raiseInfo } = require('./log_utils.js')
const bg3mh_logger = CREATE_LOGGER();

const { getConfig } = require('./config.js');
const { lslibPath } = getConfig();
Expand Down Expand Up @@ -85,7 +84,8 @@ function processDllPaths() {
DLLS.push(temp_path);
}
catch (Error) {
raiseError(Error);
console.error(Error)
// raiseError(Error);
}
}
}
Expand All @@ -98,29 +98,53 @@ async function loadDlls() {
dotnet.load(DLLS[i]);
}
catch (Error) {
raiseError(Error);
console.error(Error)
// raiseError(Error);
}
}
}


// handles the finding of LSLib. logs will be created wherever this laods from.
async function LOAD_LSLIB() {
if (fs.existsSync(path.join(lslibPath, LSLIB_DLL))) {
DLL_PATHS = await FIND_FILES(getFormats().dll, lslibPath);
if (isMainThread) {
const { raiseError } = require('./log_utils.js')
vscode = require('vscode');
findFiles = vscode.workspace.findFiles;

if (fs.existsSync(path.join(lslibPath, LSLIB_DLL))) {
DLL_PATHS = await FIND_FILES(getFormats().dll, lslibPath);
}
else if (fs.existsSync(path.join(lslibToolsPath, LSLIB_DLL))) {
DLL_PATHS = await FIND_FILES(getFormats().dll, lslibToolsPath);
}
else {
raiseError("LSLib.dll not found at " + lslibPath + ".", false);
vscode.window.showErrorMessage(`LSLib.dll not found at ${lslibPath}. Are you sure you aren't using the legacy option using divine.exe?`);
return null;
}
}
else if (fs.existsSync(path.join(lslibToolsPath, LSLIB_DLL))) {
DLL_PATHS = await FIND_FILES(getFormats().dll, lslibToolsPath);
}
else {
raiseError("LSLib.dll not found at " + lslibPath + ".", false);
vscode.window.showErrorMessage(`LSLib.dll not found at ${lslibPath}. Are you sure you aren't using the legacy option using divine.exe?`);
return null;
findFiles = FIND_FILES_SYNC;

if (fs.existsSync(path.join(lslibPath, LSLIB_DLL))) {
DLL_PATHS = FIND_FILES_SYNC(lslibPath, getFormats().dll);
}
else if (fs.existsSync(path.join(lslibToolsPath, LSLIB_DLL))) {
DLL_PATHS = FIND_FILES_SYNC(lslibToolsPath, getFormats().dll);
}
else {
// raiseError("LSLib.dll not found at " + lslibPath + ".", false);
console.log(`LSLib.dll not found at ${lslibPath}. Are you sure you aren't using the legacy option using divine.exe?`);
return null;
}

}


processDllPaths();
await loadDlls();
raiseInfo(`${DLL_PATHS} \n.dlls loaded`, false);
// raiseInfo(`${DLL_PATHS} \n.dlls loaded`, false);

// have to ignore this because the ts-linter doesn't know 'LSLib' exists :starege:
// @ts-ignore
Expand All @@ -131,7 +155,7 @@ async function LOAD_LSLIB() {

// returns an array with the absolute paths to every file found with the target file extension.
// maybe replace with findFiles()?
function FIND_FILES_v1(filesPath, targetExt = getFormats().lsf, isRecursive = true) {
function FIND_FILES_SYNC(filesPath, targetExt = getFormats().lsf, isRecursive = true) {
let filesToConvert = [];

// console.log(filesPath);
Expand Down Expand Up @@ -207,29 +231,29 @@ function FILTER_PATHS(filesPath) {


// here in case people (i'm people) have their working directory and their AppData on different hard drives.
function moveFileAcrossDevices(sourcePath, destPath, raiseError) {
function moveFileAcrossDevices(sourcePath, destPath, console) {
fs.readFile(sourcePath, (readErr, data) => {
if (readErr) {
raiseError(readErr);
console.error(readErr);
return;
}
fs.writeFile(destPath, data, (writeErr) => {
if (writeErr) {
raiseError(writeErr);
console.error(writeErr);
return;
}
fs.unlink(sourcePath, unlinkErr => {
// added the check because it was raising an error every time the func was called
if (unlinkErr) {
raiseError(unlinkErr);
console.error(unlinkErr);
return;
}
});
});
});
raiseInfo(path.basename(sourcePath) + " moved to " + destPath, false);
vscode.window.showInformationMessage(`${path.basename(sourcePath)} moved to ${destPath}.`);
// raiseInfo(path.basename(sourcePath) + " moved to " + destPath, false);
// vscode.window.showInformationMessage(`${path.basename(sourcePath)} moved to ${destPath}.`);
}


module.exports = { LSLIB, LOAD_LSLIB, FIND_FILES, FIND_FILES_v1, FILTER_PATHS, getFormats, moveFileAcrossDevices, baseNamePath, dirSeparator, compatRootModPath };
module.exports = { LSLIB, LOAD_LSLIB, FIND_FILES, FIND_FILES_SYNC, FILTER_PATHS, getFormats, moveFileAcrossDevices, baseNamePath, dirSeparator, compatRootModPath };

0 comments on commit db713ff

Please sign in to comment.