📄 winsend.cs
字号:
/*
<Aicaca Community Messenger Client>
Copyright (c) Aicaca.com, All rights reserved.
Writer : Byung-ku, Cho (Aicaca)
E-mail : aicaca@hanmail.net
Personal Homepage URL : http://www.aicaca.com
Last Updated Date : Feb. 27th, 2002
Programming Language : C#
Editor & Compiler : VisualStudio.NET
*/
using System;
using System.IO;
using System.Threading;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
namespace TalkClient
{
public class WinSend : System.Windows.Forms.Form
{
private WinCom WC = new WinCom();
private WinClient xWinClient;
private WinStream xWinStream;
private Socket FileSocket = null;
private TextWriter SocketWriter = null;
private string localID;
private string clientID;
private string threadID;
private string remoteID;
private bool lockMode;
private bool directMode;
private System.ComponentModel.IContainer components;
private System.Windows.Forms.OpenFileDialog openDialog;
private System.Windows.Forms.TextBox idTextBox;
private System.Windows.Forms.TextBox pathTextBox;
private System.Windows.Forms.Label idLabel;
private System.Windows.Forms.GroupBox downGroupBox;
private System.Windows.Forms.Button selectButton;
private System.Windows.Forms.Button sendButton;
private System.Windows.Forms.Button closeButton;
private System.Windows.Forms.TextBox mainTextBox;
public WinSend(WinClient tWinClient, string tLocalID, string tClientID)
{
xWinClient = tWinClient;
localID = tLocalID;
clientID = tClientID;
}
public void WinThread_Connect()
{
this.InitializeAll();
this.ShowDialog();
}
#region Windows Form Designer generated code
private void InitializeComponent()
{
this.idLabel = new System.Windows.Forms.Label();
this.pathTextBox = new System.Windows.Forms.TextBox();
this.closeButton = new System.Windows.Forms.Button();
this.downGroupBox = new System.Windows.Forms.GroupBox();
this.mainTextBox = new System.Windows.Forms.TextBox();
this.selectButton = new System.Windows.Forms.Button();
this.sendButton = new System.Windows.Forms.Button();
this.idTextBox = new System.Windows.Forms.TextBox();
this.openDialog = new System.Windows.Forms.OpenFileDialog();
this.downGroupBox.SuspendLayout();
this.SuspendLayout();
//
// idLabel
//
this.idLabel.Location = new System.Drawing.Point(8, 24);
this.idLabel.Name = "idLabel";
this.idLabel.Size = new System.Drawing.Size(64, 16);
this.idLabel.TabIndex = 0;
this.idLabel.Text = "Client ID";
this.idLabel.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// pathTextBox
//
this.pathTextBox.Location = new System.Drawing.Point(80, 40);
this.pathTextBox.Name = "pathTextBox";
this.pathTextBox.Size = new System.Drawing.Size(168, 21);
this.pathTextBox.TabIndex = 2;
this.pathTextBox.Text = "";
//
// closeButton
//
this.closeButton.Location = new System.Drawing.Point(176, 128);
this.closeButton.Name = "closeButton";
this.closeButton.Size = new System.Drawing.Size(72, 24);
this.closeButton.TabIndex = 5;
this.closeButton.Text = "Close";
this.closeButton.Click += new System.EventHandler(this.closeButton_Click);
//
// downGroupBox
//
this.downGroupBox.Controls.AddRange(new System.Windows.Forms.Control[] {
this.mainTextBox,
this.selectButton,
this.sendButton,
this.closeButton,
this.pathTextBox,
this.idTextBox,
this.idLabel});
this.downGroupBox.Name = "downGroupBox";
this.downGroupBox.Size = new System.Drawing.Size(256, 160);
this.downGroupBox.TabIndex = 0;
this.downGroupBox.TabStop = false;
//
// mainTextBox
//
this.mainTextBox.Location = new System.Drawing.Point(8, 72);
this.mainTextBox.MaxLength = 1000;
this.mainTextBox.Multiline = true;
this.mainTextBox.Name = "mainTextBox";
this.mainTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.mainTextBox.Size = new System.Drawing.Size(240, 48);
this.mainTextBox.TabIndex = 3;
this.mainTextBox.Text = "";
//
// selectButton
//
this.selectButton.Location = new System.Drawing.Point(8, 40);
this.selectButton.Name = "selectButton";
this.selectButton.Size = new System.Drawing.Size(64, 24);
this.selectButton.TabIndex = 1;
this.selectButton.Text = "Select";
this.selectButton.Click += new System.EventHandler(this.selectButton_Click);
//
// sendButton
//
this.sendButton.Location = new System.Drawing.Point(8, 128);
this.sendButton.Name = "sendButton";
this.sendButton.Size = new System.Drawing.Size(160, 24);
this.sendButton.TabIndex = 4;
this.sendButton.Text = "Send";
this.sendButton.Click += new System.EventHandler(this.sendButton_Click);
//
// idTextBox
//
this.idTextBox.Location = new System.Drawing.Point(80, 16);
this.idTextBox.Name = "idTextBox";
this.idTextBox.ReadOnly = true;
this.idTextBox.Size = new System.Drawing.Size(168, 21);
this.idTextBox.TabIndex = 0;
this.idTextBox.Text = "";
//
// WinSend
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(256, 165);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.downGroupBox});
this.MaximizeBox = false;
this.Name = "WinSend";
this.Text = "Aicaca WinSend";
this.Closed += new System.EventHandler(this.OnClosed);
this.downGroupBox.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private void OnClosed(object sender, System.EventArgs e)
{
if (lockMode)
{
this.SendILOVEAICACAFCA();
}
xWinClient.RemoveThread(threadID);
if (xWinStream != null) xWinStream.CloseThis();
}
private void selectButton_Click (object sender, System.EventArgs e)
{
openDialog.Title = "Send File";
openDialog.InitialDirectory = "C:\\";
openDialog.ShowDialog();
pathTextBox.Text = openDialog.FileName;
}
private void sendButton_Click (object sender, System.EventArgs e)
{
string originFileName = pathTextBox.Text;
if (originFileName.Length > 5)
{
this.SendILOVEAICACAFNO(originFileName);
}
}
private void closeButton_Click (object sender, System.EventArgs e)
{
this.Close();
}
private void InitializeAll()
{
this.StartWinMode();
string threadSort = "WinSend";
string threadName = WC.GetXML(clientID, "cn");
string threadIP = WC.GetXML(clientID, "ci");
string threadPort = WC.GetXML(clientID, "cp");
threadID = WC.MakeThreadID(threadSort, threadName, threadIP, threadPort);
string remoteSort = "WinReceive";
string remoteName = WC.GetXML(localID, "ln");
string remoteIP = WC.GetXML(localID, "li");
string remotePort = WC.GetXML(localID, "lp");
remoteID = WC.MakeRemoteID(remoteSort, remoteName, remoteIP, remotePort);
xWinClient.AddThread(threadID, this);
InitializeComponent();
this.idTextBox.Text = WC.GetXML(clientID, "cn") + ":" + WC.GetXML(clientID, "ci") + ":" + WC.GetXML(clientID, "cp");
}
private void AddCommingText(string str)
{
str = WC.ReplaceStr(str, "&Line;", "\n");
this.mainTextBox.AppendText(str + "\r\n");
}
private void SendILOVEAICACAFNO(string originFileName)
{
int fileLen = 0;
try
{
FileStream fs = new FileStream(originFileName, FileMode.Open);
fileLen = Convert.ToInt32(fs.Length);
fs.Close();
}
catch (Exception e)
{
MessageBox.Show(this, WC.lineStr11);
return;
}
if (fileLen > 3000000)
{
MessageBox.Show(this, WC.lineStr15);
return;
}
string sendStr = WC.MakeXML("ms", "ILOVEAICACAFNO") + threadID + remoteID + WC.MakeXML("fo", originFileName) + WC.MakeXML("fl", fileLen.ToString()) + "<body>" + this.mainTextBox.Text;
if (directMode == true)
{
this.StartWinStream_Connect(sendStr, null);
}
else
{
xWinClient.SendRootMsg(sendStr);
}
pathTextBox.ReadOnly = true;
selectButton.Enabled = false;
sendButton.Enabled = false;
closeButton.Text = "Cancel";
lockMode = true;
}
private void SendILOVEAICACAFCA()
{
string sendStr = sendStr = WC.MakeXML("ms", "ILOVEAICACAFCA") + threadID + remoteID;
if (FileSocket != null && FileSocket.Connected)
{
this.SendMsg(sendStr);
}
else
{
xWinClient.SendRootMsg(sendStr);
}
}
private void SendILOVEAICACAFIL(string str)
{
string originFileName = this.pathTextBox.Text;
string changeFileName = WC.GetXML(str, "fc");
byte[] sendStream = null;
int fileLen = 0;
try
{
FileStream fs = new FileStream(originFileName, FileMode.Open);
fileLen = Convert.ToInt32(fs.Length);
sendStream = new byte[fileLen];
fs.Read(sendStream,0,fileLen);
fs.Close();
}
catch (Exception e)
{
this.SendILOVEAICACAFCA();
MessageBox.Show(this, WC.lineStr11);
return;
}
string sendStr = WC.MakeXML("ms", "ILOVEAICACAFIL") + threadID + remoteID + WC.MakeXML("fc", changeFileName) + WC.MakeXML("fl", fileLen.ToString());
if (FileSocket != null && FileSocket.Connected)
{
this.SendMsg(sendStr);
this.SendStream(sendStream);
}
else
{
xWinClient.SendRootMsg(sendStr);
xWinClient.SendRootStream(sendStream);
}
}
private void StartWinMode()
{
WinMode xWinMode = new WinMode(this, clientID);
Thread ModeThread = new Thread(new ThreadStart(xWinMode.WinThread_Send));
ModeThread.Start();
}
private void StartWinStream_Connect(string sendStr, byte[] sendStream)
{
xWinStream = new WinStream(xWinClient, this, localID, clientID, sendStr, sendStream);
Thread StreamThread = new Thread(new ThreadStart(xWinStream.ClientProc));
StreamThread.Start();
}
private void StartWinStream_Accept()
{
xWinStream = new WinStream(xWinClient, this, FileSocket);
Thread StreamThread = new Thread(new ThreadStart(xWinStream.ServerProc));
StreamThread.Start();
}
public void SetSocket(Socket sk, bool threadMode)
{
lock(this)
{
if (sk != null && sk.Connected)
{
FileSocket = sk;
NetworkStream stream = new NetworkStream(FileSocket);
SocketWriter = new StreamWriter(stream);
if (threadMode == true) this.StartWinStream_Accept();
}
}
}
public void SendMsg(string str)
{
lock(this)
{
str = WC.ReplaceStr(str, "\n", "&Line;") + "\n";
SocketWriter.Write(str);
SocketWriter.Flush();
}
}
public void SendStream(byte[] b)
{
lock(this)
{
FileSocket.Send(b, b.Length, 0);
}
}
public void OnILOVEAICACAFAC(string str)
{
lock(this)
{
this.SendILOVEAICACAFIL(str);
MessageBox.Show(this, WC.lineStr12);
lockMode = false;
this.Close();
}
}
public void OnILOVEAICACAFRE()
{
lock(this)
{
MessageBox.Show(this, WC.lineStr13);
lockMode = false;
this.Close();
}
}
public void OnILOVEAICACAERR(string str)
{
lock(this)
{
MessageBox.Show(this, WC.GetXML(str, "er"));
lockMode = false;
this.Close();
}
}
public Socket pFileSocket
{
set
{
this.SetSocket(value, false);
}
}
public bool pDirectMode
{
set
{
this.directMode = value;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -