private void btnGet_Click(object sender, RoutedEventArgs e) { RemoteAppIsoStoreItem item = treeIsoStore.SelectedItem as RemoteAppIsoStoreItem; // not interesting if (item == null) { return; } System.Windows.Forms.FolderBrowserDialog dialog = new System.Windows.Forms.FolderBrowserDialog(); dialog.Description = "Select the destination folder for the downloaded files:"; dialog.ShowDialog(); if (string.IsNullOrEmpty(dialog.SelectedPath)) { return; } Analytics.Instance.Track(Analytics.Categories.IsoStore, "Get"); item.Get(dialog.SelectedPath, (chkOverwrite.IsChecked == true ? true : false)); }
private void btnDelete_Click(object sender, RoutedEventArgs e) { RemoteAppIsoStoreItem item = treeIsoStore.SelectedItem as RemoteAppIsoStoreItem; if (item == null) { return; } if (item.IsApplication) { if (MessageBox.Show("Are you sure you want to delete the IsolatedStorage for this application?\nIt will be reverted to a default state", "Delete Isolated Storage?", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.No ) { return; } } Analytics.Instance.Track(Analytics.Categories.IsoStore, "Delete"); item.Delete(); if (item.IsApplication) { item.Update(force: true); } else { item.Parent.Update(force: true); } }
private void btnPutDirectory_Click(object sender, RoutedEventArgs e) { RemoteAppIsoStoreItem item = treeIsoStore.SelectedItem as RemoteAppIsoStoreItem; // nowhere to put this if (item == null) { return; } System.Windows.Forms.FolderBrowserDialog dialog = new System.Windows.Forms.FolderBrowserDialog(); dialog.Description = "Select the folder for to send to the device:"; dialog.ShowDialog(); if (string.IsNullOrEmpty(dialog.SelectedPath)) { return; } Analytics.Instance.Track(Analytics.Categories.IsoStore, "Put Directory"); item.Put(dialog.SelectedPath, chkOverwrite.IsChecked == true); item.Update(force: true); }
private void treeIsoStoreItem_OnDrop(object sender, DragEventArgs e) { // sometimes the system sends us multiple OnDrop messages - ignore them when this happens if (_lastDropCount == _dropCount) { return; } _lastDropCount = _dropCount; TreeViewItem treeViewItem = sender as TreeViewItem; if (treeViewItem == null) { return; } RemoteAppIsoStoreItem targetItem = treeViewItem.Header as RemoteAppIsoStoreItem; string[] files = e.Data.GetData(DataFormats.FileDrop) as string[]; // only allow dropping on Application root level items and directories if (files == null || targetItem == null || (!targetItem.IsApplication && !targetItem.IsRemoteStore && !targetItem.RemoteFile.IsDirectory())) { return; } // prevent an item from being dragged on itself, or onto its parent // (which is essentially the same since dragging a\b onto a will try to replace b in a) RemoteAppIsoStoreItem draggedItem = e.Data.GetData("Random") as RemoteAppIsoStoreItem; if (draggedItem == targetItem || draggedItem.Parent == targetItem) { return; } // ensure we're not dragging onto a child of ourselves (which creates funky recursive structures) RemoteAppIsoStoreItem parentSearchItem = targetItem; while (parentSearchItem.Parent != null) { if (parentSearchItem.Parent == draggedItem) { return; } parentSearchItem = parentSearchItem.Parent; } foreach (string file in files) { targetItem.Put(file, (bool)chkOverwrite.IsChecked); } targetItem.Update(force: true); }
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { Stream stream = value as Stream; if (stream != null) { BitmapImage img = new BitmapImage(); img.BeginInit(); img.StreamSource = stream; img.EndInit(); return(img); } RemoteAppIsoStoreItem isoStoreItem = value as RemoteAppIsoStoreItem; if (isoStoreItem != null) { if (isoStoreItem.IsApplication) { return(imageApp); } else if (isoStoreItem.IsRemoteStore) { return(imageDir); } var file = isoStoreItem.RemoteFile; if (file != null) { if (file.IsDirectory()) { if (isoStoreItem.Opened) { return(imageOpenDir); } else { return(imageDir); } } else { BitmapImage img; if (fileTypeImages.TryGetValue(file.GetExtension(), out img)) { return(img); } } } } return(imageUnknown); }
private void treeIsoStore_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs <object> e) { RemoteAppIsoStoreItem item = treeIsoStore.SelectedItem as RemoteAppIsoStoreItem; if (item == null) { return; } item.Update(); stackFileProperties.DataContext = item.RemoteFileInfo; }
/// <summary> /// There has to be a better way to do this. /// /// We use FakeRemoteAppIsoStoreItems to make sure that the little expander arrows /// appear near next to expandables (apps & folders) in the file browser, and we /// remove them when Update is called. Expanded for some reason seems to always pass in /// the actual items and not the item that we're trying to expand, so we walk upwards to /// the parent and update that. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void treeIsoStore_Expanded(object sender, RoutedEventArgs e) { TreeViewItem item = e.OriginalSource as TreeViewItem; if (item.Items.Count == 1) { FakeRemoteAppIsoStoreItem fake = item.Items[0] as FakeRemoteAppIsoStoreItem; if (fake != null) { fake.Parent.Update(); } } RemoteAppIsoStoreItem isoStoreItem = treeIsoStore.SelectedItem as RemoteAppIsoStoreItem; // refresh the icon on item expansion if (isoStoreItem != null && isoStoreItem.Opened) { isoStoreItem.Icon = null; } }
private void btnLaunchMenu_Click(object sender, RoutedEventArgs e) { MenuItem contextMenuItem = (MenuItem)sender; ContextMenu contextMenu = (ContextMenu)contextMenuItem.Parent; FrameworkElement element = contextMenu.PlacementTarget as FrameworkElement; if (element != null) { FrameworkElement elemParent = element.TemplatedParent as FrameworkElement; if (elemParent != null) { TreeViewItem item = elemParent.TemplatedParent as TreeViewItem; if (item != null) { RemoteAppIsoStoreItem isoStoreItem = item.DataContext as RemoteAppIsoStoreItem; while (isoStoreItem != null && isoStoreItem.IsApplication == false) { isoStoreItem = isoStoreItem.Parent; } if (isoStoreItem != null) { Analytics.Instance.Track(Analytics.Categories.App, "Launch - IsoStore"); isoStoreItem.RemoteApp.Launch(); } } } } if (contextMenu.PlacementTarget.GetType() == typeof(TreeViewItem)) { TreeViewItem originatingTreeViewItem = (TreeViewItem)contextMenu.PlacementTarget; } }
private void OpenFileFromIsoStore() { RemoteAppIsoStoreItem item = treeIsoStore.SelectedItem as RemoteAppIsoStoreItem; if (item != null && !item.IsApplication && !item.RemoteFile.IsDirectory()) { string path = System.IO.Path.GetTempPath(); // when double clicking we should always overwrite to make sure we don't get // stale files string localFilePath = item.Get(path, true); System.Diagnostics.Debug.WriteLine(path); // double click should launch the file ProcessStartInfo info = new ProcessStartInfo(localFilePath); info.UseShellExecute = true; // decide which verb to use ("open for recognised files, otherwise "openas") // Note: info.Verbs is determined according to localFilePath info.Verb = (info.Verbs.Contains("open") ? "open" : "openas"); try { Process preview = new Process(); preview.StartInfo = info; preview.Exited += (exitSender, exitE) => { File.Delete(localFilePath); }; preview.Start(); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); } } }
private void btnPutFile_Click(object sender, RoutedEventArgs e) { RemoteAppIsoStoreItem item = treeIsoStore.SelectedItem as RemoteAppIsoStoreItem; // nowhere to put this if (item == null) { return; } OpenFileDialog dialog = new OpenFileDialog(); dialog.Multiselect = true; dialog.ShowDialog(); Analytics.Instance.Track(Analytics.Categories.IsoStore, "Put Files", "Count", dialog.FileNames.Length); foreach (string filename in dialog.FileNames) { item.Put(filename, chkOverwrite.IsChecked == true); } item.Update(force: true); }
private void treeIsoStoreItem_OnMouseMove(object sender, MouseEventArgs e) { TreeViewItem treeViewItem = sender as TreeViewItem; RemoteAppIsoStoreItem isoStoreItem = treeViewItem.DataContext as RemoteAppIsoStoreItem; if (treeViewItem != null && isoStoreItem != null && e.LeftButton == MouseButtonState.Pressed) { // We're about to enter a drag operation (which is a blocking operation) // but we need to have the files on the local system first. // Unfortunately DoDragDrop assumes that the source data (in our case IsoStore files) // are ready to be copied, which means we need to copy them to the host system before // calling DoDragDrop. Since this can take a while the user can get stuck with the program // seemingly hung while dragging, until the files have copied. If the user doesn't wait the // full amount of time the drag will fail. // An alternative is to download on a background thread, but then if the drop happens before // the files are down, we're stuck. // By the way, neither of the extra events (QueryContinueDrag & GiveFeedback) provide indication // that the drop has occurred. string tempDir = FileSystemHelpers.CreateTemporaryDirectory(); isoStoreItem.Get(tempDir, overwrite: true); DataObject dataObject = new DataObject(); dataObject.SetData(DataFormats.FileDrop, new string[] { System.IO.Path.Combine(tempDir, isoStoreItem.Name) }); dataObject.SetData("Random", isoStoreItem); DragDrop.DoDragDrop(treeViewItem, dataObject, DragDropEffects.Copy); // increment the drop counter used to smooth out multiple drops that initiate from one DoDragDrop call _dropCount++; Directory.Delete(tempDir, recursive: true); } }
public FakeRemoteAppIsoStoreItem(RemoteAppIsoStoreItem parent) : base(parent) { }