Beispiel #1
0
        public USBDrive(string model, string driveLetter, int disk, int partition, string label, string format,
                        long driveSize, long size, long free, bool bootable, string status, BootRecord bootRecord)
        {
            _model     = model;
            Letter     = driveLetter;
            _disk      = disk;
            _label     = label;
            _driveSize = driveSize;
            _partition = partition;
            _free      = free;
            _size      = size;
            _used      = _size - _free;
            _bootable  = bootable;
            if (!Enum.TryParse(format, true, out _format))
            {
                _format = DriveFormat.Unknown;
            }
            BootRecord   = bootRecord;
            _driveStatus = status;

            if (BootRecord == BootRecord.GPT && !Letter.EqualsIgnoreCase("None"))
            {
                Status = Status.Success;
            }
            else if (_bootable)
            {
                Status = Status.Success;
            }
            else if (BootRecord == BootRecord.Hybrid)
            {
                Status = Status.Success;
            }

            if (!_driveStatus.EqualsIgnoreCase("OK") || LargerThan32Gb)
            {
                Status = Status.Incompatible;
            }
        }
Beispiel #2
0
        public string PrepareUSB_MBR(bool quickFormat,
                                     DriveFormat driveFormat, ProgressBar progressBar)
        {
            if (_disk == 0)
            {
                throw new InvalidOperationException("Win Toolkit will not attempted to work with the system drive.");
            }

            if (driveFormat == DriveFormat.FAT32 && LargerThan32Gb)
            {
                throw new InvalidOperationException("Volume cannot be bigger than 30GB.");
            }

            if (driveFormat == _format && _bootable && BootRecord == BootRecord.MBR)
            {
                OnPropertyChanged("Skipping");
                return("Skipping");
            }

            if (_bootable && _format == DriveFormat.FAT32 && driveFormat == DriveFormat.NTFS)
            {
                OnPropertyChanged("Converting to NTFS...");
                var result = Processes.Run("convert", Letter + " /fs:NTFS");
                return(result);
            }

            if (driveFormat == _format && _bootable && BootRecord == BootRecord.GPT)
            {
                OnPropertyChanged("Skipping");
                return("Skipping");
            }

            OnPropertyChanged("Preparing...");

            var Tas = "Select Disk " + _disk + Environment.NewLine;

            var full = BootRecord != BootRecord.MBR || _partition == -1;

            if (full)
            {
                Tas += "CLEAN" + Environment.NewLine;
                if (BootRecord != BootRecord.MBR)
                {
                    Tas += "CONVERT MBR";
                }

                Tas       += "CREATE PARTITION PRIMARY ALIGN=512" + Environment.NewLine;
                _partition = 1;
            }

            Tas += "SELECT PARTITION " + _partition + Environment.NewLine;

            if (full || _format != driveFormat)
            {
                if (!Letter.EqualsIgnoreCase("None"))
                {
                    Tas += "REMOVE" + Environment.NewLine;
                }

                if (quickFormat)
                {
                    Tas += "FORMAT FS=" + driveFormat + " LABEL=\"" + _label + "\" QUICK" +
                           Environment.NewLine;
                }
                else
                {
                    Tas += "FORMAT FS=" + driveFormat + " LABEL=\"" + _label + "\"" + Environment.NewLine;
                }
            }
            Tas += "ACTIVE" + Environment.NewLine;

            if (full || _format != driveFormat || Letter.EqualsIgnoreCase("None"))
            {
                Tas += "ASSIGN" + Environment.NewLine;
            }

            Tas += "EXIT";

            UpdateLabel(progressBar, 20);
            OnPropertyChanged("Working...");
            var SW = new StreamWriter("C:\\T.txt");

            SW.Write(Tas);
            SW.Close();
            var R = Processes.Run("\"" + Directories.System32 + "\\DiskPart.exe\"", "/s C:\\T.txt");

            UpdateLabel(progressBar, 90);
            FileHandling.DeleteFile("C:\\T.txt");
            return(R);
        }