private void DoMenuDownloadToLocal() { List<IAsset> SelectedAssets = ReturnSelectedAssets(); if (SelectedAssets.Count == 0) return; IAsset mediaAsset = SelectedAssets.FirstOrDefault(); if (mediaAsset == null) return; var form = new DownloadToLocal(SelectedAssets, _backuprootfolderdownload); if (form.ShowDialog() == DialogResult.OK) { bool ErrorFolderCreation = false; _backuprootfolderdownload = form.FolderPath; // for reuse later if (!Directory.Exists(form.FolderPath)) { if (MessageBox.Show(string.Format("Folder '{0}' does not exist." + Constants.endline + "Do you want to create it ?", form.FolderPath), "Folder does not exist", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { try { Directory.CreateDirectory(form.FolderPath); } catch { ErrorFolderCreation = true; MessageBox.Show(string.Format("Error when creating folder '{0}'.", form.FolderPath), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); TextBoxLogWriteLine("Error when creating folder '{0}'.", form.FolderPath, true); } } else { ErrorFolderCreation = true; TextBoxLogWriteLine("User cancelled the folder creation.", true); } } if (!ErrorFolderCreation) { var listfiles = new List<string>(); // let's see if some files exist in the destination foreach (var asset in SelectedAssets) { string path = form.FolderPath; if (form.FolderOption == DownloadToFolderOption.SubfolderAssetName) { path = Path.Combine(path, asset.Name); } else if (form.FolderOption == DownloadToFolderOption.SubfolderAssetId) { path = Path.Combine(path, asset.Id); } listfiles.AddRange(asset.AssetFiles.ToList().Where(f => File.Exists(path + @"\\" + f.Name)).Select(f => path + @"\\" + f.Name).ToList()); } if (listfiles.Count > 0) { string text; if (listfiles.Count > 20) { text = string.Format( "{0} files are already in the folder(s)\n\nOverwite the files ?", listfiles.Count ); } else if (listfiles.Count > 1) { text = string.Format( "The following files are already in the folder(s)\n\n{0}\n\nOverwite the files ?", string.Join("\n", listfiles.Select(f => Path.GetFileName(f)).ToArray()) ); } else { text = string.Format( "The following file is already in the folder\n\n{0}\n\nOverwite the file ?", string.Join("\n", listfiles.Select(f => Path.GetFileName(f)).ToArray()) ); } if (MessageBox.Show(text, "File(s) overwrite", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) != DialogResult.OK) { return; } try { listfiles.ForEach(f => File.Delete(f)); } catch { MessageBox.Show("Error when deleting files", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } string label = string.Format("Download of asset '{0}'", mediaAsset.Name); if (SelectedAssets.Count > 1) label = string.Format("Download of {0} assets", SelectedAssets.Count); int index = DoGridTransferAddItem(label, TransferType.DownloadToLocal, Properties.Settings.Default.useTransferQueue); // Start a worker thread that does downloading. Task.Factory.StartNew(() => ProcessDownloadAsset(SelectedAssets, form.FolderPath, index, form.FolderOption, form.OpenFolderAfterDownload)); DotabControlMainSwitch(Constants.TabTransfers); } } }
private void DoMenuDownloadToLocal() { List<IAsset> SelectedAssets = ReturnSelectedAssets(); if (SelectedAssets.Count == 0) return; IAsset mediaAsset = SelectedAssets.FirstOrDefault(); if (mediaAsset == null) return; var form = new DownloadToLocal(SelectedAssets, _backuprootfolderdownload); if (form.ShowDialog() == DialogResult.OK) { bool ErrorFolderCreation = false; _backuprootfolderdownload = form.FolderPath; // for reuse later if (!File.Exists(form.FolderPath)) { if (MessageBox.Show(string.Format("Folder '{0}' does not exist." + Constants.endline + "Do you want to create it ?", form.FolderPath), "Folder does not exist", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { try { Directory.CreateDirectory(form.FolderPath); } catch { ErrorFolderCreation = true; MessageBox.Show(string.Format("Error when creating folder '{0}'.", form.FolderPath), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); TextBoxLogWriteLine("Error when creating folder '{0}'.", form.FolderPath, true); } } else { ErrorFolderCreation = true; TextBoxLogWriteLine("User cancelled the folder creation.", true); } } if (!ErrorFolderCreation) { string label = string.Format("Download of asset '{0}'", mediaAsset.Name); if (SelectedAssets.Count > 1) label = string.Format("Download of {0} assets", SelectedAssets.Count); int index = DoGridTransferAddItem(label, TransferType.DownloadToLocal, Properties.Settings.Default.useTransferQueue); // Start a worker thread that does downloading. Task.Factory.StartNew(() => ProcessDownloadAsset(SelectedAssets, form.FolderPath, index, form.FolderOption, form.OpenFolderAfterDownload)); DotabControlMainSwitch(Constants.TabTransfers); } } }