private void WindowOnDrop(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.FileDrop)) { var files = (string[])e.Data.GetData(DataFormats.FileDrop); var file = files.FirstOrDefault(); if (file == null) { return; } var attr = File.GetAttributes(file); if (attr.HasFlag(FileAttributes.Directory)) { _viewModel.ListItems.Clear(); var teslaCamDirectoryCollection = new TeslaCamDirectoryCollection(); teslaCamDirectoryCollection.BuildFromBaseDirectory(file); _viewModel.ListItems.Add(teslaCamDirectoryCollection); _viewModel.LeftStatusText = "Location: " + file; FrameBrowse.Navigate(new TeslaCamViewer.Views.RootCollectionView(this._viewModel)); } } }
private async Task TeslaCamSearchAsync() { try { // Update Status _viewModel.LeftStatusText = "Searching for TeslaCam ..."; // Placeholder variables used during and after worker task DirectoryInfo teslaCamDir = null; TeslaCamDirectoryCollection recentClips = null; TeslaCamDirectoryCollection savedClips = null; TeslaCamDirectoryCollection sentryClips = null; // Run the following in a worker thread and wait for it to finish await Task.Run(() => { // Get all drives var drives = System.IO.DriveInfo.GetDrives(); drives = drives.Where(e => e.DriveType == DriveType.Removable || e.DriveType == DriveType.Network || e.DriveType == DriveType.Fixed).ToArray(); // Find the first drive containing a TeslaCam folder and select that folder teslaCamDir = (from drive in drives let dirs = drive.RootDirectory.GetDirectories() from dir in dirs where dir.Name == "TeslaCam" select dir).FirstOrDefault(); // If root is found load Recent and Saved if (teslaCamDir != null) { // Get child dirs var recentClipsDir = teslaCamDir.GetDirectories().FirstOrDefault(e => e.Name == "RecentClips"); var savedClipsDir = teslaCamDir.GetDirectories().FirstOrDefault(e => e.Name == "SavedClips"); var sentryClipsDir = teslaCamDir.GetDirectories().FirstOrDefault(e => e.Name == "SentryClips"); // Load if found if (recentClipsDir != null) { recentClips = new TeslaCamDirectoryCollection(); recentClips.BuildFromBaseDirectory(recentClipsDir.FullName); recentClips.SetDisplayName("Recent Clips"); } if (savedClipsDir != null) { savedClips = new TeslaCamDirectoryCollection(); savedClips.BuildFromBaseDirectory(savedClipsDir.FullName); savedClips.SetDisplayName("Saved Clips"); } if (sentryClipsDir != null) { sentryClips = new TeslaCamDirectoryCollection(); sentryClips.BuildFromBaseDirectory(sentryClipsDir.FullName); sentryClips.SetDisplayName("Sentry Clips"); } } }); // Do finial UI updating back on main thread if (teslaCamDir != null) { // Update status to show drive was found _viewModel.LeftStatusText = "Location: " + teslaCamDir.FullName; // Add clips to UI tree if (recentClips != null) { _viewModel.ListItems.Add(recentClips); } if (savedClips != null) { _viewModel.ListItems.Add(savedClips); } if (sentryClips != null) { _viewModel.ListItems.Add(sentryClips); } // Navigate FrameBrowse.Navigate(new Views.RootCollectionView(this._viewModel)); } else { // Update status to show that drive could not be found _viewModel.LeftStatusText = "Ready"; await this.ShowMessageAsync("TeslaCam Drive Not Found", "A TeslaCam drive could not automatically be found. Drag a folder or file to start playing."); } } catch (Exception ex) { this.ShowMessageAsync("Could not load TeslaCam Drive", "An error ocurred: " + ex.Message).Wait(); } }