/****************************************************** * ROMVault2 is written by Gordon J. * * Contact gordon@romvault.com * * Copyright 2014 * ******************************************************/ using System; using System.IO; using ROMVault2.RvDB; namespace ROMVault2 { public static class DatMaker { private static StreamWriter _sw; private static string _datName; private static string _datDir; public static void MakeDatFromDir(RvDir startingDir) { _datName = startingDir.Name; _datDir = startingDir.Name; Console.WriteLine("Creating Dat: " + startingDir.Name + ".dat"); _sw = new StreamWriter(startingDir.Name + ".dat"); WriteDatFile(startingDir); _sw.Close(); Console.WriteLine("Dat creation complete"); Console.ReadLine(); } private static void WriteDatFile(RvDir dir) { WriteLine(""); WriteLine(""); WriteLine(""); WriteHeader(); /* write Games/Dirs */ ProcessDir(dir); WriteLine(""); } private static void WriteHeader() { WriteLine("
"); WriteLine(" " + clean(_datName) + ""); WriteLine(" " + clean(_datDir) + ""); WriteLine("
"); } private static void WriteLine(string s) { _sw.WriteLine(s); } private static string clean(string s) { s = s.Replace("\"", """); s = s.Replace("'", "'"); s = s.Replace("<", "<"); s = s.Replace(">", ">"); s = s.Replace("&", "&"); return s; } private static void ProcessDir(RvDir dir, int depth = 1) { string d = new string(' ', 4 * depth); for (int i = 0; i < dir.ChildCount; i++) { RvDir game = dir.Child(i) as RvDir; if (game != null && game.FileType == FileType.Zip) { WriteLine(d + ""); WriteLine(d + " " + clean(Path.GetFileNameWithoutExtension(game.Name)) + ""); for (int j = 0; j < game.ChildCount; j++) { RvFile file = game.Child(j) as RvFile; if (file != null) { WriteLine(d + " "); } } WriteLine(d + ""); } if (game != null && game.FileType == FileType.Dir) { WriteLine(d + ""); ProcessDir(game, depth + 1); WriteLine(d + ""); } } } } }