Update Install.py

This commit is contained in:
Jeffreytsai1004 2025-02-07 12:47:36 +08:00
parent bca7b92fcb
commit 643ba521d8

View File

@ -245,29 +245,51 @@ class InstallDialog(QtWidgets.QDialog):
print("Uninstallation cancelled")
def create_mod_file(self):
"""Create or update the .mod file for Maya"""
"""创建或更新Maya的.mod文件"""
modules_dir = get_maya_modules_dir()
mod_content = f"""+ {TOOL_NAME} {TOOL_VERSION} {TOOL_PATH}
scripts: {SCRIPTS_PATH}
plug-ins: plugins/{SYSTEM_OS}/{MAYA_VERSION}
XBMLANGPATH+:=resources/icons
PYTHONPATH+:=plugins/{SYSTEM_OS}/{MAYA_VERSION}
PYTHONPATH+:=plugins/{SYSTEM_OS}/{MAYA_VERSION}/pydna/{PYTHON_VERSION_DIR}
TOOL_PATH+:={TOOL_PATH}
"""
mod_file_path = os.path.join(modules_dir, TOOL_MOD_FILENAME)
self._write_mod_file(mod_file_path, mod_content)
def _write_mod_file(self, file_path, content):
"""Helper method to write .mod file"""
# 获取所有Maya版本和对应的Python版本
version_map = {
"2022": "python3",
"2023": "python397",
"2024": "python3108",
"2025": "python311"
}
# 系统映射
os_paths = {
"win64": "Windows",
"linux": "Linux"
}
# 创建mod文件内容
mod_content = f"""+ {TOOL_NAME} {TOOL_VERSION} {TOOL_PATH}
"""
# 添加每个Maya版本的配置
for maya_version, python_version in version_map.items():
# 添加每个操作系统的配置
for os_name, os_path in os_paths.items():
mod_content += f"""
if MAYA_VERSION == {maya_version} && PLATFORM == {os_name}
scripts: {SCRIPTS_PATH}
plug-ins: {os.path.join(PLUGIN_PATH, os_path)}
XBMLANGPATH+:={ICONS_PATH}
PATH+:={os.path.join(PLUGIN_PATH, os_path)}
PATH+:={os.path.join(PLUGIN_PATH, os_path, "pydna", python_version)}
PYTHONPATH+:={SCRIPTS_PATH}
PYTHONPATH+:={os.path.join(PLUGIN_PATH, os_path, "pydna", python_version)}
endif
"""
# 写入mod文件
mod_file_path = os.path.join(modules_dir, TOOL_MOD_FILENAME)
try:
with open(file_path, "w") as f:
f.write(content)
print(f"Successfully created/updated: {file_path}")
with open(mod_file_path, "w", encoding="utf-8") as f:
f.write(mod_content)
print(f"Created mod file: {mod_file_path}")
except Exception as e:
error_msg = f"Error writing .mod file: {e}"
print(error_msg)
QtWidgets.QMessageBox.critical(self, "Error", error_msg)
print(f"Error creating mod file {mod_file_path}: {e}")
def uninstall_mod_file(self):
modules_dir = get_maya_modules_dir()