protected bool _createLocalFolder(string dirName) { return(!IsCanceled && DirectoryHelper.Create(dirName)); }
private async Task setTransferAction(bool IsUpload, SmartItem[] IIDP, int j) { if (TransferEvent.Item.Exist) { if (TransferEvents.TillCloseAction != TransferAction.Unknown) { TransferEvent.Action = TransferEvents.TillCloseAction; } else if (TransferEvent.SessionAction != TransferAction.Unknown) { TransferEvent.Action = TransferEvent.SessionAction; } else { TransferEvent.RequestingAction(IIDP[j], ((TransferEvent.Item.Length > 1048576) && (TransferEvent.Item.Length > IIDP[j].Length))); } } switch (TransferEvent.Action) { case TransferAction.Unknown: TransferEvent.Item.Status = IsUpload ? ItemStatus.Uploading : ItemStatus.Downloading; break; case TransferAction.Ignore: TransferEvent.Item.Status = ItemStatus.Ignored; break; case TransferAction.Rename: if (TransferEvent.Item.Exist) { string newName = await IIDP.GetNewName(IIDP[j]); if (IsUpload) { if (await RenameItemAsync(IIDP[j], newName)) { IIDP[j].ItemName = newName; IIDP[j].FullName = IIDP[j].ItemFolder + newName; TransferEvent.Item.Exist = false; TransferEvent.Item.Status = ItemStatus.Uploading; } else { TransferEvent.Item.Status = ItemStatus.UploadError; TransferEvent.Item.HasError = true; } } else { bool renamed; if (IIDP[j].IsFile) { renamed = FileHelper.Rename(IIDP[j].FullName, IIDP[j].ItemFolder + @"\" + newName); } else { renamed = DirectoryHelper.Rename(IIDP[j].FullName, IIDP[j].ItemFolder + @"\" + newName); } if (renamed) { IIDP[j].ItemName = IIDP[j].ItemName = newName; IIDP[j].FullName = IIDP[j].ItemFolder + @"\" + newName; TransferEvent.Item.Exist = false; TransferEvent.Item.Status = ItemStatus.Downloading; } else { TransferEvent.Item.Status = ItemStatus.DownloadError; TransferEvent.Item.HasError = true; } } } else { TransferEvent.Item.Status = IsUpload ? ItemStatus.Uploading : ItemStatus.Downloading; } break; case TransferAction.Replace: TransferEvent.Item.Status = (IsUpload) ? ItemStatus.Replacing : ItemStatus.Downloading; break; case TransferAction.Resume: TransferEvent.Item.Status = ItemStatus.Resuming; break; } }
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()); }
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); } }