|
1 | 1 | import platform
|
2 | 2 | import os
|
3 | 3 |
|
4 |
| -bl_info = { |
5 |
| - "name": "Plumber", |
6 |
| - "author": "Lassi Säike", |
7 |
| - "version": (1, 1, 1), |
8 |
| - "blender": (2, 90, 0), |
9 |
| - "location": "File > Import -> Plumber", |
10 |
| - "description": "Imports Source Engine assets.", |
11 |
| - "warning": "", |
12 |
| - "tracker_url": "https://github.com/lasa01/plumber", |
13 |
| - "category": "Import-Export", |
14 |
| -} |
15 |
| - |
16 |
| -version = bl_info["version"] |
17 |
| -version_pre = bl_info["warning"] |
18 |
| - |
19 |
| -version_str = ".".join(map(str, version)) |
20 |
| - |
21 |
| -if version_pre != "": |
22 |
| - version_str += f"-{version_pre}" |
23 |
| - |
24 |
| -# check if imported by setup.py or actually running in Blender |
25 |
| -try: |
26 |
| - from bpy.app import version as bpy_version |
27 |
| -except ImportError: |
28 |
| - bpy_version = None |
29 |
| - |
30 |
| -if bpy_version is not None: |
31 |
| - is_windows = platform.system() == "Windows" |
32 |
| - |
33 |
| - def register(): |
34 |
| - if is_windows: |
35 |
| - # Check if the extension module was renamed on the last unregister, |
36 |
| - # and either rename it back or delete it if the addon was updated with a newer extension module |
37 |
| - ext_path = os.path.join(os.path.dirname(__file__), "plumber.pyd") |
38 |
| - unloaded_ext_path = os.path.join( |
39 |
| - os.path.dirname(os.path.dirname(__file__)), "plumber.pyd.unloaded" |
40 |
| - ) |
41 |
| - |
42 |
| - if os.path.isfile(unloaded_ext_path): |
43 |
| - if os.path.isfile(ext_path): |
44 |
| - try: |
45 |
| - os.remove(unloaded_ext_path) |
46 |
| - except OSError: |
47 |
| - print( |
48 |
| - "[Plumber] [WARN] old files remaining, restart Blender to finish post-update clean up" |
49 |
| - ) |
50 |
| - else: |
51 |
| - os.rename(unloaded_ext_path, ext_path) |
52 |
| - |
53 |
| - from . import addon |
54 |
| - |
55 |
| - addon.register() |
56 |
| - |
57 |
| - def unregister(): |
58 |
| - from . import addon |
59 |
| - |
60 |
| - addon.unregister() |
61 |
| - |
62 |
| - if is_windows: |
63 |
| - # Rename the extension module to allow updating the addon without restarting Blender, |
64 |
| - # since the extension module will stay open and can't be overwritten even if the addon is unloaded |
65 |
| - ext_path = os.path.join(os.path.dirname(__file__), "plumber.pyd") |
66 |
| - unloaded_ext_path = os.path.join( |
67 |
| - os.path.dirname(os.path.dirname(__file__)), "plumber.pyd.unloaded" |
68 |
| - ) |
69 |
| - |
70 |
| - try: |
71 |
| - os.rename(ext_path, unloaded_ext_path) |
72 |
| - except OSError: |
73 |
| - pass |
| 4 | +is_windows = platform.system() == "Windows" |
| 5 | + |
| 6 | + |
| 7 | +def register(): |
| 8 | + if is_windows: |
| 9 | + # Check if the extension module was renamed on the last unregister, |
| 10 | + # and either rename it back or delete it if the addon was updated with a newer extension module |
| 11 | + ext_path = os.path.join(os.path.dirname(__file__), "plumber.pyd") |
| 12 | + unloaded_ext_path = os.path.join( |
| 13 | + os.path.dirname(os.path.dirname(__file__)), "plumber.pyd.unloaded" |
| 14 | + ) |
| 15 | + |
| 16 | + if os.path.isfile(unloaded_ext_path): |
| 17 | + if os.path.isfile(ext_path): |
| 18 | + try: |
| 19 | + os.remove(unloaded_ext_path) |
| 20 | + except OSError: |
| 21 | + print( |
| 22 | + "[Plumber] [WARN] old files remaining, restart Blender to finish post-update clean up" |
| 23 | + ) |
| 24 | + else: |
| 25 | + os.rename(unloaded_ext_path, ext_path) |
| 26 | + |
| 27 | + from . import addon |
| 28 | + |
| 29 | + addon.register() |
| 30 | + |
| 31 | + |
| 32 | +def unregister(): |
| 33 | + from . import addon |
| 34 | + |
| 35 | + addon.unregister() |
| 36 | + |
| 37 | + if is_windows: |
| 38 | + # Rename the extension module to allow updating the addon without restarting Blender, |
| 39 | + # since the extension module will stay open and can't be overwritten even if the addon is unloaded |
| 40 | + ext_path = os.path.join(os.path.dirname(__file__), "plumber.pyd") |
| 41 | + unloaded_ext_path = os.path.join( |
| 42 | + os.path.dirname(os.path.dirname(__file__)), "plumber.pyd.unloaded" |
| 43 | + ) |
| 44 | + |
| 45 | + try: |
| 46 | + os.rename(ext_path, unloaded_ext_path) |
| 47 | + except OSError: |
| 48 | + pass |
0 commit comments