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));
                }
            }
        }
예제 #2
0
        private void Window_Drop(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                string[]       files = (string[])e.Data.GetData(DataFormats.FileDrop);
                var            f     = files[0];
                FileAttributes attr  = File.GetAttributes(f);

                if (attr.HasFlag(FileAttributes.Directory))
                {
                    this.model.ListItems.Clear();
                    var c = new TeslaCamDirectoryCollection();
                    c.BuildFromBaseDirectory(f);
                    this.model.ListItems.Add(c);
                    this.model.LeftStatusText = "Location: " + f;
                }
            }
        }
예제 #3
0
        private async Task TeslaCamSearchAsync()
        {
            try
            {
                // Update Status
                this.model.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 dirs           = teslaCamDir.GetDirectories();
                        var recentClipsDir = dirs.FirstOrDefault(e => e.Name == "RecentClips");
                        var savedClipsDir  = dirs.FirstOrDefault(e => e.Name == "SavedClips");
                        var sentryClipsDir = dirs.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
                    this.model.LeftStatusText = "Location: " + teslaCamDir.FullName;

                    // Add clips to UI tree
                    if (recentClips != null)
                    {
                        this.model.ListItems.Add(recentClips);
                    }
                    if (savedClips != null)
                    {
                        this.model.ListItems.Add(savedClips);
                    }
                    if (sentryClips != null)
                    {
                        this.model.ListItems.Add(sentryClips);
                    }

                    // Navigate
                    this.browseFrame.Navigate(new TeslaCamViewer.Views.RootCollectionView(this.model));
                }
                else
                {
                    // Update status to show that drive could not be found
                    this.model.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)
            {
                await this.ShowMessageAsync("Could not load TeslaCam Drive", "An error ocurred: " + ex.Message);
            }
        }
예제 #4
0
        private void TeslaCamSearch()
        {
            Task.Run(() =>
            {
                try
                {
                    Application.Current.Dispatcher.Invoke(DispatcherPriority.Background,
                                                          new Action(() =>
                                                                     { this.model.LeftStatusText = "Searching for TeslaCam ..."; }));
                    var drives      = System.IO.DriveInfo.GetDrives();
                    bool driveFound = false;
                    foreach (var drive in drives)
                    {
                        var rootDirs = drive.RootDirectory.GetDirectories();
                        foreach (var dirs in rootDirs)
                        {
                            if (dirs.Name == "TeslaCam")
                            {
                                var RecentClipsDir = dirs.GetDirectories().FirstOrDefault(e => e.Name == "RecentClips");
                                if (RecentClipsDir != null)
                                {
                                    TeslaCamDirectoryCollection c = new TeslaCamDirectoryCollection();
                                    c.BuildFromBaseDirectory(RecentClipsDir.FullName);
                                    c.SetDisplayName("Recent Clips");
                                    Application.Current.Dispatcher.Invoke(DispatcherPriority.Background,
                                                                          new Action(() => { this.model.ListItems.Add(c); }));
                                    driveFound = true;
                                }
                                var SavedClipsDir = dirs.GetDirectories().FirstOrDefault(e => e.Name == "SavedClips");
                                if (SavedClipsDir != null)
                                {
                                    TeslaCamDirectoryCollection c = new TeslaCamDirectoryCollection();
                                    c.BuildFromBaseDirectory(SavedClipsDir.FullName);
                                    c.SetDisplayName("Saved Clips");
                                    Application.Current.Dispatcher.Invoke(DispatcherPriority.Background,
                                                                          new Action(() => { this.model.ListItems.Add(c); }));
                                    driveFound = true;
                                }
                            }
                            if (driveFound)
                            {
                                Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Background,
                                                                           new Action(() =>
                                                                                      { this.model.LeftStatusText = "Location: " + dirs.FullName; }));

                                return;
                            }
                        }
                    }
                    Application.Current.Dispatcher.Invoke(DispatcherPriority.Background,
                                                          new Action(() =>
                    {
                        this.model.LeftStatusText = "Ready";
                        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)
                {
                }
            });
        }