Skip to content

Commit

Permalink
fix #41
Browse files Browse the repository at this point in the history
  • Loading branch information
chuongmep committed Nov 8, 2022
1 parent 31d1857 commit 8ec4a77
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Changelog
- 2022-11-8 **1.3.9**
- Fix problem with some user install msi with PC company have policy [#41](https://github.com/chuongmep/RevitAddInManager/issues/41).
- 2022-10-16 **1.3.8**
- Support save keep last window size change.
- 2022-09-11 **1.3.7**
Expand Down
50 changes: 47 additions & 3 deletions Installer/Installer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using ICSharpCode.SharpZipLib.Zip;
using WixSharp;
using WixSharp.CommonTasks;
using WixSharp.Controls;
using File = System.IO.File;

const string installationDir = @"%AppDataFolder%\Autodesk\Revit\Addins\";
const string projectName = "RevitAddinManager";
const string outputName = "RevitAddinManager";
const string outputDir = "output";
const string version = "1.3.8";
const string version = "1.3.9";

var fileName = new StringBuilder().Append(outputName).Append("-").Append(version);
var project = new Project
Expand Down Expand Up @@ -44,8 +47,10 @@

MajorUpgrade.Default.AllowSameVersionUpgrades = true;
project.RemoveDialogsBetween(NativeDialogs.WelcomeDlg, NativeDialogs.InstallDirDlg);
project.BuildMsi();

string buildMsi = project.BuildMsi();
FileInfo fileInfo = new FileInfo(buildMsi);
string zipfileName = Path.Combine(fileInfo.Directory.FullName, fileName + ".zip");
CompressFile(buildMsi, zipfileName);
WixEntity[] GenerateWixEntities()
{
var versionRegex = new Regex(@"\d+");
Expand All @@ -67,4 +72,43 @@ WixEntity[] GenerateWixEntities()
}

return versionStorages.Select(storage => new Dir(storage.Key, storage.Value.ToArray())).Cast<WixEntity>().ToArray();
}


void CompressFile(string filePath, string OutputFilePath, int compressLevel = 9)
{
try
{
using (ZipOutputStream OutputStream = new ZipOutputStream(File.Create(OutputFilePath)))
{
// Define the compression level
// 0 - store only to 9 - means best compression
OutputStream.SetLevel(compressLevel);
byte[] buffer = new byte[4096];
ZipEntry entry = new ZipEntry(Path.GetFileName(filePath));
entry.DateTime = DateTime.Now;
OutputStream.PutNextEntry(entry);

using (FileStream fs = File.OpenRead(filePath))
{
// Using a fixed size buffer here makes no noticeable difference for output
// but keeps a lid on memory usage.
int sourceBytes;
do
{
sourceBytes = fs.Read(buffer, 0, buffer.Length);
OutputStream.Write(buffer, 0, sourceBytes);
} while (sourceBytes > 0);
}

OutputStream.Finish();
OutputStream.Close();
Console.WriteLine("Zip file has been built: " + OutputFilePath);
}
}
catch (Exception ex)
{
// No need to rethrow the exception as for our purposes its handled.
Console.WriteLine("Exception during processing {0}", ex);
}
}
9 changes: 3 additions & 6 deletions Installer/Installer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@
<DebugType>none</DebugType>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="WixSharp.bin">
<Version>1.19.*</Version>
</PackageReference>
<PackageReference Include="WixSharp.wix.bin">
<Version>3.11.*</Version>
</PackageReference>
<PackageReference Include="WixSharp.bin" Version="1.19.*"/>
<PackageReference Include="WixSharp.wix.bin" Version="3.11.*"/>
<PackageReference Include="SharpZipLib" Version="1.4.0" />
</ItemGroup>
</Project>

0 comments on commit 8ec4a77

Please sign in to comment.