diff --git a/src/Tools/ZipFromMsi/Program.cs b/src/Tools/ZipFromMsi/Program.cs new file mode 100644 index 0000000000..d558b019a1 --- /dev/null +++ b/src/Tools/ZipFromMsi/Program.cs @@ -0,0 +1,98 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.IO.Compression; +using System.Linq; +using System.Text; +using System.Xml.Linq; + +namespace ZipFromMsi +{ + class Program + { + // Xml Constants + private const string ElementNameFragment = "Fragment"; + private const string ElementNameDirectoryRef = "DirectoryRef"; + private const string ElementNameDirectory = "Directory"; + private const string ElementNameComponent = "Component"; + private const string ElementNameFile = "File"; + + // TODO: Promote to parameters / app-computed local variables + private const string WxsFilename = "../../../../Setup/Files.wxs"; + public static string RelativePathToolToSetupFolder = "..\\..\\..\\"; + + // App Constants + private static readonly XNamespace Namespace = "http://schemas.microsoft.com/wix/2006/wi"; + private const string ZipRootDirectory = "SharpDevelop"; + + static void Main(string[] args) + { + // TODO: Pass name of zip file + // TODO: Auto-detect relative path (maybe see UpdateAssemblyInfo) + + string zipFileName = DateTime.Now.Ticks.ToString() + ".Standalone.zip"; + + CreateZip(zipFileName, LoadWxsFile(WxsFilename)); + } + + static void CreateZip(string zipFileName, XDocument doc) + { + XElement root = doc.Root; + + var fragment = root.Element(Namespace + ElementNameFragment); + var directoryRef = fragment.Element(Namespace + ElementNameDirectoryRef); + + var programDirectory = directoryRef.Elements().First(); + + if ("ProgramFilesFolder" == (string)programDirectory.Attribute("Id")) + { + var sdfolder = programDirectory.Elements().First(); + var installdir = sdfolder.Elements().First(); + + using (ZipArchive theZip = ZipFile.Open(zipFileName, ZipArchiveMode.Create)) + { + foreach (var folder in installdir.Elements(Namespace + ElementNameDirectory)) + { + ProcessFolder(folder, theZip, ZipRootDirectory); + } + } + } + } + + static void ProcessFolder(XElement folder, ZipArchive theZip, string folderRelativePath) + { + string targetDirectory = (string)folder.Attribute("Name"); + string currentRelativePath = AppendRelativePath(folderRelativePath, targetDirectory); + + Console.WriteLine("Processing folder " + currentRelativePath); + + foreach (var component in folder.Elements(Namespace + ElementNameComponent)) + { + foreach (var file in component.Elements(Namespace + ElementNameFile)) + { + string source = (string)file.Attribute("Source"); + string name = (string)file.Attribute("Name"); + + theZip.CreateEntryFromFile(RelativePathToolToSetupFolder + source, + AppendRelativePath(currentRelativePath, name), + CompressionLevel.Optimal); + } + } + + foreach (var secondaryFolder in folder.Elements(Namespace + ElementNameDirectory)) + { + ProcessFolder(secondaryFolder, theZip, currentRelativePath); + } + } + + static string AppendRelativePath(string firstPart, string newPart) + { + return firstPart + "/" + newPart; + } + + static XDocument LoadWxsFile(string filename) + { + return XDocument.Load(filename); + } + } +} diff --git a/src/Tools/ZipFromMsi/Properties/AssemblyInfo.cs b/src/Tools/ZipFromMsi/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..c135b4aef6 --- /dev/null +++ b/src/Tools/ZipFromMsi/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +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("ZipFromMsi")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("ZipFromMsi")] +[assembly: AssemblyCopyright("Copyright © 2013")] +[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("1acbffa4-d4aa-44ff-b890-7f9abaf7916a")] + +// 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")] diff --git a/src/Tools/ZipFromMsi/ZipFromMsi.csproj b/src/Tools/ZipFromMsi/ZipFromMsi.csproj new file mode 100644 index 0000000000..2da32115d9 --- /dev/null +++ b/src/Tools/ZipFromMsi/ZipFromMsi.csproj @@ -0,0 +1,63 @@ + + + + + Debug + AnyCPU + {250265F7-4579-499B-B41A-B7ECE8BB97DF} + Exe + Properties + ZipFromMsi + ZipFromMsi + v4.5 + 512 + + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + false + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + false + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Tools/ZipFromMsi/ZipFromMsi.sln b/src/Tools/ZipFromMsi/ZipFromMsi.sln new file mode 100644 index 0000000000..553afeb287 --- /dev/null +++ b/src/Tools/ZipFromMsi/ZipFromMsi.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2012 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ZipFromMsi", "ZipFromMsi.csproj", "{250265F7-4579-499B-B41A-B7ECE8BB97DF}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {250265F7-4579-499B-B41A-B7ECE8BB97DF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {250265F7-4579-499B-B41A-B7ECE8BB97DF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {250265F7-4579-499B-B41A-B7ECE8BB97DF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {250265F7-4579-499B-B41A-B7ECE8BB97DF}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/src/Tools/ZipFromMsi/app.config b/src/Tools/ZipFromMsi/app.config new file mode 100644 index 0000000000..c5e1daefd3 --- /dev/null +++ b/src/Tools/ZipFromMsi/app.config @@ -0,0 +1,3 @@ + + +