2020-04-17 21:45:50 +01:00
// /***************************************************************************
// Aaru Data Preservation Suite
// ----------------------------------------------------------------------------
//
// Filename : ImageConvertViewModel.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// Component : GUI view models.
//
// --[ Description ] ----------------------------------------------------------
//
// View model and code for the image conversion window.
//
// --[ 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/>.
//
// ----------------------------------------------------------------------------
2022-02-18 10:02:53 +00:00
// Copyright © 2011-2022 Natalia Portillo
2020-04-17 21:45:50 +01:00
// ****************************************************************************/
2022-03-07 07:36:44 +00:00
namespace Aaru.Gui.ViewModels.Windows ;
2020-04-13 04:40:35 +01:00
using System ;
using System.Collections.Generic ;
using System.Collections.ObjectModel ;
using System.IO ;
using System.Linq ;
using System.Reactive ;
2020-07-14 02:16:53 +01:00
using System.Text ;
2020-04-13 04:40:35 +01:00
using System.Threading ;
using System.Xml.Serialization ;
using Aaru.CommonTypes ;
using Aaru.CommonTypes.Enums ;
using Aaru.CommonTypes.Interfaces ;
using Aaru.CommonTypes.Metadata ;
using Aaru.CommonTypes.Structs ;
using Aaru.Console ;
using Aaru.Core ;
2020-07-14 02:16:53 +01:00
using Aaru.Core.Media ;
using Aaru.Devices ;
2020-04-13 04:40:35 +01:00
using Aaru.Gui.Models ;
using Avalonia.Controls ;
using Avalonia.Threading ;
2020-07-22 13:20:25 +01:00
using JetBrains.Annotations ;
2020-04-13 04:40:35 +01:00
using MessageBox.Avalonia ;
using MessageBox.Avalonia.Enums ;
using ReactiveUI ;
using Schemas ;
using ImageInfo = Aaru . CommonTypes . Structs . ImageInfo ;
using Version = Aaru . CommonTypes . Interop . Version ;
2022-03-06 13:29:38 +00:00
public sealed class ImageConvertViewModel : ViewModelBase
2020-04-13 04:40:35 +01:00
{
2022-03-06 13:29:38 +00:00
readonly IMediaImage _inputFormat ;
readonly Window _view ;
bool _cancel ;
CICMMetadataType _cicmMetadata ;
bool _cicmXmlFromImageVisible ;
string _cicmXmlText ;
bool _closeVisible ;
string _commentsText ;
bool _commentsVisible ;
string _creatorText ;
bool _creatorVisible ;
bool _destinationEnabled ;
string _destinationText ;
bool _destinationVisible ;
string _driveFirmwareRevisionText ;
bool _driveFirmwareRevisionVisible ;
string _driveManufacturerText ;
bool _driveManufacturerVisible ;
string _driveModelText ;
bool _driveModelVisible ;
string _driveSerialNumberText ;
bool _driveSerialNumberVisible ;
List < DumpHardwareType > _dumpHardware ;
bool _forceChecked ;
bool _formatReadOnly ;
double _lastMediaSequenceValue ;
bool _lastMediaSequenceVisible ;
string _mediaBarcodeText ;
bool _mediaBarcodeVisible ;
string _mediaManufacturerText ;
bool _mediaManufacturerVisible ;
string _mediaModelText ;
bool _mediaModelVisible ;
string _mediaPartNumberText ;
bool _mediaPartNumberVisible ;
double _mediaSequenceValue ;
bool _mediaSequenceVisible ;
string _mediaSerialNumberText ;
bool _mediaSerialNumberVisible ;
string _mediaTitleText ;
bool _mediaTitleVisible ;
bool _optionsVisible ;
bool _progress1Visible ;
bool _progress2Indeterminate ;
double _progress2MaxValue ;
string _progress2Text ;
double _progress2Value ;
bool _progress2Visible ;
bool _progressIndeterminate ;
double _progressMaxValue ;
string _progressText ;
double _progressValue ;
bool _progressVisible ;
bool _resumeFileFromImageVisible ;
string _resumeFileText ;
double _sectorsValue ;
ImagePluginModel _selectedPlugin ;
string _sourceText ;
bool _startVisible ;
bool _stopEnabled ;
bool _stopVisible ;
string _title ;
public ImageConvertViewModel ( [ NotNull ] IMediaImage inputFormat , string imageSource , Window view )
{
_view = view ;
_inputFormat = inputFormat ;
_cancel = false ;
DestinationCommand = ReactiveCommand . Create ( ExecuteDestinationCommand ) ;
CreatorCommand = ReactiveCommand . Create ( ExecuteCreatorCommand ) ;
MediaTitleCommand = ReactiveCommand . Create ( ExecuteMediaTitleCommand ) ;
MediaManufacturerCommand = ReactiveCommand . Create ( ExecuteMediaManufacturerCommand ) ;
MediaModelCommand = ReactiveCommand . Create ( ExecuteMediaModelCommand ) ;
MediaSerialNumberCommand = ReactiveCommand . Create ( ExecuteMediaSerialNumberCommand ) ;
MediaBarcodeCommand = ReactiveCommand . Create ( ExecuteMediaBarcodeCommand ) ;
MediaPartNumberCommand = ReactiveCommand . Create ( ExecuteMediaPartNumberCommand ) ;
MediaSequenceCommand = ReactiveCommand . Create ( ExecuteMediaSequenceCommand ) ;
LastMediaSequenceCommand = ReactiveCommand . Create ( ExecuteLastMediaSequenceCommand ) ;
DriveManufacturerCommand = ReactiveCommand . Create ( ExecuteDriveManufacturerCommand ) ;
DriveModelCommand = ReactiveCommand . Create ( ExecuteDriveModelCommand ) ;
DriveSerialNumberCommand = ReactiveCommand . Create ( ExecuteDriveSerialNumberCommand ) ;
DriveFirmwareRevisionCommand = ReactiveCommand . Create ( ExecuteDriveFirmwareRevisionCommand ) ;
CommentsCommand = ReactiveCommand . Create ( ExecuteCommentsCommand ) ;
CicmXmlFromImageCommand = ReactiveCommand . Create ( ExecuteCicmXmlFromImageCommand ) ;
CicmXmlCommand = ReactiveCommand . Create ( ExecuteCicmXmlCommand ) ;
ResumeFileFromImageCommand = ReactiveCommand . Create ( ExecuteResumeFileFromImageCommand ) ;
ResumeFileCommand = ReactiveCommand . Create ( ExecuteResumeFileCommand ) ;
StartCommand = ReactiveCommand . Create ( ExecuteStartCommand ) ;
CloseCommand = ReactiveCommand . Create ( ExecuteCloseCommand ) ;
StopCommand = ReactiveCommand . Create ( ExecuteStopCommand ) ;
SourceText = imageSource ;
CreatorVisible = ! string . IsNullOrWhiteSpace ( inputFormat . Info . Creator ) ;
MediaTitleVisible = ! string . IsNullOrWhiteSpace ( inputFormat . Info . MediaTitle ) ;
CommentsVisible = ! string . IsNullOrWhiteSpace ( inputFormat . Info . Comments ) ;
MediaManufacturerVisible = ! string . IsNullOrWhiteSpace ( inputFormat . Info . MediaManufacturer ) ;
MediaModelVisible = ! string . IsNullOrWhiteSpace ( inputFormat . Info . MediaModel ) ;
MediaSerialNumberVisible = ! string . IsNullOrWhiteSpace ( inputFormat . Info . MediaSerialNumber ) ;
MediaBarcodeVisible = ! string . IsNullOrWhiteSpace ( inputFormat . Info . MediaBarcode ) ;
MediaPartNumberVisible = ! string . IsNullOrWhiteSpace ( inputFormat . Info . MediaPartNumber ) ;
MediaSequenceVisible = inputFormat . Info . MediaSequence ! = 0 & & inputFormat . Info . LastMediaSequence ! = 0 ;
LastMediaSequenceVisible = inputFormat . Info . MediaSequence ! = 0 & & inputFormat . Info . LastMediaSequence ! = 0 ;
DriveManufacturerVisible = ! string . IsNullOrWhiteSpace ( inputFormat . Info . DriveManufacturer ) ;
DriveModelVisible = ! string . IsNullOrWhiteSpace ( inputFormat . Info . DriveModel ) ;
DriveSerialNumberVisible = ! string . IsNullOrWhiteSpace ( inputFormat . Info . DriveSerialNumber ) ;
DriveFirmwareRevisionVisible = ! string . IsNullOrWhiteSpace ( inputFormat . Info . DriveFirmwareRevision ) ;
PluginBase plugins = GetPluginBase . Instance ;
foreach ( IWritableImage plugin in
2020-04-13 04:40:35 +01:00
plugins . WritableImages . Values . Where ( p = > p . SupportedMediaTypes . Contains ( inputFormat . Info . MediaType ) ) )
2022-03-06 13:29:38 +00:00
PluginsList . Add ( new ImagePluginModel
{
Plugin = plugin
} ) ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
CicmXmlFromImageVisible = inputFormat . CicmMetadata ! = null ;
ResumeFileFromImageVisible = inputFormat . DumpHardware ? . Any ( ) = = true ;
_cicmMetadata = inputFormat . CicmMetadata ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
_dumpHardware = inputFormat . DumpHardware ? . Any ( ) = = true ? inputFormat . DumpHardware : null ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
CicmXmlText = _cicmMetadata = = null ? "" : "<From image>" ;
ResumeFileText = _dumpHardware = = null ? "" : "<From image>" ;
}
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
public string Title
{
get = > _title ;
set = > this . RaiseAndSetIfChanged ( ref _title , value ) ;
}
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
public string SourceText
{
get = > _sourceText ;
set = > this . RaiseAndSetIfChanged ( ref _sourceText , value ) ;
}
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
public ObservableCollection < ImagePluginModel > PluginsList { get ; }
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
public ImagePluginModel SelectedPlugin
{
get = > _selectedPlugin ;
set = > this . RaiseAndSetIfChanged ( ref _selectedPlugin , value ) ;
}
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
public string DestinationText
{
get = > _destinationText ;
set = > this . RaiseAndSetIfChanged ( ref _destinationText , value ) ;
}
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
public bool OptionsVisible
{
get = > _optionsVisible ;
set = > this . RaiseAndSetIfChanged ( ref _optionsVisible , value ) ;
}
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
public double SectorsValue
{
get = > _sectorsValue ;
set = > this . RaiseAndSetIfChanged ( ref _sectorsValue , value ) ;
}
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
public bool ForceChecked
{
get = > _forceChecked ;
set = > this . RaiseAndSetIfChanged ( ref _forceChecked , value ) ;
}
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
public string CreatorText
{
get = > _creatorText ;
set = > this . RaiseAndSetIfChanged ( ref _creatorText , value ) ;
}
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
public string MediaTitleText
{
get = > _mediaTitleText ;
set = > this . RaiseAndSetIfChanged ( ref _mediaTitleText , value ) ;
}
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
public string MediaManufacturerText
{
get = > _mediaManufacturerText ;
set = > this . RaiseAndSetIfChanged ( ref _mediaManufacturerText , value ) ;
}
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
public string MediaModelText
{
get = > _mediaModelText ;
set = > this . RaiseAndSetIfChanged ( ref _mediaModelText , value ) ;
}
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
public string MediaSerialNumberText
{
get = > _mediaSerialNumberText ;
set = > this . RaiseAndSetIfChanged ( ref _mediaSerialNumberText , value ) ;
}
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
public string MediaBarcodeText
{
get = > _mediaBarcodeText ;
set = > this . RaiseAndSetIfChanged ( ref _mediaBarcodeText , value ) ;
}
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
public string MediaPartNumberText
{
get = > _mediaPartNumberText ;
set = > this . RaiseAndSetIfChanged ( ref _mediaPartNumberText , value ) ;
}
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
public double MediaSequenceValue
{
get = > _mediaSequenceValue ;
set = > this . RaiseAndSetIfChanged ( ref _mediaSequenceValue , value ) ;
}
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
public double LastMediaSequenceValue
{
get = > _lastMediaSequenceValue ;
set = > this . RaiseAndSetIfChanged ( ref _lastMediaSequenceValue , value ) ;
}
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
public string DriveManufacturerText
{
get = > _driveManufacturerText ;
set = > this . RaiseAndSetIfChanged ( ref _driveManufacturerText , value ) ;
}
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
public string DriveModelText
{
get = > _driveModelText ;
set = > this . RaiseAndSetIfChanged ( ref _driveModelText , value ) ;
}
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
public string DriveSerialNumberText
{
get = > _driveSerialNumberText ;
set = > this . RaiseAndSetIfChanged ( ref _driveSerialNumberText , value ) ;
}
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
public string DriveFirmwareRevisionText
{
get = > _driveFirmwareRevisionText ;
set = > this . RaiseAndSetIfChanged ( ref _driveFirmwareRevisionText , value ) ;
}
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
public string CommentsText
{
get = > _commentsText ;
set = > this . RaiseAndSetIfChanged ( ref _commentsText , value ) ;
}
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
public string CicmXmlText
{
get = > _cicmXmlText ;
set = > this . RaiseAndSetIfChanged ( ref _cicmXmlText , value ) ;
}
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
public string ResumeFileText
{
get = > _resumeFileText ;
set = > this . RaiseAndSetIfChanged ( ref _resumeFileText , value ) ;
}
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
public bool ProgressVisible
{
get = > _progressVisible ;
set = > this . RaiseAndSetIfChanged ( ref _progressVisible , value ) ;
}
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
public bool Progress1Visible
{
get = > _progress1Visible ;
set = > this . RaiseAndSetIfChanged ( ref _progress1Visible , value ) ;
}
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
public string ProgressText
{
get = > _progressText ;
set = > this . RaiseAndSetIfChanged ( ref _progressText , value ) ;
}
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
public double ProgressValue
{
get = > _progressValue ;
set = > this . RaiseAndSetIfChanged ( ref _progressValue , value ) ;
}
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
public double ProgressMaxValue
{
get = > _progressMaxValue ;
set = > this . RaiseAndSetIfChanged ( ref _progressMaxValue , value ) ;
}
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
public bool ProgressIndeterminate
{
get = > _progressIndeterminate ;
set = > this . RaiseAndSetIfChanged ( ref _progressIndeterminate , value ) ;
}
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
public bool Progress2Visible
{
get = > _progress2Visible ;
set = > this . RaiseAndSetIfChanged ( ref _progress2Visible , value ) ;
}
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
public string Progress2Text
{
get = > _progress2Text ;
set = > this . RaiseAndSetIfChanged ( ref _progress2Text , value ) ;
}
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
public double Progress2Value
{
get = > _progress2Value ;
set = > this . RaiseAndSetIfChanged ( ref _progress2Value , value ) ;
}
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
public double Progress2MaxValue
{
get = > _progress2MaxValue ;
set = > this . RaiseAndSetIfChanged ( ref _progress2MaxValue , value ) ;
}
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
public bool Progress2Indeterminate
{
get = > _progress2Indeterminate ;
set = > this . RaiseAndSetIfChanged ( ref _progress2Indeterminate , value ) ;
}
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
public bool StartVisible
{
get = > _startVisible ;
set = > this . RaiseAndSetIfChanged ( ref _startVisible , value ) ;
}
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
public bool CloseVisible
{
get = > _closeVisible ;
set = > this . RaiseAndSetIfChanged ( ref _closeVisible , value ) ;
}
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
public bool StopVisible
{
get = > _stopVisible ;
set = > this . RaiseAndSetIfChanged ( ref _stopVisible , value ) ;
}
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
public bool StopEnabled
{
get = > _stopEnabled ;
set = > this . RaiseAndSetIfChanged ( ref _stopEnabled , value ) ;
}
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
public bool CreatorVisible
{
get = > _creatorVisible ;
set = > this . RaiseAndSetIfChanged ( ref _creatorVisible , value ) ;
}
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
public bool MediaTitleVisible
{
get = > _mediaTitleVisible ;
set = > this . RaiseAndSetIfChanged ( ref _mediaTitleVisible , value ) ;
}
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
public bool CommentsVisible
{
get = > _commentsVisible ;
set = > this . RaiseAndSetIfChanged ( ref _commentsVisible , value ) ;
}
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
public bool MediaManufacturerVisible
{
get = > _mediaManufacturerVisible ;
set = > this . RaiseAndSetIfChanged ( ref _mediaManufacturerVisible , value ) ;
}
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
public bool MediaModelVisible
{
get = > _mediaModelVisible ;
set = > this . RaiseAndSetIfChanged ( ref _mediaModelVisible , value ) ;
}
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
public bool MediaSerialNumberVisible
{
get = > _mediaSerialNumberVisible ;
set = > this . RaiseAndSetIfChanged ( ref _mediaSerialNumberVisible , value ) ;
}
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
public bool MediaBarcodeVisible
{
get = > _mediaBarcodeVisible ;
set = > this . RaiseAndSetIfChanged ( ref _mediaBarcodeVisible , value ) ;
}
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
public bool MediaPartNumberVisible
{
get = > _mediaPartNumberVisible ;
set = > this . RaiseAndSetIfChanged ( ref _mediaPartNumberVisible , value ) ;
}
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
public bool MediaSequenceVisible
{
get = > _mediaSequenceVisible ;
set = > this . RaiseAndSetIfChanged ( ref _mediaSequenceVisible , value ) ;
}
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
public bool LastMediaSequenceVisible
{
get = > _lastMediaSequenceVisible ;
set = > this . RaiseAndSetIfChanged ( ref _lastMediaSequenceVisible , value ) ;
}
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
public bool DriveManufacturerVisible
{
get = > _driveManufacturerVisible ;
set = > this . RaiseAndSetIfChanged ( ref _driveManufacturerVisible , value ) ;
}
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
public bool DriveModelVisible
{
get = > _driveModelVisible ;
set = > this . RaiseAndSetIfChanged ( ref _driveModelVisible , value ) ;
}
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
public bool DriveSerialNumberVisible
{
get = > _driveSerialNumberVisible ;
set = > this . RaiseAndSetIfChanged ( ref _driveSerialNumberVisible , value ) ;
}
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
public bool DriveFirmwareRevisionVisible
{
get = > _driveFirmwareRevisionVisible ;
set = > this . RaiseAndSetIfChanged ( ref _driveFirmwareRevisionVisible , value ) ;
}
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
public bool CicmXmlFromImageVisible
{
get = > _cicmXmlFromImageVisible ;
set = > this . RaiseAndSetIfChanged ( ref _cicmXmlFromImageVisible , value ) ;
}
public bool ResumeFileFromImageVisible
{
get = > _resumeFileFromImageVisible ;
set = > this . RaiseAndSetIfChanged ( ref _resumeFileFromImageVisible , value ) ;
}
public bool DestinationEnabled
{
get = > _destinationEnabled ;
set = > this . RaiseAndSetIfChanged ( ref _destinationEnabled , value ) ;
}
public ReactiveCommand < Unit , Unit > DestinationCommand { get ; }
public ReactiveCommand < Unit , Unit > CreatorCommand { get ; }
public ReactiveCommand < Unit , Unit > MediaTitleCommand { get ; }
public ReactiveCommand < Unit , Unit > MediaManufacturerCommand { get ; }
public ReactiveCommand < Unit , Unit > MediaModelCommand { get ; }
public ReactiveCommand < Unit , Unit > MediaSerialNumberCommand { get ; }
public ReactiveCommand < Unit , Unit > MediaBarcodeCommand { get ; }
public ReactiveCommand < Unit , Unit > MediaPartNumberCommand { get ; }
public ReactiveCommand < Unit , Unit > MediaSequenceCommand { get ; }
public ReactiveCommand < Unit , Unit > LastMediaSequenceCommand { get ; }
public ReactiveCommand < Unit , Unit > DriveManufacturerCommand { get ; }
public ReactiveCommand < Unit , Unit > DriveModelCommand { get ; }
public ReactiveCommand < Unit , Unit > DriveSerialNumberCommand { get ; }
public ReactiveCommand < Unit , Unit > DriveFirmwareRevisionCommand { get ; }
public ReactiveCommand < Unit , Unit > CommentsCommand { get ; }
public ReactiveCommand < Unit , Unit > CicmXmlFromImageCommand { get ; }
public ReactiveCommand < Unit , Unit > CicmXmlCommand { get ; }
public ReactiveCommand < Unit , Unit > ResumeFileFromImageCommand { get ; }
public ReactiveCommand < Unit , Unit > ResumeFileCommand { get ; }
public ReactiveCommand < Unit , Unit > StartCommand { get ; }
public ReactiveCommand < Unit , Unit > CloseCommand { get ; }
public ReactiveCommand < Unit , Unit > StopCommand { get ; }
public bool FormatReadOnly
{
get = > _formatReadOnly ;
set = > this . RaiseAndSetIfChanged ( ref _formatReadOnly , value ) ;
}
public bool DestinationVisible
{
get = > _destinationVisible ;
set = > this . RaiseAndSetIfChanged ( ref _destinationVisible , value ) ;
}
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
async void ExecuteStartCommand ( )
{
if ( SelectedPlugin is null )
2020-04-13 04:40:35 +01:00
{
2022-03-06 13:29:38 +00:00
await MessageBoxManager . GetMessageBoxStandardWindow ( "Error" , "Error trying to find selected plugin" ,
icon : Icon . Error ) . ShowDialog ( _view ) ;
return ;
2020-04-13 04:40:35 +01:00
}
2022-03-06 13:29:38 +00:00
new Thread ( DoWork ) . Start ( SelectedPlugin . Plugin ) ;
}
async void DoWork ( object plugin )
{
2022-03-07 07:36:44 +00:00
var warning = false ;
2022-03-06 13:29:38 +00:00
if ( ! ( plugin is IWritableImage outputFormat ) )
2020-04-13 04:40:35 +01:00
{
2022-03-06 13:29:38 +00:00
await MessageBoxManager . GetMessageBoxStandardWindow ( "Error" , "Error trying to find selected plugin" ,
icon : Icon . Error ) . ShowDialog ( _view ) ;
return ;
2020-04-13 04:40:35 +01:00
}
2022-03-06 13:29:38 +00:00
var inputOptical = _inputFormat as IOpticalMediaImage ;
var outputOptical = outputFormat as IWritableOpticalImage ;
List < Track > tracks ;
try
2020-04-13 04:40:35 +01:00
{
2022-03-06 13:29:38 +00:00
tracks = inputOptical ? . Tracks ;
2020-04-13 04:40:35 +01:00
}
2022-03-06 13:29:38 +00:00
catch ( Exception )
2020-04-13 04:40:35 +01:00
{
2022-03-06 13:29:38 +00:00
tracks = null ;
2020-04-13 04:40:35 +01:00
}
2022-03-06 13:29:38 +00:00
// Prepare UI
await Dispatcher . UIThread . InvokeAsync ( ( ) = >
2020-04-13 04:40:35 +01:00
{
2022-03-06 13:29:38 +00:00
CloseVisible = false ;
StartVisible = false ;
StopVisible = true ;
ProgressVisible = true ;
OptionsVisible = false ;
StopEnabled = true ;
FormatReadOnly = true ;
DestinationVisible = false ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
ProgressMaxValue = 1d ;
ProgressMaxValue + = _inputFormat . Info . ReadableMediaTags . Count ;
ProgressMaxValue + + ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
if ( tracks ! = null )
ProgressMaxValue + + ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
if ( tracks = = null )
2020-04-13 04:40:35 +01:00
{
2022-03-06 13:29:38 +00:00
ProgressMaxValue + = 2 ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
foreach ( SectorTagType tag in _inputFormat . Info . ReadableSectorTags )
{
switch ( tag )
{
case SectorTagType . AppleSectorTag :
case SectorTagType . CdSectorSync :
case SectorTagType . CdSectorHeader :
case SectorTagType . CdSectorSubHeader :
case SectorTagType . CdSectorEdc :
case SectorTagType . CdSectorEccP :
case SectorTagType . CdSectorEccQ :
case SectorTagType . CdSectorEcc :
// This tags are inline in long sector
continue ;
}
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
if ( ForceChecked & & ! outputFormat . SupportedSectorTags . Contains ( tag ) )
continue ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
ProgressMaxValue + + ;
}
2020-04-13 04:40:35 +01:00
}
2022-03-06 13:29:38 +00:00
else
2020-04-13 04:40:35 +01:00
{
2022-03-06 13:29:38 +00:00
ProgressMaxValue + = tracks . Count ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
foreach ( SectorTagType tag in _inputFormat . Info . ReadableSectorTags . OrderBy ( t = > t ) )
2020-04-13 04:40:35 +01:00
{
2022-03-06 13:29:38 +00:00
switch ( tag )
2020-04-13 04:40:35 +01:00
{
2022-03-06 13:29:38 +00:00
case SectorTagType . AppleSectorTag :
case SectorTagType . CdSectorSync :
case SectorTagType . CdSectorHeader :
case SectorTagType . CdSectorSubHeader :
case SectorTagType . CdSectorEdc :
case SectorTagType . CdSectorEccP :
case SectorTagType . CdSectorEccQ :
case SectorTagType . CdSectorEcc :
// This tags are inline in long sector
2020-04-13 04:40:35 +01:00
continue ;
}
2022-03-06 13:29:38 +00:00
if ( ForceChecked & & ! outputFormat . SupportedSectorTags . Contains ( tag ) )
continue ;
2020-04-13 04:40:35 +01:00
ProgressMaxValue + = tracks . Count ;
2022-03-06 13:29:38 +00:00
}
}
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
if ( _dumpHardware ! = null )
ProgressMaxValue + + ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
if ( _cicmMetadata ! = null )
ProgressMaxValue + + ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
ProgressMaxValue + + ;
} ) ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
foreach ( MediaTagType mediaTag in _inputFormat . Info . ReadableMediaTags . Where ( mediaTag = >
! outputFormat . SupportedMediaTags . Contains ( mediaTag ) & & ! ForceChecked ) )
{
await Dispatcher . UIThread . InvokeAsync ( action : async ( ) = > await MessageBoxManager .
GetMessageBoxStandardWindow ( "Error" ,
$"Converting image will lose media tag {mediaTag}, not continuing..." ,
icon : Icon . Error ) .
ShowDialog ( _view ) ) ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
return ;
}
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
bool useLong = _inputFormat . Info . ReadableSectorTags . Count ! = 0 ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
foreach ( SectorTagType sectorTag in _inputFormat . Info . ReadableSectorTags . Where ( sectorTag = >
! outputFormat . SupportedSectorTags . Contains ( sectorTag ) ) )
{
if ( ForceChecked )
2020-04-13 04:40:35 +01:00
{
2022-03-06 13:29:38 +00:00
if ( sectorTag ! = SectorTagType . CdTrackFlags & &
sectorTag ! = SectorTagType . CdTrackIsrc & &
sectorTag ! = SectorTagType . CdSectorSubchannel )
useLong = false ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
continue ;
2020-04-13 04:40:35 +01:00
}
2022-03-06 13:29:38 +00:00
await Dispatcher . UIThread . InvokeAsync ( action : async ( ) = > await MessageBoxManager .
GetMessageBoxStandardWindow ( "Error" ,
$"Converting image will lose sector tag {sectorTag}, not continuing..." ,
icon : Icon . Error ) .
ShowDialog ( _view ) ) ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
return ;
}
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
Dictionary < string , string > parsedOptions = new ( ) ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
/ * TODO :
if ( grpOptions . Content is StackLayout stkImageOptions )
foreach ( Control option in stkImageOptions . Children )
{
if ( cancel )
break ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
string value ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
switch ( option )
2020-04-13 04:40:35 +01:00
{
2022-03-06 13:29:38 +00:00
case CheckBox optBoolean :
value = optBooleanChecked ? . ToString ( ) ;
2020-04-13 04:40:35 +01:00
break ;
2022-03-06 13:29:38 +00:00
case NumericStepper optNumber :
value = optNumber . Value . ToString ( CultureInfo . CurrentCulture ) ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
break ;
case TextBox optString :
value = optString . Text ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
break ;
default : continue ;
}
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
string key = option . ID . Substring ( 3 ) ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
parsedOptions . Add ( key , value ) ;
}
* /
await Dispatcher . UIThread . InvokeAsync ( ( ) = >
{
ProgressText = "Creating output image" ;
Progress2Text = "" ;
Progress2Indeterminate = true ;
} ) ;
2022-03-07 07:36:44 +00:00
if ( ! outputFormat . Create ( DestinationText , _inputFormat . Info . MediaType , parsedOptions , _inputFormat . Info . Sectors ,
_inputFormat . Info . SectorSize ) )
2022-03-06 13:29:38 +00:00
{
await Dispatcher . UIThread . InvokeAsync ( action : async ( ) = > await MessageBoxManager .
GetMessageBoxStandardWindow ( "Error" ,
$"Error {outputFormat.ErrorMessage} creating output image." ,
icon : Icon . Error ) .
ShowDialog ( _view ) ) ;
AaruConsole . ErrorWriteLine ( "Error {0} creating output image." , outputFormat . ErrorMessage ) ;
return ;
}
await Dispatcher . UIThread . InvokeAsync ( ( ) = >
{
ProgressText = "Setting image metadata" ;
ProgressValue + + ;
Progress2Text = "" ;
Progress2Indeterminate = true ;
} ) ;
var metadata = new ImageInfo
{
Application = "Aaru" ,
ApplicationVersion = Version . GetVersion ( ) ,
Comments = CommentsText ,
Creator = CreatorText ,
DriveFirmwareRevision = DriveFirmwareRevisionText ,
DriveManufacturer = DriveManufacturerText ,
DriveModel = DriveModelText ,
DriveSerialNumber = DriveSerialNumberText ,
LastMediaSequence = ( int ) LastMediaSequenceValue ,
MediaBarcode = MediaBarcodeText ,
MediaManufacturer = MediaManufacturerText ,
MediaModel = MediaModelText ,
MediaPartNumber = MediaPartNumberText ,
MediaSequence = ( int ) MediaSequenceValue ,
MediaSerialNumber = MediaSerialNumberText ,
MediaTitle = MediaTitleText
} ;
if ( ! _cancel )
if ( ! outputFormat . SetMetadata ( metadata ) )
{
AaruConsole . ErrorWrite ( "Error {0} setting metadata, " , outputFormat . ErrorMessage ) ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
if ( ForceChecked ! = true )
{
await Dispatcher . UIThread . InvokeAsync ( action : async ( ) = > await MessageBoxManager .
GetMessageBoxStandardWindow ( "Error" ,
$"Error {outputFormat.ErrorMessage} setting metadata, not continuing..." ,
2022-03-07 07:36:44 +00:00
icon : Icon . Error ) .
ShowDialog ( _view ) ) ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
AaruConsole . ErrorWriteLine ( "not continuing..." ) ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
return ;
2020-04-13 04:40:35 +01:00
}
2022-03-06 13:29:38 +00:00
warning = true ;
AaruConsole . ErrorWriteLine ( "continuing..." ) ;
}
if ( tracks ! = null & &
! _cancel & &
outputOptical ! = null )
{
2020-04-13 04:40:35 +01:00
await Dispatcher . UIThread . InvokeAsync ( ( ) = >
{
2022-03-06 13:29:38 +00:00
ProgressText = "Setting tracks list" ;
ProgressValue + + ;
2020-04-13 04:40:35 +01:00
Progress2Text = "" ;
Progress2Indeterminate = true ;
} ) ;
2022-03-06 13:29:38 +00:00
if ( ! outputOptical . SetTracks ( tracks ) )
2020-04-13 04:40:35 +01:00
{
2020-07-22 13:20:25 +01:00
await Dispatcher . UIThread . InvokeAsync ( action : async ( ) = > await MessageBoxManager .
2020-11-04 23:55:24 +00:00
GetMessageBoxStandardWindow ( "Error" ,
2022-03-06 13:29:38 +00:00
$"Error {outputFormat.ErrorMessage} sending tracks list to output image." ,
2020-11-04 23:55:24 +00:00
icon : Icon . Error ) .
ShowDialog ( _view ) ) ;
2020-04-13 04:40:35 +01:00
2022-03-07 07:36:44 +00:00
AaruConsole . ErrorWriteLine ( "Error {0} sending tracks list to output image." , outputFormat . ErrorMessage ) ;
2020-04-13 04:40:35 +01:00
return ;
}
2022-03-06 13:29:38 +00:00
}
ErrorNumber errno ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
foreach ( MediaTagType mediaTag in _inputFormat . Info . ReadableMediaTags . TakeWhile ( mediaTag = > ! _cancel ) )
{
2020-04-13 04:40:35 +01:00
await Dispatcher . UIThread . InvokeAsync ( ( ) = >
{
2022-03-06 13:29:38 +00:00
ProgressText = $"Converting media tag {mediaTag}" ;
2020-04-13 04:40:35 +01:00
ProgressValue + + ;
Progress2Text = "" ;
Progress2Indeterminate = true ;
} ) ;
2022-03-06 13:29:38 +00:00
if ( ForceChecked & & ! outputFormat . SupportedMediaTags . Contains ( mediaTag ) )
continue ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
errno = _inputFormat . ReadMediaTag ( mediaTag , out byte [ ] tag ) ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
if ( errno = = ErrorNumber . NoError & &
outputFormat . WriteMediaTag ( tag , mediaTag ) )
continue ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
if ( ForceChecked )
2020-04-13 04:40:35 +01:00
{
2022-03-06 13:29:38 +00:00
warning = true ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
if ( errno = = ErrorNumber . NoError )
2022-03-07 07:36:44 +00:00
AaruConsole . ErrorWriteLine ( "Error {0} writing media tag, continuing..." , outputFormat . ErrorMessage ) ;
2022-03-06 13:29:38 +00:00
else
AaruConsole . ErrorWriteLine ( "Error {0} reading media tag, continuing..." , errno ) ;
2020-04-13 04:40:35 +01:00
}
2022-03-06 13:29:38 +00:00
else
2020-04-13 04:40:35 +01:00
{
2022-03-06 13:29:38 +00:00
if ( errno = = ErrorNumber . NoError )
2020-04-13 04:40:35 +01:00
{
2022-03-06 13:29:38 +00:00
await Dispatcher . UIThread . InvokeAsync ( action : async ( ) = >
await MessageBoxManager .
GetMessageBoxStandardWindow ( "Error" ,
$"Error {outputFormat.ErrorMessage} writing media tag, not continuing..." ,
icon : Icon . Error ) . ShowDialog ( _view ) ) ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
AaruConsole . ErrorWriteLine ( "Error {0} writing media tag, not continuing..." ,
outputFormat . ErrorMessage ) ;
2020-04-13 04:40:35 +01:00
}
else
{
2022-03-06 13:29:38 +00:00
await Dispatcher . UIThread . InvokeAsync ( action : async ( ) = >
await MessageBoxManager .
GetMessageBoxStandardWindow ( "Error" ,
$"Error {errno} reading media tag, not continuing..." ,
icon : Icon . Error ) . ShowDialog ( _view ) ) ;
2021-09-18 15:01:31 +01:00
2022-03-06 13:29:38 +00:00
AaruConsole . ErrorWriteLine ( "Error {0} reading media tag, not continuing..." , errno ) ;
2020-04-13 04:40:35 +01:00
}
2022-03-06 13:29:38 +00:00
return ;
2020-04-13 04:40:35 +01:00
}
2022-03-06 13:29:38 +00:00
}
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
ulong doneSectors = 0 ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
if ( tracks = = null & &
! _cancel )
{
await Dispatcher . UIThread . InvokeAsync ( ( ) = >
2020-04-13 04:40:35 +01:00
{
2022-03-06 13:29:38 +00:00
ProgressText =
$"Setting geometry to {_inputFormat.Info.Cylinders} cylinders, {_inputFormat.Info.Heads} heads and {_inputFormat.Info.SectorsPerTrack} sectors per track" ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
ProgressValue + + ;
Progress2Text = "" ;
Progress2Indeterminate = true ;
} ) ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
if ( ! outputFormat . SetGeometry ( _inputFormat . Info . Cylinders , _inputFormat . Info . Heads ,
_inputFormat . Info . SectorsPerTrack ) )
{
warning = true ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
AaruConsole . ErrorWriteLine ( "Error {0} setting geometry, image may be incorrect, continuing..." ,
outputFormat . ErrorMessage ) ;
}
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
await Dispatcher . UIThread . InvokeAsync ( ( ) = >
{
ProgressText = "Converting sectors" ;
ProgressValue + + ;
Progress2Text = "" ;
Progress2Indeterminate = false ;
Progress2MaxValue = ( int ) ( _inputFormat . Info . Sectors / SectorsValue ) ;
} ) ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
while ( doneSectors < _inputFormat . Info . Sectors )
{
if ( _cancel )
break ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
byte [ ] sector ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
uint sectorsToDo ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
if ( _inputFormat . Info . Sectors - doneSectors > = ( ulong ) SectorsValue )
sectorsToDo = ( uint ) SectorsValue ;
else
sectorsToDo = ( uint ) ( _inputFormat . Info . Sectors - doneSectors ) ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
ulong sectors = doneSectors ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
await Dispatcher . UIThread . InvokeAsync ( ( ) = >
{
Progress2Text =
$"Converting sectors {sectors} to {sectors + sectorsToDo} ({sectors / (double)_inputFormat.Info.Sectors:P2} done)" ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
Progress2Value = ( int ) ( sectors / SectorsValue ) ;
} ) ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
bool result ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
if ( useLong )
{
errno = sectorsToDo = = 1 ? _inputFormat . ReadSectorLong ( doneSectors , out sector )
: _inputFormat . ReadSectorsLong ( doneSectors , sectorsToDo , out sector ) ;
if ( errno = = ErrorNumber . NoError )
result = sectorsToDo = = 1 ? outputFormat . WriteSectorLong ( sector , doneSectors )
: outputFormat . WriteSectorsLong ( sector , doneSectors , sectorsToDo ) ;
else
2021-09-20 14:22:22 +01:00
{
2022-03-06 13:29:38 +00:00
result = true ;
2021-09-20 14:22:22 +01:00
2022-03-06 13:29:38 +00:00
if ( ForceChecked )
2020-04-13 04:40:35 +01:00
{
2022-03-06 13:29:38 +00:00
warning = true ;
2021-09-20 14:22:22 +01:00
2022-03-06 13:29:38 +00:00
AaruConsole . ErrorWriteLine ( "Error {0} reading sector {1}, continuing..." , errno ,
doneSectors ) ;
2020-04-13 04:40:35 +01:00
}
else
{
2022-03-06 13:29:38 +00:00
await Dispatcher . UIThread . InvokeAsync ( action : async ( ) = > await MessageBoxManager .
GetMessageBoxStandardWindow ( "Error" ,
$"Error {errno} reading sector {doneSectors}, not continuing..." ,
2022-03-07 07:36:44 +00:00
icon : Icon . Error ) . ShowDialog ( _view ) ) ;
2021-09-19 21:16:47 +01:00
2022-03-06 13:29:38 +00:00
AaruConsole . ErrorWriteLine ( "Error {0} reading sector {1}, not continuing..." , errno ,
doneSectors ) ;
2021-09-19 21:16:47 +01:00
2022-03-06 13:29:38 +00:00
return ;
2020-04-13 04:40:35 +01:00
}
}
2022-03-06 13:29:38 +00:00
}
else
{
errno = sectorsToDo = = 1 ? _inputFormat . ReadSector ( doneSectors , out sector )
: _inputFormat . ReadSectors ( doneSectors , sectorsToDo , out sector ) ;
if ( errno = = ErrorNumber . NoError )
result = sectorsToDo = = 1 ? outputFormat . WriteSector ( sector , doneSectors )
: outputFormat . WriteSectors ( sector , doneSectors , sectorsToDo ) ;
else
{
result = true ;
2020-04-13 04:40:35 +01:00
if ( ForceChecked )
{
warning = true ;
2022-03-06 13:29:38 +00:00
AaruConsole . ErrorWriteLine ( "Error {0} reading sector {1}, continuing..." , errno ,
doneSectors ) ;
2020-04-13 04:40:35 +01:00
}
else
{
2020-07-22 13:20:25 +01:00
await Dispatcher . UIThread . InvokeAsync ( action : async ( ) = > await MessageBoxManager .
2020-11-04 23:55:24 +00:00
GetMessageBoxStandardWindow ( "Error" ,
2022-03-06 13:29:38 +00:00
$"Error {errno} reading sector {doneSectors}, not continuing..." ,
2022-03-07 07:36:44 +00:00
icon : Icon . Error ) . ShowDialog ( _view ) ) ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
AaruConsole . ErrorWriteLine ( "Error {0} reading sector {1}, not continuing..." , errno ,
doneSectors ) ;
2020-04-13 04:40:35 +01:00
return ;
}
2022-03-06 13:29:38 +00:00
}
2020-04-13 04:40:35 +01:00
}
2022-03-06 13:29:38 +00:00
if ( ! result )
if ( ForceChecked )
{
warning = true ;
2020-07-14 02:16:53 +01:00
2022-03-06 13:29:38 +00:00
AaruConsole . ErrorWriteLine ( "Error {0} writing sector {1}, continuing..." ,
outputFormat . ErrorMessage , doneSectors ) ;
}
else
2020-07-14 02:16:53 +01:00
{
2022-03-06 13:29:38 +00:00
await Dispatcher . UIThread . InvokeAsync ( action : async ( ) = > await MessageBoxManager .
GetMessageBoxStandardWindow ( "Error" ,
$"Error {outputFormat.ErrorMessage} writing sector {doneSectors}, not continuing..." ,
icon : Icon . Error ) . ShowDialog ( _view ) ) ;
2020-07-14 02:16:53 +01:00
2022-03-06 13:29:38 +00:00
AaruConsole . ErrorWriteLine ( "Error {0} writing sector {1}, not continuing..." ,
outputFormat . ErrorMessage , doneSectors ) ;
2020-07-14 02:16:53 +01:00
2022-03-06 13:29:38 +00:00
return ;
2020-07-14 02:16:53 +01:00
}
2022-03-06 13:29:38 +00:00
doneSectors + = sectorsToDo ;
}
2020-07-14 02:16:53 +01:00
2022-03-06 13:29:38 +00:00
await Dispatcher . UIThread . InvokeAsync ( ( ) = >
{
Progress2Text =
$"Converting sectors {_inputFormat.Info.Sectors} to {_inputFormat.Info.Sectors} ({1.0:P2} done)" ;
2020-07-14 02:16:53 +01:00
2022-03-06 13:29:38 +00:00
Progress2Value = Progress2MaxValue ;
} ) ;
2020-07-14 02:16:53 +01:00
2022-03-06 13:29:38 +00:00
Dictionary < byte , string > isrcs = new ( ) ;
Dictionary < byte , byte > trackFlags = new ( ) ;
string mcn = null ;
HashSet < int > subchannelExtents = new ( ) ;
Dictionary < byte , int > smallestPregapLbaPerTrack = new ( ) ;
foreach ( SectorTagType tag in _inputFormat . Info . ReadableSectorTags .
Where ( t = > t = = SectorTagType . CdTrackIsrc ) . OrderBy ( t = > t ) )
{
foreach ( Track track in inputOptical . Tracks )
2020-07-14 02:16:53 +01:00
{
2022-03-06 13:29:38 +00:00
errno = _inputFormat . ReadSectorTag ( track . Sequence , tag , out byte [ ] isrc ) ;
if ( errno ! = ErrorNumber . NoError )
continue ;
2020-07-14 02:16:53 +01:00
2022-03-06 13:29:38 +00:00
isrcs [ ( byte ) track . Sequence ] = Encoding . UTF8 . GetString ( isrc ) ;
2020-07-14 02:16:53 +01:00
}
2022-03-06 13:29:38 +00:00
}
2020-07-14 02:16:53 +01:00
2022-03-06 13:29:38 +00:00
foreach ( SectorTagType tag in _inputFormat . Info . ReadableSectorTags .
Where ( t = > t = = SectorTagType . CdTrackFlags ) . OrderBy ( t = > t ) )
{
foreach ( Track track in inputOptical . Tracks )
2020-04-13 04:40:35 +01:00
{
2022-03-06 13:29:38 +00:00
errno = _inputFormat . ReadSectorTag ( track . Sequence , tag , out byte [ ] flags ) ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
if ( errno ! = ErrorNumber . NoError )
2020-04-13 04:40:35 +01:00
continue ;
2022-03-06 13:29:38 +00:00
trackFlags [ ( byte ) track . Sequence ] = flags [ 0 ] ;
}
}
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
for ( ulong s = 0 ; s < _inputFormat . Info . Sectors ; s + + )
{
if ( s > int . MaxValue )
break ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
subchannelExtents . Add ( ( int ) s ) ;
}
foreach ( SectorTagType tag in _inputFormat . Info . ReadableSectorTags . TakeWhile ( tag = > useLong & & ! _cancel ) )
{
switch ( tag )
{
case SectorTagType . AppleSectorTag :
case SectorTagType . CdSectorSync :
case SectorTagType . CdSectorHeader :
case SectorTagType . CdSectorSubHeader :
case SectorTagType . CdSectorEdc :
case SectorTagType . CdSectorEccP :
case SectorTagType . CdSectorEccQ :
case SectorTagType . CdSectorEcc :
// This tags are inline in long sector
continue ;
}
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
if ( ForceChecked & & ! outputFormat . SupportedSectorTags . Contains ( tag ) )
continue ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
await Dispatcher . UIThread . InvokeAsync ( ( ) = >
{
ProgressText = $"Converting tag {tag}" ;
ProgressValue + + ;
Progress2Text = "" ;
Progress2Indeterminate = false ;
Progress2MaxValue = ( int ) ( _inputFormat . Info . Sectors / SectorsValue ) ;
} ) ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
doneSectors = 0 ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
while ( doneSectors < _inputFormat . Info . Sectors )
{
if ( _cancel )
break ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
byte [ ] sector ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
uint sectorsToDo ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
if ( _inputFormat . Info . Sectors - doneSectors > = ( ulong ) SectorsValue )
sectorsToDo = ( uint ) SectorsValue ;
else
sectorsToDo = ( uint ) ( _inputFormat . Info . Sectors - doneSectors ) ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
ulong sectors = doneSectors ;
2020-07-14 02:16:53 +01:00
2022-03-06 13:29:38 +00:00
await Dispatcher . UIThread . InvokeAsync ( ( ) = >
{
Progress2Text =
$"Converting tag {sectors / (double)_inputFormat.Info.Sectors} for sectors {sectors} to {sectors + sectorsToDo} ({sectors / (double)_inputFormat.Info.Sectors:P2} done)" ;
2021-09-20 20:52:18 +01:00
2022-03-06 13:29:38 +00:00
Progress2Value = ( int ) ( sectors / SectorsValue ) ;
} ) ;
2020-07-14 02:16:53 +01:00
2022-03-06 13:29:38 +00:00
bool result ;
2020-07-14 02:16:53 +01:00
2022-03-06 13:29:38 +00:00
if ( sectorsToDo = = 1 )
{
errno = _inputFormat . ReadSectorTag ( doneSectors , tag , out sector ) ;
2021-09-20 20:52:18 +01:00
2022-03-06 13:29:38 +00:00
if ( errno = = ErrorNumber . NoError )
{
Track track = tracks . LastOrDefault ( t = > t . StartSector > = doneSectors ) ;
2021-09-20 20:52:18 +01:00
2022-03-06 13:29:38 +00:00
if ( tag = = SectorTagType . CdSectorSubchannel & &
track ! = null )
{
bool indexesChanged = CompactDisc . WriteSubchannelToImage ( MmcSubchannel . Raw ,
2022-03-07 07:36:44 +00:00
MmcSubchannel . Raw , sector , doneSectors , 1 , null , isrcs , ( byte ) track . Sequence ,
ref mcn , tracks . ToArray ( ) , subchannelExtents , false ,
outputFormat as IWritableOpticalImage , false , false , null , null ,
smallestPregapLbaPerTrack , false ) ;
2021-09-20 20:52:18 +01:00
2022-03-06 13:29:38 +00:00
if ( indexesChanged )
outputOptical . SetTracks ( tracks . ToList ( ) ) ;
2021-09-20 20:52:18 +01:00
2022-03-06 13:29:38 +00:00
result = true ;
2021-09-20 20:52:18 +01:00
}
2022-03-06 13:29:38 +00:00
else
result = outputFormat . WriteSectorTag ( sector , doneSectors , tag ) ;
2020-04-13 04:40:35 +01:00
}
else
{
2022-03-06 13:29:38 +00:00
result = true ;
2020-07-14 02:16:53 +01:00
2022-03-06 13:29:38 +00:00
if ( ForceChecked )
2020-07-14 02:16:53 +01:00
{
2022-03-06 13:29:38 +00:00
warning = true ;
2021-09-20 20:52:18 +01:00
2022-03-06 13:29:38 +00:00
AaruConsole . ErrorWriteLine ( "Error {0} reading sector {1}, continuing..." , errno ,
doneSectors ) ;
2020-07-14 02:16:53 +01:00
}
else
2021-09-20 20:52:18 +01:00
{
2022-03-06 13:29:38 +00:00
await Dispatcher . UIThread . InvokeAsync ( action : async ( ) = > await MessageBoxManager .
GetMessageBoxStandardWindow ( "Error" ,
$"Error {errno} reading sector {doneSectors}, not continuing..." ,
icon : Icon . Error ) .
ShowDialog ( _view ) ) ;
2021-09-20 20:52:18 +01:00
2022-03-06 13:29:38 +00:00
AaruConsole . ErrorWriteLine ( "Error {0} reading sector {1}, not continuing..." , errno ,
doneSectors ) ;
2021-09-20 20:52:18 +01:00
2022-03-06 13:29:38 +00:00
return ;
}
}
}
else
{
errno = _inputFormat . ReadSectorsTag ( doneSectors , sectorsToDo , tag , out sector ) ;
if ( errno = = ErrorNumber . NoError )
{
Track track = tracks . LastOrDefault ( t = > t . StartSector > = doneSectors ) ;
2021-09-20 20:52:18 +01:00
2022-03-06 13:29:38 +00:00
if ( tag = = SectorTagType . CdSectorSubchannel & &
track ! = null )
2021-09-20 20:52:18 +01:00
2022-03-06 13:29:38 +00:00
{
bool indexesChanged = CompactDisc . WriteSubchannelToImage ( MmcSubchannel . Raw ,
MmcSubchannel . Raw , sector , doneSectors , sectorsToDo , null , isrcs ,
( byte ) track . Sequence , ref mcn , tracks . ToArray ( ) , subchannelExtents , false ,
2022-03-07 07:36:44 +00:00
outputFormat as IWritableOpticalImage , false , false , null , null ,
smallestPregapLbaPerTrack , false ) ;
2022-03-06 13:29:38 +00:00
if ( indexesChanged )
outputOptical . SetTracks ( tracks . ToList ( ) ) ;
result = true ;
2021-09-20 20:52:18 +01:00
}
2022-03-06 13:29:38 +00:00
else
result = outputFormat . WriteSectorsTag ( sector , doneSectors , sectorsToDo , tag ) ;
2020-04-13 04:40:35 +01:00
}
2022-03-06 13:29:38 +00:00
else
{
result = true ;
2020-04-13 04:40:35 +01:00
if ( ForceChecked )
{
warning = true ;
2022-03-06 13:29:38 +00:00
AaruConsole . ErrorWriteLine ( "Error {0} reading sector {1}, continuing..." , errno ,
doneSectors ) ;
2020-04-13 04:40:35 +01:00
}
else
{
2020-07-22 13:20:25 +01:00
await Dispatcher . UIThread . InvokeAsync ( action : async ( ) = > await MessageBoxManager .
2020-11-04 23:55:24 +00:00
GetMessageBoxStandardWindow ( "Error" ,
2022-03-06 13:29:38 +00:00
$"Error {errno} reading sector {doneSectors}, not continuing..." ,
2020-11-04 23:55:24 +00:00
icon : Icon . Error ) .
ShowDialog ( _view ) ) ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
AaruConsole . ErrorWriteLine ( "Error {0} reading sector {1}, not continuing..." , errno ,
doneSectors ) ;
2020-04-13 04:40:35 +01:00
return ;
}
2022-03-06 13:29:38 +00:00
}
2020-04-13 04:40:35 +01:00
}
2022-03-06 13:29:38 +00:00
if ( ! result )
if ( ForceChecked )
{
warning = true ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
AaruConsole . ErrorWriteLine ( "Error {0} writing sector {1}, continuing..." ,
outputFormat . ErrorMessage , doneSectors ) ;
}
else
{
await Dispatcher . UIThread . InvokeAsync ( action : async ( ) = > await MessageBoxManager .
GetMessageBoxStandardWindow ( "Error" ,
$"Error {outputFormat.ErrorMessage} writing sector {doneSectors}, not continuing..." ,
2022-03-07 07:36:44 +00:00
icon : Icon . Error ) . ShowDialog ( _view ) ) ;
2020-07-14 02:16:53 +01:00
2022-03-06 13:29:38 +00:00
AaruConsole . ErrorWriteLine ( "Error {0} writing sector {1}, not continuing..." ,
outputFormat . ErrorMessage , doneSectors ) ;
2020-07-14 02:16:53 +01:00
2022-03-06 13:29:38 +00:00
return ;
}
2020-07-14 02:16:53 +01:00
2022-03-06 13:29:38 +00:00
doneSectors + = sectorsToDo ;
2020-04-13 04:40:35 +01:00
}
2022-03-06 13:29:38 +00:00
await Dispatcher . UIThread . InvokeAsync ( ( ) = >
2020-04-13 04:40:35 +01:00
{
2022-03-06 13:29:38 +00:00
Progress2Text =
$"Converting tag {tag} for sectors {_inputFormat.Info.Sectors} to {_inputFormat.Info.Sectors} ({1.0:P2} done)" ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
Progress2Value = Progress2MaxValue ;
} ) ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
if ( isrcs . Count > 0 )
foreach ( KeyValuePair < byte , string > isrc in isrcs )
outputOptical . WriteSectorTag ( Encoding . UTF8 . GetBytes ( isrc . Value ) , isrc . Key ,
SectorTagType . CdTrackIsrc ) ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
if ( trackFlags . Count > 0 )
foreach ( KeyValuePair < byte , byte > flags in trackFlags )
outputOptical . WriteSectorTag ( new [ ]
{
flags . Value
} , flags . Key , SectorTagType . CdTrackFlags ) ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
if ( mcn ! = null )
outputOptical . WriteMediaTag ( Encoding . UTF8 . GetBytes ( mcn ) , MediaTagType . CD_MCN ) ;
}
}
else
{
foreach ( Track track in tracks . TakeWhile ( track = > ! _cancel ) )
{
doneSectors = 0 ;
ulong trackSectors = track . EndSector - track . StartSector + 1 ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
await Dispatcher . UIThread . InvokeAsync ( ( ) = >
{
ProgressText = $"Converting sectors in track {track.Sequence}" ;
ProgressValue + + ;
Progress2Text = "" ;
Progress2Indeterminate = false ;
Progress2MaxValue = ( int ) ( trackSectors / SectorsValue ) ;
} ) ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
while ( doneSectors < trackSectors )
{
if ( _cancel )
break ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
byte [ ] sector ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
uint sectorsToDo ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
if ( trackSectors - doneSectors > = ( ulong ) SectorsValue )
sectorsToDo = ( uint ) SectorsValue ;
else
sectorsToDo = ( uint ) ( trackSectors - doneSectors ) ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
ulong sectors = doneSectors ;
2021-09-20 14:22:22 +01:00
2022-03-06 13:29:38 +00:00
await Dispatcher . UIThread . InvokeAsync ( ( ) = >
{
Progress2Text =
$"Converting sectors {sectors + track.StartSector} to {sectors + sectorsToDo + track.StartSector} in track {track.Sequence} ({(sectors + track.StartSector) / (double)_inputFormat.Info.Sectors:P2} done)" ;
2021-09-20 14:22:22 +01:00
2022-03-06 13:29:38 +00:00
Progress2Value = ( int ) ( sectors / SectorsValue ) ;
} ) ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
bool result ;
2021-09-20 14:22:22 +01:00
2022-03-06 13:29:38 +00:00
if ( useLong )
{
errno = sectorsToDo = = 1
? _inputFormat . ReadSectorLong ( doneSectors + track . StartSector , out sector )
: _inputFormat . ReadSectorsLong ( doneSectors + track . StartSector , sectorsToDo ,
2021-09-19 21:16:47 +01:00
out sector ) ;
2022-03-06 13:29:38 +00:00
if ( errno = = ErrorNumber . NoError )
result = sectorsToDo = = 1
? outputFormat . WriteSectorLong ( sector , doneSectors + track . StartSector )
: outputFormat . WriteSectorsLong ( sector , doneSectors + track . StartSector ,
2021-09-19 21:16:47 +01:00
sectorsToDo ) ;
2022-03-06 13:29:38 +00:00
else
{
result = true ;
2021-09-19 21:16:47 +01:00
2022-03-06 13:29:38 +00:00
if ( ForceChecked )
{
warning = true ;
2021-09-19 21:16:47 +01:00
2022-03-06 13:29:38 +00:00
AaruConsole . ErrorWriteLine ( "Error {0} reading sector {1}, continuing..." , errno ,
doneSectors ) ;
}
else
{
await Dispatcher . UIThread . InvokeAsync ( action : async ( ) = > await MessageBoxManager .
GetMessageBoxStandardWindow ( "Error" ,
$"Error {errno} reading sector {doneSectors}, not continuing..." ,
icon : Icon . Error ) .
ShowDialog ( _view ) ) ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
return ;
2020-04-13 04:40:35 +01:00
}
}
2022-03-06 13:29:38 +00:00
}
else
{
2022-03-07 07:36:44 +00:00
errno = sectorsToDo = = 1 ? _inputFormat . ReadSector ( doneSectors + track . StartSector , out sector )
2022-03-06 13:29:38 +00:00
: _inputFormat . ReadSectors ( doneSectors + track . StartSector , sectorsToDo ,
out sector ) ;
if ( errno = = ErrorNumber . NoError )
result = sectorsToDo = = 1
? outputFormat . WriteSector ( sector , doneSectors + track . StartSector )
: outputFormat . WriteSectors ( sector , doneSectors + track . StartSector ,
sectorsToDo ) ;
else
{
result = true ;
2020-04-13 04:40:35 +01:00
if ( ForceChecked )
{
warning = true ;
2022-03-06 13:29:38 +00:00
AaruConsole . ErrorWriteLine ( "Error {0} reading sector {1}, continuing..." , errno ,
doneSectors ) ;
2020-04-13 04:40:35 +01:00
}
else
{
2020-07-22 13:20:25 +01:00
await Dispatcher . UIThread . InvokeAsync ( action : async ( ) = > await MessageBoxManager .
2020-11-04 23:55:24 +00:00
GetMessageBoxStandardWindow ( "Error" ,
2022-03-06 13:29:38 +00:00
$"Error {errno} reading sector {doneSectors}, not continuing..." ,
2020-11-04 23:55:24 +00:00
icon : Icon . Error ) .
ShowDialog ( _view ) ) ;
2020-04-13 04:40:35 +01:00
return ;
}
2022-03-06 13:29:38 +00:00
}
2020-04-13 04:40:35 +01:00
}
2022-03-06 13:29:38 +00:00
if ( ! result )
if ( ForceChecked )
2020-04-13 04:40:35 +01:00
{
2022-03-06 13:29:38 +00:00
warning = true ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
AaruConsole . ErrorWriteLine ( "Error {0} writing sector {1}, continuing..." ,
outputFormat . ErrorMessage , doneSectors ) ;
}
else
2020-04-13 04:40:35 +01:00
{
2022-03-06 13:29:38 +00:00
await Dispatcher . UIThread . InvokeAsync ( action : async ( ) = > await MessageBoxManager .
GetMessageBoxStandardWindow ( "Error" ,
$"Error {outputFormat.ErrorMessage} writing sector {doneSectors}, not continuing..." ,
2022-03-07 07:36:44 +00:00
icon : Icon . Error ) . ShowDialog ( _view ) ) ;
2021-09-20 20:52:18 +01:00
2022-03-06 13:29:38 +00:00
return ;
}
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
doneSectors + = sectorsToDo ;
}
}
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
await Dispatcher . UIThread . InvokeAsync ( ( ) = >
{
Progress2Text =
$"Converting sectors {_inputFormat.Info.Sectors} to {_inputFormat.Info.Sectors} in track {tracks.Count} ({1.0:P2} done)" ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
Progress2Value = Progress2MaxValue ;
} ) ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
foreach ( SectorTagType tag in _inputFormat . Info . ReadableSectorTags . OrderBy ( t = > t ) .
TakeWhile ( tag = > useLong & & ! _cancel ) )
{
switch ( tag )
{
case SectorTagType . AppleSectorTag :
case SectorTagType . CdSectorSync :
case SectorTagType . CdSectorHeader :
case SectorTagType . CdSectorSubHeader :
case SectorTagType . CdSectorEdc :
case SectorTagType . CdSectorEccP :
case SectorTagType . CdSectorEccQ :
case SectorTagType . CdSectorEcc :
// This tags are inline in long sector
continue ;
}
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
if ( ForceChecked & & ! outputFormat . SupportedSectorTags . Contains ( tag ) )
continue ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
foreach ( Track track in tracks . TakeWhile ( track = > ! _cancel ) )
{
doneSectors = 0 ;
ulong trackSectors = track . EndSector - track . StartSector + 1 ;
byte [ ] sector ;
bool result ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
await Dispatcher . UIThread . InvokeAsync ( ( ) = >
{
ProgressText = $"Converting tag {tag} in track {track.Sequence}." ;
ProgressValue + + ;
Progress2Text = "" ;
Progress2Indeterminate = false ;
Progress2MaxValue = ( int ) ( trackSectors / SectorsValue ) ;
} ) ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
switch ( tag )
{
case SectorTagType . CdTrackFlags :
case SectorTagType . CdTrackIsrc :
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
errno = _inputFormat . ReadSectorTag ( track . Sequence , tag , out sector ) ;
2021-09-20 20:52:18 +01:00
if ( errno = = ErrorNumber . NoError )
2022-03-06 13:29:38 +00:00
result = outputFormat . WriteSectorTag ( sector , track . Sequence , tag ) ;
2020-04-13 04:40:35 +01:00
else
{
2021-09-20 20:52:18 +01:00
if ( ForceChecked )
{
warning = true ;
2022-03-06 13:29:38 +00:00
AaruConsole . ErrorWriteLine ( "Error {0} reading tag, continuing..." , errno ) ;
2021-09-20 20:52:18 +01:00
}
else
{
2022-03-06 13:29:38 +00:00
await Dispatcher . UIThread . InvokeAsync ( action : async ( ) = >
await MessageBoxManager .
GetMessageBoxStandardWindow ( "Error" ,
$"Error {errno} reading tag, not continuing..." ,
icon : Icon . Error ) .
ShowDialog ( _view ) ) ;
2020-04-13 04:40:35 +01:00
2021-09-20 20:52:18 +01:00
return ;
}
2022-03-06 13:29:38 +00:00
continue ;
2020-04-13 04:40:35 +01:00
}
if ( ! result )
if ( ForceChecked )
{
warning = true ;
2022-03-06 13:29:38 +00:00
AaruConsole . ErrorWriteLine ( "Error {0} writing tag, continuing..." ,
outputFormat . ErrorMessage ) ;
2020-04-13 04:40:35 +01:00
}
else
{
2022-03-06 13:29:38 +00:00
await Dispatcher . UIThread . InvokeAsync ( action : async ( ) = >
await MessageBoxManager .
GetMessageBoxStandardWindow ( "Error" ,
$"Error {outputFormat.ErrorMessage} writing tag, not continuing..." ,
icon : Icon . Error ) .
ShowDialog ( _view ) ) ;
2020-04-13 04:40:35 +01:00
return ;
}
2022-03-06 13:29:38 +00:00
continue ;
2020-04-13 04:40:35 +01:00
}
2022-03-06 13:29:38 +00:00
while ( doneSectors < trackSectors )
{
if ( _cancel )
break ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
uint sectorsToDo ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
if ( trackSectors - doneSectors > = ( ulong ) SectorsValue )
sectorsToDo = ( uint ) SectorsValue ;
else
sectorsToDo = ( uint ) ( trackSectors - doneSectors ) ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
ulong sectors = doneSectors ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
await Dispatcher . UIThread . InvokeAsync ( ( ) = >
{
Progress2Text =
$"Converting tag {tag} for sectors {sectors + track.StartSector} to {sectors + sectorsToDo + track.StartSector} in track {track.Sequence} ({(sectors + track.StartSector) / (double)_inputFormat.Info.Sectors:P2} done)" ;
Progress2Value = ( int ) ( sectors / SectorsValue ) ;
} ) ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
errno = sectorsToDo = = 1
? _inputFormat . ReadSectorTag ( doneSectors + track . StartSector , tag , out sector )
: _inputFormat . ReadSectorsTag ( doneSectors + track . StartSector , sectorsToDo , tag ,
out sector ) ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
if ( errno = = ErrorNumber . NoError )
result = sectorsToDo = = 1
? outputFormat . WriteSectorTag ( sector , doneSectors + track . StartSector , tag )
: outputFormat . WriteSectorsTag ( sector , doneSectors + track . StartSector ,
sectorsToDo , tag ) ;
else
{
result = true ;
if ( ForceChecked )
{
warning = true ;
2022-03-07 07:36:44 +00:00
AaruConsole . ErrorWriteLine ( "Error {0} reading tag for sector {1}, continuing..." , errno ,
doneSectors ) ;
2022-03-06 13:29:38 +00:00
}
else
{
await Dispatcher . UIThread . InvokeAsync ( action : async ( ) = > await MessageBoxManager .
GetMessageBoxStandardWindow ( "Error" ,
$"Error {errno} reading tag for sector {doneSectors}, not continuing..." ,
icon : Icon . Error ) .
ShowDialog ( _view ) ) ;
return ;
}
}
if ( ! result )
if ( ForceChecked )
{
warning = true ;
AaruConsole . ErrorWriteLine ( "Error {0} writing tag for sector {1}, continuing..." ,
outputFormat . ErrorMessage , doneSectors ) ;
}
else
{
await Dispatcher . UIThread . InvokeAsync ( action : async ( ) = > await MessageBoxManager .
GetMessageBoxStandardWindow ( "Error" ,
$"Error {outputFormat.ErrorMessage} writing tag for sector {doneSectors}, not continuing..." ,
icon : Icon . Error ) .
ShowDialog ( _view ) ) ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
return ;
}
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
doneSectors + = sectorsToDo ;
}
}
2020-04-13 04:40:35 +01:00
}
2022-03-06 13:29:38 +00:00
}
await Dispatcher . UIThread . InvokeAsync ( ( ) = >
{
Progress2Visible = false ;
Progress2Visible = false ;
} ) ;
bool ret ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
if ( _dumpHardware ! = null & &
! _cancel )
{
2020-04-13 04:40:35 +01:00
await Dispatcher . UIThread . InvokeAsync ( ( ) = >
{
2022-03-06 13:29:38 +00:00
ProgressText = "Writing dump hardware list to output image." ;
ProgressValue + + ;
2020-04-13 04:40:35 +01:00
} ) ;
2022-03-06 13:29:38 +00:00
ret = outputFormat . SetDumpHardware ( _dumpHardware ) ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
if ( ! ret )
AaruConsole . WriteLine ( "Error {0} writing dump hardware list to output image." ,
outputFormat . ErrorMessage ) ;
}
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
ret = false ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
if ( _cicmMetadata ! = null & &
! _cancel )
{
await Dispatcher . UIThread . InvokeAsync ( ( ) = >
2020-04-13 04:40:35 +01:00
{
2022-03-06 13:29:38 +00:00
ProgressText = "Writing CICM XML metadata to output image." ;
ProgressValue + + ;
} ) ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
outputFormat . SetCicmMetadata ( _cicmMetadata ) ;
if ( ! ret )
AaruConsole . WriteLine ( "Error {0} writing CICM XML metadata to output image." ,
outputFormat . ErrorMessage ) ;
}
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
await Dispatcher . UIThread . InvokeAsync ( ( ) = >
{
ProgressText = "Closing output image." ;
ProgressIndeterminate = true ;
} ) ;
if ( _cancel )
{
2020-04-13 04:40:35 +01:00
await Dispatcher . UIThread . InvokeAsync ( action : async ( ) = >
{
2022-03-06 13:29:38 +00:00
await MessageBoxManager .
GetMessageBoxStandardWindow ( "Error" , "Operation canceled, the output file is not correct." ,
icon : Icon . Error ) . ShowDialog ( _view ) ;
2020-04-13 04:40:35 +01:00
CloseVisible = true ;
StopVisible = false ;
ProgressVisible = false ;
} ) ;
2022-03-06 13:29:38 +00:00
return ;
2020-04-13 04:40:35 +01:00
}
2022-03-06 13:29:38 +00:00
if ( ! outputFormat . Close ( ) )
2020-04-13 04:40:35 +01:00
{
2022-03-06 13:29:38 +00:00
await Dispatcher . UIThread . InvokeAsync ( action : async ( ) = > await MessageBoxManager .
GetMessageBoxStandardWindow ( "Error" ,
$"Error {outputFormat.ErrorMessage} closing output image... Contents are not correct." ,
icon : Icon . Error ) .
ShowDialog ( _view ) ) ;
return ;
2020-04-13 04:40:35 +01:00
}
2022-03-06 13:29:38 +00:00
await Dispatcher . UIThread . InvokeAsync ( action : async ( ) = >
{
await MessageBoxManager . GetMessageBoxStandardWindow ( warning ? "Warning" : "Conversion success" ,
warning
? "Some warnings happened. Check console for more information. Image should be correct."
: "Image converted successfully." ,
icon : warning ? Icon . Warning : Icon . Info ) .
ShowDialog ( _view ) ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
CloseVisible = true ;
StopVisible = false ;
ProgressVisible = false ;
} ) ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
Statistics . AddCommand ( "convert-image" ) ;
}
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
void ExecuteCloseCommand ( ) = > _view . Close ( ) ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
internal void ExecuteStopCommand ( )
{
_cancel = true ;
StopEnabled = false ;
}
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
/ * TODO
void OnCmbFormatSelectedIndexChanged ( )
{
txtDestination . Text = "" ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
if ( ! ( cmbFormat . SelectedValue is IWritableImage plugin ) )
{
grpOptions . Visible = false ;
btnDestination . Enabled = false ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
return ;
}
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
btnDestination . Enabled = true ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
if ( ! plugin . SupportedOptions . Any ( ) )
{
grpOptions . Content = null ;
grpOptions . Visible = false ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
return ;
}
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
chkForce . Visible = false ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
foreach ( MediaTagType mediaTag in inputFormat . Info . ReadableMediaTags )
{
if ( plugin . SupportedMediaTags . Contains ( mediaTag ) )
continue ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
chkForce . Visible = true ;
ForceChecked = true ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
break ;
}
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
foreach ( SectorTagType sectorTag in inputFormat . Info . ReadableSectorTags )
{
if ( plugin . SupportedSectorTags . Contains ( sectorTag ) )
continue ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
chkForce . Visible = true ;
ForceChecked = true ;
break ;
2020-04-13 04:40:35 +01:00
}
2022-03-06 13:29:38 +00:00
grpOptions . Visible = true ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
var stkImageOptions = new StackLayout
{
Orientation = Orientation . Vertical
} ;
foreach ( ( string name , Type type , string description , object @default ) option in plugin . SupportedOptions )
switch ( option . type . ToString ( ) )
{
case "System.Boolean" :
var optBoolean = new CheckBox ( ) ;
optBoolean . ID = "opt" + option . name ;
optBoolean . Text = option . description ;
optBooleanChecked = ( bool ) option . @default ;
stkImageOptions . Items . Add ( optBoolean ) ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
break ;
case "System.SByte" :
case "System.Int16" :
case "System.Int32" :
case "System.Int64" :
var stkNumber = new StackLayout ( ) ;
stkNumber . Orientation = Orientation . Horizontal ;
var optNumber = new NumericStepper ( ) ;
optNumber . ID = "opt" + option . name ;
optNumber . Value = Convert . ToDouble ( option . @default ) ;
stkNumber . Items . Add ( optNumber ) ;
var lblNumber = new Label ( ) ;
lblNumber . Text = option . description ;
stkNumber . Items . Add ( lblNumber ) ;
stkImageOptions . Items . Add ( stkNumber ) ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
break ;
case "System.Byte" :
case "System.UInt16" :
case "System.UInt32" :
case "System.UInt64" :
var stkUnsigned = new StackLayout ( ) ;
stkUnsigned . Orientation = Orientation . Horizontal ;
var optUnsigned = new NumericStepper ( ) ;
optUnsigned . ID = "opt" + option . name ;
optUnsigned . MinValue = 0 ;
optUnsigned . Value = Convert . ToDouble ( option . @default ) ;
stkUnsigned . Items . Add ( optUnsigned ) ;
var lblUnsigned = new Label ( ) ;
lblUnsigned . Text = option . description ;
stkUnsigned . Items . Add ( lblUnsigned ) ;
stkImageOptions . Items . Add ( stkUnsigned ) ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
break ;
case "System.Single" :
case "System.Double" :
var stkFloat = new StackLayout ( ) ;
stkFloat . Orientation = Orientation . Horizontal ;
var optFloat = new NumericStepper ( ) ;
optFloat . ID = "opt" + option . name ;
optFloat . DecimalPlaces = 2 ;
optFloat . Value = Convert . ToDouble ( option . @default ) ;
stkFloat . Items . Add ( optFloat ) ;
var lblFloat = new Label ( ) ;
lblFloat . Text = option . description ;
stkFloat . Items . Add ( lblFloat ) ;
stkImageOptions . Items . Add ( stkFloat ) ;
break ;
case "System.Guid" :
// TODO
break ;
case "System.String" :
var stkString = new StackLayout ( ) ;
stkString . Orientation = Orientation . Horizontal ;
var lblString = new Label ( ) ;
lblString . Text = option . description ;
stkString . Items . Add ( lblString ) ;
var optString = new TextBox ( ) ;
optString . ID = "opt" + option . name ;
optString . Text = ( string ) option . @default ;
stkString . Items . Add ( optString ) ;
stkImageOptions . Items . Add ( stkString ) ;
break ;
}
grpOptions . Content = stkImageOptions ;
2020-04-13 04:40:35 +01:00
}
2022-03-06 13:29:38 +00:00
* /
async void ExecuteDestinationCommand ( )
{
if ( SelectedPlugin is null )
return ;
var dlgDestination = new SaveFileDialog
{
Title = "Choose destination file"
} ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
dlgDestination . Filters . Add ( new FileDialogFilter
{
Name = SelectedPlugin . Plugin . Name ,
Extensions = SelectedPlugin . Plugin . KnownExtensions . ToList ( )
} ) ;
string result = await dlgDestination . ShowAsync ( _view ) ;
if ( result is null | |
result . Length ! = 1 )
{
DestinationText = "" ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
return ;
2020-04-13 04:40:35 +01:00
}
2022-03-06 13:29:38 +00:00
if ( string . IsNullOrEmpty ( Path . GetExtension ( result ) ) )
result + = SelectedPlugin . Plugin . KnownExtensions . First ( ) ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
DestinationText = result ;
}
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
void ExecuteCreatorCommand ( ) = > CreatorText = _inputFormat . Info . Creator ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
void ExecuteMediaTitleCommand ( ) = > MediaTitleText = _inputFormat . Info . MediaTitle ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
void ExecuteCommentsCommand ( ) = > CommentsText = _inputFormat . Info . Comments ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
void ExecuteMediaManufacturerCommand ( ) = > MediaManufacturerText = _inputFormat . Info . MediaManufacturer ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
void ExecuteMediaModelCommand ( ) = > MediaModelText = _inputFormat . Info . MediaModel ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
void ExecuteMediaSerialNumberCommand ( ) = > MediaSerialNumberText = _inputFormat . Info . MediaSerialNumber ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
void ExecuteMediaBarcodeCommand ( ) = > MediaBarcodeText = _inputFormat . Info . MediaBarcode ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
void ExecuteMediaPartNumberCommand ( ) = > MediaPartNumberText = _inputFormat . Info . MediaPartNumber ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
void ExecuteMediaSequenceCommand ( ) = > MediaSequenceValue = _inputFormat . Info . MediaSequence ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
void ExecuteLastMediaSequenceCommand ( ) = > LastMediaSequenceValue = _inputFormat . Info . LastMediaSequence ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
void ExecuteDriveManufacturerCommand ( ) = > DriveManufacturerText = _inputFormat . Info . DriveManufacturer ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
void ExecuteDriveModelCommand ( ) = > DriveModelText = _inputFormat . Info . DriveModel ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
void ExecuteDriveSerialNumberCommand ( ) = > DriveSerialNumberText = _inputFormat . Info . DriveSerialNumber ;
2020-04-13 04:40:35 +01:00
2022-03-07 07:36:44 +00:00
void ExecuteDriveFirmwareRevisionCommand ( ) = > DriveFirmwareRevisionText = _inputFormat . Info . DriveFirmwareRevision ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
void ExecuteCicmXmlFromImageCommand ( )
{
CicmXmlText = "<From image>" ;
_cicmMetadata = _inputFormat . CicmMetadata ;
}
async void ExecuteCicmXmlCommand ( )
{
_cicmMetadata = null ;
CicmXmlText = "" ;
var dlgMetadata = new OpenFileDialog
{
Title = "Choose existing metadata sidecar"
} ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
dlgMetadata . Filters . Add ( new FileDialogFilter
{
Name = "CICM XML metadata" ,
Extensions = new List < string > ( new [ ]
2020-04-13 04:40:35 +01:00
{
2022-03-06 13:29:38 +00:00
".xml"
} )
} ) ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
string [ ] result = await dlgMetadata . ShowAsync ( _view ) ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
if ( result is null | |
result . Length ! = 1 )
return ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
var sidecarXs = new XmlSerializer ( typeof ( CICMMetadataType ) ) ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
try
{
var sr = new StreamReader ( result [ 0 ] ) ;
_cicmMetadata = ( CICMMetadataType ) sidecarXs . Deserialize ( sr ) ;
sr . Close ( ) ;
CicmXmlText = result [ 0 ] ;
2020-04-13 04:40:35 +01:00
}
2022-03-06 13:29:38 +00:00
catch
2020-04-13 04:40:35 +01:00
{
2022-03-06 13:29:38 +00:00
await MessageBoxManager . GetMessageBoxStandardWindow ( "Error" , "Incorrect metadata sidecar file..." ,
icon : Icon . Error ) . ShowDialog ( _view ) ;
2020-04-13 04:40:35 +01:00
}
2022-03-06 13:29:38 +00:00
}
void ExecuteResumeFileFromImageCommand ( )
{
ResumeFileText = "<From image>" ;
_dumpHardware = _inputFormat . DumpHardware ;
}
async void ExecuteResumeFileCommand ( )
{
_dumpHardware = null ;
ResumeFileText = "" ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
var dlgMetadata = new OpenFileDialog
2020-04-13 04:40:35 +01:00
{
2022-03-06 13:29:38 +00:00
Title = "Choose existing resume file"
} ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
dlgMetadata . Filters . Add ( new FileDialogFilter
{
Name = "CICM XML metadata" ,
Extensions = new List < string > ( new [ ]
2020-04-13 04:40:35 +01:00
{
2022-03-06 13:29:38 +00:00
".xml"
} )
} ) ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
string [ ] result = await dlgMetadata . ShowAsync ( _view ) ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
if ( result is null | |
result . Length ! = 1 )
return ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
var sidecarXs = new XmlSerializer ( typeof ( Resume ) ) ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
try
{
var sr = new StreamReader ( result [ 0 ] ) ;
var resume = ( Resume ) sidecarXs . Deserialize ( sr ) ;
2020-04-13 04:40:35 +01:00
2022-03-06 13:29:38 +00:00
if ( resume . Tries ? . Any ( ) = = false )
2020-04-13 04:40:35 +01:00
{
2022-03-06 13:29:38 +00:00
_dumpHardware = resume . Tries ;
ResumeFileText = result [ 0 ] ;
2020-04-13 04:40:35 +01:00
}
2022-03-06 13:29:38 +00:00
else
2020-04-13 04:40:35 +01:00
await MessageBoxManager .
2022-03-07 07:36:44 +00:00
GetMessageBoxStandardWindow ( "Error" , "Resume file does not contain dump hardware information..." ,
2022-03-06 13:29:38 +00:00
icon : Icon . Error ) . ShowDialog ( _view ) ;
sr . Close ( ) ;
}
catch
{
2022-03-07 07:36:44 +00:00
await MessageBoxManager . GetMessageBoxStandardWindow ( "Error" , "Incorrect resume file..." , icon : Icon . Error ) .
ShowDialog ( _view ) ;
2020-04-13 04:40:35 +01:00
}
}
}