NtStatus IDokanOperations.FindFiles(string fileName, out IList <FileInformation> files, DokanFileInfo info) { SftpDrive drive = this.GetDriveByMountPoint(fileName, out fileName); LogFSActionError("FindFiles", fileName, drive, "!? not using FindFilesWithPattern !?"); if (drive != null) { return(GetSubSystemOperations(drive).FindFiles(fileName, out files, info)); } //this shoud be never called files = new List <FileInformation>(); string path = fileName.Substring(1);//cut leading \ foreach (SftpDrive subdrive in _subsytems) { string mp = subdrive.MountPoint; // mp1 || mp1\mp2 ... if (path.Length > 0) //not root dir { if (path == mp) //this shoud not happend, because is managed by drive { Log("Error, mountpoint not in drives?"); break; } if (mp.IndexOf(path + '\\') == 0) //path is part of mount point =>implies=> length of path>mp { mp = mp.Substring(path.Length + 1); //cut the path } else { continue; } } int cuttmp = mp.IndexOf('\\'); if (cuttmp > 0) // have submountpoint like mp1\mp2 { mp = mp.Substring(0, cuttmp); } if (!files.Select(file => file.FileName).Contains(mp) && mp != "") { FileInformation fi = new FileInformation(); fi.FileName = mp; fi.Attributes = FileAttributes.NotContentIndexed | FileAttributes.Directory | FileAttributes.ReparsePoint | FileAttributes.Offline; fi.CreationTime = DateTime.Now; fi.LastWriteTime = DateTime.Now; fi.LastAccessTime = DateTime.Now; files.Add(fi); } } return(NtStatus.Success); }
NtStatus IDokanOperations.CreateFile(string fileName, FileAccess access, FileShare share, FileMode mode, FileOptions options, FileAttributes attributes, IDokanFileInfo info) { if (info.IsDirectory) { if (mode == FileMode.Open) { return(OpenDirectory(fileName, info)); } if (mode == FileMode.CreateNew) { return(CreateDirectory(fileName, info)); } return(NtStatus.NotImplemented); } if (fileName.EndsWith("desktop.ini", StringComparison.OrdinalIgnoreCase) || fileName.EndsWith("autorun.inf", StringComparison.OrdinalIgnoreCase)) { return(NtStatus.NoSuchFile); } SftpDrive drive = this.GetDriveByMountPoint(fileName, out fileName); LogFSActionInit("OpenFile", fileName, drive, "Mode:{0}", mode); if (drive != null) { LogFSActionSuccess("OpenFile", fileName, drive, "Mode:{0} NonVFS", mode); IDokanOperations idops = GetSubSystemOperations(drive); return(idops?.CreateFile(fileName, access, share, mode, options, attributes, info) ?? NtStatus.AccessDenied); //AccessDenied happens if mounting failed } //check against mountpoints if virtual dir exists string path = fileName.Substring(1); if (path == "") { //info.IsDirectory = true; info.Context = null; LogFSActionSuccess("OpenFile", fileName, null, "VFS root"); return(NtStatus.Success); } foreach (var drive2 in this._subsytems.Where(drive2 => drive2.MountPoint.Length > 0) .Where(drive2 => drive2.MountPoint.IndexOf(path) == 0)) { info.IsDirectory = true; info.Context = drive2; LogFSActionSuccess("OpenFile", fileName, drive2, "VFS (sub)mountpoint"); return(NtStatus.Success); } //pathnotfound detection? LogFSActionError("OpenFile", fileName, null, "File not found"); return(NtStatus.NoSuchFile); }
internal void RemoveSubFS(SftpDrive sftpDrive) { _drives.Remove(sftpDrive); if (_filesystem != null) { _filesystem.RemoveSubFS(sftpDrive); } }
NtStatus IDokanOperations.UnlockFile(string fileName, long offset, long length, IDokanFileInfo info) { SftpDrive drive = this.GetDriveByMountPoint(fileName, out fileName); return(drive != null ? GetSubSystemOperations(drive).UnlockFile(fileName, offset, length, info) : NtStatus.AccessDenied); }
internal void AddSubFS(SftpDrive sftpDrive) { _drives.Add(sftpDrive); if (_filesystem != null) { _filesystem.AddSubFS(sftpDrive); } }
private NtStatus OpenDirectory(string fileName, IDokanFileInfo info) { SftpDrive drive = this.GetDriveByMountPoint(fileName, out fileName); LogFSActionInit("OpenDir", fileName, drive, ""); if (drive != null) { lastActiveSubsytem = drive; IDokanOperations ops = GetSubSystemOperations(drive); if (ops == null) { LogFSActionError("OpenDir", fileName, drive, "Cannot open, mount failed?"); return(NtStatus.AccessDenied); } LogFSActionSuccess("OpenDir", fileName, drive, "Found, subsytem"); return(ops.CreateFile(fileName, FileAccess.GenericRead, FileShare.None, FileMode.Open, FileOptions.None, FileAttributes.Directory, info)); } if (fileName.Length == 1) //root dir { LogFSActionSuccess("OpenDir", fileName, drive, "Found, VFS root"); info.IsDirectory = true; return(NtStatus.Success); } //root test should keep lastactive if drag and drop(win8) lastActiveSubsytem = null; string path = fileName.Substring(1); //cut leading \ foreach (SftpDrive subdrive in _subsytems) { string mp = subdrive.MountPoint; // mp1 || mp1\mp2 ... if (path == mp) { info.Context = subdrive; info.IsDirectory = true; LogFSActionSuccess("OpenDir", fileName, drive, "Found, final mountpoint"); return(NtStatus.Success); } if (mp.IndexOf(path + '\\') == 0) { //path is part of mount point info.Context = subdrive; info.IsDirectory = true; LogFSActionSuccess("OpenDir", fileName, drive, "Found, part of mountpoint"); return(NtStatus.Success); } } LogFSActionError("OpenDir", fileName, drive, "Path not found"); return(NtStatus.ObjectPathNotFound); }
NtStatus IDokanOperations.SetAllocationSize(string fileName, long length, IDokanFileInfo info) { Log("VFS SetSize"); SftpDrive drive = this.GetDriveByMountPoint(fileName, out fileName); return(drive != null ? GetSubSystemOperations(drive).SetAllocationSize(fileName, length, info) : NtStatus.AccessDenied); }
NtStatus IDokanOperations.DeleteDirectory(string fileName, IDokanFileInfo info) { Log("VFS DeleteDirectory:{0}", fileName); SftpDrive drive = this.GetDriveByMountPoint(fileName, out fileName); return(drive != null ? GetSubSystemOperations(drive).DeleteDirectory(fileName, info) : NtStatus.AccessDenied); }
NtStatus IDokanOperations.SetFileTime(string fileName, DateTime?creationTime, DateTime?lastAccessTime, DateTime?lastWriteTime, IDokanFileInfo info) { SftpDrive drive = this.GetDriveByMountPoint(fileName, out fileName); return(drive != null ? GetSubSystemOperations(drive).SetFileTime(fileName, creationTime, lastAccessTime, lastWriteTime, info) : NtStatus.AccessDenied); }
NtStatus IDokanOperations.SetFileAttributes(string fileName, FileAttributes attributes, IDokanFileInfo info) { Log("VFS TrySetAttributes:{0}\n{1};", fileName, attributes); SftpDrive drive = this.GetDriveByMountPoint(fileName, out fileName); return(drive != null ? GetSubSystemOperations(drive).SetFileAttributes(fileName, attributes, info) : NtStatus.AccessDenied); }
NtStatus IDokanOperations.SetFileSecurity(string fileName, FileSystemSecurity security, AccessControlSections sections, IDokanFileInfo info) { Log("VFS TrySetSecurity:{0}", fileName); SftpDrive drive = this.GetDriveByMountPoint(fileName, out fileName); return(drive != null ? GetSubSystemOperations(drive).SetFileSecurity(fileName, security, sections, info) : NtStatus.AccessDenied); }
NtStatus IDokanOperations.SetEndOfFile(string fileName, long length, DokanFileInfo info) { SftpDrive drive = this.GetDriveByMountPoint(fileName, out fileName); if (drive != null) { return(GetSubSystemOperations(drive).SetEndOfFile(fileName, length, info)); } return(NtStatus.AccessDenied); }
DokanError IDokanOperations.UnlockFile(string fileName, long offset, long length, DokanFileInfo info) { SftpDrive drive = this.GetDriveByMountPoint(fileName, out fileName); if (drive != null) { return(GetSubSystemOperations(drive).UnlockFile(fileName, offset, length, info)); } return(DokanError.ErrorAccessDenied); }
DokanError IDokanOperations.CreateFile(string fileName, FileAccess access, FileShare share, FileMode mode, FileOptions options, FileAttributes attributes, DokanFileInfo info) { if (fileName.EndsWith("desktop.ini", StringComparison.OrdinalIgnoreCase) || fileName.EndsWith("autorun.inf", StringComparison.OrdinalIgnoreCase)) //.... { return(DokanError.ErrorFileNotFound); } SftpDrive drive = this.GetDriveByMountPoint(fileName, out fileName); LogFSActionInit("OpenFile", fileName, drive, "Mode:{0}", mode); if (drive != null) { LogFSActionSuccess("OpenFile", fileName, drive, "Mode:{0} NonVFS", mode); IDokanOperations idops = GetSubSystemOperations(drive); if (idops == null) { //this happens if mounting failed return(DokanError.ErrorAccessDenied); } return(idops.CreateFile(fileName, access, share, mode, options, attributes, info)); } //check against mountpoints if virtual dir exists string path = fileName.Substring(1); if (path == "") { info.IsDirectory = true; info.Context = null; LogFSActionSuccess("OpenFile", fileName, null, "VFS root"); return(DokanError.ErrorSuccess); } foreach (SftpDrive drive2 in this._subsytems) { if (drive2.MountPoint.Length > 0) { if (drive2.MountPoint.IndexOf(path) == 0) { info.IsDirectory = true; info.Context = drive2; LogFSActionSuccess("OpenFile", fileName, drive2, "VFS (sub)mountpoint"); return(DokanError.ErrorSuccess); } } } //pathnotfound detection? LogFSActionError("OpenFile", fileName, null, "File not found"); return(DokanError.ErrorFileNotFound); }
DokanError IDokanOperations.DeleteFile(string fileName, DokanFileInfo info) { SftpDrive drive = this.GetDriveByMountPoint(fileName, out fileName); if (drive != null) { return(GetSubSystemOperations(drive).DeleteFile(fileName, info)); } return(DokanError.ErrorAccessDenied); }
NtStatus IDokanOperations.FlushFileBuffers(string fileName, DokanFileInfo info) { SftpDrive drive = this.GetDriveByMountPoint(fileName, out fileName); if (drive != null) { return(GetSubSystemOperations(drive).FlushFileBuffers(fileName, info)); } return(NtStatus.Success); }
private NtStatus CreateDirectory(string fileName, DokanFileInfo info) { SftpDrive drive = this.GetDriveByMountPoint(fileName, out fileName); if (drive != null) { return(GetSubSystemOperations(drive).CreateFile(fileName, FileAccess.GenericRead, FileShare.None, FileMode.CreateNew, FileOptions.None, FileAttributes.Directory, info)); } return(NtStatus.AccessDenied); }
private void letterBox_SelectedIndexChanged(object sender, EventArgs e) { _updateLockLetterBox = true; SftpDrive drive = driveListView.SelectedItems[0].Tag as SftpDrive; drive.Letter = letterBox.Text[0]; this.updateVirtualDriveCombo(); _updateLockLetterBox = false; }
DokanError IDokanOperations.SetFileAttributes(string fileName, FileAttributes attributes, DokanFileInfo info) { Log("VFS TrySetAttributes:{0}\n{1};", fileName, attributes); SftpDrive drive = this.GetDriveByMountPoint(fileName, out fileName); if (drive != null) { return(GetSubSystemOperations(drive).SetFileAttributes(fileName, attributes, info)); } return(DokanError.ErrorAccessDenied); }
private IDokanOperations GetSubSystemOperations(SftpDrive drive) { if (drive == null) { return(null); } if ((drive.Status != DriveStatus.Mounted) && (drive.Status != DriveStatus.Mounting)) { try { LogFSActionInit("MOUNT", "", drive, "Mounting..."); drive.Mount(); } catch (Exception e) { if (e.Message == "Pageant not running") { return(null); } LogFSActionError("MOUNT", "", drive, "Mounting failed: {0}", e.Message); //Log("VFS: Mount error: {0}", e.Message); //maybe failed because of letter blocked, but we dont need the letter: if (drive.Letter != ' ') { LogFSActionError("MOUNT", "", drive, "Trying without mounting drive {0}", drive.Letter); char l = drive.Letter; drive.Letter = ' '; try { drive.Mount(); drive.Letter = l; } catch { LogFSActionError("MOUNT", "", drive, "Mounting failed again: {0}", e.Message); //connection error drive.Letter = l; //Log("VFS: Mount error: {0}", e.Message); return(null); } } else { return(null); } } } return((IDokanOperations)drive._filesystem); }
DokanError IDokanOperations.SetFileTime(string fileName, DateTime?creationTime, DateTime?lastAccessTime, DateTime?lastWriteTime, DokanFileInfo info) { SftpDrive drive = this.GetDriveByMountPoint(fileName, out fileName); if (drive != null) { return(GetSubSystemOperations(drive).SetFileTime(fileName, creationTime, lastAccessTime, lastWriteTime, info)); } return(DokanError.ErrorAccessDenied); }
DokanError IDokanOperations.SetAllocationSize(string fileName, long length, DokanFileInfo info) { Log("VFS SetSize"); SftpDrive drive = this.GetDriveByMountPoint(fileName, out fileName); if (drive != null) { return(GetSubSystemOperations(drive).SetAllocationSize(fileName, length, info)); } return(DokanError.ErrorAccessDenied); }
NtStatus IDokanOperations.WriteFile(string fileName, byte[] buffer, out int bytesWritten, long offset, DokanFileInfo info) { SftpDrive drive = this.GetDriveByMountPoint(fileName, out fileName); if (drive != null) { return(GetSubSystemOperations(drive).WriteFile(fileName, buffer, out bytesWritten, offset, info)); } bytesWritten = 0; return(NtStatus.AccessDenied); }
DokanError IDokanOperations.ReadFile(string fileName, byte[] buffer, out int bytesRead, long offset, DokanFileInfo info) { SftpDrive drive = this.GetDriveByMountPoint(fileName, out fileName); if (drive != null) { return(GetSubSystemOperations(drive).ReadFile(fileName, buffer, out bytesRead, offset, info)); } bytesRead = 0; return(DokanError.ErrorAccessDenied); }
DokanError IDokanOperations.SetFileSecurity(string fileName, FileSystemSecurity security, AccessControlSections sections, DokanFileInfo info) { Log("VFS TrySetSecurity:{0}", fileName); SftpDrive drive = this.GetDriveByMountPoint(fileName, out fileName); if (drive != null) { return(GetSubSystemOperations(drive).SetFileSecurity(fileName, security, sections, info)); } return(DokanError.ErrorAccessDenied); }
DokanError IDokanOperations.OpenDirectory(string fileName, DokanFileInfo info) { SftpDrive drive = this.GetDriveByMountPoint(fileName, out fileName); LogFSActionInit("OpenDir", fileName, drive, ""); if (drive != null) { lastActiveSubsytem = drive; IDokanOperations ops = GetSubSystemOperations(drive); if (ops == null) { LogFSActionError("OpenDir", fileName, drive, "Cannot open, mount failed?"); return(DokanError.ErrorAccessDenied); } LogFSActionSuccess("OpenDir", fileName, drive, "Found, subsytem"); return(ops.OpenDirectory(fileName, info)); } lastActiveSubsytem = null; info.IsDirectory = true; if (fileName.Length == 1) //root dir { LogFSActionSuccess("OpenDir", fileName, drive, "Found, VFS root"); return(DokanError.ErrorSuccess); } string path = fileName.Substring(1);//cut leading \ foreach (SftpDrive subdrive in _subsytems) { string mp = subdrive.MountPoint; // mp1 || mp1\mp2 ... if (path == mp) { info.Context = subdrive; LogFSActionSuccess("OpenDir", fileName, drive, "Found, final mountpoint"); return(DokanError.ErrorSuccess); } if (mp.IndexOf(path + '\\') == 0) { //path is part of mount point info.Context = subdrive; LogFSActionSuccess("OpenDir", fileName, drive, "Found, part of mountpoint"); return(DokanError.ErrorSuccess); } } LogFSActionError("OpenDir", fileName, drive, "Path not found"); return(DokanError.ErrorPathNotFound); }
NtStatus IDokanOperations.GetFileSecurity(string fileName, out FileSystemSecurity security, AccessControlSections sections, DokanFileInfo info) { Log("VFS GetSecurrityInfo:{0}:{1}", fileName, sections); SftpDrive drive = this.GetDriveByMountPoint(fileName, out fileName); if (drive != null) { return(GetSubSystemOperations(drive).GetFileSecurity(fileName, out security, sections, info)); } security = null; return(NtStatus.AccessDenied); }
private void saveButton_Click(object sender, EventArgs e) { if (String.IsNullOrEmpty(nameBox.Text)) { MessageBox.Show("Drive name connot be empty", Text); nameBox.Focus(); return; } SftpDrive drive = driveListView.SelectedItems[0].Tag as SftpDrive; if ((_regex.IsMatch(nameBox.Text) || nameBox.Text == String.Format("{0}@'{1}'", drive.Username, drive.Host)) && !String.IsNullOrEmpty(userBox.Text) && !String.IsNullOrEmpty(hostBox.Text)) { nameBox.Text = String.Format("{0}@'{1}'", userBox.Text, hostBox.Text); } driveListView.SelectedItems[0].Text = drive.Name = nameBox.Text; driveListView.SelectedItems[0].EnsureVisible(); driveListView.Sorting = SortOrder.None; driveListView.Sorting = SortOrder.Ascending; drive.Host = hostBox.Text; drive.Port = (int)portBox.Value; drive.Username = userBox.Text; switch (authCombo.SelectedIndex) { case 2: drive.ConnectionType = ConnectionType.Pageant; break; case 1: drive.ConnectionType = ConnectionType.PrivateKey; break; default: drive.ConnectionType = ConnectionType.Password; break; } drive.Letter = letterBox.Text[0]; drive.Root = directoryBox.Text.Trim(); drive.Automount = mountCheck.Checked; drive.Password = passwordBox.Text; drive.PrivateKey = privateKeyBox.Text; drive.Passphrase = passphraseBox.Text; drive.MountPoint = mountPointBox.Text; drive.ProxyType = proxyType.SelectedIndex; drive.ProxyHost = proxyHostBox.Text; drive.ProxyUser = proxyLoginBox.Text; drive.ProxyPass = proxyPassBox.Text; drive.KeepAliveInterval = (int)keepAliveIntervalBox.Value; _dirty = true; }
private void addButton_Click(object sender, EventArgs e) { char letter; try { letter = Utilities.GetAvailableDrives().Except(_drives.Select(d => d.Letter)).First(); } catch { MessageBox.Show("No more drive letters available", Text); return; } var drive = new SftpDrive { Name = String.Format("New Drive {0}", ++_namecount), Port = 22, Root = ".", Letter = letter, MountPoint = "", KeepAliveInterval = 30 }; drive.StatusChanged += drive_StatusChanged; _drives.Add(drive); this.virtualDrive.AddSubFS(drive); var item = (drive.Tag = new ListViewItem(drive.Name, 0) { Tag = drive, Selected = true }) as ListViewItem; driveListView.Items.Add(item ); item.EnsureVisible(); SetupPanels(); _dirty = true; }
void IDokanOperations.CloseFile(string fileName, IDokanFileInfo info) { SftpDrive drive = this.GetDriveByMountPoint(fileName, out fileName); LogFSActionInit("CloseFile", fileName, drive, ""); if (drive != null) { LogFSActionSuccess("CloseFile", fileName, drive, "NonVFS close"); GetSubSystemOperations(drive).CloseFile(fileName, info); return; } if (info.Context != null) { drive = info.Context as SftpDrive; info.Context = null; } LogFSActionSuccess("CloseFile", fileName, drive, "VFS close"); }
internal void AddSubFS(SftpDrive sftpDrive) { _drives.Add(sftpDrive); if (_filesystem!=null) _filesystem.AddSubFS(sftpDrive); }
internal void RemoveSubFS(SftpDrive sftpDrive) { _drives.Remove(sftpDrive); if (_filesystem!=null) _filesystem.RemoveSubFS(sftpDrive); }
DokanError IDokanOperations.OpenDirectory(string fileName, DokanFileInfo info) { SftpDrive drive = this.GetDriveByMountPoint(fileName, out fileName); LogFSActionInit("OpenDir", fileName, drive, ""); if (drive != null) { lastActiveSubsytem = drive; IDokanOperations ops = GetSubSystemOperations(drive); if (ops == null) { LogFSActionError("OpenDir", fileName, drive, "Cannot open, mount failed?"); return DokanError.ErrorAccessDenied; } LogFSActionSuccess("OpenDir", fileName, drive, "Found, subsytem"); return ops.OpenDirectory(fileName, info); } lastActiveSubsytem = null; info.IsDirectory = true; if (fileName.Length == 1) //root dir { LogFSActionSuccess("OpenDir", fileName, drive, "Found, VFS root"); return DokanError.ErrorSuccess; } string path = fileName.Substring(1);//cut leading \ foreach (SftpDrive subdrive in _subsytems) { string mp = subdrive.MountPoint; // mp1 || mp1\mp2 ... if (path == mp) { info.Context = subdrive; LogFSActionSuccess("OpenDir", fileName, drive, "Found, final mountpoint"); return DokanError.ErrorSuccess; } if (mp.IndexOf(path + '\\') == 0) { //path is part of mount point info.Context = subdrive; LogFSActionSuccess("OpenDir", fileName, drive, "Found, part of mountpoint"); return DokanError.ErrorSuccess; } } LogFSActionError("OpenDir", fileName, drive, "Path not found"); return DokanError.ErrorPathNotFound; }
internal void AddSubFS(SftpDrive sftpDrive) { _subsytems.Add(sftpDrive); }
internal void RemoveSubFS(SftpDrive sftpDrive) { _subsytems.Remove(sftpDrive); }
private IDokanOperations GetSubSystemOperations(SftpDrive drive) { if (drive == null) return null; if ((drive.Status != DriveStatus.Mounted)&&(drive.Status != DriveStatus.Mounting)) { try { LogFSActionInit("MOUNT", "", drive, "Mounting..."); drive.Mount(); } catch (Exception e) { if (e.Message == "Pageant not running") { return null; } LogFSActionError("MOUNT", "", drive, "Mounting failed: {0}",e.Message); //Log("VFS: Mount error: {0}", e.Message); //maybe failed because of letter blocked, but we dont need the letter: if (drive.Letter != ' ') { LogFSActionError("MOUNT", "", drive, "Trying without mounting drive {0}", drive.Letter); char l = drive.Letter; drive.Letter = ' '; try { drive.Mount(); drive.Letter = l; } catch { LogFSActionError("MOUNT", "", drive, "Mounting failed again: {0}", e.Message); //connection error drive.Letter = l; //Log("VFS: Mount error: {0}", e.Message); return null; } } else { return null; } } } return ((IDokanOperations)drive._filesystem); }
private void LogFSAction(String action, String path, SftpDrive subsystem, string format, params object[] arg) { Debug.Write(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "\t" + "[--VFS--]" + "\t" + action + "\t" + ( subsystem!=null? subsystem.Name : "- ") + "\t" + path + "\t"); Debug.WriteLine(format, arg); }
private void LogFSActionSuccess(String action, String path, SftpDrive subsystem, string format, params object[] arg) { LogFSAction(action + "$", path, subsystem, format, arg); }
private void updateLetterBoxCombo(SftpDrive drive) { if (_updateLockLetterBox) return; if (drive == null) { if (driveListView.SelectedItems.Count == 0) return; drive = driveListView.SelectedItems[0].Tag as SftpDrive; if (drive == null) return; } letterBox.BeginUpdate(); letterBox.Items.Clear(); letterBox.Items.Add(" None"); letterBox.Items.AddRange( Utilities.GetAvailableDrives() .Except(_drives.Select(d => d.Letter)) .Except(new char[] {virtualDrive.Letter}) .Select(l => String.Format("{0} :", l)) .ToArray()); if (drive.Letter!=' ') letterBox.Items.Add(String.Format("{0} :", drive.Letter)); letterBox.SelectedIndex = letterBox.FindString(drive.Letter.ToString()); letterBox.EndUpdate(); }
private void addButton_Click(object sender, EventArgs e) { char letter; try { letter = Utilities.GetAvailableDrives().Except(_drives.Select(d => d.Letter)).First(); } catch { MessageBox.Show("No more drive letters available", Text); return; } var drive = new SftpDrive { Name = String.Format("New Drive {0}", ++_namecount), Port = 22, Root = ".", Letter = letter }; drive.StatusChanged += drive_StatusChanged; _drives.Add(drive); var item = (drive.Tag = new ListViewItem(drive.Name, 0) {Tag = drive, Selected = true}) as ListViewItem; driveListView.Items.Add(item ); item.EnsureVisible(); SetupPanels(); _dirty = true; }
private void MountDrive(SftpDrive drive) { Task.Factory.StartNew(() => { try { drive.Mount(); } catch (Exception e) { BeginInvoke(new MethodInvoker(() => { if ( (drive.Tag as ListViewItem) .Selected) { muButton.Enabled = true; } })); if (Visible) { BeginInvoke( new MethodInvoker( () => MessageBox.Show(this, String.Format("{0} could not connect:\n{1}", drive.Name, e.Message), Text))); } else { ShowBallon(String.Format("{0} : {1}", drive.Name, e.Message),true); } } }); }