Major changes to structure and code

First is the inclusion of two new projects: SabreHelper and SingleGame. SabreHelper is a DLL that contains anything that might be in common between programs (converters, db tools, logging). SingleGame is an experimental program to minimize a DAT for server usage, requested by Kludge.

The new structure represents a cleaner approach to having helper functions in a DLL, making each individual executable smaller and more well-defined.
This commit is contained in:
Matt Nadareski
2016-04-06 00:01:54 -07:00
parent 762c80d280
commit 0f0313d52b
26 changed files with 469 additions and 23 deletions

View File

@@ -16,10 +16,9 @@ namespace SabreTools
private static Logger logger;
private static string _dbName = "DATabase.sqlite";
private static string _connectionString = "Data Source=" + _dbName + ";Version = 3;";
private static string _version = "0.3.0.0";
private static string _header =
@"+-----------------------------------------------------------------------------+
| DATabase " + _version + @" |
| DATabase " + Build.Version + @" |
| |
| Programming: Matt Nadareski (darksabre76) |
| Testing: @tractivo |
@@ -656,9 +655,9 @@ or 'b' to go back to the previous menu:
fs.Close();
Console.WriteLine("Converted file: " + Path.GetFileNameWithoutExtension(filename) + ".new.dat");
}
catch (XmlException ex)
catch (XmlException)
{
logger.Warning("The file " + filename + " could not be parsed as an XML file.");
logger.Warning("The file " + filename + " could not be parsed as an XML file");
}
}
else

View File

@@ -66,15 +66,10 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Helper\Converters.cs" />
<Compile Include="Core\Generate.cs" />
<Compile Include="Core\Import.cs" />
<Compile Include="Helper\DBTools.cs" />
<Compile Include="Generate.cs" />
<Compile Include="Import.cs" />
<Compile Include="DATabase.cs" />
<Compile Include="Helper\Logger.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Helper\Remapping.cs" />
<Compile Include="Helper\Style.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
@@ -97,6 +92,12 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SabreHelper\SabreHelper.csproj">
<Project>{225a1afd-0890-44e8-b779-7502665c23a5}</Project>
<Name>SabreHelper</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\System.Data.SQLite.Core.1.0.99.0\build\net451\System.Data.SQLite.Core.targets" Condition="Exists('..\packages\System.Data.SQLite.Core.1.0.99.0\build\net451\System.Data.SQLite.Core.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">

View File

@@ -340,7 +340,7 @@ namespace SabreTools
{
doc.LoadXml(File.ReadAllText(_filepath));
}
catch (XmlException ex)
catch (XmlException)
{
doc.LoadXml(Converters.RomVaultToXML(File.ReadAllLines(_filepath)).ToString());
}

View File

@@ -14,7 +14,6 @@ namespace DatSplit
private static string extA;
private static string extB;
private static string filename;
private static string _version = "0.3.0.0";
public static void Main(string[] args)
{
@@ -36,7 +35,7 @@ namespace DatSplit
{
doc.LoadXml(File.ReadAllText(filename));
}
catch (XmlException ex)
catch (XmlException)
{
doc.LoadXml(Converters.RomVaultToXML(File.ReadAllLines(filename)).ToString());
}

View File

@@ -50,9 +50,9 @@
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DATabase\DATabase.csproj">
<Project>{3b615702-1866-4d7b-8af1-7b43fd0cc1d0}</Project>
<Name>DATabase</Name>
<ProjectReference Include="..\SabreHelper\SabreHelper.csproj">
<Project>{225a1afd-0890-44e8-b779-7502665c23a5}</Project>
<Name>SabreHelper</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

View File

@@ -13,7 +13,6 @@ namespace SabreTools
/// </summary>
class Headerer
{
private static string _version = "0.3.0.0";
private static string _dbName = "Headerer.sqlite";
private static string _connectionString = "Data Source=" + _dbName + ";Version = 3;";
private static Dictionary<string, int> types;

View File

@@ -73,6 +73,12 @@
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SabreHelper\SabreHelper.csproj">
<Project>{225a1afd-0890-44e8-b779-7502665c23a5}</Project>
<Name>SabreHelper</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\System.Data.SQLite.Core.1.0.99.0\build\net451\System.Data.SQLite.Core.targets" Condition="Exists('..\packages\System.Data.SQLite.Core.1.0.99.0\build\net451\System.Data.SQLite.Core.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">

24
SabreHelper/App.config Normal file
View File

@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v12.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
</providers>
</entityFramework>
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SQLite.EF6" />
<add name="SQLite Data Provider (Entity Framework 6)" invariant="System.Data.SQLite.EF6" description=".NET Framework Data Provider for SQLite (Entity Framework 6)" type="System.Data.SQLite.EF6.SQLiteProviderFactory, System.Data.SQLite.EF6" />
<remove invariant="System.Data.SQLite" /><add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".NET Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" /></DbProviderFactories>
</system.data>
</configuration>

10
SabreHelper/Build.cs Normal file
View File

@@ -0,0 +1,10 @@
namespace SabreTools.Helper
{
public class Build
{
public static string Version
{
get { return "0.3.0.0"; }
}
}
}

View File

@@ -7,7 +7,7 @@ namespace SabreTools.Helper
/// <summary>
/// All general database operations
/// </summary>
class DBTools
public class DBTools
{
/// <summary>
/// Ensure that the databse exists and has the proper schema

View File

@@ -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("SabreHelper")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SabreHelper")]
[assembly: AssemblyCopyright("Copyright © 2016")]
[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("225a1afd-0890-44e8-b779-7502665c23a5")]
// 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")]

View File

@@ -8,7 +8,7 @@ namespace SabreTools.Helper
/// <summary>
/// Contains all remappings of known import classes
/// </summary>
class Remapping
public class Remapping
{
// Remapping classes represented by dictionaries
public static Dictionary<string, string> MAME = new Dictionary<string, string>();

View File

@@ -0,0 +1,93 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.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>{225A1AFD-0890-44E8-B779-7502665C23A5}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>SabreTools.Helper</RootNamespace>
<AssemblyName>SabreTools</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</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="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<HintPath>..\packages\EntityFramework.6.0.0\lib\net45\EntityFramework.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<HintPath>..\packages\EntityFramework.6.0.0\lib\net45\EntityFramework.SqlServer.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Core" />
<Reference Include="System.Data.SQLite, Version=1.0.99.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=MSIL">
<HintPath>..\packages\System.Data.SQLite.Core.1.0.99.0\lib\net451\System.Data.SQLite.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Data.SQLite.EF6, Version=1.0.99.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=MSIL">
<HintPath>..\packages\System.Data.SQLite.EF6.1.0.99.0\lib\net451\System.Data.SQLite.EF6.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Data.SQLite.Linq, Version=1.0.99.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=MSIL">
<HintPath>..\packages\System.Data.SQLite.Linq.1.0.99.0\lib\net451\System.Data.SQLite.Linq.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Converters.cs" />
<Compile Include="DBTools.cs" />
<Compile Include="Logger.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Remapping.cs" />
<Compile Include="Style.cs" />
<Compile Include="Build.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\System.Data.SQLite.Core.1.0.99.0\build\net451\System.Data.SQLite.Core.targets" Condition="Exists('..\packages\System.Data.SQLite.Core.1.0.99.0\build\net451\System.Data.SQLite.Core.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\System.Data.SQLite.Core.1.0.99.0\build\net451\System.Data.SQLite.Core.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\System.Data.SQLite.Core.1.0.99.0\build\net451\System.Data.SQLite.Core.targets'))" />
</Target>
<!-- 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>

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="EntityFramework" version="6.0.0" targetFramework="net452" />
<package id="System.Data.SQLite" version="1.0.99.0" targetFramework="net452" />
<package id="System.Data.SQLite.Core" version="1.0.99.0" targetFramework="net452" />
<package id="System.Data.SQLite.EF6" version="1.0.99.0" targetFramework="net452" />
<package id="System.Data.SQLite.Linq" version="1.0.99.0" targetFramework="net452" />
</packages>

View File

@@ -11,6 +11,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SabreToolsUI", "SabreToolsU
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DatSplit", "DatSplit\DatSplit.csproj", "{9EB4738D-CAE7-420D-8A26-78A53CEA5E82}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SingleGame", "SingleGame\SingleGame.csproj", "{07EB8EA7-303A-407F-A881-060ED4595D7F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SabreHelper", "SabreHelper\SabreHelper.csproj", "{225A1AFD-0890-44E8-B779-7502665C23A5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -33,6 +37,14 @@ Global
{9EB4738D-CAE7-420D-8A26-78A53CEA5E82}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9EB4738D-CAE7-420D-8A26-78A53CEA5E82}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9EB4738D-CAE7-420D-8A26-78A53CEA5E82}.Release|Any CPU.Build.0 = Release|Any CPU
{07EB8EA7-303A-407F-A881-060ED4595D7F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{07EB8EA7-303A-407F-A881-060ED4595D7F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{07EB8EA7-303A-407F-A881-060ED4595D7F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{07EB8EA7-303A-407F-A881-060ED4595D7F}.Release|Any CPU.Build.0 = Release|Any CPU
{225A1AFD-0890-44E8-B779-7502665C23A5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{225A1AFD-0890-44E8-B779-7502665C23A5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{225A1AFD-0890-44E8-B779-7502665C23A5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{225A1AFD-0890-44E8-B779-7502665C23A5}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@@ -8,7 +8,7 @@ using System.Threading.Tasks;
namespace SabreTools
{
class Helper
class UIHelper
{
private static string _dbName = "DATabase.sqlite";
private static string _connectionString = "Data Source=" + _dbName + ";Version = 3;";

View File

@@ -123,7 +123,7 @@
// systemsCheckedListBox
//
this.systemsCheckedListBox.FormattingEnabled = true;
this.systemsCheckedListBox.Items.AddRange(Helper.GetAllSystems());
this.systemsCheckedListBox.Items.AddRange(UIHelper.GetAllSystems());
this.systemsCheckedListBox.Location = new System.Drawing.Point(77, 65);
this.systemsCheckedListBox.Name = "systemsCheckedListBox";
this.systemsCheckedListBox.Size = new System.Drawing.Size(260, 34);
@@ -132,7 +132,7 @@
// sourcesCheckedListBox
//
this.sourcesCheckedListBox.FormattingEnabled = true;
this.sourcesCheckedListBox.Items.AddRange(Helper.GetAllSources());
this.sourcesCheckedListBox.Items.AddRange(UIHelper.GetAllSources());
this.sourcesCheckedListBox.Location = new System.Drawing.Point(415, 65);
this.sourcesCheckedListBox.Name = "sourcesCheckedListBox";
this.sourcesCheckedListBox.Size = new System.Drawing.Size(244, 34);

View File

@@ -104,6 +104,12 @@
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SabreHelper\SabreHelper.csproj">
<Project>{225a1afd-0890-44e8-b779-7502665c23a5}</Project>
<Name>SabreHelper</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\System.Data.SQLite.Core.1.0.99.0\build\net451\System.Data.SQLite.Core.targets" Condition="Exists('..\packages\System.Data.SQLite.Core.1.0.99.0\build\net451\System.Data.SQLite.Core.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">

6
SingleGame/App.config Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
</configuration>

View File

@@ -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("SingleGame")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SingleGame")]
[assembly: AssemblyCopyright("Copyright © 2016")]
[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("07eb8ea7-303a-407f-a881-060ed4595d7f")]
// 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")]

145
SingleGame/SingleGame.cs Normal file
View File

@@ -0,0 +1,145 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Linq;
using SabreTools.Helper;
namespace SabreTools
{
public class SingleGame
{
private static string filename;
public static void Main(string[] args)
{
if (args.Length != 1)
{
Help();
return;
}
filename = args[0];
// Take the filename, and load it as an XML document
XmlDocument doc = new XmlDocument();
try
{
doc.LoadXml(File.ReadAllText(filename));
}
catch (XmlException)
{
doc.LoadXml(Converters.RomVaultToXML(File.ReadAllLines(filename)).ToString());
}
// We all start the same
XmlNode node = doc.FirstChild;
if (node != null && node.Name == "xml")
{
// Skip over everything that's not an element
while (node.NodeType != XmlNodeType.Element)
{
node = node.NextSibling;
}
}
XmlDocument tempDoc = new XmlDocument();
XmlNode outNode = tempDoc.CreateNode(XmlNodeType.Element, node.Name, "");
// Once we find the main body, enter it
if (node != null && node.Name == "datafile")
{
node = node.FirstChild;
}
// Now here's where it differs from import
bool inGame = false;
while (node != null)
{
// If we're at a game node, add the parent node but not all the internals
if (node.NodeType == XmlNodeType.Element && (node.Name == "machine" || node.Name == "game"))
{
if (!inGame)
{
XmlElement tempNode = tempDoc.CreateElement(node.Name);
tempNode.SetAttribute("name", "!");
outNode.AppendChild(tempNode);
outNode = outNode.LastChild;
inGame = true;
}
// Get the roms from the machine
if (node.HasChildNodes)
{
// If this node has children, traverse the children
foreach (XmlNode child in node.ChildNodes)
{
// If we find a rom or disk, add it
if (child.NodeType == XmlNodeType.Element && (child.Name == "rom" || child.Name == "disk"))
{
// Take care of hex-sized files
long size = -1;
if (child.Attributes["size"] != null && child.Attributes["size"].Value.Contains("0x"))
{
size = Convert.ToInt64(child.Attributes["size"].Value, 16);
}
else if (child.Attributes["size"] != null)
{
size = Int64.Parse(child.Attributes["size"].Value);
}
XmlElement tempNode = (XmlElement)tempDoc.ImportNode(child, true);
// Windows max name length is 260. Taking into account the game name of "!", we can use 259 characters
tempNode.SetAttribute("name", "(" + node.Attributes["name"].Value + ")" + child.Attributes["name"].Value);
tempNode.Attributes["name"].Value = (tempNode.Attributes["name"].Value.Length > 259 ? tempNode.Attributes["name"].Value.Substring(0, 259) : tempNode.Attributes["name"].Value);
outNode.AppendChild(tempNode);
}
}
}
}
else
{
XmlNode tempNode = tempDoc.ImportNode(node, true);
outNode.AppendChild(tempNode);
}
node = node.NextSibling;
}
tempDoc.AppendChild(tempDoc.CreateDocumentType("datafile", "-//Logiqx//DTD ROM Management Datafile//EN", "http://www.logiqx.com/Dats/datafile.dtd", null));
tempDoc.AppendChild(outNode);
string outPath = Path.GetFileNameWithoutExtension(filename) + ".new" + Path.GetExtension(filename);
File.WriteAllText(outPath, Beautify(tempDoc));
}
private static void Help()
{
}
// http://stackoverflow.com/questions/203528/what-is-the-simplest-way-to-get-indented-xml-with-line-breaks-from-xmldocument
// http://www.timvw.be/2007/01/08/generating-utf-8-with-systemxmlxmlwriter/
static public string Beautify(XmlDocument doc)
{
MemoryStream ms = new MemoryStream();
XmlWriterSettings settings = new XmlWriterSettings
{
Encoding = new UTF8Encoding(false),
Indent = true,
IndentChars = "\t",
NewLineChars = "\r\n",
NewLineHandling = NewLineHandling.Replace
};
using (XmlWriter writer = XmlWriter.Create(ms, settings))
{
doc.Save(writer);
}
return Encoding.UTF8.GetString(ms.ToArray());
}
}
}

View File

@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.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>{07EB8EA7-303A-407F-A881-060ED4595D7F}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>SingleGame</RootNamespace>
<AssemblyName>SingleGame</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\..\Builds\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</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>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="SingleGame.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SabreHelper\SabreHelper.csproj">
<Project>{225a1afd-0890-44e8-b779-7502665c23a5}</Project>
<Name>SabreHelper</Name>
</ProjectReference>
</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>