private void LoadSessionNode(TreeNode sessionNode)
        {
            string session = sessionNode.Tag as string;

            if (string.IsNullOrEmpty(session))
            {
                return;
            }

            sessionNode.Nodes.Clear();

            IEnumerable <CaptureHistoryEntry> entries = CaptureHistory.GetEntries(session);

            foreach (CaptureHistoryEntry entry in entries)
            {
                TreeNode entryNode = new TreeNode();
                string   filename  = Path.GetFileName(entry.CaptureFile);
                string   time      = entry.Start.ToLongTimeString();
                entryNode.Text = string.Format("{0}  -  {1}", time, filename);
                entryNode.Tag  = entry;

                if (string.IsNullOrEmpty(entry.CameraIdentifier) || !tvCaptureHistory.ImageList.Images.ContainsKey(entry.CameraIdentifier))
                {
                    entryNode.ImageKey = "unknownCamera";
                }
                else
                {
                    entryNode.ImageKey = entry.CameraIdentifier;
                }

                entryNode.SelectedImageKey = entryNode.ImageKey;

                sessionNode.Nodes.Add(entryNode);
            }
        }
        private void btnImportHistory_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog fbd = new FolderBrowserDialog();

            fbd.ShowNewFolderButton = false;
            fbd.RootFolder          = Environment.SpecialFolder.Desktop;

            if (fbd.ShowDialog() == DialogResult.OK && fbd.SelectedPath.Length > 0)
            {
                CaptureHistory.ImportDirectory(fbd.SelectedPath);
                ReloadCaptureHistory(true);
            }
        }
예제 #3
0
        private void StopRecording()
        {
            if (!cameraLoaded || !recording || !consumerRecord.Active)
            {
                return;
            }

            recording = false;
            consumerRecord.Deactivate();
            view.Toast(ScreenManagerLang.Toast_StopRecord, 750);

            NotificationCenter.RaiseRefreshFileExplorer(this, false);

            if (recordingThumbnail != null)
            {
                AddCapturedFile(consumerRecord.Filename, recordingThumbnail, true);
                recordingThumbnail.Dispose();
                recordingThumbnail = null;
            }

            CaptureHistoryEntry entry = CreateHistoryEntry();

            CaptureHistory.AddEntry(entry);

            // We need to use the original filename with patterns still in it.
            string filenameWithoutExtension = view.CurrentVideoFilename;

            if (index == 0)
            {
                PreferencesManager.CapturePreferences.CapturePathConfiguration.LeftVideoFile = filenameWithoutExtension;
            }
            else
            {
                PreferencesManager.CapturePreferences.CapturePathConfiguration.RightVideoFile = filenameWithoutExtension;
            }

            PreferencesManager.Save();

            string next = Filenamer.ComputeNextFilename(filenameWithoutExtension);

            view.UpdateNextVideoFilename(next);

            view.UpdateRecordingStatus(recording);
        }
        private void DeleteSelectedVideo(TreeView tv)
        {
            if (!tv.Focused)
            {
                return;
            }

            if (tv.SelectedNode == null)
            {
                return;
            }

            CaptureHistoryEntry entry = tv.SelectedNode.Tag as CaptureHistoryEntry;

            if (entry == null)
            {
                return;
            }

            TreeNode parent = tv.SelectedNode.Parent;

            if (parent == null)
            {
                return;
            }

            string session = parent.Tag as string;

            string path = entry.CaptureFile;

            if (path == null)
            {
                return;
            }

            FilesystemHelper.DeleteFile(path);
            if (!File.Exists(path))
            {
                CaptureHistory.RemoveEntry(session, entry);
                ReloadCaptureHistoryExpandedSessions();
            }
        }
        public void ReloadCaptureHistory(bool clear)
        {
            //------------------------------------------------------------------------------------------------------
            // Capture history tree view update mechanics.
            // 1. Deleting a file, we only need to refresh the session node where the deleted file was. We use ReloadCaptureHistoryExpandedNodes alone.
            // 2. Adding a file through recording. We need to reload the whole list because it could be the first file for today.
            // We need to add the new session node. But we also want to keep the current expanded nodes.
            // For this, we use the parallel dictionary (captureHistoryNodes) keeping track of the currently added nodes, whether days or months.
            // 3. When importing from an existing directory we must insert the new nodes at the correct chronological place.
            // For this, we clear and recreate the whole list for simplicity.
            //
            // This function is only concerned with the top level hierarchy (days and months), not the individual files.
            //------------------------------------------------------------------------------------------------------

            if (clear)
            {
                captureHistoryNodes.Clear();
                tvCaptureHistory.Nodes.Clear();
            }

            IEnumerable <string> sessions = CaptureHistory.GetRoots();

            foreach (string session in sessions)
            {
                if (captureHistoryNodes.ContainsKey(session))
                {
                    continue;
                }

                // Find the correct place to insert this node.
                DateTime dt;
                bool     parsed = DateTime.TryParseExact(session, "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None, out dt);

                if (!parsed)
                {
                    TreeNode node = CreateCaptureHistoryNode(session);
                    node.Text = session;

                    tvCaptureHistory.Nodes.Add(node);
                    captureHistoryNodes.Add(session, node);
                }
                else
                {
                    TreeNode node = CreateCaptureHistoryNodeDated(session, dt);

                    TimeSpan age = DateTime.Now - dt;
                    if (age.TotalDays < 30)
                    {
                        tvCaptureHistory.Nodes.Add(node);
                        captureHistoryNodes.Add(session, node);
                    }
                    else
                    {
                        // Archived session (stored by month).
                        string archiveName = string.Format("{0:yyyy-MM}", dt);

                        if (!captureHistoryNodes.ContainsKey(archiveName))
                        {
                            TreeNode archiveNode = CreateCaptureHistoryNodeArchive(archiveName);

                            tvCaptureHistory.Nodes.Add(archiveNode);
                            captureHistoryNodes.Add(archiveName, archiveNode);
                        }

                        TreeNode parent = captureHistoryNodes[archiveName];
                        parent.Nodes.Add(node);
                        captureHistoryNodes.Add(session, node);
                    }
                }
            }
        }
예제 #6
0
        private void MakeSnapshot()
        {
            if (!cameraLoaded || consumerDisplay.Bitmap == null)
            {
                return;
            }

            string root;
            string subdir;

            if (index == 0)
            {
                root   = PreferencesManager.CapturePreferences.CapturePathConfiguration.LeftImageRoot;
                subdir = PreferencesManager.CapturePreferences.CapturePathConfiguration.LeftImageSubdir;
            }
            else
            {
                root   = PreferencesManager.CapturePreferences.CapturePathConfiguration.RightImageRoot;
                subdir = PreferencesManager.CapturePreferences.CapturePathConfiguration.RightImageSubdir;
            }

            string filenameWithoutExtension = view.CurrentImageFilename;
            string extension = Filenamer.GetImageFileExtension();

            Dictionary <FilePatternContexts, string> context = BuildCaptureContext();

            string path = Filenamer.GetFilePath(root, subdir, filenameWithoutExtension, extension, context);

            FilesystemHelper.CreateDirectory(path);

            if (!FilePathSanityCheck(path))
            {
                return;
            }

            if (!OverwriteCheck(path))
            {
                return;
            }

            //Actual save.
            Bitmap outputImage = BitmapHelper.Copy(consumerDisplay.Bitmap);

            if (outputImage == null)
            {
                return;
            }

            ImageHelper.Save(path, outputImage);
            view.Toast(ScreenManagerLang.Toast_ImageSaved, 750);

            // After save routines.
            NotificationCenter.RaiseRefreshFileExplorer(this, false);

            AddCapturedFile(path, outputImage, false);
            CaptureHistoryEntry entry = CreateHistoryEntrySnapshot(path);

            CaptureHistory.AddEntry(entry);

            if (index == 0)
            {
                PreferencesManager.CapturePreferences.CapturePathConfiguration.LeftImageFile = filenameWithoutExtension;
            }
            else
            {
                PreferencesManager.CapturePreferences.CapturePathConfiguration.RightImageFile = filenameWithoutExtension;
            }

            PreferencesManager.Save();

            // Compute next name for user feedback.
            string next = Filenamer.ComputeNextFilename(filenameWithoutExtension);

            view.UpdateNextImageFilename(next);
        }