Ejemplo n.º 1
0
        // Load the code template and then the images from either the database (if it exists) or the actual images (if it doesn't exist)
        private void loadImagesFromSources()
        {
            // First, select a template file which should reside with  the image set, otherwise abort loading (which means the user can try again later)
            // Also pass it the last image folder / template file viewed, which will be shown in the file dialog
            string tpath = persist.ReadLastImageFolderPath();       // the last path opened by the user is stored in the registry
            string filename = persist.ReadLastImageTemplateName();  // the template filname opened by the user is stored in the registry

            tpath = Utilities.GetTemplateFileFromUser(tpath, filename);  // Returns the path and the file name
            if (tpath == null) return;
            // Parse the returned file path to get just the filename and the path to the folder.
            filename = System.IO.Path.GetFileName(tpath);
            if (filename.Equals ("")) filename = Constants.DBTEMPLATEFILENAME;
            persist.WriteLastImageTemplateName(filename);  // We should really do this on exit as well, but I didn't feel like storing it

            tpath = System.IO.Path.GetDirectoryName(tpath);

            if ("" == tpath || null == tpath) return;

            this.FolderPath = tpath;        // We keep the path in two places for convenience of referencing them
            this.dbData.FolderPath = tpath;

            // Create the template to the Timelapse Template database
            this.template = new Template();

            if (!template.Open(this.FolderPath, filename)) return;

            // We now have the template file. Load the TemplateTable from that file, which makes it data accessible through its table
            template.LoadTemplateTable();

            // Find the .ddb file in the image set folder. If a single .ddb file is found, use that one
            // If there are multiple .ddb files, ask the use to choose one and use that
            // However, if the user cancels that choice, just abort.
            // If there are no .ddb files, then just create the standard one.
            switch (this.dbData.FindFile())
            {
                case 0: // An existing .ddb file is available
                    if (this.LoadImagesFromDB(template) == true)
                    {
                        if (state.immediateExit) return;
                        LoadComplete(false);
                    }
                    break;
                case 1: // User cancelled the process of choosing between .ddb files
                    if (state.immediateExit) return;
                    break;
                case 2: // There are no existing .ddb files
                default:
                    if (LoadDByScanningImageFolder() == false)
                    {
                        DlgMessageBox dlgMB = new DlgMessageBox();

                        dlgMB.MessageTitle = "No Images Found in the Image Set Folder";
                        dlgMB.MessageProblem = "There doesn't seem to be any JPG images in your chosen image folder:";
                        dlgMB.MessageProblem += Environment.NewLine + "\u2022 " + this.FolderPath + Environment.NewLine;
                        dlgMB.MessageReason = "\u2022 The folder has no JPG files in it (image files ending in '.jpg'), or" + Environment.NewLine;
                        dlgMB.MessageReason += "\u2022 You may has selected the wrong folder, i.e., a folder other than the one containing the images.";
                        dlgMB.MessageSolution = "\u2022 Check that the chosen folder actually contains JPG images (i.e., a 'jpg' suffix), or" + Environment.NewLine;
                        dlgMB.MessageSolution += "\u2022 Choose another folder.";
                        dlgMB.IconType = MessageBoxImage.Error;
                        dlgMB.ButtonType = MessageBoxButton.OK;
                        dlgMB.ShowDialog();
                        return;
                    }
                    break;
            }
            state.isContentChanged = false; // We've altered some content

            // For persistance: set a flag if We've opened the same image folder we worked with in the last session.
            // If its different, saved the new folder path
            this.ImageFolderReopened = (tpath == this.FolderPath) ? true : false;
        }