public void Do() { //System.Threading.Thread.Sleep(100); VirtualDrive.DeleteDirectory(Dir, true); }
public void Undo() { VirtualDrive.CreateDirectory(Dir); }
private void editOptions() { OptionsWindow options = new OptionsWindow(_options); options.ShowDialog(this); virtualDrive = _options.VirtualDrive; selectedDrive.Text = virtualDrive.ToString(); }
public bool findDT() { InfoWindow info = new InfoWindow(Localization.Strings.DTSearching); info.Show(this); if (DT.Type == DTType.None) { LogHelper.RaiseError(this, Localization.Strings.DTNotFound); this.DTVersion.Text = Localization.Strings.DTNotFound; info.Close(); return false; } else { this.DTVersion.Text = "DT " + DT.Type.ToString() + " " + DT.Version; LogHelper.WriteLine(this.DTVersion.Text, LogHelper.MessageType.INFO); if (!_options.Reload() || !_options.VirtualDrive.IsValid) { info.Close(); editOptions(); } else { virtualDrive = _options.VirtualDrive; selectedDrive.Text = virtualDrive.ToString(); info.Close(); } return true; } }
private static void TestMoveDir_AlreadyExists_Skip() { string undoFileName = VirtualDrive.VirtualFileName( "TestMoveDir_AlreadyExists_Skip.txt"); string folder0 = VirtualDrive.VirtualFileName(@"fold00\folder0"); string filename00 = Path.Combine(folder0, "t0.bin"); string filename01 = Path.Combine(folder0, "t1.bin"); string folder1 = VirtualDrive.VirtualFileName(@"fold01\folder1"); string filename10 = Path.Combine(folder1, "t0.bin"); string filename11 = Path.Combine(folder1, "t1.bin"); VirtualDrive.Store(VirtualDrive.VirtualFileName(filename00), null); VirtualDrive.Store(VirtualDrive.VirtualFileName(filename01), null); VirtualDrive.Store(VirtualDrive.VirtualFileName(filename10), null); UnitTest.Test(VirtualDrive.ExistsDirectory(folder0)); UnitTest.Test(VirtualDrive.ExistsDirectory(folder1)); UnitTest.Test(VirtualDrive.ExistsFile(filename00)); UnitTest.Test(VirtualDrive.ExistsFile(filename01)); UnitTest.Test(VirtualDrive.ExistsFile(filename10)); UnitTest.Test(!VirtualDrive.ExistsFile(filename11)); using (UndoFileWriter undoFileWriter = new UndoFileWriter(undoFileName)) { FileOperationProcessor p = new FileOperationProcessor(); p.Operation = FileOperationProcessor.FileOperation.Move; p.UndoFile = undoFileWriter; p.NewName = folder1; p.Conflicts = FileOperationProcessor.ConflictSolving.Skip; p.Process(new DirectoryInfo(folder0)); } UnitTest.Test(VirtualDrive.ExistsDirectory(folder0)); UnitTest.Test(VirtualDrive.ExistsDirectory(folder1)); UnitTest.Test(VirtualDrive.ExistsFile(filename00)); UnitTest.Test(VirtualDrive.ExistsFile(filename01)); UnitTest.Test(VirtualDrive.ExistsFile(filename10)); UnitTest.Test(!VirtualDrive.ExistsFile(filename11)); UndoFilePlayer.Undo(undoFileName); UnitTest.Test(VirtualDrive.ExistsDirectory(folder0)); UnitTest.Test(VirtualDrive.ExistsDirectory(folder1)); UnitTest.Test(VirtualDrive.ExistsFile(filename00)); UnitTest.Test(VirtualDrive.ExistsFile(filename01)); UnitTest.Test(VirtualDrive.ExistsFile(filename10)); UnitTest.Test(!VirtualDrive.ExistsFile(filename11)); UndoFilePlayer.Redo(undoFileName); UnitTest.Test(VirtualDrive.ExistsDirectory(folder0)); UnitTest.Test(VirtualDrive.ExistsDirectory(folder1)); UnitTest.Test(VirtualDrive.ExistsFile(filename00)); UnitTest.Test(VirtualDrive.ExistsFile(filename01)); UnitTest.Test(VirtualDrive.ExistsFile(filename10)); UnitTest.Test(!VirtualDrive.ExistsFile(filename11)); VirtualDrive.DeleteDirectory(folder0, true); VirtualDrive.DeleteDirectory(folder1, true); }
private static void TestMoveDir_AlreadyExists_Overwrite() { SetupRecycleBin(); string undoFileName = VirtualDrive.VirtualFileName( "TestFileCopyProcessorUndoFile.txt"); string folder0 = VirtualDrive.VirtualFileName(@"fold00\folder0"); string folder1 = VirtualDrive.VirtualFileName(@"fold01\folder1"); string srcFile0 = Path.Combine(folder0, "t0.bin"); string replaceFile0 = Path.Combine(folder1, "t1.bin"); string dstFile0 = Path.Combine(folder1, "t0.bin"); string recycleBin = VirtualDrive.VirtualFileName(@"recycle"); string recycleFile0 = Path.Combine(Path.Combine(recycleBin, "0"), "t1.bin"); VirtualDrive.Store(VirtualDrive.VirtualFileName(srcFile0), null); VirtualDrive.Store(VirtualDrive.VirtualFileName(replaceFile0), null); UnitTest.Test(VirtualDrive.ExistsDirectory(folder0)); UnitTest.Test(VirtualDrive.ExistsDirectory(folder1)); UnitTest.Test(VirtualDrive.ExistsFile(srcFile0)); UnitTest.Test(!VirtualDrive.ExistsFile(dstFile0)); UnitTest.Test(VirtualDrive.ExistsFile(replaceFile0)); UnitTest.Test(!VirtualDrive.ExistsFile(recycleFile0)); using (UndoFileWriter undoFileWriter = new UndoFileWriter(undoFileName)) { FileOperationProcessor p = new FileOperationProcessor(); p.Operation = FileOperationProcessor.FileOperation.Move; p.UndoFile = undoFileWriter; p.NewName = folder1; p.Conflicts = FileOperationProcessor.ConflictSolving.Overwrite; p.Process(new DirectoryInfo(folder0)); } UnitTest.Test(!VirtualDrive.ExistsDirectory(folder0)); UnitTest.Test(VirtualDrive.ExistsDirectory(folder1)); UnitTest.Test(!VirtualDrive.ExistsFile(srcFile0)); UnitTest.Test(VirtualDrive.ExistsFile(dstFile0)); UnitTest.Test(!VirtualDrive.ExistsFile(replaceFile0)); UnitTest.Test(VirtualDrive.ExistsFile(recycleFile0)); UndoFilePlayer.Undo(undoFileName); UnitTest.Test(VirtualDrive.ExistsDirectory(folder0)); UnitTest.Test(VirtualDrive.ExistsDirectory(folder1)); UnitTest.Test(VirtualDrive.ExistsFile(srcFile0)); UnitTest.Test(!VirtualDrive.ExistsFile(dstFile0)); UnitTest.Test(VirtualDrive.ExistsFile(replaceFile0)); UnitTest.Test(!VirtualDrive.ExistsFile(recycleFile0)); UndoFilePlayer.Redo(undoFileName); UnitTest.Test(!VirtualDrive.ExistsDirectory(folder0)); UnitTest.Test(VirtualDrive.ExistsDirectory(folder1)); UnitTest.Test(!VirtualDrive.ExistsFile(srcFile0)); UnitTest.Test(VirtualDrive.ExistsFile(dstFile0)); UnitTest.Test(!VirtualDrive.ExistsFile(replaceFile0)); UnitTest.Test(VirtualDrive.ExistsFile(recycleFile0)); VirtualDrive.DeleteDirectory(folder1, true); VirtualDrive.DeleteDirectory(recycleBin, true); }
public static bool AreFilesEqual(string fileName0, string fileName1) { return(Math.Min(VirtualDrive.FileLength(fileName0), VirtualDrive.FileLength(fileName1)) == CountEqualBytes(fileName0, fileName1)); }
public Writer(FileInfo file) { Filename = file.FullName; stream = VirtualDrive.OpenOutStream(file.FullName); }
private static bool IsDirectoryEmpty(DirectoryInfo dir) { return(VirtualDrive.GetFiles(dir.FullName, "*.*").Length == 0 && VirtualDrive.GetDirectories(dir.FullName).Length == 0); }
protected override void OnLoad(EventArgs e) { notifyIcon.Text = Text = String.Format("Sshfs Manager - 4every1 edition - v. {0}", Assembly.GetEntryAssembly().GetName().Version); portBox.Minimum = IPEndPoint.MinPort; portBox.Maximum = IPEndPoint.MaxPort; openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile, Environment.SpecialFolderOption.None);//Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile,Environment.SpecialFolderOption.DoNotVerify),".ssh"); /* if (!Directory.Exists(openFileDialog.InitialDirectory)) openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal, Environment.SpecialFolderOption.DoNotVerify);*/ startupMenuItem.Checked = Utilities.IsAppRegistredForStarup(); // _drives.Presist("config.xml",true); virtualDrive = virtualDrive.Load("vfs.xml"); if (virtualDrive == null) { virtualDrive = new VirtualDrive { Letter = 'Z' }; } virtualDrive.StatusChanged += drive_VFSStatusChanged; updateVirtualDriveCombo(); this.tryMountVFS(); buttonVFSupdate(); _drives.Load("config.xml"); driveListView.BeginUpdate(); for (int i = 0; i < _drives.Count; i++) { driveListView.Items.Add( ( _drives[i].Tag = new ListViewItem(_drives[i].Name, 0) {Tag = _drives[i]} ) as ListViewItem ); _drives[i].StatusChanged += drive_StatusChanged; if (_drives[i].Name.StartsWith("New Drive")) _namecount++; virtualDrive.AddSubFS(_drives[i]); } if (driveListView.Items.Count != 0) { driveListView.SelectedIndices.Add(0); } driveListView.Sorting = SortOrder.Ascending; driveListView.EndUpdate(); //just to remove HScroll if (driveListView.Items.Count > 10) { driveListView.Items[10].EnsureVisible(); driveListView.Items[0].EnsureVisible(); } SetupPanels(); SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged; base.OnLoad(e); }
public bool MountDiskImage(VirtualDrive vd) { if (_diskImage.Length == 0) return true; if (!File.Exists(_diskImage) || !vd.IsValid) return false; return vd.Mount(_diskImage); }
private static int Start(string progName) { var trayIcon = new NotifyIcon { Icon = GUI.Properties.Resources.icon }; var progs = new ProgList(); Prog prog; try { int progId = Int32.Parse(progName); prog = progs.Get(progId); } catch (FormatException) { prog = progs.Get(progName); } if (prog == null || !prog.IsOK() || (prog.DiskImage.Length > 0 && !prog.DiskImageOK())) { ShowError(String.Format(Localization.Strings.ProgNotFound, progName)); return(-1); } var info = new InfoWindow(String.Format(Localization.Strings.ProgPreparing, prog.Name)); info.Show(); trayIcon.Text = String.Format(Localization.Strings.ProgWaitingEnd, prog.Name); VirtualDrive virtualDrive = null; if (prog.DiskImage.Length > 0) { if (!new MainWindow().findDT()) { return(-1); } var opts = new Options(); if (!opts.Reload()) { ShowError(Localization.Strings.OptionsError); return(-1); } virtualDrive = opts.VirtualDrive; if (!virtualDrive.IsValid) { info.Close(); ShowError(Localization.Strings.InvalidDrive + " : " + virtualDrive); return(-1); } info.Close(); info = new InfoWindow(String.Format(Localization.Strings.DiskImageMounting, prog.DiskImage, prog.Name)); info.Show(); if (!prog.MountDiskImage(virtualDrive)) { ShowError(Localization.Strings.ErrorMounting); return(-1); } } info.Close(); info = new InfoWindow(String.Format(Localization.Strings.ProgStarting, prog.Name)); info.Show(); Process proc = prog.Start(); trayIcon.Visible = true; info.Close(); proc.WaitForExit(); trayIcon.Visible = false; if (virtualDrive != null && virtualDrive.IsValid) { info = new InfoWindow(Localization.Strings.DiskImageUnmounting); info.Show(); virtualDrive.Umount(); info.Close(); } return(0); }
public static Stream OpenInStream(FileInfo file) { return(VirtualDrive.OpenInStream(file.FullName)); }
public static BinaryWriter OpenWriter(FileInfo file) { return(new BinaryWriter( VirtualDrive.OpenOutStream(file.FullName), System.Text.Encoding.BigEndianUnicode)); }
public abstract Task Run(VirtualDrive drive);