5 changed files with 220 additions and 0 deletions
@ -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); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -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")] |
||||||
@ -0,0 +1,63 @@ |
|||||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||||
|
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
||||||
|
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> |
||||||
|
<PropertyGroup> |
||||||
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> |
||||||
|
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> |
||||||
|
<ProjectGuid>{250265F7-4579-499B-B41A-B7ECE8BB97DF}</ProjectGuid> |
||||||
|
<OutputType>Exe</OutputType> |
||||||
|
<AppDesignerFolder>Properties</AppDesignerFolder> |
||||||
|
<RootNamespace>ZipFromMsi</RootNamespace> |
||||||
|
<AssemblyName>ZipFromMsi</AssemblyName> |
||||||
|
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion> |
||||||
|
<FileAlignment>512</FileAlignment> |
||||||
|
<TargetFrameworkProfile /> |
||||||
|
</PropertyGroup> |
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> |
||||||
|
<PlatformTarget>AnyCPU</PlatformTarget> |
||||||
|
<DebugSymbols>true</DebugSymbols> |
||||||
|
<DebugType>full</DebugType> |
||||||
|
<Optimize>false</Optimize> |
||||||
|
<OutputPath>bin\Debug\</OutputPath> |
||||||
|
<DefineConstants>DEBUG;TRACE</DefineConstants> |
||||||
|
<ErrorReport>prompt</ErrorReport> |
||||||
|
<WarningLevel>4</WarningLevel> |
||||||
|
<Prefer32Bit>false</Prefer32Bit> |
||||||
|
</PropertyGroup> |
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> |
||||||
|
<PlatformTarget>AnyCPU</PlatformTarget> |
||||||
|
<DebugType>pdbonly</DebugType> |
||||||
|
<Optimize>true</Optimize> |
||||||
|
<OutputPath>bin\Release\</OutputPath> |
||||||
|
<DefineConstants>TRACE</DefineConstants> |
||||||
|
<ErrorReport>prompt</ErrorReport> |
||||||
|
<WarningLevel>4</WarningLevel> |
||||||
|
<Prefer32Bit>false</Prefer32Bit> |
||||||
|
</PropertyGroup> |
||||||
|
<ItemGroup> |
||||||
|
<Reference Include="System" /> |
||||||
|
<Reference Include="System.Core" /> |
||||||
|
<Reference Include="System.IO.Compression" /> |
||||||
|
<Reference Include="System.IO.Compression.FileSystem" /> |
||||||
|
<Reference Include="System.Xml.Linq" /> |
||||||
|
<Reference Include="System.Data.DataSetExtensions" /> |
||||||
|
<Reference Include="Microsoft.CSharp" /> |
||||||
|
<Reference Include="System.Data" /> |
||||||
|
<Reference Include="System.Xml" /> |
||||||
|
</ItemGroup> |
||||||
|
<ItemGroup> |
||||||
|
<Compile Include="Program.cs" /> |
||||||
|
<Compile Include="Properties\AssemblyInfo.cs" /> |
||||||
|
</ItemGroup> |
||||||
|
<ItemGroup> |
||||||
|
<None Include="app.config" /> |
||||||
|
</ItemGroup> |
||||||
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> |
||||||
|
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. |
||||||
|
Other similar extension points exist, see Microsoft.Common.targets. |
||||||
|
<Target Name="BeforeBuild"> |
||||||
|
</Target> |
||||||
|
<Target Name="AfterBuild"> |
||||||
|
</Target> |
||||||
|
--> |
||||||
|
</Project> |
||||||
@ -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 |
||||||
Loading…
Reference in new issue