⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frmshare.cs

📁 一个p2p的c#版源码
💻 CS
📖 第 1 页 / 共 2 页
字号:
namespace Client				// Copyright 2001 Dreamtech Software India Inc.
{								// All rights reserved
    
	using System;				// Provides the basic functionality of .NET
	using System.Drawing;		// Provides the Drawing features, Used for cursors
    using System.Windows.Forms;	// Provides the darwing of buttons, listviews etc	
	using System.Net;			// Provides the net related functionality 
	using System.Net.Sockets;	// Provides the functionality of sockets
	using System.Text;			// Provides the text manipulation functions
	using System.IO;			// Provides I/O features
	using WorkingWithXML;		// Custom class 
	using System.Collections;	// Provides the different type of class collections
    using System.ComponentModel;// Provides the facility of using components

	/// <summary>
    ///    Summary description for frmShare.
    /// </summary>
    public class frmShare : System.Windows.Forms.Form
    {
		private System.ComponentModel.IContainer components;
		private	System.Windows.Forms.OpenFileDialog	FileOpenDialog;
		public	System.Windows.Forms.Button			btnClose;
		public	System.Windows.Forms.StatusBar		sBar;
		private System.Windows.Forms.SaveFileDialog	FileSaveDialog;
		private System.Windows.Forms.ToolTip		toolTipText;
		public	System.Windows.Forms.ListView		lvFiles;
		public	System.Windows.Forms.Button			btnSearch;
		public	System.Windows.Forms.Button			btnDownload;
		public	System.Windows.Forms.Button			btnUpload;
		private System.Windows.Forms.ColumnHeader	clhFilename;
		private System.Windows.Forms.ColumnHeader	clhFileSize;
		private System.Windows.Forms.ColumnHeader	clhType;

		/// <summary>
		/// User defined variables.
		/// </summary>
		
		/// <summary>
		/// stores the number of bytes written or read from any stream
		/// </summary>
		private int						iBytes;
		
		/// <summary>
		///	These variables are used to store the name of the computer
		///	to which you have connected and the parent folder name.
		///	Parent folder name is the name of the folder of the contents
		///	which you are viewing in the window
		/// </summary>
		private string					COMPUTERNAME,PARENTFOLDER;
		
		/// <summary>
		/// Stores a new created socket of type TCPClient(System defined class)
		/// used to communicate with the listener
		/// </summary>
		private TcpClient				ClientSocket;
		
		/// <summary>
		/// creates a variable for XMLCreater(User defined class) to 
		/// create XML requests for the listener
		/// </summary>
		private XMLCreater				xmlCreate;
		
		/// <summary>
		/// StreamTCP points to the NetworkStream(System defined class)
		/// which is used for transfer data over the Socket connection
		/// </summary>
		private NetworkStream			StreamTCP;
		
		/// <summary>
		/// fileStream is an object of type FileStream(System defined class)
		/// used to have I/O capabilities for files which are used
		/// in this program
		/// </summary>
		private FileStream				fileStream;
		
		/// <summary>
		/// ReadBuffer and WriteBuffer Byte arrays used for 
		/// Reading and Writing any file.
		/// </summary>
		private Byte[]					ReadBuffer,WriteBuffer;
		
		/// <summary>
		/// xmlParser is of type XMLParser(User defined class)
		/// It is used to have the access for Parsing the XML file
		/// This class is present in WorkingWithXML
		/// </summary>
		private	XMLParser				xmlParser;
		
		/// <summary>
		/// xmlStruct is of type XMLSTRUCT(User defined structure)
		/// It is used to store the different records obtained
		/// from parsing the XML. This structure is present in WorkingWithXML
		/// </summary>
		private	XMLSTRUCT				xmlStruct;
		
		/// <summary>
		/// strArray if of Type __SHOWFILES of XMLSTRUCT Structure and
		/// used to save the corresponding Files/Folder which are seen in the
		/// the List view at run time
		/// </summary>
		private XMLSTRUCT.__SHOWFILES[] strArray;

		
		/// <summary>
		/// The below variables are readonly variables that u cannot
		/// assign a new value to these variables again. They are
		/// constant type variables
		/// </summary>
		
		/// <summary>
		/// REQUESTFILE have the name of the file which have to be created
		/// for a particular request
		/// </summary>
		public readonly string REQUESTFILE = Application.StartupPath + "\\Request.xml";

		/// <summary>
		/// RESPONSEFILE have the name of the file which have to be created
		/// for a particular request
		/// </summary>
		public readonly string RESPONSEFILE = Application.StartupPath + "\\Response.xml";
		private System.Windows.Forms.Label lblCopyright;

		/// <summary>
		/// MAX_SIZE defines the maximum size of the read or write buffer
		/// which is used for reading or wrting a file
		/// </summary>
		public readonly int MAX_SIZE = 512;

		/// <summary>
		/// This is the default contructor of the this class
		/// This is called from the View files button
		/// </summary>
		public frmShare()
        {
            //
            // Required for Windows Form Designer support
            //
            // Auto generated code line by the IDE
			InitializeComponent();

			// Puts the Computer.ico as the form icon
			this.Icon = new System.Drawing.Icon(Application.StartupPath + "\\Computer.ico");

			// Changes the Caption of this dialog box
			this.Text = "Search Result";
			sBar.Text = "Root";
			COMPUTERNAME = null;
			PARENTFOLDER = null;
        }

		/// <summary>
		/// This is a user defined constructor called from the 
		/// Open button in the frmClient
		/// Computername is passed to this function, which you
		/// have selected from the Main window
		/// </summary>
		/// <param name="Computername"> </param>
		public frmShare(string Computername)
		{
            //
            // Required for Windows Form Designer support
			// This line is not auto generated, instead it has been copied from
			// default constructor
            InitializeComponent();
			
			// Puts the Computer.ico as the form icon
			this.Icon = new System.Drawing.Icon(Application.StartupPath + "\\Computer.ico");

			// COMPUTERNAME is a global variable used to store the name
			// and IP Address of the computer to which you are currently
			// connected
			COMPUTERNAME = Computername;
			
			// Open connection is a user defined function responsible for
			// opening a socket connection for listener. This function
			// returns a bool value
			if( OpenConnection(COMPUTERNAME) )
			{
				// This will creates a SHOWFILE request XML for seding it
				// to the listener
				CreateRequest("SHOWFILES","","");
				
				// This will actually sends the REQUESTFILE to the listener
				SendDataToListener(REQUESTFILE);
				
				// This will get the response of the above request from
				// listener and store that response in a RESPONSEFILE
				GetDataFromListener(RESPONSEFILE);
				
				// This will Parse that response XML File and results are
				// shown to the user
				Parsing(RESPONSEFILE);
				
				// Closes any Opened socket or stream connection
				CloseConnection();
				
				// Since this constructor is called at the root level
				// therefore no parent folder is associated with it
				PARENTFOLDER = null;
				
				// Changes the caption of this dialog box
				this.Text = "Shared contents on: " + Computername.ToUpper();
				
				// Sets the text for the Status bar
				sBar.Text = "Root";
			}
		}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -