Esempio n. 1
0
        /// <summary>
        /// 初始化HardDeviceInfo对象
        /// </summary>
        /// <param name="Device">驱动器文件夹</param>
        /// <param name="Thumbnail">缩略图</param>
        /// <param name="PropertiesRetrieve">额外信息</param>
        public HardDeviceInfo(StorageFolder Device, BitmapImage Thumbnail, IDictionary <string, object> PropertiesRetrieve, DriveType DriveType)
        {
            Folder = Device ?? throw new FileNotFoundException();

            this.Thumbnail = Thumbnail ?? new BitmapImage(new Uri("ms-appx:///Assets/DeviceIcon.png"));
            this.DriveType = DriveType;

            if (PropertiesRetrieve != null)
            {
                if (PropertiesRetrieve.ContainsKey("System.Capacity") && PropertiesRetrieve["System.Capacity"] is ulong TotalByte)
                {
                    this.TotalByte = TotalByte;
                    Capacity       = TotalByte.ToFileSizeDescription();
                }
                else
                {
                    Capacity = Globalization.GetString("UnknownText");
                }

                if (PropertiesRetrieve.ContainsKey("System.FreeSpace") && PropertiesRetrieve["System.FreeSpace"] is ulong FreeByte)
                {
                    this.FreeByte = FreeByte;
                    FreeSpace     = FreeByte.ToFileSizeDescription();
                }
                else
                {
                    FreeSpace = Globalization.GetString("UnknownText");
                }

                if (PropertiesRetrieve.ContainsKey("System.Volume.FileSystem") && PropertiesRetrieve["System.Volume.FileSystem"] is string FileSystem)
                {
                    this.FileSystem = FileSystem;
                }
                else
                {
                    this.FileSystem = Globalization.GetString("UnknownText");
                }

                if (this.TotalByte != 0)
                {
                    Percent = 1 - this.FreeByte / Convert.ToDouble(this.TotalByte);
                }
                else
                {
                    Percent = 0;
                }
            }
            else
            {
                Capacity   = Globalization.GetString("UnknownText");
                FreeSpace  = Globalization.GetString("UnknownText");
                FileSystem = Globalization.GetString("UnknownText");
                Percent    = 0;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 初始化HardDeviceInfo对象
        /// </summary>
        /// <param name="Device">驱动器文件夹</param>
        /// <param name="Thumbnail">缩略图</param>
        /// <param name="PropertiesRetrieve">额外信息</param>
        public HardDeviceInfo(StorageFolder Device, BitmapImage Thumbnail, IDictionary <string, object> PropertiesRetrieve, DriveType DriveType)
        {
            Folder = Device ?? throw new FileNotFoundException();

            this.Thumbnail = Thumbnail ?? new BitmapImage(new Uri("ms-appx:///Assets/DeviceIcon.png"));
            this.DriveType = DriveType;

            if (PropertiesRetrieve != null)
            {
                if (PropertiesRetrieve.TryGetValue("System.Capacity", out object TotalByteRaw) && TotalByteRaw is ulong TotalByte)
                {
                    this.TotalByte = TotalByte;
                    Capacity       = TotalByte.ToFileSizeDescription();
                }
                else
                {
                    Capacity = Globalization.GetString("UnknownText");
                }

                if (PropertiesRetrieve.TryGetValue("System.FreeSpace", out object FreeByteRaw) && FreeByteRaw is ulong FreeByte)
                {
                    this.FreeByte = FreeByte;
                    FreeSpace     = FreeByte.ToFileSizeDescription();
                }
                else
                {
                    FreeSpace = Globalization.GetString("UnknownText");
                }

                if (PropertiesRetrieve.TryGetValue("System.Volume.FileSystem", out object FileSystemRaw) && FileSystemRaw is string FileSystem)
                {
                    this.FileSystem = FileSystem;
                }
                else
                {
                    this.FileSystem = Globalization.GetString("UnknownText");
                }

                /*
                 * | System.Volume.      | Control Panel                    | manage-bde conversion     | manage-bde     | Get-BitlockerVolume          | Get-BitlockerVolume |
                 * | BitLockerProtection |                                  |                           | protection     | VolumeStatus                 | ProtectionStatus    |
                 * | ------------------- | -------------------------------- | ------------------------- | -------------- | ---------------------------- | ------------------- |
                 * |                   1 | BitLocker on                     | Used Space Only Encrypted | Protection On  | FullyEncrypted               | On                  |
                 * |                   1 | BitLocker on                     | Fully Encrypted           | Protection On  | FullyEncrypted               | On                  |
                 * |                   1 | BitLocker on                     | Fully Encrypted           | Protection On  | FullyEncryptedWipeInProgress | On                  |
                 * |                   2 | BitLocker off                    | Fully Decrypted           | Protection Off | FullyDecrypted               | Off                 |
                 * |                   3 | BitLocker Encrypting             | Encryption In Progress    | Protection Off | EncryptionInProgress         | Off                 |
                 * |                   3 | BitLocker Encryption Paused      | Encryption Paused         | Protection Off | EncryptionSuspended          | Off                 |
                 * |                   4 | BitLocker Decrypting             | Decryption in progress    | Protection Off | DecyptionInProgress          | Off                 |
                 * |                   4 | BitLocker Decryption Paused      | Decryption Paused         | Protection Off | DecryptionSuspended          | Off                 |
                 * |                   5 | BitLocker suspended              | Used Space Only Encrypted | Protection Off | FullyEncrypted               | Off                 |
                 * |                   5 | BitLocker suspended              | Fully Encrypted           | Protection Off | FullyEncrypted               | Off                 |
                 * |                   6 | BitLocker on (Locked)            | Unknown                   | Unknown        | $null                        | Unknown             |
                 * |                   7 |                                  |                           |                |                              |                     |
                 * |                   8 | BitLocker waiting for activation | Used Space Only Encrypted | Protection Off | FullyEncrypted               | Off                 |
                 *
                 * We could use Powershell command: Get-BitLockerVolume -MountPoint C: | Select -ExpandProperty LockStatus -------------->Locked / Unlocked
                 * But powershell might speed too much time to load. So we would not use it
                 */
                if (PropertiesRetrieve.TryGetValue("System.Volume.BitLockerProtection", out object BitlockerStateRaw) && BitlockerStateRaw is int BitlockerState)
                {
                    if (BitlockerState == 6 && Capacity == Globalization.GetString("UnknownText") && FreeSpace == Globalization.GetString("UnknownText"))
                    {
                        IsLockedByBitlocker = true;
                    }
                    else
                    {
                        IsLockedByBitlocker = false;
                    }
                }
                else
                {
                    IsLockedByBitlocker = false;
                }

                if (this.TotalByte != 0)
                {
                    Percent = 1 - this.FreeByte / Convert.ToDouble(this.TotalByte);
                }
                else
                {
                    Percent = 0;
                }
            }
            else
            {
                Capacity   = Globalization.GetString("UnknownText");
                FreeSpace  = Globalization.GetString("UnknownText");
                FileSystem = Globalization.GetString("UnknownText");
                Percent    = 0;
            }
        }