コード例 #1
0
        private void OnScanDrivesCompleted(IEnumerable <InstalledMountedDriveInfo> drives)
        {
            Drives.Clear();

            Drives.AddRange(drives.Select(drive => new DriveViewModel(drive)));

            SelectedDrive = Drives.FirstOrDefault();

            IsScanning = false;
        }
コード例 #2
0
ファイル: Model.cs プロジェクト: bartoszhajduk/-POIG-MiniTC
 public List <string> getLogicalDrives()
 {
     Drives.Clear();
     string[] tmp = Directory.GetLogicalDrives();
     foreach (var i in tmp)
     {
         Drives.Add(i);
     }
     return(Drives);
 }
コード例 #3
0
        public void Dispose( )
        {
            foreach (MediaWriterDrive drive in Drives)
            {
                drive.OnDeviceEvent -= new EventHandler <MediaWriterDevNotifyEventArgs> (drive_OnDeviceEvent);
                drive.Dispose( );
            }

            Drives.Clear( );

            if (null != __MediaWriter)
            {
                __MediaWriter.Dispose( );
            }
        }
コード例 #4
0
        public void Load()
        {
            IEnumerable <DriveDto> lookup;

            if (CanShowHidden)
            {
                itemsCount = _lookupDataService
                             .GetDrivesCountByCondition(x => x.Title.Contains(FilterText), x => x.DriveCode
                                                        , false, 1, int.MaxValue);

                lookup = _lookupDataService.GetDrivesByCondition(x => x.Title.Contains(FilterText), x => x.DriveCode
                                                                 , false, CurrentPage, PageLength);
            }
            else
            {
                itemsCount = _lookupDataService
                             .GetDrivesCountByCondition(x => x.Title.Contains(FilterText) && x.IsSecret == false, x => x.DriveCode
                                                        , false, 1, int.MaxValue);

                lookup = _lookupDataService.GetDrivesByCondition(x => x.Title.Contains(FilterText) && x.IsSecret == false, x => x.DriveCode
                                                                 , false, CurrentPage, PageLength);
            }


            Drives.Clear();
            foreach (var item in lookup)
            {
                Drives.Add(new NavigationDriveItemViewModel(
                               item.DriveId, string.Format("{0}", item.Title.TrimEnd(' ')
                                                           ), nameof(DriveDetailViewModel), _eventAggregator, item.DriveCode.TrimEnd(' '), item.IsSecret));
            }


            //var categoryLookup =  _categoryLookupDataService.GetCategoryLookup();
            //Categories.Clear();
            //foreach (var item in categoryLookup)
            //{
            //    //Categories.Add(new NavigationItemViewModel(item.Id,
            //    //item.DisplayMember, nameof(CategoryDetailViewModel), _eventAggregator));
            //}
        }
コード例 #5
0
ファイル: MountService.cs プロジェクト: sganis/golddrive
        //public ReturnBox DownloadFile(string src, string dst)
        //{
        //    ReturnBox r = new ReturnBox();
        //    if (Connected)
        //    {
        //        try
        //        {
        //            using (Stream fs = File.Create(dst))
        //            {
        //                Sftp.DownloadFile(src, fs);
        //            }
        //            r.Success = true;
        //        }
        //        catch (Exception ex)
        //        {
        //            r.Error = ex.Message;
        //        }
        //    }
        //    return r;
        //}

        //public ReturnBox UploadFile(string src, string dir, string filename)
        //{
        //    ReturnBox r = new ReturnBox();
        //    if (Connected)
        //    {
        //        try
        //        {
        //            using (var fs = new FileStream(src, FileMode.Open))
        //            {
        //                Sftp.BufferSize = 4 * 1024; // bypass Payload error large files
        //                Sftp.ChangeDirectory(dir);
        //                Sftp.UploadFile(fs, filename, true);
        //            }
        //            r.Success = true;
        //        }
        //        catch (Exception ex)
        //        {
        //            r.Error = ex.Message;
        //        }
        //    }
        //    return r;
        //}

        #endregion

        #region Local Drive Management


        public void UpdateDrives(Settings settings)
        {
            string      GOLDLETTERS = "GHIJKLMNOPQRSTUVWXYZ";
            List <char> letters     = GOLDLETTERS.ToCharArray().ToList();

            DriveInfo[] drives = DriveInfo.GetDrives();
            Drives.Clear();
            var settingsDrives = settings.Drives.Values.ToList();
            var netUseDrives   = GetUsedDrives();

            foreach (char c in letters)
            {
                //if (c == 'W')
                //    c.ToString();
                bool  used = false;
                Drive d    = new Drive {
                    Letter = c.ToString()
                };

                for (int i = 0; i < drives.Length; i++)
                {
                    try {
                        DriveInfo dinfo = drives[i];
                        if (dinfo.Name[0] == c)
                        {
                            d.Status = DriveStatus.UNKNOWN;
                            // this triggers IOException when drive is unavailable
                            d.IsGoldDrive = dinfo.DriveFormat == "FUSE-Golddrive";
                            used          = true;
                            if (d.IsGoldDrive == true)
                            {
                                d.MountPoint = dinfo.VolumeLabel.Replace("/", "\\");
                                d.Label      = GetExplorerDriveLabel(d);
                                if (dinfo.IsReady)
                                {
                                    d.Status = DriveStatus.CONNECTED;
                                }
                                else
                                {
                                    d.Status = DriveStatus.BROKEN;
                                }
                                var d1 = settingsDrives.Find(x => x.Letter == d.Letter);
                                if (d1 != null)
                                {
                                    //d.MountPoint = d1.MountPoint;
                                    d.Args  = d1.Args;
                                    d.Label = d1.Label;
                                }
                            }
                            Drives.Add(d);
                            break;
                        }
                    } catch (IOException e) {
                    } catch (Exception ex) {
                    }
                }

                if (!used)
                {
                    var d0 = netUseDrives.Find(x => x.Letter == d.Letter);
                    if (d0 != null)
                    {
                        d.IsGoldDrive = d0.IsGoldDrive;
                        d.Status      = d0.Status;
                        if (d.IsGoldDrive == true)
                        {
                            d.Status     = DriveStatus.BROKEN;
                            d.MountPoint = d0.MountPoint;
                            d.Label      = d0.Label;
                            var d1 = settingsDrives.Find(x1 => x1.Letter == d.Letter);
                            if (d1 != null)
                            {
                                d.Args  = d1.Args;
                                d.Label = d1.Label;
                            }
                        }
                        else
                        {
                            d.Status = DriveStatus.UNKNOWN;
                        }
                    }
                    else
                    {
                        var d1 = settingsDrives.Find(x1 => x1.Letter == d.Letter);
                        if (d1 != null)
                        {
                            d.Status      = DriveStatus.DISCONNECTED;
                            d.MountPoint  = d1.MountPoint;
                            d.Args        = d1.Args;
                            d.Label       = d1.Label;
                            d.IsGoldDrive = true;
                        }
                        else
                        {
                            d.Status = DriveStatus.FREE;
                        }
                    }
                    Drives.Add(d);
                }
            }
        }
コード例 #6
0
    public async Task RefreshAsync()
    {
        using (await RefreshAsyncLock.LockAsync())
        {
            Drives.Clear();

            DriveInfo[] drives;

            try
            {
                drives = DriveInfo.GetDrives();
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "Getting drives");

                await Services.MessageUI.DisplayMessageAsync(Resources.DriveSelection_RefreshError, MessageType.Error);

                return;
            }

            foreach (var drive in drives)
            {
                if (BrowseVM.AllowedTypes != null && !BrowseVM.AllowedTypes.Contains(drive.DriveType))
                {
                    continue;
                }

                ImageSource icon  = null;
                string      label = null;
                string      path;
                string      format    = null;
                ByteSize?   freeSpace = null;
                ByteSize?   totalSize = null;
                DriveType?  type      = null;
                bool?       ready     = null;

                try
                {
                    label = drive.VolumeLabel;
                }
                catch (Exception ex)
                {
                    Logger.Debug(ex, "Getting drive label");
                }

                try
                {
                    path = drive.Name;

                    try
                    {
                        using var shellObj = ShellObject.FromParsingName(path);
                        var thumb = shellObj.Thumbnail;
                        thumb.CurrentSize = new System.Windows.Size(16, 16);
                        icon = thumb.GetTransparentBitmap()?.ToImageSource();
                    }
                    catch (Exception ex)
                    {
                        Logger.Debug(ex, "Getting drive icon");
                    }
                }
                catch (Exception ex)
                {
                    Logger.Debug(ex, "Getting drive name");
                    continue;
                }

                try
                {
                    format = drive.DriveFormat;
                }
                catch (Exception ex)
                {
                    Logger.Debug(ex, "Getting drive format");
                }

                try
                {
                    freeSpace = ByteSize.FromBytes(drive.TotalFreeSpace);
                }
                catch (Exception ex)
                {
                    Logger.Debug(ex, "Getting drive freeSpace");
                }

                try
                {
                    totalSize = ByteSize.FromBytes(drive.TotalSize);
                }
                catch (Exception ex)
                {
                    Logger.Debug(ex, "Getting drive totalSize");
                }

                try
                {
                    type = drive.DriveType;
                }
                catch (Exception ex)
                {
                    Logger.Debug(ex, "Getting drive type");
                }

                try
                {
                    ready = drive.IsReady;
                    if (!drive.IsReady && !BrowseVM.AllowNonReadyDrives)
                    {
                        continue;
                    }
                }
                catch (Exception ex)
                {
                    Logger.Debug(ex, "Getting drive ready");
                    if (!BrowseVM.AllowNonReadyDrives)
                    {
                        continue;
                    }
                }

                // Create the view model
                var vm = new DriveViewModel()
                {
                    Path      = path,
                    Icon      = icon,
                    Format    = format,
                    Label     = label,
                    Type      = type,
                    FreeSpace = freeSpace,
                    TotalSize = totalSize,
                    IsReady   = ready
                };

                Drives.Add(vm);
            }
        }
    }
コード例 #7
0
ファイル: TCPanelViewModel.cs プロジェクト: zwalone/MIniTC
 public void UpdateDrives()
 {
     Drives.Clear();
     Directory.GetLogicalDrives().ToList().ForEach(x => Drives.Add(x));
 }