Files
ShrlAlgoToolkit/Sai.RvKits Setup/Program.cs
2024-09-22 11:05:41 +08:00

199 lines
7.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using WixSharp;
using WixSharp.CommonTasks;
using WixToolset.Dtf.WindowsInstaller;
namespace Sai.RvKits_Setup
{
public class Program
{
static void Main()
{
var baseFeature = new Feature("必要组件", "加载插件的必须组件") { Display = FeatureDisplay.hidden };
var revit2018 = new Feature("Revit2018", "Revit2018的功能描述", true);
//var revit2019 = new Feature("Revit2019", "Revit2019的功能描述") { IsEnabled = false };
var revit2020 = new Feature("Revit2020", "Revit2020的功能描述", true);
//var pluginsFolder = @"%CommonAppDataFolder%\Autodesk\ApplicationPlugins\Sai.RvKits.bundle";
var pluginsFolder =
$@"{Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData)}\Autodesk\ApplicationPlugins\{Settings.AddInAppName}.bundle";
//var project = new ManagedProject("建模工具集",
// new Dir(@"%ProgramFiles%\Sai\Sai.RvKits",
// new File("Program.cs"), new Files(@"..\Sai.RvKit\bin\Debug\*.*")));
var project = new ManagedProject(
"建模工具集",
new WixEntity[]
{
//new Dir(@"%ProgramFiles%\Sai.RvKit"),
new Dir(baseFeature, pluginsFolder, new File($@"..\bin\{Settings.AddInAppName}.bundle\PackageContents.xml")),
new Dir(
new Id("R18"),
$@"{pluginsFolder}\Contents\2018",
new WixEntity[]
{
new Files(revit2018, @"..\bin\Debug\2018\*.*") /*, new File(revit2018, @"..\bin\Debug\2018\Sai.RvKits.addin")*/
}
),
//new Dir($"{pluginsFolder}\\Contents\\2019", new WixEntity[] { new Files(revit2019, @"..\bin\Debug\2019\*.*"), new File(revit2019, @"..\bin\Sai.RvKits.addin") }),
new Dir(
new Id("R20"),
$@"{pluginsFolder}\Contents\2020",
new WixEntity[]
{
new Files(revit2020, @"..\bin\Debug\2020\*.*") /*, new File(revit2020, @"..\bin\Debug\2020\Sai.RvKits.addin")*/
}
)
}
)
{
UI = WUI.WixUI_Minimal,
//GUID = new Guid("6fe30b47-2577-43ad-9095-1861ba25889b"),
GUID = new Guid("0EB16058-1682-4620-BD5A-BD777BFD4934"),
Language = "zh-cn",
Version = new Version(1, 0, 0, 0),
LocalizationFile = "WixUI_zh-CN.wxl",
//Feature = baseFeature,
DefaultFeature = revit2018,
// all stock UI dialogs
//ManagedUI = ManagedUI.DefaultWpf,
//MSI包名称
//project.OutFileName = "软件名称" + $"{DateTime.Now.Year}{DateTime.Now.Month:00}{DateTime.Now.Day:00}{DateTime.Now.Hour:00}{DateTime.Now.Minute:00}";
//custom set of UI WPF dialogs
ManagedUI = new ManagedUI(),
ValidateBackgroundImage = false, //关闭背景图片大小验证
BackgroundImage = @"Images\dlgbmp.png", //建议宽度156高度312
BannerImage = @"Images\bannerbmp.png",
//安装新版本时自动卸载旧版本
UpgradeCode = new Guid("511EED44-E344-4821-BF25-B42175CE41AC"),
MajorUpgrade = new MajorUpgrade
{
AllowSameVersionUpgrades = true,
DowngradeErrorMessage = "当前安装的版本低于已安装的版,无法再次安装。",
AllowDowngrades = false,
Schedule = UpgradeSchedule.afterInstallValidate
}
};
project.OutFileName = $"建模工具集{project.Version}";
project.Package.AttributesDefinition = "Platform=x64";
project.ManagedUI.Icon = @"Images\Revit2021x.ico"; //标题栏图标
//设置控制面板制造商名称
project.ControlPanelInfo.Manufacturer = "Sai";
//设置控制面板图标
project.ControlPanelInfo.ProductIcon = @"Images\Revit2021x.ico";
//project.SourceBaseDir = "<input dir path>";
//project.OutDir = "<output dir path>";
project.SetNetFxPrerequisite(WixSharp.Condition.Net48_Installed, "请先安装.netFrameworks4.8");
project.ManagedUI.InstallDialogs
.Add<Sai.RvKits_Setup.WelcomeDialog>()
.Add<Sai.RvKits_Setup.LicenceDialog>()
.Add<Sai.RvKits_Setup.FeaturesDialog>()
.Add<Sai.RvKits_Setup.InstallDirDialog>()
.Add<Sai.RvKits_Setup.ProgressDialog>()
.Add<Sai.RvKits_Setup.ExitDialog>();
project.ManagedUI.ModifyDialogs
.Add<Sai.RvKits_Setup.MaintenanceTypeDialog>()
.Add<Sai.RvKits_Setup.FeaturesDialog>()
.Add<Sai.RvKits_Setup.ProgressDialog>()
.Add<Sai.RvKits_Setup.ExitDialog>();
//project.AddAction()
project.Load += Project_Load;
project.BeforeInstall += Project_BeforeInstall;
project.AfterInstall += Project_AfterInstall;
project.BuildMsi();
}
private static void Project_AfterInstall(SetupEventArgs e)
{
if (!e.IsUISupressed && !e.IsUninstalling)
MessageBox.Show(e.ToString(), "AfterExecute");
}
private static void Project_BeforeInstall(SetupEventArgs e)
{
if (!e.IsUISupressed && !e.IsUninstalling)
MessageBox.Show(e.ToString(), "BeforeInstall");
}
private static void Project_Load(SetupEventArgs e)
{
if (!e.IsUISupressed && !e.IsUninstalling)
MessageBox.Show(e.ToString(), "Load");
}
[CustomAction]
public static ActionResult Installer(Session session)
{
session.Log("Begin Installer");
//MessageBox.Show("rundll32.exe");
var manufacturer = session["Manufacturer"];
var productName = session["ProductName"];
var appDir = session["APPDIR"]; //安装路径,根据用户选择
var sourceDir = session["SourceDir"]; //安装包解压路径
var programFiles64Folder = session["ProgramFiles64Folder"]; //64位安装路径C:\ProgramFiles
var commonAppDataFolder = session["CommonAppDataFolder"]; //C:\ProgramData
var addInFilePath = $"{commonAppDataFolder}\\Autodesk\\{Settings.AddInFileName}.bundle\\Contents";
//List<RevitProduct> revitProductsInstalled = RevitProductUtility.GetAllInstalledRevitProducts();
//foreach (var product in revitProductsInstalled)
//{
//}
var fileInfos = new List<System.IO.FileInfo>();
var dir = System.IO.Directory.CreateDirectory(appDir);
//var sb = new StringBuilder();
foreach (var fileInfo in dir.GetFiles("*", System.IO.SearchOption.AllDirectories))
{
//var match = Regex.Match(filePath.Name, @"Sai\.RvKit\.dll$");
//if (!match.Success)
//{
// match = Regex.Match(filePath.Name, @"(\d\d\d\d)\.exe$");
// if (!match.Success)
// continue;
//}
//if (match.Success)
//{
// dlls.Add(filePath.FullName);
//}
if (fileInfo.Name == Settings.DllFileName)
{
fileInfos.Add(fileInfo);
}
}
foreach (var dllPath in fileInfos)
{
var versionNum = dllPath.Directory?.Name;
var manager = new AddInManager(versionNum, Settings.AddInFileName);
foreach (var fullName in Settings.RibbonFullClassNames)
{
manager.CreateApplication(Settings.AddInAppName, dllPath.FullName, fullName);
}
manager.Uninstall();
manager.Install();
}
return ActionResult.Success;
}
[CustomAction]
public static ActionResult Uninstaller(Session session)
{
session.Log("Begin Uninstaller");
var commonAppDataFolder = session["CommonAppDataFolder"];
var addInFilePath = $"{commonAppDataFolder}\\Autodesk\\{Settings.AddInAppName}.bundle";
System.IO.Directory.Delete(addInFilePath, true);
return ActionResult.Success;
}
}
}