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'
});
if (prompt == 'Continue') {
deleteTemplate(template);
deleteTemplate(version, template);
}
}
</script>

View File

@ -11,7 +11,7 @@ import europa from '$lib/assets/fonts/Europa-Mono-Medium.otf';
import { BASE_LIBRARY_DIR } from './settings';
import figlet from 'figlet';
import shadow from 'figlet/fonts/Classy';
import { getInstalledVersions } from './library';
import { getInstalledVersions, getTemplatesDir } from './library';
figlet.parseFont('Big', shadow);
/**
@ -120,14 +120,23 @@ export async function createBanner(text) {
});
}
export async function addTemplateFile(version, templateFilePath) {
const newFileName = await pathBasename(templateFilePath);
const templatesPath = await join(version.path, 'templates', newFileName);
await copyFile(templateFilePath, templatesPath);
export async function addTemplateFile(version, filePath) {
const newFileName = await pathBasename(filePath);
const templateName = newFileName.replace(/\.blend$/i, '');
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();
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.
* @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 {
await removeTemplate(templatePath);
await getInstalledVersions();
@ -328,7 +330,7 @@ export async function getInstalledVersions() {
const currentPlatform = platform();
// Get templates for this version
var templates = await getTemplates(version);
let newVersion = {
version,
@ -336,8 +338,12 @@ export async function getInstalledVersions() {
executable,
platform: currentPlatform,
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
await generateVersionIcon(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
*/
export async function getTemplates(version) {
try {
const settings = get(currentSettings);
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'
);
const templatesDir = await getTemplatesDir(version)
await ensureDirectory(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
* @returns {Promise<string>}
*/
export async function getTemplateDir(version, template) {
export async function getTemplate(version, template) {
try {
const settings = get(currentSettings);
const libraryDir = settings.libraryDir;
const blenderConfigPath = await join(libraryDir, BASE_LIBRARY_DIR, 'config', version);
// Launch the executable
const templatesDir = await join(
blenderConfigPath,
version.split('.').slice(0, 2).join('.'),
'scripts',
'startup',
'bl_app_templates_system',
const templatesDir = await join(await getTemplatesDir(version),
template
);
return templatesDir;
@ -531,7 +543,7 @@ export async function launchBlenderVersion(version, template = null) {
// Launch the executable
let bannerPath;
if (template) {
const templateDir = await getTemplateDir(version.version, template);
const templateDir = await getTemplate(version, template);
bannerPath = await join(templateDir, 'banner.png');
} else {
bannerPath = await join(version.path, 'banner.png');