diff --git a/DATFromDir/DATFromDir.cs b/DATFromDir/DATFromDir.cs
index 8a56de56..3ac6cb9f 100644
--- a/DATFromDir/DATFromDir.cs
+++ b/DATFromDir/DATFromDir.cs
@@ -227,11 +227,6 @@ namespace SabreTools
return String.Compare(A.Game, B.Game);
});
- //TODO: So, this below section is a pretty much one for one copy of code that is written in generate
- // this means that in the future, "writing to DAT" will be abstracted out to the DLL so that any
- // properly formatted data can be passed in and it will get written as necessary. That would open
- // the possibiliites for different ways to generate a DAT from multiple things
-
// Double check to see what it needs to be named
if (_name == "")
{
@@ -252,87 +247,8 @@ namespace SabreTools
_desc = (_desc == "" ? _name + (_noDate ? "" : " (" + _date + ")") : _desc);
// Now write it all out as a DAT
- try
- {
- FileStream fs = File.Create(_desc + ".xml");
- StreamWriter sw = new StreamWriter(fs, Encoding.UTF8);
-
- string header_old = "clrmamepro (\n" +
- "\tname \"" + _name + "\"\n" +
- "\tdescription \"" + _desc + "\"\n" +
- "\tversion \"" + _version + "\"\n" +
- "\tcomment \"\"\n" +
- "\tauthor \"" + _author + "\"\n" +
- (_forceunzip ? "\tforcezipping no\n" : "") +
- ")\n";
-
- string header = "\n" +
- "\n\n" +
- "\t\n" +
- "\t\t\n" +
- "\t\t\t" + HttpUtility.HtmlEncode(_name) + "\n" +
- "\t\t\t" + HttpUtility.HtmlEncode(_desc) + "\n" +
- "\t\t\t" + HttpUtility.HtmlEncode(_cat) + "\n" +
- "\t\t\t" + HttpUtility.HtmlEncode(_version) + "\n" +
- "\t\t\t" + _date + "\n" +
- "\t\t\t" + HttpUtility.HtmlEncode(_author) + "\n" +
- (_forceunzip ? "\t\t\t\n" : "") +
- "\t\t\n";
-
- // Write the header out
- sw.Write((_old ? header_old : header));
-
- // Write out each of the machines and roms
- string lastgame = "";
- foreach (RomData rom in _roms)
- {
- string state = "";
- if (lastgame != "" && lastgame != rom.Game)
- {
- state += (_old ? ")\n" : "\t\n");
- }
-
- if (lastgame != rom.Game)
- {
- state += (_old ? "game (\n\tname \"" + rom.Game + "\"\n" +
- "\tdescription \"" + rom.Game + "\"\n" :
- "\t\n" +
- "\t\t" + HttpUtility.HtmlEncode(rom.Game) + "\n");
- }
-
- if (_old)
- {
- state += "\trom ( name \"" + rom.Name + "\"" +
- (rom.Size != 0 ? " size " + rom.Size : "") +
- (rom.CRC != "" ? " crc " + rom.CRC.ToLowerInvariant() : "") +
- (rom.MD5 != "" ? " md5 " + rom.MD5.ToLowerInvariant() : "") +
- (rom.SHA1 != "" ? " sha1 " + rom.SHA1.ToLowerInvariant() : "") +
- " )\n";
- }
- else
- {
- state += "\t\t\n";
- }
-
- lastgame = rom.Game;
-
- sw.Write(state);
- }
-
- sw.Write((_old ? ")" : "\t\n"));
- _logger.Log("File written!" + Environment.NewLine);
- sw.Close();
- fs.Close();
- }
- catch (Exception ex)
- {
- _logger.Error(ex.ToString());
- }
+ Output.WriteToDat(_name, _desc, _version, _date, _cat, _author, _forceunzip, _old, Environment.CurrentDirectory, _roms, _logger);
+
_logger.Close();
}
@@ -420,6 +336,7 @@ namespace SabreTools
_roms.Add(new RomData
{
+ Type = "rom",
Game = Path.GetFileNameWithoutExtension(item),
Name = entry.Remove(0, _tempDir.Length),
Size = (new FileInfo(entry)).Length,
@@ -483,6 +400,7 @@ namespace SabreTools
_roms.Add(new RomData
{
+ Type = "rom",
Game = actualroot,
Name = actualitem,
Size = (new FileInfo(item)).Length,
diff --git a/DATabase/Generate.cs b/DATabase/Generate.cs
index ec683b89..d33d5018 100644
--- a/DATabase/Generate.cs
+++ b/DATabase/Generate.cs
@@ -182,106 +182,7 @@ namespace SabreTools
string intname = systemname + " (" + sourcename + ")";
string datname = systemname + " (" + sourcename + " " + version + ")";
- // Create and open an output file for writing (currently uses current time, change to "last updated time"
- _logger.Log("Opening file for writing: " + _outdir + datname + (_old ? ".dat" : ".xml"));
-
- try
- {
- FileStream fs = File.Create(_outdir + datname + (_old ? ".dat" : ".xml"));
- StreamWriter sw = new StreamWriter(fs, Encoding.UTF8);
-
- // Temporarilly set _system if we're in MEGAMERGED mode to get the right header skip XML
- if (_systems == "" && _sources == "")
- {
- _systems = "0";
- }
-
- string header_old = "clrmamepro (\n" +
- "\tname \"" + HttpUtility.HtmlEncode(intname) + "\"\n" +
- "\tdescription \"" + HttpUtility.HtmlEncode(datname) + "\"\n" +
- "\tversion \"" + version + "\"\n" +
- //(_systems != "" && _systems.Split(',').Length == 1 && _headers.ContainsKey(Int32.Parse(_systems)) ? " header \"" + _headers[Int32.Parse(_systems)] + "\"\n" : "") +
- "\tcomment \"\"\n" +
- "\tauthor \"The Wizard of DATz\"\n" +
- ")\n";
-
- string header = "\n" +
- "\n\n" +
- "\t\n" +
- "\t\t\n" +
- "\t\t\t" + HttpUtility.HtmlEncode(intname) + "\n" +
- "\t\t\t" + HttpUtility.HtmlEncode(datname) + "\n" +
- "\t\t\tThe Wizard of DATz\n" +
- "\t\t\t" + version + "\n" +
- "\t\t\t" + version + "\n" +
- "\t\t\tThe Wizard of DATz\n" +
- //"\t\t\t\n" +
- "\t\t\n";
-
- // Unset _system again if we're in MEGAMERGED mode
- if (_systems == "0" && _sources == "")
- {
- _systems = "";
- }
-
- // Write the header out
- sw.Write((_old ? header_old : header));
-
- // Write out each of the machines and roms
- string lastgame = "";
- foreach (RomData rom in roms)
- {
- string state = "";
- if (lastgame != "" && lastgame != rom.Game)
- {
- state += (_old ? ")\n" : "\t\n");
- }
-
- if (lastgame != rom.Game)
- {
- state += (_old ? "game (\n\tname \"" + rom.Game + "\"\n" +
- "\tdescription \"" + rom.Game + "\"\n" :
- "\t\n" +
- "\t\t" + HttpUtility.HtmlEncode(rom.Game) + "\n");
- }
-
- if (_old)
- {
- state += "\t" + rom.Type + " ( name \"" + rom.Name + "\"" +
- (rom.Size != 0 ? " size " + rom.Size : "") +
- (rom.CRC != "" ? " crc " + rom.CRC.ToLowerInvariant() : "") +
- (rom.MD5 != "" ? " md5 " + rom.MD5.ToLowerInvariant() : "") +
- (rom.SHA1 != "" ? " sha1 " + rom.SHA1.ToLowerInvariant() : "") +
- " )\n";
- }
- else
- {
- state += "\t\t<" + rom.Type + " name=\"" + HttpUtility.HtmlEncode(rom.Name) + "\"" +
- (rom.Size != -1 ? " size=\"" + rom.Size + "\"" : "") +
- (rom.CRC != "" ? " crc=\"" + rom.CRC.ToLowerInvariant() + "\"" : "") +
- (rom.MD5 != "" ? " md5=\"" + rom.MD5.ToLowerInvariant() + "\"" : "") +
- (rom.SHA1 != "" ? " sha1=\"" + rom.SHA1.ToLowerInvariant() + "\"" : "") +
- " />\n";
- }
-
- lastgame = rom.Game;
-
- sw.Write(state);
- }
-
- sw.Write((_old ? ")" : "\t\n"));
- _logger.Log("File written!");
- sw.Close();
- fs.Close();
- }
- catch (Exception ex)
- {
- _logger.Error(ex.ToString());
- return false;
- }
-
- return true;
+ return Output.WriteToDat(intname, datname, version, version, "The Wizard of DATz", "The Wizard of DATz", false, _old, _outdir, roms, _logger);
}
///
diff --git a/SabreHelper/Output.cs b/SabreHelper/Output.cs
index e35f1182..6f3b140f 100644
--- a/SabreHelper/Output.cs
+++ b/SabreHelper/Output.cs
@@ -86,7 +86,7 @@ namespace SabreTools.Helper
}
sw.Write((old ? ")" : "\t\n"));
- logger.Log("File written!");
+ logger.Log("File written!" + Environment.NewLine);
sw.Close();
fs.Close();
}