/// <summary> /// Write out DatItem using the supplied StreamWriter /// </summary> /// <param name="iw">IniWriter to output to</param> /// <param name="datItem">DatItem object to be output</param> private void WriteDatItem(IniWriter iw, DatItem datItem) { /* * The rominfo order is as follows: * 1 - parent name * 2 - parent description * 3 - game name * 4 - game description * 5 - rom name * 6 - rom crc * 7 - rom size * 8 - romof name * 9 - merge name */ // Pre-process the item name ProcessItemName(datItem, true); // Build the state switch (datItem.ItemType) { case ItemType.Rom: var rom = datItem as Rom; iw.WriteString($"¬{rom.Machine.CloneOf ?? string.Empty}"); iw.WriteString($"¬{rom.Machine.CloneOf ?? string.Empty}"); iw.WriteString($"¬{rom.Machine.Name ?? string.Empty}"); if (string.IsNullOrWhiteSpace(rom.Machine.Description ?? string.Empty)) { iw.WriteString($"¬{rom.Machine.Name ?? string.Empty}"); } else { iw.WriteString($"¬{rom.Machine.Description ?? string.Empty}"); } iw.WriteString($"¬{rom.Name ?? string.Empty}"); iw.WriteString($"¬{rom.CRC ?? string.Empty}"); iw.WriteString($"¬{rom.Size?.ToString() ?? string.Empty}"); iw.WriteString($"¬{rom.Machine.RomOf ?? string.Empty}"); iw.WriteString($"¬{rom.MergeTag ?? string.Empty}"); iw.WriteString("¬"); iw.WriteLine(); break; } iw.Flush(); }
public void TestLineEndingLF() { using (var mem = new MemoryStream()) using (var streamWriter = new StreamWriter(mem)) using (var writer = new IniWriter(streamWriter, new IniOptions(lineEndings: LineEnding.LF))) { writer.StartSection("section"); writer.Write(); writer.Flush(); mem.Position = 0; var memReader = new StreamReader(mem); var read = memReader.ReadToEnd(); Assert.AreEqual("[section]\n", read); } }
public void TestSectionComment() { using (var mem = new MemoryStream()) using (var streamWriter = new StreamWriter(mem)) using (var writer = new IniWriter(streamWriter, IniOptions.Default)) { writer.StartSection("section", "section"); writer.Write(); writer.Flush(); mem.Position = 0; var memReader = new StreamReader(mem); var read = memReader.ReadToEnd(); Assert.AreEqual("#section\n[section]\n", read); } }
public void TestPropertyComment() { using (var mem = new MemoryStream()) using (var streamWriter = new StreamWriter(mem)) using (var writer = new IniWriter(streamWriter, IniOptions.Default)) { writer.AddProperty("value", 10L, "property"); writer.Write(); writer.Flush(); mem.Position = 0; var memReader = new StreamReader(mem); var read = memReader.ReadToEnd(); Assert.AreEqual("#property\nvalue=10\n", read); } }
/// <summary> /// Write out DAT header using the supplied StreamWriter /// </summary> /// <param name="iw">IniWriter to output to</param> private void WriteHeader(IniWriter iw) { iw.WriteSection("CREDITS"); iw.WriteKeyValuePair("author", Header.Author); iw.WriteKeyValuePair("version", Header.Version); iw.WriteKeyValuePair("comment", Header.Comment); iw.WriteSection("DAT"); iw.WriteKeyValuePair("version", Header.RomCenterVersion ?? "2.50"); iw.WriteKeyValuePair("plugin", Header.System); iw.WriteKeyValuePair("split", Header.ForceMerging == MergingFlag.Split ? "1" : "0"); iw.WriteKeyValuePair("merge", Header.ForceMerging == MergingFlag.Full || Header.ForceMerging == MergingFlag.Merged ? "1" : "0"); iw.WriteSection("EMULATOR"); iw.WriteKeyValuePair("refname", Header.Name); iw.WriteKeyValuePair("version", Header.Description); iw.WriteSection("GAMES"); iw.Flush(); }
public void TestOptionTemplateUnix() { using (var reader = new IniReader("case-sensitivity.ini", IniOptions.Unix)) { Assert.Throws <ArgumentException>(() => reader.GetInt64("uppercase")); } using (var mem = new MemoryStream()) using (var streamWriter = new StreamWriter(mem)) using (var writer = new IniWriter(streamWriter, IniOptions.Unix)) { writer.StartSection("section"); writer.Write(); writer.Flush(); mem.Position = 0; var memReader = new StreamReader(mem); var read = memReader.ReadToEnd(); Assert.AreEqual("[section]\n", read); } }
public Result Save(string path, bool overwrite, bool compress) // compress is not implemented. { var returnResult = new Result("Compiling to \"{0}\"".Format2(path), false); logger.Info("Compiling to \"{0}\"".Format2(path)); try { switch (map.InterfaceOptions.CompileType) { case CompileType.Multiplayer: if (int.Parse(map.InterfaceOptions.CompileMultiPlayers) < 2 | int.Parse(map.InterfaceOptions.CompileMultiPlayers) > Constants.PlayerCountMax) { returnResult.ProblemAdd(string.Format("Number of players was below 2 or above {0}.", Constants.PlayerCountMax)); return(returnResult); } break; case CompileType.Campaign: break; default: returnResult.ProblemAdd("Unknown compile method."); return(returnResult); } if (!overwrite) { if (File.Exists(path)) { returnResult.ProblemAdd("The selected file already exists."); return(returnResult); } } if (map.InterfaceOptions.CompileType == CompileType.Multiplayer) { if (!overwrite) { if (File.Exists(path)) { returnResult.ProblemAdd(string.Format("A file already exists at: {0}", path)); return(returnResult); } } try { using (var zip = new ZipOutputStream(path)) { // Set encoding zip.AlternateEncoding = Encoding.GetEncoding("UTF-8"); zip.AlternateEncodingUsage = ZipOption.Always; // Set compression zip.CompressionLevel = CompressionLevel.BestCompression; // .xplayers.lev var zipPath = string.Format("{0}c-{1}.xplayers.lev", map.InterfaceOptions.CompileMultiPlayers, map.InterfaceOptions.CompileName); if (map.InterfaceOptions.CompileType == CompileType.Multiplayer) { zip.PutNextEntry(zipPath); returnResult.Add(Serialize_WZ_LEV(zip)); } var inZipPath = string.Format("multiplay/maps/{0}c-{1}", map.InterfaceOptions.CompileMultiPlayers, map.InterfaceOptions.CompileName); zip.PutNextEntry(string.Format("{0}.gam", inZipPath)); returnResult.Add(Serialize_WZ_Gam(zip, 0U, map.InterfaceOptions.CompileType, map.InterfaceOptions.ScrollMin, map.InterfaceOptions.ScrollMax)); zip.PutNextEntry(string.Format("{0}/struct.ini", inZipPath)); var iniStruct = new IniWriter(zip); returnResult.Add(Serialize_WZ_StructuresINI(iniStruct, int.Parse(map.InterfaceOptions.CompileMultiPlayers))); iniStruct.Flush(); zip.PutNextEntry(string.Format("{0}/droid.ini", inZipPath)); var iniDroid = new IniWriter(zip); returnResult.Add(Serialize_WZ_DroidsINI(iniDroid, int.Parse(map.InterfaceOptions.CompileMultiPlayers))); iniDroid.Flush(); zip.PutNextEntry(string.Format("{0}/labels.ini", inZipPath)); var iniLabels = new IniWriter(zip); returnResult.Add(Serialize_WZ_LabelsINI(iniLabels, int.Parse(map.InterfaceOptions.CompileMultiPlayers))); iniLabels.Flush(); zip.PutNextEntry(string.Format("{0}/feature.ini", inZipPath)); var iniFeature = new IniWriter(zip); returnResult.Add(Serialize_WZ_FeaturesINI(iniFeature)); iniFeature.Flush(); zip.PutNextEntry(string.Format("{0}/game.map", inZipPath)); returnResult.Add(Serialize_WZ_Map(zip)); zip.PutNextEntry(string.Format("{0}/ttypes.ttp", inZipPath)); var ttpSaver = new TTPSaver(map); returnResult.Add(ttpSaver.Save(zip)); } } catch (Exception ex) { Debugger.Break(); returnResult.ProblemAdd(ex.Message); logger.ErrorException("Got an exception", ex); return(returnResult); } return(returnResult); } if (map.InterfaceOptions.CompileType == CompileType.Campaign) { var CampDirectory = PathUtil.EndWithPathSeperator(path); if (!Directory.Exists(CampDirectory)) { returnResult.ProblemAdd(string.Format("Directory {0} does not exist.", CampDirectory)); return(returnResult); } var filePath = string.Format("{0}{1}.gam", CampDirectory, map.InterfaceOptions.CompileName); using (var file = File.Open(filePath, FileMode.Open | FileMode.CreateNew)) { returnResult.Add(Serialize_WZ_Gam(file, (UInt32)map.InterfaceOptions.CampaignGameType, map.InterfaceOptions.CompileType, map.InterfaceOptions.ScrollMin, map.InterfaceOptions.ScrollMax)); } CampDirectory += map.InterfaceOptions.CompileName + Convert.ToString(App.PlatformPathSeparator); try { Directory.CreateDirectory(CampDirectory); } catch (Exception ex) { returnResult.ProblemAdd(string.Format("Unable to create directory {0}", CampDirectory)); logger.ErrorException("Got an exception", ex); return(returnResult); } filePath = CampDirectory + "droid.ini"; using (var file = File.Open(filePath, FileMode.Open | FileMode.CreateNew)) { var iniDroid = new IniWriter(file); returnResult.Add(Serialize_WZ_DroidsINI(iniDroid, -1)); iniDroid.Flush(); } filePath = CampDirectory + "feature.ini"; using (var file = File.Open(filePath, FileMode.Open | FileMode.CreateNew)) { var iniFeatures = new IniWriter(file); returnResult.Add(Serialize_WZ_FeaturesINI(iniFeatures)); iniFeatures.Flush(); } filePath = CampDirectory + "game.map"; using (var file = File.Open(filePath, FileMode.Open | FileMode.CreateNew)) { returnResult.Add(Serialize_WZ_Map(file)); } filePath = CampDirectory + "struct.ini"; using (var file = File.Open(filePath, FileMode.Open | FileMode.CreateNew)) { var iniStruct = new IniWriter(file); returnResult.Add(Serialize_WZ_StructuresINI(iniStruct, -1)); iniStruct.Flush(); } filePath = CampDirectory + "ttypes.ttp"; var ttpSaver = new TTPSaver(map); returnResult.Add(ttpSaver.Save(filePath, false)); filePath = CampDirectory + "labels.ini"; using (var file = File.Open(filePath, FileMode.Open | FileMode.CreateNew)) { var iniLabels = new IniWriter(file); returnResult.Add(Serialize_WZ_LabelsINI(iniLabels, 0)); iniLabels.Flush(); } } } catch (Exception ex) { Debugger.Break(); returnResult.ProblemAdd(ex.Message); logger.ErrorException("Got an exception", ex); return(returnResult); } return(returnResult); }