📄 formwriteimagedisk.cs
字号:
void p_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
//MessageBox.Show("out "+e.Data);
}
void worker_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
label4.Text = e.UserState.ToString () + e.ProgressPercentage.ToString();
}
void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
//worker.IsBusy
if (e.Error != null) {
MessageBox.Show(e.Error.Message);
}
//else
//{
// MessageBox.Show("Done!");
//}
//buttonMake.Enabled = true;
}
private void button1_Click(object sender, EventArgs e)
{
// string sdf = "Disk /dev/sdc: 2003 MB, 2003795968 bytes";
//string[] sdfsg= sdf.Replace(" ", "_").Split('_');
//foreach (string id in sdfsg) {
// MessageBox.Show(id);
//}
}
void FindUSBDisk(object o) {
Thread st = (Thread)o;
//if (!File.Exists("busybox.exe")) { MessageBox.Show("[busybox.exe] File isn't exists"); return; }
//if (!File.Exists("cygcrypt-0.dll")) { MessageBox.Show("[cygcrypt-0.dll] File isn't exists"); return; }
//if (!File.Exists("cygwin1.dll")) { MessageBox.Show("[cygwin1.dll] File isn't exists"); return; }
Dictionary<string, DeviceInfo> sdfs = new Dictionary<string, DeviceInfo>();
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
p.Start();
string strOutput = string.Empty;
p.StandardInput.WriteLine("busybox.exe fdisk -l");
p.StandardInput.Write(p.StandardInput.NewLine);
p.StandardInput.WriteLine("exit");
//strOutput = p.StandardOutput.ReadToEnd();
//MessageBox.Show(strOutput);
if (!p.HasExited)
{
strOutput = p.StandardOutput.ReadToEnd();
//MessageBox.Show(strOutput);
//p.Close();
string[] sddddddd = strOutput.Split(new string[] { "\n" }, StringSplitOptions.None);
foreach (string s in sddddddd)
{
if (!string.IsNullOrEmpty(s))
{
if (s.Contains("Disk /dev/sd"))
{
if (s.Split(':').Length == 2)
{
//MessageBox.Show(s);
//comboBoxSelectDrive.Invoke(new comboboxAddHandler(AddDriveItem), new object[] { s });
DeviceInfo di = new DeviceInfo();
di.DeviceName = s.Split(':')[0].ToLower().Replace("disk", " ").Trim();
string shortsize = s.Split(':')[1];
if (shortsize.Split(',').Length == 2)
{
di.DeviceSize = shortsize.Split(',')[0];
string longsize = shortsize.Split(',')[1].ToLower().Replace("bytes", " ").Trim();
di.DeviceLength = Convert.ToInt64(longsize);
if (di.DeviceLength <= 16041885696)
{
if (!sdfs.ContainsKey(di.DeviceName)) {
try
{
sdfs.Add(di.DeviceName, di);
}
catch
{
MessageBox.Show("Read USB disk infomation error ,Remove them add refresh again.", "Error");
}
}
}
}
}
}
}
}
//while ((strOutput = p.StandardOutput.ReadLine()) != null)
//{
// if (strOutput.Contains("Disk /dev/sd"))
// {
// //MessageBox.Show(strOutput);
// if (strOutput.Split(':').Length == 2)
// {
// //sdfs.Add(strOutput.Split(':')[0], strOutput.Split(':')[1]);
// DeviceInfo di = new DeviceInfo();
// di.DeviceName = strOutput.Split(':')[0].ToLower().Replace("disk", " ").Trim();
// string shortsize = strOutput.Split(':')[1];
// if (shortsize.Split(',').Length == 2)
// {
// di.DeviceSize = shortsize.Split(',')[0];
// string longsize = shortsize.Split(',')[1].ToLower().Replace("bytes", " ").Trim();
// di.DeviceLength = Convert.ToInt64(longsize);
// if (di.DeviceLength <= 16041885696) {
// sdfs.Add(di.DeviceName, di);
// comboBoxSelectDrive.Invoke(new comboboxAddHandler(AddDriveItem), new object[] { strOutput });
// }
// }
// //MessageBox.Show(di.DeviceName + @"|" + di.DeviceLength);
// }
// }
//}
olvDevices.SetObjects(sdfs.Values);
}
//p.WaitForExit();
////
p.Close();
//return sdfs;
st.Abort();
st = null;
}
private void buttonRefresh_Click(object sender, EventArgs e)
{
Thread ss = new Thread(new ParameterizedThreadStart(FindUSBDisk));
ss.IsBackground = true;
ss.Start(ss);
}
private void FormWriteImageDisk_FormClosed(object sender, FormClosedEventArgs e)
{
}
private void FormWriteImageDisk_FormClosing(object sender, FormClosingEventArgs e)
{
e.Cancel = closeform;
Process[] mProcess = Process.GetProcesses();
foreach (Process p in mProcess)
{
if (p.Id == busyboxProcessID)
{
//MessageBox.Show(p.ProcessName);
if (MessageBox.Show("It is working for creating recovery disk.Are you sure to quit?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
p.Kill();
e.Cancel = false;
}
else
{
e.Cancel = true;
}
break;
}
else {
e.Cancel = false;
}
}
}
}
public class DeviceInfo
{
public DeviceInfo() { }
long length;
string name, size;
public string DeviceName { get { return name; } set { name = value; } }
public string DeviceSize { get { return size; } set { size = value; } }
public long DeviceLength { get { return length; } set { length = value; } }
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -