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 ;
2017-05-18 16:33:32 +01:00
using System.Collections.Generic ;
2017-05-16 03:36:57 +01:00
using System.Collections.ObjectModel ;
using System.Threading ;
2017-05-15 07:30:27 +01:00
using Eto.Drawing ;
2017-05-16 03:36:57 +01:00
using Eto.Forms ;
2017-05-15 07:30:27 +01:00
using Eto.Serialization.Xaml ;
2017-05-15 07:33:13 +01:00
using osrepodbmgr.Core ;
2017-05-15 07:30:27 +01:00
namespace osrepodbmgr.Eto
{
2017-05-15 07:33:13 +01:00
public class frmMain : Form
2017-05-15 07:30:27 +01:00
{
2017-12-30 00:32:21 +00:00
int infectedFiles ;
ObservableCollection < DbFile > lstFiles ;
2017-05-15 07:33:13 +01:00
ObservableCollection < DBEntryForEto > lstOSes ;
2017-12-30 00:32:21 +00:00
DbFile outIter ;
bool populatingFiles ;
bool scanningFiles ;
Thread thdCleanFiles ;
Thread thdCompressTo ;
Thread thdPopulateFiles ;
Thread thdPopulateOSes ;
Thread thdSaveAs ;
Thread thdScanFile ;
2017-05-15 07:33:13 +01:00
2017-05-15 07:30:27 +01:00
public frmMain ( )
{
XamlReader . Load ( this ) ;
2017-05-15 07:33:13 +01:00
Workers . InitDB ( ) ;
lstOSes = new ObservableCollection < DBEntryForEto > ( ) ;
treeOSes . DataStore = lstOSes ;
treeOSes . Columns . Add ( new GridColumn
{
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"
} ) ;
treeOSes . Columns . Add ( new GridColumn
{
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"
} ) ;
treeOSes . Columns . Add ( new GridColumn
{
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"
} ) ;
treeOSes . Columns . Add ( new GridColumn
{
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"
} ) ;
treeOSes . Columns . Add ( new GridColumn
{
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"
} ) ;
treeOSes . Columns . Add ( new GridColumn
{
2017-12-30 00:32:21 +00:00
DataCell = new TextBoxCell { Binding = Binding . Property < DBEntryForEto , string > ( r = > r . machine ) } ,
2017-05-15 07:33:13 +01:00
HeaderText = "Machine"
} ) ;
treeOSes . Columns . Add ( new GridColumn
{
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"
} ) ;
treeOSes . Columns . Add ( new GridColumn
{
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"
} ) ;
treeOSes . Columns . Add ( new GridColumn
{
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?"
} ) ;
treeOSes . Columns . Add ( new GridColumn
{
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?"
} ) ;
treeOSes . Columns . Add ( new GridColumn
{
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?"
} ) ;
treeOSes . Columns . Add ( new GridColumn
{
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?"
} ) ;
treeOSes . Columns . Add ( new GridColumn
{
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?"
} ) ;
treeOSes . Columns . Add ( new GridColumn
{
2017-12-30 00:32:21 +00:00
DataCell = new CheckBoxCell { Binding = Binding . Property < DBEntryForEto , bool? > ( r = > r . netinstall ) } ,
2017-05-15 07:33:13 +01:00
HeaderText = "NetInstall?"
} ) ;
treeOSes . AllowMultipleSelection = false ;
2017-12-30 00:32:21 +00:00
lstFiles = new ObservableCollection < DbFile > ( ) ;
2017-05-18 16:33:32 +01:00
treeFiles . DataStore = lstFiles ;
treeFiles . Columns . Add ( new GridColumn
{
2017-12-30 00:32:21 +00:00
DataCell = new TextBoxCell { Binding = Binding . Property < DbFile , string > ( r = > r . Sha256 ) } ,
2017-05-18 16:33:32 +01:00
HeaderText = "SHA256"
} ) ;
treeFiles . Columns . Add ( new GridColumn
{
2017-12-30 00:32:21 +00:00
DataCell = new TextBoxCell
{
Binding = Binding . Property < DbFile , long > ( r = > r . Length ) . Convert ( s = > s . ToString ( ) )
} ,
2017-05-18 16:33:32 +01:00
HeaderText = "Length"
} ) ;
treeFiles . Columns . Add ( new GridColumn
{
2017-12-30 00:32:21 +00:00
DataCell = new CheckBoxCell { Binding = Binding . Property < DbFile , bool? > ( r = > r . Crack ) } ,
2017-05-18 16:33:32 +01:00
HeaderText = "Crack?"
} ) ;
treeFiles . Columns . Add ( new GridColumn
{
2017-12-30 00:32:21 +00:00
DataCell = new CheckBoxCell { Binding = Binding . Property < DbFile , bool? > ( r = > r . HasVirus ) } ,
2017-05-19 01:56:33 +01:00
HeaderText = "Has virus?"
2017-05-18 16:33:32 +01:00
} ) ;
treeFiles . Columns . Add ( new GridColumn
{
2017-12-30 00:32:21 +00:00
DataCell = new TextBoxCell
{
Binding = Binding . Property < DbFile , DateTime ? > ( r = > r . ClamTime )
. Convert ( s = > s = = null ? "Never" : s . Value . ToString ( ) )
} ,
2017-05-18 16:33:32 +01:00
HeaderText = "Last scanned with clamd"
} ) ;
treeFiles . Columns . Add ( new GridColumn
{
2017-12-30 00:32:21 +00:00
DataCell = new TextBoxCell
{
Binding = Binding . Property < DbFile , DateTime ? > ( r = > r . VirusTotalTime )
. Convert ( s = > s = = null ? "Never" : s . Value . ToString ( ) )
} ,
2017-05-18 16:33:32 +01:00
HeaderText = "Last checked on VirusTotal"
} ) ;
treeFiles . Columns . Add ( new GridColumn
{
2017-12-30 00:32:21 +00:00
DataCell = new TextBoxCell
{
Binding = Binding . Property < DbFile , string > ( r = > r . Virus ) . Convert ( s = > s ? ? "None" )
} ,
2017-05-18 16:33:32 +01:00
HeaderText = "Virus"
} ) ;
2017-12-30 00:32:21 +00:00
treeFiles . AllowMultipleSelection = false ;
treeFiles . CellFormatting + = ( sender , e ) = >
2017-05-18 16:33:32 +01:00
{
2017-12-30 00:32:21 +00:00
if ( ( ( DbFile ) e . Item ) . HasVirus . HasValue )
e . BackgroundColor = ( ( DbFile ) e . Item ) . HasVirus . Value ? Colors . Red : Colors . Green ;
else e . BackgroundColor = Colors . Yellow ;
2017-05-18 16:33:32 +01:00
e . ForegroundColor = Colors . Black ;
} ;
2017-05-15 07:33:13 +01:00
prgProgress . Indeterminate = true ;
2017-12-30 00:32:21 +00:00
if ( ! Context . UsableDotNetZip )
2017-05-16 05:14:39 +01:00
{
btnCompress . Visible = false ;
mnuCompress . Enabled = false ;
}
2017-12-30 00:32:21 +00:00
Workers . Failed + = LoadOSesFailed ;
Workers . Finished + = LoadOSesFinished ;
2017-05-15 07:33:13 +01:00
Workers . UpdateProgress + = UpdateProgress ;
2017-12-30 00:32:21 +00:00
Workers . AddOS + = AddOs ;
Workers . AddFile + = AddFile ;
Workers . AddFiles + = AddFiles ;
thdPopulateOSes = new Thread ( Workers . GetAllOSes ) ;
2017-05-15 07:33:13 +01:00
thdPopulateOSes . Start ( ) ;
}
void LoadOSesFailed ( string text )
{
Application . Instance . Invoke ( delegate
{
2017-12-30 00:32:21 +00:00
MessageBox . Show ( $"Error {text} when populating OSes file, exiting..." , MessageBoxButtons . OK ,
MessageBoxType . Error , MessageBoxDefaultButton . OK ) ;
2017-05-15 07:33:13 +01:00
if ( thdPopulateOSes ! = null )
{
thdPopulateOSes . Abort ( ) ;
thdPopulateOSes = null ;
}
2017-12-30 00:32:21 +00:00
Workers . Failed - = LoadOSesFailed ;
Workers . Finished - = LoadOSesFinished ;
2017-05-15 07:33:13 +01:00
Workers . UpdateProgress - = UpdateProgress ;
Application . Instance . Quit ( ) ;
} ) ;
}
void LoadOSesFinished ( )
{
Application . Instance . Invoke ( delegate
{
2017-12-30 00:32:21 +00:00
Workers . Failed - = LoadOSesFailed ;
Workers . Finished - = LoadOSesFinished ;
2017-05-17 06:53:47 +01:00
Workers . UpdateProgress - = UpdateProgress ;
2017-12-30 00:32:21 +00:00
Workers . AddOS - = AddOs ;
2017-05-15 07:33:13 +01:00
if ( thdPopulateOSes ! = null )
{
thdPopulateOSes . Abort ( ) ;
thdPopulateOSes = null ;
}
2017-12-30 00:32:21 +00:00
2017-05-15 07:33:13 +01:00
lblProgress . Visible = false ;
prgProgress . Visible = false ;
2017-12-30 00:32:21 +00:00
treeOSes . Enabled = true ;
btnAdd . Visible = true ;
btnRemove . Visible = true ;
btnCompress . Visible = Context . UsableDotNetZip ;
btnSave . Visible = true ;
btnHelp . Enabled = true ;
2017-05-15 07:33:13 +01:00
btnSettings . Enabled = true ;
2017-05-19 18:04:21 +01:00
lblOSStatus . Visible = true ;
2017-12-30 00:32:21 +00:00
lblOSStatus . Text = $"{lstOSes.Count} operating systems" ;
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 ) )
2017-12-30 00:32:21 +00:00
lblProgress . Text = $"{text}: {inner}" ;
2017-05-17 06:26:20 +01:00
else if ( ! string . IsNullOrWhiteSpace ( inner ) )
2017-05-15 07:33:13 +01:00
lblProgress . Text = inner ;
else
lblProgress . Text = text ;
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 ) )
2017-12-30 00:32:21 +00:00
lblProgress2 . Text = $"{text}: {inner}" ;
2017-05-17 06:26:20 +01:00
else if ( ! string . IsNullOrWhiteSpace ( inner ) )
2017-05-15 07:33:13 +01:00
lblProgress2 . Text = inner ;
else
lblProgress2 . Text = text ;
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
} ) ;
}
2017-12-30 00:32:21 +00:00
void AddOs ( DbEntry os )
2017-05-15 07:33:13 +01:00
{
2017-12-30 00:32:21 +00:00
Application . Instance . Invoke ( delegate { lstOSes . Add ( new DBEntryForEto ( os ) ) ; } ) ;
2017-05-15 07:33:13 +01:00
}
protected void OnBtnAddClicked ( object sender , EventArgs e )
{
2017-12-30 00:32:21 +00:00
dlgAdd dlgAdd = new dlgAdd ( ) ;
dlgAdd . OnAddedOS + = os = > { lstOSes . Add ( new DBEntryForEto ( os ) ) ; } ;
dlgAdd . ShowModal ( this ) ;
2017-05-15 07:33:13 +01:00
}
protected void OnBtnRemoveClicked ( object sender , EventArgs e )
{
2017-12-30 00:32:21 +00:00
if ( treeOSes . SelectedItem = = null ) return ;
if ( MessageBox . Show ( "Are you sure you want to remove the selected OS?" , MessageBoxButtons . YesNo ,
MessageBoxType . Question , MessageBoxDefaultButton . No ) ! = DialogResult . Yes ) return ;
Workers . RemoveOS ( ( ( DBEntryForEto ) treeOSes . SelectedItem ) . id , ( ( DBEntryForEto ) treeOSes . SelectedItem ) . mdid ) ;
lstOSes . Remove ( ( DBEntryForEto ) treeOSes . SelectedItem ) ;
2017-05-15 07:33:13 +01:00
}
protected void OnBtnSaveClicked ( object sender , EventArgs e )
{
2017-12-30 00:32:21 +00:00
if ( treeOSes . SelectedItem = = null ) return ;
SelectFolderDialog dlgFolder = new SelectFolderDialog { Title = "Save to..." } ;
if ( dlgFolder . ShowDialog ( this ) ! = DialogResult . Ok ) return ;
Context . DbInfo . Id = ( ( DBEntryForEto ) treeOSes . SelectedItem ) . id ;
Context . Path = dlgFolder . Directory ;
lblProgress . Visible = true ;
prgProgress . Visible = true ;
lblProgress2 . Visible = true ;
prgProgress2 . Visible = true ;
treeOSes . Enabled = false ;
btnAdd . Visible = false ;
btnRemove . Visible = false ;
btnCompress . Visible = false ;
btnSave . Visible = false ;
btnHelp . Enabled = true ;
btnSettings . Enabled = false ;
btnStop . Visible = true ;
Workers . Failed + = SaveAsFailed ;
Workers . Finished + = SaveAsFinished ;
Workers . UpdateProgress + = UpdateProgress ;
Workers . UpdateProgress2 + = UpdateProgress2 ;
thdSaveAs = new Thread ( Workers . SaveAs ) ;
thdSaveAs . Start ( ) ;
2017-05-15 07:33:13 +01:00
}
2017-12-30 00:32:21 +00:00
void SaveAsFailed ( string text )
2017-05-15 07:33:13 +01:00
{
Application . Instance . Invoke ( delegate
{
MessageBox . Show ( text , MessageBoxButtons . OK , MessageBoxType . Error ) ;
2017-12-30 00:32:21 +00:00
lblProgress . Visible = false ;
prgProgress . Visible = false ;
2017-05-15 07:33:13 +01:00
lblProgress2 . Visible = false ;
prgProgress2 . Visible = false ;
2017-12-30 00:32:21 +00:00
treeOSes . Enabled = true ;
btnAdd . Visible = true ;
btnRemove . Visible = true ;
btnCompress . Visible = Context . UsableDotNetZip ;
btnSave . Visible = true ;
btnHelp . Enabled = true ;
btnSettings . Enabled = true ;
btnStop . Visible = false ;
Workers . Failed - = SaveAsFailed ;
Workers . Finished - = SaveAsFinished ;
Workers . UpdateProgress - = UpdateProgress ;
2017-05-15 07:33:13 +01:00
Workers . UpdateProgress2 - = UpdateProgress2 ;
2017-05-17 06:53:47 +01:00
if ( thdSaveAs ! = null )
{
thdSaveAs . Abort ( ) ;
thdSaveAs = null ;
}
2017-12-30 00:32:21 +00:00
Context . Path = null ;
2017-05-15 07:33:13 +01:00
} ) ;
}
2017-12-30 00:32:21 +00:00
void SaveAsFinished ( )
2017-05-15 07:33:13 +01:00
{
Application . Instance . Invoke ( delegate
{
2017-12-30 00:32:21 +00:00
lblProgress . Visible = false ;
prgProgress . Visible = false ;
2017-05-15 07:33:13 +01:00
lblProgress2 . Visible = false ;
prgProgress2 . Visible = false ;
2017-12-30 00:32:21 +00:00
treeOSes . Enabled = true ;
btnAdd . Visible = true ;
btnRemove . Visible = true ;
btnCompress . Visible = Context . UsableDotNetZip ;
btnSave . Visible = true ;
btnHelp . Enabled = true ;
btnSettings . Enabled = true ;
btnStop . Visible = false ;
Workers . Failed - = SaveAsFailed ;
Workers . Finished - = SaveAsFinished ;
2017-05-15 07:33:13 +01:00
Workers . UpdateProgress - = UpdateProgress ;
2017-05-17 06:53:47 +01:00
if ( thdSaveAs ! = null )
{
thdSaveAs . Abort ( ) ;
thdSaveAs = null ;
}
2017-12-30 00:32:21 +00:00
MessageBox . Show ( $"Correctly saved to {Context.Path}" ) ;
2017-05-15 07:33:13 +01:00
2017-12-30 00:32:21 +00:00
Context . Path = null ;
2017-05-15 07:33:13 +01:00
} ) ;
}
protected void OnBtnHelpClicked ( object sender , EventArgs e )
{
dlgHelp _dlgHelp = new dlgHelp ( ) ;
_dlgHelp . ShowModal ( ) ;
}
protected void OnBtnSettingsClicked ( object sender , EventArgs e )
{
dlgSettings _dlgSettings = new dlgSettings ( ) ;
_dlgSettings . ShowModal ( ) ;
}
protected void OnBtnQuitClicked ( object sender , EventArgs e )
{
OnBtnStopClicked ( sender , e ) ;
Application . Instance . Quit ( ) ;
}
protected void OnBtnStopClicked ( object sender , EventArgs e )
{
2017-12-30 00:32:21 +00:00
Workers . AddOS - = AddOs ;
Workers . Failed - = CompressToFailed ;
Workers . Failed - = LoadOSesFailed ;
Workers . Failed - = SaveAsFailed ;
Workers . Finished - = CompressToFinished ;
Workers . Finished - = LoadOSesFinished ;
Workers . Finished - = SaveAsFinished ;
Workers . UpdateProgress - = UpdateProgress ;
2017-05-17 06:53:47 +01:00
Workers . UpdateProgress2 - = UpdateProgress2 ;
2017-05-15 07:33:13 +01:00
if ( thdPopulateOSes ! = null )
{
thdPopulateOSes . Abort ( ) ;
thdPopulateOSes = null ;
}
2017-12-30 00:32:21 +00:00
2017-05-15 07:33:13 +01:00
if ( thdCompressTo ! = null )
{
thdPopulateOSes . Abort ( ) ;
thdPopulateOSes = null ;
}
2017-12-30 00:32:21 +00:00
if ( thdSaveAs = = null ) return ;
thdSaveAs . Abort ( ) ;
thdSaveAs = null ;
2017-05-15 07:33:13 +01:00
}
protected void OnDeleteEvent ( object sender , EventArgs e )
{
OnBtnStopClicked ( sender , e ) ;
}
protected void OnBtnCompressClicked ( object sender , EventArgs e )
{
2017-12-30 00:32:21 +00:00
if ( treeOSes . SelectedItem = = null ) return ;
SaveFileDialog dlgFile = new SaveFileDialog { Title = "Compress to..." } ;
if ( dlgFile . ShowDialog ( this ) ! = DialogResult . Ok ) return ;
Context . DbInfo . Id = ( ( DBEntryForEto ) treeOSes . SelectedItem ) . id ;
Context . Path = dlgFile . FileName ;
lblProgress . Visible = true ;
prgProgress . Visible = true ;
lblProgress2 . Visible = true ;
prgProgress2 . Visible = true ;
treeOSes . Enabled = false ;
btnAdd . Visible = false ;
btnRemove . Visible = false ;
btnCompress . Visible = false ;
btnSave . Visible = false ;
//btnHelp.Visible = false;
btnSettings . Enabled = false ;
btnStop . Visible = true ;
Workers . Failed + = CompressToFailed ;
Workers . Finished + = CompressToFinished ;
Workers . UpdateProgress + = UpdateProgress ;
Workers . UpdateProgress2 + = UpdateProgress2 ;
thdCompressTo = new Thread ( Workers . CompressTo ) ;
thdCompressTo . Start ( ) ;
2017-05-15 07:33:13 +01:00
}
2017-12-30 00:32:21 +00:00
void CompressToFailed ( string text )
2017-05-15 07:33:13 +01:00
{
Application . Instance . Invoke ( delegate
{
MessageBox . Show ( text , MessageBoxButtons . OK , MessageBoxType . Error ) ;
2017-12-30 00:32:21 +00:00
lblProgress . Visible = false ;
2017-05-15 07:33:13 +01:00
lblProgress2 . Visible = false ;
2017-12-30 00:32:21 +00:00
prgProgress . Visible = false ;
2017-05-15 07:33:13 +01:00
prgProgress2 . Visible = false ;
2017-12-30 00:32:21 +00:00
treeOSes . Enabled = true ;
btnAdd . Visible = true ;
btnRemove . Visible = true ;
btnCompress . Visible = Context . UsableDotNetZip ;
btnSave . Visible = true ;
btnHelp . Enabled = true ;
btnSettings . Enabled = true ;
btnStop . Visible = false ;
Workers . Failed - = CompressToFailed ;
Workers . Finished - = CompressToFinished ;
Workers . UpdateProgress - = UpdateProgress ;
2017-05-15 07:33:13 +01:00
Workers . UpdateProgress2 - = UpdateProgress2 ;
2017-05-17 06:53:47 +01:00
if ( thdCompressTo ! = null )
{
thdCompressTo . Abort ( ) ;
thdCompressTo = null ;
}
2017-12-30 00:32:21 +00:00
Context . Path = null ;
2017-05-15 07:33:13 +01:00
} ) ;
}
2017-12-30 00:32:21 +00:00
void CompressToFinished ( )
2017-05-15 07:33:13 +01:00
{
Application . Instance . Invoke ( delegate
{
2017-12-30 00:32:21 +00:00
lblProgress . Visible = false ;
2017-05-15 07:33:13 +01:00
lblProgress2 . Visible = false ;
2017-12-30 00:32:21 +00:00
prgProgress . Visible = false ;
2017-05-15 07:33:13 +01:00
prgProgress2 . Visible = false ;
2017-12-30 00:32:21 +00:00
treeOSes . Enabled = true ;
btnAdd . Visible = true ;
btnRemove . Visible = true ;
btnCompress . Visible = Context . UsableDotNetZip ;
btnSave . Visible = true ;
btnHelp . Enabled = true ;
btnSettings . Enabled = true ;
btnStop . Visible = false ;
Workers . Failed - = CompressToFailed ;
Workers . Finished - = CompressToFinished ;
Workers . UpdateProgress - = UpdateProgress ;
2017-05-15 07:33:13 +01:00
Workers . UpdateProgress2 - = UpdateProgress2 ;
2017-05-17 06:53:47 +01:00
if ( thdCompressTo ! = null )
{
thdCompressTo . Abort ( ) ;
thdCompressTo = null ;
}
2017-12-30 00:32:21 +00:00
MessageBox . Show ( $"Correctly compressed as {Context.Path}" ) ;
2017-05-15 07:33:13 +01:00
2017-12-30 00:32:21 +00:00
Context . Path = null ;
2017-05-15 07:33:13 +01:00
} ) ;
2017-05-15 07:30:27 +01:00
}
2017-05-18 16:33:32 +01:00
protected void OnBtnStopFilesClicked ( object sender , EventArgs e )
{
if ( populatingFiles )
{
2017-12-30 00:32:21 +00:00
Workers . Failed - = LoadFilesFailed ;
Workers . Finished - = LoadFilesFinished ;
2017-05-19 13:56:32 +01:00
Workers . UpdateProgress - = UpdateFileProgress2 ;
2017-12-30 00:32:21 +00:00
Workers . AddFile - = AddFile ;
Workers . AddFiles - = AddFiles ;
2017-05-18 16:33:32 +01:00
if ( thdPopulateFiles ! = null )
{
thdPopulateFiles . Abort ( ) ;
thdPopulateFiles = null ;
}
lstFiles . Clear ( ) ;
2017-12-30 00:32:21 +00:00
btnStopFiles . Visible = false ;
2017-05-18 16:33:32 +01:00
btnPopulateFiles . Visible = true ;
}
2017-05-19 13:56:32 +01:00
if ( scanningFiles )
if ( thdScanFile ! = null )
{
thdScanFile . Abort ( ) ;
thdScanFile = null ;
}
2017-12-30 00:32:21 +00:00
2017-05-19 13:56:32 +01:00
AllClamdFinished ( ) ;
2017-05-18 16:33:32 +01:00
}
2017-05-18 17:56:28 +01:00
protected void OnBtnToggleCrackClicked ( object sender , EventArgs e )
2017-05-18 16:33:32 +01:00
{
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
DbFile file = ( DbFile ) treeFiles . SelectedItem ;
bool crack = ! file . Crack ;
2017-05-18 17:56:28 +01:00
2017-12-30 00:32:21 +00:00
Workers . ToggleCrack ( file . Sha256 , crack ) ;
lstFiles . Remove ( file ) ;
file . Crack = crack ;
lstFiles . Add ( file ) ;
2017-05-18 16:33:32 +01:00
}
protected void OnBtnScanWithClamdClicked ( object sender , EventArgs e )
{
2017-12-30 00:32:21 +00:00
if ( treeFiles . SelectedItem = = null ) return ;
2017-05-18 22:23:49 +01:00
2017-12-30 00:32:21 +00:00
DbFile file = Workers . GetDBFile ( ( ( DbFile ) treeFiles . SelectedItem ) . Sha256 ) ;
outIter = ( DbFile ) treeFiles . SelectedItem ;
2017-05-18 22:23:49 +01:00
2017-12-30 00:32:21 +00:00
if ( file = = null )
{
MessageBox . Show ( "Cannot get file from database" , MessageBoxType . Error ) ;
return ;
2017-05-18 22:23:49 +01:00
}
2017-12-30 00:32:21 +00:00
treeFiles . Enabled = false ;
btnToggleCrack . Enabled = false ;
btnScanWithClamd . Enabled = false ;
btnCheckInVirusTotal . Enabled = false ;
prgProgressFiles1 . Visible = true ;
lblProgressFiles1 . Visible = true ;
Workers . Failed + = ClamdFailed ;
Workers . ScanFinished + = ClamdFinished ;
Workers . UpdateProgress + = UpdateVirusProgress ;
lblProgressFiles1 . Text = "Scanning file with clamd." ;
prgProgressFiles1 . Indeterminate = true ;
thdScanFile = new Thread ( ( ) = > Workers . ClamScanFileFromRepo ( file ) ) ;
thdScanFile . Start ( ) ;
2017-05-18 22:23:49 +01:00
}
void ClamdFailed ( string text )
{
Application . Instance . Invoke ( delegate
{
2017-12-30 00:32:21 +00:00
treeFiles . Enabled = true ;
btnToggleCrack . Enabled = true ;
btnScanWithClamd . Enabled = true ;
btnCheckInVirusTotal . Enabled = true ;
prgProgressFiles1 . Visible = false ;
lblProgressFiles1 . Visible = false ;
Workers . Failed - = ClamdFailed ;
Workers . ScanFinished - = ClamdFinished ;
Workers . UpdateProgress - = UpdateVirusProgress ;
lblProgressFiles1 . Text = "" ;
if ( thdScanFile = = null ) return ;
thdScanFile . Abort ( ) ;
thdScanFile = null ;
2017-05-18 22:23:49 +01:00
} ) ;
}
2017-12-30 00:32:21 +00:00
void ClamdFinished ( DbFile file )
2017-05-18 22:23:49 +01:00
{
Application . Instance . Invoke ( delegate
{
2017-12-30 00:32:21 +00:00
treeFiles . Enabled = true ;
btnToggleCrack . Enabled = true ;
btnScanWithClamd . Enabled = true ;
btnCheckInVirusTotal . Enabled = true ;
Workers . Failed - = ClamdFailed ;
Workers . ScanFinished - = ClamdFinished ;
Workers . UpdateProgress - = UpdateVirusProgress ;
lblProgressFiles1 . Text = "" ;
prgProgressFiles1 . Visible = false ;
lblProgressFiles1 . Visible = false ;
if ( thdScanFile ! = null ) thdScanFile = null ;
if ( ( ! outIter . HasVirus . HasValue | | outIter . HasVirus . HasValue & & ! outIter . HasVirus . Value ) & &
file . HasVirus . HasValue & & file . HasVirus . Value ) infectedFiles + + ;
2017-05-19 18:04:21 +01:00
2017-05-18 22:23:49 +01:00
lstFiles . Remove ( outIter ) ;
AddFile ( file ) ;
2017-05-19 18:04:21 +01:00
2017-12-30 00:32:21 +00:00
lblFileStatus . Text = $"{lstFiles.Count} files ({infectedFiles} infected)" ;
2017-05-18 22:23:49 +01:00
} ) ;
2017-05-18 16:33:32 +01:00
}
protected void OnBtnCheckInVirusTotalClicked ( object sender , EventArgs e )
{
2017-12-30 00:32:21 +00:00
if ( treeFiles . SelectedItem = = null ) return ;
2017-05-19 01:13:53 +01:00
2017-12-30 00:32:21 +00:00
DbFile file = Workers . GetDBFile ( ( ( DbFile ) treeFiles . SelectedItem ) . Sha256 ) ;
outIter = ( DbFile ) treeFiles . SelectedItem ;
2017-05-19 01:13:53 +01:00
2017-12-30 00:32:21 +00:00
if ( file = = null )
{
MessageBox . Show ( "Cannot get file from database" , MessageBoxType . Error ) ;
return ;
2017-05-19 01:13:53 +01:00
}
2017-12-30 00:32:21 +00:00
treeFiles . Enabled = false ;
btnToggleCrack . Enabled = false ;
btnScanWithClamd . Enabled = false ;
btnCheckInVirusTotal . Enabled = false ;
prgProgressFiles1 . Visible = true ;
lblProgressFiles1 . Visible = true ;
Workers . Failed + = VirusTotalFailed ;
Workers . ScanFinished + = VirusTotalFinished ;
Workers . UpdateProgress + = UpdateVirusProgress ;
lblProgressFiles1 . Text = "Scanning file with VirusTotal." ;
prgProgressFiles1 . Indeterminate = true ;
thdScanFile = new Thread ( ( ) = > Workers . VirusTotalFileFromRepo ( file ) ) ;
thdScanFile . Start ( ) ;
2017-05-18 16:33:32 +01:00
}
2017-05-19 01:13:53 +01:00
void VirusTotalFailed ( string text )
{
Application . Instance . Invoke ( delegate
{
2017-12-30 00:32:21 +00:00
treeFiles . Enabled = true ;
btnToggleCrack . Enabled = true ;
btnScanWithClamd . Enabled = true ;
btnCheckInVirusTotal . Enabled = true ;
prgProgressFiles1 . Visible = false ;
Workers . Failed - = VirusTotalFailed ;
Workers . ScanFinished - = VirusTotalFinished ;
Workers . UpdateProgress - = UpdateVirusProgress ;
lblProgressFiles1 . Text = "" ;
if ( thdScanFile ! = null ) thdScanFile = null ;
2017-05-19 03:25:03 +01:00
MessageBox . Show ( text , MessageBoxType . Error ) ;
2017-05-19 01:13:53 +01:00
} ) ;
}
2017-12-30 00:32:21 +00:00
void VirusTotalFinished ( DbFile file )
2017-05-19 01:13:53 +01:00
{
Application . Instance . Invoke ( delegate
{
2017-12-30 00:32:21 +00:00
treeFiles . Enabled = true ;
btnToggleCrack . Enabled = true ;
btnScanWithClamd . Enabled = true ;
btnCheckInVirusTotal . Enabled = true ;
Workers . Failed - = VirusTotalFailed ;
Workers . ScanFinished - = VirusTotalFinished ;
Workers . UpdateProgress - = UpdateVirusProgress ;
lblProgressFiles1 . Text = "" ;
prgProgressFiles1 . Visible = false ;
if ( thdScanFile ! = null ) thdScanFile = null ;
if ( ( ! outIter . HasVirus . HasValue | | outIter . HasVirus . HasValue & & ! outIter . HasVirus . Value ) & &
file . HasVirus . HasValue & & file . HasVirus . Value ) infectedFiles + + ;
2017-05-19 18:04:21 +01:00
2017-05-19 01:13:53 +01:00
lstFiles . Remove ( outIter ) ;
AddFile ( file ) ;
2017-05-19 18:04:21 +01:00
2017-12-30 00:32:21 +00:00
lblFileStatus . Text = $"{lstFiles.Count} files ({infectedFiles} infected)" ;
2017-05-19 01:13:53 +01:00
} ) ;
}
2017-12-30 00:32:21 +00:00
void UpdateVirusProgress ( string text , string inner , long current , long maximum )
2017-05-18 16:33:32 +01:00
{
2017-12-30 00:32:21 +00:00
Application . Instance . Invoke ( delegate { lblProgressFiles1 . Text = text ; } ) ;
2017-05-19 01:13:53 +01:00
}
2017-05-18 16:33:32 +01:00
2017-05-19 01:13:53 +01:00
protected void OnBtnPopulateFilesClicked ( object sender , EventArgs e )
{
2017-05-19 13:56:32 +01:00
lstFiles . Clear ( ) ;
2017-12-30 00:32:21 +00:00
tabOSes . Enabled = false ;
btnStopFiles . Visible = true ;
2017-05-18 16:33:32 +01:00
btnPopulateFiles . Visible = false ;
2017-12-30 00:32:21 +00:00
lblProgressFiles1 . Text = "Loading files from database" ;
lblProgressFiles1 . Visible = true ;
lblProgressFiles2 . Visible = true ;
prgProgressFiles1 . Visible = true ;
prgProgressFiles2 . Visible = true ;
prgProgressFiles1 . Indeterminate = true ;
Workers . Failed + = LoadFilesFailed ;
Workers . Finished + = LoadFilesFinished ;
Workers . UpdateProgress + = UpdateFileProgress2 ;
populatingFiles = true ;
infectedFiles = 0 ;
thdPopulateFiles = new Thread ( Workers . GetFilesFromDb ) ;
2017-05-18 16:33:32 +01:00
thdPopulateFiles . Start ( ) ;
}
2017-12-30 00:32:21 +00:00
void UpdateFileProgress ( string text , string inner , long current , long maximum )
2017-05-19 13:56:32 +01:00
{
Application . Instance . Invoke ( delegate
{
if ( ! string . IsNullOrWhiteSpace ( text ) & & ! string . IsNullOrWhiteSpace ( inner ) )
2017-12-30 00:32:21 +00:00
lblProgressFiles1 . Text = $"{text}: {inner}" ;
2017-05-19 13:56:32 +01:00
else if ( ! string . IsNullOrWhiteSpace ( inner ) )
lblProgressFiles1 . Text = inner ;
else
lblProgressFiles1 . Text = text ;
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-19 13:56:32 +01:00
prgProgressFiles1 . Indeterminate = false ;
2017-12-30 00:32:21 +00:00
prgProgressFiles1 . MinValue = 0 ;
prgProgressFiles1 . MaxValue = ( int ) maximum ;
prgProgressFiles1 . Value = ( int ) current ;
2017-05-19 13:56:32 +01:00
}
2017-12-30 00:32:21 +00:00
else prgProgressFiles1 . Indeterminate = true ;
2017-05-19 13:56:32 +01:00
} ) ;
}
2017-12-30 00:32:21 +00:00
void UpdateFileProgress2 ( string text , string inner , long current , long maximum )
2017-05-18 16:33:32 +01:00
{
Application . Instance . Invoke ( delegate
{
if ( ! string . IsNullOrWhiteSpace ( text ) & & ! string . IsNullOrWhiteSpace ( inner ) )
2017-12-30 00:32:21 +00:00
lblProgressFiles2 . Text = $"{text}: {inner}" ;
2017-05-18 16:33:32 +01:00
else if ( ! string . IsNullOrWhiteSpace ( inner ) )
lblProgressFiles2 . Text = inner ;
else
lblProgressFiles2 . Text = text ;
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-18 16:33:32 +01:00
prgProgressFiles2 . Indeterminate = false ;
2017-12-30 00:32:21 +00:00
prgProgressFiles2 . MinValue = 0 ;
prgProgressFiles2 . MaxValue = ( int ) maximum ;
prgProgressFiles2 . Value = ( int ) current ;
2017-05-18 16:33:32 +01:00
}
2017-12-30 00:32:21 +00:00
else prgProgressFiles2 . Indeterminate = true ;
2017-05-18 16:33:32 +01:00
} ) ;
}
2017-12-30 00:32:21 +00:00
void AddFile ( DbFile file )
2017-05-18 16:33:32 +01:00
{
Application . Instance . Invoke ( delegate
{
2017-12-30 00:32:21 +00:00
if ( file . HasVirus . HasValue & & file . HasVirus . Value ) infectedFiles + + ;
2017-05-19 18:04:21 +01:00
2017-05-18 16:33:32 +01:00
lstFiles . Add ( file ) ;
} ) ;
}
2017-12-30 00:32:21 +00:00
void AddFiles ( List < DbFile > files )
2017-05-18 16:33:32 +01:00
{
Application . Instance . Invoke ( delegate
{
2017-12-30 00:32:21 +00:00
List < DbFile > foo = new List < DbFile > ( ) ;
2017-05-18 16:33:32 +01:00
foo . AddRange ( lstFiles ) ;
foo . AddRange ( files ) ;
2017-12-30 00:32:21 +00:00
lstFiles = new ObservableCollection < DbFile > ( foo ) ;
2017-05-19 18:04:21 +01:00
2017-12-30 00:32:21 +00:00
foreach ( DbFile file in files )
2017-05-19 18:04:21 +01:00
if ( file . HasVirus . HasValue & & file . HasVirus . Value )
infectedFiles + + ;
2017-05-18 16:33:32 +01:00
} ) ;
}
void LoadFilesFailed ( string text )
{
Application . Instance . Invoke ( delegate
{
2017-12-30 00:32:21 +00:00
MessageBox . Show ( $"Error {text} when populating files, exiting..." , MessageBoxType . Error ) ;
Workers . Failed - = LoadFilesFailed ;
Workers . Finished - = LoadFilesFinished ;
2017-05-19 13:56:32 +01:00
Workers . UpdateProgress - = UpdateFileProgress2 ;
2017-05-18 16:33:32 +01:00
if ( thdPopulateFiles ! = null )
{
thdPopulateFiles . Abort ( ) ;
thdPopulateFiles = null ;
}
2017-12-30 00:32:21 +00:00
2017-05-18 16:33:32 +01:00
tabOSes . Enabled = true ;
lstFiles . Clear ( ) ;
2017-12-30 00:32:21 +00:00
btnStopFiles . Visible = false ;
2017-05-18 16:33:32 +01:00
btnPopulateFiles . Visible = true ;
2017-12-30 00:32:21 +00:00
populatingFiles = false ;
2017-05-18 16:33:32 +01:00
} ) ;
}
void LoadFilesFinished ( )
{
Application . Instance . Invoke ( delegate
{
2017-12-30 00:32:21 +00:00
Workers . Failed - = LoadFilesFailed ;
Workers . Finished - = LoadFilesFinished ;
2017-05-19 13:56:32 +01:00
Workers . UpdateProgress - = UpdateFileProgress2 ;
2017-05-18 16:33:32 +01:00
if ( thdPopulateFiles ! = null )
{
thdPopulateFiles . Abort ( ) ;
thdPopulateFiles = null ;
}
2017-12-30 00:32:21 +00:00
treeFiles . DataStore = lstFiles ;
lblProgressFiles1 . Visible = false ;
lblProgressFiles2 . Visible = false ;
prgProgressFiles1 . Visible = false ;
prgProgressFiles2 . Visible = false ;
btnToggleCrack . Visible = true ;
btnScanWithClamd . Visible = true ;
2017-05-18 16:33:32 +01:00
btnCheckInVirusTotal . Visible = true ;
2017-12-30 00:32:21 +00:00
btnStopFiles . Visible = false ;
btnPopulateFiles . Visible = false ;
populatingFiles = false ;
treeFiles . Enabled = true ;
tabOSes . Enabled = true ;
btnScanAllPending . Visible = true ;
btnCleanFiles . Visible = true ;
lblFileStatus . Visible = true ;
lblFileStatus . Text = $"{lstFiles.Count} files ({infectedFiles} infected)" ;
2017-05-18 16:33:32 +01:00
} ) ;
}
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 ;
2017-05-19 13:56:32 +01:00
2017-12-30 00:32:21 +00:00
btnToggleCrack . Text = ( ( DbFile ) treeFiles . SelectedItem ) . Crack ? "Mark as not crack" : "Mark as crack" ;
}
2017-05-19 13:56:32 +01:00
protected void OnBtnScanAllPendingClicked ( object sender , EventArgs e )
{
2017-12-30 00:32:21 +00:00
treeFiles . Enabled = false ;
btnToggleCrack . Enabled = false ;
btnScanWithClamd . Enabled = false ;
btnCheckInVirusTotal . Enabled = false ;
lblProgressFiles1 . Visible = true ;
lblProgressFiles2 . Visible = true ;
prgProgressFiles1 . Visible = true ;
prgProgressFiles2 . Visible = true ;
btnScanAllPending . Enabled = false ;
Workers . Finished + = AllClamdFinished ;
Workers . UpdateProgress + = UpdateVirusProgress2 ;
Workers . UpdateProgress2 + = UpdateFileProgress ;
btnStopFiles . Visible = true ;
scanningFiles = true ;
lblProgressFiles2 . Text = "Scanning file with clamd." ;
2017-05-19 13:56:32 +01:00
prgProgressFiles2 . Indeterminate = true ;
thdScanFile = new Thread ( Workers . ClamScanAllFiles ) ;
thdScanFile . Start ( ) ;
}
void AllClamdFinished ( )
{
Application . Instance . Invoke ( delegate
{
2017-12-30 00:32:21 +00:00
treeFiles . Enabled = true ;
btnToggleCrack . Enabled = true ;
btnScanWithClamd . Enabled = true ;
btnCheckInVirusTotal . Enabled = true ;
btnScanAllPending . Enabled = true ;
Workers . Finished - = AllClamdFinished ;
Workers . UpdateProgress - = UpdateVirusProgress2 ;
Workers . UpdateProgress2 - = UpdateFileProgress ;
lblProgressFiles1 . Text = "" ;
prgProgressFiles1 . Visible = false ;
lblProgressFiles2 . Text = "" ;
prgProgressFiles2 . Visible = false ;
btnStopFiles . Visible = false ;
scanningFiles = false ;
if ( thdScanFile ! = null ) thdScanFile = null ;
2017-05-19 13:56:32 +01:00
2017-05-19 15:07:39 +01:00
OnBtnPopulateFilesClicked ( null , new EventArgs ( ) ) ;
2017-05-19 13:56:32 +01:00
} ) ;
}
2017-12-30 00:32:21 +00:00
void UpdateVirusProgress2 ( string text , string inner , long current , long maximum )
2017-05-19 13:56:32 +01:00
{
2017-12-30 00:32:21 +00:00
Application . Instance . Invoke ( delegate { lblProgressFiles2 . Text = text ; } ) ;
2017-05-19 13:56:32 +01:00
}
2017-05-19 16:57:28 +01:00
protected void OnBtnCleanFilesClicked ( object sender , EventArgs e )
{
2017-12-30 00:32:21 +00:00
DialogResult result =
MessageBox . Show ( "This option will search the database for any known file that doesn't\n" + "belong to any OS and remove it from the database.\n\n" + "It will then search the repository for any file not on the database and remove it.\n\n" + "THIS OPERATION MAY VERY LONG, CANNOT BE CANCELED AND REMOVES DATA ON DISK.\n\n" + "Are you sure to continue?" ,
MessageBoxButtons . YesNo , MessageBoxType . Question ) ;
if ( result ! = DialogResult . Yes ) return ;
btnCleanFiles . Visible = false ;
btnToggleCrack . Visible = false ;
btnScanWithClamd . Visible = false ;
btnScanAllPending . Visible = false ;
btnCheckInVirusTotal . Visible = false ;
tabOSes . Enabled = false ;
treeFiles . Enabled = false ;
lblProgressFiles1 . Visible = true ;
lblProgressFiles2 . Visible = true ;
Workers . Finished + = CleanFilesFinished ;
Workers . UpdateProgress + = UpdateFileProgress ;
Workers . UpdateProgress2 + = UpdateFileProgress2 ;
lblProgressFiles1 . Text = "" ;
prgProgressFiles1 . Visible = true ;
lblProgressFiles2 . Text = "" ;
prgProgressFiles2 . Visible = true ;
btnStopFiles . Visible = false ;
prgProgress2 . Indeterminate = true ;
btnSettings . Enabled = false ;
btnHelp . Enabled = false ;
mnuCompress . Enabled = false ;
btnQuit . Enabled = false ;
mnuFile . Enabled = false ;
thdCleanFiles = new Thread ( Workers . CleanFiles ) ;
thdCleanFiles . Start ( ) ;
2017-05-19 16:57:28 +01:00
}
void CleanFilesFinished ( )
{
Application . Instance . Invoke ( delegate
{
2017-12-30 00:32:21 +00:00
btnCleanFiles . Visible = true ;
btnToggleCrack . Visible = true ;
btnScanWithClamd . Visible = true ;
btnScanAllPending . Visible = true ;
btnCheckInVirusTotal . Visible = true ;
tabOSes . Enabled = true ;
treeFiles . Enabled = true ;
Workers . Finished - = CleanFilesFinished ;
Workers . UpdateProgress - = UpdateFileProgress ;
Workers . UpdateProgress2 - = UpdateFileProgress2 ;
lblProgressFiles1 . Text = "" ;
prgProgressFiles1 . Visible = false ;
lblProgressFiles2 . Text = "" ;
prgProgressFiles2 . Visible = false ;
btnSettings . Enabled = true ;
btnHelp . Enabled = true ;
mnuCompress . Enabled = true ;
btnQuit . Enabled = true ;
mnuFile . Enabled = true ;
if ( thdCleanFiles ! = null ) thdCleanFiles = null ;
2017-05-19 16:57:28 +01:00
OnBtnPopulateFilesClicked ( null , new EventArgs ( ) ) ;
} ) ;
}
2017-12-30 00:32:21 +00:00
#region XAML UI elements
#pragma warning disable 0649
GridView treeOSes ;
Label lblProgress ;
ProgressBar prgProgress ;
Label lblProgress2 ;
ProgressBar prgProgress2 ;
Button btnAdd ;
Button btnRemove ;
Button btnCompress ;
Button btnSave ;
Button btnStop ;
ButtonMenuItem btnSettings ;
ButtonMenuItem btnHelp ;
ButtonMenuItem mnuCompress ;
GridView treeFiles ;
Label lblProgressFiles1 ;
ProgressBar prgProgressFiles1 ;
Label lblProgressFiles2 ;
ProgressBar prgProgressFiles2 ;
Button btnStopFiles ;
Button btnToggleCrack ;
Button btnScanWithClamd ;
Button btnCheckInVirusTotal ;
Button btnPopulateFiles ;
TabPage tabOSes ;
Button btnScanAllPending ;
Button btnCleanFiles ;
ButtonMenuItem btnQuit ;
ButtonMenuItem mnuFile ;
Label lblOSStatus ;
Label lblFileStatus ;
#pragma warning restore 0649
#endregion XAML UI elements
2017-05-15 07:30:27 +01:00
}
2017-12-30 00:32:21 +00:00
}