using FTPop; using GameBackup3H3.DbOp; using ryCommon; using ryCommonDb; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.Drawing; using System.Linq; using System.Security.Policy; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; using WinSCP; using 开发辅助工具.Manager.FTP; using 开发辅助工具.Manager; using BrightIdeasSoftware; using WeifenLuo.WinFormsUI.Docking; using 开发辅助工具.Tools.SmartEditor; using SuperDesign.Tools.SmartEditor; using ObjectListViewDemo; using System.IO; using ScintillaNET; using DiffPlex.Model; using ryControls.Interface; using static System.Net.WebRequestMethods; using ryControls; using static VPKSoft.ScintillaLexers.LexerEnumerations; using VPKSoft.ScintillaLexers; using TheArtOfDev.HtmlRenderer.Adapters.Entities; using static ScintillaNET.Style; using RySmartEditor.Controls; using ExtendUI.FTPManager; namespace SuperDesign.Manager.FTP { public partial class FrmFTPBrowser : DockContent { public FrmFTPBrowser() { InitializeComponent(); OlvFileName.AspectGetter = (x) => { return ((FTPop.RemoteFileInfo)x)?.Name; }; OlvFileName.ImageGetter = delegate (object x) { var item = (FTPop.RemoteFileInfo)x; if (item == null) { return ""; } return GetImageIndex(item.IsDirectory,System.IO.Path.GetExtension(item.Name)); }; OlvFileSize.AspectGetter = (x) => { return ((FTPop.RemoteFileInfo)x).IsDirectory ? 0L : ((FTPop.RemoteFileInfo)x).Length; }; OlvFileSize.AspectToStringConverter = (rowdata, x) => { return ((long)x) == 0 ? "-" : RyFiles.GetFileSizeStr((long)x); }; OlvFileType.AspectGetter = (x) => { return ((FTPop.RemoteFileInfo)x).IsDirectory ? "文件夹" : "文件"; }; OlvLastWriteTime.AspectGetter = (x) => { var item = (FTPop.RemoteFileInfo)x; if(item.Name=="." || item.Name == "..") { return "-"; } return item.LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss"); }; procUse = true; CbbMatch.SelectedIndex = 0; procUse = false; objectListView1.PrimarySortColumn = OlvFileType; objectListView1.PrimarySortOrder = SortOrder.Descending; objectListView1.SecondarySortColumn = OlvLastWriteTime; objectListView1.SecondarySortOrder = SortOrder.Descending; SetupDragAndDrop(); } private void SetupDragAndDrop() { // Drag and drop support // Indicate that the OLV can be used to drag items out. // You can write this code, or you can set IsSimpleDropSource to true (in the Designer). this.objectListView1.DragSource = new SimpleDragSource(); // Indicate that the OLV can be accept items being dropped on it. // These items could come from an ObjectListView or from some other control (or even // from another application). // If the drag source is an ObjectListView, you can listen for ModelCanDrop and // ModelDropped events, which have some extra properties to make your life easier. // If the drag source is not an ObjectListView, you have to listen for CanDrop and // Dropped events, and figure out everything for yourself. SimpleDropSink dropSink = new SimpleDropSink(); dropSink.CanDropOnItem = true; //dropSink.CanDropOnSubItem = true; dropSink.FeedbackColor = Color.IndianRed; // just to be different this.objectListView1.DropSink = dropSink; // For our purpose here, we will make it that if you drop one or more person // onto someone, they all become married. dropSink.ModelCanDrop += delegate (object sender, ModelDropEventArgs e) { FTPop.RemoteFileInfo file = e.TargetModel as FTPop.RemoteFileInfo; if (file == null) e.Effect = DragDropEffects.None; else { if (!file.IsDirectory) { e.Effect = DragDropEffects.None; e.InfoMessage = "不能拖放到文件"; } else e.Effect = DragDropEffects.Link; } }; dropSink.ModelDropped += delegate (object sender, ModelDropEventArgs e) { if (e.TargetModel == null) return; var item = (FTPop.RemoteFileInfo)e.TargetModel; var from_list = e.SourceModels; var del_list = new List(); if (GetFTP().IsOpen) { try { for (int i = 0; i < from_list.Count; i++) { var from_item = (FTPop.RemoteFileInfo)from_list[i]; var result = GetFTP().MoveFile(from_item.FullName, item.FullName+"/"+System.IO.Path.GetFileName(from_item.FullName)); if (result>=0) { del_list.Add(from_item); } else { MessageBox.Show("移动失败=>" + from_item.FullName, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } catch (Exception ex) { this.Invoke(new Action(() => { MessageBox.Show(ex.Message + "\r\n" + ex.Source, "出错", MessageBoxButtons.OK, MessageBoxIcon.Warning); })); } } objectListView1.RemoveObjects(del_list); }; TxtFtpPath.AllowDrop = true; TxtFtpPath.DragEnter += Form_DragEnter; TxtFtpPath.DragDrop += Form_DragDrop; } private void Form_DragDrop(object sender, DragEventArgs e) { string[] s = (string[])e.Data.GetData(DataFormats.FileDrop, false); List UploadList = new List(); for (int i = 0; i < s.Length; i++) { var uploadinfo = new UploadInfo() { FtpInfo =this.Cur_FTPInfo, RemotePath = CurFolder.TrimEnd('/')+"/"+System.IO.Path.GetFileName(s[i]), LocalPath = s[i] }; UploadList.Add(uploadinfo); } if (UploadList.Count > 0) { FrmUploadProg frm = new FrmUploadProg(); frm.UploadList.AddRange(UploadList); if (frm.ShowDialog() == DialogResult.OK) { 刷新列表ToolStripMenuItem.PerformClick(); //MessageBox.Show("上传成功。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("上传失败。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } frm.Dispose(); } } private void Form_DragEnter(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.FileDrop)) { e.Effect = DragDropEffects.All; } else { e.Effect = DragDropEffects.None; } } private int GetImageIndex(bool isDir,string ext) { string path; if(isDir) { path = System.Environment.SystemDirectory; if (imageListSmall.Images.ContainsKey("|folder")) return imageListSmall.Images.IndexOfKey("|folder"); try { imageListSmall.Images.Add("|folder", ShellUtilities.GetFileIcon(path, true, true)); return imageListSmall.Images.IndexOfKey("|folder"); } catch (ArgumentNullException) { return -1; } } else { if (imageListSmall.Images.ContainsKey(ext)) return imageListSmall.Images.IndexOfKey(ext); try { imageListSmall.Images.Add(ext, ShellUtilities.GetFileIcon(ext, true, true)); return imageListSmall.Images.IndexOfKey(ext); } catch (ArgumentNullException) { return -1; } } } public void TimedFilter(BrightIdeasSoftware.ObjectListView olv, string txt, int matchKind) { BrightIdeasSoftware.TextMatchFilter filter = null; if (!String.IsNullOrEmpty(txt)) { switch (matchKind) { case 0: default: filter = BrightIdeasSoftware.TextMatchFilter.Contains(olv, txt); break; case 1: filter = BrightIdeasSoftware.TextMatchFilter.Prefix(olv, txt); break; case 2: filter = BrightIdeasSoftware.TextMatchFilter.Regex(olv, txt); break; } } // Text highlighting requires at least a default renderer if (olv.DefaultRenderer == null) olv.DefaultRenderer = new BrightIdeasSoftware.HighlightTextRenderer(filter); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); olv.AdditionalFilter = filter; //olv.Invalidate(); stopWatch.Stop(); } private void FTPBrowser_Load(object sender, EventArgs e) { Resizes(); } private void TxtSearch_TextChanged2(object sender, EventArgs e) { TimedFilter(this.objectListView1, ((ryControls.TextBoxEx2)sender).Text, this.CbbMatch.SelectedIndex); } public int FTPId { get; set; } = 0; private bool IsRunning { get; set; } = false; public GameBackup3H3.DbOp.FTPInfo Cur_FTPInfo { get;private set; } private IFTP Cur_Ftp { get; set; } =null; private string Error_Msg { get; set; } = ""; private IFTP GetFTP() { if(Cur_Ftp==null || !Cur_Ftp.IsOpen) { var ftp = new FTPop.FTPWinSCP(); ftp.Open(Cur_FTPInfo); Error_Msg = ftp.ErrorMsg; Cur_Ftp = ftp; } return Cur_Ftp; } private void LoadFTPInfo(bool noLoadFiles=false) { if (IsRunning) { return; } IsRunning = true; TaskStartState(); Thread th = new Thread(Start); th.Start(); void Start() { #region 获取ftp信息 try { IDbInterface db = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType); if (db.ConnDb(Itrycn_Db.User_SQLConn) == 1) { DataSet ds = db.ReadData("select * from Ftp where Id=" + FTPId); if (ds.HaveData()) { //DirectoryInfo fileSystemInfo =new DirectoryInfo(""); //fileSystemInfo.GetFileSystemInfos() DataRow row = ds.Tables[0].Rows[0]; var FtpInfo = new GameBackup3H3.DbOp.FTPInfo() { Id = row["id"].ToInt(), Name = row["name"].ToString(), IP = row["ip"].ToString(), Port = row["port"].ToInt(), RemoteDir = row["remoteDir"].ToString(), UserName = row["username"].ToString(), Pwd = row["pwd"].ToString(), Encrypt = row["encrypt"].ToInt(0, 2, 0), AddTime = row["AddTime"].ToDateTime() }; Cur_FTPInfo = FtpInfo; if (!noLoadFiles) { CurFolder = FtpInfo.RemoteDir; if (CurFolder.Length == 0) { CurFolder = "/"; } this.Invoke(new Action(() => { TxtFtpPath.Text = CurFolder; })); var ftp = new FTPop.FTPWinSCP(); var opened = ftp.Open(FtpInfo); if (opened == 1) { Cur_Ftp = ftp; var result = ftp.ListDirectory(CurFolder, out var error); objectListView1.AddObjects(result); if(error.Length>0) { this.Invoke(new Action(() => { MessageBox.Show(error, "FTP错误", MessageBoxButtons.OK, MessageBoxIcon.Information); })); } } else { this.Invoke(new Action(() => { MessageBox.Show("FTP打开失败。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); })); } } } ds.Dispose(); } db.Free(); } catch (Exception ex) { } #endregion this.Invoke(new Action(() => { TaskEndState(); IsRunning = false; })); } } /// /// 初始化到指定目录 /// /// public void Init(string CurFolder) { LoadFTPInfo(true); if (CurFolder.Length == 0) { GotoDir("/"); } else { GotoDir(CurFolder); } } /// /// 初始化到指定目录 /// /// public void InitByNoFiles(string CurFolder) { LoadFTPInfo(true); this.CurFolder = CurFolder.Length==0?"/": CurFolder; TxtFtpPath.Text = this.CurFolder; objectListView1.Enabled = false; BtnUp.Enabled = false; BtnMustUpdate.Visible = true; } /// /// 初始化到默认目录 /// public void Init() { LoadFTPInfo(); } private void TaskStartState(bool clear=true) { label1.Text = "正在加载...."; PnlState.Visible = true; TxtSearch.Enabled = false; CbbMatch.Enabled = false; BtnUp.Enabled = false; objectListView1.Enabled = false; if (clear) objectListView1.ClearObjects(); objectListView1.AllColumns[0].Text = "文件名(" + objectListView1.GetItemCount() + ")"; } private void TaskEndState() { this.Invoke(new Action(() => { objectListView1.AllColumns[0].Text = "文件名(" + objectListView1.GetItemCount() + ")"; PnlState.Visible = false; objectListView1.Enabled = true; BtnUp.Enabled = true; TxtSearch.Enabled = true; CbbMatch.Enabled = true; })); } readonly bool procUse = false; private void CbbMatch_SelectedIndexChanged(object sender, EventArgs e) { if (procUse) { return; } TimedFilter(this.objectListView1, TxtSearch.Text, this.CbbMatch.SelectedIndex); } public string CurFolder { get; private set; } = ""; private void ObjectListView1_DoubleClick(object sender, EventArgs e) { var rfile = (FTPop.RemoteFileInfo)objectListView1.SelectedObjects[0]; if (rfile == null) { return; } if (rfile.IsDirectory) { if (CurFolder.TrimEnd('/').Length == 0) { CurFolder = rfile.Name == ".." ? "/" : (rfile.FullName); } else { if (rfile.Name == "..") { CurFolder = System.IO.Path.GetDirectoryName(CurFolder.TrimEnd('/')).Replace("\\", "/").Replace("//", "/"); } else { CurFolder = CurFolder.TrimEnd('/').Replace("\\", "/").Replace("//", "/") + "/" + rfile.Name; } } GotoDir(CurFolder); } else { if(rfile.Length>=1024*1024*10) { MessageBox.Show("大于10MB的FTP文件暂时不支持编辑。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (Itrycn_Db.WinSCP_IsRunning()) { MessageBox.Show("检测到外部FTP相关软件正在运行,建议关闭后编辑。", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error); } var siteinfo = new SiteInfo(); bool noedit = false; IDbInterface db = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType); if (db.ConnDb(Itrycn_Db.User_SQLConn) == 1) { siteinfo.FtpId = FTPId; DataSet ds_site = db.ReadData("select * from Site where FtpId=" + FTPId); if (ds_site.HaveData()) { for (int i = 0; i < ds_site.Tables[0].Rows.Count; i++) { DataRow reader = ds_site.Tables[0].Rows[i]; if(rfile.FullName.IndexOfEx(reader["ftpDir"].ToString())==0) { var local_file = reader["localPath"].ToString().Trim('\\')+"\\"+ rfile.FullName.Substring(reader["ftpDir"].ToString().Length).Trim('/'); if(System.IO.File.Exists(local_file)) { if(RyFiles.GetFileDate(local_file).LastWriteTime.ToInt64() > rfile.LastWriteTime.ToInt64()) { switch (MessageBox.Show("当前本地文件日期比服务器上的要新,是否要编辑服务器文件?", "询问", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2)) { case DialogResult.No: noedit = true; break; } } else if (RyFiles.GetFileDate(local_file).LastWriteTime.ToInt64() == rfile.LastWriteTime.ToInt64()) { if (RyFiles.GetFileSize(local_file) != rfile.Length) { switch (MessageBox.Show("当前本地文件与服务器文件日期一致,但大小不一致,是否要编辑服务器文件?\r\n\r\n本地:" + RyFiles.GetFileSizeStr(local_file) + "=>服务器:" + RyFiles.GetFileSizeStr(rfile.Length), "询问", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2)) { case DialogResult.No: noedit = true; break; } } } } siteinfo.Name = reader["name"].ToString(); siteinfo.LocalPath = reader["localPath"].ToString(); siteinfo.FtpDir = reader["ftpDir"].ToString(); siteinfo.Id = reader["Id"].ToInt(); break; } } } ds_site.Dispose(); } db.Free(); if(!noedit) _ = FrmMainEditor.MainEditor.OpenFTPFileByNewForm(siteinfo, rfile.FullName); } } private void GotoDir(string folder_path) { if (IsRunning) { return; } IsRunning = true; TaskStartState(); new Thread(Start).Start(); void Start() { IFTP ftp = GetFTP(); if (ftp.IsOpen) { this.Invoke(new Action(() => { TxtFtpPath.Text = folder_path; })); var result = ftp.ListDirectory(folder_path, out var error); this.Invoke(new Action(() => { objectListView1.AddObjects(result); })); if (error.Length > 0) { this.Invoke(new Action(() => { MessageBox.Show(error, "FTP错误", MessageBoxButtons.OK, MessageBoxIcon.Information); })); } else { } } else { this.Invoke(new Action(() => { MessageBox.Show("FTP打开失败=>"+ Error_Msg, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); })); } ftp.Close(); TaskEndState(); IsRunning = false; } } private void 重命名ToolStripMenuItem1_Click(object sender, EventArgs e) { FrmTitle frm = new FrmTitle(); frm.TxtTitle.Text = Text; frm.Text = "请输入重命名的名称"; if (frm.ShowDialog() == DialogResult.OK) { Text = frm.TxtTitle.Text; } frm.Dispose(); } private void 刷新列表ToolStripMenuItem_Click(object sender, EventArgs e) { GotoDir(CurFolder); } private void FrmFTPBrowser_FormClosing(object sender, FormClosingEventArgs e) { if (IsRunning) { e.Cancel = true; } } private void FrmFTPBrowser_ResizeEnd(object sender, EventArgs e) { } private void Resizes() { BtnMustUpdate.Left = objectListView1.Left + (objectListView1.Width - BtnMustUpdate.Width) / 2; BtnMustUpdate.Top = objectListView1.Top + (objectListView1.Height - BtnMustUpdate.Height) / 2; PnlState.Left = objectListView1.Left; PnlState.Width = objectListView1.Width; } private void BtnMustUpdate_Click(object sender, EventArgs e) { if(Itrycn_Db.WinSCP_IsRunning()) { MessageBox.Show("外部FTP软件正在运行,部分功能将不可用", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); } BtnUp.Enabled = true; objectListView1.Enabled = true; BtnMustUpdate.Visible = false; 刷新列表ToolStripMenuItem.PerformClick(); } private void FrmFTPBrowser_SizeChanged(object sender, EventArgs e) { Resizes(); } private void ObjectListView1_SelectionChanged(object sender, EventArgs e) { var rfile = (FTPop.RemoteFileInfo)objectListView1.SelectedObject; label6.ForeColor = Color.Black; label7.Visible = false; if (rfile == null) { label5.Text = "无"; label6.Text = "无"; return; } if (rfile.Name == "." || rfile.Name == "..") { label5.Text = "无"; label6.Text = "无"; return; } IDbInterface db = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType); if (db.ConnDb(Itrycn_Db.User_SQLConn) == 1) { DataSet ds_site = db.ReadData("select * from Site where FtpId=" + FTPId); if (ds_site.HaveData()) { for (int i = 0; i < ds_site.Tables[0].Rows.Count; i++) { DataRow reader = ds_site.Tables[0].Rows[i]; if (rfile.FullName.IndexOfEx(reader["ftpDir"].ToString()) == 0) { var local_file = reader["localPath"].ToString().Trim('\\') + "\\" + rfile.FullName.Substring(reader["ftpDir"].ToString().Length).Trim('/').Replace("/","\\"); string file_dt; if (System.IO.Directory.Exists(local_file)) { label5.Text = "不支持文件夹"; file_dt = "[本地]" + RyFiles.GetFileDate(local_file).LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss"); } else if (System.IO.File.Exists(local_file)) { var local_filesize = RyFiles.GetFileSize(local_file); var local_filetime =RyFiles.GetFileDate(local_file).LastWriteTime; if (local_filetime.ToInt64() > rfile.LastWriteTime.ToInt64()) { label7.ForeColor = Color.Red; label7.Text = "本地文件比较新"; label7.Visible = true; label6.ForeColor = Color.Red; } else if (local_filetime.ToInt64() < rfile.LastWriteTime.ToInt64()) { label7.ForeColor = Color.Blue; label7.Text = "FTP文件比较新"; label7.Visible = true; label6.ForeColor = Color.Blue; } else if (local_filetime.ToInt64() == rfile.LastWriteTime.ToInt64()) { if(local_filesize!= rfile.Length) { label7.ForeColor = Color.Red; label7.Text = "本地与FTP文件时间一致,但大小不一致"; } else { label7.ForeColor = Color.Black; label7.Text = "本地与FTP文件时间一致"; } label7.Visible = true; label6.ForeColor = Color.Black; } string start_size_str; if(local_filesize>rfile.Length) { start_size_str = "本地大"; } else if (local_filesize == rfile.Length) { start_size_str = "一样大"; } else { start_size_str = "远程大"; } label5.Text = "[本地]"+RyFiles.GetFileSizeStr(local_filesize) + "=>[远程]" + RyFiles.GetFileSizeStr(rfile.Length)+ "["+start_size_str+"]"; file_dt = "[本地]" + local_filetime.ToString("yyyy-MM-dd HH:mm:ss"); } else { label5.Text = "[本地]无=>[远程]" + RyFiles.GetFileSizeStr(rfile.Length); file_dt = "[本地]无"; } label6.Text = file_dt + "=>\r\n[远程]" + rfile.LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss"); break; } } } ds_site.Dispose(); } db.Free(); } private void 打开同位置本地文件ToolStripMenuItem_Click(object sender, EventArgs e) { var rfile = (FTPop.RemoteFileInfo)objectListView1.SelectedObject; if (rfile == null) { if(objectListView1.SelectedObjects.Count>1) { MessageBox.Show("无法打开多个。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } return; } if (rfile.Name == "." || rfile.Name == "..") { return; } bool noedit = false; IDbInterface db = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType); if (db.ConnDb(Itrycn_Db.User_SQLConn) == 1) { DataSet ds_site = db.ReadData("select * from Site where FtpId=" + FTPId); if (ds_site.HaveData()) { for (int i = 0; i < ds_site.Tables[0].Rows.Count; i++) { DataRow reader = ds_site.Tables[0].Rows[i]; if (rfile.FullName.IndexOfEx(reader["ftpDir"].ToString()) == 0) { var local_file = reader["localPath"].ToString().Trim('\\') + "\\" + rfile.FullName.Substring(reader["ftpDir"].ToString().Length).Trim('/').Replace("/","\\"); if (System.IO.File.Exists(local_file)) { if (RyFiles.GetFileDate(local_file).LastWriteTime.ToInt64() < rfile.LastWriteTime.ToInt64()) { switch (MessageBox.Show("当前本地文件日期比服务器上的要老,是否要编辑本地文件?", "询问", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2)) { case DialogResult.No: noedit = true; break; } } else if (RyFiles.GetFileDate(local_file).LastWriteTime.ToInt64() ==rfile.LastWriteTime.ToInt64()) { if(RyFiles.GetFileSize(local_file)!=rfile.Length) { switch (MessageBox.Show("当前本地文件与服务器文件日期一致,但大小不一致,是否要编辑本地文件?\r\n\r\n本地:"+RyFiles.GetFileSizeStr(local_file)+"=>服务器:"+ RyFiles.GetFileSizeStr(rfile.Length), "询问", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2)) { case DialogResult.No: noedit = true; break; } } } if (!noedit) { FrmMainEditor.MainEditor.OpenFile(local_file); } } else if (System.IO.Directory.Exists(local_file)) { RyFiles.OpenFile(local_file); } else { MessageBox.Show("无法找到对应文件。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } break; } } } ds_site.Dispose(); } db.Free(); } public void UpdateFileInfo() { ObjectListView1_SelectionChanged(objectListView1, EventArgs.Empty); } public void UpdateFileInfo(string path,DateTime LastWriteTime,long FileSize) { var mpath = "/"+path.ToLower().TrimStart('/'); if(objectListView1.SelectedObject!=null) { var obj = (FTPop.RemoteFileInfo)objectListView1.SelectedObject; if (obj.FullName.ToLower() == mpath) { obj.LastWriteTime = LastWriteTime; obj.Length = FileSize; objectListView1.RefreshObject(obj); ObjectListView1_SelectionChanged(objectListView1, EventArgs.Empty); return; } } for (int i = 0; i < objectListView1.ObjectsList.Count; i++) { var item = (FTPop.RemoteFileInfo)objectListView1.ObjectsList[i]; if (item.FullName.ToLower() == mpath) { item.LastWriteTime = LastWriteTime; item.Length = FileSize; objectListView1.RefreshObject(item); if(item==objectListView1.SelectedObject) { ObjectListView1_SelectionChanged(objectListView1, EventArgs.Empty); } return; } } } private void 查看历史记录ToolStripMenuItem_Click(object sender, EventArgs e) { var rfile = (FTPop.RemoteFileInfo)objectListView1.SelectedObject; if (rfile == null) { return; } if (rfile.Name == "." || rfile.Name == "..") { return; } UploadInfo uploadinfo = null; IDbInterface db = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType); if (db.ConnDb(Itrycn_Db.User_SQLConn) == 1) { DataSet ds = db.ReadData("select * from Ftp where Id=" + FTPId); if (ds.HaveData()) { DataRow row = ds.Tables[0].Rows[0]; var FtpInfo = new GameBackup3H3.DbOp.FTPInfo() { Id = row["id"].ToInt(), Name = row["name"].ToString(), IP = row["ip"].ToString(), Port = row["port"].ToInt(), RemoteDir ="/", UserName = row["username"].ToString(), Pwd = row["pwd"].ToString(), Encrypt = row["encrypt"].ToInt(0, 2, 0), AddTime = row["AddTime"].ToDateTime() }; uploadinfo = new UploadInfo() { FtpInfo = FtpInfo, RemotePath = rfile.FullName, LocalPath = Application.StartupPath + "\\UserDb\\tmp\\FTP\\" + rfile.Name }; } ds.Dispose(); } db.Free(); if (uploadinfo == null) { return; } RyFiles.DeleteFile(uploadinfo.LocalPath); FrmDownProg frm = new FrmDownProg(); frm.DownList.Add(uploadinfo); if (frm.ShowDialog() == DialogResult.OK) { LexerType CurHighliteLang; try { var LexerType = VPKSoft.ScintillaLexers.HelperClasses.LexerFileExtensions.LexerTypeFromFileName(uploadinfo.LocalPath); CurHighliteLang = LexerType; } catch { CurHighliteLang = LexerType.Unknown; } FrmHistoryView frm2 = new FrmHistoryView { FilePath = "[FTP:"+FTPId+"]" +rfile.FullName, Content =RyFiles.ReadAllText(uploadinfo.LocalPath), CurHighliteLang = CurHighliteLang, SelectModeOn = true, TopMost = this.TopMost }; frm2.ShowDialog(); frm2.Dispose(); RyFiles.DeleteFile(uploadinfo.LocalPath); } frm.Dispose(); } private void ObjectListView1_BeforeSorting(object sender, BeforeSortingEventArgs e) { } private void BtnUp_Click(object sender, EventArgs e) { if (BtnMustUpdate.Visible) { return; } BtnUp.Enabled = false; objectListView1.Enabled = false; if (CurFolder.TrimEnd('/').Length == 0) { CurFolder = "/"; } else { CurFolder = System.IO.Path.GetDirectoryName(CurFolder.TrimEnd('/')).Replace("\\", "/").Replace("//", "/"); } GotoDir(CurFolder); BtnUp.Enabled = true; objectListView1.Enabled = true; } private void 下载选定文件到对应目录ToolStripMenuItem_Click(object sender, EventArgs e) { var list = objectListView1.SelectedObjects; if (list.Count == 0) { return; } if(list.Count>15) { MessageBox.Show("你选中了"+ list.Count+"项,即将进行下载。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } List DownList = new List(); IDbInterface db = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType); if (db.ConnDb(Itrycn_Db.User_SQLConn) == 1) { if (Cur_FTPInfo != null) { DataSet ds_site = db.ReadData("select * from Site where FtpId=" + FTPId); if (ds_site.HaveData()) { for (int r = 0; r < list.Count; r++) { var rfile = (FTPop.RemoteFileInfo)list[r]; if (rfile == null) { continue; } if (rfile.Name == "." || rfile.Name == "..") { continue; } for (int i = 0; i < ds_site.Tables[0].Rows.Count; i++) { DataRow reader = ds_site.Tables[0].Rows[i]; if (rfile.FullName.IndexOfEx(reader["ftpDir"].ToString()) == 0) { var canReplace = true; var local_file = reader["localPath"].ToString().Trim('\\') + "\\" + rfile.FullName.Substring(reader["ftpDir"].ToString().Length).Trim('/').Replace("/", "\\"); if (System.IO.File.Exists(local_file)) { if (RyFiles.GetFileDate(local_file).LastWriteTime.ToInt64() >rfile.LastWriteTime.ToInt64()) { switch (MessageBox.Show("当前服务器上的文件日期比本地的要旧,是否要替换?\r\n"+ local_file, "询问", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2)) { case DialogResult.No: canReplace = false; break; } } else if (RyFiles.GetFileDate(local_file).LastWriteTime.ToInt64() == rfile.LastWriteTime.ToInt64()) { if (RyFiles.GetFileSize(local_file) != rfile.Length) { switch (MessageBox.Show("当前本地文件与服务器文件日期一致,但大小不一致,是否要替换?\r\n"+ local_file + "\r\n\r\n本地:" + RyFiles.GetFileSizeStr(local_file) + "=>服务器:" + RyFiles.GetFileSizeStr(rfile.Length), "询问", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2)) { case DialogResult.No: canReplace = false; break; } } } } else if (System.IO.Directory.Exists(local_file)) { canReplace = false; } if (canReplace) { DownList.Add(new UploadInfo() { FtpInfo = Cur_FTPInfo, RemotePath = rfile.FullName, LocalPath = local_file }); } break; } } } } ds_site.Dispose(); } } db.Free(); if(DownList.Count==0) { MessageBox.Show("当前选中的文件无法在本地找到对应目录。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } FrmDownProg frm = new FrmDownProg(); frm.DownList.AddRange(DownList); if (frm.ShowDialog() == DialogResult.OK) { if (DownList.Count == list.Count) { MessageBox.Show("全部下载成功。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("选中"+list.Count+"项,下载成功"+DownList.Count+"项。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } frm.Dispose(); if (DownList.Count > 0) { foreach (IDockContent document in FrmMainEditor.MainEditor.DockPanel.DocumentsToArray()) { // IMPORANT: dispose all panes. if (document is FrmFileBrowser_New frm2) { if (frm2.CurFolderPath.ToLower().Trim('\\') ==System.IO.Path.GetDirectoryName(DownList[0].LocalPath).ToLower().Trim('\\')) { frm2.GotoPath(System.IO.Path.GetDirectoryName(DownList[0].LocalPath), DownList[0].LocalPath); } } } } } private void 删除选定文件ToolStripMenuItem_Click(object sender, EventArgs e) { var list = objectListView1.SelectedObjects; if (list.Count == 0) { return; } if (list.Count == 1) { switch (MessageBox.Show("确定要删除 " + ((FTPop.RemoteFileInfo)list[0]).Name + " ?这将不可恢复?", "询问", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2)) { case DialogResult.No: return; } } else { switch (MessageBox.Show("确定要删除选定的 " + list.Count + "项 FTP文件?这将不可恢复?", "询问", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2)) { case DialogResult.No: return; } } if (IsRunning) { return; } IsRunning = true; TaskStartState(false); new Thread(Start).Start(); void Start() { this.Invoke(new Action(() => { label1.Text = "正在加载FTP...."; })); if (GetFTP().IsOpen) { var error = 0; var remove_list = new List(); for (int i = 0; i < list.Count; i++) { var rfile = (FTPop.RemoteFileInfo)list[i]; if(rfile.Name=="." || rfile.Name == "..") { continue; } this.Invoke(new Action(() => { label1.Text = "正在删除第"+(i+1)+"个文件...."; })); try { if (GetFTP().DelFile(rfile.FullName) < 0) { error++; } else { remove_list.Add(rfile); } }catch(Exception ex) { this.Invoke(new Action(() => { MessageBox.Show(ex.Message+"\r\n"+ex.Source, "出错", MessageBoxButtons.OK, MessageBoxIcon.Warning); })); error++; } } this.Invoke(new Action(() => { objectListView1.RemoveObjects(remove_list); })); if(error>0) { this.Invoke(new Action(() => { MessageBox.Show("删除时有"+error+"项失败。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); })); } } else { this.Invoke(new Action(() => { MessageBox.Show("FTP打开失败。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); })); } TaskEndState(); IsRunning = false; } } private void 重命名ToolStripMenuItem_Click(object sender, EventArgs e) { } private void ObjectListView1_CellEditFinished(object sender, CellEditEventArgs e) { if (!e.Cancel) { var item = (FTPop.RemoteFileInfo)e.RowObject; var new_filename = e.NewValue.ToString(); if (new_filename == e.Value.ToString()) { return; } if (RyFiles.IsValidFileName(new_filename)) { if (IsRunning) { return; } IsRunning = true; TaskStartState(false); new Thread(Start).Start(); void Start() { this.Invoke(new Action(() => { label1.Text = "正在加载FTP...."; })); if (GetFTP().IsOpen) { try { var result = GetFTP().MoveFile(item.FullName, System.IO.Path.GetDirectoryName(item.FullName) + "/" + new_filename); if(result>0) { item.FullName = System.IO.Path.GetDirectoryName(item.FullName) + "/" + new_filename; item.Name = new_filename; this.Invoke(new Action(() => { objectListView1.RefreshObject(item); })); } } catch (Exception ex) { this.Invoke(new Action(() => { MessageBox.Show(ex.Message + "\r\n" + ex.Source, "出错", MessageBoxButtons.OK, MessageBoxIcon.Warning); })); } } else { this.Invoke(new Action(() => { MessageBox.Show("FTP打开失败。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); })); } TaskEndState(); IsRunning = false; } } } } private void 复制选定文件名ToolStripMenuItem_Click(object sender, EventArgs e) { var list = objectListView1.SelectedObjects; if (list.Count == 0) { return; } var txt = ""; for (int i = 0; i < list.Count; i++) { var rfile = (FTPop.RemoteFileInfo)list[i]; if (rfile.Name == "." || rfile.Name == "..") { continue; } if (txt.Length > 0) { txt += "\r\n"; } txt+= rfile.Name; } RyFiles.CopyToClip(txt); } private void TxtFtpPath_KeyDown(object sender, KeyEventArgs e) { if(e.KeyCode==Keys.Enter) { if (BtnMustUpdate.Visible) { objectListView1.Enabled = true; BtnMustUpdate.Visible = false; } if (TxtFtpPath.Text.TrimEnd('/').Length == 0) { CurFolder = "/"; } else { CurFolder = TxtFtpPath.Text.TrimEnd('/').Replace("\\", "/").Replace("//", "/"); } BtnUp.Enabled = false; objectListView1.Enabled = false; GotoDir(CurFolder); BtnUp.Enabled = true; objectListView1.Enabled = true; } } } }