public void DisposeStringWriterNullReference() { StringWriter writer = new StringWriter(); IniWriter iniWriter = new IniWriter(writer); iniWriter.WriteSection("Test"); iniWriter.Dispose(); }
/// <summary> /// Create and open an output file for writing direct from a dictionary /// </summary> /// <param name="outfile">Name of the file to write to</param> /// <param name="ignoreblanks">True if blank roms should be skipped on output, false otherwise (default)</param> /// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param> /// <returns>True if the DAT was written correctly, false otherwise</returns> public override bool WriteToFile(string outfile, bool ignoreblanks = false, bool throwOnError = false) { try { logger.User($"Opening file for writing: {outfile}"); FileStream fs = FileExtensions.TryCreate(outfile); // If we get back null for some reason, just log and return if (fs == null) { logger.Warning($"File '{outfile}' could not be created for writing! Please check to see if the file is writable"); return(false); } IniWriter iw = new IniWriter(fs, new UTF8Encoding(false)); // Write out the header WriteHeader(iw); // Write out each of the machines and roms string lastgame = null; List <string> splitpath = new List <string>(); // Use a sorted list of games to output foreach (string key in Items.SortedKeys) { List <DatItem> datItems = Items.FilteredItems(key); // If this machine doesn't contain any writable items, skip if (!ContainsWritable(datItems)) { continue; } // Resolve the names in the block datItems = DatItem.ResolveNames(datItems); for (int index = 0; index < datItems.Count; index++) { DatItem datItem = datItems[index]; // Check for a "null" item datItem = ProcessNullifiedItem(datItem); // Write out the item if we're not ignoring if (!ShouldIgnore(datItem, ignoreblanks)) { WriteDatItem(iw, datItem); } // Set the new data to compare against lastgame = datItem.Machine.Name; } } logger.Verbose("File written!" + Environment.NewLine); iw.Dispose(); fs.Dispose(); } catch (Exception ex) { logger.Error(ex); if (throwOnError) { throw ex; } return(false); } return(true); }