|
|
using System.Diagnostics;
|
|
|
|
|
|
namespace Estsh.Client.Common.FileManager
|
|
|
{
|
|
|
public static class FileInfoExtensions
|
|
|
{
|
|
|
public static int CompareTo(this FileInfo fileInfo, FileInfo other)
|
|
|
{
|
|
|
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(fileInfo.FullName);
|
|
|
FileVersionInfo fviOther = FileVersionInfo.GetVersionInfo(other.FullName);
|
|
|
|
|
|
|
|
|
if (null == fvi.FileVersion || null == fviOther.FileVersion)
|
|
|
{
|
|
|
return fileInfo.LastWriteTime.CompareTo(other.LastWriteTime);
|
|
|
}
|
|
|
else if (fvi.FileVersion.IndexOf('.') < 0 || fviOther.FileVersion.IndexOf('.') < 0)
|
|
|
{
|
|
|
return fileInfo.LastWriteTime.CompareTo(other.LastWriteTime);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
//return Version.CompareTo(other.Version);
|
|
|
string[] vers = fvi.FileVersion.Split('.');
|
|
|
string[] vers_other = fviOther.FileVersion.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);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
///// <summary>
|
|
|
///// 文件信息集合類
|
|
|
///// </summary>
|
|
|
//[Serializable]
|
|
|
//public class FileInfos
|
|
|
//{
|
|
|
// /// <summary>
|
|
|
// /// 文件信息類的集合
|
|
|
// /// </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>
|
|
|
// /// 文件版本(EXE, DLL 文件)
|
|
|
// /// </summary>
|
|
|
// private string _version;
|
|
|
|
|
|
// /// <summary>
|
|
|
// /// 文件名稱
|
|
|
// /// </summary>
|
|
|
// public string Name
|
|
|
// {
|
|
|
// get { return _name; }
|
|
|
// set { _name = value; }
|
|
|
// }
|
|
|
// /// <summary>
|
|
|
// /// 文件大小
|
|
|
// /// </summary>
|
|
|
// public long Size
|
|
|
// {
|
|
|
// get { return _size; }
|
|
|
// set { _size = value; }
|
|
|
// }
|
|
|
// /// <summary>
|
|
|
// /// 文件最后修改時間
|
|
|
// /// </summary>
|
|
|
// public DateTime LastWriteTime
|
|
|
// {
|
|
|
// get { return _lastWriteTime; }
|
|
|
// set { _lastWriteTime = value; }
|
|
|
// }
|
|
|
// /// <summary>
|
|
|
// /// 文件版本(EXE, DLL 文件)
|
|
|
// /// </summary>
|
|
|
// public string Version
|
|
|
// {
|
|
|
// get { return _version; }
|
|
|
// set { _version = value; }
|
|
|
// }
|
|
|
|
|
|
// #region IComparable<FileInfo> 成員
|
|
|
|
|
|
// 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
|
|
|
//}
|
|
|
}
|