mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-18 14:31:39 +00:00
Fix "Restart Blender" button for Microsoft Store Blender #5582
This commit is contained in:
@@ -923,7 +923,14 @@ class RestartBlender(bpy.types.Operator):
|
|||||||
bl_options = {"REGISTER", "UNDO"}
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
import os
|
ms_store_app_id = tool.Blender.get_microsoft_store_app_id()
|
||||||
|
if not ms_store_app_id:
|
||||||
path = bpy.app.binary_path
|
path = bpy.app.binary_path
|
||||||
os.execv(path, sys.argv)
|
os.execv(path, sys.argv)
|
||||||
|
else:
|
||||||
|
# Microsoft apps do not allow launching blender.exe directly
|
||||||
|
# since Blender folder is kind of private.
|
||||||
|
cmd_exe = Path(os.environ["SystemRoot"]) / "system32" / "cmd.exe"
|
||||||
|
blender_app = f"shell:AppsFolder\\BlenderFoundation.Blender_{ms_store_app_id}!BLENDER"
|
||||||
|
cmd_args = ["/c", "start", blender_app] + sys.argv[1:]
|
||||||
|
os.execv(cmd_exe, cmd_args)
|
||||||
|
|||||||
@@ -1272,3 +1272,17 @@ class Blender(bonsai.core.tool.Blender):
|
|||||||
|
|
||||||
obj, path = path_resolve(bpy_object, prop_path)
|
obj, path = path_resolve(bpy_object, prop_path)
|
||||||
setattr(obj, path, value)
|
setattr(obj, path, value)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_microsoft_store_app_id(cls) -> Union[str, None]:
|
||||||
|
"""Get Microsoft Store app ID for current Blender instance.
|
||||||
|
|
||||||
|
:return: `None` if Blender is installed not from Microsoft Store (possibly using non-Windows platform).
|
||||||
|
Otherwise return app ID string (e.g. 'ppwjx1n5r4v9t').
|
||||||
|
"""
|
||||||
|
if os.name != "nt":
|
||||||
|
return None
|
||||||
|
blender_binary_path = Path(bpy.app.binary_path)
|
||||||
|
if len(blender_binary_path.parents) > 3 and blender_binary_path.parents[2].name == "WindowsApps":
|
||||||
|
return blender_binary_path.parents[1].name.rsplit("__", 1)[-1]
|
||||||
|
return None
|
||||||
|
|||||||
Reference in New Issue
Block a user