2018-10-23 23:59:33 +01:00
// /***************************************************************************
2020-02-27 12:31:25 +00:00
// Aaru Data Preservation Suite
2018-10-23 23:59:33 +01:00
// ----------------------------------------------------------------------------
//
// Filename : frmImageConvert.xeto.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// Component : Image conversion window.
//
// --[ Description ] ----------------------------------------------------------
//
// Implements converting media image.
//
// --[ 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/>.
//
// ----------------------------------------------------------------------------
2020-01-03 17:51:30 +00:00
// Copyright © 2011-2020 Natalia Portillo
2018-10-23 23:59:33 +01:00
// ****************************************************************************/
using System ;
using System.Collections.Generic ;
using System.Collections.ObjectModel ;
using System.Globalization ;
using System.IO ;
using System.Linq ;
using System.Threading ;
using System.Xml.Serialization ;
2020-02-27 00:33:26 +00:00
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 ;
2018-10-23 23:59:33 +01:00
using Eto.Forms ;
using Eto.Serialization.Xaml ;
using Schemas ;
2020-02-27 00:33:26 +00:00
using ImageInfo = Aaru . CommonTypes . Structs . ImageInfo ;
using Version = Aaru . CommonTypes . Interop . Version ;
2018-10-23 23:59:33 +01:00
2020-02-27 00:33:26 +00:00
namespace Aaru.Gui.Forms
2018-10-23 23:59:33 +01:00
{
public class frmImageConvert : Form
{
2020-02-29 18:03:35 +00:00
readonly IMediaImage inputFormat ;
2018-10-23 23:59:33 +01:00
bool cancel ;
CICMMetadataType cicmMetadata ;
List < DumpHardwareType > dumpHardware ;
public frmImageConvert ( IMediaImage inputFormat , string imageSource )
{
this . inputFormat = inputFormat ;
XamlReader . Load ( this ) ;
cancel = false ;
txtSource . Text = imageSource ;
btnCreator . Visible = ! string . IsNullOrWhiteSpace ( inputFormat . Info . Creator ) ;
btnMediaTitle . Visible = ! string . IsNullOrWhiteSpace ( inputFormat . Info . MediaTitle ) ;
btnComments . Visible = ! string . IsNullOrWhiteSpace ( inputFormat . Info . Comments ) ;
btnMediaManufacturer . Visible = ! string . IsNullOrWhiteSpace ( inputFormat . Info . MediaManufacturer ) ;
btnMediaModel . Visible = ! string . IsNullOrWhiteSpace ( inputFormat . Info . MediaModel ) ;
btnMediaSerialNumber . Visible = ! string . IsNullOrWhiteSpace ( inputFormat . Info . MediaSerialNumber ) ;
btnMediaBarcode . Visible = ! string . IsNullOrWhiteSpace ( inputFormat . Info . MediaBarcode ) ;
btnMediaPartNumber . Visible = ! string . IsNullOrWhiteSpace ( inputFormat . Info . MediaPartNumber ) ;
2020-02-29 18:03:35 +00:00
btnMediaSequence . Visible = inputFormat . Info . MediaSequence ! = 0 & & inputFormat . Info . LastMediaSequence ! = 0 ;
2018-10-23 23:59:33 +01:00
btnLastMediaSequence . Visible =
inputFormat . Info . MediaSequence ! = 0 & & inputFormat . Info . LastMediaSequence ! = 0 ;
2020-02-29 18:03:35 +00:00
2018-10-23 23:59:33 +01:00
btnDriveManufacturer . Visible = ! string . IsNullOrWhiteSpace ( inputFormat . Info . DriveManufacturer ) ;
btnDriveModel . Visible = ! string . IsNullOrWhiteSpace ( inputFormat . Info . DriveModel ) ;
btnDriveSerialNumber . Visible = ! string . IsNullOrWhiteSpace ( inputFormat . Info . DriveSerialNumber ) ;
btnDriveFirmwareRevision . Visible = ! string . IsNullOrWhiteSpace ( inputFormat . Info . DriveFirmwareRevision ) ;
ObservableCollection < IWritableImage > lstPlugins = new ObservableCollection < IWritableImage > ( ) ;
PluginBase plugins = GetPluginBase . Instance ;
2020-02-29 18:03:35 +00:00
2018-10-23 23:59:33 +01:00
foreach ( IWritableImage plugin in
plugins . WritableImages . Values . Where ( p = > p . SupportedMediaTypes . Contains ( inputFormat . Info . MediaType ) ) )
lstPlugins . Add ( plugin ) ;
2020-02-29 18:03:35 +00:00
2018-10-23 23:59:33 +01:00
cmbFormat . ItemTextBinding = Binding . Property ( ( IWritableImage p ) = > p . Name ) ;
cmbFormat . ItemKeyBinding = Binding . Property ( ( IWritableImage p ) = > p . Id . ToString ( ) ) ;
cmbFormat . DataStore = lstPlugins ;
btnCicmXmlFromImage . Visible = inputFormat . CicmMetadata ! = null ;
btnResumeFileFromImage . Visible = inputFormat . DumpHardware ! = null & & inputFormat . DumpHardware . Any ( ) ;
cicmMetadata = inputFormat . CicmMetadata ;
2020-02-29 18:03:35 +00:00
dumpHardware = inputFormat . DumpHardware ! = null & & inputFormat . DumpHardware . Any ( ) ? inputFormat . DumpHardware
2018-10-23 23:59:33 +01:00
: null ;
txtCicmXml . Text = cicmMetadata = = null ? "" : "<From image>" ;
txtResumeFile . Text = dumpHardware = = null ? "" : "<From image>" ;
}
protected void OnBtnStart ( object sender , EventArgs e )
{
if ( ! ( cmbFormat . SelectedValue is IWritableImage plugin ) )
{
MessageBox . Show ( "Error trying to find selected plugin" , MessageBoxType . Error ) ;
2020-02-29 18:03:35 +00:00
2018-10-23 23:59:33 +01:00
return ;
}
new Thread ( DoWork ) . Start ( plugin ) ;
}
void DoWork ( object plugin )
{
bool warning = false ;
2020-02-29 18:03:35 +00:00
2018-10-23 23:59:33 +01:00
if ( ! ( plugin is IWritableImage outputFormat ) )
{
MessageBox . Show ( "Error trying to find selected plugin" , MessageBoxType . Error ) ;
2020-02-29 18:03:35 +00:00
2018-10-23 23:59:33 +01:00
return ;
}
2020-02-29 18:03:35 +00:00
var inputOptical = inputFormat as IOpticalMediaImage ;
var outputOptical = outputFormat as IWritableOpticalImage ;
2019-01-20 20:11:10 +00:00
2018-10-23 23:59:33 +01:00
List < Track > tracks ;
2020-02-29 18:03:35 +00:00
try
{
tracks = inputOptical ? . Tracks ;
}
catch ( Exception )
{
tracks = null ;
}
2018-10-23 23:59:33 +01:00
// Prepare UI
Application . Instance . Invoke ( ( ) = >
{
btnClose . Visible = false ;
btnStart . Visible = false ;
btnStop . Visible = true ;
stkProgress . Visible = true ;
stkOptions . Visible = false ;
btnStop . Enabled = true ;
cmbFormat . ReadOnly = true ;
btnDestination . Visible = false ;
prgProgress . MaxValue = 1 ;
prgProgress . MaxValue + = inputFormat . Info . ReadableMediaTags . Count ;
prgProgress . MaxValue + + ;
2020-02-29 18:03:35 +00:00
if ( tracks ! = null )
prgProgress . MaxValue + + ;
2018-10-23 23:59:33 +01:00
if ( tracks = = null )
{
prgProgress . MaxValue + = 2 ;
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-02-29 18:03:35 +00:00
if ( chkForce . Checked = = true & &
! outputFormat . SupportedSectorTags . Contains ( tag ) )
continue ;
2018-10-23 23:59:33 +01:00
prgProgress . MaxValue + + ;
}
}
else
{
prgProgress . MaxValue + = tracks . Count ;
foreach ( SectorTagType tag in inputFormat . Info . ReadableSectorTags . OrderBy ( t = > t ) )
{
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-02-29 18:03:35 +00:00
if ( chkForce . Checked = = true & &
! outputFormat . SupportedSectorTags . Contains ( tag ) )
continue ;
2018-10-23 23:59:33 +01:00
prgProgress . MaxValue + = tracks . Count ;
}
}
2020-02-29 18:03:35 +00:00
if ( dumpHardware ! = null )
prgProgress . MaxValue + + ;
if ( cicmMetadata ! = null )
prgProgress . MaxValue + + ;
2018-10-23 23:59:33 +01:00
prgProgress . MaxValue + + ;
} ) ;
foreach ( MediaTagType mediaTag in inputFormat . Info . ReadableMediaTags )
{
2020-02-29 18:03:35 +00:00
if ( outputFormat . SupportedMediaTags . Contains ( mediaTag ) | |
chkForce . Checked = = true )
continue ;
2018-10-23 23:59:33 +01:00
Application . Instance . Invoke ( ( ) = >
{
2020-02-29 18:03:35 +00:00
MessageBox . Show ( $"Converting image will lose media tag {mediaTag}, not continuing..." ,
MessageBoxType . Error ) ;
2018-10-23 23:59:33 +01:00
} ) ;
return ;
}
bool useLong = inputFormat . Info . ReadableSectorTags . Count ! = 0 ;
foreach ( SectorTagType sectorTag in inputFormat . Info . ReadableSectorTags )
{
2020-02-29 18:03:35 +00:00
if ( outputFormat . SupportedSectorTags . Contains ( sectorTag ) )
continue ;
2018-10-23 23:59:33 +01:00
if ( chkForce . Checked = = true )
{
2020-02-29 18:03:35 +00:00
if ( sectorTag ! = SectorTagType . CdTrackFlags & &
sectorTag ! = SectorTagType . CdTrackIsrc & &
sectorTag ! = SectorTagType . CdSectorSubchannel )
useLong = false ;
2018-10-23 23:59:33 +01:00
continue ;
}
Application . Instance . Invoke ( ( ) = >
{
2020-02-29 18:03:35 +00:00
MessageBox . Show ( $"Converting image will lose sector tag {sectorTag}, not continuing..." ,
MessageBoxType . Error ) ;
2018-10-23 23:59:33 +01:00
} ) ;
2020-02-29 18:03:35 +00:00
2018-10-23 23:59:33 +01:00
return ;
}
Dictionary < string , string > parsedOptions = new Dictionary < string , string > ( ) ;
if ( grpOptions . Content is StackLayout stkImageOptions )
foreach ( Control option in stkImageOptions . Children )
{
2020-02-29 18:03:35 +00:00
if ( cancel )
break ;
2018-10-23 23:59:33 +01:00
string value ;
switch ( option )
{
case CheckBox optBoolean :
value = optBoolean . Checked ? . ToString ( ) ;
2020-02-29 18:03:35 +00:00
2018-10-23 23:59:33 +01:00
break ;
case NumericStepper optNumber :
value = optNumber . Value . ToString ( CultureInfo . CurrentCulture ) ;
2020-02-29 18:03:35 +00:00
2018-10-23 23:59:33 +01:00
break ;
case TextBox optString :
value = optString . Text ;
2020-02-29 18:03:35 +00:00
2018-10-23 23:59:33 +01:00
break ;
default : continue ;
}
string key = option . ID . Substring ( 3 ) ;
parsedOptions . Add ( key , value ) ;
}
Application . Instance . Invoke ( ( ) = >
{
lblProgress . Text = "Creating output image" ;
lblProgress2 . Text = "" ;
prgProgress2 . Indeterminate = true ;
} ) ;
if ( ! outputFormat . Create ( txtDestination . Text , inputFormat . Info . MediaType , parsedOptions ,
inputFormat . Info . Sectors , inputFormat . Info . SectorSize ) )
{
Application . Instance . Invoke ( ( ) = >
{
2020-02-29 18:03:35 +00:00
MessageBox . Show ( $"Error {outputFormat.ErrorMessage} creating output image." , MessageBoxType . Error ) ;
2018-10-23 23:59:33 +01:00
} ) ;
2020-02-27 23:48:41 +00:00
AaruConsole . ErrorWriteLine ( "Error {0} creating output image." , outputFormat . ErrorMessage ) ;
2020-02-29 18:03:35 +00:00
2018-10-23 23:59:33 +01:00
return ;
}
Application . Instance . Invoke ( ( ) = >
{
lblProgress . Text = "Setting image metadata" ;
prgProgress . Value + + ;
lblProgress2 . Text = "" ;
prgProgress2 . Indeterminate = true ;
} ) ;
2020-02-29 18:03:35 +00:00
var metadata = new ImageInfo
2018-10-23 23:59:33 +01:00
{
2020-02-29 18:03:35 +00:00
Application = "Aaru" , ApplicationVersion = Version . GetVersion ( ) ,
Comments = txtComments . Text ,
Creator = txtCreator . Text , DriveFirmwareRevision = txtDriveFirmwareRevision . Text ,
DriveManufacturer = txtDriveManufacturer . Text , DriveModel = txtDriveModel . Text ,
DriveSerialNumber = txtDriveSerialNumber . Text , LastMediaSequence = ( int ) numLastMediaSequence . Value ,
MediaBarcode = txtMediaBarcode . Text , MediaManufacturer = txtMediaManufacturer . Text ,
MediaModel = txtMediaModel . Text , MediaPartNumber = txtMediaPartNumber . Text ,
MediaSequence = ( int ) numMediaSequence . Value , MediaSerialNumber = txtMediaSerialNumber . Text ,
MediaTitle = txtMediaTitle . Text
2018-10-23 23:59:33 +01:00
} ;
if ( ! cancel )
if ( ! outputFormat . SetMetadata ( metadata ) )
{
2020-02-27 23:48:41 +00:00
AaruConsole . ErrorWrite ( "Error {0} setting metadata, " , outputFormat . ErrorMessage ) ;
2020-02-29 18:03:35 +00:00
2018-10-23 23:59:33 +01:00
if ( chkForce . Checked ! = true )
{
Application . Instance . Invoke ( ( ) = >
{
2020-02-29 18:03:35 +00:00
MessageBox . Show ( $"Error {outputFormat.ErrorMessage} setting metadata, not continuing..." ,
MessageBoxType . Error ) ;
2018-10-23 23:59:33 +01:00
} ) ;
2020-02-27 23:48:41 +00:00
AaruConsole . ErrorWriteLine ( "not continuing..." ) ;
2020-02-29 18:03:35 +00:00
2018-10-23 23:59:33 +01:00
return ;
}
warning = true ;
2020-02-27 23:48:41 +00:00
AaruConsole . ErrorWriteLine ( "continuing..." ) ;
2018-10-23 23:59:33 +01:00
}
2020-02-29 18:03:35 +00:00
if ( tracks ! = null & &
! cancel & &
outputOptical ! = null )
2018-10-23 23:59:33 +01:00
{
Application . Instance . Invoke ( ( ) = >
{
lblProgress . Text = "Setting tracks list" ;
prgProgress . Value + + ;
lblProgress2 . Text = "" ;
prgProgress2 . Indeterminate = true ;
} ) ;
2019-01-20 20:11:10 +00:00
if ( ! outputOptical . SetTracks ( tracks ) )
2018-10-23 23:59:33 +01:00
{
Application . Instance . Invoke ( ( ) = >
{
2020-02-29 18:03:35 +00:00
MessageBox . Show ( $"Error {outputFormat.ErrorMessage} sending tracks list to output image." ,
MessageBoxType . Error ) ;
2018-10-23 23:59:33 +01:00
} ) ;
2020-02-27 23:48:41 +00:00
AaruConsole . ErrorWriteLine ( "Error {0} sending tracks list to output image." ,
2020-02-29 18:03:35 +00:00
outputFormat . ErrorMessage ) ;
2018-10-23 23:59:33 +01:00
return ;
}
}
foreach ( MediaTagType mediaTag in inputFormat . Info . ReadableMediaTags )
{
2020-02-29 18:03:35 +00:00
if ( cancel )
break ;
2018-10-23 23:59:33 +01:00
Application . Instance . Invoke ( ( ) = >
{
lblProgress . Text = $"Converting media tag {mediaTag}" ;
prgProgress . Value + + ;
lblProgress2 . Text = "" ;
prgProgress2 . Indeterminate = true ;
} ) ;
2020-02-29 18:03:35 +00:00
if ( chkForce . Checked = = true & &
! outputFormat . SupportedMediaTags . Contains ( mediaTag ) )
continue ;
2018-10-23 23:59:33 +01:00
byte [ ] tag = inputFormat . ReadDiskTag ( mediaTag ) ;
2020-02-29 18:03:35 +00:00
if ( outputFormat . WriteMediaTag ( tag , mediaTag ) )
continue ;
2018-10-23 23:59:33 +01:00
if ( chkForce . Checked = = true )
{
warning = true ;
2020-02-27 23:48:41 +00:00
AaruConsole . ErrorWriteLine ( "Error {0} writing media tag, continuing..." , outputFormat . ErrorMessage ) ;
2018-10-23 23:59:33 +01:00
}
else
{
Application . Instance . Invoke ( ( ) = >
{
2020-02-29 18:03:35 +00:00
MessageBox . Show ( $"Error {outputFormat.ErrorMessage} writing media tag, not continuing..." ,
MessageBoxType . Error ) ;
2018-10-23 23:59:33 +01:00
} ) ;
2020-02-27 23:48:41 +00:00
AaruConsole . ErrorWriteLine ( "Error {0} writing media tag, not continuing..." ,
2020-02-29 18:03:35 +00:00
outputFormat . ErrorMessage ) ;
2018-10-23 23:59:33 +01:00
return ;
}
}
ulong doneSectors = 0 ;
2020-02-29 18:03:35 +00:00
if ( tracks = = null & &
! cancel )
2018-10-23 23:59:33 +01:00
{
Application . Instance . Invoke ( ( ) = >
{
lblProgress . Text =
$"Setting geometry to {inputFormat.Info.Cylinders} cylinders, {inputFormat.Info.Heads} heads and {inputFormat.Info.SectorsPerTrack} sectors per track" ;
2020-02-29 18:03:35 +00:00
2018-10-23 23:59:33 +01:00
prgProgress . Value + + ;
lblProgress2 . Text = "" ;
prgProgress2 . Indeterminate = true ;
} ) ;
if ( ! outputFormat . SetGeometry ( inputFormat . Info . Cylinders , inputFormat . Info . Heads ,
inputFormat . Info . SectorsPerTrack ) )
{
warning = true ;
2020-02-29 18:03:35 +00:00
2020-02-27 23:48:41 +00:00
AaruConsole . ErrorWriteLine ( "Error {0} setting geometry, image may be incorrect, continuing..." ,
2020-02-29 18:03:35 +00:00
outputFormat . ErrorMessage ) ;
2018-10-23 23:59:33 +01:00
}
Application . Instance . Invoke ( ( ) = >
{
lblProgress . Text = "Converting sectors" ;
prgProgress . Value + + ;
lblProgress2 . Text = "" ;
prgProgress2 . Indeterminate = false ;
prgProgress2 . MaxValue = ( int ) ( inputFormat . Info . Sectors / numCount . Value ) ;
} ) ;
while ( doneSectors < inputFormat . Info . Sectors )
{
2020-02-29 18:03:35 +00:00
if ( cancel )
break ;
2018-10-23 23:59:33 +01:00
byte [ ] sector ;
uint sectorsToDo ;
2020-02-29 18:03:35 +00:00
2018-10-23 23:59:33 +01:00
if ( inputFormat . Info . Sectors - doneSectors > = ( ulong ) numCount . Value )
2020-02-29 18:03:35 +00:00
sectorsToDo = ( uint ) numCount . Value ;
else
sectorsToDo = ( uint ) ( inputFormat . Info . Sectors - doneSectors ) ;
2018-10-23 23:59:33 +01:00
ulong sectors = doneSectors ;
2020-02-29 18:03:35 +00:00
2018-10-23 23:59:33 +01:00
Application . Instance . Invoke ( ( ) = >
{
lblProgress2 . Text =
$"Converting sectors {sectors} to {sectors + sectorsToDo} ({sectors / (double)inputFormat.Info.Sectors:P2} done)" ;
2020-02-29 18:03:35 +00:00
2018-10-23 23:59:33 +01:00
;
prgProgress2 . Value = ( int ) ( sectors / numCount . Value ) ;
} ) ;
bool result ;
2020-02-29 18:03:35 +00:00
2018-10-23 23:59:33 +01:00
if ( useLong )
if ( sectorsToDo = = 1 )
{
sector = inputFormat . ReadSectorLong ( doneSectors ) ;
result = outputFormat . WriteSectorLong ( sector , doneSectors ) ;
}
else
{
sector = inputFormat . ReadSectorsLong ( doneSectors , sectorsToDo ) ;
result = outputFormat . WriteSectorsLong ( sector , doneSectors , sectorsToDo ) ;
}
else
{
if ( sectorsToDo = = 1 )
{
sector = inputFormat . ReadSector ( doneSectors ) ;
result = outputFormat . WriteSector ( sector , doneSectors ) ;
}
else
{
sector = inputFormat . ReadSectors ( doneSectors , sectorsToDo ) ;
result = outputFormat . WriteSectors ( sector , doneSectors , sectorsToDo ) ;
}
}
if ( ! result )
if ( chkForce . Checked = = true )
{
warning = true ;
2020-02-29 18:03:35 +00:00
2020-02-27 23:48:41 +00:00
AaruConsole . ErrorWriteLine ( "Error {0} writing sector {1}, continuing..." ,
2020-02-29 18:03:35 +00:00
outputFormat . ErrorMessage , doneSectors ) ;
2018-10-23 23:59:33 +01:00
}
else
{
Application . Instance . Invoke ( ( ) = >
{
2020-02-29 18:03:35 +00:00
MessageBox .
Show ( $"Error {outputFormat.ErrorMessage} writing sector {doneSectors}, not continuing..." ,
2018-10-23 23:59:33 +01:00
MessageBoxType . Error ) ;
} ) ;
2020-02-27 23:48:41 +00:00
AaruConsole . ErrorWriteLine ( "Error {0} writing sector {1}, not continuing..." ,
2020-02-29 18:03:35 +00:00
outputFormat . ErrorMessage , doneSectors ) ;
2018-10-23 23:59:33 +01:00
return ;
}
doneSectors + = sectorsToDo ;
}
Application . Instance . Invoke ( ( ) = >
{
lblProgress2 . Text =
$"Converting sectors {inputFormat.Info.Sectors} to {inputFormat.Info.Sectors} ({1.0:P2} done)" ;
2020-02-29 18:03:35 +00:00
2018-10-23 23:59:33 +01:00
;
prgProgress2 . Value = prgProgress2 . MaxValue ;
} ) ;
foreach ( SectorTagType tag in inputFormat . Info . ReadableSectorTags )
{
2020-02-29 18:03:35 +00:00
if ( ! useLong | | cancel )
break ;
2018-10-23 23:59:33 +01:00
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-02-29 18:03:35 +00:00
if ( chkForce . Checked = = true & &
! outputFormat . SupportedSectorTags . Contains ( tag ) )
continue ;
2018-10-23 23:59:33 +01:00
Application . Instance . Invoke ( ( ) = >
{
lblProgress . Text = $"Converting tag {tag}" ;
prgProgress . Value + + ;
lblProgress2 . Text = "" ;
prgProgress2 . Indeterminate = false ;
prgProgress2 . MaxValue = ( int ) ( inputFormat . Info . Sectors / numCount . Value ) ;
} ) ;
doneSectors = 0 ;
2020-02-29 18:03:35 +00:00
2018-10-23 23:59:33 +01:00
while ( doneSectors < inputFormat . Info . Sectors )
{
2020-02-29 18:03:35 +00:00
if ( cancel )
break ;
2018-10-23 23:59:33 +01:00
byte [ ] sector ;
uint sectorsToDo ;
2020-02-29 18:03:35 +00:00
2018-10-23 23:59:33 +01:00
if ( inputFormat . Info . Sectors - doneSectors > = ( ulong ) numCount . Value )
2020-02-29 18:03:35 +00:00
sectorsToDo = ( uint ) numCount . Value ;
else
sectorsToDo = ( uint ) ( inputFormat . Info . Sectors - doneSectors ) ;
2018-10-23 23:59:33 +01:00
ulong sectors = doneSectors ;
2020-02-29 18:03:35 +00:00
2018-10-23 23:59:33 +01:00
Application . Instance . Invoke ( ( ) = >
{
lblProgress2 . Text =
$"Converting tag {sectors / (double)inputFormat.Info.Sectors} for sectors {sectors} to {sectors + sectorsToDo} ({sectors / (double)inputFormat.Info.Sectors:P2} done)" ;
2020-02-29 18:03:35 +00:00
2018-10-23 23:59:33 +01:00
prgProgress2 . Value = ( int ) ( sectors / numCount . Value ) ;
} ) ;
bool result ;
2020-02-29 18:03:35 +00:00
2018-10-23 23:59:33 +01:00
if ( sectorsToDo = = 1 )
{
sector = inputFormat . ReadSectorTag ( doneSectors , tag ) ;
result = outputFormat . WriteSectorTag ( sector , doneSectors , tag ) ;
}
else
{
sector = inputFormat . ReadSectorsTag ( doneSectors , sectorsToDo , tag ) ;
result = outputFormat . WriteSectorsTag ( sector , doneSectors , sectorsToDo , tag ) ;
}
if ( ! result )
if ( chkForce . Checked = = true )
{
warning = true ;
2020-02-29 18:03:35 +00:00
2020-02-27 23:48:41 +00:00
AaruConsole . ErrorWriteLine ( "Error {0} writing sector {1}, continuing..." ,
2020-02-29 18:03:35 +00:00
outputFormat . ErrorMessage , doneSectors ) ;
2018-10-23 23:59:33 +01:00
}
else
{
Application . Instance . Invoke ( ( ) = >
{
2020-02-29 18:03:35 +00:00
MessageBox .
Show ( $"Error {outputFormat.ErrorMessage} writing sector {doneSectors}, not continuing..." ,
2018-10-23 23:59:33 +01:00
MessageBoxType . Error ) ;
} ) ;
2020-02-27 23:48:41 +00:00
AaruConsole . ErrorWriteLine ( "Error {0} writing sector {1}, not continuing..." ,
2020-02-29 18:03:35 +00:00
outputFormat . ErrorMessage , doneSectors ) ;
2018-10-23 23:59:33 +01:00
return ;
}
doneSectors + = sectorsToDo ;
}
Application . Instance . Invoke ( ( ) = >
{
lblProgress2 . Text =
$"Converting tag {tag} for sectors {inputFormat.Info.Sectors} to {inputFormat.Info.Sectors} ({1.0:P2} done)" ;
2020-02-29 18:03:35 +00:00
2018-10-23 23:59:33 +01:00
prgProgress2 . Value = prgProgress2 . MaxValue ;
} ) ;
}
}
else
{
foreach ( Track track in tracks )
{
2020-02-29 18:03:35 +00:00
if ( cancel )
break ;
2018-10-23 23:59:33 +01:00
doneSectors = 0 ;
2020-02-29 18:03:35 +00:00
ulong trackSectors = ( track . TrackEndSector - track . TrackStartSector ) + 1 ;
2018-10-23 23:59:33 +01:00
Application . Instance . Invoke ( ( ) = >
{
lblProgress . Text = $"Converting sectors in track {track.TrackSequence}" ;
prgProgress . Value + + ;
lblProgress2 . Text = "" ;
prgProgress2 . Indeterminate = false ;
prgProgress2 . MaxValue = ( int ) ( trackSectors / numCount . Value ) ;
} ) ;
while ( doneSectors < trackSectors )
{
2020-02-29 18:03:35 +00:00
if ( cancel )
break ;
2018-10-23 23:59:33 +01:00
byte [ ] sector ;
uint sectorsToDo ;
2020-02-29 18:03:35 +00:00
if ( trackSectors - doneSectors > = ( ulong ) numCount . Value )
sectorsToDo = ( uint ) numCount . Value ;
2018-10-23 23:59:33 +01:00
else
2020-02-29 18:03:35 +00:00
sectorsToDo = ( uint ) ( trackSectors - doneSectors ) ;
2018-10-23 23:59:33 +01:00
ulong sectors = doneSectors ;
2020-02-29 18:03:35 +00:00
2018-10-23 23:59:33 +01:00
Application . Instance . Invoke ( ( ) = >
{
lblProgress2 . Text =
$"Converting sectors {sectors + track.TrackStartSector} to {sectors + sectorsToDo + track.TrackStartSector} in track {track.TrackSequence} ({(sectors + track.TrackStartSector) / (double)inputFormat.Info.Sectors:P2} done)" ;
2020-02-29 18:03:35 +00:00
2018-10-23 23:59:33 +01:00
prgProgress2 . Value = ( int ) ( sectors / numCount . Value ) ;
} ) ;
bool result ;
2020-02-29 18:03:35 +00:00
2018-10-23 23:59:33 +01:00
if ( useLong )
if ( sectorsToDo = = 1 )
{
sector = inputFormat . ReadSectorLong ( doneSectors + track . TrackStartSector ) ;
result = outputFormat . WriteSectorLong ( sector , doneSectors + track . TrackStartSector ) ;
}
else
{
sector = inputFormat . ReadSectorsLong ( doneSectors + track . TrackStartSector , sectorsToDo ) ;
2020-02-29 18:03:35 +00:00
2018-10-23 23:59:33 +01:00
result = outputFormat . WriteSectorsLong ( sector , doneSectors + track . TrackStartSector ,
sectorsToDo ) ;
}
else
{
if ( sectorsToDo = = 1 )
{
sector = inputFormat . ReadSector ( doneSectors + track . TrackStartSector ) ;
result = outputFormat . WriteSector ( sector , doneSectors + track . TrackStartSector ) ;
}
else
{
sector = inputFormat . ReadSectors ( doneSectors + track . TrackStartSector , sectorsToDo ) ;
2020-02-29 18:03:35 +00:00
2018-10-23 23:59:33 +01:00
result = outputFormat . WriteSectors ( sector , doneSectors + track . TrackStartSector ,
sectorsToDo ) ;
}
}
if ( ! result )
if ( chkForce . Checked = = true )
{
warning = true ;
2020-02-29 18:03:35 +00:00
2020-02-27 23:48:41 +00:00
AaruConsole . ErrorWriteLine ( "Error {0} writing sector {1}, continuing..." ,
2020-02-29 18:03:35 +00:00
outputFormat . ErrorMessage , doneSectors ) ;
2018-10-23 23:59:33 +01:00
}
else
{
Application . Instance . Invoke ( ( ) = >
{
2020-02-29 18:03:35 +00:00
MessageBox .
Show ( $"Error {outputFormat.ErrorMessage} writing sector {doneSectors}, not continuing..." ,
2018-10-23 23:59:33 +01:00
MessageBoxType . Error ) ;
} ) ;
return ;
}
doneSectors + = sectorsToDo ;
}
}
Application . Instance . Invoke ( ( ) = >
{
lblProgress2 . Text =
$"Converting sectors {inputFormat.Info.Sectors} to {inputFormat.Info.Sectors} in track {tracks.Count} ({1.0:P2} done)" ;
2020-02-29 18:03:35 +00:00
2018-10-23 23:59:33 +01:00
prgProgress2 . Value = prgProgress2 . MaxValue ;
} ) ;
foreach ( SectorTagType tag in inputFormat . Info . ReadableSectorTags . OrderBy ( t = > t ) )
{
2020-02-29 18:03:35 +00:00
if ( ! useLong | | cancel )
break ;
2018-10-23 23:59:33 +01:00
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-02-29 18:03:35 +00:00
if ( chkForce . Checked = = true & &
! outputFormat . SupportedSectorTags . Contains ( tag ) )
continue ;
2018-10-23 23:59:33 +01:00
foreach ( Track track in tracks )
{
2020-02-29 18:03:35 +00:00
if ( cancel )
break ;
2018-10-23 23:59:33 +01:00
doneSectors = 0 ;
2020-02-29 18:03:35 +00:00
ulong trackSectors = ( track . TrackEndSector - track . TrackStartSector ) + 1 ;
2018-10-23 23:59:33 +01:00
byte [ ] sector ;
bool result ;
Application . Instance . Invoke ( ( ) = >
{
lblProgress . Text = $"Converting tag {tag} in track {track.TrackSequence}." ;
prgProgress . Value + + ;
lblProgress2 . Text = "" ;
prgProgress2 . Indeterminate = false ;
prgProgress2 . MaxValue = ( int ) ( trackSectors / numCount . Value ) ;
} ) ;
switch ( tag )
{
case SectorTagType . CdTrackFlags :
case SectorTagType . CdTrackIsrc :
sector = inputFormat . ReadSectorTag ( track . TrackStartSector , tag ) ;
result = outputFormat . WriteSectorTag ( sector , track . TrackStartSector , tag ) ;
2020-02-29 18:03:35 +00:00
2018-10-23 23:59:33 +01:00
if ( ! result )
if ( chkForce . Checked = = true )
{
warning = true ;
2020-02-29 18:03:35 +00:00
2020-02-27 23:48:41 +00:00
AaruConsole . ErrorWriteLine ( "Error {0} writing tag, continuing..." ,
2020-02-29 18:03:35 +00:00
outputFormat . ErrorMessage ) ;
2018-10-23 23:59:33 +01:00
}
else
{
Application . Instance . Invoke ( ( ) = >
{
2020-02-29 18:03:35 +00:00
MessageBox .
Show ( $"Error {outputFormat.ErrorMessage} writing tag, not continuing..." ,
2018-10-23 23:59:33 +01:00
MessageBoxType . Error ) ;
} ) ;
return ;
}
continue ;
}
while ( doneSectors < trackSectors )
{
2020-02-29 18:03:35 +00:00
if ( cancel )
break ;
2018-10-23 23:59:33 +01:00
uint sectorsToDo ;
2020-02-29 18:03:35 +00:00
if ( trackSectors - doneSectors > = ( ulong ) numCount . Value )
sectorsToDo = ( uint ) numCount . Value ;
2018-10-23 23:59:33 +01:00
else
2020-02-29 18:03:35 +00:00
sectorsToDo = ( uint ) ( trackSectors - doneSectors ) ;
2018-10-23 23:59:33 +01:00
ulong sectors = doneSectors ;
2020-02-29 18:03:35 +00:00
2018-10-23 23:59:33 +01:00
Application . Instance . Invoke ( ( ) = >
{
lblProgress2 . Text =
$"Converting tag {tag} for sectors {sectors + track.TrackStartSector} to {sectors + sectorsToDo + track.TrackStartSector} in track {track.TrackSequence} ({(sectors + track.TrackStartSector) / (double)inputFormat.Info.Sectors:P2} done)" ;
2020-02-29 18:03:35 +00:00
2018-10-23 23:59:33 +01:00
prgProgress2 . Value = ( int ) ( sectors / numCount . Value ) ;
} ) ;
if ( sectorsToDo = = 1 )
{
sector = inputFormat . ReadSectorTag ( doneSectors + track . TrackStartSector , tag ) ;
result = outputFormat . WriteSectorTag ( sector , doneSectors + track . TrackStartSector , tag ) ;
}
else
{
sector = inputFormat . ReadSectorsTag ( doneSectors + track . TrackStartSector , sectorsToDo ,
tag ) ;
2020-02-29 18:03:35 +00:00
2018-10-23 23:59:33 +01:00
result = outputFormat . WriteSectorsTag ( sector , doneSectors + track . TrackStartSector ,
sectorsToDo , tag ) ;
}
if ( ! result )
if ( chkForce . Checked = = true )
{
warning = true ;
2020-02-29 18:03:35 +00:00
2020-02-27 23:48:41 +00:00
AaruConsole . ErrorWriteLine ( "Error {0} writing tag for sector {1}, continuing..." ,
2020-02-29 18:03:35 +00:00
outputFormat . ErrorMessage , doneSectors ) ;
2018-10-23 23:59:33 +01:00
}
else
{
Application . Instance . Invoke ( ( ) = >
{
2020-02-29 18:03:35 +00:00
MessageBox .
Show ( $"Error {outputFormat.ErrorMessage} writing tag for sector {doneSectors}, not continuing..." ,
2018-10-23 23:59:33 +01:00
MessageBoxType . Error ) ;
} ) ;
return ;
}
doneSectors + = sectorsToDo ;
}
}
}
}
Application . Instance . Invoke ( ( ) = >
{
lblProgress2 . Visible = false ;
prgProgress2 . Visible = false ;
} ) ;
bool ret = false ;
2020-02-29 18:03:35 +00:00
if ( dumpHardware ! = null & &
! cancel )
2018-10-23 23:59:33 +01:00
{
Application . Instance . Invoke ( ( ) = >
{
lblProgress . Text = "Writing dump hardware list to output image." ;
prgProgress . Value + + ;
} ) ;
ret = outputFormat . SetDumpHardware ( dumpHardware ) ;
2020-02-29 18:03:35 +00:00
2018-10-23 23:59:33 +01:00
if ( ! ret )
2020-02-27 23:48:41 +00:00
AaruConsole . WriteLine ( "Error {0} writing dump hardware list to output image." ,
2020-02-29 18:03:35 +00:00
outputFormat . ErrorMessage ) ;
2018-10-23 23:59:33 +01:00
}
ret = false ;
2020-02-29 18:03:35 +00:00
if ( cicmMetadata ! = null & &
! cancel )
2018-10-23 23:59:33 +01:00
{
Application . Instance . Invoke ( ( ) = >
{
lblProgress . Text = "Writing CICM XML metadata to output image." ;
prgProgress . Value + + ;
} ) ;
outputFormat . SetCicmMetadata ( cicmMetadata ) ;
2020-02-29 18:03:35 +00:00
2018-10-23 23:59:33 +01:00
if ( ! ret )
2020-02-27 23:48:41 +00:00
AaruConsole . WriteLine ( "Error {0} writing CICM XML metadata to output image." ,
2020-02-29 18:03:35 +00:00
outputFormat . ErrorMessage ) ;
2018-10-23 23:59:33 +01:00
}
Application . Instance . Invoke ( ( ) = >
{
lblProgress . Text = "Closing output image." ;
prgProgress . Indeterminate = true ;
} ) ;
if ( cancel )
{
Application . Instance . Invoke ( ( ) = >
{
MessageBox . Show ( "Operation canceled, the output file is not correct." , MessageBoxType . Error ) ;
btnClose . Visible = true ;
btnStop . Visible = false ;
stkProgress . Visible = false ;
} ) ;
return ;
}
if ( ! outputFormat . Close ( ) )
{
Application . Instance . Invoke ( ( ) = >
{
2020-02-29 18:03:35 +00:00
MessageBox .
Show ( $"Error {outputFormat.ErrorMessage} closing output image... Contents are not correct." ,
2018-10-23 23:59:33 +01:00
MessageBoxType . Error ) ;
} ) ;
return ;
}
Application . Instance . Invoke ( ( ) = >
{
MessageBox . Show ( warning
? "Some warnings happened. Check console for more information. Image should be correct."
: "Image converted successfully." ) ;
btnClose . Visible = true ;
btnStop . Visible = false ;
stkProgress . Visible = false ;
} ) ;
Statistics . AddCommand ( "convert-image" ) ;
}
2020-02-29 18:03:35 +00:00
protected void OnBtnClose ( object sender , EventArgs e ) = > Close ( ) ;
2018-10-23 23:59:33 +01:00
protected void OnBtnStop ( object sender , EventArgs e )
{
cancel = true ;
btnStop . Enabled = false ;
}
void OnCmbFormatSelectedIndexChanged ( object sender , EventArgs e )
{
txtDestination . Text = "" ;
if ( ! ( cmbFormat . SelectedValue is IWritableImage plugin ) )
{
grpOptions . Visible = false ;
btnDestination . Enabled = false ;
2020-02-29 18:03:35 +00:00
2018-10-23 23:59:33 +01:00
return ;
}
btnDestination . Enabled = true ;
if ( ! plugin . SupportedOptions . Any ( ) )
{
grpOptions . Content = null ;
grpOptions . Visible = false ;
2020-02-29 18:03:35 +00:00
2018-10-23 23:59:33 +01:00
return ;
}
chkForce . Visible = false ;
2020-02-29 18:03:35 +00:00
2018-10-23 23:59:33 +01:00
foreach ( MediaTagType mediaTag in inputFormat . Info . ReadableMediaTags )
{
2020-02-29 18:03:35 +00:00
if ( plugin . SupportedMediaTags . Contains ( mediaTag ) )
continue ;
2018-10-23 23:59:33 +01:00
chkForce . Visible = true ;
chkForce . Checked = true ;
2020-02-29 18:03:35 +00:00
2018-10-23 23:59:33 +01:00
break ;
}
foreach ( SectorTagType sectorTag in inputFormat . Info . ReadableSectorTags )
{
2020-02-29 18:03:35 +00:00
if ( plugin . SupportedSectorTags . Contains ( sectorTag ) )
continue ;
2018-10-23 23:59:33 +01:00
chkForce . Visible = true ;
chkForce . Checked = true ;
2020-02-29 18:03:35 +00:00
2018-10-23 23:59:33 +01:00
break ;
}
grpOptions . Visible = true ;
2020-02-29 18:03:35 +00:00
var stkImageOptions = new StackLayout
{
Orientation = Orientation . Vertical
} ;
2018-10-23 23:59:33 +01:00
foreach ( ( string name , Type type , string description , object @default ) option in plugin . SupportedOptions )
switch ( option . type . ToString ( ) )
{
case "System.Boolean" :
2020-02-29 18:03:35 +00:00
var optBoolean = new CheckBox ( ) ;
2018-10-23 23:59:33 +01:00
optBoolean . ID = "opt" + option . name ;
optBoolean . Text = option . description ;
optBoolean . Checked = ( bool ) option . @default ;
stkImageOptions . Items . Add ( optBoolean ) ;
2020-02-29 18:03:35 +00:00
2018-10-23 23:59:33 +01:00
break ;
case "System.SByte" :
case "System.Int16" :
case "System.Int32" :
case "System.Int64" :
2020-02-29 18:03:35 +00:00
var stkNumber = new StackLayout ( ) ;
2018-10-23 23:59:33 +01:00
stkNumber . Orientation = Orientation . Horizontal ;
2020-02-29 18:03:35 +00:00
var optNumber = new NumericStepper ( ) ;
2018-10-23 23:59:33 +01:00
optNumber . ID = "opt" + option . name ;
optNumber . Value = Convert . ToDouble ( option . @default ) ;
stkNumber . Items . Add ( optNumber ) ;
2020-02-29 18:03:35 +00:00
var lblNumber = new Label ( ) ;
2018-10-23 23:59:33 +01:00
lblNumber . Text = option . description ;
stkNumber . Items . Add ( lblNumber ) ;
stkImageOptions . Items . Add ( stkNumber ) ;
2020-02-29 18:03:35 +00:00
2018-10-23 23:59:33 +01:00
break ;
case "System.Byte" :
case "System.UInt16" :
case "System.UInt32" :
case "System.UInt64" :
2020-02-29 18:03:35 +00:00
var stkUnsigned = new StackLayout ( ) ;
2018-10-23 23:59:33 +01:00
stkUnsigned . Orientation = Orientation . Horizontal ;
2020-02-29 18:03:35 +00:00
var optUnsigned = new NumericStepper ( ) ;
2018-10-23 23:59:33 +01:00
optUnsigned . ID = "opt" + option . name ;
optUnsigned . MinValue = 0 ;
optUnsigned . Value = Convert . ToDouble ( option . @default ) ;
stkUnsigned . Items . Add ( optUnsigned ) ;
2020-02-29 18:03:35 +00:00
var lblUnsigned = new Label ( ) ;
2018-10-23 23:59:33 +01:00
lblUnsigned . Text = option . description ;
stkUnsigned . Items . Add ( lblUnsigned ) ;
stkImageOptions . Items . Add ( stkUnsigned ) ;
2020-02-29 18:03:35 +00:00
2018-10-23 23:59:33 +01:00
break ;
case "System.Single" :
case "System.Double" :
2020-02-29 18:03:35 +00:00
var stkFloat = new StackLayout ( ) ;
2018-10-23 23:59:33 +01:00
stkFloat . Orientation = Orientation . Horizontal ;
2020-02-29 18:03:35 +00:00
var optFloat = new NumericStepper ( ) ;
2018-10-23 23:59:33 +01:00
optFloat . ID = "opt" + option . name ;
optFloat . DecimalPlaces = 2 ;
optFloat . Value = Convert . ToDouble ( option . @default ) ;
stkFloat . Items . Add ( optFloat ) ;
2020-02-29 18:03:35 +00:00
var lblFloat = new Label ( ) ;
2018-10-23 23:59:33 +01:00
lblFloat . Text = option . description ;
stkFloat . Items . Add ( lblFloat ) ;
stkImageOptions . Items . Add ( stkFloat ) ;
2020-02-29 18:03:35 +00:00
2018-10-23 23:59:33 +01:00
break ;
case "System.Guid" :
// TODO
break ;
case "System.String" :
2020-02-29 18:03:35 +00:00
var stkString = new StackLayout ( ) ;
2018-10-23 23:59:33 +01:00
stkString . Orientation = Orientation . Horizontal ;
2020-02-29 18:03:35 +00:00
var lblString = new Label ( ) ;
2018-10-23 23:59:33 +01:00
lblString . Text = option . description ;
stkString . Items . Add ( lblString ) ;
2020-02-29 18:03:35 +00:00
var optString = new TextBox ( ) ;
2018-10-23 23:59:33 +01:00
optString . ID = "opt" + option . name ;
optString . Text = ( string ) option . @default ;
stkString . Items . Add ( optString ) ;
stkImageOptions . Items . Add ( stkString ) ;
2020-02-29 18:03:35 +00:00
2018-10-23 23:59:33 +01:00
break ;
}
grpOptions . Content = stkImageOptions ;
}
void OnBtnDestinationClick ( object sender , EventArgs e )
{
2020-02-29 18:03:35 +00:00
if ( ! ( cmbFormat . SelectedValue is IWritableImage plugin ) )
return ;
var dlgDestination = new SaveFileDialog
{
Title = "Choose destination file"
} ;
2018-10-23 23:59:33 +01:00
dlgDestination . Filters . Add ( new FileFilter ( plugin . Name , plugin . KnownExtensions . ToArray ( ) ) ) ;
DialogResult result = dlgDestination . ShowDialog ( this ) ;
if ( result ! = DialogResult . Ok )
{
txtDestination . Text = "" ;
2020-02-29 18:03:35 +00:00
2018-10-23 23:59:33 +01:00
return ;
}
if ( string . IsNullOrEmpty ( Path . GetExtension ( dlgDestination . FileName ) ) )
dlgDestination . FileName + = plugin . KnownExtensions . First ( ) ;
txtDestination . Text = dlgDestination . FileName ;
}
2020-02-29 18:03:35 +00:00
void OnBtnCreator ( object sender , EventArgs e ) = > txtCreator . Text = inputFormat . Info . Creator ;
2018-10-23 23:59:33 +01:00
2020-02-29 18:03:35 +00:00
void OnBtnMediaTitle ( object sender , EventArgs e ) = > txtMediaTitle . Text = inputFormat . Info . MediaTitle ;
2018-10-23 23:59:33 +01:00
2020-02-29 18:03:35 +00:00
void OnBtnComments ( object sender , EventArgs e ) = > txtComments . Text = inputFormat . Info . Comments ;
2018-10-23 23:59:33 +01:00
2020-02-29 18:03:35 +00:00
void OnBtnMediaManufacturer ( object sender , EventArgs e ) = >
2018-10-23 23:59:33 +01:00
txtMediaManufacturer . Text = inputFormat . Info . MediaManufacturer ;
2020-02-29 18:03:35 +00:00
void OnBtnMediaModel ( object sender , EventArgs e ) = > txtMediaModel . Text = inputFormat . Info . MediaModel ;
2018-10-23 23:59:33 +01:00
2020-02-29 18:03:35 +00:00
void OnBtnMediaSerialNumber ( object sender , EventArgs e ) = >
2018-10-23 23:59:33 +01:00
txtMediaSerialNumber . Text = inputFormat . Info . MediaSerialNumber ;
2020-02-29 18:03:35 +00:00
void OnBtnMediaBarcode ( object sender , EventArgs e ) = > txtMediaBarcode . Text = inputFormat . Info . MediaBarcode ;
2018-10-23 23:59:33 +01:00
2020-02-29 18:03:35 +00:00
void OnBtnMediaPartNumber ( object sender , EventArgs e ) = >
2018-10-23 23:59:33 +01:00
txtMediaPartNumber . Text = inputFormat . Info . MediaPartNumber ;
2020-02-29 18:03:35 +00:00
void OnBtnMediaSequence ( object sender , EventArgs e ) = > numMediaSequence . Value = inputFormat . Info . MediaSequence ;
2018-10-23 23:59:33 +01:00
2020-02-29 18:03:35 +00:00
void OnBtnLastMediaSequence ( object sender , EventArgs e ) = >
2018-10-23 23:59:33 +01:00
numLastMediaSequence . Value = inputFormat . Info . LastMediaSequence ;
2020-02-29 18:03:35 +00:00
void OnBtnDriveManufacturer ( object sender , EventArgs e ) = >
2018-10-23 23:59:33 +01:00
txtDriveManufacturer . Text = inputFormat . Info . DriveManufacturer ;
2020-02-29 18:03:35 +00:00
void OnBtnDriveModel ( object sender , EventArgs e ) = > txtDriveModel . Text = inputFormat . Info . DriveModel ;
2018-10-23 23:59:33 +01:00
2020-02-29 18:03:35 +00:00
void OnBtnDriveSerialNumber ( object sender , EventArgs e ) = >
2018-10-23 23:59:33 +01:00
txtDriveSerialNumber . Text = inputFormat . Info . DriveSerialNumber ;
2020-02-29 18:03:35 +00:00
void OnBtnDriveFirmwareRevision ( object sender , EventArgs e ) = >
2018-10-23 23:59:33 +01:00
txtDriveFirmwareRevision . Text = inputFormat . Info . DriveFirmwareRevision ;
void OnBtnCicmXmlFromImageClick ( object sender , EventArgs e )
{
txtCicmXml . Text = "<From image>" ;
cicmMetadata = inputFormat . CicmMetadata ;
}
void OnBtnCicmXmlClick ( object sender , EventArgs e )
{
cicmMetadata = null ;
txtCicmXml . Text = "" ;
2020-02-29 18:03:35 +00:00
var dlgMetadata = new OpenFileDialog
{
Title = "Choose existing metadata sidecar" , CheckFileExists = true
} ;
2018-10-23 23:59:33 +01:00
dlgMetadata . Filters . Add ( new FileFilter ( "CICM XML metadata" , ".xml" ) ) ;
DialogResult result = dlgMetadata . ShowDialog ( this ) ;
2020-02-29 18:03:35 +00:00
if ( result ! = DialogResult . Ok )
return ;
var sidecarXs = new XmlSerializer ( typeof ( CICMMetadataType ) ) ;
2018-10-23 23:59:33 +01:00
try
{
2020-02-29 18:03:35 +00:00
var sr = new StreamReader ( dlgMetadata . FileName ) ;
2018-10-23 23:59:33 +01:00
cicmMetadata = ( CICMMetadataType ) sidecarXs . Deserialize ( sr ) ;
sr . Close ( ) ;
txtCicmXml . Text = dlgMetadata . FileName ;
}
2020-02-29 18:03:35 +00:00
catch
{
MessageBox . Show ( "Incorrect metadata sidecar file..." , MessageBoxType . Error ) ;
}
2018-10-23 23:59:33 +01:00
}
void OnBtnResumeFileFromImageClick ( object sender , EventArgs e )
{
txtResumeFile . Text = "<From image>" ;
dumpHardware = inputFormat . DumpHardware ;
}
void OnBtnResumeFileClick ( object sender , EventArgs e )
{
dumpHardware = null ;
txtResumeFile . Text = "" ;
2020-02-29 18:03:35 +00:00
var dlgMetadata = new OpenFileDialog
{
Title = "Choose existing resume file" , CheckFileExists = true
} ;
2018-10-23 23:59:33 +01:00
dlgMetadata . Filters . Add ( new FileFilter ( "CICM XML metadata" , ".xml" ) ) ;
DialogResult result = dlgMetadata . ShowDialog ( this ) ;
2020-02-29 18:03:35 +00:00
if ( result ! = DialogResult . Ok )
return ;
var sidecarXs = new XmlSerializer ( typeof ( Resume ) ) ;
2018-10-23 23:59:33 +01:00
try
{
2020-02-29 18:03:35 +00:00
var sr = new StreamReader ( dlgMetadata . FileName ) ;
var resume = ( Resume ) sidecarXs . Deserialize ( sr ) ;
2018-10-23 23:59:33 +01:00
2020-02-29 18:03:35 +00:00
if ( resume . Tries ! = null & &
! resume . Tries . Any ( ) )
2018-10-23 23:59:33 +01:00
{
dumpHardware = resume . Tries ;
txtResumeFile . Text = dlgMetadata . FileName ;
}
2020-02-29 18:03:35 +00:00
else
MessageBox . Show ( "Resume file does not contain dump hardware information..." , MessageBoxType . Error ) ;
2018-10-23 23:59:33 +01:00
sr . Close ( ) ;
}
2020-02-29 18:03:35 +00:00
catch
{
MessageBox . Show ( "Incorrect resume file..." , MessageBoxType . Error ) ;
}
2018-10-23 23:59:33 +01:00
}
#region XAML IDs
TextBox txtSource ;
ComboBox cmbFormat ;
TextBox txtDestination ;
Button btnDestination ;
StackLayout stkOptions ;
NumericStepper numCount ;
Label txtCount ;
CheckBox chkForce ;
Label lblCreator ;
TextBox txtCreator ;
Button btnCreator ;
GroupBox grpMetadata ;
Label lblMediaTitle ;
TextBox txtMediaTitle ;
Button btnMediaTitle ;
Label lblMediaManufacturer ;
TextBox txtMediaManufacturer ;
Button btnMediaManufacturer ;
Label lblMediaModel ;
TextBox txtMediaModel ;
Button btnMediaModel ;
Label lblMediaSerialNumber ;
TextBox txtMediaSerialNumber ;
Button btnMediaSerialNumber ;
Label lblMediaBarcode ;
TextBox txtMediaBarcode ;
Button btnMediaBarcode ;
Label lblMediaPartNumber ;
TextBox txtMediaPartNumber ;
Button btnMediaPartNumber ;
Label lblMediaSequence ;
NumericStepper numMediaSequence ;
Button btnMediaSequence ;
Label lblLastMediaSequence ;
NumericStepper numLastMediaSequence ;
Button btnLastMediaSequence ;
Label lblDriveManufacturer ;
TextBox txtDriveManufacturer ;
Button btnDriveManufacturer ;
Label lblDriveModel ;
TextBox txtDriveModel ;
Button btnDriveModel ;
Label lblDriveSerialNumber ;
TextBox txtDriveSerialNumber ;
Button btnDriveSerialNumber ;
Label lblDriveFirmwareRevision ;
TextBox txtDriveFirmwareRevision ;
Button btnDriveFirmwareRevision ;
TextArea txtComments ;
Button btnComments ;
TextBox txtCicmXml ;
Button btnCicmXmlFromImage ;
Button btnCicmXml ;
TextBox txtResumeFile ;
Button btnResumeFileFromImage ;
Button btnResumeFile ;
GroupBox grpOptions ;
StackLayout stkProgress ;
StackLayout stkProgress1 ;
Label lblProgress ;
ProgressBar prgProgress ;
StackLayout stkProgress2 ;
Label lblProgress2 ;
ProgressBar prgProgress2 ;
Button btnStart ;
Button btnClose ;
Button btnStop ;
#endregion
}
}