private void listView1_SelectedIndexChanged(object sender, EventArgs e) { int count = listView2.SelectedItems.Count; SetContentMenuItem(count == 0); if (count == 1) { SetContentMenuItem2(true); ListViewItem row = listView2.SelectedItems[0]; ChannelSftp.LsEntry entry = (ChannelSftp.LsEntry)row.Tag; if (entry.getAttrs().isDir()) { openToolStripMenuItem.Visible = true; editToolStripMenuItem.Visible = false; } else { openToolStripMenuItem.Visible = false; editToolStripMenuItem.Visible = true; } } else if (count > 1) { SetContentMenuItem2(false); } }
public void Set(string dataPath, string urlPath, ChannelSftp.LsEntry entry) { urlPath = _convertPath(urlPath); _config[urlPath] = entry.getAttrs().getMTime().ToString(CultureInfo.InvariantCulture); var dest = _convertLocalPath(urlPath); GrfPath.CreateDirectoryFromFile(dest); GrfPath.Delete(dest); File.Copy(dataPath, dest); }
private void FileAttrForm_Load(object sender, EventArgs e) { this.Text = file.getFilename() + " 的属性"; if (file.getAttrs().isDir()) { text_type.Text = "文件夹"; icon.BackgroundImage = Properties.Resources.folder_64px; } else { text_type.Text = getFileExt(file.getFilename()); icon.Image = Properties.Resources.filen_64px; } text_name.Text = file.getFilename(); text_size.Text = Utils.getFileSize(file.getAttrs().getSize()); text_host.Text = user.Host; text_location.Text = dir + file.getFilename(); text_modified.Text = file.getAttrs().getMtimeString(); text_owner.Text = getFileOwner(file.getLongname(), 3); text_group.Text = getFileOwner(file.getLongname(), 4); text_permiss.Text = file.getAttrs().getPermissionsString(); }
public bool Exists(string path, ChannelSftp.LsEntry entry) { path = _convertPath(path); var result = _config[path, null]; if (String.IsNullOrEmpty(result)) { return(false); } var timeLocal = Int32.Parse(result); var timeSource = entry.getAttrs().getMTime(); if (timeLocal != timeSource) { return(false); } return(true); }
private void listView2_MouseDoubleClick(object sender, MouseEventArgs e) { if (listView2.SelectedItems.Count > 0) { ListViewItem row = listView2.SelectedItems[0]; ChannelSftp.LsEntry entry = (ChannelSftp.LsEntry)row.Tag; if (entry.getAttrs().isDir()) { if (entry.getFilename() == "..") { // 上一层 OpenUpDir(); } else { // 进入下一层 OpenDownDir(getCurrDir() + entry.getFilename()); } } } }
private void editToolStripMenuItem_Click(object sender, EventArgs e) { if (listView2.SelectedItems.Count > 0) { ListViewItem row = listView2.SelectedItems[0]; ChannelSftp.LsEntry entry = (ChannelSftp.LsEntry)row.Tag; if (!entry.getAttrs().isDir()) { try { string resfile = getCurrDir() + entry.getFilename(); string targetfile = MainForm.TEMP_DIR + string.Format("{0}.file", DateTime.Now.ToString("MMddHHmmss")); targetfile = targetfile.Replace("\\", "/"); TextEditorForm editor = new TextEditorForm(); editor.Show(this); editor.LoadRemoteFile(new ShellForm(this), resfile, targetfile); } catch { } } } }
private void renameToolStripMenuItem_Click(object sender, EventArgs e) { int count = listView2.SelectedItems.Count; if (count > 0) { ListViewItem row = listView2.SelectedItems[0]; if (row != null) { string oldName = row.Text; ChannelSftp.LsEntry entry = (ChannelSftp.LsEntry)row.Tag; string msg = "请输入文件夹的新名称"; if (!entry.getAttrs().isDir()) { msg = "请输入文件的新名称"; } InputForm form = new InputForm(msg, oldName, new InputForm.FormResult((newName) => { if (oldName != newName) { string dirs = getCurrDir(); string path1 = dirs + Utils.getLinuxName(oldName); string path2 = dirs + Utils.getLinuxName(newName); SendShell(string.Format("mv {0} {1}", path1, path2)); ThreadPool.QueueUserWorkItem((a) => { Thread.Sleep(500); RefreshFiles(); }); } })); form.ShowDialog(this); } } }
public void LoadDirFilesToListView(string path, LoadFilesResult result = null) { this.BeginInvoke((MethodInvoker) delegate() { try { if (null == sftpChannel) { return; } ArrayList files = sftpChannel.ls(path); if (files != null) { ChannelSftp.LsEntry file = null; listView2.Items.Clear(); LargeImages.Images.Clear(); SmallImages.Images.Clear(); LargeImages.Images.Add(Properties.Resources.filen_64px); LargeImages.Images.Add(Properties.Resources.folder_64px); SmallImages.Images.Add(Properties.Resources.filen_16px); SmallImages.Images.Add(Properties.Resources.folder_16px); ListViewItem item = null; ListViewItem.ListViewSubItem subItem = null; List <ListViewItem> itemList = new List <ListViewItem>(); for (int i = 0; i < files.Count; i++) { object obj = files[i]; if (obj is ChannelSftp.LsEntry) { file = (ChannelSftp.LsEntry)obj; if (file.getFilename() == ".") { continue; } item = new ListViewItem(); item.Text = file.getFilename(); item.Tag = file; if (file.getFilename() != "..") { subItem = new ListViewItem.ListViewSubItem(); subItem.Text = Utils.getFileSize(file.getAttrs().getSize()); item.SubItems.Add(subItem); subItem = new ListViewItem.ListViewSubItem(); subItem.Text = file.getAttrs().isDir() ? "文件夹" : file.getAttrs().isLink() ? "快捷方式" : getFileExt(file.getFilename()); item.SubItems.Add(subItem); subItem = new ListViewItem.ListViewSubItem(); subItem.Text = file.getAttrs().getMtimeString(); item.SubItems.Add(subItem); subItem = new ListViewItem.ListViewSubItem(); subItem.Text = file.getAttrs().getPermissionsString(); item.SubItems.Add(subItem); subItem = new ListViewItem.ListViewSubItem(); subItem.Text = getFileOwner(file.getLongname()); item.SubItems.Add(subItem); item.ImageIndex = file.getAttrs().isDir() ? 1 : 0; if (file.getAttrs().isDir()) { listView2.Items.Add(item); } else { itemList.Add(item); } } else { subItem = new ListViewItem.ListViewSubItem(); subItem.Text = ""; item.SubItems.Add(subItem); subItem = new ListViewItem.ListViewSubItem(); subItem.Text = ""; item.SubItems.Add(subItem); subItem = new ListViewItem.ListViewSubItem(); subItem.Text = ""; item.SubItems.Add(subItem); subItem = new ListViewItem.ListViewSubItem(); subItem.Text = ""; item.SubItems.Add(subItem); subItem = new ListViewItem.ListViewSubItem(); subItem.Text = ""; item.SubItems.Add(subItem); item.ImageIndex = 1; listView2.Items.Add(item); } } } foreach (ListViewItem item2 in itemList) { listView2.Items.Add(item2); } if (null != result) { result(); } } else { MessageBox.Show(this, "目录不存在", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception e) { logger.Error("加载数据失败:" + e.Message, e); if (!success) { sftpForm.CloseTab(this); } } }); }