//the endpoint for clicking the "restore" button in the interface private void RestoreItems(object o, System.EventArgs e) { //ask where we're restoring to Gtk.FileChooserDialog restoreTo = new Gtk.FileChooserDialog("Where should files be saved?", this, FileChooserAction.SelectFolder, "Cancel",ResponseType.Cancel, "Restore",ResponseType.Accept); string restorePath; if (restoreTo.Run () == (int)ResponseType.Accept) { restorePath = restoreTo.Filename; restoreTo.Destroy(); } else { restoreTo.Destroy(); return; } //get the selected items Gtk.TreeSelection selection = treeview1.Selection; Gtk.TreePath[] selectionPath = selection.GetSelectedRows(); if(selectionPath.Length < 1) return; //build our arguments to send to the listener ArchiveSelectedEventArgs args = new ArchiveSelectedEventArgs(); args.archiveIDs = new List<string>(); args.paths = new List<Int64>(); args.restoreTo = restorePath; //iterate over the selections foreach (Gtk.TreePath path in selectionPath) { TreeIter iter; if(!selection.TreeView.Model.GetIter(out iter, path)) continue; string archiveID = (string)selection.TreeView.Model.GetValue(iter, 5); //if we have an archive id, add it to the list if(!String.IsNullOrWhiteSpace(archiveID)) args.archiveIDs.Add (archiveID); else { //otherwise, we're on a directory Int64 directoryID = (Int64)selection.TreeView.Model.GetValue(iter, 6); args.paths.Add(directoryID); } } //fire the event ArchivesSelectedForRestore(this, args); }
//handles the restore event from the ArchiveBrowser protected void OnArchivesRestore(object sender, ArchiveSelectedEventArgs e) { string fileName; foreach (string s in e.archiveIDs) { fileName = DataStore.GetFullPath(DataStore.GetFileParent(s)) + DataStore.GetFileName(s); enqueueDownload(fileName,FileAttributes.Normal,e.restoreTo,s); } foreach (Int64 p in e.paths) { fileName = DataStore.GetFullPath(p); enqueueDownload(fileName,FileAttributes.Directory,e.restoreTo); } }