Beispiel #1
0
        public static ConvertParams GetConvertedParams(ConvertParams param, Thumb thumb)
        {
            ConvertParams result = new ConvertParams();

            result.extension = param.extension;
            result.filename = Path.ChangeExtension(String.Format("{0}_{1}", Path.GetFileNameWithoutExtension(param.filename), thumb.name), param.extension);
            result.filepath = Path.Combine(Path.GetDirectoryName(param.filepath), result.filename);

            return result;
        }
Beispiel #2
0
        private void ConvertFiles(string[] files, Thumb thumb)
        {
            ProgressInit(files.Length);

            string OutString = "";

            BackgroundWorker bgw = new BackgroundWorker();
            bgw.WorkerReportsProgress = true;

            bgw.DoWork += delegate (object o, DoWorkEventArgs dwea)
            {
                for (int i = 0; i < files.Length; ++i)
                {
                    try
                    {
                        ConvertParams oldparams = ConvertParams.GetParams(files[i]);
                        ConvertParams newparams = ConvertParams.GetConvertedParams(oldparams, thumb);

                        if(!ConvertParams.ConvertFile(oldparams, newparams, thumb))
                            OutString += newparams.filename + " already exists. Skipping.\n";

                        bgw.ReportProgress(i+1);
                    }
                    catch (Exception x)
                    {
                        OutString += x.Message + "\n" + x.StackTrace + "\n";
                    }
                }
            };

            bgw.ProgressChanged += delegate (object o, ProgressChangedEventArgs pcea)
            {
                ProgressStep(ofd.FileNames.Length, pcea.ProgressPercentage);
            };

            bgw.RunWorkerCompleted += delegate (object o, RunWorkerCompletedEventArgs rwcea)
            {
                OutString += "Completed.";
                MessageBox.Show(OutString);
                ProgressFinish();
            };

            bgw.RunWorkerAsync();
        }
Beispiel #3
0
        public static bool ConvertFile(ConvertParams oldparams, ConvertParams newparams, Thumb thumb)
        {
            if (File.Exists(newparams.filepath))
                return false;

            string parameters = String.Format("-o \"{0}\" -overwrite -quiet -out {3} -ratio -resize {2} 0 \"{1}\"", 
                newparams.filepath, 
                oldparams.filepath, 
                thumb.width, 
                newparams.IsPng() ? "png" : "jpeg");

            ProcessStartInfo info = new ProcessStartInfo("nconvert.exe", parameters);
            info.CreateNoWindow = true;
            info.WindowStyle = ProcessWindowStyle.Hidden;

            Process proc = Process.Start(info);
            proc.WaitForExit();

            return true;
        }