Search for hard drive

xiaoxiao2021-03-06  39

using System; using System.IO; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.Management; using System.Threading;

Summary description of Namespace Search {///

/// Form1. /// public class Form1: System.Windows.Forms.Form {private System.Windows.Forms.Label label1; private System.Windows.Forms.Button btnSearch; private System.Windows.Forms.TextBox tbInfo; private System.Windows.Forms.StatusBar sbStatus; private System.Windows.Forms.Label label2; private System.Windows.Forms.TextBox tbFilePath; private System.Windows.Forms.Button btnSelect; private System.Windows.Forms.NotifyIcon niIcon; private System.Windows.Forms.openfileDialog OFDFILE; Private System.comPonentmodel.icontainer Components;

Private system.windows.forms.checkedlistbox clbdisk; private system.windows.forms.label label3;

Private const Int Removable = 2; private const INT localdisk = 3; private const Int network = 4; private const INT CD = 5; private system.windows.Forms.TextBox TBFilter;

Private string [] filterlist; private system.windows.forms.button btnstop; private thread th; private int j = 0;

Public Form1 () {// // Windows Form Designer Support for // InitializeComponent ();

// // Todo: Add any constructor code after INITIALIZEComponent call //}

///

/// Clean all the resources being used. /// Protected Override Void Dispose (Bool Disposing) {if (disponents! = Null) {components.dispose ();}} Base.Dispose (4);

#REGION Windows Form Designer The code ///

/// designer supports the required method - do not use the code editor to modify the // / this method.

/// private void InitializeComponent () {this.components = new System.ComponentModel.Container (); System.Resources.ResourceManager resources = new System.Resources.ResourceManager (typeof (Form1)); this.label1 = New system.windows.forms.label (); this.btnsEarch = new system.windows.Forms.Button (); this.tbinfo = new system.windows.forms.textbox (); this.sbstatus = new System.Windows. Forms.statusbar (); this.tbfilter = new system.windows.forms.textbox (); this.label2 = new system.windows.forms.label (); this.tbfilepath = new system.windows.forms.textbox () This.btnselect = new system.windows.Forms.Button (); this.niicon = new system.windows.forms.notifyicon (this.Components); this.ofdfile = new system.windows.forms.openfileDialog (); this . clbdisk = new system.windows.forms.checkedlistbox (); this.label3 = new system.windows.forms.Label (); this.btnstop = new system.windows.form = new system.windows.Forms.Button (); this.suspendlayout () ;... /// Label1 // this.label1.locatio n = new system.drawing.point (184, 87); this.label1.name = "label1"; this.label1.size = new system.drawing.size (72, 23); this.label1.tabindex = 0; THIS.Label1.Text = "Conditions:"; // // btnsearch // this.btnsearch.location = new system.drawing.point (520, 87); this.btnsearch.name = "btnsearch"; this.btnsearch .Tabindex = 1; this.btnsearch.text = "archive"; this.btnsearch.click = new system.eventhandler (this.btnsearch_click; // // Tbinfo // this.tbinfo.location = new system.drawing. Point (8, 192); this.tbinfo.multiline = true; this.tbinfo.name = "

tbInfo "; this.tbInfo.ReadOnly = true; this.tbInfo.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; this.tbInfo.Size = new System.Drawing.Size (608, 96); this.tbInfo.TabIndex = 2; this.tbinfo.text = ""; /// sbstatus // this.sbstatus.location = new system.drawing.point (0, 312); this.sbstatus.name = "sbstatus"; this.sbstatus .Size = new system.drawing.size (624, 22); this.sbstatus.tabindex = 3; /// TBFILTER // this.tbfilter.location = new system.drawing.point (248, 88); this. TBFilter.name = "tbfilter"; this.tbfilter.size = new system.drawing.size (248, 21); this.tbfilter.tabindex = 4; this.tbfilter.text = ""; // // Label2 // THISLABEL2.LOCATION = New System.drawing.Point (192, 32); this.label2.name = "label2"; this.label2.size = new system.drawing.size (56, 23); this.label2. TabINDEX = 5; this.Label2.text = "Archive to:"; /// TbFilePath // this.tbfilepath.location = new system.drawing.point (248, 32); this.tbfilepath.n AME = "tbfilepath"; this.tbfilepath.size = new system.drawing.size (248, 21); this.tbfilepath.tabindex = 6; this.tbfilepath.text = ""; /// btnselect // this. BtNselect.location = new system.drawing.point (520, 32); this.btnselect.name = "btnselect"; this.btnselect.tabindex = 7; this.btnselect.text = "Select ..."; this.btnselect .Click = new system.eventhandler (this.btnselect_click); /// niicon // this.niicon.icon = ((System.drawing.icon) ("Niicon.icon"));

THISNIICON.TEXT = ""; this.niicon.visible = true; this.niicon.doubleClick = new system.EventHandler (this.niicon_doubleclick); ///////////// this.ofdfile.filter = text file | * .txt | XML files | * .xml "; // // CLBDisk // this.clbdisk.checkonclick = true; this.clbdisk.location = new system.drawing.point (24, 56); this.clbdisk. Multicolumn = true; this.clbdisk.name = "clbdisk"; this.clbdisk.size = new system.drawing.size (120, 116); this.clbdisk.tabindex = 8; // // label3 // this.label3 .Location = new system.drawing.point (24, 32); this.label3.name = "label3"; this.label3.size = new system.drawing.size (128, 16); this.label3.tabindex = 9 "This.Label3.text =" Drive to be scan "; // // btnstop // this.btnstop.location = new system.drawing.point (520, 136); this.btnstop.name =" btnstop "; this.btnStop.TabINDEX = 10; this.btnStop.Text = "Stop"; this.btnStop.Click = new system.EventHandler (this.btnstop_click); // // Form1 // this.autoscaleb Asesize = new system.drawing.size (6, 14); this.clientsize = new system.drawing.size (624, 334); this.controls.add (this.btnstop); this.controls.add (this.label3 This.controls.add (this.clbdisk); this.Controls.add (this.btnselect); this.controls.add (this.tbfilepath); this.controls.add (this.label2); this.Controls. Add (THIS.TBFILTER); this.controls.add (this.sbstatus); this.controls.add (this.tbinfo); this.Controls.add (this.btnsearch); this.controls.add (this.label1) Id.maximizebox = false; this.name = "form1"; this.startPosition =

System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "archive hard file"; this.SizeChanged = new System.EventHandler (this.Form1_SizeChanged); this.Load = new System.EventHandler (this.Form1_Load); this.ResumeLayout (false);} #ENDREGION

///

/// The primary entry point of the application. /// [stathread] static void main () {Application.run (new form1 ());}

Private void form1_load (object sender, system.eventargs e) {niicon.visible = false; infoAdd ("Scan Information ..."); InfoAdd ("--------------- ------------- "); STATUADD (" Scan ... "); showDisk (); statuadd (" scanned "); infoadd (" -------- --------------------- ");} private void infoadd (string info) {tbinfo.text = info " / r / n ";} private void statuadd string statu) {sbStatus.Text = statu;} private void ShowDisk () {string str = string.Empty; ManagementObjectCollection queryCollection = GetDrives (); foreach (ManagementObject obj in queryCollection) {switch (int.Parse (obj [ "DriveType" ] .Tostring ())) {Case Removable: // Removable Drives Str = "Mobile Hard Disk"; Break; Case LocalDisk: // Local Drives Str = "Local Hard Drive"; Break; Case CD: // CD ROM Drives Str = "Light Drive; Break; Case Network: // network drives str = "network hard disk"; break; default: // defalut to folder str = "unknown drive"; Break;} clbdisk.Items.add (Obj ["name"] .Tostring ()); InfoAdd (Obj ["name"]. TOSTRING () "" STR);

}} Private ManagementObjectCollection GetDrives () {// get drive collection ManagementObjectSearcher query = new ManagementObjectSearcher ( "SELECT * From Win32_LogicalDisk"); ManagementObjectCollection queryCollection = query.Get (); // InfoAdd ( "Total" queryCollection.Count.ToString ( ) "logical drives"); return queryCollection;} private void btnSelect_Click (object sender, System.EventArgs e) {if (ofdFile.ShowDialog () == DialogResult.Cancel) return; tbFilePath.Text = ofdFile.FileName;}

Private void btnsearch_click (object sender, system.eventargs e) {// Bool ListItem = true, diskItem = true; if (tbfilter.Text.trim () == String.empty) {// ListItem = false; // IF ( Messagebox.show ("There is no settings, the program will extract all files! / R / n Continue?", "Tips", MessageBoxButtons.okCancel) == DialogResult.cancel) MessageBox.show ("Please set your condition! Such as /".txt ,.exe/ "", "Tips"); Return;} else {filterlist = tbfilter.text.split (',');} TH = New Threadstart (beginsearch); th. Start ();} private void based beginsearch () {infoAdd ("scan" clbdisk.checkedItems.count.toString () "drive ../r/N -------------- ------------------ "); for (int i = 0; i

InfoAdd (Info.FullName); J ;}}} Writer.flush (); Writer.close (); Foreach (DirectoryInfo Info in Dirs) {log (info.fullname);}} catch (exception ex) {infoAdd (" Scan exception: " ex.Message); // statuadd (" Scan is ended by exceptions ");}}}}}}} private void btnstop_click (object sender, system.eventargs e) {if (th.isalive) {th.abort ); InfoAdd ("Scan" J.Tostring () "File"); StatuAdd ("Stop Scan");

Private void Niicon_doubleClick (Object Sender, System.Eventargs E) {this.visible = true; this.windowstate = system.windows.forms.formwindowstate.Normal; this.niicon.visible = false;}

private void Form1_SizeChanged (object sender, System.EventArgs e) {if (this.WindowState == System.Windows.Forms.FormWindowState.Minimized) {this.Hide (); this.niIcon.Visible = true;}}}}

转载请注明原文地址:https://www.9cbs.com/read-78156.html

New Post(0)