Template Upload
Template Launch
Template Deletion
This commit is contained in:
valerio 2026-07-25 16:56:25 +02:00
parent 29bf3dfa66
commit 1cecec5a97
3 changed files with 63 additions and 42 deletions

View File

@ -28,7 +28,7 @@
type: 'warning' type: 'warning'
}); });
if (prompt == 'Continue') { if (prompt == 'Continue') {
deleteTemplate(template); deleteTemplate(version, template);
} }
} }
</script> </script>

View File

@ -11,7 +11,7 @@ import europa from '$lib/assets/fonts/Europa-Mono-Medium.otf';
import { BASE_LIBRARY_DIR } from './settings'; import { BASE_LIBRARY_DIR } from './settings';
import figlet from 'figlet'; import figlet from 'figlet';
import shadow from 'figlet/fonts/Classy'; import shadow from 'figlet/fonts/Classy';
import { getInstalledVersions } from './library'; import { getInstalledVersions, getTemplatesDir } from './library';
figlet.parseFont('Big', shadow); figlet.parseFont('Big', shadow);
/** /**
@ -120,14 +120,23 @@ export async function createBanner(text) {
}); });
} }
export async function addTemplateFile(version, templateFilePath) { export async function addTemplateFile(version, filePath) {
const newFileName = await pathBasename(templateFilePath); const newFileName = await pathBasename(filePath);
const templatesPath = await join(version.path, 'templates', newFileName); const templateName = newFileName.replace(/\.blend$/i, '');
await copyFile(templateFilePath, templatesPath); const newTemplatePath = await join(await getTemplatesDir(version), templateName);
await ensureDirectory(newTemplatePath)
const newTemplateFile = await join(newTemplatePath, 'startup.blend');
try {
await copyFile(filePath, newTemplateFile);
} catch (error) {
console.error('Error adding template file:', error);
return;
}
await getInstalledVersions(); await getInstalledVersions();
console.log('adding ', templateFilePath, ' to ', version.path); console.log('adding ', filePath, ' to ', newTemplateFile);
} }
/** /**

View File

@ -247,9 +247,11 @@ export async function toggleFavourite(version) {
/** /**
* Remove a template from the library. * Remove a template from the library.
* @param {string} templatePath The path of the template to remove. * @param {blenderVersion} version The version to remove the template from.
* @param {string} template The name of the template to remove.
*/ */
export async function deleteTemplate(templatePath) { export async function deleteTemplate(version, template) {
const templatePath = await join(await getTemplatesDir(version), template);
try { try {
await removeTemplate(templatePath); await removeTemplate(templatePath);
await getInstalledVersions(); await getInstalledVersions();
@ -328,7 +330,7 @@ export async function getInstalledVersions() {
const currentPlatform = platform(); const currentPlatform = platform();
// Get templates for this version // Get templates for this version
var templates = await getTemplates(version);
let newVersion = { let newVersion = {
version, version,
@ -336,9 +338,13 @@ export async function getInstalledVersions() {
executable, executable,
platform: currentPlatform, platform: currentPlatform,
favourite: favourites[version] || false, favourite: favourites[version] || false,
templates: templates || [] templates: []
}; };
var templates = await getTemplates(newVersion);
newVersion.templates = templates;
//check if version has an icon, if not generate one //check if version has an icon, if not generate one
await generateVersionIcon(newVersion); await generateVersionIcon(newVersion);
await generateVersionBanner(newVersion); await generateVersionBanner(newVersion);
@ -383,29 +389,16 @@ export async function getInstalledVersions() {
} }
} }
/** /**
* *
* @param {string} version * @param {blenderVersion} version
* @returns {Promise<string[]>} List of .blend files paths in the templates directory * @returns {Promise<string[]>} List of .blend files paths in the templates directory
*/ */
export async function getTemplates(version) { export async function getTemplates(version) {
try { try {
const settings = get(currentSettings); const templatesDir = await getTemplatesDir(version)
const libraryDir = settings.libraryDir;
if (!libraryDir) {
console.error('No library directory set');
return [];
}
const blenderConfigPath = await join(libraryDir, BASE_LIBRARY_DIR, 'blender', version);
const templatesDir = await join(
blenderConfigPath,
version.split('.').slice(0, 2).join('.'),
'scripts',
'startup',
'bl_app_templates_system'
);
await ensureDirectory(templatesDir); await ensureDirectory(templatesDir);
const entries = await readDir(templatesDir); const entries = await readDir(templatesDir);
@ -464,25 +457,44 @@ export async function registerVersion(version) {
} }
} }
/**
* Returns the templates directory for a given Blender version
* @param {blenderVersion} version
* @returns {Promise<string>}
*/
export async function getTemplatesDir(version) {
const versionNumber = version?.version;
try {
const templatesDir = await join(
version.path,
versionNumber.split('.').slice(0, 2).join('.'),
'scripts',
'startup',
'bl_app_templates_system'
);
await ensureDirectory(templatesDir);
console.log(templatesDir)
return templatesDir;
} catch (error) {
console.error(error);
return null;
}
}
/** /**
* *
* @param {string} version * @param {blenderVersion} version
* @param {string} template * @param {string} template
* @returns {Promise<string>} * @returns {Promise<string>}
*/ */
export async function getTemplateDir(version, template) { export async function getTemplate(version, template) {
try { try {
const settings = get(currentSettings);
const libraryDir = settings.libraryDir;
const blenderConfigPath = await join(libraryDir, BASE_LIBRARY_DIR, 'config', version);
// Launch the executable // Launch the executable
const templatesDir = await join( const templatesDir = await join(await getTemplatesDir(version),
blenderConfigPath,
version.split('.').slice(0, 2).join('.'),
'scripts',
'startup',
'bl_app_templates_system',
template template
); );
return templatesDir; return templatesDir;
@ -531,7 +543,7 @@ export async function launchBlenderVersion(version, template = null) {
// Launch the executable // Launch the executable
let bannerPath; let bannerPath;
if (template) { if (template) {
const templateDir = await getTemplateDir(version.version, template); const templateDir = await getTemplate(version, template);
bannerPath = await join(templateDir, 'banner.png'); bannerPath = await join(templateDir, 'banner.png');
} else { } else {
bannerPath = await join(version.path, 'banner.png'); bannerPath = await join(version.path, 'banner.png');