Repository navigation
Expand file tree
/
Copy pathfrmCreateSysImage.cs
More file actions
149 lines (131 loc) · 4.84 KB
/
Copy pathfrmCreateSysImage.cs
File metadata and controls
149 lines (131 loc) · 4.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
using System;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using FileSystemImage.FileSystem;
using GeneralToolkitLib.Converters;
using FileSystemImage.DataModels;
using Serilog;
namespace FileSystemImage
{
public partial class FrmCreateSysImage : Form
{
private readonly object _fileSystemDriveLock = new object();
private FileSystemDrive _currentFileSystemDrive;
private FrmMain _mainWindow;
public FrmCreateSysImage()
{
InitializeComponent();
}
public void SetMainWindow(FrmMain frm)
{
_mainWindow = frm;
}
protected void frmCreateSysImage_Load(object sender, EventArgs e)
{
DriveInfo[] driveInfoArr = null;
try
{
driveInfoArr = DriveInfo.GetDrives();
}
catch(Exception ex)
{
Log.Error(ex,"Error in frmCreateSysImage.frmCreateSysImage_Load() @ DriveInfo.GetDrives(): ");
return;
}
foreach (DriveInfo di in driveInfoArr.Where(d => d.IsReady))
{
try
{
drpDrive.Items.Add(new ListItem(GetDriveInfoListItemText(di), di.Name));
}
catch(IOException ioException)
{
Log.Error(ioException, "Error in frmCreateSysImage.frmCreateSysImage_Load(): {Message}", ioException.Message);
}
}
if(drpDrive.Items.Count > 0)
drpDrive.SelectedIndex = 0;
}
private string GetDriveInfoListItemText(DriveInfo driveInfo)
{
string driveInfoText = driveInfo.VolumeLabel ?? "";
if(!string.IsNullOrEmpty(driveInfo.Name))
driveInfoText += $" ({driveInfo.Name.Replace("\\", "")}) ";
else
driveInfoText += " [" + driveInfo.VolumeLabel + "]";
driveInfoText +=
$"{GeneralConverters.FormatFileSizeToString(driveInfo.TotalFreeSpace)} free of {GeneralConverters.FormatFileSizeToString(driveInfo.TotalSize)} [{driveInfo.DriveType}, {driveInfo.DriveFormat}]";
return driveInfoText;
}
private void btnStart_Click(object sender, EventArgs e)
{
if(drpDrive.SelectedIndex >= 0)
{
FileUtils.CreateFileSystemDriveData(((ListItem)drpDrive.Items[drpDrive.SelectedIndex]).Value, ProgressUpdate, SetFileSystemDrive);
btnStart.Enabled = false;
btnCancel.Enabled = true;
btnLoadFileSys.Enabled = false;
}
}
private void btnCancel_Click(object sender, EventArgs e)
{
FileUtils.CancelCreateFileSystemDriveData();
btnStart.Enabled = true;
btnCancel.Enabled = false;
}
//Foreign thread
public void ProgressUpdate(double percentComplete)
{
Invoke(new ProgressCallback(ProgressUpdateNativeThead), percentComplete);
}
//NativeThead
protected void ProgressUpdateNativeThead(double percentComplete)
{
int pbarUpdateValue = Convert.ToInt32(Math.Round(progressBar1.Maximum*percentComplete, 0));
if(pbarUpdateValue >= 0 && pbarUpdateValue < progressBar1.Maximum)
progressBar1.Value = pbarUpdateValue;
else
progressBar1.Value = progressBar1.Maximum;
}
//Foreign thread
public void SetFileSystemDrive(FileSystemDrive fileSystemDrive)
{
lock (_fileSystemDriveLock)
{
_currentFileSystemDrive = fileSystemDrive;
}
if(Visible)
Invoke(new CreateFileSystemImageComplete(SetFileSystemDriveComplete));
FileUtils.DeAllocateWorkerThread();
}
//NativeThead
protected void SetFileSystemDriveComplete()
{
if(_currentFileSystemDrive != null)
{
btnLoadFileSys.Enabled = true;
btnCancel.Enabled = false;
btnStart.Enabled = true;
}
}
private void frmCreateSysImage_FormClosing(object sender, FormClosingEventArgs e)
{
if(FileUtils.IsRunning)
{
e.Cancel = true;
MessageBox.Show("Please cancel the drive scan operation before closing this window");
}
}
private delegate void CreateFileSystemImageComplete();
private void btnLoadFileSys_Click(object sender, EventArgs e)
{
if (_mainWindow != null)
{
_mainWindow.LoadFileSystemDrive(_currentFileSystemDrive);
this.DialogResult = DialogResult.OK;
Close();
}
}
}
}