예제 #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));
        }
예제 #2
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>
        /// <param name="cancellationToken">The cancellation token.</param>
        public static async ValueTask <IRomData> ConvertToAsync(this IRomData data, ERomFormat format, CancellationToken cancellationToken = default)
        {
            Guard.IsNotNull(data, nameof(data));

            byte[] copy = new byte[data.Length];
            var    src  = await data.GetDataAsync();

            src.CopyTo(copy);

            ConvertTo(format, copy);

            return(await RomData.LoadRomAsync(copy, cancellationToken));
        }
예제 #3
0
            static async ValueTask <EInputBlockResult> ConvertAsync(IRomData data, ERomFormat format)
            {
                FileInfo output;

                EraseLine();
                if (data.Header.Format == format)
                {
                    Console.WriteLine();
                    Console.WriteLine("The ROM data is already in the correct format.");
                    if (data is not RomFile)
                    {
                        output = new FileInfo(data.GetFilename());
                        await data.SaveAsync(output);

                        Console.WriteLine($"File saved to {output.FullName}");
                    }

                    // If it is a RomFile, the file already exists. Do nothing.
                    return(EInputBlockResult.Success);
                }

                output = data is RomFile rf
                    ? rf.File.WithExtension(RomHeader.GetFormatExtension(format))
                    : new FileInfo(data.GetFilename());

                var converted = await data.ConvertToAsync(format);

                if (await PromptOverwriteIfExistsAsync(output) != EInputBlockResult.Success)
                {
                    return(EInputBlockResult.Failed);
                }

                await converted.SaveAsync(output);

                Console.WriteLine($"File saved to {output.FullName}");
                return(EInputBlockResult.Success);