Beispiel #1
0
        public bool VerifySettings(out List <string> errors)
        {
            // Code execute when user decides to confirm changes made since BeginEdit was called.
            // Executed before EndEdit is called and EndEdit is not called if false is returned.
            // List of errors is presented to user if verification fails.

            // Check if Drive letter is free, should not already be assigned
            // Should probably check if any image is mounted before we do this, and if so, unmount
            errors = new List <string>();

            // Unmount game image
            AutoMounter.Plugin.UnmountGameImage();

            if (!AutoMountHelpers.IsDriveLetterFree(AssignedDriveLetter))
            {
                errors.Add("Assigned Drive Letter is not free...");
            }

            if (Engine == CDMountingEngine.WinCDEmu && !File.Exists(WinCDEmuLocation))
            {
                errors.Add("Location of WinCDEmu incorrect");
            }


            if (errors.Count() > 0)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Beispiel #2
0
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            // Ensure no cd images mounted
            if (AutoMounter.Plugin.currentImage != null)
            {
                AutoMounter.Plugin.UnmountGameImage();
            }

            // Populate the free drive list - this should work right?...
            List <string> freeDriveLetters = AutoMountHelpers.GetFreeDriveLetters();

            // Clear existing items
            ComboAssignedDrive.Items.Clear();
            // Get current assigned drive letter
            string assignedDriveLetter = ((AutoMountSettings)DataContext).AssignedDriveLetter;

            foreach (string drive in freeDriveLetters)
            {
                int index = ComboAssignedDrive.Items.Add(drive);
            }

            ComboAssignedDrive.Text = assignedDriveLetter;

            // Populate CD mounting engine list
            ComboEngine.Items.Clear();
            Array enumVals = Enum.GetValues(typeof(CDMountingEngine));

            foreach (CDMountingEngine cd in enumVals)
            {
                ComboEngine.Items.Add(cd);
            }

            // Set selected item to current setting
            ComboEngine.SelectedItem = ((AutoMountSettings)DataContext).Engine;
        }
Beispiel #3
0
 public override bool IsRequestedDriveLetterAvailable()
 {
     return(AutoMountHelpers.IsDriveLetterFree(RequestedDriveLetter));
 }
Beispiel #4
0
        public override bool MountDiskImage()
        {
            if (Path.GetExtension(DiskImage).ToLower() != ".iso")
            {
                AutoMounter.Plugin.LogInfo($"WinVirtDisk: Failed to open ISO as VirtualDisk, not an ISO - {DiskImage}");
                return(false);
            }

            // Check file exists! Probably should return some nice error message...
            if (!File.Exists(DiskImage))
            {
                AutoMounter.Plugin.LogInfo($"WinVirtDisk: Failed to open ISO as VirtualDisk, ISO does not exist on disk {DiskImage}");
                return(false);
            }

            if (!AutoMountHelpers.IsDriveLetterFree(RequestedDriveLetter))
            {
                AutoMounter.Plugin.LogInfo($"WinVirtDisk: Failed to open ISO as VirtualDisk, Drive Letter in use {RequestedDriveLetter}");
                AutoMounter.API.Dialogs.ShowErrorMessage("Failed to open ISO as VirtualDisk, Drive Letter is in use", "AutoMounter");
                return(false);
            }


            VirtDisk.VIRTUAL_STORAGE_TYPE type = new VirtDisk.VIRTUAL_STORAGE_TYPE(VirtDisk.VIRTUAL_STORAGE_TYPE_DEVICE_TYPE.VIRTUAL_STORAGE_TYPE_DEVICE_ISO);
            Win32Error error = VirtDisk.OpenVirtualDisk(
                ref type,
                DiskImage,
                VirtDisk.VIRTUAL_DISK_ACCESS_MASK.VIRTUAL_DISK_ACCESS_READ,
                VirtDisk.OPEN_VIRTUAL_DISK_FLAG.OPEN_VIRTUAL_DISK_FLAG_NONE,
                null,
                out mountedHandle);

            // Opened successfully
            if (error.Succeeded)
            {
                VirtDisk.ATTACH_VIRTUAL_DISK_PARAMETERS param = VirtDisk.ATTACH_VIRTUAL_DISK_PARAMETERS.Default;

                // Attach disk (no drive letter)
                error = VirtDisk.AttachVirtualDisk(
                    mountedHandle,
                    NullSafeHandle.Null(),
                    VirtDisk.ATTACH_VIRTUAL_DISK_FLAG.ATTACH_VIRTUAL_DISK_FLAG_NO_DRIVE_LETTER |
                    VirtDisk.ATTACH_VIRTUAL_DISK_FLAG.ATTACH_VIRTUAL_DISK_FLAG_READ_ONLY, // NO_DRIVE_LETTER at a later date
                    0,
                    ref param,
                    IntPtr.Zero);

                if (error.Succeeded)
                {
                    // Try and assign the requested drive letter to the mounted image
                    if (AssignDriveLetter(RequestedDriveLetter, mountedHandle))
                    {
                        return(true);
                    }
                    else
                    {
                        AutoMounter.Plugin.LogInfo($"WinVirtDisk: Failed to open ISO as VirtualDisk, Unable to mount to drive letter {RequestedDriveLetter}");
                        AutoMounter.API.Dialogs.ShowErrorMessage("Failed to open ISO as VirtualDisk, Unable to mount to assigned drive letter", "AutoMounter");
                        UnmountCurrentDiskImage();
                        return(false);
                    }
                }
                else
                {
                    AutoMounter.Plugin.LogInfo($"WinVirtDisk: Failed to open ISO as VirtualDisk {error.ToString()}, AttachVirtualDisk Fail");
                    AutoMounter.API.Dialogs.ShowErrorMessage("Failed to open ISO as VirtualDisk, AttachVirtualDisk Fail", "AutoMounter");
                    UnmountCurrentDiskImage();
                    return(false);
                }
            }
            else
            {
                AutoMounter.Plugin.LogInfo($"WinVirtDisk: Failed to open ISO as VirtualDisk {error.ToString()}, OpenVirtualDisk Fail");
                AutoMounter.API.Dialogs.ShowErrorMessage("Failed to open ISO as VirtualDisk, OpenVirtualDisk Fail", "AutoMounter");
                UnmountCurrentDiskImage();
                return(false);
            }
        }