Ejemplo n.º 1
0
 private static void AttachAutomatics(List <FileWithOptions> todoList, List <FileWithOptions> failedList)
 {
     foreach (var fwo in todoList)
     {
         try {
             Thread.Sleep(1000); //a bit of breather
             var access  = Medo.IO.VirtualDiskAccessMask.All;
             var options = Medo.IO.VirtualDiskAttachOptions.PermanentLifetime;
             if (fwo.ReadOnly)
             {
                 options |= Medo.IO.VirtualDiskAttachOptions.ReadOnly;
             }
             if (fwo.NoDriveLetter)
             {
                 options |= Medo.IO.VirtualDiskAttachOptions.NoDriveLetter;
             }
             var fileName = fwo.FileName;
             using (var disk = new Medo.IO.VirtualDisk(fileName)) {
                 disk.Open(access);
                 disk.Attach(options);
             }
         } catch (Exception ex) {
             if (failedList != null)
             {
                 failedList.Add(fwo);
             }
             Trace.TraceError("E: Cannot attach file \"" + fwo.FileName + "\". " + ex.Message);
             Medo.Diagnostics.ErrorReport.SaveToTemp(ex, fwo.FileName);
         }
     }
 }
Ejemplo n.º 2
0
 private static void ReceivedAttach(TinyPacket packet)
 {
     try {
         var    path             = packet["Path"];
         var    isReadOnly       = packet["MountReadOnly"].Equals("True", StringComparison.OrdinalIgnoreCase);
         var    shouldInitialize = packet["InitializeDisk"].Equals("True", StringComparison.OrdinalIgnoreCase);
         string diskPath         = null;
         using (var disk = new Medo.IO.VirtualDisk(path)) {
             var access  = Medo.IO.VirtualDiskAccessMask.All;
             var options = Medo.IO.VirtualDiskAttachOptions.PermanentLifetime;
             if (isReadOnly)
             {
                 if (shouldInitialize == false)
                 {
                     access = Medo.IO.VirtualDiskAccessMask.AttachReadOnly;
                 }
                 options |= Medo.IO.VirtualDiskAttachOptions.ReadOnly;
             }
             disk.Open(access);
             disk.Attach(options);
             if (shouldInitialize)
             {
                 diskPath = disk.GetAttachedPath();
             }
         }
         if (shouldInitialize)
         {
             DiskIO.InitializeDisk(diskPath);
         }
     } catch (Exception ex) {
         throw new InvalidOperationException(string.Format("Virtual disk file \"{0}\" cannot be attached.", (new FileInfo(packet["Path"])).Name), ex);
     }
 }
        private void m_btnAttachVHDandMount_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(GetPasswordFunc()))
            {
                PopUp.Error("Password is empty", "Password");
                return;
            }

            FileInfo fi = new FileInfo(m_cmbVHD_FileName.Text);

            if (!fi.Exists)
            {
                if (PopUp.Question("File not found: " + fi.FullName + "\nRemove from Recent Files List?", "Mount VHD - ERROR",
                                   MessageBoxImage.Asterisk, TextAlignment.Center, PopUp.PopUpButtonsType.NoYes) == PopUp.PopUpResult.Yes)
                {
                    _recentFiles.RemoveFromList(m_cmbVHD_FileName.Text, m_mnuFileAttachVHD.DropDown, m_cmbVHD_FileName);
                }
                return;
            }

            ExecuteClickAction(() =>
            {
                _recentFiles.AddRecent(m_cmbVHD_FileName.Text, m_mnuFileAttachVHD.DropDown, m_cmbVHD_FileName);

                fi.IsReadOnly = false; //unlock file to enable load

                _cachedDriveInfo = new List <DiskCryptor.DriveInfo>(_diskCryptor.DriveList);

                if (_virtualDisk != null)
                {
                    _virtualDisk.Close();
                }

                _virtualDisk = new Medo.IO.VirtualDisk(fi.FullName);
                _virtualDisk.Open();
                try { _virtualDisk.Detach(); } catch (Exception err) { Debug.WriteLine("Cannot detach: " + err.Message); }

                _selectedDriveLetterForMount = _selectedDriveLetter;
                _diskCryptor.OnDisksAdded   += OnDiskAddedMountDiskCryptorDisk; //mount DiskCryptor disk

                Medo.IO.VirtualDiskAttachOptions options = Medo.IO.VirtualDiskAttachOptions.NoDriveLetter;
                if (m_chkPermanent.Checked)
                {
                    options |= Medo.IO.VirtualDiskAttachOptions.PermanentLifetime;
                }
                _virtualDisk.Attach(options);

                fi.IsReadOnly = true; //lock file to improve security
            }, sender);
        }
Ejemplo n.º 4
0
 private static void AttachAutomatics(List<FileWithOptions> todoList, List<FileWithOptions> failedList)
 {
     foreach (var fwo in todoList) {
         try {
             Thread.Sleep(1000); //a bit of breather
             var access = Medo.IO.VirtualDiskAccessMask.All;
             var options = Medo.IO.VirtualDiskAttachOptions.PermanentLifetime;
             if (fwo.ReadOnly) { options |= Medo.IO.VirtualDiskAttachOptions.ReadOnly; }
             if (fwo.NoDriveLetter) { options |= Medo.IO.VirtualDiskAttachOptions.NoDriveLetter; }
             var fileName = fwo.FileName;
             using (var disk = new Medo.IO.VirtualDisk(fileName)) {
                 disk.Open(access);
                 disk.Attach(options);
             }
         } catch (Exception ex) {
             if (failedList != null) { failedList.Add(fwo); }
             Trace.TraceError("E: Cannot attach file \"" + fwo.FileName + "\". " + ex.Message);
             Medo.Diagnostics.ErrorReport.SaveToTemp(ex, fwo.FileName);
         }
     }
 }
Ejemplo n.º 5
0
 private static void ReceivedAttach(TinyPacket packet)
 {
     try {
         var path = packet["Path"];
         var isReadOnly = packet["MountReadOnly"].Equals("True", StringComparison.OrdinalIgnoreCase);
         var shouldInitialize = packet["InitializeDisk"].Equals("True", StringComparison.OrdinalIgnoreCase);
         string diskPath = null;
         using (var disk = new Medo.IO.VirtualDisk(path)) {
             var access = Medo.IO.VirtualDiskAccessMask.All;
             var options = Medo.IO.VirtualDiskAttachOptions.PermanentLifetime;
             if (isReadOnly) {
                 if (shouldInitialize == false) {
                     access = Medo.IO.VirtualDiskAccessMask.AttachReadOnly;
                 }
                 options |= Medo.IO.VirtualDiskAttachOptions.ReadOnly;
             }
             disk.Open(access);
             disk.Attach(options);
             if (shouldInitialize) { diskPath = disk.GetAttachedPath(); }
         }
         if (shouldInitialize) {
             DiskIO.InitializeDisk(diskPath);
         }
     } catch (Exception ex) {
         throw new InvalidOperationException(string.Format("Virtual disk file \"{0}\" cannot be attached.", (new FileInfo(packet["Path"])).Name), ex);
     }
 }