Ejemplo n.º 1
0
        private void LoadProfile(ProfileHandler.Profile profile)
        {
            if (profile == null)
            {
                log.debug("Skipping profile load, got null pointer");
                return;
            }
            log.debug("Loading profile {0}", profile.name);

            setResizeMetdhod(profile.method);
            widthTB.Text  = profile.width.ToString();
            heightTB.Text = profile.height.ToString();

            Settings.Default.activeProfile = profile.name;
            Settings.Default.Save();
        }
Ejemplo n.º 2
0
        /* Returns the current conversion parameters. Called from the background worker.
         */
        ProfileHandler.Profile get_current_params()
        {
            ProfileHandler.Profile p;

            try
            {
                p = new ProfileHandler.Profile("dummy",
                                               ((ResizeMethod)resizeMethodCmBx.SelectedItem).method,
                                               Convert.ToInt32(widthTB.Text),
                                               Convert.ToInt32(heightTB.Text),
                                               false);

                p.input_folder  = this.inputFolderTB.Text;
                p.output_folder = this.outputFolderTB.Text;
            }
            catch (Exception ex)
            {
                log.error("Unable to obtain current conversion parameters to return into the worker thread");
                log.debug(ex.ToString());
                p = null;
            }
            return(p);
        }
Ejemplo n.º 3
0
        private void backgroundProcessor_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker = sender as BackgroundWorker;

            e.Result = null;

            ProfileHandler.Profile conversion_params = null;

            log.debug("Getting conversion params from main thread");

            // Get the parameters from the main thread
            Invoke(new MethodInvoker(delegate
            {
                conversion_params = get_current_params();
            }
                                     ));

            if (conversion_params == null)
            {
                log.error("Unable to retrieve conversion params, aborting working thread");
                e.Result = this.get_lang_string("dialog_worker_params_retr_err");
                return;
            }

            // Check we have a valid folder
            if (!Directory.Exists(conversion_params.input_folder))
            {
                log.error("Input directory '{0}' does not exist", conversion_params.input_folder);
                MessageBox.Show(String.Format("{0}:\r\n{1}", this.get_lang_string("dialog_input_directory_not_exists_full"), conversion_params.input_folder),
                                this.get_lang_string("dialog_input_directory_not_exists_caption"),
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                e.Cancel = true;    // Mark result on GUI as operation canceled
                return;
            }
            log.info("Input folder: {0}", conversion_params.input_folder);
            if (Directory.Exists(conversion_params.output_folder))
            {
                log.error("Output directory '{0}' exist.", conversion_params.output_folder);
                MessageBox.Show(String.Format("{0}:\r\n{1}", this.get_lang_string("dialog_output_directory_exists_full"), conversion_params.output_folder),
                                this.get_lang_string("dialog_output_directory_exists_caption"),
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                e.Cancel = true;    // Mark result on GUI as operation canceled
                return;
            }
            log.info("Output folder: {0}", conversion_params.output_folder);

            // Create output folder if it doesn't exist
            if (Directory.Exists(conversion_params.output_folder))
            {
                log.debug("Output folder exists");
            }
            else
            {
                log.info("Output folder does not exist. Creating it...");
                try
                {
                    Directory.CreateDirectory(conversion_params.output_folder);
                }
                catch (Exception ex)
                {
                    log.error("Unable to create output folder");
                    log.debug(ex.ToString());
                    MessageBox.Show(this.get_lang_string("dialog_cannot_create_out_dir_full"),
                                    this.get_lang_string("dialog_cannot_create_out_dir_caption"),
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);

                    return;
                }
                log.debug("Output folder succesfully created");
            }

            // Locate the available images
            string[] all_files = Directory.GetFiles(conversion_params.input_folder);

            // Filter files per extension
            List <String> files      = new List <string>();
            int           file_count = all_files.Length;

            for (int i = 0; i < file_count; i++)
            {
                string file = all_files[i];
                string ext  = Path.GetExtension(file).ToLower();

                if (ext == ".jpg" || ext == ".jpeg")
                {
                    files.Add(file);
                }
                else
                {
                    log.warning("Unsupported file extension: {0}", ext);
                }
            }

            file_count = files.Count;

            log.debug("Located {0} matching files on input directory", file_count);

            for (int i = 0; i < file_count; i++)
            {
                if (worker.CancellationPending == true)
                {
                    e.Cancel = true;
                    break;
                }

                string file  = Path.GetFileName(files[i]);
                string ffile = Path.Combine(conversion_params.input_folder, file);
                string ext   = Path.GetExtension(file).ToLower();

                log.debug("Processing {0}", ffile);
                worker.ReportProgress(100 * i / file_count, string.Format("{0}/{1} - {2}", i, file_count, file));

                if (ext == ".jpg" || ext == ".jpeg")
                {
                    resize_image(ffile,
                                 conversion_params.output_folder,
                                 conversion_params.method,
                                 conversion_params.width,
                                 conversion_params.height
                                 );
                }
                else
                {
                    log.warning("Unsupported file extension: {0}", ext);
                }
            }
        }
Ejemplo n.º 4
0
        /* Returns the current conversion parameters. Called from the background worker.
         */
        ProfileHandler.Profile get_current_params()
        {
            ProfileHandler.Profile p;

            try
            {
                p = new ProfileHandler.Profile("dummy",
                    ((ResizeMethod)resizeMethodCmBx.SelectedItem).method,
                    Convert.ToInt32(widthTB.Text),
                    Convert.ToInt32(heightTB.Text),
                    false);

                p.input_folder = this.inputFolderTB.Text;
                p.output_folder = this.outputFolderTB.Text;
            }
            catch (Exception ex)
            {
                log.error("Unable to obtain current conversion parameters to return into the worker thread");
                log.debug(ex.ToString());
                p = null;
            }
            return p;
        }