2021-12-28 03:21:18 +00:00
|
|
|
// /***************************************************************************
|
|
|
|
|
// Aaru Data Preservation Suite
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Filename : Retrode.cs
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
//
|
|
|
|
|
// Component : Dumping SNES/MD/GEN/MS/N64/GB/GB/GBA carts with a Retrode.
|
|
|
|
|
//
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Handles dumping using a Retrode.
|
|
|
|
|
//
|
|
|
|
|
// --[ License ] --------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
|
// it under the terms of the GNU General Public License as
|
|
|
|
|
// published by the Free Software Foundation, either version 3 of the
|
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
|
//
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
//
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
//
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2024-12-19 10:45:18 +00:00
|
|
|
// Copyright © 2011-2025 Natalia Portillo
|
2021-12-28 03:21:18 +00:00
|
|
|
// ****************************************************************************/
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using Aaru.CommonTypes;
|
|
|
|
|
using Aaru.CommonTypes.Enums;
|
|
|
|
|
using Aaru.CommonTypes.Interfaces;
|
2022-12-05 21:29:04 +00:00
|
|
|
using Aaru.Core.Graphics;
|
2025-08-19 15:17:19 +01:00
|
|
|
using Aaru.Logging;
|
2023-09-26 02:40:11 +01:00
|
|
|
using Humanizer;
|
|
|
|
|
using Humanizer.Bytes;
|
2023-09-26 03:39:10 +01:00
|
|
|
using Humanizer.Localisation;
|
2021-12-28 03:21:18 +00:00
|
|
|
using Version = Aaru.CommonTypes.Interop.Version;
|
|
|
|
|
|
2022-11-15 15:58:43 +00:00
|
|
|
namespace Aaru.Core.Devices.Dumping;
|
|
|
|
|
|
2021-12-28 03:21:18 +00:00
|
|
|
public partial class Dump
|
|
|
|
|
{
|
2023-09-29 18:27:27 +01:00
|
|
|
static readonly byte[] _sfcExtension = "SFC"u8.ToArray();
|
|
|
|
|
static readonly byte[] _genesisExtension = "BIN"u8.ToArray();
|
|
|
|
|
static readonly byte[] _smsExtension = "SMS"u8.ToArray();
|
|
|
|
|
static readonly byte[] _z64Extension = "Z64"u8.ToArray();
|
|
|
|
|
static readonly byte[] _gbExtension = "GB "u8.ToArray();
|
|
|
|
|
static readonly byte[] _gbcExtension = "GBC"u8.ToArray();
|
|
|
|
|
static readonly byte[] _gbaExtension = "GBA"u8.ToArray();
|
2021-12-28 03:45:51 +00:00
|
|
|
|
2021-12-28 03:30:34 +00:00
|
|
|
/// <summary>Dumps a game cartridge using a Retrode adapter</summary>
|
2021-12-28 03:21:18 +00:00
|
|
|
void Retrode()
|
|
|
|
|
{
|
2024-05-01 04:05:22 +01:00
|
|
|
bool sense = _dev.Read10(out byte[] buffer,
|
|
|
|
|
out _,
|
|
|
|
|
0,
|
|
|
|
|
false,
|
|
|
|
|
true,
|
|
|
|
|
false,
|
|
|
|
|
false,
|
|
|
|
|
0,
|
|
|
|
|
512,
|
|
|
|
|
0,
|
|
|
|
|
1,
|
|
|
|
|
_dev.Timeout,
|
2021-12-28 03:21:18 +00:00
|
|
|
out _);
|
|
|
|
|
|
|
|
|
|
if(sense)
|
|
|
|
|
{
|
2022-11-23 16:06:46 +00:00
|
|
|
StoppingErrorMessage?.Invoke(Localization.Core.Could_not_read);
|
2021-12-28 03:21:18 +00:00
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-19 15:17:19 +01:00
|
|
|
byte[] tmp = new byte[8];
|
2021-12-28 03:21:18 +00:00
|
|
|
|
|
|
|
|
Array.Copy(buffer, 0x36, tmp, 0, 8);
|
|
|
|
|
|
|
|
|
|
// UMDs are stored inside a FAT16 volume
|
|
|
|
|
if(!tmp.SequenceEqual(_fatSignature))
|
|
|
|
|
{
|
2022-11-23 16:06:46 +00:00
|
|
|
StoppingErrorMessage?.Invoke(Localization.Core.Retrode_partition_not_recognized_not_dumping);
|
2021-12-28 03:21:18 +00:00
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-19 15:17:19 +01:00
|
|
|
ushort fatStart = (ushort)((buffer[0x0F] << 8) + buffer[0x0E]);
|
|
|
|
|
ushort sectorsPerFat = (ushort)((buffer[0x17] << 8) + buffer[0x16]);
|
|
|
|
|
ushort rootStart = (ushort)(sectorsPerFat * 2 + fatStart);
|
|
|
|
|
ushort rootSize = (ushort)(((buffer[0x12] << 8) + buffer[0x11]) * 32 / 512);
|
|
|
|
|
byte sectorsPerCluster = buffer[0x0D];
|
2021-12-28 03:21:18 +00:00
|
|
|
|
2022-11-23 16:06:46 +00:00
|
|
|
UpdateStatus?.Invoke(string.Format(Localization.Core.Reading_root_directory_in_sector_0, rootStart));
|
2021-12-28 03:21:18 +00:00
|
|
|
|
|
|
|
|
sense = _dev.Read10(out buffer, out _, 0, false, true, false, false, rootStart, 512, 0, 1, _dev.Timeout, out _);
|
|
|
|
|
|
|
|
|
|
if(sense)
|
|
|
|
|
{
|
2022-11-23 16:06:46 +00:00
|
|
|
StoppingErrorMessage?.Invoke(Localization.Core.Could_not_read);
|
2021-12-28 03:21:18 +00:00
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-19 15:17:19 +01:00
|
|
|
int romPos;
|
|
|
|
|
bool sfcFound = false;
|
|
|
|
|
bool genesisFound = false;
|
|
|
|
|
bool smsFound = false;
|
|
|
|
|
bool n64Found = false;
|
|
|
|
|
bool gbFound = false;
|
|
|
|
|
bool gbcFound = false;
|
|
|
|
|
bool gbaFound = false;
|
2021-12-28 03:21:18 +00:00
|
|
|
tmp = new byte[3];
|
|
|
|
|
|
|
|
|
|
for(romPos = 0; romPos < buffer.Length; romPos += 0x20)
|
|
|
|
|
{
|
|
|
|
|
Array.Copy(buffer, romPos + 8, tmp, 0, 3);
|
|
|
|
|
|
2021-12-28 03:30:34 +00:00
|
|
|
if(tmp.SequenceEqual(_sfcExtension))
|
|
|
|
|
{
|
|
|
|
|
sfcFound = true;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
2021-12-28 03:21:18 +00:00
|
|
|
|
2021-12-28 03:30:34 +00:00
|
|
|
if(tmp.SequenceEqual(_genesisExtension))
|
|
|
|
|
{
|
|
|
|
|
genesisFound = true;
|
2021-12-28 03:21:18 +00:00
|
|
|
|
2021-12-28 03:30:34 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2021-12-28 03:36:13 +00:00
|
|
|
|
|
|
|
|
if(tmp.SequenceEqual(_smsExtension))
|
|
|
|
|
{
|
|
|
|
|
smsFound = true;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
2021-12-28 03:42:32 +00:00
|
|
|
|
|
|
|
|
if(tmp.SequenceEqual(_z64Extension))
|
|
|
|
|
{
|
|
|
|
|
n64Found = true;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
2021-12-28 03:45:51 +00:00
|
|
|
|
|
|
|
|
if(tmp.SequenceEqual(_gbExtension))
|
|
|
|
|
{
|
|
|
|
|
gbFound = true;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(tmp.SequenceEqual(_gbcExtension))
|
|
|
|
|
{
|
|
|
|
|
gbcFound = true;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
if(!tmp.SequenceEqual(_gbaExtension)) continue;
|
2021-12-28 03:45:51 +00:00
|
|
|
|
2022-11-13 21:14:18 +00:00
|
|
|
gbaFound = true;
|
|
|
|
|
|
|
|
|
|
break;
|
2021-12-28 03:21:18 +00:00
|
|
|
}
|
|
|
|
|
|
2023-10-05 01:56:40 +01:00
|
|
|
if(!sfcFound && !genesisFound && !smsFound && !n64Found && !gbaFound && !gbFound && !gbcFound)
|
2021-12-28 03:21:18 +00:00
|
|
|
{
|
2022-11-23 16:06:46 +00:00
|
|
|
StoppingErrorMessage?.Invoke(Localization.Core.No_cartridge_found_not_dumping);
|
2021-12-28 03:21:18 +00:00
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-19 15:17:19 +01:00
|
|
|
ushort cluster = BitConverter.ToUInt16(buffer, romPos + 0x1A);
|
|
|
|
|
uint romSize = BitConverter.ToUInt32(buffer, romPos + 0x1C);
|
2021-12-28 03:21:18 +00:00
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
MediaType mediaType = gbaFound
|
|
|
|
|
? MediaType.GameBoyAdvanceGamePak
|
|
|
|
|
: gbFound || gbcFound
|
|
|
|
|
? MediaType.GameBoyGamePak
|
|
|
|
|
: n64Found
|
|
|
|
|
? MediaType.N64GamePak
|
|
|
|
|
: smsFound
|
|
|
|
|
? MediaType.MasterSystemCartridge
|
|
|
|
|
: genesisFound
|
|
|
|
|
? MediaType.MegaDriveCartridge
|
|
|
|
|
: MediaType.SNESGamePak;
|
2021-12-28 03:36:13 +00:00
|
|
|
|
2025-08-22 19:57:09 +01:00
|
|
|
uint blocksToRead = 64;
|
|
|
|
|
double totalDuration = 0;
|
|
|
|
|
double currentSpeed = 0;
|
|
|
|
|
double maxSpeed = double.MinValue;
|
|
|
|
|
double minSpeed = double.MaxValue;
|
|
|
|
|
ReadOnlySpan<byte> senseBuf;
|
2021-12-28 03:21:18 +00:00
|
|
|
|
2023-10-04 17:34:40 +01:00
|
|
|
if(_outputPlugin is not IByteAddressableImage outputBai || !outputBai.SupportedMediaTypes.Contains(mediaType))
|
2021-12-28 03:21:18 +00:00
|
|
|
{
|
2024-05-01 04:05:22 +01:00
|
|
|
StoppingErrorMessage?.Invoke(Localization.Core
|
|
|
|
|
.The_specified_format_does_not_support_the_inserted_cartridge);
|
2021-12-28 03:21:18 +00:00
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
sense = _dev.Read10(out byte[] readBuffer,
|
|
|
|
|
out _,
|
|
|
|
|
0,
|
|
|
|
|
false,
|
|
|
|
|
true,
|
|
|
|
|
false,
|
|
|
|
|
false,
|
|
|
|
|
0,
|
|
|
|
|
512,
|
|
|
|
|
0,
|
|
|
|
|
1,
|
|
|
|
|
_dev.Timeout,
|
2021-12-28 03:21:18 +00:00
|
|
|
out _);
|
|
|
|
|
|
|
|
|
|
if(sense)
|
|
|
|
|
{
|
2022-11-23 16:06:46 +00:00
|
|
|
StoppingErrorMessage?.Invoke(Localization.Core.Could_not_read);
|
2021-12-28 03:21:18 +00:00
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-19 15:17:19 +01:00
|
|
|
uint startSector = (uint)(rootStart + rootSize + (cluster - 2) * sectorsPerCluster);
|
2021-12-28 03:21:18 +00:00
|
|
|
uint romSectors = romSize / 512;
|
|
|
|
|
uint romRemaining = romSize % 512;
|
|
|
|
|
|
2025-08-22 19:57:09 +01:00
|
|
|
UpdateStatus?.Invoke(string.Format(Localization.Core.Cartridge_has_0_bytes_1,
|
|
|
|
|
romSize,
|
2025-08-20 00:24:20 +01:00
|
|
|
ByteSize.FromBytes(romSize).ToString("0.000")));
|
2021-12-28 03:21:18 +00:00
|
|
|
|
2025-08-23 00:13:52 +01:00
|
|
|
UpdateStatus?.Invoke(string.Format(Localization.Core.Media_identified_as_0, mediaType.Humanize()));
|
2021-12-28 03:21:18 +00:00
|
|
|
|
|
|
|
|
ErrorNumber ret = outputBai.Create(_outputPath, mediaType, _formatOptions, romSize);
|
|
|
|
|
|
|
|
|
|
// Cannot create image
|
|
|
|
|
if(ret != ErrorNumber.NoError)
|
|
|
|
|
{
|
2022-11-23 16:06:46 +00:00
|
|
|
StoppingErrorMessage?.Invoke(Localization.Core.Error_creating_output_image_not_continuing +
|
2023-10-04 17:34:40 +01:00
|
|
|
Environment.NewLine +
|
|
|
|
|
outputBai.ErrorMessage);
|
2021-12-28 03:21:18 +00:00
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
if(_createGraph) _mediaGraph = new BlockMap((int)_dimensions, (int)_dimensions, romSectors);
|
2022-12-05 21:29:04 +00:00
|
|
|
|
2023-09-26 20:16:24 +01:00
|
|
|
_dumpStopwatch.Restart();
|
2023-10-03 22:57:50 +01:00
|
|
|
double imageWriteDuration = 0;
|
2021-12-28 03:21:18 +00:00
|
|
|
|
2023-09-26 20:16:24 +01:00
|
|
|
_speedStopwatch.Restart();
|
2023-10-03 22:57:50 +01:00
|
|
|
ulong sectorSpeedStart = 0;
|
2021-12-28 03:21:18 +00:00
|
|
|
InitProgress?.Invoke();
|
|
|
|
|
|
|
|
|
|
for(ulong i = 0; i < romSectors; i += blocksToRead)
|
|
|
|
|
{
|
|
|
|
|
if(_aborted)
|
|
|
|
|
{
|
2022-11-23 16:06:46 +00:00
|
|
|
UpdateStatus?.Invoke(Localization.Core.Aborted);
|
2021-12-28 03:21:18 +00:00
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
if(romSectors - i < blocksToRead) blocksToRead = (uint)(romSectors - i);
|
2021-12-28 03:21:18 +00:00
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
if(currentSpeed > maxSpeed && currentSpeed > 0) maxSpeed = currentSpeed;
|
2021-12-28 03:21:18 +00:00
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
if(currentSpeed < minSpeed && currentSpeed > 0) minSpeed = currentSpeed;
|
2021-12-28 03:21:18 +00:00
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
UpdateProgress?.Invoke(string.Format(Localization.Core.Reading_byte_0_of_1_2,
|
|
|
|
|
i * 512,
|
|
|
|
|
romSize,
|
|
|
|
|
ByteSize.FromMegabytes(currentSpeed).Per(_oneSecond).Humanize()),
|
|
|
|
|
(long)i * 512,
|
|
|
|
|
romSize);
|
2021-12-28 03:21:18 +00:00
|
|
|
|
2024-04-26 03:16:36 +01:00
|
|
|
_speedStopwatch.Start();
|
2024-05-01 04:05:22 +01:00
|
|
|
|
|
|
|
|
sense = _dev.Read10(out readBuffer,
|
|
|
|
|
out senseBuf,
|
|
|
|
|
0,
|
|
|
|
|
false,
|
|
|
|
|
true,
|
|
|
|
|
false,
|
|
|
|
|
false,
|
|
|
|
|
(uint)(startSector + i),
|
|
|
|
|
512,
|
|
|
|
|
0,
|
|
|
|
|
(ushort)blocksToRead,
|
|
|
|
|
_dev.Timeout,
|
|
|
|
|
out double cmdDuration);
|
|
|
|
|
|
2024-04-26 03:16:36 +01:00
|
|
|
_speedStopwatch.Stop();
|
2021-12-28 03:21:18 +00:00
|
|
|
totalDuration += cmdDuration;
|
|
|
|
|
|
2023-09-26 20:16:24 +01:00
|
|
|
_writeStopwatch.Restart();
|
|
|
|
|
|
2023-10-04 17:34:40 +01:00
|
|
|
if(!sense && !_dev.Error)
|
2021-12-28 03:21:18 +00:00
|
|
|
{
|
|
|
|
|
outputBai.WriteBytes(readBuffer, 0, readBuffer.Length, out _);
|
2023-09-26 20:16:24 +01:00
|
|
|
imageWriteDuration += _writeStopwatch.Elapsed.TotalSeconds;
|
2022-12-05 21:29:04 +00:00
|
|
|
_mediaGraph.PaintSectorsGood(i, blocksToRead);
|
2021-12-28 03:21:18 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_errorLog?.WriteLine(i, _dev.Error, _dev.LastError, senseBuf);
|
|
|
|
|
|
|
|
|
|
// TODO: Reset device after X errors
|
2024-05-01 04:05:22 +01:00
|
|
|
if(_stopOnError) return; // TODO: Return more cleanly
|
2021-12-28 03:21:18 +00:00
|
|
|
|
2025-08-19 15:17:19 +01:00
|
|
|
AaruLogging.WriteLine(Localization.Core.Skipping_0_bytes_from_errored_byte_1, _skip * 512, i * 512);
|
2021-12-28 03:21:18 +00:00
|
|
|
i += _skip - blocksToRead;
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-26 20:16:24 +01:00
|
|
|
_writeStopwatch.Stop();
|
|
|
|
|
|
2021-12-28 03:21:18 +00:00
|
|
|
sectorSpeedStart += blocksToRead;
|
|
|
|
|
|
2023-09-26 20:16:24 +01:00
|
|
|
double elapsed = _speedStopwatch.Elapsed.TotalSeconds;
|
2021-12-28 03:21:18 +00:00
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
if(elapsed <= 0 || sectorSpeedStart * 512 < 524288) continue;
|
2021-12-28 03:21:18 +00:00
|
|
|
|
|
|
|
|
currentSpeed = sectorSpeedStart * 512 / (1048576 * elapsed);
|
|
|
|
|
sectorSpeedStart = 0;
|
2024-04-26 03:16:36 +01:00
|
|
|
_speedStopwatch.Reset();
|
2021-12-28 03:21:18 +00:00
|
|
|
}
|
|
|
|
|
|
2023-09-26 20:16:24 +01:00
|
|
|
_speedStopwatch.Stop();
|
|
|
|
|
|
2023-10-04 17:34:40 +01:00
|
|
|
if(romRemaining > 0 && !_aborted)
|
2021-12-28 03:21:18 +00:00
|
|
|
{
|
2024-05-01 04:05:22 +01:00
|
|
|
if(currentSpeed > maxSpeed && currentSpeed > 0) maxSpeed = currentSpeed;
|
|
|
|
|
|
|
|
|
|
if(currentSpeed < minSpeed && currentSpeed > 0) minSpeed = currentSpeed;
|
|
|
|
|
|
|
|
|
|
UpdateProgress?.Invoke(string.Format(Localization.Core.Reading_byte_0_of_1_2,
|
|
|
|
|
romSectors * 512,
|
|
|
|
|
romSize,
|
|
|
|
|
ByteSize.FromMegabytes(currentSpeed).Per(_oneSecond).Humanize()),
|
|
|
|
|
(long)romSectors * 512,
|
|
|
|
|
romSize);
|
|
|
|
|
|
|
|
|
|
sense = _dev.Read10(out readBuffer,
|
|
|
|
|
out senseBuf,
|
|
|
|
|
0,
|
|
|
|
|
false,
|
|
|
|
|
true,
|
|
|
|
|
false,
|
|
|
|
|
false,
|
|
|
|
|
romSectors,
|
|
|
|
|
512,
|
|
|
|
|
0,
|
|
|
|
|
1,
|
|
|
|
|
_dev.Timeout,
|
|
|
|
|
out double cmdDuration);
|
2021-12-28 03:21:18 +00:00
|
|
|
|
|
|
|
|
totalDuration += cmdDuration;
|
|
|
|
|
|
2023-10-04 17:34:40 +01:00
|
|
|
if(!sense && !_dev.Error)
|
2021-12-28 03:21:18 +00:00
|
|
|
{
|
2023-09-26 20:16:24 +01:00
|
|
|
_writeStopwatch.Restart();
|
2021-12-28 03:21:18 +00:00
|
|
|
outputBai.WriteBytes(readBuffer, 0, (int)romRemaining, out _);
|
2023-09-26 20:16:24 +01:00
|
|
|
imageWriteDuration += _writeStopwatch.Elapsed.TotalSeconds;
|
|
|
|
|
_writeStopwatch.Stop();
|
2021-12-28 03:21:18 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_errorLog?.WriteLine(romSectors, _dev.Error, _dev.LastError, senseBuf);
|
|
|
|
|
|
|
|
|
|
// TODO: Reset device after X errors
|
2024-05-01 04:05:22 +01:00
|
|
|
if(_stopOnError) return; // TODO: Return more cleanly
|
2021-12-28 03:21:18 +00:00
|
|
|
|
2025-08-19 15:17:19 +01:00
|
|
|
AaruLogging.WriteLine(Localization.Core.Skipping_0_bytes_from_errored_byte_1,
|
|
|
|
|
_skip * 512,
|
|
|
|
|
romSectors * 512);
|
2021-12-28 03:21:18 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EndProgress?.Invoke();
|
|
|
|
|
|
2023-09-26 20:16:24 +01:00
|
|
|
UpdateStatus?.Invoke(string.Format(Localization.Core.Dump_finished_in_0,
|
|
|
|
|
_dumpStopwatch.Elapsed.Humanize(minUnit: TimeUnit.Second)));
|
2021-12-28 03:21:18 +00:00
|
|
|
|
2023-09-26 02:40:11 +01:00
|
|
|
UpdateStatus?.Invoke(string.Format(Localization.Core.Average_dump_speed_0,
|
2024-05-01 04:05:22 +01:00
|
|
|
ByteSize.FromBytes(512 * (romSectors + 1))
|
|
|
|
|
.Per(totalDuration.Milliseconds())
|
|
|
|
|
.Humanize()));
|
2021-12-28 03:21:18 +00:00
|
|
|
|
2023-09-26 02:40:11 +01:00
|
|
|
UpdateStatus?.Invoke(string.Format(Localization.Core.Average_write_speed_0,
|
2024-05-01 04:05:22 +01:00
|
|
|
ByteSize.FromBytes(512 * (romSectors + 1))
|
|
|
|
|
.Per(imageWriteDuration.Seconds())
|
|
|
|
|
.Humanize()));
|
2021-12-28 03:21:18 +00:00
|
|
|
|
2022-11-15 15:58:43 +00:00
|
|
|
var metadata = new CommonTypes.Structs.ImageInfo
|
2021-12-28 03:21:18 +00:00
|
|
|
{
|
|
|
|
|
Application = "Aaru",
|
|
|
|
|
ApplicationVersion = Version.GetVersion()
|
|
|
|
|
};
|
|
|
|
|
|
2022-12-15 22:21:07 +00:00
|
|
|
if(!outputBai.SetImageInfo(metadata))
|
2023-10-03 22:57:50 +01:00
|
|
|
{
|
2023-10-04 17:34:40 +01:00
|
|
|
ErrorMessage?.Invoke(Localization.Core.Error_0_setting_metadata +
|
|
|
|
|
Environment.NewLine +
|
2021-12-28 03:21:18 +00:00
|
|
|
outputBai.ErrorMessage);
|
2023-10-03 22:57:50 +01:00
|
|
|
}
|
2021-12-28 03:21:18 +00:00
|
|
|
|
|
|
|
|
// TODO: Set dump hardware
|
|
|
|
|
//outputBAI.SetDumpHardware();
|
|
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
if(_preSidecar != null) outputBai.SetMetadata(_preSidecar);
|
2021-12-28 03:21:18 +00:00
|
|
|
|
2022-11-23 16:06:46 +00:00
|
|
|
UpdateStatus?.Invoke(Localization.Core.Closing_output_file);
|
2023-09-26 20:16:24 +01:00
|
|
|
_imageCloseStopwatch.Restart();
|
2021-12-28 03:21:18 +00:00
|
|
|
outputBai.Close();
|
2023-09-26 20:16:24 +01:00
|
|
|
_imageCloseStopwatch.Stop();
|
|
|
|
|
|
2025-08-19 15:17:19 +01:00
|
|
|
AaruLogging.WriteLine(Localization.Core.Closed_in_0,
|
|
|
|
|
_imageCloseStopwatch.Elapsed.Humanize(minUnit: TimeUnit.Second));
|
2021-12-28 03:21:18 +00:00
|
|
|
|
|
|
|
|
if(_aborted)
|
|
|
|
|
{
|
2022-11-23 16:06:46 +00:00
|
|
|
UpdateStatus?.Invoke(Localization.Core.Aborted);
|
2021-12-28 03:21:18 +00:00
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double totalChkDuration = 0;
|
|
|
|
|
|
|
|
|
|
/* TODO: Create sidecar
|
|
|
|
|
if(_metadata)
|
|
|
|
|
WriteOpticalSidecar(blockSize, blocks, mediaType, null, null, 1, out totalChkDuration, null);
|
|
|
|
|
*/
|
|
|
|
|
UpdateStatus?.Invoke("");
|
|
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
UpdateStatus?.Invoke(string.Format(Localization.Core
|
|
|
|
|
.Took_a_total_of_0_1_processing_commands_2_checksumming_3_writing_4_closing,
|
|
|
|
|
_dumpStopwatch.Elapsed.Humanize(minUnit: TimeUnit.Second),
|
|
|
|
|
totalDuration.Milliseconds().Humanize(minUnit: TimeUnit.Second),
|
|
|
|
|
totalChkDuration.Milliseconds().Humanize(minUnit: TimeUnit.Second),
|
|
|
|
|
imageWriteDuration.Seconds().Humanize(minUnit: TimeUnit.Second),
|
|
|
|
|
_imageCloseStopwatch.Elapsed.Humanize(minUnit: TimeUnit.Second)));
|
2021-12-28 03:21:18 +00:00
|
|
|
|
2023-09-26 02:40:11 +01:00
|
|
|
UpdateStatus?.Invoke(string.Format(Localization.Core.Average_speed_0,
|
2024-05-01 04:05:22 +01:00
|
|
|
ByteSize.FromBytes(512 * (romSectors + 1))
|
|
|
|
|
.Per(totalDuration.Milliseconds())
|
|
|
|
|
.Humanize()));
|
2021-12-28 03:21:18 +00:00
|
|
|
|
|
|
|
|
if(maxSpeed > 0)
|
2023-10-03 22:57:50 +01:00
|
|
|
{
|
2023-09-26 10:51:43 +01:00
|
|
|
UpdateStatus?.Invoke(string.Format(Localization.Core.Fastest_speed_burst_0,
|
|
|
|
|
ByteSize.FromMegabytes(maxSpeed).Per(_oneSecond).Humanize()));
|
2023-10-03 22:57:50 +01:00
|
|
|
}
|
2021-12-28 03:21:18 +00:00
|
|
|
|
|
|
|
|
if(minSpeed is > 0 and < double.MaxValue)
|
2023-10-03 22:57:50 +01:00
|
|
|
{
|
2023-09-26 02:40:11 +01:00
|
|
|
UpdateStatus?.Invoke(string.Format(Localization.Core.Slowest_speed_burst_0,
|
2023-09-26 10:51:43 +01:00
|
|
|
ByteSize.FromMegabytes(minSpeed).Per(_oneSecond).Humanize()));
|
2023-10-03 22:57:50 +01:00
|
|
|
}
|
2021-12-28 03:21:18 +00:00
|
|
|
|
|
|
|
|
UpdateStatus?.Invoke("");
|
|
|
|
|
|
|
|
|
|
Statistics.AddMedia(mediaType, true);
|
|
|
|
|
}
|
|
|
|
|
}
|