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); } } } ///// ///// 文件信息集合類 ///// //[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; // /// // /// 文件版本(EXE, DLL 文件) // /// // 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; } // } // /// // /// 文件版本(EXE, DLL 文件) // /// // 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 //} }