添加项目文件。

This commit is contained in:
GG Z
2024-09-22 11:05:41 +08:00
parent fb5d55723a
commit 49ceaae6a8
764 changed files with 78850 additions and 0 deletions

View File

@@ -0,0 +1,71 @@
#region
using System;
using System.IO;
using Autodesk.RevitAddIns;
#endregion
namespace Sai.AddInDeployer
{
public class AddInManager
{
private RevitAddInManifest Manifest { get; }
private string ManifestPath { get; }
internal AddInManager(string revitVersion, string addInName)
{
Manifest = new RevitAddInManifest();
ManifestPath = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData),
$@"Autodesk\ApplicationPlugins\{Contraints.BundleFolderName}\Contents",
revitVersion,
addInName
);
//ManifestPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Autodesk\\Revit\\Addins", revitVersion, addInName);
}
internal void CreateApplication(string name, string assemblyPath, string fullClassName)
{
RevitAddInApplication item = new RevitAddInApplication(name, assemblyPath, Guid.NewGuid(), fullClassName, Contraints.VendorId)
{
VendorDescription = Contraints.VendorDescription
};
Manifest.AddInApplications.Add(item);
}
internal void CreateCommand(string assemblyPath, string fullClassName)
{
RevitAddInCommand item = new RevitAddInCommand(assemblyPath, Guid.NewGuid(), fullClassName, Contraints.VendorId)
{
VendorDescription = Contraints.VendorDescription
};
Manifest.AddInCommands.Add(item);
}
internal void Install()
{
DirectoryInfo directory = new FileInfo(ManifestPath).Directory;
if (directory == null)
{
return;
}
if (!directory.Exists)
{
Directory.CreateDirectory(directory.FullName);
}
Manifest.SaveAs(ManifestPath);
}
internal void Uninstall()
{
if (File.Exists(ManifestPath))
{
File.Delete(ManifestPath);
}
}
}
}

View File

@@ -0,0 +1,16 @@
using System.Collections.Generic;
namespace Sai.AddInDeployer
{
public static class Contraints
{
public static string DllFileName { get; set; } = "Sai.RvKits.dll";
public static string AddInFileName { get; set; } = "Sai.RvKits.addin";
public static string VendorDescription { get; set; } = "Zhanggg";
public static string VendorId { get; set; } = "ADSK";
public static string BundleFolderName { get; set; } = "Sai.RvKits.bundle";
public static List<string> RibbonFullClassNames = new List<string>() { "Sai.RvKits.UIApp.RvApp", };
public static string AddInAppName { get; set; } = "Sai.RvKits";
}
}

View File

@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<!--
Use supportedRuntime tags to explicitly specify the version(s) of the .NET Framework runtime that
the custom action should run on. If no versions are specified, the chosen version of the runtime
will be the "best" match to what Microsoft.Deployment.WindowsInstaller.dll was built against.
WARNING: leaving the version unspecified is dangerous as it introduces a risk of compatibility
problems with future versions of the .NET Framework runtime. It is highly recommended that you specify
only the version(s) of the .NET Framework runtime that you have tested against.
Note for .NET Framework v3.0 and v3.5, the runtime version is still v2.0.
In order to enable .NET Framework version 2.0 runtime activation policy, which is to load all assemblies
by using the latest supported runtime, @useLegacyV2RuntimeActivationPolicy="true".
For more information, see http://msdn.microsoft.com/en-us/library/bbx34a2h.aspx
-->
<supportedRuntime version="v4.0" />
<supportedRuntime version="v2.0.50727" />
</startup>
<!--
Add additional configuration settings here. For more information on application config files,
see http://msdn.microsoft.com/en-us/library/kza1yk3a.aspx
-->
</configuration>

View File

@@ -0,0 +1,74 @@
using System.Collections.Generic;
using System.IO;
using System.Text;
using Microsoft.Deployment.WindowsInstaller;
namespace Sai.AddInDeployer
{
public class CustomActions
{
[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\\{Contraints.BundleFolderName}\\Contents";
//List<RevitProduct> revitProductsInstalled = RevitProductUtility.GetAllInstalledRevitProducts();
//foreach (var product in revitProductsInstalled)
//{
//}
var fileInfos = new List<FileInfo>();
var dir = Directory.CreateDirectory(appDir);
var sb = new StringBuilder();
foreach (var fileInfo in dir.GetFiles("*", 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 == Contraints.DllFileName)
{
fileInfos.Add(fileInfo);
}
}
foreach (var dllPath in fileInfos)
{
var versionNum = dllPath.Directory?.Name;
var manager = new AddInManager(versionNum, Contraints.AddInFileName);
foreach (var fullName in Contraints.RibbonFullClassNames)
{
manager.CreateApplication(Contraints.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\\{Contraints.BundleFolderName}";
Directory.Delete(addInFilePath, true);
return ActionResult.Success;
}
}
}

View File

@@ -0,0 +1,34 @@
using System.Reflection;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Sai.AddinDeployer")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyCompany("Administrator")]
[assembly: AssemblyProduct("Sai.AddinDeployer")]
[assembly: AssemblyCopyright("Copyright © Administrator 2022")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("1e6f7706-97b3-4929-8ff9-79df5485801b")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@@ -0,0 +1,41 @@
<Project InitialTargets="EnsureWixToolsetInstalled" Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<OutputType>Library</OutputType>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<UseWindowsForms>true</UseWindowsForms>
<ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets>
<AppendPlatformToOutputPath>False</AppendPlatformToOutputPath>
<AppendTargetFrameworkToOutputPath>False</AppendTargetFrameworkToOutputPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<OutputPath>bin\x64\Debug\</OutputPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\x64\Release\</OutputPath>
</PropertyGroup>
<ItemGroup>
<Reference Include="RevitAddInUtility">
<HintPath>C:\Program Files\Autodesk\Revit 2020\RevitAddInUtility.dll</HintPath>
</Reference>
<Reference Include="System.Configuration" />
<Reference Include="Microsoft.Deployment.WindowsInstaller">
<Private>True</Private>
</Reference>
<Reference Include="System.Xml.Serialization" />
</ItemGroup>
<ItemGroup>
<Content Include="CustomAction.config" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="System.Management" Version="8.0.0" />
</ItemGroup>
<Target Name="EnsureWixToolsetInstalled" Condition=" '$(WixCATargetsImported)' != 'true' ">
<Error Text="The WiX Toolset v3.11 (or newer) build tools must be installed to build this project. To download the WiX Toolset, see http://wixtoolset.org/releases/" />
</Target>
</Project>