From 4d84861b6256c8194a57088172614185469f487d Mon Sep 17 00:00:00 2001 From: Lino Schmidt Date: Wed, 15 Jun 2022 00:55:18 +0200 Subject: [PATCH] Added download script for blender --- .gitignore | 9 +++-- {assets => dependencies}/blenderScript.py | 0 {assets => dependencies}/template.blend | Bin package.json | 19 +++++----- scripts/download-blender.py | 44 ++++++++++++++++++++++ src/components/paths.ts | 15 ++++++-- 6 files changed, 71 insertions(+), 16 deletions(-) rename {assets => dependencies}/blenderScript.py (100%) rename {assets => dependencies}/template.blend (100%) create mode 100644 scripts/download-blender.py diff --git a/.gitignore b/.gitignore index 139f4f7..f41997e 100644 --- a/.gitignore +++ b/.gitignore @@ -263,8 +263,9 @@ out/ output/ -blender-win/ -blender-linux/ -blender/ +dependencies/windows/ +dependencies/darwin/ +dependencies/linux/ -index.build.js \ No newline at end of file +index.build.js +index.build.js.LICENSE.txt \ No newline at end of file diff --git a/assets/blenderScript.py b/dependencies/blenderScript.py similarity index 100% rename from assets/blenderScript.py rename to dependencies/blenderScript.py diff --git a/assets/template.blend b/dependencies/template.blend similarity index 100% rename from assets/template.blend rename to dependencies/template.blend diff --git a/package.json b/package.json index f016011..5a01526 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,11 @@ { - "version": "0.6.2", + "version": "0.8.1", "name": "stickexportertx", "productName": "StickExporterTX", "description": "3D stick exporter for EdgeTX/OpenTX logs", "main": "src/index.build.js", "scripts": { + "install:deps": "python ./scripts/download-blender.py", "build:main": "cross-env NODE_ENV=production webpack --config configs/webpack.main.prod.config.babel.js", "build:renderer": "cross-env NODE_ENV=production webpack --config configs/webpack.renderer.prod.config.babel.js", "build": "cross-env npm run build:main && cross-env npm run build:renderer", @@ -29,8 +30,8 @@ "package.json" ], "extraFiles": [ - "assets/template.blend", - "assets/blenderScript.py" + "dependencies/template.blend", + "dependencies/blenderScript.py" ], "win": { "icon": "icon.png", @@ -39,8 +40,8 @@ ], "extraFiles": [ { - "from": "assets/blender/", - "to": "assets/blender/", + "from": "dependencies/windows/", + "to": "dependencies/windows/", "filter": [ "**/*" ] @@ -62,8 +63,8 @@ ], "extraFiles": [ { - "from": "assets/blender/", - "to": "assets/blender/", + "from": "dependencies/linux/", + "to": "dependencies/linux/", "filter": [ "**/*" ] @@ -78,8 +79,8 @@ ], "extraFiles": [ { - "from": "assets/blender/", - "to": "assets/blender/", + "from": "dependencies/darwin/", + "to": "dependencies/darwin/", "filter": [ "**/*" ] diff --git a/scripts/download-blender.py b/scripts/download-blender.py new file mode 100644 index 0000000..3432f25 --- /dev/null +++ b/scripts/download-blender.py @@ -0,0 +1,44 @@ +from io import BytesIO +import urllib.request +from zipfile import ZipFile +import tarfile +import os +import shutil +import time + +windowsURL = 'https://ftp.halifax.rwth-aachen.de/blender/release/Blender3.2/blender-3.2.0-windows-x64.zip' +linuxURL = 'https://ftp.halifax.rwth-aachen.de/blender/release/Blender3.2/blender-3.2.0-linux-x64.tar.xz' + +# Windows +if(os.path.exists('./dependencies/windows')): + print("Removing old windows folder") + shutil.rmtree('./dependencies/windows') + +print("Downloading windows version") +with urllib.request.urlopen(windowsURL) as zipresp: + with ZipFile(BytesIO(zipresp.read())) as zfile: + zfile.extractall('./dependencies/windows') + +print("Adjust windows version") +oldWindowsName = windowsURL.split('/')[-1].replace('.zip', '') +os.rename('./dependencies/windows/' + oldWindowsName, './dependencies/windows/blender') + +# Linux +if(os.path.exists('./dependencies/linux')): + print("Removing old linux folder") + shutil.rmtree('./dependencies/linux') + +print("Downloading linux version") +os.mkdir('./dependencies/linux') + +urllib.request.urlretrieve(linuxURL, './dependencies/linux/blender.tar.xz') +print("Extracting linux version") +with tarfile.open('./dependencies/linux/blender.tar.xz') as tfile: + tfile.extractall('./dependencies/linux') + +print("Adjust linux version") +oldLinuxName = linuxURL.split('/')[-1].replace('.tar.xz', '') +os.rename('./dependencies/linux/' + oldLinuxName, './dependencies/linux/blender') + +print("Clean up linux folder") +os.remove('./dependencies/linux/blender.tar.xz') \ No newline at end of file diff --git a/src/components/paths.ts b/src/components/paths.ts index 183b148..d3dc90d 100644 --- a/src/components/paths.ts +++ b/src/components/paths.ts @@ -6,6 +6,15 @@ export const SettingPath = path.join(dataPath, "settings.xml"); export const defaultOutputPath = path.join(app.getPath('videos'), "StickExporterTX"); -export const blenderPath = path.join("assets", "blender", "blender"); -export const templatePath = path.join("assets", "template.blend"); -export const blenderScriptPath = path.join("assets", "blenderScript.py"); \ No newline at end of file +let platformFolder = ""; +if(process.platform === "win32"){ + platformFolder = "windows"; +} else if(process.platform === "darwin"){ + platformFolder = "darwin"; +} else if(process.platform === "linux"){ + platformFolder = "linux"; +} + +export const blenderPath = path.join("dependencies", platformFolder, "blender", "blender"); +export const templatePath = path.join("dependencies", "template.blend"); +export const blenderScriptPath = path.join("dependencies", "blenderScript.py"); \ No newline at end of file