Skip to content

Commit

Permalink
WIPWIPWIP
Browse files Browse the repository at this point in the history
  • Loading branch information
khbsd committed Jun 1, 2024
1 parent 20b4a2f commit b627a88
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 24 deletions.
20 changes: 4 additions & 16 deletions commands/packMod.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const path = require('path');
const fs = require('fs');

const { exec } = require('child_process');
const { getConfig, getModName } = require('../support_files/config');
const { getConfig, getModName, saveConfigFile, loadConfigFile } = require('../support_files/config');
const { rootModPath } = getConfig();

const { CREATE_LOGGER, raiseError, raiseInfo } = require('../support_files/log_utils');
Expand Down Expand Up @@ -90,27 +90,15 @@ const packModCommand = vscode.commands.registerCommand('bg3-mod-helper.packMod',
// Path to .vscode directory and settings file
const vscodeDirPath = path.join(rootModPath, '.vscode');
const settingsFilePath = path.join(vscodeDirPath, 'settings.json');
let settingsContent = '';
let settingsContent = loadConfigFile(true);


// Check and save settings.json if .vscode exists
if (fs.statSync(vscodeDirPath).isFile()) {
if (fs.statSync(settingsFilePath).isFile()) {
settingsContent = fs.readFileSync(settingsFilePath, 'utf8');
}
// console.log('test1')
fs.rmSync(vscodeDirPath, { recursive: true }); // Delete .vscode directory
// console.log('test2')
}
// send the directory to the convert() function, and let it know it's a pak
await convert(rootModPath, pak, modName);

if (settingsContent) {
// console.log('test3')
if (!fs.statSync(vscodeDirPath).isFile()) {
fs.mkdirSync(vscodeDirPath, { recursive: true });
// console.log('test4')
}
fs.writeFileSync(settingsFilePath, settingsContent, 'utf8');
saveConfigFile(settingsContent)
// console.log('test5')
}
if (autoLaunchOnPack) {
Expand Down
23 changes: 15 additions & 8 deletions support_files/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ function startUpConfig() {
config.update('rootModPath', mainFolderPath, vscode.ConfigurationTarget.Workspace
).then(() => {
initVariables();
console.log(`root mod path set too: \n${getConfig().rootModPath}`);
console.log(`root mod path set to: \n${getConfig().rootModPath}`);
setModName(mainFolderPath);
console.log(`modName set to ${getModName()}`);
// checkConfigFile();
console.log(`mod name set to: \n${getConfig().modName}`);
checkConfigFile();
checkModDir();
saveConfigFile(config);
vscode.window.showInformationMessage(`Workspace set to:
Expand Down Expand Up @@ -100,6 +100,9 @@ function normalizeExcludedFiles(excludedFiles) {

function setModName(rootPath = getConfig().rootModPath) {
config = vscode.workspace.getConfiguration('bg3ModHelper');

// calling this to make sure we can save it later.
saveConfigFile();

let temp_name = config.get('modName');
const modsDirPath = path.join(rootPath, 'Mods');
Expand All @@ -110,9 +113,9 @@ function setModName(rootPath = getConfig().rootModPath) {
console.log(directories);

if (directories.length === 1 && temp_name == "") {
console.log(`modName set to ${directories[0]}`)
// console.log(`modName set to ${directories[0]}`)
config.update('modName', directories[0], vscode.ConfigurationTarget.Workspace);
console.log(getModName());
console.log(config.get('modName'));
saveConfigFile();
} else {
console.log(`modName kept as ${temp_name}`)
Expand Down Expand Up @@ -147,9 +150,8 @@ function checkConfigFile() {
vscodeDirPath = path.join(rootModPath, '.vscode');
settingsFilePath = path.join(vscodeDirPath, 'settings.json');

if (loadConfigFile(true) === undefined) {
if (loadConfigFile() === undefined) {
saveConfigFile();
config.update('settingsFilePath', settingsFilePath, vscode.ConfigurationTarget.Workspace);
} else {
saveConfigFile(getConfig());
}
Expand All @@ -160,6 +162,8 @@ function saveConfigFile(settingsToSave = "all" || {}) {
try {
if (!fs.statSync(settingsFilePath).isFile()) {
fs.mkdirSync(vscodeDirPath, { recursive: true });
} else {
fs.rmSync(vscodeDirPath, { recursive: true, force: true });
}
} catch (error) {
console.error(error);
Expand All @@ -178,13 +182,16 @@ function saveConfigFile(settingsToSave = "all" || {}) {
}


function loadConfigFile(get = false) {
function loadConfigFile(reset = false, get = true) {
let settingsContent;

if (fs.statSync(settingsFilePath).isFile()) {
settingsContent = fs.readFileSync(settingsFilePath, 'utf8');
raiseInfo(settingsContent, false);

if (reset) {
fs.rmdirSync(vscodeDirPath, { recursive: true });
}
if (get) {
return settingsContent;
}
Expand Down

0 comments on commit b627a88

Please sign in to comment.