From 7499f5a86c4553b2de53ffeee28dc173f4bdd05c Mon Sep 17 00:00:00 2001 From: ghostboats <106226990+ghostboats@users.noreply.github.com> Date: Tue, 16 Jul 2024 02:52:34 -0500 Subject: [PATCH] see read me (hover show path removed and some otehr stuff idk) --- commands/folderShortcuts.js | 14 +++++++- commands/indentXmlFiles.js | 64 ++++++++++++++++++++++++++++++++++ extension.js | 11 ++++-- package.json | 5 --- support_files/config.js | 1 - support_files/release_notes.js | 24 +++++++------ 6 files changed, 99 insertions(+), 20 deletions(-) create mode 100644 commands/indentXmlFiles.js diff --git a/commands/folderShortcuts.js b/commands/folderShortcuts.js index 928ee2ff..3b6ae1ee 100644 --- a/commands/folderShortcuts.js +++ b/commands/folderShortcuts.js @@ -49,4 +49,16 @@ const openWorkspaceFolderCommand = vscode.commands.registerCommand('bg3-mod-help } }); -module.exports = { openModsFolderCommand, openGameFolderCommand, openLogsFolderCommand, openWorkspaceFolderCommand }; \ No newline at end of file +const openPlayerProfilesFolderCommand = vscode.commands.registerCommand('bg3-mod-helper.openPlayerProfilesFolder', async () => { + const appDataPath = process.env.LOCALAPPDATA; + const playerProfilesPath = path.join(appDataPath, 'Larian Studios', "Baldur's Gate 3", 'PlayerProfiles'); + + try { + await fs.access(playerProfilesPath); + vscode.env.openExternal(vscode.Uri.file(playerProfilesPath)); + } catch (error) { + vscode.window.showInformationMessage('PlayerProfiles folder not found.'); + } +}); + +module.exports = { openModsFolderCommand, openGameFolderCommand, openLogsFolderCommand, openWorkspaceFolderCommand, openPlayerProfilesFolderCommand }; \ No newline at end of file diff --git a/commands/indentXmlFiles.js b/commands/indentXmlFiles.js new file mode 100644 index 00000000..740cd4ec --- /dev/null +++ b/commands/indentXmlFiles.js @@ -0,0 +1,64 @@ +const vscode = require('vscode'); +const fs = require('fs'); +const path = require('path'); +const os = require('os'); +const { raiseError, raiseInfo } = require('../support_files/log_utils'); +const { getConfig, loadConfigFile, setModName, setConfig } = require('../support_files/config'); +const builder = require('xmlbuilder'); + +async function indentXmlFiles() { + const config = getConfig(); + const rootModPath = config.rootModPath; + const indentLevel = await vscode.window.showInputBox({ + prompt: 'Enter the number of spaces for indentation', + validateInput: (value) => { + const num = parseInt(value, 10); + return isNaN(num) || num < 0 ? 'Please enter a valid non-negative number' : null; + } + }); + + if (!indentLevel) { + return; // User cancelled the input box + } + + const findFiles = (dir, extensions, fileList = []) => { + fs.readdirSync(dir).forEach(file => { + const filePath = path.join(dir, file); + if (fs.statSync(filePath).isDirectory()) { + // Skip the Localization folder + if (path.basename(filePath).toLowerCase() !== 'localization') { + fileList = findFiles(filePath, extensions, fileList); + } + } else if (extensions.some(ext => filePath.endsWith(ext))) { + fileList.push(filePath); + } + }); + return fileList; + }; + + const files = findFiles(rootModPath, ['.lsx', '.lsj']); + + for (const filePath of files) { + let fileContent = fs.readFileSync(filePath, 'utf-8'); + // Remove BOM if it exists + if (fileContent.charCodeAt(0) === 0xFEFF) { + fileContent = fileContent.slice(1); + } + try { + const doc = builder.create(fileContent, { headless: true }); + const formattedContent = doc.end({ pretty: true, indent: ' '.repeat(parseInt(indentLevel, 10)) }); + fs.writeFileSync(filePath, formattedContent, 'utf-8'); + raiseInfo(`File ${filePath} has been formatted with an indent level of ${indentLevel} spaces.`); + } catch (error) { + raiseError(`Failed to process file ${filePath}: ${error.message}`); + } + } + + raiseInfo('XML files formatting process completed.'); +} + +const indentXmlFilesCommand = vscode.commands.registerCommand('bg3-mod-helper.indentXmlFilesCommand', async function () { + await indentXmlFiles(); +}); + +module.exports = { indentXmlFilesCommand }; diff --git a/extension.js b/extension.js index b4dfe29e..939289b6 100644 --- a/extension.js +++ b/extension.js @@ -34,9 +34,11 @@ let packModImport, openGameFolderCommand, openLogsFolderCommand, openWorkspaceFolderCommand, + openPlayerProfilesFolderCommand, organizeDataFilesCommand, xmlMergerCommand, symlinkerCommand, + indentXmlFilesCommand, debugCommand, debug2Command, unpackGameDataCommand, @@ -85,6 +87,7 @@ function setCommands() { openGameFolderCommand = require('./commands/folderShortcuts').openGameFolderCommand; openLogsFolderCommand = require('./commands/folderShortcuts').openLogsFolderCommand; openWorkspaceFolderCommand = require('./commands/folderShortcuts').openWorkspaceFolderCommand; + openPlayerProfilesFolderCommand = require('./commands/folderShortcuts').openPlayerProfilesFolderCommand; // image commands resizeImageTooltip = require('./commands/resizeImage').resizeImageTooltip; @@ -104,6 +107,7 @@ function setCommands() { xmlMergerCommand = require('./commands/xmlMerger'); organizeDataFilesCommand = require('./commands/organizeDataFiles'); symlinkerCommand = require('./commands/symlinker'); + indentXmlFilesCommand = require('./commands/indentXmlFiles'); // debug commands debugCommand = require('./commands/debug'); @@ -194,7 +198,7 @@ function activate(context) { let createModTemplateCommand = vscode.commands.registerCommand('bg3-mod-helper.createModTemplate', createModTemplateImport); context.subscriptions.push(vscode.commands.registerCommand('bg3-mod-helper.addToExcludeList', addToExcludeList)); context.subscriptions.push(vscode.commands.registerCommand('bg3-mod-helper.removeFromExcludeList', removeFromExcludeList)); - context.subscriptions.push(uuidsHandlesHoverProvider, functionsHoverProvider, DDSToPNGCommand, PNGToDDSCommand, resizeTooltipCommand, resizeControllerCommand, resizeHotbarCommand, resizeCustomCommand, createModTemplateCommand, addIconBackgroundCommand, openConverterCommand, versionGeneratorCommand, rotationToolCommand, openModsFolderCommand, openGameFolderCommand, openLogsFolderCommand, openWorkspaceFolderCommand); + context.subscriptions.push(uuidsHandlesHoverProvider, functionsHoverProvider, DDSToPNGCommand, PNGToDDSCommand, resizeTooltipCommand, resizeControllerCommand, resizeHotbarCommand, resizeCustomCommand, createModTemplateCommand, addIconBackgroundCommand, openConverterCommand, versionGeneratorCommand, rotationToolCommand, openModsFolderCommand, openGameFolderCommand, openLogsFolderCommand, openWorkspaceFolderCommand, openPlayerProfilesFolderCommand); } @@ -224,7 +228,6 @@ function aSimpleDataProvider() { { label: 'BBCode/Markdown Editor ', command: 'bg3-mod-helper.textEditorTool'}, { label: 'Version Generator', command: 'bg3-mod-helper.versionGenerator' }, { label: 'Merge Xmls', command: 'bg3-mod-helper.xmlMerger' }, - { label: 'Add Dependencies to Meta via modsettings.lsx', command: 'bg3-mod-helper.addDependencies'}, { label: 'Add/Remove Symlink (in development)', command: 'bg3-mod-helper.symlinker' }, { label: 'Rotation Tool (in development)', command: 'bg3-mod-helper.rotationTool' }, { label: 'DDS Viewer (in development)', command: 'bg3-mod-helper.DDSViewer' }, @@ -243,7 +246,8 @@ function aSimpleDataProvider() { ]); } else if (element.id === 'formatting') { return Promise.resolve([ - { label: 'Organize Data Files (Alphabetically)', command: 'bg3-mod-helper.organizeDataFilesCommand' } + { label: 'Organize Data Files (Alphabetically)', command: 'bg3-mod-helper.organizeDataFilesCommand' }, + { label: 'Mass Indent LSX Files', command: 'bg3-mod-helper.indentXmlFilesCommand'} ]); } else if (element.id === 'config') { return Promise.resolve([ @@ -264,6 +268,7 @@ function aSimpleDataProvider() { { label: 'Workspace Folder', command: 'bg3-mod-helper.openWorkspaceFolder' }, { label: 'Extension Logs Folder', command: 'bg3-mod-helper.openLogsFolder' }, { label: 'Game Data Folder', command: 'bg3-mod-helper.openGameFolder' }, + { label: 'Player Profiles Folder', command: 'bg3-mod-helper.openPlayerProfilesFolder' }, ]); } else { return Promise.resolve([]); diff --git a/package.json b/package.json index a66aa02a..cb3606e8 100644 --- a/package.json +++ b/package.json @@ -244,11 +244,6 @@ "default": true, "description": "Enable or disable hover feature." }, - "bg3ModHelper.hoverShowPath": { - "type": "boolean", - "default": true, - "description": "Toggle file path in hover message (not working in current update)." - }, "bg3ModHelper.rootModPath": { "type": "string", "default": "", diff --git a/support_files/config.js b/support_files/config.js index ae5b81aa..f6c2e552 100644 --- a/support_files/config.js +++ b/support_files/config.js @@ -91,7 +91,6 @@ function getConfig() { return { hoverMaxFiles: config.get('hoverMaxFiles'), hoverEnabled: config.get('hoverEnabled'), - hoverShowPath: config.get('hoverShowPath'), maxCacheSize: config.get('maxCacheSize'), rootModPath: path.normalize(config.get('rootModPath')), modDestPath: path.normalize(config.get('modDestPath')), diff --git a/support_files/release_notes.js b/support_files/release_notes.js index 3c39b41f..c51e9705 100644 --- a/support_files/release_notes.js +++ b/support_files/release_notes.js @@ -66,19 +66,21 @@ function generateReleaseNotes(version) { { title: "Mod Setting Changes [IMPORTANT]", details: [ - "Modname changes complete, add details here", - "Configuration Options Data Provider complete, add details here", - "New setting to add files to be excluded when packing (maybe this mixes with stuff below regarding exclude hidden(todo))", + "Modname Setting Added. This value should be autoset on launch as long as you only have one folder in your rootmodpath's Mods folder. If you have multiple it will need to be set!", + "Configuration Options Data Provider complete, see below", "Conversion exclusion list UI changes to show difference between this and packing exclusion list (todo)", - "Exclude Hidden (not sure if working yet so putting as (todo), need to talk to beans)", - "Auto Launch Game and Zip options removed as settings. This is now handled via the dropdown data provider, the 'Pack and Play' and 'Pack and Zip' options respectivly." + "Exclude Hidden (implemented but requires new lslib which is unreleased atm) setting added, possible remove as setting and make it always check files for .(todo)", + "Auto Launch Game and Zip options removed as settings. This is now handled via the dropdown data provider, the 'Pack and Play' and 'Pack and Zip' options respectivly.", + "Remove hover enabled setting to remvoe dead setting" ] }, { - title: ".helperignore used [IMPORTANT]", + title: "Configuration Options Data Provider", details: [ - "Similar to other . files like .gitignore or .vscode, you can now use a .helperignore (should be in same dir as rootmodfolder (Public, Localizations, etc)(todo)", - "Will ask if you want one generated for you for the first time on a new release on launch (todo)" + "Contains several quick actions revolving around modSetting which are accessed from the data provider:", + "Reload Window: Will refresh the current vscode window, allowing for new settings to take effect (For example, if you change things like lslib path, you should reload)", + "Extension Setting: Opens the settings page, filtering the bg3 mod helper settings for quick access", + "Update Settings: (todo, overwrites workspace, need to confirm with beans this is the desired effect)" ] }, { @@ -90,7 +92,7 @@ function generateReleaseNotes(version) { }, { title: "Symlink Fixes", - details: ["Symlink will no longer create 'random' folders when linking/unlinking (seems to be working, will leave in development tag for now while users test. No errors when personally testing, maybe its a linux only issue?)"] + details: ["Symlink will no longer create 'random' folders when linking/unlinking (seems to be working, will leave in development tag for now while users test. No errors when personally testing, please send paths/screenshots/info/etc if you have any issues)"] }, { title: "Zipping Fixes", @@ -109,7 +111,9 @@ function generateReleaseNotes(version) { title: "Minor Changes", details: [ "Extension confirmed to work on Linux (ty satan!)", - "Check if game is lauched for linus in packing(todo)" + "Check if game is lauched for linus in packing(todo)", + "Shortcut to PlayerProfiles Folder added in folder shortcuts", + "Atlas Fix if .lsx file doenst exist yet (todo)" ] } ]