/*----------------------------------------------------------------
// Copyright (C) 2007 liu523@QQ.COM
// 版权所有。
// 开发者:liu523@QQ.COM团队
// 文件名:FileCode.cs
// 文件功能描述:涉及到文件管理的指令-文件指令类。
//----------------------------------------------------------------*/
using System;
using System.IO;
namespace RemoteControlLib.Codes
{
///
/// 文件指令类
///
[Serializable]
public class FileCode : BaseCode
{
private string fileName;
private string savePath;
private byte[] mbyte;
///
/// 文件字节数
///
private long fileLength;
///
/// 文件流字节块
///
public byte[] Mbyte
{
get { return mbyte; }
set { mbyte = value; }
}
///
/// 保存路径
///
public string SavePath
{
get { return savePath; }
set { savePath = value; }
}
///
/// 文件指令类的构造函数
///
///
public FileCode(string fileName)
{
this.fileName = fileName;
}
///
/// 读取文件
///
public void readFile()
{
FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read);
fileLength = fileStream.Length;
mbyte = new byte[fileLength];
int m = 0;
int startmbyte = 0;
int allmybyte = (int)fileLength;
do
{
m = fileStream.Read(mbyte, startmbyte, allmybyte);
startmbyte += m;
allmybyte -= m;
} while (m > 0);
fileStream.Close();
}
///
/// 保存文件
///
public void SaveFile()
{
try
{
FileStream output = new FileStream(savePath, FileMode.OpenOrCreate, FileAccess.Write);
output.Write(mbyte, 0, (int)fileLength);
output.Close();
}
catch (Exception exp)
{
System.Windows.Forms.MessageBox.Show(exp.ToString());
}
}
}
}