private async Task DownloadDatasheetToLibrary(ISearchResult item) { try { string destfile = System.IO.Path.Combine(Settings.DocumentsDir, item.Filename); string tmpfile; if (!temporaryFileMap.TryGetValue(item, out tmpfile)) { // Download file to TEMP if not already downloaded tmpfile = await DownloadDatasheet(item); } if (!System.IO.File.Exists(tmpfile)) { throw new InvalidOperationException($"Temp file has disappeared?? {tmpfile}"); } // Copy the temporary file into the library await ShellOperation.SHFileOperationAsync( ShellOperation.FileOperation.Move, new string[] { tmpfile }, new string[] { destfile }); // FSWatcher should automatically pick up the new item when it's copied into the library directory IsOperationInProgress = false; // Close the search view FinishSearch(); } finally { IsOperationInProgress = false; } }
private async void tree_Drop(object sender, DragEventArgs e) { // Determine the requested operation var result = tree_DragOperation(sender, e); var operation = result.Item1; var srcfiles = result.Item2; var srcuri = result.Item3; // Nothing dropped if ((srcfiles == null || srcfiles.Length == 0) && (srcuri == null)) { return; } // Default to the library root var destdir = Settings.DocumentsDir; // If dropped onto a folder, that's where the file should go var currentItem = (IItem)tree.SelectedItem; if (currentItem != null) { if (currentItem is Folder) { destdir = currentItem.FilePath; // Sanity check - don't want the file to end up somewhere outside the library! if (!System.IO.Path.GetFullPath(destdir).StartsWith(Settings.DocumentsDir)) { throw new InvalidOperationException($"Unexpected destination: {destdir}"); } } } // Otherwise this doesn't get called if you drop tree_DragLeaveForReal(sender, e); if (srcfiles != null && srcfiles.Length > 0) { switch (operation) { case DragDropEffects.Copy: await ShellOperation.SHFileOperationAsync(ShellOperation.FileOperation.Copy, srcfiles.ToArray(), destdir); //await Database.RefreshAsync(); break; case DragDropEffects.Move: await ShellOperation.SHFileOperationAsync(ShellOperation.FileOperation.Move, srcfiles.ToArray(), destdir); //await Database.RefreshAsync(); break; default: // Not supported throw new NotImplementedException($"{operation} operation not supported"); } } else if (srcuri != null) { if (operation == DragDropEffects.Link) { if (e.Data.GetData("FileGroupDescriptor") != null) { ShellOperation.ExtractUrlFileFromDrop(e, destdir); } else { //ShellOperation.CreateShellLink(srcuri, "title", destdir); throw new InvalidOperationException("Unsupported URL drop"); } } else { throw new NotImplementedException($"{operation} operation not supported"); } } else { throw new InvalidOperationException("Invalid drop operation"); } e.Handled = true; }