Example #1
0
        private void TidyFiles(ThreadDataBundle bundle)
        {
            File.Copy(bundle.TempOutputFileName, bundle.OutputPath, true);

            if (bundle.TempOutputFileName != bundle.TempFileName) // prevents us trying to delete files that do not exist
                File.Delete(bundle.TempOutputFileName);

            File.Delete(bundle.TempFileName);
        }
Example #2
0
        private void NotificationHandler(ThreadDataBundle bundle)
        {
            lock (_notifyLock)
            {
                progress.BeginInvoke(new Action(() => progress.Increment(1)));

                notification.BeginInvoke(new Action(() =>
                {
                    completed++;
                    if (completed != total)
                        notification.Text = string.Format("{0}/{1} files processed", completed, total);
                    else
                        notification.Text = "All files processed; operation completed";

                    if (errors > 0)
                    {
                        if(errors == 1)
                            notification.Text = string.Format("{0} (An error have occurred, see log for details)", notification.Text);
                        else
                            notification.Text = string.Format("{0} ({1} errors have occurred, see log for details)", notification.Text, errors);
                    }
                }));

                selection.BeginInvoke(new Action(() => selection.Items.Remove(bundle.AssociatedListItem)));
            }
        }
Example #3
0
        private void ProcessLog(ThreadDataBundle bundle)
        {
            lock (_fileLock)
            {
                logBox.BeginInvoke(new Action(() =>
                {
                    if (useLog.Checked)
                    {
                        File.AppendAllText(logPath.Text, bundle.ExecutionStandardOutput);
                        File.AppendAllText(logPath.Text, bundle.ExecutionStandardError);
                    }

                    logBox.AppendText(bundle.ExecutionStandardOutput);
                    logBox.AppendText(bundle.ExecutionStandardError);
                }));
            }
        }
Example #4
0
        private bool ExecuteOptiPNG(string execPath, string args, ThreadDataBundle bundle)
        {
            // ready the temp file
            File.Copy(bundle.InputPath, bundle.TempFileName, true);

            Process proc = new Process
            {
                StartInfo = new ProcessStartInfo
                {
                    WindowStyle = ProcessWindowStyle.Hidden,
                    FileName = execPath,
                    RedirectStandardOutput = true,
                    RedirectStandardError = true,
                    Arguments = string.Format("{1} {0}", bundle.TempFileName, args),
                    UseShellExecute = false, // allows for stdout and stderr redirection
                    CreateNoWindow = true // this stops console windows appearing and grabbing focus
                },
            };

            proc.Start();

            bundle.SetStandardOutput(proc.StandardOutput.ReadToEnd().Replace(bundle.TempOutputFileName, bundle.OutputPath).Replace(bundle.TempFileName, bundle.InputPath));
            bundle.SetStandardError(proc.StandardError.ReadToEnd().Replace(bundle.TempOutputFileName, bundle.OutputPath).Replace(bundle.TempFileName, bundle.InputPath));

            proc.WaitForExit();

            if (proc.ExitCode == 2) // examining the optipng source lead me to believe this errorcode is given when an error occurs; may be wrong however
                return false;

            return true;
        }