2014-07-17 21:36:13 +01:00
using System ;
2014-07-21 12:42:06 +01:00
using System.Collections ;
2014-07-17 21:36:13 +01:00
using System.Data ;
using System.Drawing ;
using System.Linq ;
using System.Text ;
2014-07-30 22:30:23 +01:00
using System.Threading ;
2014-07-17 21:36:13 +01:00
using System.Windows.Forms ;
2014-07-21 12:42:06 +01:00
using System.IO ;
2014-07-17 21:36:13 +01:00
namespace Saviour_Backup_System
{
public partial class mainWindow : Form
{
2014-11-22 22:50:53 +00:00
public DriveInfo selectedDrive ;
2014-07-30 22:30:23 +01:00
2014-09-14 15:19:00 +01:00
public mainWindow ( ) {
2014-07-17 21:36:13 +01:00
InitializeComponent ( ) ;
2014-11-07 15:08:53 +00:00
try
{
if ( setup . runtimeArguements [ 0 ] = = "STARTUP" ) { this . removeDisplay ( ) ; }
else { this . showDisplay ( ) ; }
2014-12-03 12:18:56 +00:00
}
catch { this . showDisplay ( ) ; }
2014-11-04 17:25:54 +00:00
}
2014-09-14 15:19:00 +01:00
2014-11-11 22:55:14 +00:00
public void removeDisplay ( ) {
2014-11-04 17:25:54 +00:00
formatDriveCapacityTimer . Stop ( ) ;
driveRefreshTimer . Stop ( ) ;
2014-11-10 14:50:31 +00:00
connectedDrivesList . Update ( ) ;
2014-11-04 17:25:54 +00:00
clearDriveDetails ( ) ;
this . Hide ( ) ;
setup . icon . notifyIcon . Visible = true ;
}
2014-08-01 22:14:26 +01:00
2014-11-11 22:55:14 +00:00
public void showDisplay ( ) {
2014-11-04 17:25:54 +00:00
refreshDriveList ( ) ;
2014-11-10 14:50:31 +00:00
connectedDrivesList . Update ( ) ;
2014-11-04 17:25:54 +00:00
connectedDrivesList . Items [ 0 ] . Selected = true ;
2014-11-21 22:29:10 +00:00
displayDriveDetails ( USBTools . getDriveObject ( connectedDrivesList . SelectedItems [ 0 ] . Text . Substring ( 0 , 1 ) ) ) ;
2014-07-30 22:30:23 +01:00
formatDriveCapacityTimer . Start ( ) ;
driveRefreshTimer . Start ( ) ;
2014-11-04 17:25:54 +00:00
setup . icon . notifyIcon . Visible = false ;
2014-11-10 14:50:31 +00:00
this . Show ( ) ;
2014-07-18 13:36:31 +01:00
}
2014-07-30 22:30:23 +01:00
2014-11-11 22:55:14 +00:00
public void refreshDriveList ( ) {
2014-07-22 21:14:30 +01:00
DriveInfo [ ] drives = USBTools . getConnectedDrives ( ) ;
2014-11-10 14:50:31 +00:00
if ( connectedDrivesList . Items . Count = = USBTools . countDrives ( ) ) { return ; } //if there is no change in the numer
2014-07-22 21:14:30 +01:00
connectedDrivesList . Items . Clear ( ) ;
2014-07-30 22:30:23 +01:00
bool deviceStillConnected = false ;
2014-07-22 21:14:30 +01:00
foreach ( DriveInfo drive in drives ) {
2014-08-01 22:14:26 +01:00
try {
ListViewItem driveItem = new ListViewItem ( drive . Name + " " + tools . Trim ( drive . VolumeLabel , 24 ) ) ;
driveItem . SubItems . Add ( "X" ) ;
connectedDrivesList . Items . Add ( driveItem ) ;
if ( drive . VolumeLabel = = driveNameDisplay . Text )
{
deviceStillConnected = true ;
driveItem . Selected = true ;
}
2014-07-31 15:34:00 +01:00
}
2014-08-01 22:14:26 +01:00
catch { continue ; }
2014-07-22 21:14:30 +01:00
}
2014-07-30 22:30:23 +01:00
if ( ! deviceStillConnected ) { clearDriveDetails ( ) ; }
2014-07-22 21:14:30 +01:00
connectedDrivesList . Sort ( ) ;
}
2014-07-30 22:30:23 +01:00
2014-07-22 21:14:30 +01:00
private void connectedDrivesListRefresh_Click ( object sender , EventArgs e )
{
2014-07-27 21:03:06 +01:00
foreach ( ListViewItem i in connectedDrivesList . SelectedItems ) { i . Selected = false ; } //Deselected all elements in the list first
2014-08-01 22:14:26 +01:00
clearDriveDetails ( ) ;
2014-07-22 21:14:30 +01:00
refreshDriveList ( ) ;
}
2014-07-30 22:30:23 +01:00
private void connectedDrivesList_Selection ( object sender , ListViewItemSelectionChangedEventArgs e ) {
if ( ! e . IsSelected ) {
2014-08-01 22:14:26 +01:00
deviceTab . Visible = false ;
2014-07-30 22:30:23 +01:00
backupRestoreTab . Select ( ) ;
return ;
}
2014-11-10 14:50:31 +00:00
formatDriveCapacityTimer . Start ( ) ;
2014-07-30 22:30:23 +01:00
ribbonControl . RecalcLayout ( ) ;
2014-08-01 22:14:26 +01:00
populateDeviceTab ( ) ;
2014-07-30 22:30:23 +01:00
string selectedDevice = connectedDrivesList . SelectedItems [ 0 ] . Text ;
2014-11-21 22:29:10 +00:00
displayDriveDetails ( USBTools . getDriveObject ( selectedDevice . Substring ( 0 , 1 ) ) ) ;
2014-07-22 21:14:30 +01:00
}
2014-07-30 22:30:23 +01:00
2014-11-21 22:29:10 +00:00
private void displayDriveDetails ( DriveInfo drive ) {
selectedDrive = drive ;
2014-07-31 15:34:00 +01:00
driveNameDisplay . Text = tools . Trim ( selectedDrive . VolumeLabel , 16 ) ;
2014-07-30 22:30:23 +01:00
driveLetterDisplay . Text = selectedDrive . Name ;
driveSystemDisplay . Text = selectedDrive . DriveFormat ;
driveTypeDisplay . Text = USBTools . getDriveType ( selectedDrive ) ;
switch ( USBTools . getDriveType ( selectedDrive ) )
{
case "Optical Disk Drive" :
driveIconBox . Image = Properties . Resources . cdIcon ;
break ;
case "Removable Drive" :
driveIconBox . Image = Properties . Resources . usbIcon ;
break ;
case "Fixed Disk Drive" :
driveIconBox . Image = Properties . Resources . hddIcon ;
break ;
}
}
private void formatDriveCapacity ( )
{
DriveInfo drive = selectedDrive ;
int driveCapacityPerc = USBTools . spacePercentage ( drive ) ;
2014-08-01 22:14:26 +01:00
driveCapacityDisplay . Text = "Drive Capacity: " + ( driveCapacityDisplay . Value / 100 ) . ToString ( ) + "%" ;
2014-07-30 22:30:23 +01:00
while ( driveCapacityPerc ! = driveCapacityDisplay . Value ) {
if ( driveCapacityPerc < driveCapacityDisplay . Value ) { driveCapacityDisplay . Value - = 1 ; }
if ( driveCapacityPerc > driveCapacityDisplay . Value ) { driveCapacityDisplay . Value + = 1 ; }
2014-07-31 15:34:00 +01:00
driveCapacityDisplay . Text = "Drive Capacity: " + ( driveCapacityDisplay . Value / 100 ) . ToString ( ) + "%" ;
2014-07-30 22:30:23 +01:00
//adjust the colour of the progressbar depending on capacity of the drive
if ( driveCapacityDisplay . Value < = 6800 ) { driveCapacityDisplay . ColorTable = DevComponents . DotNetBar . eProgressBarItemColor . Normal ; }
else if ( driveCapacityDisplay . Value > 6800 & & driveCapacityDisplay . Value < 9000 ) { driveCapacityDisplay . ColorTable = DevComponents . DotNetBar . eProgressBarItemColor . Paused ; }
else if ( driveCapacityDisplay . Value > = 9000 ) { driveCapacityDisplay . ColorTable = DevComponents . DotNetBar . eProgressBarItemColor . Error ; }
}
2014-11-10 14:50:31 +00:00
formatDriveCapacityTimer . Stop ( ) ;
2014-07-31 15:34:00 +01:00
2014-07-30 22:30:23 +01:00
}
private void clearDriveDetails ( ) {
string blankText = "" ;
2014-08-01 22:14:26 +01:00
selectedDrive = null ;
2014-07-30 22:30:23 +01:00
driveNameDisplay . Text = blankText ;
driveLetterDisplay . Text = blankText ;
driveSystemDisplay . Text = blankText ;
driveTypeDisplay . Text = blankText ;
driveCapacityDisplay . Value = 0 ;
2014-08-01 22:14:26 +01:00
driveCapacityDisplay . Text = blankText ;
2014-07-30 22:30:23 +01:00
}
private void driveRefreshTimer_Tick ( object sender , EventArgs e ) { refreshDriveList ( ) ; }
2014-09-14 15:19:00 +01:00
private void formatDriveCapacityTimer_Tick ( object sender , EventArgs e ) { try { formatDriveCapacity ( ) ; } catch { } } //Because background workers cant interact with the GUI (very quickly), so a timer has to
2014-07-30 22:30:23 +01:00
2014-08-01 22:14:26 +01:00
private void populateDeviceTab ( ) {
2014-11-21 22:29:10 +00:00
// put stuff in here for changing labels of buttons etc.
2014-08-01 22:14:26 +01:00
deviceTab . Visible = true ;
deviceTab . Select ( ) ;
}
2014-11-04 17:25:54 +00:00
private void mainWindow_FormClosing ( object sender , FormClosingEventArgs e ) {
2014-11-10 14:50:31 +00:00
e . Cancel = true ;
switch ( e . CloseReason ) {
2014-11-04 17:25:54 +00:00
case ( CloseReason . ApplicationExitCall ) :
2014-11-10 14:50:31 +00:00
case ( CloseReason . WindowsShutDown ) :
2014-11-06 10:20:59 +00:00
formatDriveCapacityTimer . Stop ( ) ;
driveRefreshTimer . Stop ( ) ;
2014-11-04 17:25:54 +00:00
this . Close ( ) ;
2014-11-16 17:15:53 +00:00
this . Dispose ( ) ;
2014-11-04 17:25:54 +00:00
break ;
case ( CloseReason . UserClosing ) :
this . removeDisplay ( ) ;
setup . icon . displayStillRunning ( ) ;
break ;
default :
this . Close ( ) ;
break ;
}
}
2014-11-15 13:45:18 +00:00
private void addBackupRuleButton_Click ( object sender , EventArgs e )
{
setup . ABW = new addBackupWizard ( ) ;
2014-11-17 16:12:21 +00:00
setup . ABW . ShowDialog ( ) ;
2014-11-15 13:45:18 +00:00
}
2014-11-21 22:29:10 +00:00
private void exitButton_Click ( object sender , EventArgs e ) { setup . closeProgram ( ) ; }
2014-11-20 14:32:50 +00:00
2014-11-21 22:29:10 +00:00
private void currentTransfersButton_Click ( object sender , EventArgs e )
2014-11-20 14:32:50 +00:00
{
2014-11-21 22:29:10 +00:00
setup . CT . ShowDialog ( ) ;
2014-11-20 14:32:50 +00:00
}
2014-11-21 22:29:10 +00:00
private void backupDetailsPanel_Click ( object sender , EventArgs e )
2014-11-20 14:32:50 +00:00
{
2014-11-21 22:29:10 +00:00
2014-11-20 14:32:50 +00:00
}
2014-12-08 15:20:07 +00:00
private void viewAllRulesButton_Click ( object sender , EventArgs e )
{
setup . BV = new backupViewer ( ) ;
setup . BV . Show ( ) ;
}
2014-07-17 21:36:13 +01:00
}
}