diff --git a/commands/debug2.js b/commands/debug2.js index 39b86e25..238c809a 100644 --- a/commands/debug2.js +++ b/commands/debug2.js @@ -17,7 +17,7 @@ const { saveConfigFile, loadConfigFile } = require('../support_files/helper_func 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 { FIND_FILES, getFormats, dirSeparator, LOAD_LSLIB } = require('../support_files/lslib_utils.js'); const { pak } = getFormats(); const { processPak } = require('../support_files/process_pak.js'); @@ -29,24 +29,22 @@ const debug2 = vscode.commands.registerCommand('bg3-mod-helper.debug2Command', a let halfCoreCount = os.availableParallelism() / 2; let workerArray = []; - let workerInfo = await loadConfigFile(true); + let workerConfig = JSON.parse(loadConfigFile(true)); + // let workerLSLIB = await LOAD_LSLIB(); if (isMainThread) { for (let i = 0; i < halfCoreCount; i++) { - workerArray.push(new Worker(__dirname + "/worker_test.js")); + workerArray.push(new Worker(__dirname + "/worker_test.js", { workerData: workerConfig })); workerArray[i].on('message', (message) => { console.log(`${message} received from worker ${workerArray[i].threadId}!`) }); - workerArray[i].postMessage(workerInfo); + workerArray[i].postMessage(workerConfig); } } - saveConfigFile(); - console.log(await loadConfigFile(true)); - }); diff --git a/commands/worker_test.js b/commands/worker_test.js index 47db30b1..fc9e4959 100644 --- a/commands/worker_test.js +++ b/commands/worker_test.js @@ -1,13 +1,18 @@ -// const { CREATE_LOGGER, raiseError, raiseInfo } = require('../support_files/log_utils.js'); -// const bg3mh_logger = CREATE_LOGGER(); -const { parentPort } = require('node:worker_threads'); +const { CREATE_LOGGER, raiseError, raiseInfo } = require('../support_files/log_utils.js'); +const bg3mh_logger = CREATE_LOGGER(); +const { parentPort, workerData } = require('node:worker_threads'); const path = require('node:path'); const fs = require('node:fs'); +const { LOAD_LSLIB } = require('../support_files/lslib_utils.js') -parentPort.once('message', (message) => { - let messageParsed = JSON.parse(message); +parentPort.once('message', async () => { + raiseInfo(`lookee lslib @ ${workerData.lslibPath}`) + parentPort.postMessage("i got the workerData bitchhhhhhh"); - let rootModPath = messageParsed.rootModPath; - parentPort.postMessage(rootModPath); + /*try { + let LSLIB = await LOAD_LSLIB(); + } catch (Error) { + raiseError(Error); + }*/ }); \ No newline at end of file diff --git a/extension.js b/extension.js index 804b6ce2..ecd3789a 100644 --- a/extension.js +++ b/extension.js @@ -42,7 +42,7 @@ const setupFunctionDescriptionHoverProvider = require('./hovers/functionDescript const setupUuidsHandlesHoverProvider = require('./hovers/uuidsHandlesCollector'); const { resizeImageTooltip, resizeImageController, resizeImageHotbar, resizeImageCustom } = require('./commands/resizeImage'); -const { getFullPath } = require('./support_files/helper_functions'); +const { getFullPath, saveConfigFile, loadConfigFile } = require('./support_files/helper_functions'); async function addToExcludeList(fileUri) { @@ -101,23 +101,10 @@ function activate(context) { }); } - let config = vscode.workspace.getConfiguration('bg3ModHelper'); - - setConfig({ - maxFilesToShow: config.get('hover.maxFiles'), - hoverEnabled: config.get('hover.enabled'), - maxCacheSize: config.get('maxCacheSize'), - rootModPath: config.get('rootModPath'), - modDestPath: config.get('modDestPath'), - lslibPath: config.get('lslibPath'), - autoLaunchOnPack: config.get('autoLaunchOnPack'), - launchContinueGame: config.get('launchContinueGame'), - addHandlesToAllLocas: config.get('addHandlesToAllLocas'), - excludedFiles: config.get('excludedFiles') || [], - gameInstallLocation: config.get('gameInstallLocation') - }); - raiseInfo('Initial configs set:' + JSON.stringify(config, null, 2), false); - + if (loadConfigFile(true) === undefined) { + saveConfigFile(); + } + if (!vscode.workspace.workspaceFolders || vscode.workspace.workspaceFolders.length === 0) { vscode.window.showWarningMessage( 'bg3-mod-helper extension requires a workspace to be set for optimal functionality, one not found.' diff --git a/support_files/helper_functions.js b/support_files/helper_functions.js index 5abc527d..4494ac7c 100644 --- a/support_files/helper_functions.js +++ b/support_files/helper_functions.js @@ -4,7 +4,7 @@ const { getConfig, setConfig } = require('./config'); const fs = require('fs'); const rootModPath = getConfig().rootModPath; -const vscodeDirPath = path.join(rootModPath, '.vscode'); +const vscodeDirPath = path.join(rootModPath, '/.vscode'); const settingsFilePath = path.join(vscodeDirPath, 'settings.json'); const { CREATE_LOGGER, raiseInfo } = require('./log_utils'); @@ -70,37 +70,47 @@ async function findInstancesInWorkspace(word, currentFilePath, maxFilesToShow) { } -async function saveConfigFile(settingToSave = "all") { +function saveConfigFile(settingToSave = "all") { let config = vscode.workspace.getConfiguration('bg3ModHelper'); - let settings = {}; + let allSettings = { + maxFilesToShow: config.get('hover.maxFiles'), + hoverEnabled: config.get('hover.enabled'), + maxCacheSize: config.get('maxCacheSize'), + rootModPath: config.get('rootModPath'), + modDestPath: config.get('modDestPath'), + lslibPath: config.get('lslibPath'), + autoLaunchOnPack: config.get('autoLaunchOnPack'), + launchContinueGame: config.get('launchContinueGame'), + addHandlesToAllLocas: config.get('addHandlesToAllLocas'), + excludedFiles: config.get('excludedFiles') || [], + gameInstallLocation: config.get('gameInstallLocation') + }; + + try { + console.log(fs.statSync(vscodeDirPath).isFile()); + } catch (error) { + setConfig(allSettings); + console.log(`settings set to ${allSettings}`) + } - console.log(`${settingsFilePath}\n${rootModPath}`) + if (!fs.statSync(vscodeDirPath).isFile()) { + fs.mkdirSync(vscodeDirPath, { recursive: true }); + } if (settingToSave === "all") { - settings = { - maxFilesToShow: config.get('hover.maxFiles'), - hoverEnabled: config.get('hover.enabled'), - maxCacheSize: config.get('maxCacheSize'), - rootModPath: config.get('rootModPath'), - modDestPath: config.get('modDestPath'), - lslibPath: config.get('lslibPath'), - autoLaunchOnPack: config.get('autoLaunchOnPack'), - launchContinueGame: config.get('launchContinueGame'), - addHandlesToAllLocas: config.get('addHandlesToAllLocas'), - excludedFiles: config.get('excludedFiles') || [], - gameInstallLocation: config.get('gameInstallLocation') - }; + setConfig(allSettings); + } else { // it's gonna do something else eventually + setConfig(allSettings); } - setConfig(settings); let settingsJson = JSON.stringify(config, null, 4); fs.writeFileSync(settingsFilePath, settingsJson, 'utf8'); - raiseInfo('Initial configs set:' + JSON.stringify(config, null, 4), false); + raiseInfo('Initial configs set:\n' + JSON.stringify(config, null, 4), false); } -async function loadConfigFile(get = false) { +function loadConfigFile(get = false) { let settingsContent; if (fs.statSync(settingsFilePath).isFile()) { diff --git a/support_files/log_utils.js b/support_files/log_utils.js index 7bcb8b51..c1ff4cab 100644 --- a/support_files/log_utils.js +++ b/support_files/log_utils.js @@ -3,7 +3,7 @@ const path = require('path'); var lslibPath; var logPath; -const { isMainThread } = require('worker_threads'); +const { isMainThread, workerData } = require('worker_threads'); // TODO: clear logs function @@ -87,7 +87,7 @@ if (isMainThread) { bg3mh_logger.info(info); } } else { - lslibPath = require('./config').getConfig().lslibPath; + lslibPath = workerData.lslibPath; logPath = path.normalize(lslibPath + "\\logs\\bg3mh_log_" + LOGDATE() + ".log"); CREATE_LOGGER = () => { @@ -144,6 +144,4 @@ if (isMainThread) { } - - module.exports = { LOGDATE, logPath, CREATE_LOGGER, raiseError, raiseInfo }; \ No newline at end of file diff --git a/support_files/lslib_utils.js b/support_files/lslib_utils.js index 9142c95f..b3e2e90d 100644 --- a/support_files/lslib_utils.js +++ b/support_files/lslib_utils.js @@ -5,9 +5,6 @@ */ const path = require('path'); const fs = require('fs'); -const vscode = require('vscode'); -const findFiles = vscode.workspace.findFiles; -const parse = vscode.Uri.parse; // loads the api @@ -23,11 +20,6 @@ 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(); -const compatRootModPath = path.join(getConfig().rootModPath + "\\"); -const lslibToolsPath = path.join(getConfig().lslibPath, TOOL_SUBDIR); - // separated for future use const elasticDlls = ['Elastic.Transport.dll', 'Elastic.Clients.Elasticsearch.dll']; const storyCompilerDlls = ['StoryCompiler.dll', 'StoryDecompiler.dll']; @@ -40,9 +32,28 @@ const convertDirs = ["[PAK]_UI", "[PAK]_Armor", "RootTemplates", "MultiEffectInf // excluding this because it will match to "UI" in convertDirs const illegalFiles = ["Icons_Items.lsx"]; +// tools to test where the process is +const { isMainThread, workerData } = require('node:worker_threads'); + var DLLS = []; -var DLL_PATHS; -var LSLIB; +var DLL_PATHS, LSLIB, lslibPath, compatRootModPath, lslibToolsPath, vscode, findFiles, parse; +var getConfig; + + +if (isMainThread) { + getConfig = require('./config.js').getConfig; + lslibPath = getConfig().lslibPath; + compatRootModPath = path.join(getConfig().rootModPath + "\\"); + lslibToolsPath = path.join(getConfig().lslibPath, TOOL_SUBDIR); + vscode = require('vscode'); + findFiles = vscode.workspace.findFiles; + parse = vscode.Uri.parse; +} else { + getConfig = workerData; + lslibPath = getConfig.lslibPath; + compatRootModPath = path.join(getConfig.rootModPath + "\\"); + lslibToolsPath = path.join(getConfig.lslibPath, TOOL_SUBDIR); +} function getFormats() { @@ -106,21 +117,36 @@ async function loadDlls() { // 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); - } - 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; + if (isMainThread) { + 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(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 + "."); + return null; + } } processDllPaths(); await loadDlls(); - raiseInfo(`${DLL_PATHS} \n.dlls loaded`, false); + bg3mh_logger.info(`${DLL_PATHS} \n.dlls loaded`); + console.log(`${DLL_PATHS} \n.dlls loaded`); // have to ignore this because the ts-linter doesn't know 'LSLib' exists :starege: // @ts-ignore @@ -131,7 +157,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); @@ -161,12 +187,12 @@ async function FIND_FILES(targetExt = getFormats().lsf, filesPath = '**/*') { if (targetExt === getFormats().dll) { let dllDir = new vscode.RelativePattern(filesPath, '*' + targetExt); - console.log(dllDir); + // 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); + // console.log(dllDir); filesList = (await findFiles(dllDir)).map(file => dirSeparator(file.path)); } else { @@ -184,7 +210,13 @@ async function FIND_FILES(targetExt = getFormats().lsf, filesPath = '**/*') { function FILTER_PATHS(filesPath) { - let excludedFiles = getConfig().excludedFiles; + let excludedFiles = []; + if (isMainThread) { + excludedFiles = getConfig().excludedFiles; + } else { + excludedFiles = getConfig.excludedFiles; + } + if (Array.isArray(filesPath)) { let filteredPaths = []; @@ -222,6 +254,8 @@ 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) { + let infoMsg = `${path.basename(sourcePath)} moved to ${destPath}.`; + fs.readFile(sourcePath, (readErr, data) => { if (readErr) { raiseError(readErr); @@ -241,9 +275,14 @@ function moveFileAcrossDevices(sourcePath, destPath, raiseError) { }); }); }); - raiseInfo(path.basename(sourcePath) + " moved to " + destPath, false); - vscode.window.showInformationMessage(`${path.basename(sourcePath)} moved to ${destPath}.`); + + if (isMainThread) { + raiseInfo(infoMsg, false); + vscode.window.showInformationMessage(infoMsg); + } else { + raiseInfo(infoMsg); + } } -module.exports = { LSLIB, LOAD_LSLIB, FIND_FILES, FIND_FILES_v1, FILTER_PATHS, getFormats, moveFileAcrossDevices, baseNamePath, dirSeparator, compatRootModPath }; \ No newline at end of file +module.exports = { LSLIB, LOAD_LSLIB, FIND_FILES, FIND_FILES_SYNC, FILTER_PATHS, getFormats, moveFileAcrossDevices, baseNamePath, dirSeparator, compatRootModPath }; \ No newline at end of file