You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

141 lines
3.4 KiB
C#

using System;
using System.Collections.Generic;
using System.Text;
namespace Estsh.Client.Common.FileUtil
{
/// <summary>
/// 文件列表封装类
/// </summary>
[Serializable]
public class FileInfos
{
/// <summary>
/// 文件信息列表<E58897>
/// </summary>
public List<FileInfo> Infos;
// private long _totalBytes;
/// <summary>
/// 构造方法
/// </summary>
public FileInfos()
{
Infos = new List<FileInfo>();
}
public long TotalBytes
{
get
{
long totals = 0;
foreach (FileInfo fi in Infos)
{
totals += fi.Size;
}
return totals;
}
}
}
/// <summary>
/// 自定义文件信息类
/// </summary>
[Serializable]
public class FileInfo : IComparable<FileInfo>
{
/// <summary>
/// 文件名称
/// </summary>
private string _name;
/// <summary>
/// 文件大小
/// </summary>
private long _size;
/// <summary>
/// 最后更新时间
/// </summary>
private DateTime _lastWriteTime;
/// <summary>
/// 文件版本
/// </summary>
private string _version;
/// <summary>
/// 文件名称
/// </summary>
public string Name
{
get { return _name; }
set { _name = value; }
}
/// <summary>
/// 文件大小<E5A4A7>
/// </summary>
public long Size
{
get { return _size; }
set { _size = value; }
}
/// <summary>
/// 最后更新时间
/// </summary>
public DateTime LastWriteTime
{
get { return _lastWriteTime; }
set { _lastWriteTime = value; }
}
/// <summary>
/// 文件版本
/// </summary>
public string Version
{
get { return _version; }
set { _version = value; }
}
#region IComparable<FileInfo> Θ<>
/// <summary>
/// 文件比对
/// </summary>
/// <param name="other"></param>
/// <returns></returns>
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
}
}