84 lines
4.0 KiB
PowerShell
84 lines
4.0 KiB
PowerShell
# Design Express Res 部署脚本: 复制 DLL + 注册每用户 COM + 生成 .addin (无需管理员权限)
|
|
# 架构: DesignExpress.Core.dll(独立核心) + DesignExpress.InventorLink.dll(Inventor 适配)
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
$invVer = "2022"
|
|
$addinDir = Join-Path $env:APPDATA "Autodesk\Inventor $invVer\Addins"
|
|
$clsid = "{D422E0BF-02D0-4DAE-958A-7BBA80B718E9}"
|
|
$progId = "DesignExpress.InventorLink.AddInServer"
|
|
$asmName = "DesignExpress.InventorLink, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"
|
|
|
|
$srcCore = Join-Path $PSScriptRoot "DesignExpress.Core.dll"
|
|
$srcLink = Join-Path $PSScriptRoot "DesignExpress.InventorLink.dll"
|
|
if (-not (Test-Path $srcCore)) { Write-Host "未找到 DesignExpress.Core.dll"; exit 1 }
|
|
if (-not (Test-Path $srcLink)) { Write-Host "未找到 DesignExpress.InventorLink.dll"; exit 1 }
|
|
|
|
New-Item -ItemType Directory -Force -Path $addinDir | Out-Null
|
|
Copy-Item -LiteralPath $srcCore -Destination (Join-Path $addinDir "DesignExpress.Core.dll") -Force
|
|
$dstLink = Join-Path $addinDir "DesignExpress.InventorLink.dll"
|
|
Copy-Item -LiteralPath $srcLink -Destination $dstLink -Force
|
|
Write-Host "DLL 已复制: $addinDir"
|
|
|
|
# 每用户 COM 注册 (HKCU\Software\Classes)
|
|
$clsBase = "HKCU:\Software\Classes\CLSID\$clsid"
|
|
Remove-Item -Path $clsBase -Recurse -Force -ErrorAction SilentlyContinue
|
|
New-Item -Path $clsBase -Force | Out-Null
|
|
Set-ItemProperty -Path $clsBase -Name "(default)" -Value $progId
|
|
New-Item -Path "$clsBase\InprocServer32" -Force | Out-Null
|
|
Set-ItemProperty -Path "$clsBase\InprocServer32" -Name "(default)" -Value "mscoree.dll"
|
|
Set-ItemProperty -Path "$clsBase\InprocServer32" -Name "Class" -Value $progId
|
|
Set-ItemProperty -Path "$clsBase\InprocServer32" -Name "Assembly" -Value $asmName
|
|
$codebase = "file:///" + ($dstLink.Replace('\', '/'))
|
|
Set-ItemProperty -Path "$clsBase\InprocServer32" -Name "CodeBase" -Value $codebase
|
|
Set-ItemProperty -Path "$clsBase\InprocServer32" -Name "ThreadingModel" -Value "Both"
|
|
|
|
$progBase = "HKCU:\Software\Classes\$progId"
|
|
Remove-Item -Path $progBase -Recurse -Force -ErrorAction SilentlyContinue
|
|
New-Item -Path "$progBase\CLSID" -Force | Out-Null
|
|
Set-ItemProperty -Path "$progBase\CLSID" -Name "(default)" -Value $clsid
|
|
Write-Host "COM 注册完成 (HKCU)"
|
|
|
|
# 生成 .addin
|
|
$addinXml = @"
|
|
<Addin Type="Standard">
|
|
<ClassId>$clsid</ClassId>
|
|
<ClientId>$clsid</ClientId>
|
|
<DisplayName>Design Express Res</DisplayName>
|
|
<Description>设计标注检查与设计数据查询工具(Core+Link 架构)</Description>
|
|
<Assembly>$dstLink</Assembly>
|
|
<LoadOnStartUp>1</LoadOnStartUp>
|
|
<UserUnloadable>1</UserUnloadable>
|
|
<Hidden>0</Hidden>
|
|
<SupportedSoftwareVersionGreaterThan>25..</SupportedSoftwareVersionGreaterThan>
|
|
<DataVersion>1</DataVersion>
|
|
<UserInterfaceVersion>1</UserInterfaceVersion>
|
|
</Addin>
|
|
"@
|
|
$addinFile = Join-Path $addinDir "DesignExpress.InventorLink.addin"
|
|
[System.IO.File]::WriteAllText($addinFile, $addinXml, [System.Text.Encoding]::UTF8)
|
|
Write-Host ".addin 已生成: $addinFile"
|
|
|
|
# 清理旧版本文件
|
|
Remove-Item (Join-Path $addinDir "InventorDesignCheck.dll") -Force -ErrorAction SilentlyContinue
|
|
Remove-Item (Join-Path $addinDir "InventorDesignCheck.addin") -Force -ErrorAction SilentlyContinue
|
|
|
|
# 关键: 修复 AddInLoadRules(加载规则文件), 确保本加载项允许加载
|
|
# 该文件为 UTF-16 二进制, 每条记录: "{GUID}" + DWORD(0=允许, 1=禁止)
|
|
$rulesFile = Join-Path $addinDir "AddInLoadRules"
|
|
if (Test-Path $rulesFile) {
|
|
$b = [System.IO.File]::ReadAllBytes($rulesFile)
|
|
$u = [System.Text.Encoding]::Unicode.GetString($b)
|
|
$guid = "{D422E0BF-02D0-4DAE-958A-7BBA80B718E9}"
|
|
$pos = $u.IndexOf($guid)
|
|
if ($pos -ge 0) {
|
|
$bytePos = $pos * 2 + $guid.Length * 2
|
|
if ([BitConverter]::ToUInt32($b, $bytePos) -ne 0) {
|
|
$b[$bytePos] = 0; $b[$bytePos + 1] = 0; $b[$bytePos + 2] = 0; $b[$bytePos + 3] = 0
|
|
[System.IO.File]::WriteAllBytes($rulesFile, $b)
|
|
Write-Host "已修复加载规则(允许加载)"
|
|
}
|
|
}
|
|
}
|
|
|
|
Write-Host "部署完成! 请重启 Inventor, 功能区将出现 [Design Express Res] 选项卡。"
|