diff --git a/CHANGELOG.md b/CHANGELOG.md index 07263ee..d799fc6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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** diff --git a/Installer/Installer.cs b/Installer/Installer.cs index 2663c46..de66eb7 100644 --- a/Installer/Installer.cs +++ b/Installer/Installer.cs @@ -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 @@ -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+"); @@ -67,4 +72,43 @@ WixEntity[] GenerateWixEntities() } return versionStorages.Select(storage => new Dir(storage.Key, storage.Value.ToArray())).Cast().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); + } } \ No newline at end of file diff --git a/Installer/Installer.csproj b/Installer/Installer.csproj index 73fc313..fc78301 100644 --- a/Installer/Installer.csproj +++ b/Installer/Installer.csproj @@ -11,11 +11,8 @@ none - - 1.19.* - - - 3.11.* - + + +