Exemplo n.º 1
0
        /// <summary>
        /// Converts the content in <paramref name="data"/> to the format
        /// specified in <paramref name="format"/>.
        /// </summary>
        /// <remarks>
        /// This method will make a copy of the data even if the format is not
        /// changed.
        /// </remarks>
        /// <param name="data">The data to convert to.</param>
        /// <param name="format">The format to convert.</param>
        public static IRomData ConvertTo(this IRomData data, ERomFormat format)
        {
            Guard.IsNotNull(data, nameof(data));

            byte[] copy = new byte[data.Length];
            data.GetData().CopyTo(copy);

            ConvertTo(format, copy);

            return(RomData.LoadRom(copy));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Saves <paramref name="romData"/> to disk.
        /// </summary>
        /// <param name="romData">The data to save.</param>
        /// <param name="file">The output file.</param>
        public static void Save(this IRomData romData, FileInfo file)
        {
            Guard.IsNotNull(romData, nameof(romData));
            Guard.IsNotNull(file, nameof(file));

            if (file.Directory?.Exists == false)
            {
                file.Directory.Create();
            }

            using var fs = file.Open(FileMode.Create, FileAccess.Write, FileShare.None);
            fs.Write(romData.GetData().Span);
            fs.Flush();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Saves <paramref name="romData"/> to disk, using the metadata of the ROM
        /// to generate the output file name.
        /// </summary>
        /// <param name="romData">The data to save.</param>
        /// <param name="outputDirectory">The output directory.</param>
        public static void Save(this IRomData romData, DirectoryInfo outputDirectory)
        {
            Guard.IsNotNull(romData, nameof(romData));
            Guard.IsNotNull(outputDirectory, nameof(outputDirectory));

            if (!outputDirectory.Exists)
            {
                outputDirectory.Create();
            }

            string fileName = romData.GetFilename();
            var    file     = new FileInfo(Path.Combine(outputDirectory.FullName, fileName));

            using var fs = file.Open(FileMode.Create, FileAccess.Write, FileShare.None);
            fs.Write(romData.GetData().Span);
            fs.Flush();
        }