Server项目:
Form1.h
谁动了我的头(文件).h
G系列函数.cpp
一般函数.cpp
多线程函数.cpp
派生类函数.cpp
---------------Form1.h-------------------
#pragma once
extern bool is[30];
extern Int32 Count;
namespace Server {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::Runtime::InteropServices;
using namespace System::Threading;
using namespace System::Net;
using namespace System::Net::Sockets;
using namespace System::Text;
/// <summary>
/// Form1 摘要
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: 在此处添加构造函数代码
//
}
protected:
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::SplitContainer^ splitContainer1;
private: System::Windows::Forms::TableLayoutPanel^ tableLayoutPanel1;
private: System::Windows::Forms::Button^ button1;
private: System::Windows::Forms::Button^ button2;
private: System::Windows::Forms::NotifyIcon^ notifyIcon1;
private: System::ComponentModel::IContainer^ components;
TcpListener^ Server; //服务器侦听器
array<Socket^>^ SAtServer; //服务器端socket
private: System::Windows::Forms::ListView^ mylist;
private: System::Windows::Forms::TreeView^ mytree;
private: System::Windows::Forms::ColumnHeader^ columnHeader1;
private: System::Windows::Forms::ColumnHeader^ columnHeader2;
private: System::Windows::Forms::ImageList^ imageList1;
private: System::Windows::Forms::StatusStrip^ statusStrip1;
private: System::Windows::Forms::ToolStripStatusLabel^ toolStripStatusLabel1;
private: System::Windows::Forms::ToolStripStatusLabel^ zhuangtai;
private: System::Windows::Forms::ToolStripStatusLabel^ toolStripStatusLabel2;
private: System::Windows::Forms::ContextMenuStrip^ contextMenuStrip1;
private: System::Windows::Forms::ToolStripMenuItem^ 显示主窗体ToolStripMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ 退出ToolStripMenuItem;
private: System::Windows::Forms::ToolTip^ toolTip1;
private: System::Windows::Forms::ContextMenuStrip^ contextMenuStrip2;
private: System::Windows::Forms::ToolStripMenuItem^ 踢出房间ToolStripMenuItem;
array<Thread^>^ readThread; //独立于界面线程的另一线程
void f1(); //子线程,侦听服务
void f2(); //消息接收
void f3(); //消息处理函数
void g1(array<Byte>^ ,Int32 ,Int32 ); //"aab"类型,接收用户发送的资料流数据
void g2(array<Byte>^ ,Int32 ,Int32 ); //"aac"类型,心跳检测消息,参数意思是 字节 接收大小 socket索引
void g3(array<Byte>^ ,Int32 ,Int32 ); //"aai"类型,更新用户视图
void g4(array<Byte>^ ,Int32 ,Int32 ); //“bbb'类型,更新用户视图
yonghu^ g6(array<Byte>^ ,Int32); //秘密文件项
yonghu^ g7(array<Byte>^ ,Int32); //一般项
yonghu^ g9(array<Byte>^ ,Int32); //秘密文件夹2
yonghu^ g10(array<Byte>^ ,Int32); //一般文件夹
void g11(array<Byte>^ ,Int32 ,Int32 ); //"bbc" 用户请求下载指令
void g12(array<Byte>^ ,Int32 ,Int32 ); //"bbd"下载失败消息
void g13(array<Byte>^ ,Int32 ,Int32 ); //"cht" 聊天消息
void g14(array<Byte>^ ,Int32 ,Int32 ); //"wlk"用户离开消息
array<huancun>^ Cdate; //服务器缓存
int leave; //退出的用户
bool isequals(String^ ,String^ ); //帮助私密文件夹CText赋值函数
void caozuo(TreeNode^ ,String^ ); //对某个节点的父节点CText赋值
void clear(); //清除
protected:
protected:
private:
/// <summary>
/// 必需的设计器变量。
/// </summary>
#pragma region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
void InitializeComponent(void)
{
this->components = (gcnew System::ComponentModel::Container());
System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(Form1::typeid));
this->splitContainer1 = (gcnew System::Windows::Forms::SplitContainer());
this->mylist = (gcnew System::Windows::Forms::ListView());
this->columnHeader1 = (gcnew System::Windows::Forms::ColumnHeader());
this->columnHeader2 = (gcnew System::Windows::Forms::ColumnHeader());
this->contextMenuStrip2 = (gcnew System::Windows::Forms::ContextMenuStrip(this->components));
this->踢出房间ToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->imageList1 = (gcnew System::Windows::Forms::ImageList(this->components));
this->statusStrip1 = (gcnew System::Windows::Forms::StatusStrip());
this->toolStripStatusLabel1 = (gcnew System::Windows::Forms::ToolStripStatusLabel());
this->zhuangtai = (gcnew System::Windows::Forms::ToolStripStatusLabel());
this->toolStripStatusLabel2 = (gcnew System::Windows::Forms::ToolStripStatusLabel());
this->mytree = (gcnew System::Windows::Forms::TreeView());
this->tableLayoutPanel1 = (gcnew System::Windows::Forms::TableLayoutPanel());
this->button1 = (gcnew System::Windows::Forms::Button());
this->button2 = (gcnew System::Windows::Forms::Button());
this->notifyIcon1 = (gcnew System::Windows::Forms::NotifyIcon(this->components));
this->contextMenuStrip1 = (gcnew System::Windows::Forms::ContextMenuStrip(this->components));
this->显示主窗体ToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->退出ToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->toolTip1 = (gcnew System::Windows::Forms::ToolTip(this->components));
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->splitContainer1))->BeginInit();
this->splitContainer1->Panel1->SuspendLayout();
this->splitContainer1->Panel2->SuspendLayout();
this->splitContainer1->SuspendLayout();
this->contextMenuStrip2->SuspendLayout();
this->statusStrip1->SuspendLayout();
this->tableLayoutPanel1->SuspendLayout();
this->contextMenuStrip1->SuspendLayout();
this->SuspendLayout();
//
// splitContainer1
//
this->splitContainer1->Dock = System::Windows::Forms::DockStyle::Fill;
this->splitContainer1->IsSplitterFixed = true;
this->splitContainer1->Location = System::Drawing::Point(0, 0);
this->splitContainer1->Name = L"splitContainer1";
this->splitContainer1->Orientation = System::Windows::Forms::Orientation::Horizontal;
//
// splitContainer1.Panel1
//
this->splitContainer1->Panel1->Controls->Add(this->mylist);
this->splitContainer1->Panel1->Controls->Add(this->statusStrip1);
this->splitContainer1->Panel1->Controls->Add(this->mytree);
//
// splitContainer1.Panel2
//
this->splitContainer1->Panel2->Controls->Add(this->tableLayoutPanel1);
this->splitContainer1->Size = System::Drawing::Size(262, 491);
this->splitContainer1->SplitterDistance = 408;
this->splitContainer1->TabIndex = 0;
//
// mylist
//
this->mylist->Columns->AddRange(gcnew cli::array< System::Windows::Forms::ColumnHeader^ >(2) {this->columnHeader1, this->columnHeader2});
this->mylist->ContextMenuStrip = this->contextMenuStrip2;
this->mylist->Dock = System::Windows::Forms::DockStyle::Fill;
this->mylist->Font = (gcnew System::Drawing::Font(L"微软雅黑", 10));
this->mylist->FullRowSelect = true;
this->mylist->Location = System::Drawing::Point(0, 0);
this->mylist->Name = L"mylist";
this->mylist->Size = System::Drawing::Size(262, 386);
this->mylist->SmallImageList = this->imageList1;
this->mylist->TabIndex = 2;
this->mylist->UseCompatibleStateImageBehavior = false;
this->mylist->View = System::Windows::Forms::View::Details;
//
// columnHeader1
//
this->columnHeader1->Text = L"用户";
this->columnHeader1->Width = 169;
//
// columnHeader2
//
this->columnHeader2->Text = L"状态";
this->columnHeader2->Width = 61;
//
// contextMenuStrip2
//
this->contextMenuStrip2->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(1) {this->踢出房间ToolStripMenuItem});
this->contextMenuStrip2->Name = L"contextMenuStrip2";
this->contextMenuStrip2->Size = System::Drawing::Size(125, 26);
this->contextMenuStrip2->Opening += gcnew System::ComponentModel::CancelEventHandler(this, &Form1::contextMenuStrip2_Opening);
//
// 踢出房间ToolStripMenuItem
//
this->踢出房间ToolStripMenuItem->Name = L"踢出房间ToolStripMenuItem";
this->踢出房间ToolStripMenuItem->Size = System::Drawing::Size(124, 22);
this->踢出房间ToolStripMenuItem->Text = L"踢出房间";
this->踢出房间ToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::踢出房间ToolStripMenuItem_Click);
//
// imageList1
//
this->imageList1->ColorDepth = System::Windows::Forms::ColorDepth::Depth32Bit;
this->imageList1->ImageSize = System::Drawing::Size(50, 50);
this->imageList1->TransparentColor = System::Drawing::Color::Transparent;
//
// statusStrip1
//
this->statusStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(3) {this->toolStripStatusLabel1,
this->zhuangtai, this->toolStripStatusLabel2});
this->statusStrip1->Location = System::Drawing::Point(0, 386);
this->statusStrip1->Name = L"statusStrip1";
this->statusStrip1->Size = System::Drawing::Size(262, 22);
this->statusStrip1->TabIndex = 3;
this->statusStrip1->Text = L"statusStrip1";
//
// toolStripStatusLabel1
//
this->toolStripStatusLabel1->Name = L"toolStripStatusLabel1";
this->toolStripStatusLabel1->Size = System::Drawing::Size(48, 17);
this->toolStripStatusLabel1->Text = L" 已加入";
//
// zhuangtai
//
this->zhuangtai->Name = L"zhuangtai";
this->zhuangtai->Size = System::Drawing::Size(0, 17);
//
// toolStripStatusLabel2
//
this->toolStripStatusLabel2->Name = L"toolStripStatusLabel2";
this->toolStripStatusLabel2->Size = System::Drawing::Size(32, 17);
this->toolStripStatusLabel2->Text = L"用户";
//
// mytree
//
this->mytree->Location = System::Drawing::Point(24, 49);
this->mytree->Name = L"mytree";
this->mytree->Size = System::Drawing::Size(202, 300);
this->mytree->TabIndex = 1;
this->mytree->Visible = false;
//
// tableLayoutPanel1
//
this->tableLayoutPanel1->ColumnCount = 2;
this->tableLayoutPanel1->ColumnStyles->Add((gcnew System::Windows::Forms::ColumnStyle(System::Windows::Forms::SizeType::Percent,
50)));
this->tableLayoutPanel1->ColumnStyles->Add((gcnew System::Windows::Forms::ColumnStyle(System::Windows::Forms::SizeType::Percent,
50)));
this->tableLayoutPanel1->Controls->Add(this->button1, 0, 0);
this->tableLayoutPanel1->Controls->Add(this->button2, 1, 0);
this->tableLayoutPanel1->Location = System::Drawing::Point(24, 13);
this->tableLayoutPanel1->Name = L"tableLayoutPanel1";
this->tableLayoutPanel1->RowCount = 1;
this->tableLayoutPanel1->RowStyles->Add((gcnew System::Windows::Forms::RowStyle(System::Windows::Forms::SizeType::Percent, 50)));
this->tableLayoutPanel1->Size = System::Drawing::Size(238, 54);
this->tableLayoutPanel1->TabIndex = 0;
//
// button1
//
this->button1->Font = (gcnew System::Drawing::Font(L"微软雅黑", 9, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(134)));
this->button1->Location = System::Drawing::Point(3, 3);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(96, 48);
this->button1->TabIndex = 0;
this->button1->Text = L"禁止新用户加入";
this->toolTip1->SetToolTip(this->button1, L"点击按钮后,此功能需再接收一名客户才生效");
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
//
// button2
//
this->button2->Font = (gcnew System::Drawing::Font(L"微软雅黑", 9, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(134)));
this->button2->Location = System::Drawing::Point(122, 3);
this->button2->Name = L"button2";
this->button2->Size = System::Drawing::Size(95, 48);
this->button2->TabIndex = 1;
this->button2->Text = L"退出服务器";
this->button2->UseVisualStyleBackColor = true;
this->button2->Click += gcnew System::EventHandler(this, &Form1::button2_Click);
//
// notifyIcon1
//
this->notifyIcon1->ContextMenuStrip = this->contextMenuStrip1;
this->notifyIcon1->Icon = (cli::safe_cast<System::Drawing::Icon^ >(resources->GetObject(L"notifyIcon1.Icon")));
this->notifyIcon1->Text = L"notifyIcon1";
this->notifyIcon1->Visible = true;
this->notifyIcon1->DoubleClick += gcnew System::EventHandler(this, &Form1::notifyIcon1_DoubleClick);
//
// contextMenuStrip1
//
this->contextMenuStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(2) {this->显示主窗体ToolStripMenuItem,
this->退出ToolStripMenuItem});
this->contextMenuStrip1->Name = L"contextMenuStrip1";
this->contextMenuStrip1->Size = System::Drawing::Size(137, 48);
//
// 显示主窗体ToolStripMenuItem
//
this->显示主窗体ToolStripMenuItem->Name = L"显示主窗体ToolStripMenuItem";
this->显示主窗体ToolStripMenuItem->Size = System::Drawing::Size(136, 22);
this->显示主窗体ToolStripMenuItem->Text = L"显示主窗体";
this->显示主窗体ToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::显示主窗体ToolStripMenuItem_Click);
//
// 退出ToolStripMenuItem
//
this->退出ToolStripMenuItem->Name = L"退出ToolStripMenuItem";
this->退出ToolStripMenuItem->Size = System::Drawing::Size(136, 22);
this->退出ToolStripMenuItem->Text = L"退出";
this->退出ToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::退出ToolStripMenuItem_Click);
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 12);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(262, 491);
this->Controls->Add(this->splitContainer1);
this->Icon = (cli::safe_cast<System::Drawing::Icon^ >(resources->GetObject(L"$this.Icon")));
this->Location = System::Drawing::Point(1040, 99);
this->MaximumSize = System::Drawing::Size(278, 530);
this->MinimumSize = System::Drawing::Size(278, 530);
this->Name = L"Form1";
this->StartPosition = System::Windows::Forms::FormStartPosition::Manual;
this->Text = L"Server of Need For Share";
this->FormClosing += gcnew System::Windows::Forms::FormClosingEventHandler(this, &Form1::Form1_FormClosing);
this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
this->splitContainer1->Panel1->ResumeLayout(false);
this->splitContainer1->Panel1->PerformLayout();
this->splitContainer1->Panel2->ResumeLayout(false);
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->splitContainer1))->EndInit();
this->splitContainer1->ResumeLayout(false);
this->contextMenuStrip2->ResumeLayout(false);
this->statusStrip1->ResumeLayout(false);
this->statusStrip1->PerformLayout();
this->tableLayoutPanel1->ResumeLayout(false);
this->contextMenuStrip1->ResumeLayout(false);
this->ResumeLayout(false);
}
#pragma endregion
//窗体关闭时函数
private: System::Void Form1_FormClosing(System::Object^ sender, System::Windows::Forms::FormClosingEventArgs^ e) {
if(is[0])
return;
// 取消关闭窗体
e->Cancel = true;
// 将窗体变为最小化
this->WindowState = FormWindowState::Minimized;
this->ShowInTaskbar = false; //不显示在系统任务栏
notifyIcon1->Visible = true; //托盘图标可见
}
//托盘小图标双击时间
private: System::Void notifyIcon1_DoubleClick(System::Object^ sender, System::EventArgs^ e) {
if (this->WindowState == FormWindowState::Minimized)
{
this->Show();
this->WindowState = FormWindowState::Normal ;
this->ShowInTaskbar = true;
}
}
//窗体加载函数,初始化Socket和Sdate
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
clear();
leave=0;
SAtServer=gcnew array<Socket^>(100);
Cdate=gcnew array<huancun>(10);
for(int i=0;i<10;i++)
{
Cdate[i].date=gcnew array<Byte>(5242880);
Cdate[i].is=false;
Cdate[i].hCount=0;
Cdate[i].Index=0;
}
readThread=gcnew array<Thread^>(3);
readThread[0]=gcnew Thread(gcnew ThreadStart(this,&Form1::f1));
readThread[0]->IsBackground=true;
readThread[0]->Start();
readThread[1]=gcnew Thread(gcnew ThreadStart(this,&Form1::f2));
readThread[1]->IsBackground=true;
readThread[1]->Start();
readThread[2]=gcnew Thread(gcnew ThreadStart(this,&Form1::f3));
readThread[2]->IsBackground=true;
readThread[2]->Start();
}
//退出按钮
private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
is[0]=true;
this->Close();
}
//禁止、允许用户加入函数
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
if(button1->Text->Equals("禁止新用户加入"))
{
is[1]=true;
button1->Text="允许新用户加入";
}
else
{
is[1]=false;
button1->Text="禁止新用户加入";
}
}
//显示主窗体
private: System::Void 显示主窗体ToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
this->WindowState=FormWindowState::Normal;
this->ShowInTaskbar = true;
}
//退出
private: System::Void 退出ToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
is[0]=true;
this->Close();
}
//踢出房间函数
private: System::Void 踢出房间ToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
int k=mylist->SelectedIndices[0];
MessageBoxButtons buttons=MessageBoxButtons::YesNo;
System::Windows::Forms::DialogResult result;
result=MessageBox::Show("此功能不友好,确认使用?","将要踢 "+mylist->Items[k]->Text+" 出房间",buttons);
if(result==System::Windows::Forms::DialogResult::No)
return;
array<Byte>^ tosas=gcnew array<Byte>(13);
Encoding::UTF8->GetBytes("13 ",0,7,tosas,0);
tosas[7]='w';
tosas[8]='l';
tosas[9]='k';
Encoding::UTF8->GetBytes((k+100).ToString(),0,3,tosas,10);
SAtServer[k]->Send(tosas);
g14(tosas,13,k);
}
//右键展开菜单
private: System::Void contextMenuStrip2_Opening(System::Object^ sender, System::ComponentModel::CancelEventArgs^ e) {
if(mylist->SelectedItems->Count==0)
{
踢出房间ToolStripMenuItem->Enabled=false;
}
else
{
踢出房间ToolStripMenuItem->Enabled=true;
}
}
};
}
-----------------谁动了我的头(文件).h--------------------
#ifndef HEAD
#define HEAD
#include<Windows.h>
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::IO;
using namespace System::Text;
//设置缓存数据结构
value struct huancun
{
array<Byte>^ date;
Int32 hCount; //huancun接收的字节数
Int32 Index; //Socket索引
bool is;
};
//Int32 链表,帮助将TreeView转换为字节
value struct fuzhu
{
Int32 length; //长度
Int16 leixing; //类型
fuzhu^ next; //next指针
};
//用户节点派生类
ref class yonghu:public TreeNode
{
public:
Int16 choice; //分辨树节点类型123456分别为用户、秘密文件夹、秘密文件项、一般项、秘密文件夹2、一般文件夹
String^ CName; //用户名
String^ CText; //用户备注名或者秘密文件夹标志位序列号
String^ CPicture; //用户头像路径名
bool CSex; //性别
Int32 CMark; //用户标志位或者秘密文件项标志位
Int32 length;
Double size; //记录大小
yonghu(){}
yonghu(Int16);
array<Byte>^ ConvertByte(Int16 ); //类转换为流数据
private:
array<Byte>^ c1(); //类型转换函数选择体系
array<Byte>^ c2();
array<Byte>^ c3();
array<Byte>^ c4();
array<Byte>^ c5();
array<Byte>^ c6();
};
//树视图转换为类数据
array<Byte>^ ConvertByte(TreeView^ );
//Int32转换为字节数组
array<Byte>^ IntToByte(Int32 i);
//进行消息判断处理
Int32 trigger(String^ a);
//返回应用程序被安装的文件夹地址!!应用程序命名时不能有"\"
char* AppName();
//类内部的消息判断
Int32 trigger1(String^ a);
#endif
--------------G系列函数.cpp---------------------
#include"stdafx.h"
using namespace Server;
using namespace System::ComponentModel;
extern bool is[30];
extern Int32 Count;
//"aab"类型,用户资料类型
void Form1::g1(array<Byte>^ a,Int32 b,Int32 c)
{
for(Int16 i=0;i<Count;i++)
{
if(i==c)
continue;
try
{
SAtServer[i]->Send(a,0,b,SocketFlags::None);
} //如果出问题,坐等客户端自己发觉
catch(Exception^ ){}
} //给每个用户发送新用户消息,更新用户树视图
yonghu^ temp=gcnew yonghu(1); //增加的是用户
temp->length=b; //长度赋值
temp->CName=Encoding::UTF8->GetString(a,10,45)->Trim(); //用户名
temp->CText=Encoding::UTF8->GetString(a,55,45)->Trim(); //备注名
temp->CSex=Boolean::Parse(Encoding::UTF8->GetString(a,100,5)->Trim()); //性别
temp->CMark=Int32::Parse(Encoding::UTF8->GetString(a,105,3)->Trim()); //用户标志位
temp->size=Double::Parse(Encoding::UTF8->GetString(a,108,10)->Trim()); //获取大小
String^ form=Encoding::UTF8->GetString(a,118,6)->Trim(); //图片格式
temp->CPicture=gcnew String(AppName()); //用户头像路径
temp->CPicture+="Picture\\"+(temp->CMark+leave).ToString()+form;
FileStream^ fs=gcnew FileStream(temp->CPicture,FileMode::OpenOrCreate,FileAccess::Write,FileShare::ReadWrite);
fs->Write(a,124,b-124); //写入图片流
fs->Close();
temp->Text=" "+temp->CText;
if(temp->CSex)
temp->Text+=" ♂";
else
temp->Text+=" ♀"; //树节点标签
mytree->Nodes->Add(temp); //新增树节点
yonghu^ temp1=gcnew yonghu(2);
mytree->Nodes[Count-1]->Nodes->Add(temp1); //新增秘密分享文件夹
imageList1->Images->Add(Image::FromFile(temp->CPicture)); //头像下标赋值
mylist->Items->Add(mytree->Nodes[Count-1]->Text,Count-1);
mylist->Items[Count-1]->SubItems->Add("已连接");
mylist->Items[Count-1]->ImageIndex=Count-1; //配置列表视图
zhuangtai->Text=Count.ToString(); //更新状态栏
array<Byte>^ sd=ConvertByte(mytree);
UInt32 s=UInt32::Parse(Encoding::UTF8->GetString(sd,10,10)->Trim());
if(s<=5242873)
{
try
{
SAtServer[c]->Send(sd); //给当前用户发送树视图
}
catch(Exception^ ){}
}
else
{
array<Byte>^ zhongjian=gcnew array<Byte>(5242880); //中间变量,辅助发送
Encoding::UTF8->GetBytes("5242880",0,7,zhongjian,0);
Array::Copy(sd,7,zhongjian,7,5242873);
try
{
SAtServer[c]->Send(zhongjian);
}
catch(Exception^ ){}
Int32 jindu=5242880; //发送进度辅助
Int16 cishu=2; //同上
s-=5242873;
while(1)
{
if(s>=5242870)
{
Array::Copy(sd,jindu,zhongjian,10,5242870);
Encoding::UTF8->GetBytes("ab"+cishu.ToString(),0,3,zhongjian,7);
jindu+=5242870;
s-=5242870;
cishu++;
try
{
SAtServer[c]->Send(zhongjian);
}
catch(Exception^ ){}
}
else
{
zhongjian=gcnew array<Byte>(s+10);
Array::Copy(sd,jindu,zhongjian,10,s);
Encoding::UTF8->GetBytes("abe",0,3,zhongjian,7);
Encoding::UTF8->GetBytes((s+10).ToString()->PadRight(7),0,7,zhongjian,0);
try
{
SAtServer[c]->Send(zhongjian);
}
catch(Exception^ ){}
break;
}
}
}
}
//心跳检测消息
void Form1::g2(array<byte>^ a,Int32 b,Int32 c)
{
if(Encoding::UTF8->GetString(a,10,9)->Equals("Heartbeat"))
{
array<Byte>^ temp=gcnew array<Byte>(19);
Array::Copy(a,0,temp,0,19); //返回一样的心跳消息
try
{
SAtServer[c]->Send(temp);
}
catch(Exception^ )
{}
}
}
//"aai"更新用户视图类型
void Form1::g3(array<Byte>^ a,Int32 b,Int32 c)
{
for(Int16 i=0;i<Count;i++)
{
if(i==c)
continue;
try
{
SAtServer[i]->Send(a,0,b,SocketFlags::None);
}
catch(Exception^ ){}
} //给每个用户发送出同样的信息
String^ path=Encoding::UTF8->GetString(a,10,97)->Trim();
path=path->Remove(0,2);
if(path->Length%2)
path+=" ";
TreeNodeCollection^ dingwei=mytree->Nodes;
Int16 pmark;
for(int i=0;2*i<path->Length;i++)
{
pmark=Int16::Parse(path->Substring(2*i,2)->Trim());
dingwei=dingwei[pmark]->Nodes;
}
yonghu^ tem;
array<Byte>^ chuansong=gcnew array<Byte>(b-107);
Array::Copy(a,107,chuansong,0,b-107);
switch(trigger1(Encoding::UTF8->GetString(chuansong,7,3)))
{
case 5:
tem=g6(chuansong,b-107);//秘密文件项
break;
case 6:
tem=g7(chuansong,b-107);//一般文件项
break;
case 8:
tem=g9(chuansong,b-107);//秘密文件夹2
break;
case 9:
tem=g10(chuansong,b-107);//一般文件夹
break;
default:
break;
}
tem->length=b-107;
dingwei->Add(tem);
//刷新私密文件夹的CText属性
if(tem->choice==3)
{
bool jububiaoji=false; //判断单个掩码的状态
for(int i=0;i+1<tem->CText->Length;i+=3)
{
jububiaoji=isequals(tem->CText->Substring(1+3*i,3),safe_cast<yonghu^>(tem->Parent)->CText); //该函数的功能是判断temp父节点中是否有掩码了,是true
if(jububiaoji)
continue;
else
{
TreeNode^ temp2=safe_cast<TreeNode^>(tem);
caozuo(temp2,tem->CText->Substring(1+3*i,3)); //对temp父节点CText赋值
}
}
}
//更新节点size信息
while(tem->Parent!=nullptr)
{
safe_cast<yonghu^>(tem->Parent)->size+=tem->size;
tem=safe_cast<yonghu^>(tem->Parent);
}
}
//"bbb"更新用户视图
void Form1::g4(array<Byte>^ a,Int32 b,Int32 c)
{
for(Int16 i=0;i<Count;i++)
{
if(i==c)
continue;
try
{
SAtServer[i]->Send(a,0,b,SocketFlags::None);
}
catch(Exception^ ){}
} //给每个用户发送出同样的信息
String^ path=Encoding::UTF8->GetString(a,10,97)->Trim();
path=path->Remove(0,2);
if(path->Length%2)
path+=" ";
TreeNodeCollection^ dingwei=mytree->Nodes;
Int16 pmark;
for(int i=0;2*i<path->Length-2;i++)
{
pmark=Int16::Parse(path->Substring(2*i,2)->Trim());
dingwei=dingwei[pmark]->Nodes;
}
pmark=Int16::Parse(path->Substring(path->Length-2,2)->Trim());
yonghu^ tem=gcnew yonghu();
array<Byte>^ chuansong=gcnew array<Byte>(b-107);
Array::Copy(a,107,chuansong,0,b-107);
switch(trigger1(Encoding::UTF8->GetString(chuansong,7,3)))
{
case 5:
tem=g6(chuansong,b-107);
break;
case 6:
tem=g7(chuansong,b-107);
break;
case 8:
tem=g9(chuansong,b-107);
break;
case 9:
tem=g10(chuansong,b-107);
break;
default:
break;
}
tem->length=b-107;
dingwei->Insert(pmark,tem);
dingwei->RemoveAt(pmark+1);
}
//"aae"秘密文件项
yonghu^ Form1::g6(array<Byte>^ a,Int32 b)
{
yonghu^ temp=gcnew yonghu(3);
temp->size=Double::Parse(Encoding::UTF8->GetString(a,10,10)->Trim());
Int32 textlen=Int32::Parse(Encoding::UTF8->GetString(a,20,10)->Trim());
temp->CText=Encoding::UTF8->GetString(a,30,textlen);
Int32 len=Int32::Parse(Encoding::UTF8->GetString(a,30+textlen,10)->Trim());
temp->CPicture=Encoding::UTF8->GetString(a,40+textlen,3*len)->Trim();
len=3*len+40+textlen;
textlen=Int32::Parse(Encoding::UTF8->GetString(a,len,10)->Trim());
temp->Text=Encoding::UTF8->GetString(a,b-5*textlen,3*textlen)->Trim();
temp->choice=3;
return temp;
}
//"aaf"一般文件项
yonghu^ Form1::g7(array<Byte>^ a,Int32 b)
{
yonghu^ temp=gcnew yonghu(4);
temp->size=Double::Parse(Encoding::UTF8->GetString(a,10,10)->Trim());
Int32 len=Int32::Parse(Encoding::UTF8->GetString(a,20,10)->Trim());
temp->CPicture=Encoding::UTF8->GetString(a,30,3*len)->Trim();
len=Int32::Parse(Encoding::UTF8->GetString(a,3*len+30,10)->Trim());
temp->Text=Encoding::UTF8->GetString(a,b-5*len,3*len)->Trim();
temp->choice=4;
return temp;
}
//"aag"秘密文件夹2
yonghu^ Form1::g9(array<Byte>^ a,Int32 b)
{
yonghu^ temp=gcnew yonghu(5);
temp->size=Double::Parse(Encoding::UTF8->GetString(a,10,10)->Trim());
Int32 len=Int32::Parse(Encoding::UTF8->GetString(a,20,10)->Trim());
temp->CText=Encoding::UTF8->GetString(a,30,len);
len=Int32::Parse(Encoding::UTF8->GetString(a,30+len,10)->Trim());
temp->Text=Encoding::UTF8->GetString(a,b-5*len,3*len)->Trim();
temp->Text=temp->Text->Replace(" ","");
temp->choice=5;
return temp;
}
//"aah"一般文件夹
yonghu^ Form1::g10(array<Byte>^ a,Int32 b)
{
yonghu^ temp=gcnew yonghu(6);
temp->size=Double::Parse(Encoding::UTF8->GetString(a,10,10)->Trim());
temp->Text=Encoding::UTF8->GetString(a,20,b-20)->Trim();
temp->Text=temp->Text->Replace(" ","");
//在这里要做一下特别的解释,为什么要有replace函数呢,因为在我debug过程中,发现
//Trim()函数失效。为什么会失效,原因不明,据我瞎猜,是因为Text的末尾有某个我看不到的
//结束符,对于Trim来说,就没有尾部的空白项删除了。好吧,我只能吐血了…………
temp->choice=6;
return temp;
}
//"bbc"用户请求下载指令"bbe""bbg""ccc"
void Form1::g11(array<Byte>^ a,Int32 b,Int32 c)
{
Int16 cmark=Int16::Parse(Encoding::UTF8->GetString(a,10,3));
try
{
SAtServer[cmark-100]->Send(a,0,b,SocketFlags::None);
}
catch(Exception^ ){}
}
//"bbd"下载失败消息,只需要发回给请求方就可以了
void Form1::g12(array<Byte>^ a,Int32 b,Int32 c)
{
Int16 cmark=Int16::Parse(Encoding::UTF8->GetString(a,14,3));
try
{
SAtServer[cmark-100]->Send(a,0,b,SocketFlags::None);
}
catch(Exception^ ){}
}
//"cht"聊天消息
void Form1::g13(array<Byte>^ a,Int32 b,Int32 c)
{
Int16 cmark=Int16::Parse(Encoding::UTF8->GetString(a,10,3)->Trim());
if(cmark==0)
{
for(int i=0;i<Count;i++)
{
if(c==i)
continue;
SAtServer[i]->Send(a,0,b,SocketFlags::None);
}
}
else
{
SAtServer[cmark-100]->Send(a,0,b,SocketFlags::None);
}
}
//用户离开消息
void Form1::g14(array<Byte>^ a,Int32 b,Int32 c)
{
leave++;
for(int i=0;i<Count;i++)
{
if(i==c)
continue;
SAtServer[i]->Send(a);
}
mytree->Nodes->RemoveAt(c);
for(int i=c;i<Count-1;i++)
{
SAtServer[i]=SAtServer[i+1];
safe_cast<yonghu^>(mytree->Nodes[i])->CMark--;
}
Count--;
delete imageList1->Images[c];
delete mylist->Items[c];
mylist->Items->RemoveAt(c);
imageList1->Images->RemoveAt(c);
for(int i=c;i<mylist->Items->Count;i++)
{
mylist->Items[i]->ImageIndex=safe_cast<yonghu^>(mytree->Nodes[i])->CMark-100;
}
zhuangtai->Text=Count.ToString(); //更新状态栏
}
//帮助私密文件夹CText赋值函数
bool Form1::isequals(String^ a,String^ b)
{
for(int i=0;i+1<b->Length;i+=3)
{
if(b->Substring(1+i*3,3)->Equals(a))
return true;
}
return false;
}
//对某个节点的父节点CText赋值
void Form1::caozuo(TreeNode^ a,String^ b)
{
for(int i=2;i<=a->Level;i++)
{
safe_cast<yonghu^>(a->Parent)->CText+=b;
a=a->Parent;
}
}
//清除
void Form1::clear()
{
String^ path=gcnew String(AppName())+"Picture";
if(!Directory::Exists(path))
{
Directory::Delete(path,true);
Directory::CreateDirectory(path);
}
}
---------------一般函数.cpp----------------
#include"stdafx.h"
using namespace Server;
//Int32转换为字节数组
array<Byte>^ IntToByte(Int32 i)
{
array<Byte>^ temp=gcnew array<Byte>(3);
Encoding::UTF8->GetBytes(i.ToString(),0,3,temp,0);
return temp;
}
//进行消息判断处理
Int32 trigger(String^ a)
{
if(a->Equals("bbe")||a->Equals("bbc")||a->Equals("bbg")) //"bbc"用户的请求下载指令,"bbe"下载内容
return 10;
if(a->Equals("aab")) //"aab"接收用户发送数据
return 0;
if(a->Equals("aac")) //"aac"心跳检测
return 1;
if(a->Equals("aai")) //"aai"更新用户视图
return 2;
if(a->Equals("bbb")) //"bbb"同上
return 3;
if(a->Equals("bbd")) //"bbd"下载失败指令
return 11;
if(a->Equals("cht")||a->Substring(0,2)->Equals("zh")||a->Equals("his")) //"cht"聊天消息或者"zh"流
return 12;
if(a->Equals("wlk"))
return 13; //用户离开消息
return -1;
}
//类内部的消息判断
Int32 trigger1(String^ a)
{
if(a->Equals("aab")) //用户消息
return 1;
if(a->Equals("aad")) //秘密文件夹
return 4;
if(a->Equals("aae")) //秘密文件项
return 5;
if(a->Equals("aaf")) //一般项
return 6;
if(a->Equals("aag")) //秘密文件夹2
return 8;
if(a->Equals("aah")) //一般文件夹
return 9;
return -1;
}
//返回应用程序被安装的文件夹地址!!应用程序命名时不能有"\"
char* AppName()
{
wchar_t cxPath[MAX_PATH];
GetModuleFileName(NULL,cxPath,MAX_PATH);
DWORD dwNum = WideCharToMultiByte(CP_OEMCP,NULL,cxPath,-1,NULL,0,NULL,FALSE);
char *path=new char[dwNum];
WideCharToMultiByte (CP_OEMCP,NULL,cxPath,-1,path,dwNum,NULL,FALSE);
String^path_1=gcnew String(path);
Int32 mark=path_1->LastIndexOf('\\');
path_1=path_1->Remove(mark+1,path_1->Length-mark-1);
path_1=path_1->Replace("\\","\\\\");
path_1+="Server\\";
delete[] path;
char* temp=(char*)(Marshal::StringToHGlobalAnsi(path_1).ToPointer());
return temp;
}
//树视图转换函数
array<Byte>^ ConvertByte(TreeView^ a)
{
TreeNode^ temp;
temp=a->Nodes[0];
UInt32 zonglength=0; //总长度记录
Int16 cishu=0; //记录项数
fuzhu^ head=gcnew fuzhu;
fuzhu^ p;
head->length=safe_cast<yonghu^>(temp)->length;
zonglength+=head->length;
cishu++;
head->leixing=0; //0表示首项用户
head->next=nullptr;
p=head; //进行链表初始化
bool end;
bool e;
Int16 pjia;
do
{
end=true;
do
{
e=true;
while(temp->FirstNode!=nullptr)
{
temp=temp->Nodes[0];
p->next=gcnew fuzhu;
p->next->length=safe_cast<yonghu^>(temp)->length;
p->next->leixing=1;
p=p->next;
zonglength+=p->length;
cishu++;
p->next=nullptr;
}
if(temp->NextNode!=nullptr)
{
temp=temp->NextNode;
p->next=gcnew fuzhu;
p->next->length=safe_cast<yonghu^>(temp)->length;
p->next->leixing=2;
p=p->next;
zonglength+=p->length;
cishu++;
p->next=nullptr;
e=false;
}
}while(!e);
pjia=0;
while(temp->Parent!=nullptr)
{
temp=temp->Parent;
pjia++;
if(temp->NextNode!=nullptr)
{
temp=temp->NextNode;
p->next=gcnew fuzhu;
p->next->length=safe_cast<yonghu^>(temp)->length;
p->next->leixing=2+pjia;
p=p->next;
zonglength+=p->length;
cishu++;
p->next=nullptr;
end=false;
break;
}
}
}while(!end);
//总字节块,计算方式是cishu*11(项*11)+zonglength(总长度)+13(报头+长度位数)
zonglength+=cishu*11+13;
array<Byte>^ zongbyte=gcnew array<Byte>(zonglength);
zongbyte[0]='a';
zongbyte[1]='b';
if(zonglength<=5242873)
zongbyte[2]='g';
else
zongbyte[2]='1'; //是否一次性发完在这里进行标记
Encoding::UTF8->GetBytes(zonglength.ToString()->PadRight(10),0,10,zongbyte,3);
temp=a->Nodes[0];
p=head;
Encoding::UTF8->GetBytes(p->length.ToString()->PadRight(10),0,10,zongbyte,13);
Encoding::UTF8->GetBytes(p->leixing.ToString(),0,1,zongbyte,23);
Array::Copy(safe_cast<yonghu^>(temp)->ConvertByte(safe_cast<yonghu^>(temp)->choice),0,zongbyte,24,p->length);
UInt32 jindu=p->length+24; //记录字节块写到哪一项的索引
p=p->next;
do
{
end=true;
do
{
e=true;
while(temp->FirstNode!=nullptr)
{
temp=temp->Nodes[0];
Encoding::UTF8->GetBytes(p->length.ToString()->PadRight(10),0,10,zongbyte,jindu);
Encoding::UTF8->GetBytes(p->leixing.ToString(),0,1,zongbyte,jindu+10);
Array::Copy(safe_cast<yonghu^>(temp)->ConvertByte(safe_cast<yonghu^>(temp)->choice),0,zongbyte,jindu+11,p->length);
jindu+=11+p->length;
p=p->next;
}
if(temp->NextNode!=nullptr)
{
temp=temp->NextNode;
Encoding::UTF8->GetBytes(p->length.ToString()->PadRight(10),0,10,zongbyte,jindu);
Encoding::UTF8->GetBytes(p->leixing.ToString(),0,1,zongbyte,jindu+10);
Array::Copy(safe_cast<yonghu^>(temp)->ConvertByte(safe_cast<yonghu^>(temp)->choice),0,zongbyte,jindu+11,p->length);
jindu+=11+p->length;
p=p->next;
e=false;
}
}while(!e);
while(temp->Parent!=nullptr)
{
temp=temp->Parent;
if(temp->NextNode!=nullptr)
{
temp=temp->NextNode;
Encoding::UTF8->GetBytes(p->length.ToString()->PadRight(10),0,10,zongbyte,jindu);
Encoding::UTF8->GetBytes(p->leixing.ToString(),0,1,zongbyte,jindu+10);
Array::Copy(safe_cast<yonghu^>(temp)->ConvertByte(safe_cast<yonghu^>(temp)->choice),0,zongbyte,jindu+11,p->length);
jindu+=11+p->length;
p=p->next;
end=false;
break;
}
}
}while(!end);
array<Byte>^ gh=gcnew array<Byte>(7+zongbyte->Length);
Encoding::UTF8->GetBytes((7+zongbyte->Length).ToString()->PadRight(7),0,7,gh,0);
Array::Copy(zongbyte,0,gh,7,zongbyte->Length);
return gh;
}
-------------------多线程函数.cpp-------------------
#include"stdafx.h"
using namespace Server;
bool is[30];
Int32 Count=0; //用户数记录
void Form1::f1()
{
Int32 port=13500;
IPAddress^ localAddr=IPAddress::Parse("0.0.0.0");
Server=gcnew TcpListener(localAddr,port);
Server->Start();
//建立服务器侦听器
int bz;
while(!is[1]) //is[1]判断侦听线程是否结束
{
bz=Count;
SAtServer[Count]=Server->AcceptSocket(); //开始侦听客户端,程序进入阻塞
if(bz!=Count)
{
SAtServer[Count]=SAtServer[bz];
}
try
{
SAtServer[Count]->Send(IntToByte(Count+100)); //发送掩码
}
catch(Exception^ ){}
Count++;
Thread::Sleep(100);
}
}
//接收消息
void Form1::f2()
{
Int32 c=0; // 缓存切换下标
int zlen;
while(!is[2])
{
for(int i=0;i<Count;i++)
{
if(SAtServer[i]->Available>0)
{
Cdate[c].hCount=SAtServer[i]->Receive(Cdate[c].date,0,7,SocketFlags::None);
try
{
zlen=Int32::Parse(Encoding::UTF8->GetString(Cdate[c].date,0,7)->Trim());
}
catch(Exception^ e)
{
MessageBox::Show("出错");
Cdate[c].hCount=SAtServer[i]->Receive(Cdate[c].date);
continue;
}
while(Cdate[c].hCount!=zlen)
{
Cdate[c].hCount+=SAtServer[i]->Receive(Cdate[c].date,Cdate[c].hCount,zlen-Cdate[c].hCount,SocketFlags::None);
Thread::Sleep(1);
}
Cdate[c].is=true;
Cdate[c].Index=i;
c++;
if(c==10)
c=0;
}
}
Thread::Sleep(1);
}
}
//服务器消息处理函数
void Form1::f3()
{
Int16 i=0;
while(!is[3])
{
if(Cdate[i].is)
{
switch(trigger(Encoding::UTF8->GetString(Cdate[i].date,7,3))) //触发消息类型处理
{
case 0:
g1(Cdate[i].date,Cdate[i].hCount,Cdate[i].Index);
break;
case 1:
g2(Cdate[i].date,Cdate[i].hCount,Cdate[i].Index);
break;
case 2:
g3(Cdate[i].date,Cdate[i].hCount,Cdate[i].Index);
break;
case 3:
g4(Cdate[i].date,Cdate[i].hCount,Cdate[i].Index);
break;
case 10:
g11(Cdate[i].date,Cdate[i].hCount,Cdate[i].Index); //用户的请求下载指令、和下载内容
break;
case 11:
g12(Cdate[i].date,Cdate[i].hCount,Cdate[i].Index);
break; //"bbd"下载失败消息
case 12:
g13(Cdate[i].date,Cdate[i].hCount,Cdate[i].Index); //"cht"聊天消息
break;
case 13:
g14(Cdate[i].date,Cdate[i].hCount,Cdate[i].Index); //用户离开消息
break;
default:
break;
}
Cdate[i].is=false;
i++;
if(i==10)
i=0;
}
Thread::Sleep(1);
}
}
----------------派生类函数.cpp-----------------------
#include"stdafx.h"
using namespace Server;
//有a指定的不同方式的构造函数
yonghu::yonghu(Int16 a) //123456分别为用户、秘密文件夹、秘密文件项、一般项、秘密文件夹2号、一般文件夹
{
choice=a;
size=0;
switch(a)
{
case 2:
CText="0";
Text="私密分享";
length=21;
break;
case 3:
Text="";
CPicture="";
CMark=0;
length=43;
break;
case 4:
Text="";
CPicture="";
length=40;
break;
case 5:
Text="";
CText="0";
length=41;
break;
case 6:
Text="";
length=20;
break;
default:
break;
}
}
array<Byte>^ yonghu::ConvertByte(Int16 a) //转换为流数据
{
switch(a)
{
case 1:
return c1();
case 2:
return c2();
case 3:
return c3();
case 4:
return c4();
case 5:
return c5();
case 6:
return c6();
default:
return nullptr;
}
}
//用户资料的变换,已改
array<Byte>^ yonghu::c1()
{
FileStream^ fs=gcnew FileStream(CPicture,FileMode::Open,FileAccess::Read,FileShare::ReadWrite);
array<Byte>^ Cdate=gcnew array<Byte>(124+fs->Length);
Encoding::UTF8->GetBytes((124+fs->Length).ToString()->PadRight(7),0,7,Cdate,0); //写入字节块长度
Cdate[7]='a';
Cdate[8]='a';
Cdate[9]='b'; // aab为用户资料消息类型
String^ temp=CPicture->Substring(CPicture->LastIndexOf('.'),CPicture->Length-CPicture->LastIndexOf('.'));
Encoding::UTF8->GetBytes(CName->PadRight(45),0,45,Cdate,10); //用户名
Encoding::UTF8->GetBytes(CText->PadRight(45),0,45,Cdate,55); //备注名
Encoding::UTF8->GetBytes(CSex.ToString()->PadRight(5),0,5,Cdate,100); //性别
Encoding::UTF8->GetBytes(CMark.ToString()->PadRight(3),0,3,Cdate,105); //掩码
Encoding::UTF8->GetBytes(size.ToString()->PadRight(10),0,10,Cdate,108); //记录大小
Encoding::UTF8->GetBytes(temp->PadRight(6),0,6,Cdate,118); //图片流格式
fs->Read(Cdate,124,fs->Length); //图片流
fs->Close();
return Cdate;
}
//秘密文件夹,已改
array<Byte>^ yonghu::c2()
{
array<Byte>^ temp=gcnew array<Byte>(20+CText->Length);
Encoding::UTF8->GetBytes((20+CText->Length).ToString()->PadRight(7),0,7,temp,0);
temp[7]='a';
temp[8]='a';
temp[9]='d';
Encoding::UTF8->GetBytes(size.ToString()->PadRight(10),0,10,temp,10); //大小记录
Encoding::UTF8->GetBytes(CText,0,CText->Length,temp,20); //标志位序列记录
return temp;
}
//秘密项,已改
array<Byte>^ yonghu::c3()
{
array<Byte>^temp=gcnew array<Byte>(50+CText->Length+5*Text->Length+3*CPicture->Length);
Encoding::UTF8->GetBytes((50+CText->Length+5*Text->Length+3*CPicture->Length).ToString()->PadRight(7),0,7,temp,0);
temp[7]='a';
temp[8]='a';
temp[9]='e';
Encoding::UTF8->GetBytes(size.ToString()->PadRight(10),0,10,temp,10); //大小记录
Encoding::UTF8->GetBytes(CText->Length.ToString()->PadRight(10),0,10,temp,20);
Encoding::UTF8->GetBytes(CText,0,CText->Length,temp,30);
Encoding::UTF8->GetBytes(CPicture->Length.ToString()->PadRight(10),0,10,temp,30+CText->Length);
Encoding::UTF8->GetBytes(CPicture->PadRight(3*CPicture->Length),0,3*CPicture->Length,temp,40+CText->Length); //路径记录
Encoding::UTF8->GetBytes(Text->Length.ToString()->PadRight(10),0,10,temp,40+CText->Length+3*CPicture->Length);
Encoding::UTF8->GetBytes(Text->PadRight(3*Text->Length),0,3*Text->Length,temp,50+CText->Length+3*CPicture->Length); // 项名 记录
return temp;
}
//一般文件项,已改
array<Byte>^ yonghu::c4()
{
array<Byte>^ temp=gcnew array<Byte>(40+5*Text->Length+3*CPicture->Length);
Encoding::UTF8->GetBytes((33+5*Text->Length+3*CPicture->Length).ToString()->PadRight(7),0,7,temp,0);
temp[7]='a';
temp[8]='a';
temp[9]='f';
Encoding::UTF8->GetBytes(size.ToString()->PadRight(10),0,10,temp,10); //大小记录
Encoding::UTF8->GetBytes(CPicture->Length.ToString()->PadRight(10),0,10,temp,20);
Encoding::UTF8->GetBytes(CPicture->PadRight(3*CPicture->Length),0,3*CPicture->Length,temp,30); //路径记录
Encoding::UTF8->GetBytes(Text->Length.ToString()->PadRight(10),0,10,temp,30+3*CPicture->Length);
Encoding::UTF8->GetBytes(Text->PadRight(3*Text->Length),0,3*Text->Length,temp,40+3*CPicture->Length); // 项名记录
return temp;
}
//秘密文件夹2,已改
array<Byte>^ yonghu::c5()
{
array<Byte>^ temp=gcnew array<Byte>(40+5*Text->Length+CText->Length);
Encoding::UTF8->GetBytes((33+5*Text->Length+CText->Length).ToString()->PadRight(7),0,7,temp,0);
temp[7]='a';
temp[8]='a';
temp[9]='g';
Encoding::UTF8->GetBytes(size.ToString()->PadRight(10),0,10,temp,10); //大小记录
Encoding::UTF8->GetBytes(CText->Length.ToString()->PadRight(10),0,10,temp,20); //标志位序列号记录
Encoding::UTF8->GetBytes(CText,0,CText->Length,temp,30);
Encoding::UTF8->GetBytes(Text->Length.ToString()->PadRight(10),0,10,temp,30+CText->Length);
Encoding::UTF8->GetBytes(Text->PadRight(3*Text->Length),0,3*Text->Length,temp,40+CText->Length);//项名记录
return temp;
}
//一般文件夹,已改
array<Byte>^ yonghu::c6()
{
array<Byte>^ temp=gcnew array<Byte>(20+5*Text->Length);
Encoding::UTF8->GetBytes((20+5*Text->Length).ToString()->PadRight(7),0,7,temp,0);
temp[7]='a';
temp[8]='a';
temp[9]='h';
Encoding::UTF8->GetBytes(size.ToString()->PadRight(10),0,10,temp,10); //大小记录
Encoding::UTF8->GetBytes(Text->PadRight(3*Text->Length),0,3*Text->Length,temp,20);//项名记录
return temp;
}

|