v1
This commit is contained in:
52
src/main/PathResolver.js
Normal file
52
src/main/PathResolver.js
Normal file
@@ -0,0 +1,52 @@
|
||||
const path = require("path");
|
||||
const fs = require("fs");
|
||||
|
||||
const STR_EXE_NAME = process.platform === "win32" ? "blender.exe" : "blender";
|
||||
|
||||
const PathResolver = {
|
||||
_str_blender_path: null,
|
||||
|
||||
get_blender_path: () => {
|
||||
if (PathResolver._str_blender_path) {
|
||||
return PathResolver._str_blender_path;
|
||||
}
|
||||
|
||||
// Mode package : resources/blender/
|
||||
let str_resources_dir = path.join(process.resourcesPath, "blender");
|
||||
let str_found = PathResolver._find_in_dir(str_resources_dir);
|
||||
if (str_found) {
|
||||
PathResolver._str_blender_path = str_found;
|
||||
return str_found;
|
||||
}
|
||||
|
||||
// Mode dev : racine projet/blender/
|
||||
let str_dev_dir = path.join(__dirname, "..", "..", "blender");
|
||||
str_found = PathResolver._find_in_dir(str_dev_dir);
|
||||
if (str_found) {
|
||||
PathResolver._str_blender_path = str_found;
|
||||
return str_found;
|
||||
}
|
||||
|
||||
// Fallback : PATH systeme
|
||||
PathResolver._str_blender_path = "blender";
|
||||
return "blender";
|
||||
},
|
||||
|
||||
_find_in_dir: (str_dir) => {
|
||||
if (!fs.existsSync(str_dir)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
let list_entries = fs.readdirSync(str_dir);
|
||||
for (let str_entry of list_entries) {
|
||||
let str_exe = path.join(str_dir, str_entry, STR_EXE_NAME);
|
||||
if (fs.existsSync(str_exe)) {
|
||||
return str_exe;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = PathResolver;
|
||||
Reference in New Issue
Block a user