示例#1
0
        internal static DriveInfo[] GetDrives()
        {
            DriveInfo[] drives = new DriveInfo[] { };

            try { drives = DriveInfo.GetDrives(); }
            catch (Exception exp) { ExceptionHelper.Log(exp); }

            if (drives.Length == 0)
            {
                return(drives);
            }

            List <DriveInfo> drivesList = new List <DriveInfo>(drives.Length);

            for (int i = 0; i < drives.Length; i++)
            {
                if (DirectoryHelper.Exists(drives[i].Name))
                {
                    drivesList.Add(drives[i]);
                }
            }

            return(drivesList.ToArray());
        }
        protected async Task <SmartItem[]> _prepareForUpload(string[] items, string destination)
        {
            List <SmartItem> uploadList = new List <SmartItem>();
            IList <string>   folders    = new List <string>();

            await Task.Run(async delegate
            {
                for (int i = 0; i < items.Length; i++)
                {
                    if (Paused)
                    {
                        while (Paused && !IsCanceled)
                        {
                            await Task.Delay(200);
                        }
                    }
                    if (IsCanceled)
                    {
                        break;
                    }
                    if (FileHelper.Exists(items[i]))
                    {
                        FileInfo file = null;
                        try
                        {
                            file = new FileInfo(items[i]);
                            uploadList.Add(new SmartItem(file, destination));
                            TransferEvent.TotalSize += file.Length;
                            TransferEvent.TotalFiles++;
                        }
                        catch (Exception exp) { ExceptionHelper.Log(exp); }
                        file = null;
                    }
                    else if (DirectoryHelper.Exists(items[i]))
                    {
                        folders.Add(items[i]);
                    }
                }
                items = null;

                for (int i = 0; i < folders.Count; i++)
                {
                    if (Paused)
                    {
                        while (Paused && !IsCanceled)
                        {
                            await Task.Delay(200);
                        }
                    }
                    if (IsCanceled)
                    {
                        break;
                    }
                    uploadList.AddRange(await _getLocalItems(new DirectoryInfo(folders[i]), destination, -1, uploadList.Count));
                }
                folders = null;
            });

            if (IsCanceled)
            {
                return new SmartItem[] { }
            }
            ;
            return(uploadList.ToArray());
        }
示例#3
0
        internal static async Task <bool> SetItemsAsync(string path)
        {
            if (path.NullEmpty())
            {
                return(false);
            }
            if ((path != LocalHelper.ThisPC) && !DirectoryHelper.Exists(path))
            {
                return(false);
            }

            fsw.EnableRaisingEvents = false;
            List <SmartItem> items  = new List <SmartItem>();
            bool             listed = false;
            await Task.Run(() =>
            {
                if (path == Home)
                {
                    SmartItem item = new SmartItem();
                    item.FullName  = item.ItemName = LocalHelper.ThisPC;
                    item.ItemIcon  = IconHelper.Get((int)ImageList.SpecialFolderCSIDL.DRIVES);

                    items.Add(item);
                    //items.Add(documentsPath);
                    listed = true;
                }

                if (path == LocalHelper.ThisPC)
                {
                    DriveInfo[] localDrives = DirectoryHelper.GetDrives();
                    try
                    {
                        for (int i = 0; i < localDrives.Length; i++)
                        {
                            SmartItem Ditem = new SmartItem(new DirectoryInfo(localDrives[i].Name));
                            Ditem.ItemName  = (localDrives[i].IsReady ? localDrives[i].VolumeLabel : string.Empty) + " (" + localDrives[i].Name.TrimEnd('\\') + ')' + (localDrives[i].IsReady ?
                                                                                                                                                                       " " + AppLanguage.Get("LangFreeSpaceX").FormatC(SizeUnit.Parse(localDrives[i].AvailableFreeSpace)) : string.Empty);
                            items.Add(Ditem);
                        }
                        listed = true;
                    }
                    catch (Exception exp) { ExceptionHelper.Log(exp); }
                    localDrives = null;
                }
                else
                {
                    DirectoryInfo Localdir = null;
                    try { Localdir = new DirectoryInfo(path); }
                    catch (Exception exp) { ExceptionHelper.Log(exp); }

                    if (Localdir != null)
                    {
                        listed = true;
                        DirectoryInfo[] dirs = null;
                        try
                        {
                            dirs = Localdir.GetDirectories();
                            for (int i = 0; i < dirs.Length; i++)
                            {
                                if ((dirs[i].Attributes & FileAttributes.Hidden) != FileAttributes.Hidden)
                                {
                                    items.Add(new SmartItem(dirs[i]));
                                }
                            }
                        }
                        catch (Exception exp) { ExceptionHelper.Log(exp); }
                        dirs = null;

                        FileInfo[] files = null;
                        try
                        {
                            files = Localdir.GetFiles();
                            for (int i = 0; i < files.Length; i++)
                            {
                                if ((files[i].Attributes & FileAttributes.Hidden) != FileAttributes.Hidden)
                                {
                                    items.Add(new SmartItem(files[i]));
                                }
                            }
                        }
                        catch (Exception exp) { ExceptionHelper.Log(exp); }
                        files = null;
                    }
                    Localdir = null;
                }
            });

            if (listed)
            {
                if (DirectoryHelper.Exists(path))
                {
                    if (fsw.Path != path)
                    {
                        fsw.Path = path;
                    }
                    fsw.EnableRaisingEvents = true;
                }

                LastPath    = CurrentPath;
                CurrentPath = path;

                if (path == LocalHelper.ThisPC)
                {
                    ParentPath = Home;
                }
                else
                {
                    ParentPath = DirectoryHelper.GetParentPath(path);
                }

                Items = new ObservableCollection <SmartItem>(items);
                return(true);
            }
            else
            {
                return(false);
            }
        }