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-07-31 15:34:00 +01:00
private 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-09-14 15:19:00 +01:00
//populates the drive list
2014-08-01 22:14:26 +01:00
refreshDriveList ( ) ;
2014-09-14 15:19:00 +01:00
//selects the first item in the list of drives
connectedDrivesList . Items [ 0 ] . Selected = true ;
//Displays the details for the selected drive
displayDriveDetails ( connectedDrivesList . SelectedItems [ 0 ] . Text . Substring ( 0 , 3 ) ) ;
2014-08-01 22:14:26 +01:00
//Starts the thread for displaying the capacity of a drive
2014-07-30 22:30:23 +01:00
formatDriveCapacityTimer . Start ( ) ;
//Starts the timer for refreshing drive list
driveRefreshTimer . Start ( ) ;
2014-07-18 13:36:31 +01:00
}
2014-07-30 22:30:23 +01:00
2014-09-14 15:19:00 +01:00
internal void refreshDriveList ( ) {
2014-07-22 21:14:30 +01:00
DriveInfo [ ] drives = USBTools . getConnectedDrives ( ) ;
2014-09-14 15:19:00 +01:00
if ( connectedDrivesList . Items . Count = = USBTools . countDrives ( ) ) { return ; } //f 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 ;
}
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 ;
displayDriveDetails ( selectedDevice . Substring ( 0 , 3 ) ) ;
2014-07-22 21:14:30 +01:00
}
2014-07-30 22:30:23 +01:00
private void displayDriveDetails ( string driveName )
{
foreach ( DriveInfo drive in USBTools . getConnectedDrives ( ) ) {
if ( drive . Name = = driveName ) { selectedDrive = drive ; break ; }
}
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 ;
}
2014-08-01 22:14:26 +01:00
2014-07-30 22:30:23 +01:00
}
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-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-08-02 10:46:28 +01:00
// put stuff in here!!
2014-08-01 22:14:26 +01:00
deviceTab . Visible = true ;
deviceTab . Select ( ) ;
}
2014-10-07 17:06:39 +01:00
private void mainWindow_FormClosing ( object sender , FormClosingEventArgs e ) { /*setup.closeProgram(sender, e);*/ }
2014-07-17 21:36:13 +01:00
}
}