mirror of
https://github.com/upscayl/upscayl.git
synced 2024-11-23 23:21:05 +01:00
95843ded88
* Initial refactor * Remove unused imports * Update code * Refactor and Update Code - Change file names to kebab-caase - Add new useTranslation Hook - Change useLog hook name to useLogger - Update translation hook to provide autocomplete * Update import and component name * Rename files and components * Update locales * Update electron commands * Update var * Change Lowercase * Replace filter with map * Add props * Update flag check * Add validate paths * Update formats * Update import * Update function * Update function and translation * Update handlePaste
76 lines
2.2 KiB
TypeScript
76 lines
2.2 KiB
TypeScript
import fs from "fs";
|
|
import logit from "./logit";
|
|
import { MessageBoxOptions, app, dialog } from "electron";
|
|
import settings from "electron-settings";
|
|
import { FEATURE_FLAGS } from "../../common/feature-flags";
|
|
|
|
const getModels = async (folderPath: string | undefined) => {
|
|
let models: string[] = [];
|
|
let isValid = false;
|
|
|
|
// SECURITY SCOPED BOOKMARKS
|
|
let closeAccess;
|
|
const customModelsBookmarks = await settings.get("custom-models-bookmarks");
|
|
if (FEATURE_FLAGS.APP_STORE_BUILD && customModelsBookmarks) {
|
|
console.log(
|
|
"🚀 => file: get-models.ts:18 => customModelsBookmarks:",
|
|
customModelsBookmarks,
|
|
);
|
|
try {
|
|
closeAccess = app.startAccessingSecurityScopedResource(
|
|
customModelsBookmarks as string,
|
|
);
|
|
} catch (error) {
|
|
logit("📁 Custom Models Bookmarks Error: ", error);
|
|
}
|
|
}
|
|
|
|
if (!folderPath) {
|
|
logit("❌ Invalid Custom Model Folder Detected");
|
|
const options: MessageBoxOptions = {
|
|
type: "error",
|
|
title: "Invalid Folder",
|
|
message:
|
|
"The selected folder does not contain valid model files. Make sure you select the folder that ONLY contains '.param' and '.bin' files.",
|
|
buttons: ["OK"],
|
|
};
|
|
dialog.showMessageBoxSync(options);
|
|
return null;
|
|
}
|
|
|
|
// READ CUSTOM MODELS FOLDER
|
|
fs.readdirSync(folderPath).forEach((file) => {
|
|
// log.log("Files in Folder: ", file);
|
|
if (
|
|
file.endsWith(".param") ||
|
|
file.endsWith(".PARAM") ||
|
|
file.endsWith(".bin") ||
|
|
file.endsWith(".BIN")
|
|
) {
|
|
isValid = true;
|
|
const modelName = file.substring(0, file.lastIndexOf(".")) || file;
|
|
if (!models.includes(modelName)) {
|
|
models.push(modelName);
|
|
}
|
|
}
|
|
});
|
|
|
|
if (!isValid) {
|
|
logit("❌ Invalid Custom Model Folder Detected");
|
|
const options: MessageBoxOptions = {
|
|
type: "error",
|
|
title: "Invalid Folder",
|
|
message:
|
|
"The selected folder does not contain valid model files. Make sure you select the folder that ONLY contains '.param' and '.bin' files.",
|
|
buttons: ["OK"],
|
|
};
|
|
dialog.showMessageBoxSync(options);
|
|
return null;
|
|
}
|
|
|
|
logit("🔎 Detected Custom Models: ", models);
|
|
return models;
|
|
};
|
|
|
|
export default getModels;
|