//遍历标准文件夹 private void GetDirList(string fPath) { if (!Directory.Exists(fPath)) { return; } string[] directories = Directory.GetDirectories(fPath); foreach (string filePath in directories) { DirectoryInfo dirinfo = new DirectoryInfo(filePath); FileDetailInfo Info = new FileDetailInfo(); Info.FileName = dirinfo.Name; Info.IsEnable = true; if (Directory.Exists(filePath)) { Info.IsDir = true; } string splitstr = "standard"; int pos = filePath.IndexOf(splitstr); Info.LocalDir = filePath.Substring(pos + splitstr.Length, filePath.Length - pos - splitstr.Length); UInt32 CRC32 = 0; NetInterface.NetCRC32(filePath, ref CRC32); Info.LocalCRC = Convert.ToString(CRC32);; Info.MotifyLocalTime = dirinfo.LastWriteTime.ToString(); LocalList.Add(Info); } GetFileList(fPath); }
//选择列表文件 private void OnSelectFiles(object sender, RoutedEventArgs e) { CheckBox cb = sender as CheckBox; FileDetailInfo obj = (FileDetailInfo)cb.DataContext; TransFilesInfo info = new TransFilesInfo(); if (true == cb.IsChecked) { if ("LocalFilesCheckBox" == cb.Name) { info.Path = obj.LocalDir; info.Type = obj.IsDir ? 0 : 1; SelectLocalList.Add(info); } else if ("RemoteFilesCheckBox" == cb.Name) { info.Path = obj.RemoteDir; info.Type = obj.IsDir ? 0 : 1; SelectRemoteList.Add(info); } } else { if ("LocalFilesCheckBox" == cb.Name) { info.Path = obj.LocalDir; info.Type = obj.IsDir ? 0 : 1; SelectLocalList.Remove(SelectLocalList.Where(p => p.Path == obj.LocalDir).FirstOrDefault()); } else if ("RemoteFilesCheckBox" == cb.Name) { info.Path = obj.RemoteDir; info.Type = obj.IsDir ? 0 : 1; SelectRemoteList.Remove(SelectRemoteList.Where(p => p.Path == obj.RemoteDir).FirstOrDefault()); } } }
private void GetFileList(string fPath) { string[] files = Directory.GetFiles(fPath, "*"); foreach (string filePath in files) { FileDetailInfo Info = new FileDetailInfo(); Info.FileName = System.IO.Path.GetFileName(filePath); FileInfo fi = new FileInfo(filePath); UInt32 CRC32 = 0; NetInterface.NetCRC32(filePath, ref CRC32); Info.IsDir = false; Info.IsEnable = true; string splitstr = "standard"; int pos = filePath.IndexOf(splitstr); Info.LocalDir = filePath.Substring(pos + splitstr.Length, filePath.Length - pos - splitstr.Length); Info.LocalCRC = Convert.ToString(CRC32); Info.MotifyLocalTime = fi.LastWriteTime.ToString(); LocalList.Add(Info); } }
//校验选择文件列表 private void CheckSelFileList(ref List <TransFilesInfo> list) { FileDetailInfo item = (FileDetailInfo)PointItem; if (null == item) { list = SelectRemoteList; } else { if (item.IsSelectedRemote) { list = SelectRemoteList; } else { TransFilesInfo info = new TransFilesInfo(); info.Path = item.RemoteDir; info.Type = item.IsDir ? 0 : 1; list.Add(info); } } }
public static void InitFileClassify(List <FileDetailInfo> standard, List <FileDetailInfo> remote, ref List <FileDetailInfo> standardOut, ref List <FileDetailInfo> remoteOut) { int MaxCount = (standard.Count > remote.Count ? standard.Count : remote.Count); Dictionary <string, FileDetailInfo> MapTotalFileInfo = new Dictionary <string, FileDetailInfo>(); Dictionary <string, FileDetailInfo> dictStandard = standard.ToDictionary(key => key.FileName, value => value); Dictionary <string, FileDetailInfo> dictRemote = remote.ToDictionary(key => key.FileName, value => value); //求远端和本地文件信息的全集 for (int i = 0; i < MaxCount; i++) { if (i < standard.Count) { if (!MapTotalFileInfo.ContainsKey(standard[i].FileName)) { MapTotalFileInfo[standard[i].FileName] = standard[i]; } } if (i < remote.Count) { if (!MapTotalFileInfo.ContainsKey(remote[i].FileName)) { MapTotalFileInfo[remote[i].FileName] = remote[i]; } } } //全集跟各自的文件信息对比,不存在的FileName="" Dictionary <string, FileDetailInfo> tmpStandardFileInfo = new Dictionary <string, FileDetailInfo>(MapTotalFileInfo); Dictionary <string, FileDetailInfo> tmpRemoteFileInfo = new Dictionary <string, FileDetailInfo>(MapTotalFileInfo); foreach (string filename in MapTotalFileInfo.Keys) { FileDetailInfo info = MapTotalFileInfo[filename]; if (!dictStandard.ContainsKey(info.FileName)) { FileDetailInfo InvalidInfo = new FileDetailInfo(); InvalidInfo.FileName = ""; InvalidInfo.IsDir = dictRemote[info.FileName].IsDir; InvalidInfo.IsEnable = false; InvalidInfo.MotifyLocalTime = ""; InvalidInfo.LocalCRC = ""; tmpStandardFileInfo[info.FileName] = InvalidInfo; } if (!dictRemote.ContainsKey(info.FileName)) { FileDetailInfo InvalidInfo = new FileDetailInfo(); InvalidInfo.FileName = ""; InvalidInfo.IsDir = dictStandard[info.FileName].IsDir; InvalidInfo.IsEnable = false; InvalidInfo.MotifyRemoteTime = ""; InvalidInfo.RemoteCRC = ""; tmpRemoteFileInfo[info.FileName] = InvalidInfo; } } //还原目录 foreach (string filename in tmpStandardFileInfo.Keys) { if (filename == "") { continue; } if (dictStandard.ContainsKey(filename)) { tmpStandardFileInfo[filename].LocalDir = dictStandard[filename].LocalDir; tmpStandardFileInfo[filename].LocalCRC = dictStandard[filename].LocalCRC; tmpStandardFileInfo[filename].MotifyLocalTime = dictStandard[filename].MotifyLocalTime; } } foreach (string filename in tmpRemoteFileInfo.Keys) { if (filename == "") { continue; } if (dictRemote.ContainsKey(filename)) { tmpRemoteFileInfo[filename].RemoteDir = dictRemote[filename].RemoteDir; tmpRemoteFileInfo[filename].RemoteCRC = dictRemote[filename].RemoteCRC; tmpRemoteFileInfo[filename].MotifyRemoteTime = dictRemote[filename].MotifyRemoteTime; tmpRemoteFileInfo[filename].IsEnable = dictRemote[filename].IsEnable; } } //比较差异性,个数一致 foreach (string filename in tmpStandardFileInfo.Keys) { if (!tmpRemoteFileInfo.ContainsKey(filename)) { continue; } if (("" == tmpRemoteFileInfo[filename].FileName && "" != tmpStandardFileInfo[filename].FileName) || ("" != tmpRemoteFileInfo[filename].FileName && "" == tmpStandardFileInfo[filename].FileName)) { tmpRemoteFileInfo[filename].RemoteType = DifferType.None; tmpStandardFileInfo[filename].LocalType = DifferType.None; continue; } if ("" != tmpRemoteFileInfo[filename].FileName && "" != tmpStandardFileInfo[filename].FileName) { if (tmpStandardFileInfo[filename].IsDir) { //UInt32 localCRC32 = 0; //UInt32 remoteCRC32 = 0; //NetInterface.NetCRC32(tmpStandardFileInfo[filename].LocalDir, ref localCRC32); //NetInterface.NetCRC32(tmpRemoteFileInfo[filename].RemoteDir, ref remoteCRC32); if (tmpStandardFileInfo[filename].LocalCRC != tmpRemoteFileInfo[filename].RemoteCRC) { tmpRemoteFileInfo[filename].RemoteType = DifferType.CRC32; tmpRemoteFileInfo[filename].LocalType = DifferType.CRC32; } } else { if (tmpStandardFileInfo[filename].LocalCRC != tmpRemoteFileInfo[filename].RemoteCRC) { tmpRemoteFileInfo[filename].RemoteType = DifferType.CRC32; tmpRemoteFileInfo[filename].LocalType = DifferType.CRC32; } } } } //重新排列 standardOut = tmpStandardFileInfo.Values.ToList <FileDetailInfo>(); remoteOut = tmpRemoteFileInfo.Values.ToList <FileDetailInfo>(); }
//双击列表文件夹 private void OnDoubleClickFileList(object sender, MouseButtonEventArgs e) { ListView list = sender as ListView; if (null == list) { return; } if (null == PointItem) { return; } FileDetailInfo item = ((FileDetailInfo)PointItem); if (item.IsDir) { string strRelativeDir = ""; if ("RemoteListView" == list.Name) { string splitstr = IP; if (null == item.RemoteDir) { return; } int pos = item.RemoteDir.IndexOf(IP); strRelativeDir = item.RemoteDir; } else if ("LocalListView" == list.Name) { if (null == item.LocalDir) { return; } strRelativeDir = item.LocalDir; } NodeOperationInitList(strRelativeDir); } else { if ("" == item.FileName) { return; } string pathRemote = ""; if (item.RemoteDir != null) { pathRemote = item.RemoteDir.Substring(1, item.RemoteDir.Length - 1); } String dir = null; Tool.Setting.ConfigRead.ReadLocalDir(ref dir); string pathLocal = ""; if (item.LocalDir != null) { pathLocal = dir + item.LocalDir.Substring(1, item.LocalDir.Length - 1); } if ("RemoteListView" == list.Name) { if (item.FileSize > 1024 * 1024) { NotifyMessageEx.ShowNotify(Tool.MainWindow.This, "文件大于1M,无法显示", "提示"); return; } TransFilesInfo info = new TransFilesInfo(); info.Path = ((FileDetailInfo)PointItem).RemoteDir; info.Type = ((FileDetailInfo)PointItem).IsDir ? 0 : 1; List <TransFilesInfo> tmpList = new List <TransFilesInfo>(); tmpList.Add(info); int retval = -1; this.Dispatcher.Invoke(() => { this.WaitEvent(() => { unsafe { retval = Tool.FileHandle.FTS.DownLoadFile(EP, tmpList, BaseDir); } }, true, true); }); if (retval < 0) { NotifyMessageEx.ShowNotify(Tool.MainWindow.This, "下载文件失败!", "错误"); return; } } else if ("LocalListView" == list.Name) { if (!CheckFileSize(pathLocal)) { return; } if (item.FileSize > 1024 * 1024) { NotifyMessageEx.ShowNotify(Tool.MainWindow.This, "文件大于1M,无法显示", "提示"); return; } TransFilesInfo info = new TransFilesInfo(); info.Path = ((FileDetailInfo)PointItem).RemoteDir; info.Type = ((FileDetailInfo)PointItem).IsDir ? 0 : 1; List <TransFilesInfo> tmpList = new List <TransFilesInfo>(); tmpList.Add(info); int retval = -1; this.Dispatcher.Invoke(() => { this.WaitEvent(() => { unsafe { retval = Tool.FileHandle.FTS.DownLoadFile(EP, tmpList, BaseDir); } }, true, true); }); if (retval < 0) { NotifyMessageEx.ShowNotify(Tool.MainWindow.This, "下载文件失败!", "错误"); return; } } WidCompareListEx.Show(Tool.MainWindow.This, EP, pathLocal, pathRemote, DirRelative); } }
//初始化Remote文件列表信息 private void InitRemoteList() { Int32 retval = -1; Proto.ProtoFileList fileList = new Proto.ProtoFileList(); this.Dispatcher.Invoke(() => { unsafe { void *r_data = null; int r_len = 0; retval = NetInterface.NetQueryCurrentCatalog(EP, DirRelative, &r_data, &r_len); if (r_len == 0) { return; } byte[] ack_msg = null; ack_msg = new byte[r_len]; using (UnmanagedMemoryStream ms = new UnmanagedMemoryStream((byte *)r_data, r_len)) { ms.Read(ack_msg, 0, ack_msg.Length); } Tool.Proto.Unpackage <Proto.ProtoFileList> list = new Proto.Unpackage <Proto.ProtoFileList>(ack_msg); if (list.build()) { fileList = list.ob; } NetInterface.FreeDetail(r_data); } }); if (retval < -1) { NotifyMessageEx.ShowNotify(Tool.MainWindow.This, "获取车载文件列表失败", "错误"); return; } DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1601, 1, 1)); foreach (var obj in fileList.FileListList) { FileDetailInfo Info = new FileDetailInfo(); Info.FileName = obj.FileName.value_; Info.IsEnable = true; if (".\\" == DirRelative) { Info.RemoteDir = DirRelative + Info.FileName; } else { Info.RemoteDir = DirRelative + "\\" + Info.FileName; } if (0 == obj.FileType.value_) { Info.IsDir = true; } Info.RemoteCRC = obj.FileCRC32.value_.ToString(); DateTime targetDt = dtStart.AddTicks((long)obj.FileModifyTime.value_); Info.MotifyRemoteTime = targetDt.ToString(); Info.FileSize = obj.FileSize.value_; RemoteList.Add(Info); } }