using System;
using System.Collections.Generic;
using System.Text;
namespace Estsh.Client.Common.FileUtil
{
///
/// 文件列表封装类
///
[Serializable]
public class FileInfos
{
///
/// 文件信息列表
///
public List Infos;
// private long _totalBytes;
///
/// 构造方法
///
public FileInfos()
{
Infos = new List();
}
public long TotalBytes
{
get
{
long totals = 0;
foreach (FileInfo fi in Infos)
{
totals += fi.Size;
}
return totals;
}
}
}
///
/// 自定义文件信息类
///
[Serializable]
public class FileInfo : IComparable
{
///
/// 文件名称
///
private string _name;
///
/// 文件大小
///
private long _size;
///
/// 最后更新时间
///
private DateTime _lastWriteTime;
///
/// 文件版本
///
private string _version;
///
/// 文件名称
///
public string Name
{
get { return _name; }
set { _name = value; }
}
///
/// 文件大小
///
public long Size
{
get { return _size; }
set { _size = value; }
}
///
/// 最后更新时间
///
public DateTime LastWriteTime
{
get { return _lastWriteTime; }
set { _lastWriteTime = value; }
}
///
/// 文件版本
///
public string Version
{
get { return _version; }
set { _version = value; }
}
#region IComparable Θ
///
/// 文件比对
///
///
///
public int CompareTo(FileInfo other)
{
if (null == Version || null == other.Version)
{
return LastWriteTime.CompareTo(other.LastWriteTime);
}
else if (Version.IndexOf('.') < 0 || other.Version.IndexOf('.') < 0)
{
return LastWriteTime.CompareTo(other.LastWriteTime);
}
else
{
//return Version.CompareTo(other.Version);
string[] vers = Version.Split('.');
string[] vers_other = other.Version.Split('.');
int iVer = 0, iVer_other = 0;
for (int index=0; index < vers.Length; index++)
{
iVer = Convert.ToInt32(vers[index]);
iVer_other = Convert.ToInt32(vers_other[index]);
if (iVer != iVer_other)
return iVer.CompareTo(iVer_other);
}
return iVer.CompareTo(iVer_other);
}
}
#endregion
}
}