2017-05-17 05:12:57 +01:00
//
2017-05-15 07:30:27 +01:00
// Author:
// Natalia Portillo claunia@claunia.com
//
// Copyright (c) 2017, © Claunia.com
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the distribution.
// * Neither the name of the [ORGANIZATION] nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
2017-12-30 00:32:21 +00:00
2017-05-15 07:30:27 +01:00
using System ;
using System.Collections.Generic ;
2017-05-15 07:33:13 +01:00
using System.Collections.ObjectModel ;
2017-05-16 03:36:57 +01:00
using System.ComponentModel ;
2017-05-15 07:33:13 +01:00
using System.IO ;
2018-03-15 15:55:59 +00:00
using System.Linq ;
2017-05-16 03:36:57 +01:00
using System.Threading ;
2017-05-15 07:33:13 +01:00
using System.Xml.Serialization ;
2018-02-23 02:14:58 +00:00
using apprepodbmgr.Core ;
2017-05-16 03:36:57 +01:00
using Eto.Drawing ;
using Eto.Forms ;
using Eto.Serialization.Xaml ;
2017-05-15 07:33:13 +01:00
using Newtonsoft.Json ;
2017-05-16 03:36:57 +01:00
using Schemas ;
2017-05-15 07:30:27 +01:00
2018-02-23 02:14:58 +00:00
namespace apprepodbmgr.Eto
2017-05-15 07:30:27 +01:00
{
2017-05-15 07:33:13 +01:00
public class dlgAdd : Dialog
2017-05-15 07:30:27 +01:00
{
2018-02-23 03:33:22 +00:00
public delegate void OnAddedAppDelegate ( DbEntry app ) ;
2017-05-15 07:33:13 +01:00
2018-02-23 03:33:22 +00:00
ObservableCollection < DBEntryForEto > appView ;
2018-02-23 03:42:57 +00:00
ObservableCollection < FileEntry > fileView ;
int knownFiles ;
bool stopped ;
Thread thdAddFiles ;
Thread thdCheckFiles ;
Thread thdExtractArchive ;
Thread thdFindFiles ;
Thread thdHashFiles ;
Thread thdOpenArchive ;
Thread thdPackFiles ;
Thread thdRemoveTemp ;
2017-05-15 07:33:13 +01:00
2017-05-15 07:30:27 +01:00
public dlgAdd ( )
{
XamlReader . Load ( this ) ;
2017-05-15 07:33:13 +01:00
Context . UnarChangeStatus + = UnarChangeStatus ;
Context . CheckUnar ( ) ;
fileView = new ObservableCollection < FileEntry > ( ) ;
treeFiles . DataStore = fileView ;
treeFiles . Columns . Add ( new GridColumn
{
2017-12-30 00:32:21 +00:00
DataCell = new TextBoxCell { Binding = Binding . Property < FileEntry , string > ( r = > r . Path ) } ,
2017-05-15 07:33:13 +01:00
HeaderText = "Path"
} ) ;
treeFiles . Columns . Add ( new GridColumn
2017-05-18 17:56:28 +01:00
{
2017-12-30 00:32:21 +00:00
DataCell = new CheckBoxCell { Binding = Binding . Property < FileEntry , bool? > ( r = > r . IsCrack ) } ,
2017-05-18 17:56:28 +01:00
HeaderText = "Crack?"
} ) ;
treeFiles . Columns . Add ( new GridColumn
2017-05-15 07:33:13 +01:00
{
2017-12-30 00:32:21 +00:00
DataCell = new TextBoxCell { Binding = Binding . Property < FileEntry , string > ( r = > r . Hash ) } ,
2017-05-15 07:33:13 +01:00
HeaderText = "SHA256"
} ) ;
treeFiles . Columns . Add ( new GridColumn
{
2017-12-30 00:32:21 +00:00
DataCell = new CheckBoxCell { Binding = Binding . Property < FileEntry , bool? > ( r = > r . Known ) } ,
2017-05-15 07:33:13 +01:00
HeaderText = "Known?"
} ) ;
treeFiles . AllowMultipleSelection = false ;
2017-05-16 03:34:17 +01:00
treeFiles . CellFormatting + = ( sender , e ) = >
{
2017-12-30 00:32:21 +00:00
e . BackgroundColor = ( ( FileEntry ) e . Item ) . Known ? Colors . Green : Colors . Red ;
2017-05-15 07:33:13 +01:00
} ;
2018-02-23 03:33:22 +00:00
appView = new ObservableCollection < DBEntryForEto > ( ) ;
2017-05-15 07:33:13 +01:00
2018-02-23 03:33:22 +00:00
treeApps . DataStore = appView ;
2017-05-15 07:33:13 +01:00
2018-02-23 03:33:22 +00:00
treeApps . Columns . Add ( new GridColumn
2017-05-15 07:33:13 +01:00
{
2017-12-30 00:32:21 +00:00
DataCell = new TextBoxCell { Binding = Binding . Property < DBEntryForEto , string > ( r = > r . developer ) } ,
2017-05-15 07:33:13 +01:00
HeaderText = "Developer"
} ) ;
2018-02-23 03:33:22 +00:00
treeApps . Columns . Add ( new GridColumn
2017-05-15 07:33:13 +01:00
{
2017-12-30 00:32:21 +00:00
DataCell = new TextBoxCell { Binding = Binding . Property < DBEntryForEto , string > ( r = > r . product ) } ,
2017-05-15 07:33:13 +01:00
HeaderText = "Product"
} ) ;
2018-02-23 03:33:22 +00:00
treeApps . Columns . Add ( new GridColumn
2017-05-15 07:33:13 +01:00
{
2017-12-30 00:32:21 +00:00
DataCell = new TextBoxCell { Binding = Binding . Property < DBEntryForEto , string > ( r = > r . version ) } ,
2017-05-15 07:33:13 +01:00
HeaderText = "Version"
} ) ;
2018-02-23 03:33:22 +00:00
treeApps . Columns . Add ( new GridColumn
2017-05-15 07:33:13 +01:00
{
2017-12-30 00:32:21 +00:00
DataCell = new TextBoxCell { Binding = Binding . Property < DBEntryForEto , string > ( r = > r . languages ) } ,
2017-05-15 07:33:13 +01:00
HeaderText = "Languages"
} ) ;
2018-02-23 03:33:22 +00:00
treeApps . Columns . Add ( new GridColumn
2017-05-15 07:33:13 +01:00
{
2017-12-30 00:32:21 +00:00
DataCell = new TextBoxCell { Binding = Binding . Property < DBEntryForEto , string > ( r = > r . architecture ) } ,
2017-05-15 07:33:13 +01:00
HeaderText = "Architecture"
} ) ;
2018-02-23 03:33:22 +00:00
treeApps . Columns . Add ( new GridColumn
2017-05-15 07:33:13 +01:00
{
2018-03-15 15:55:59 +00:00
DataCell = new TextBoxCell { Binding = Binding . Property < DBEntryForEto , string > ( r = > r . targetos ) } ,
HeaderText = "Target OS"
2017-05-15 07:33:13 +01:00
} ) ;
2018-02-23 03:33:22 +00:00
treeApps . Columns . Add ( new GridColumn
2017-05-15 07:33:13 +01:00
{
2017-12-30 00:32:21 +00:00
DataCell = new TextBoxCell { Binding = Binding . Property < DBEntryForEto , string > ( r = > r . format ) } ,
2017-05-15 07:33:13 +01:00
HeaderText = "Format"
} ) ;
2018-02-23 03:33:22 +00:00
treeApps . Columns . Add ( new GridColumn
2017-05-15 07:33:13 +01:00
{
2017-12-30 00:32:21 +00:00
DataCell = new TextBoxCell { Binding = Binding . Property < DBEntryForEto , string > ( r = > r . description ) } ,
2017-05-15 07:33:13 +01:00
HeaderText = "Description"
} ) ;
2018-02-23 03:33:22 +00:00
treeApps . Columns . Add ( new GridColumn
2017-05-15 07:33:13 +01:00
{
2017-12-30 00:32:21 +00:00
DataCell = new CheckBoxCell { Binding = Binding . Property < DBEntryForEto , bool? > ( r = > r . oem ) } ,
2017-05-15 07:33:13 +01:00
HeaderText = "OEM?"
} ) ;
2018-02-23 03:33:22 +00:00
treeApps . Columns . Add ( new GridColumn
2017-05-15 07:33:13 +01:00
{
2017-12-30 00:32:21 +00:00
DataCell = new CheckBoxCell { Binding = Binding . Property < DBEntryForEto , bool? > ( r = > r . upgrade ) } ,
2017-05-15 07:33:13 +01:00
HeaderText = "Upgrade?"
} ) ;
2018-02-23 03:33:22 +00:00
treeApps . Columns . Add ( new GridColumn
2017-05-15 07:33:13 +01:00
{
2017-12-30 00:32:21 +00:00
DataCell = new CheckBoxCell { Binding = Binding . Property < DBEntryForEto , bool? > ( r = > r . update ) } ,
2017-05-15 07:33:13 +01:00
HeaderText = "Update?"
} ) ;
2018-02-23 03:33:22 +00:00
treeApps . Columns . Add ( new GridColumn
2017-05-15 07:33:13 +01:00
{
2017-12-30 00:32:21 +00:00
DataCell = new CheckBoxCell { Binding = Binding . Property < DBEntryForEto , bool? > ( r = > r . source ) } ,
2017-05-15 07:33:13 +01:00
HeaderText = "Source?"
} ) ;
2018-02-23 03:33:22 +00:00
treeApps . Columns . Add ( new GridColumn
2017-05-15 07:33:13 +01:00
{
2017-12-30 00:32:21 +00:00
DataCell = new CheckBoxCell { Binding = Binding . Property < DBEntryForEto , bool? > ( r = > r . files ) } ,
2017-05-15 07:33:13 +01:00
HeaderText = "Files?"
} ) ;
2018-02-23 03:33:22 +00:00
treeApps . Columns . Add ( new GridColumn
2017-05-15 07:33:13 +01:00
{
2018-03-15 15:55:59 +00:00
DataCell = new CheckBoxCell { Binding = Binding . Property < DBEntryForEto , bool? > ( r = > r . Installer ) } ,
HeaderText = "Installer?"
2017-05-15 07:33:13 +01:00
} ) ;
2018-02-23 03:33:22 +00:00
treeApps . AllowMultipleSelection = false ;
2018-03-15 17:30:13 +00:00
2018-03-16 15:44:21 +00:00
txtArchitecture . ToolTip =
"This field contains a comma separated list of architectures the application can run on. To edit its contents use the metadata editor." ;
2018-03-15 17:30:13 +00:00
txtDescription . ToolTip = "This field contains a free-form text description of this application." ;
2018-03-16 15:44:21 +00:00
txtDeveloper . ToolTip =
"This field contains the developer of the application. To edit its contents use the metadata editor." ;
txtFormat . ToolTip =
"This field is contains the name of the format of the disk images, when it is not a byte-by-byte format like .iso or .img." ;
txtLanguages . ToolTip =
"This field contains a comma separated list of languages the application includes. To edit its contents use the metadata editor." ;
txtProduct . ToolTip =
"This field contains the application name. To edit its contents use the metadata editor." ;
txtTargetOs . ToolTip =
"This field contains a comma separated list of operating systems this application can run on. To edit its contents use the metadata editor." ;
txtVersion . ToolTip =
"This field contains the application version. To edit its contents use the metadata editor." ;
2018-03-15 17:30:13 +00:00
chkFiles . ToolTip = "If this field is checked it indicates the application is already installed." ;
2018-03-16 15:44:21 +00:00
chkInstaller . ToolTip =
"If this field is checked it indicates the application comes as an installer (one or several files), but it's not installed neither disk images." ;
chkOem . ToolTip =
"If this field is checked it indicates the application came bundled with hardware (aka OEM distributed)." ;
2018-03-15 17:30:13 +00:00
chkSource . ToolTip = "If this field is checked it indicates this is the source code for the application." ;
2018-03-16 15:44:21 +00:00
chkUpdate . ToolTip =
"If this field is checked it indicates this version is a minor version update that requires a previous version of the application already installed." ;
chkUpgrade . ToolTip =
"If this field is checked it indicates this version is a major version upgrade that requires a previous version of the application already installed." ;
2018-03-15 17:30:13 +00:00
txtArchitecture . ReadOnly = true ;
2018-03-16 15:44:21 +00:00
txtDeveloper . ReadOnly = true ;
txtLanguages . ReadOnly = true ;
txtProduct . ReadOnly = true ;
txtTargetOs . ReadOnly = true ;
txtVersion . ReadOnly = true ;
2017-05-15 07:33:13 +01:00
}
2018-02-23 03:33:22 +00:00
public event OnAddedAppDelegate OnAddedApp ;
2017-12-30 00:32:21 +00:00
2017-05-15 07:33:13 +01:00
void UnarChangeStatus ( )
{
2017-12-30 00:32:21 +00:00
Application . Instance . Invoke ( delegate { btnArchive . Enabled = Context . UnarUsable ; } ) ;
2017-05-15 07:33:13 +01:00
}
protected void OnDeleteEvent ( object sender , CancelEventArgs e )
{
2017-12-30 00:32:21 +00:00
if ( btnStop . Visible ) btnStop . PerformClick ( ) ;
if ( btnClose . Enabled ) btnClose . PerformClick ( ) ;
2017-05-15 07:33:13 +01:00
}
protected void OnBtnFolderClicked ( object sender , EventArgs e )
{
2017-12-30 00:32:21 +00:00
SelectFolderDialog dlgFolder = new SelectFolderDialog { Title = "Open folder" } ;
if ( dlgFolder . ShowDialog ( this ) ! = DialogResult . Ok ) return ;
knownFiles = 0 ;
stopped = false ;
lblProgress . Text = "Finding files" ;
lblProgress . Visible = true ;
prgProgress . Visible = true ;
btnExit . Enabled = false ;
btnFolder . Visible = false ;
btnArchive . Visible = false ;
thdFindFiles = new Thread ( Workers . FindFiles ) ;
Context . Path = dlgFolder . Directory ;
Workers . Failed + = FindFilesFailed ;
Workers . Finished + = FindFilesFinished ;
btnStop . Visible = true ;
thdFindFiles . Start ( ) ;
2017-05-15 07:33:13 +01:00
}
void FindFilesFailed ( string text )
{
Application . Instance . Invoke ( delegate
{
2017-12-30 00:32:21 +00:00
if ( ! stopped ) MessageBox . Show ( text , MessageBoxType . Error ) ;
lblProgress . Visible = false ;
prgProgress . Visible = false ;
btnExit . Enabled = true ;
btnFolder . Visible = true ;
btnArchive . Visible = true ;
btnStop . Visible = false ;
Workers . Failed - = FindFilesFailed ;
Workers . Finished - = FindFilesFinished ;
thdFindFiles = null ;
2017-05-15 07:33:13 +01:00
} ) ;
}
void FindFilesFinished ( )
{
Application . Instance . Invoke ( delegate
{
2017-12-30 00:32:21 +00:00
Workers . Failed - = FindFilesFailed ;
2017-05-15 07:33:13 +01:00
Workers . Finished - = FindFilesFinished ;
2017-12-30 00:32:21 +00:00
lblProgress . Visible = true ;
prgProgress . Visible = true ;
2017-05-15 07:33:13 +01:00
lblProgress2 . Visible = true ;
prgProgress2 . Visible = true ;
2017-12-30 00:32:21 +00:00
thdFindFiles = null ;
thdHashFiles = new Thread ( Workers . HashFiles ) ;
Workers . Failed + = HashFilesFailed ;
Workers . Finished + = HashFilesFinished ;
Workers . UpdateProgress + = UpdateProgress ;
2017-05-15 07:33:13 +01:00
Workers . UpdateProgress2 + = UpdateProgress2 ;
thdHashFiles . Start ( ) ;
} ) ;
}
void HashFilesFailed ( string text )
{
Application . Instance . Invoke ( delegate
{
2017-12-30 00:32:21 +00:00
if ( ! stopped ) MessageBox . Show ( text , MessageBoxType . Error ) ;
lblProgress . Visible = false ;
prgProgress . Visible = false ;
lblProgress2 . Visible = false ;
prgProgress2 . Visible = false ;
Workers . Failed - = HashFilesFailed ;
Workers . Finished - = HashFilesFinished ;
Workers . UpdateProgress - = UpdateProgress ;
2017-05-15 07:33:13 +01:00
Workers . UpdateProgress2 - = UpdateProgress2 ;
2017-12-30 00:32:21 +00:00
btnExit . Enabled = true ;
btnFolder . Visible = true ;
btnArchive . Visible = true ;
btnStop . Visible = false ;
thdHashFiles = null ;
2017-05-15 07:33:13 +01:00
} ) ;
}
void HashFilesFinished ( )
{
Application . Instance . Invoke ( delegate
{
2017-12-30 00:32:21 +00:00
lblProgress . Visible = false ;
prgProgress . Visible = false ;
lblProgress2 . Visible = false ;
prgProgress2 . Visible = false ;
Workers . Failed - = HashFilesFailed ;
Workers . Finished - = HashFilesFinished ;
Workers . UpdateProgress - = UpdateProgress ;
2017-05-15 07:33:13 +01:00
Workers . UpdateProgress2 - = UpdateProgress2 ;
2017-12-30 00:32:21 +00:00
thdHashFiles = null ;
2017-05-15 07:33:13 +01:00
2017-05-19 03:25:03 +01:00
lblProgress . Visible = true ;
2017-05-15 07:33:13 +01:00
prgProgress . Visible = true ;
2017-12-30 00:32:21 +00:00
thdCheckFiles = new Thread ( Workers . CheckDbForFiles ) ;
Workers . Failed + = ChkFilesFailed ;
Workers . Finished + = ChkFilesFinished ;
Workers . UpdateProgress + = UpdateProgress ;
2017-05-15 07:33:13 +01:00
Workers . UpdateProgress2 + = UpdateProgress2 ;
2018-02-23 03:42:57 +00:00
Workers . AddFileForApp + = AddFile ;
Workers . AddApp + = AddApp ;
2017-05-15 07:33:13 +01:00
thdCheckFiles . Start ( ) ;
} ) ;
}
void ChkFilesFailed ( string text )
{
Application . Instance . Invoke ( delegate
{
2017-12-30 00:32:21 +00:00
if ( ! stopped ) MessageBox . Show ( text , MessageBoxType . Error ) ;
prgProgress . Visible = false ;
btnStop . Visible = false ;
btnClose . Visible = false ;
btnExit . Enabled = true ;
Workers . Failed - = ChkFilesFailed ;
Workers . Finished - = ChkFilesFinished ;
Workers . UpdateProgress - = UpdateProgress ;
2017-05-15 07:33:13 +01:00
Workers . UpdateProgress2 - = UpdateProgress2 ;
2018-02-23 03:42:57 +00:00
Workers . AddFileForApp - = AddFile ;
Workers . AddApp - = AddApp ;
2017-12-30 00:32:21 +00:00
thdCheckFiles ? . Abort ( ) ;
2017-05-15 07:33:13 +01:00
thdHashFiles = null ;
2017-12-30 00:32:21 +00:00
fileView ? . Clear ( ) ;
2018-02-23 03:33:22 +00:00
if ( appView = = null ) return ;
2017-12-30 00:32:21 +00:00
2018-02-23 03:33:22 +00:00
tabApps . Visible = false ;
appView . Clear ( ) ;
2017-05-15 07:33:13 +01:00
} ) ;
}
void ChkFilesFinished ( )
{
Application . Instance . Invoke ( delegate
{
2017-12-30 00:32:21 +00:00
Workers . Failed - = ChkFilesFailed ;
Workers . Finished - = ChkFilesFinished ;
Workers . UpdateProgress - = UpdateProgress ;
2017-05-15 07:33:13 +01:00
Workers . UpdateProgress2 - = UpdateProgress2 ;
2018-02-23 03:42:57 +00:00
Workers . AddFileForApp - = AddFile ;
Workers . AddApp - = AddApp ;
2017-12-30 00:32:21 +00:00
thdCheckFiles ? . Abort ( ) ;
2018-03-17 21:56:18 +00:00
thdHashFiles = null ;
lblProgress . Visible = false ;
prgProgress . Visible = false ;
btnStop . Visible = false ;
if ( Context . Executables ? . Count > 0 | | Context . Readmes ? . Count > 0 )
{
dlgImportMetadata importMetadataDlg = new dlgImportMetadata ( ) ;
importMetadataDlg . ShowModal ( this ) ;
if ( ! importMetadataDlg . canceled & & ( importMetadataDlg . chosenArchitectures . Count > 0 | |
importMetadataDlg . chosenOses . Count > 0 | |
! string . IsNullOrWhiteSpace ( importMetadataDlg . description ) | |
! string . IsNullOrWhiteSpace ( importMetadataDlg . developer ) | |
! string . IsNullOrWhiteSpace ( importMetadataDlg . product ) | |
! string . IsNullOrWhiteSpace ( importMetadataDlg . publisher ) | |
! string . IsNullOrWhiteSpace ( importMetadataDlg . version ) ) )
{
if ( Context . Metadata = = null & & ( importMetadataDlg . chosenArchitectures . Count > 0 | |
importMetadataDlg . chosenOses . Count > 0 | |
! string . IsNullOrWhiteSpace ( importMetadataDlg . developer ) | |
! string . IsNullOrWhiteSpace ( importMetadataDlg . product ) | |
! string . IsNullOrWhiteSpace ( importMetadataDlg . publisher ) | |
! string . IsNullOrWhiteSpace ( importMetadataDlg . version ) ) )
Context . Metadata = new CICMMetadataType ( ) ;
if ( ! string . IsNullOrWhiteSpace ( importMetadataDlg . description ) )
txtDescription . Text = importMetadataDlg . description ;
if ( ! string . IsNullOrWhiteSpace ( importMetadataDlg . product ) )
Context . Metadata . Name = importMetadataDlg . product ;
if ( ! string . IsNullOrWhiteSpace ( importMetadataDlg . publisher ) )
Context . Metadata . Publisher = new [ ] { importMetadataDlg . publisher } ;
if ( ! string . IsNullOrWhiteSpace ( importMetadataDlg . developer ) )
Context . Metadata . Developer = new [ ] { importMetadataDlg . developer } ;
if ( importMetadataDlg . chosenArchitectures . Count > 0 )
Context . Metadata . Architectures = importMetadataDlg . chosenArchitectures . ToArray ( ) ;
if ( importMetadataDlg . chosenOses . Count > 0 )
{
List < RequiredOperatingSystemType > reqOs = new List < RequiredOperatingSystemType > ( ) ;
foreach ( TargetOsEntry osEntry in importMetadataDlg . chosenOses )
reqOs . Add ( new RequiredOperatingSystemType
{
Name = osEntry . name ,
Version = new [ ] { osEntry . version }
} ) ;
Context . Metadata . RequiredOperatingSystems = reqOs . ToArray ( ) ;
}
}
}
2017-12-30 00:32:21 +00:00
btnClose . Visible = true ;
btnExit . Enabled = true ;
btnPack . Visible = true ;
btnPack . Enabled = true ;
btnRemoveFile . Visible = true ;
2017-05-18 17:56:28 +01:00
btnToggleCrack . Visible = true ;
2017-12-30 00:32:21 +00:00
btnRemoveFile . Enabled = true ;
2017-05-21 14:25:58 +01:00
btnToggleCrack . Enabled = true ;
2017-05-15 07:33:13 +01:00
2018-03-16 15:44:21 +00:00
txtFormat . ReadOnly = false ;
txtDescription . ReadOnly = false ;
chkOem . Enabled = true ;
chkFiles . Enabled = true ;
chkUpdate . Enabled = true ;
chkUpgrade . Enabled = true ;
chkInstaller . Enabled = true ;
chkSource . Enabled = true ;
2017-05-15 07:33:13 +01:00
btnMetadata . Visible = true ;
2017-12-30 00:32:21 +00:00
if ( Context . Metadata ! = null )
2017-05-15 07:33:13 +01:00
{
2017-12-30 00:32:21 +00:00
if ( Context . Metadata . Developer ! = null )
foreach ( string developer in Context . Metadata . Developer )
2017-05-15 07:33:13 +01:00
{
2017-12-30 00:32:21 +00:00
if ( ! string . IsNullOrWhiteSpace ( txtDeveloper . Text ) ) txtDeveloper . Text + = "," ;
2018-03-15 15:55:59 +00:00
txtDeveloper . Text + = developer ;
2017-05-15 07:33:13 +01:00
}
2017-12-30 00:32:21 +00:00
if ( ! string . IsNullOrWhiteSpace ( Context . Metadata . Name ) ) txtProduct . Text = Context . Metadata . Name ;
if ( ! string . IsNullOrWhiteSpace ( Context . Metadata . Version ) ) txtVersion . Text = Context . Metadata . Version ;
2017-05-15 07:33:13 +01:00
2017-12-30 00:32:21 +00:00
if ( Context . Metadata . Languages ! = null )
foreach ( LanguagesTypeLanguage language in Context . Metadata . Languages )
2017-05-15 07:33:13 +01:00
{
2017-12-30 00:32:21 +00:00
if ( ! string . IsNullOrWhiteSpace ( txtLanguages . Text ) ) txtLanguages . Text + = "," ;
2018-03-15 15:55:59 +00:00
txtLanguages . Text + = language ;
2017-05-15 07:33:13 +01:00
}
2017-12-30 00:32:21 +00:00
if ( Context . Metadata . Architectures ! = null )
foreach ( ArchitecturesTypeArchitecture architecture in Context . Metadata . Architectures )
2017-05-15 07:33:13 +01:00
{
2017-12-30 00:32:21 +00:00
if ( ! string . IsNullOrWhiteSpace ( txtArchitecture . Text ) ) txtArchitecture . Text + = "," ;
2018-03-15 15:55:59 +00:00
txtArchitecture . Text + = architecture ;
2017-05-15 07:33:13 +01:00
}
2018-03-15 15:55:59 +00:00
if ( Context . Metadata . RequiredOperatingSystems ! = null )
foreach ( string targetos in Context
. Metadata . RequiredOperatingSystems . Select ( os = > os . Name ) . Distinct ( ) )
2017-05-15 07:33:13 +01:00
{
2018-03-15 15:55:59 +00:00
if ( ! string . IsNullOrWhiteSpace ( txtTargetOs . Text ) ) txtTargetOs . Text + = "," ;
txtTargetOs . Text + = targetos ;
2017-05-15 07:33:13 +01:00
}
btnMetadata . BackgroundColor = Colors . Green ;
}
2017-12-30 00:32:21 +00:00
else btnMetadata . BackgroundColor = Colors . Red ;
2017-05-19 18:22:54 +01:00
2017-05-19 18:04:21 +01:00
lblStatus . Visible = true ;
2017-12-30 00:32:21 +00:00
lblStatus . Text = $"{fileView.Count} files ({knownFiles} already known)" ;
2017-05-15 07:33:13 +01:00
} ) ;
}
2017-05-18 17:56:28 +01:00
void AddFile ( string filename , string hash , bool known , bool isCrack )
2017-05-15 07:33:13 +01:00
{
Application . Instance . Invoke ( delegate
{
2017-12-30 00:32:21 +00:00
fileView . Add ( new FileEntry { Path = filename , Hash = hash , Known = known , IsCrack = isCrack } ) ;
2018-03-15 15:55:59 +00:00
btnPack . Enabled | = ! known ;
2017-12-30 00:32:21 +00:00
if ( known ) knownFiles + + ;
2017-05-15 07:33:13 +01:00
} ) ;
}
2018-02-23 03:33:22 +00:00
void AddApp ( DbEntry app )
2017-05-15 07:33:13 +01:00
{
Application . Instance . Invoke ( delegate
{
2018-02-23 03:33:22 +00:00
tabApps . Visible = true ;
appView . Add ( new DBEntryForEto ( app ) ) ;
2017-05-15 07:33:13 +01:00
} ) ;
}
protected void OnBtnExitClicked ( object sender , EventArgs e )
{
2017-12-30 00:32:21 +00:00
if ( btnClose . Enabled ) OnBtnCloseClicked ( sender , e ) ;
2017-05-15 07:33:13 +01:00
Close ( ) ;
}
protected void OnBtnCloseClicked ( object sender , EventArgs e )
{
2017-12-30 00:32:21 +00:00
btnFolder . Visible = true ;
btnArchive . Visible = true ;
Context . Path = "" ;
Context . Files = null ;
Context . Hashes = null ;
2018-03-17 21:56:18 +00:00
Context . Executables = null ;
Context . Readmes = null ;
2017-12-30 00:32:21 +00:00
btnStop . Visible = false ;
btnPack . Visible = false ;
btnClose . Visible = false ;
btnRemoveFile . Visible = false ;
2017-05-18 17:56:28 +01:00
btnToggleCrack . Visible = false ;
2017-12-30 00:32:21 +00:00
fileView ? . Clear ( ) ;
2018-02-23 03:33:22 +00:00
if ( appView ! = null )
2017-05-15 07:33:13 +01:00
{
2018-02-23 03:33:22 +00:00
tabApps . Visible = false ;
appView . Clear ( ) ;
2017-05-15 07:33:13 +01:00
}
2017-12-30 00:32:21 +00:00
2018-03-16 15:44:21 +00:00
txtFormat . ReadOnly = true ;
txtDescription . ReadOnly = true ;
chkOem . Enabled = false ;
chkFiles . Enabled = false ;
chkUpdate . Enabled = false ;
chkUpgrade . Enabled = false ;
chkInstaller . Enabled = false ;
chkSource . Enabled = false ;
txtFormat . Text = "" ;
txtTargetOs . Text = "" ;
txtProduct . Text = "" ;
txtVersion . Text = "" ;
txtLanguages . Text = "" ;
txtDeveloper . Text = "" ;
txtDescription . Text = "" ;
txtArchitecture . Text = "" ;
chkOem . Checked = false ;
chkFiles . Checked = false ;
chkUpdate . Checked = false ;
chkUpgrade . Checked = false ;
chkInstaller . Checked = false ;
chkSource . Checked = false ;
2017-12-30 00:32:21 +00:00
if ( Context . TmpFolder ! = null )
2017-05-15 07:33:13 +01:00
{
2017-12-30 00:32:21 +00:00
btnStop . Visible = false ;
prgProgress . Visible = true ;
lblProgress . Visible = true ;
lblProgress . Text = "Removing temporary files" ;
prgProgress . Indeterminate = true ;
Workers . Failed + = RemoveTempFilesFailed ;
Workers . Finished + = RemoveTempFilesFinished ;
thdRemoveTemp = new Thread ( Workers . RemoveTempFolder ) ;
2017-05-15 07:33:13 +01:00
thdRemoveTemp . Start ( ) ;
}
btnMetadata . Visible = false ;
2017-12-30 00:32:21 +00:00
Context . Metadata = null ;
lblStatus . Visible = false ;
2017-05-15 07:33:13 +01:00
}
2017-12-30 00:32:21 +00:00
void UpdateProgress ( string text , string inner , long current , long maximum )
2017-05-15 07:33:13 +01:00
{
Application . Instance . Invoke ( delegate
{
2017-05-17 06:26:20 +01:00
if ( ! string . IsNullOrWhiteSpace ( text ) & & ! string . IsNullOrWhiteSpace ( inner ) )
2018-03-15 15:55:59 +00:00
lblProgress . Text = $"{text}: {inner}" ;
else if ( ! string . IsNullOrWhiteSpace ( inner ) ) lblProgress . Text = inner ;
else lblProgress . Text = text ;
2017-05-15 07:33:13 +01:00
if ( maximum > 0 )
{
2017-12-30 00:32:21 +00:00
if ( current < int . MinValue | | current > int . MaxValue | | maximum < int . MinValue | |
maximum > int . MaxValue )
2017-06-20 07:28:16 +01:00
{
current / = 100 ;
maximum / = 100 ;
}
2017-05-15 07:33:13 +01:00
prgProgress . Indeterminate = false ;
2017-12-30 00:32:21 +00:00
prgProgress . MinValue = 0 ;
prgProgress . MaxValue = ( int ) maximum ;
prgProgress . Value = ( int ) current ;
2017-05-15 07:33:13 +01:00
}
2017-12-30 00:32:21 +00:00
else prgProgress . Indeterminate = true ;
2017-05-15 07:33:13 +01:00
} ) ;
}
2017-12-30 00:32:21 +00:00
void UpdateProgress2 ( string text , string inner , long current , long maximum )
2017-05-15 07:33:13 +01:00
{
Application . Instance . Invoke ( delegate
{
2017-05-17 06:26:20 +01:00
if ( ! string . IsNullOrWhiteSpace ( text ) & & ! string . IsNullOrWhiteSpace ( inner ) )
2018-03-15 15:55:59 +00:00
lblProgress2 . Text = $"{text}: {inner}" ;
else if ( ! string . IsNullOrWhiteSpace ( inner ) ) lblProgress2 . Text = inner ;
else lblProgress2 . Text = text ;
2017-05-15 07:33:13 +01:00
if ( maximum > 0 )
{
2017-12-30 00:32:21 +00:00
if ( current < int . MinValue | | current > int . MaxValue | | maximum < int . MinValue | |
maximum > int . MaxValue )
2017-06-20 07:28:16 +01:00
{
current / = 100 ;
maximum / = 100 ;
}
2017-05-15 07:33:13 +01:00
prgProgress2 . Indeterminate = false ;
2017-12-30 00:32:21 +00:00
prgProgress2 . MinValue = 0 ;
prgProgress2 . MaxValue = ( int ) maximum ;
prgProgress2 . Value = ( int ) current ;
2017-05-15 07:33:13 +01:00
}
2017-12-30 00:32:21 +00:00
else prgProgress2 . Indeterminate = true ;
2017-05-15 07:33:13 +01:00
} ) ;
}
protected void OnBtnStopClicked ( object sender , EventArgs e )
{
stopped = true ;
2018-02-23 03:42:57 +00:00
Workers . AddFileForApp - = AddFile ;
Workers . AddApp - = AddApp ;
2017-12-30 00:32:21 +00:00
Workers . Failed - = AddFilesToDbFailed ;
Workers . Failed - = ChkFilesFailed ;
Workers . Failed - = ExtractArchiveFailed ;
Workers . Failed - = FindFilesFailed ;
Workers . Failed - = HashFilesFailed ;
Workers . Failed - = OpenArchiveFailed ;
Workers . Failed - = PackFilesFailed ;
Workers . Failed - = RemoveTempFilesFailed ;
Workers . Finished - = AddFilesToDbFinished ;
Workers . Finished - = ChkFilesFinished ;
Workers . Finished - = ExtractArchiveFinished ;
Workers . Finished - = FindFilesFinished ;
Workers . Finished - = HashFilesFinished ;
Workers . Finished - = OpenArchiveFinished ;
Workers . Finished - = RemoveTempFilesFinished ;
2017-05-17 06:53:47 +01:00
Workers . FinishedWithText - = PackFilesFinished ;
2017-12-30 00:32:21 +00:00
Workers . UpdateProgress - = UpdateProgress ;
Workers . UpdateProgress2 - = UpdateProgress2 ;
2017-05-17 06:53:47 +01:00
2017-05-15 07:33:13 +01:00
if ( thdFindFiles ! = null )
{
thdFindFiles . Abort ( ) ;
thdFindFiles = null ;
}
if ( thdHashFiles ! = null )
{
thdHashFiles . Abort ( ) ;
thdHashFiles = null ;
}
if ( thdCheckFiles ! = null )
{
thdCheckFiles . Abort ( ) ;
thdCheckFiles = null ;
}
if ( thdAddFiles ! = null )
{
thdAddFiles . Abort ( ) ;
thdAddFiles = null ;
}
if ( thdPackFiles ! = null )
{
thdPackFiles . Abort ( ) ;
thdPackFiles = null ;
}
if ( thdOpenArchive ! = null )
{
thdOpenArchive . Abort ( ) ;
thdOpenArchive = null ;
}
2017-12-30 00:32:21 +00:00
if ( Context . UnarProcess ! = null )
2017-05-15 07:33:13 +01:00
{
2017-12-30 00:32:21 +00:00
Context . UnarProcess . Kill ( ) ;
Context . UnarProcess = null ;
2017-05-15 07:33:13 +01:00
}
2017-12-30 00:32:21 +00:00
if ( Context . TmpFolder ! = null )
2017-05-15 07:33:13 +01:00
{
2017-12-30 00:32:21 +00:00
btnStop . Visible = false ;
lblProgress . Text = "Removing temporary files" ;
prgProgress . Indeterminate = true ;
Workers . Failed + = RemoveTempFilesFailed ;
Workers . Finished + = RemoveTempFilesFinished ;
thdRemoveTemp = new Thread ( Workers . RemoveTempFolder ) ;
2017-05-15 07:33:13 +01:00
thdRemoveTemp . Start ( ) ;
}
2017-12-30 00:32:21 +00:00
else RestoreUi ( ) ;
2017-05-15 07:33:13 +01:00
}
2017-12-30 00:32:21 +00:00
void RestoreUi ( )
2017-05-15 07:33:13 +01:00
{
2017-12-30 00:32:21 +00:00
lblProgress . Visible = false ;
prgProgress . Visible = false ;
lblProgress2 . Visible = false ;
prgProgress2 . Visible = false ;
btnExit . Enabled = true ;
btnFolder . Visible = true ;
btnArchive . Visible = true ;
lblProgress . Visible = false ;
prgProgress . Visible = false ;
btnExit . Enabled = true ;
btnFolder . Visible = true ;
btnArchive . Visible = true ;
Workers . Failed - = FindFilesFailed ;
Workers . Failed - = HashFilesFailed ;
Workers . Failed - = ChkFilesFailed ;
Workers . Failed - = OpenArchiveFailed ;
Workers . Failed - = AddFilesToDbFailed ;
Workers . Failed - = PackFilesFailed ;
Workers . Failed - = ExtractArchiveFailed ;
Workers . Failed - = RemoveTempFilesFailed ;
Workers . Finished - = FindFilesFinished ;
Workers . Finished - = HashFilesFinished ;
Workers . Finished - = ChkFilesFinished ;
Workers . Finished - = OpenArchiveFinished ;
Workers . Finished - = AddFilesToDbFinished ;
Workers . Finished - = ExtractArchiveFinished ;
Workers . Finished - = RemoveTempFilesFinished ;
2017-05-15 07:33:13 +01:00
Workers . FinishedWithText - = PackFilesFinished ;
2017-12-30 00:32:21 +00:00
Workers . UpdateProgress - = UpdateProgress ;
Workers . UpdateProgress2 - = UpdateProgress2 ;
btnStop . Visible = false ;
fileView ? . Clear ( ) ;
2018-02-23 03:33:22 +00:00
if ( appView = = null ) return ;
2017-12-30 00:32:21 +00:00
2018-02-23 03:33:22 +00:00
tabApps . Visible = false ;
appView . Clear ( ) ;
2017-05-15 07:33:13 +01:00
}
2017-12-30 00:32:21 +00:00
void RemoveTempFilesFailed ( string text )
2017-05-15 07:33:13 +01:00
{
Application . Instance . Invoke ( delegate
{
MessageBox . Show ( text , MessageBoxType . Error ) ;
2017-12-30 00:32:21 +00:00
Workers . Failed - = RemoveTempFilesFailed ;
Workers . Finished - = RemoveTempFilesFinished ;
Context . Path = null ;
Context . TmpFolder = null ;
RestoreUi ( ) ;
2017-05-15 07:33:13 +01:00
} ) ;
}
2017-12-30 00:32:21 +00:00
void RemoveTempFilesFinished ( )
2017-05-15 07:33:13 +01:00
{
Application . Instance . Invoke ( delegate
{
2017-12-30 00:32:21 +00:00
Workers . Failed - = RemoveTempFilesFailed ;
Workers . Finished - = RemoveTempFilesFinished ;
Context . Path = null ;
Context . TmpFolder = null ;
RestoreUi ( ) ;
2017-05-15 07:33:13 +01:00
} ) ;
}
void AddToDatabase ( )
{
2018-03-16 15:44:21 +00:00
btnRemoveFile . Enabled = false ;
btnToggleCrack . Enabled = false ;
btnPack . Enabled = false ;
btnClose . Enabled = false ;
prgProgress . Visible = true ;
txtFormat . ReadOnly = true ;
txtDescription . ReadOnly = true ;
chkOem . Enabled = false ;
chkFiles . Enabled = false ;
chkUpdate . Enabled = false ;
chkUpgrade . Enabled = false ;
chkInstaller . Enabled = false ;
chkSource . Enabled = false ;
2017-05-15 07:33:13 +01:00
Workers . UpdateProgress + = UpdateProgress ;
2017-12-30 00:32:21 +00:00
Workers . Finished + = AddFilesToDbFinished ;
Workers . Failed + = AddFilesToDbFailed ;
Context . DbInfo . Architecture = txtArchitecture . Text ;
Context . DbInfo . Description = txtDescription . Text ;
Context . DbInfo . Developer = txtDeveloper . Text ;
Context . DbInfo . Format = txtFormat . Text ;
Context . DbInfo . Languages = txtLanguages . Text ;
2018-03-15 15:55:59 +00:00
Context . DbInfo . TargetOs = txtTargetOs . Text ;
2017-12-30 00:32:21 +00:00
Context . DbInfo . Product = txtProduct . Text ;
Context . DbInfo . Version = txtVersion . Text ;
Context . DbInfo . Files = chkFiles . Checked . Value ;
2018-03-15 15:55:59 +00:00
Context . DbInfo . Installer = chkInstaller . Checked . Value ;
2017-12-30 00:32:21 +00:00
Context . DbInfo . Oem = chkOem . Checked . Value ;
Context . DbInfo . Source = chkSource . Checked . Value ;
Context . DbInfo . Update = chkUpdate . Checked . Value ;
Context . DbInfo . Upgrade = chkUpgrade . Checked . Value ;
if ( Context . Metadata ! = null )
2017-05-15 07:33:13 +01:00
{
2017-12-30 00:32:21 +00:00
MemoryStream ms = new MemoryStream ( ) ;
2017-05-15 07:33:13 +01:00
XmlSerializer xs = new XmlSerializer ( typeof ( CICMMetadataType ) ) ;
2017-12-30 00:32:21 +00:00
xs . Serialize ( ms , Context . Metadata ) ;
Context . DbInfo . Xml = ms . ToArray ( ) ;
2018-03-15 15:55:59 +00:00
JsonSerializer js = new JsonSerializer ( ) ;
ms = new MemoryStream ( ) ;
StreamWriter sw = new StreamWriter ( ms ) ;
2017-12-30 00:32:21 +00:00
js . Serialize ( sw , Context . Metadata , typeof ( CICMMetadataType ) ) ;
Context . DbInfo . Json = ms . ToArray ( ) ;
2017-05-15 07:33:13 +01:00
}
else
{
2017-12-30 00:32:21 +00:00
Context . DbInfo . Xml = null ;
Context . DbInfo . Json = null ;
2017-05-15 07:33:13 +01:00
}
thdAddFiles = new Thread ( Workers . AddFilesToDb ) ;
thdAddFiles . Start ( ) ;
}
2017-12-30 00:32:21 +00:00
void AddFilesToDbFinished ( )
2017-05-15 07:33:13 +01:00
{
Application . Instance . Invoke ( delegate
{
Workers . UpdateProgress - = UpdateProgress ;
2017-12-30 00:32:21 +00:00
Workers . Finished - = AddFilesToDbFinished ;
Workers . Failed - = AddFilesToDbFailed ;
2017-05-15 07:33:13 +01:00
2017-12-30 00:32:21 +00:00
thdAddFiles ? . Abort ( ) ;
2017-05-17 06:53:47 +01:00
2017-05-15 07:33:13 +01:00
long counter = 0 ;
fileView . Clear ( ) ;
2018-02-23 03:33:22 +00:00
foreach ( KeyValuePair < string , DbAppFile > kvp in Context . Hashes )
2017-05-15 07:33:13 +01:00
{
2017-12-30 00:32:21 +00:00
UpdateProgress ( null , "Updating table" , counter , Context . Hashes . Count ) ;
fileView . Add ( new FileEntry { Path = kvp . Key , Hash = kvp . Value . Sha256 , Known = true } ) ;
2017-05-15 07:33:13 +01:00
counter + + ;
}
2018-02-23 03:33:22 +00:00
// TODO: Update application table
2017-05-15 07:33:13 +01:00
2018-02-23 03:33:22 +00:00
OnAddedApp ? . Invoke ( Context . DbInfo ) ;
2017-05-15 07:33:13 +01:00
2017-05-17 06:26:20 +01:00
lblProgress . Visible = false ;
2017-05-15 07:33:13 +01:00
prgProgress . Visible = false ;
2017-12-30 00:32:21 +00:00
btnClose . Enabled = true ;
2017-05-15 07:33:13 +01:00
} ) ;
}
2017-12-30 00:32:21 +00:00
void AddFilesToDbFailed ( string text )
2017-05-15 07:33:13 +01:00
{
Application . Instance . Invoke ( delegate
{
2017-12-30 00:32:21 +00:00
if ( ! stopped ) MessageBox . Show ( text , MessageBoxType . Error ) ;
2017-05-15 07:33:13 +01:00
Workers . UpdateProgress - = UpdateProgress ;
2017-12-30 00:32:21 +00:00
Workers . Finished - = AddFilesToDbFinished ;
Workers . Failed - = AddFilesToDbFailed ;
2017-05-15 07:33:13 +01:00
2017-12-30 00:32:21 +00:00
thdAddFiles ? . Abort ( ) ;
2017-05-17 06:53:47 +01:00
2017-05-15 07:33:13 +01:00
ChkFilesFinished ( ) ;
} ) ;
}
protected void OnBtnPackClicked ( object sender , EventArgs e )
{
2018-03-16 15:44:21 +00:00
btnRemoveFile . Enabled = false ;
btnToggleCrack . Enabled = false ;
btnPack . Enabled = false ;
btnClose . Enabled = false ;
prgProgress . Visible = true ;
prgProgress2 . Visible = true ;
lblProgress . Visible = true ;
lblProgress2 . Visible = true ;
txtFormat . ReadOnly = true ;
txtDescription . ReadOnly = true ;
chkOem . Enabled = false ;
chkFiles . Enabled = false ;
chkUpdate . Enabled = false ;
chkUpgrade . Enabled = false ;
chkInstaller . Enabled = false ;
chkSource . Enabled = false ;
2017-12-30 00:32:21 +00:00
Workers . UpdateProgress + = UpdateProgress ;
Workers . UpdateProgress2 + = UpdateProgress2 ;
2017-05-15 07:33:13 +01:00
Workers . FinishedWithText + = PackFilesFinished ;
2017-12-30 00:32:21 +00:00
Workers . Failed + = PackFilesFailed ;
Context . DbInfo . Architecture = txtArchitecture . Text ;
Context . DbInfo . Description = txtDescription . Text ;
Context . DbInfo . Developer = txtDeveloper . Text ;
Context . DbInfo . Format = txtFormat . Text ;
Context . DbInfo . Languages = txtLanguages . Text ;
2018-03-15 15:55:59 +00:00
Context . DbInfo . TargetOs = txtTargetOs . Text ;
2017-12-30 00:32:21 +00:00
Context . DbInfo . Product = txtProduct . Text ;
Context . DbInfo . Version = txtVersion . Text ;
Context . DbInfo . Files = chkFiles . Checked . Value ;
2018-03-15 15:55:59 +00:00
Context . DbInfo . Installer = chkInstaller . Checked . Value ;
2017-12-30 00:32:21 +00:00
Context . DbInfo . Oem = chkOem . Checked . Value ;
Context . DbInfo . Source = chkSource . Checked . Value ;
Context . DbInfo . Update = chkUpdate . Checked . Value ;
Context . DbInfo . Upgrade = chkUpgrade . Checked . Value ;
2017-05-15 07:33:13 +01:00
thdPackFiles = new Thread ( Workers . CompressFiles ) ;
thdPackFiles . Start ( ) ;
}
2017-12-30 00:32:21 +00:00
void PackFilesFinished ( string text )
2017-05-15 07:33:13 +01:00
{
Application . Instance . Invoke ( delegate
{
2017-12-30 00:32:21 +00:00
Workers . UpdateProgress - = UpdateProgress ;
Workers . UpdateProgress2 - = UpdateProgress2 ;
2017-05-15 07:33:13 +01:00
Workers . FinishedWithText - = PackFilesFinished ;
2017-12-30 00:32:21 +00:00
Workers . Failed - = PackFilesFailed ;
prgProgress2 . Visible = false ;
lblProgress2 . Visible = false ;
2017-05-15 07:33:13 +01:00
2017-12-30 00:32:21 +00:00
thdPackFiles ? . Abort ( ) ;
2017-05-17 06:53:47 +01:00
2017-05-15 07:33:13 +01:00
AddToDatabase ( ) ;
MessageBox . Show ( text ) ;
} ) ;
}
2017-12-30 00:32:21 +00:00
void PackFilesFailed ( string text )
2017-05-15 07:33:13 +01:00
{
Application . Instance . Invoke ( delegate
{
2017-12-30 00:32:21 +00:00
if ( ! stopped ) MessageBox . Show ( text , MessageBoxType . Error ) ;
2017-05-15 07:33:13 +01:00
2017-12-30 00:32:21 +00:00
Workers . UpdateProgress - = UpdateProgress ;
Workers . UpdateProgress2 - = UpdateProgress2 ;
2017-05-15 07:33:13 +01:00
Workers . FinishedWithText - = PackFilesFinished ;
2017-12-30 00:32:21 +00:00
Workers . Failed - = PackFilesFailed ;
thdPackFiles ? . Abort ( ) ;
2018-03-16 15:44:21 +00:00
btnRemoveFile . Enabled = true ;
btnToggleCrack . Enabled = true ;
btnPack . Enabled = true ;
btnClose . Enabled = true ;
prgProgress . Visible = false ;
prgProgress2 . Visible = false ;
lblProgress . Visible = false ;
lblProgress2 . Visible = false ;
txtFormat . ReadOnly = false ;
txtDescription . ReadOnly = false ;
chkOem . Enabled = true ;
chkFiles . Enabled = true ;
chkUpdate . Enabled = true ;
chkUpgrade . Enabled = true ;
chkInstaller . Enabled = true ;
chkSource . Enabled = true ;
2017-05-15 07:33:13 +01:00
} ) ;
}
protected void OnBtnArchiveClicked ( object sender , EventArgs e )
{
2017-12-30 00:32:21 +00:00
if ( ! Context . UnarUsable )
2017-05-15 07:33:13 +01:00
{
MessageBox . Show ( "Cannot open archives without a working unar installation." , MessageBoxType . Error ) ;
return ;
}
2017-12-30 00:32:21 +00:00
OpenFileDialog dlgFile = new OpenFileDialog { Title = "Open archive" , MultiSelect = false } ;
if ( dlgFile . ShowDialog ( this ) ! = DialogResult . Ok ) return ;
knownFiles = 0 ;
stopped = false ;
lblProgress . Text = "Opening archive" ;
lblProgress . Visible = false ;
prgProgress . Visible = true ;
btnExit . Enabled = false ;
btnFolder . Visible = false ;
btnArchive . Visible = false ;
prgProgress . Indeterminate = true ;
thdOpenArchive = new Thread ( Workers . OpenArchive ) ;
Context . Path = dlgFile . FileName ;
Workers . Failed + = OpenArchiveFailed ;
Workers . Finished + = OpenArchiveFinished ;
btnStop . Visible = true ;
thdOpenArchive . Start ( ) ;
2017-05-15 07:33:13 +01:00
}
2017-12-30 00:32:21 +00:00
void OpenArchiveFailed ( string text )
2017-05-15 07:33:13 +01:00
{
Application . Instance . Invoke ( delegate
{
2017-12-30 00:32:21 +00:00
if ( ! stopped ) MessageBox . Show ( text , MessageBoxType . Error ) ;
lblProgress . Visible = false ;
prgProgress . Visible = false ;
btnExit . Enabled = true ;
btnFolder . Visible = true ;
btnArchive . Visible = true ;
btnStop . Visible = false ;
Workers . Failed - = OpenArchiveFailed ;
Workers . Finished - = OpenArchiveFinished ;
thdOpenArchive = null ;
2017-05-15 07:33:13 +01:00
} ) ;
}
2017-12-30 00:32:21 +00:00
void OpenArchiveFinished ( )
2017-05-15 07:33:13 +01:00
{
Application . Instance . Invoke ( delegate
{
2017-12-30 00:32:21 +00:00
stopped = false ;
lblProgress . Text = "Extracting archive" ;
prgProgress . Visible = true ;
prgProgress2 . Visible = true ;
btnExit . Enabled = false ;
btnFolder . Visible = false ;
btnArchive . Visible = false ;
Workers . UpdateProgress + = UpdateProgress ;
lblProgress . Visible = true ;
lblProgress2 . Visible = true ;
Workers . Failed - = OpenArchiveFailed ;
Workers . Finished - = OpenArchiveFinished ;
thdOpenArchive = null ;
Workers . Failed + = ExtractArchiveFailed ;
Workers . Finished + = ExtractArchiveFinished ;
2017-05-15 07:33:13 +01:00
Workers . UpdateProgress2 + = UpdateProgress2 ;
2017-12-30 00:32:21 +00:00
thdExtractArchive = new Thread ( Workers . ExtractArchive ) ;
2017-05-15 07:33:13 +01:00
thdExtractArchive . Start ( ) ;
} ) ;
}
2017-12-30 00:32:21 +00:00
void ExtractArchiveFailed ( string text )
2017-05-15 07:33:13 +01:00
{
Application . Instance . Invoke ( delegate
{
2017-12-30 00:32:21 +00:00
if ( ! stopped ) MessageBox . Show ( text , MessageBoxType . Error ) ;
lblProgress2 . Visible = false ;
prgProgress2 . Visible = false ;
btnExit . Enabled = true ;
btnFolder . Visible = true ;
btnArchive . Visible = true ;
Workers . Failed - = ExtractArchiveFailed ;
Workers . Finished - = ExtractArchiveFinished ;
Workers . UpdateProgress - = UpdateProgress ;
2017-05-15 07:33:13 +01:00
Workers . UpdateProgress2 - = UpdateProgress2 ;
2017-12-30 00:32:21 +00:00
thdExtractArchive = null ;
if ( Context . TmpFolder = = null ) return ;
btnStop . Visible = false ;
lblProgress . Text = "Removing temporary files" ;
prgProgress . Indeterminate = true ;
Workers . Failed + = RemoveTempFilesFailed ;
Workers . Finished + = RemoveTempFilesFinished ;
thdRemoveTemp = new Thread ( Workers . RemoveTempFolder ) ;
thdRemoveTemp . Start ( ) ;
2017-05-15 07:33:13 +01:00
} ) ;
}
2017-12-30 00:32:21 +00:00
void ExtractArchiveFinished ( )
2017-05-15 07:33:13 +01:00
{
Application . Instance . Invoke ( delegate
{
2017-12-30 00:32:21 +00:00
stopped = false ;
lblProgress . Text = "Finding files" ;
lblProgress . Visible = true ;
lblProgress2 . Visible = false ;
prgProgress . Visible = true ;
btnExit . Enabled = false ;
btnFolder . Visible = false ;
btnArchive . Visible = false ;
Workers . Failed - = ExtractArchiveFailed ;
Workers . Finished - = ExtractArchiveFinished ;
Workers . UpdateProgress - = UpdateProgress ;
Workers . UpdateProgress2 - = UpdateProgress2 ;
prgProgress . Indeterminate = true ;
thdExtractArchive = null ;
thdFindFiles = new Thread ( Workers . FindFiles ) ;
Workers . Failed + = FindFilesFailed ;
Workers . Finished + = FindFilesFinished ;
btnStop . Visible = true ;
2017-05-15 07:33:13 +01:00
thdFindFiles . Start ( ) ;
} ) ;
}
protected void OnBtnMetadataClicked ( object sender , EventArgs e )
{
2017-12-30 00:32:21 +00:00
dlgMetadata _dlgMetadata = new dlgMetadata { Metadata = Context . Metadata } ;
2017-05-15 07:33:13 +01:00
_dlgMetadata . FillFields ( ) ;
_dlgMetadata . ShowModal ( this ) ;
2017-12-30 00:32:21 +00:00
if ( ! _dlgMetadata . Modified ) return ;
2017-05-15 07:33:13 +01:00
2017-12-30 00:32:21 +00:00
Context . Metadata = _dlgMetadata . Metadata ;
if ( string . IsNullOrWhiteSpace ( txtDeveloper . Text ) )
if ( Context . Metadata . Developer ! = null )
foreach ( string developer in Context . Metadata . Developer )
2017-05-15 07:33:13 +01:00
{
2017-12-30 00:32:21 +00:00
if ( ! string . IsNullOrWhiteSpace ( txtDeveloper . Text ) ) txtDeveloper . Text + = "," ;
2018-03-15 15:55:59 +00:00
txtDeveloper . Text + = developer ;
2017-05-15 07:33:13 +01:00
}
2017-12-30 00:32:21 +00:00
if ( string . IsNullOrWhiteSpace ( txtProduct . Text ) )
if ( ! string . IsNullOrWhiteSpace ( Context . Metadata . Name ) )
txtProduct . Text = Context . Metadata . Name ;
2017-05-15 07:33:13 +01:00
2017-12-30 00:32:21 +00:00
if ( string . IsNullOrWhiteSpace ( txtVersion . Text ) )
if ( ! string . IsNullOrWhiteSpace ( Context . Metadata . Version ) )
txtVersion . Text = Context . Metadata . Version ;
2017-05-15 07:33:13 +01:00
2017-12-30 00:32:21 +00:00
if ( string . IsNullOrWhiteSpace ( txtLanguages . Text ) )
if ( Context . Metadata . Languages ! = null )
foreach ( LanguagesTypeLanguage language in Context . Metadata . Languages )
2017-05-15 07:33:13 +01:00
{
2017-12-30 00:32:21 +00:00
if ( ! string . IsNullOrWhiteSpace ( txtLanguages . Text ) ) txtLanguages . Text + = "," ;
2018-03-15 15:55:59 +00:00
txtLanguages . Text + = language ;
2017-05-15 07:33:13 +01:00
}
2017-12-30 00:32:21 +00:00
if ( string . IsNullOrWhiteSpace ( txtArchitecture . Text ) )
if ( Context . Metadata . Architectures ! = null )
foreach ( ArchitecturesTypeArchitecture architecture in Context . Metadata . Architectures )
2017-05-15 07:33:13 +01:00
{
2017-12-30 00:32:21 +00:00
if ( ! string . IsNullOrWhiteSpace ( txtArchitecture . Text ) ) txtArchitecture . Text + = "," ;
2018-03-15 15:55:59 +00:00
txtArchitecture . Text + = architecture ;
2017-05-15 07:33:13 +01:00
}
2018-03-15 15:55:59 +00:00
if ( string . IsNullOrWhiteSpace ( txtTargetOs . Text ) )
if ( Context . Metadata . RequiredOperatingSystems ! = null )
foreach ( string targetos in Context . Metadata . RequiredOperatingSystems . Select ( os = > os . Name )
. Distinct ( ) )
2017-05-15 07:33:13 +01:00
{
2018-03-15 15:55:59 +00:00
if ( ! string . IsNullOrWhiteSpace ( txtTargetOs . Text ) ) txtTargetOs . Text + = "," ;
txtTargetOs . Text + = targetos ;
2017-05-15 07:33:13 +01:00
}
2017-12-30 00:32:21 +00:00
btnMetadata . BackgroundColor = Colors . Green ;
2017-05-15 07:33:13 +01:00
}
protected void OnBtnRemoveFileClicked ( object sender , EventArgs e )
{
2017-12-30 00:32:21 +00:00
if ( treeFiles . SelectedItem = = null ) return ;
2017-05-15 07:33:13 +01:00
2017-12-30 00:32:21 +00:00
string name = ( ( FileEntry ) treeFiles . SelectedItem ) . Path ;
string filesPath ;
2017-05-15 07:33:13 +01:00
2017-12-30 00:32:21 +00:00
if ( ! string . IsNullOrEmpty ( Context . TmpFolder ) & & Directory . Exists ( Context . TmpFolder ) )
filesPath = Context . TmpFolder ;
else filesPath = Context . Path ;
Context . Hashes . Remove ( name ) ;
Context . Files . Remove ( Path . Combine ( filesPath , name ) ) ;
fileView . Remove ( ( FileEntry ) treeFiles . SelectedItem ) ;
2017-05-15 07:30:27 +01:00
}
2017-05-18 17:56:28 +01:00
protected void OnBtnToggleCrackClicked ( object sender , EventArgs e )
{
2017-12-30 00:32:21 +00:00
if ( treeFiles . SelectedItem = = null ) return ;
2017-05-18 17:56:28 +01:00
2017-12-30 00:32:21 +00:00
string name = ( ( FileEntry ) treeFiles . SelectedItem ) . Path ;
bool known = ( ( FileEntry ) treeFiles . SelectedItem ) . Known ;
2017-05-18 17:56:28 +01:00
2018-02-23 03:33:22 +00:00
if ( ! Context . Hashes . TryGetValue ( name , out DbAppFile appFile ) ) return ;
2017-12-30 00:32:21 +00:00
2018-02-23 03:33:22 +00:00
appFile . Crack = ! appFile . Crack ;
2017-12-30 00:32:21 +00:00
Context . Hashes . Remove ( name ) ;
2018-02-23 03:33:22 +00:00
Context . Hashes . Add ( name , appFile ) ;
( ( FileEntry ) treeFiles . SelectedItem ) . IsCrack = appFile . Crack ;
2017-12-30 00:32:21 +00:00
fileView . Remove ( ( FileEntry ) treeFiles . SelectedItem ) ;
2018-02-23 03:33:22 +00:00
fileView . Add ( new FileEntry { Path = name , Hash = appFile . Sha256 , Known = known , IsCrack = appFile . Crack } ) ;
2017-05-18 17:56:28 +01:00
}
void treeFilesSelectionChanged ( object sender , EventArgs e )
{
2017-12-30 00:32:21 +00:00
if ( treeFiles . SelectedItem = = null ) return ;
btnToggleCrack . Text = ( ( FileEntry ) treeFiles . SelectedItem ) . IsCrack ? "Mark as not crack" : "Mark as crack" ;
2017-05-18 17:56:28 +01:00
}
2017-12-30 00:32:21 +00:00
class FileEntry
{
public string Path { get ; set ; }
public string Hash { get ; set ; }
public bool Known { get ; set ; }
public bool IsCrack { get ; set ; }
}
#region XAML UI elements
#pragma warning disable 0649
TextBox txtDeveloper ;
TextBox txtProduct ;
TextBox txtVersion ;
TextBox txtLanguages ;
TextBox txtArchitecture ;
2018-03-15 15:55:59 +00:00
TextBox txtTargetOs ;
2017-12-30 00:32:21 +00:00
TextBox txtFormat ;
2018-03-15 17:30:13 +00:00
TextArea txtDescription ;
2017-12-30 00:32:21 +00:00
CheckBox chkOem ;
CheckBox chkUpdate ;
CheckBox chkUpgrade ;
CheckBox chkFiles ;
CheckBox chkSource ;
2018-03-15 15:55:59 +00:00
CheckBox chkInstaller ;
2017-12-30 00:32:21 +00:00
GridView treeFiles ;
2018-02-23 03:33:22 +00:00
TabPage tabApps ;
GridView treeApps ;
2017-12-30 00:32:21 +00:00
Label lblProgress ;
ProgressBar prgProgress ;
Label lblProgress2 ;
ProgressBar prgProgress2 ;
Button btnRemoveFile ;
Button btnMetadata ;
Button btnStop ;
Button btnFolder ;
Button btnArchive ;
Button btnPack ;
Button btnClose ;
Button btnExit ;
Button btnToggleCrack ;
Label lblStatus ;
#pragma warning restore 0649
#endregion XAML UI elements
2017-05-15 07:30:27 +01:00
}
2017-05-15 07:33:13 +01:00
}