Skip to content
This repository was archived by the owner on Feb 25, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions VDProjectXml.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@

Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VDProjectXml", "VDProjectXml\VDProjectXml.csproj", "{5A8370C6-742B-48F9-8D65-15F4CB69FC25}"
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.24720.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VDProject2Xml", "VDProjectXml\VDProject2Xml.csproj", "{5A8370C6-742B-48F9-8D65-15F4CB69FC25}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
139 changes: 101 additions & 38 deletions VDProjectXml/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,34 @@
using System.Xml;
using System.Text.RegularExpressions;

namespace VDProjectXml
namespace VDProject2Xml
{
class Program
{
/// <summary>
/// Matches "key" [= "8:value"] with support for backslash escapes.
/// </summary>
private static readonly Regex ElementRegex = new Regex(@"^""([^""\\]*(?:\\.[^""\\]*)*)""(?:\s*=\s*""(\d+):([^""\\]*(?:\\.[^""\\]*)*)"")?$", RegexOptions.Singleline);

private const string Indent = " ";

static void Main(string[] args)
/// <summary>
/// Matches <c>"key" [= "8:value"]</c> with support for backslash escapes.
/// </summary>
private static readonly Regex ElementRegex = new Regex(@"^""([^""\\]*(?:\\.[^""\\]*)*)""(?:\s*=\s*""(\d+):([^""\\]*(?:\\.[^""\\]*)*)"")?$", RegexOptions.Singleline);

/// <summary>
/// Mataches <c>"value:value"</c> for keyless entries like <c>"{EDC2488A-8267-493A-A98E-7D9C3B36CDF3}:.NETFramework,Version=v4.5.2"</c>
/// or <c>"BootstrapperCfg:{63ACBE69-63AA-4F98-B2B6-99F9E24495F2}"</c>.
/// </summary>
private static readonly Regex NoKeyEntry = new Regex(@"^""([^""]*?):([^""]*)""$", RegexOptions.Singleline);

private const string Indent = " ";
private const string NoKeyEntryName = "NoKeyEntry";
private const string ValueTypeAttribute = "valueType";
private const string ValueAttribute = "value";

static int Main(string[] args)
{
if (args.Length == 0 || args.Length > 3)
{
ShowHelp();
return -1;
}

string inputFile = args[0];
string outputFile = args.Length > 1 ? args[1] : null;

Expand All @@ -33,14 +48,43 @@ static void Main(string[] args)
break;

default:
throw new Exception("Unknown file type: " + inputFile);
ShowHelp();
return -2;
}

return 0;
}

static void ConvertVDProjToXml(string vdrpojFile, string xmlFile)
{
private static void ShowHelp()
{
Console.WriteLine("VDProject2Xml - A Visual Studio installer to XML converter.");
Console.WriteLine("Usage: VDProject2Xml installerProject.vdproj [installerProject.xml]");
Console.WriteLine(" VDProject2Xml installerProject.xml [installerProject.vdproj]");
Console.WriteLine("If no output file path is provided the program will use the input filename with the extension changed to .xml");
Console.WriteLine("Set the environment variable VDPROJECT2XML_INDENT to \"{0}\" to make the outputed XML use newlines and indenting.", Boolean.TrueString);
}

public static bool CheckIfShouldIndent()
{
var indentString = Environment.GetEnvironmentVariable("VDPROJECT2XML_INDENT");
bool result;
if (!Boolean.TryParse(indentString, out result))
{
result = false;
}
return result;
}

static void ConvertVDProjToXml(string vdrpojFile, string xmlFile)
{

XmlWriterSettings settings = new XmlWriterSettings()
{
Indent = CheckIfShouldIndent()
};

using (StreamReader reader = File.OpenText(vdrpojFile))
using (XmlWriter writer = XmlWriter.Create(xmlFile))
using (XmlWriter writer = XmlWriter.Create(xmlFile, settings))
{
string line;
bool prevLineElement = false;
Expand All @@ -52,23 +96,33 @@ static void ConvertVDProjToXml(string vdrpojFile, string xmlFile)

Match match = ElementRegex.Match(line);

if (match.Success)
if (match.Success)
{
if (prevLineElement)
writer.WriteEndElement();

string elementName = Unescape(match.Groups[1].Value);
string fixedElementName = XmlConvert.EncodeLocalName(elementName);

writer.WriteStartElement(fixedElementName);

if (match.Groups[2].Success)
{
writer.WriteAttributeString("valueType", match.Groups[2].Value);
writer.WriteAttributeString("value", Unescape(match.Groups[3].Value));
}

prevLineElement = true;
Match noKeyMatch = NoKeyEntry.Match(line);
if (noKeyMatch.Success)
{
writer.WriteStartElement(NoKeyEntryName);
writer.WriteAttributeString(ValueTypeAttribute, Unescape(noKeyMatch.Groups[1].Value));
writer.WriteAttributeString(ValueAttribute, Unescape(noKeyMatch.Groups[2].Value));
}
else
{
string elementName = Unescape(match.Groups[1].Value);
string fixedElementName = XmlConvert.EncodeLocalName(elementName);

writer.WriteStartElement(fixedElementName);

if (match.Groups[2].Success)
{
writer.WriteAttributeString(ValueTypeAttribute, match.Groups[2].Value);
writer.WriteAttributeString(ValueAttribute, Unescape(match.Groups[3].Value));
}
}

prevLineElement = true;
}
else
{
Expand All @@ -91,7 +145,7 @@ static void ConvertVDProjToXml(string vdrpojFile, string xmlFile)
}
}

static void ConvertXmlVDProj(string vdrpojFile, string xmlFile)
static void ConvertXmlVDProj(string xmlFile, string vdrpojFile)
{
int indentLevel = -1;

Expand Down Expand Up @@ -125,17 +179,26 @@ static void ConvertXmlVDProj(string vdrpojFile, string xmlFile)
}

private static void WriteElement(XmlReader reader, TextWriter writer)
{
string elementName = Escape(XmlConvert.DecodeName(reader.LocalName));

writer.Write("\"{0}\"", elementName);

string value = reader.GetAttribute("value");

if (value != null)
{
writer.Write(" = \"{0}:{1}\"", reader.GetAttribute("valueType"), Escape(value));
}
{
string valueType = reader.GetAttribute(ValueTypeAttribute);
string value = reader.GetAttribute(ValueAttribute);

if (reader.LocalName == NoKeyEntryName)
{
writer.Write("\"{0}:{1}\"", Escape(valueType), Escape(value));
}
else
{
string elementName = Escape(XmlConvert.DecodeName(reader.LocalName));

writer.Write("\"{0}\"", elementName);

if (value != null)
{
writer.Write(" = \"{0}:{1}\"", valueType, Escape(value));
}
}


writer.WriteLine();
}
Expand Down
146 changes: 88 additions & 58 deletions VDProjectXml/VDProjectXml.csproj → VDProjectXml/VDProject2Xml.csproj
Original file line number Diff line number Diff line change
@@ -1,59 +1,89 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{5A8370C6-742B-48F9-8D65-15F4CB69FC25}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>VDProjectXml</RootNamespace>
<AssemblyName>VDProjectXml</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data.DataSetExtensions">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</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>
-->
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{5A8370C6-742B-48F9-8D65-15F4CB69FC25}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>VDProject2Xml</RootNamespace>
<AssemblyName>VDProject2Xml</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<FileUpgradeFlags>
</FileUpgradeFlags>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<OldToolsVersion>3.5</OldToolsVersion>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<StartupObject>VDProject2Xml.Program</StartupObject>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data.DataSetExtensions">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
</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>