コード例 #1
0
        /// <summary>
        /// updates the actual GUI with the status information received as parameter
        /// If the StatusUpdate indicates that the job has ended, the Progress window is closed
        /// and the logging messages from the StatusUpdate object are added to the log tab
        /// if the job mentioned in the statusupdate has a next job name defined, the job is looked
        /// up and processing of that job starts - this applies even in queue encoding mode
        /// the linked jobs will always be encoded first, regardless of their position in the queue
        /// If we're in queue encoding mode, the next nob in the queue is also started
        /// </summary>
        /// <param name="su">StatusUpdate object containing the current encoder stats</param>
        private void UpdateGUIStatus(StatusUpdate su)
        {
            if (su.IsComplete)
            {
                JobFinished(su);
                return;
            }

            // job is not complete yet
            try
            {
                if (pw.IsHandleCreated && pw.Visible) // the window is there, send the update to the window
                {
                    TaggedJob job = mainForm.Jobs.ByName(su.JobName);
                    su.JobStatus = job.Status;
                    if (job.Status != JobStatus.PAUSED)
                    {
                        pw.BeginInvoke(new UpdateStatusCallback(pw.UpdateStatus), su);
                    }
                }
            }
            catch (Exception e)
            {
                mainForm.Log.LogValue("Error trying to update status while a job is running", e, ImageType.Warning);
            }

            if (su.PercentageDoneExact > 100)
            {
                progress = 100;
            }
            else
            {
                progress = su.PercentageDoneExact ?? 0;
            }
            UpdateProgress();
        }
コード例 #2
0
        /// <summary>
        /// updates the actual GUI with the status information received as parameter
        /// If the StatusUpdate indicates that the job has ended, the Progress window is closed
        /// and the logging messages from the StatusUpdate object are added to the log tab
        /// if the job mentioned in the statusupdate has a next job name defined, the job is looked
        /// up and processing of that job starts - this applies even in queue encoding mode
        /// the linked jobs will always be encoded first, regardless of their position in the queue
        /// If we're in queue encoding mode, the next nob in the queue is also started
        /// </summary>
        /// <param name="su">StatusUpdate object containing the current encoder stats</param>
        private void UpdateGUIStatus(StatusUpdate su)
        {
            if (su.IsComplete)
            {
                // so we don't lock up the GUI, we start a new thread
                Thread t = new Thread(new ThreadStart(delegate
                {
                    TaggedJob job = mainForm.Jobs.ByName(su.JobName);

                    copyInfoIntoJob(job, su);
                    progress = 0;
                    HideProcessWindow();

                    // Postprocessing
                    bool jobFailed = (job.Status != JobStatus.PROCESSING);
                    if (!jobFailed)
                    {
                        postprocessJob(job.Job);
                        job.Status = JobStatus.DONE;
                    }

                    currentProcessor = null;
                    currentJob       = null;

                    // Logging
                    log.LogEvent("Job completed");
                    log.Collapse();

                    if (!jobFailed && mainForm.Settings.DeleteCompletedJobs)
                    {
                        mainForm.Jobs.RemoveCompletedJob(job);
                    }
                    else
                    {
                        mainForm.Jobs.saveJob(job, mainForm.MeGUIPath);     //AAA: save state more often
                    }
                    if (shutdownWorkerIfJobsCompleted())
                    {
                    }
                    else if (job.Status == JobStatus.ABORTED)
                    {
                        log.LogEvent("Current job was aborted");
                        status = JobWorkerStatus.Idle;
                    }
                    else if (status == JobWorkerStatus.Stopping)
                    {
                        log.LogEvent("Queue mode stopped");
                        status = JobWorkerStatus.Idle;
                    }
                    else
                    {
                        switch (startNextJobInQueue())
                        {
                        case JobStartInfo.JOB_STARTED:
                            break;

                        case JobStartInfo.COULDNT_START:
                            status = JobWorkerStatus.Idle;
                            break;

                        case JobStartInfo.NO_JOBS_WAITING:
                            status = JobWorkerStatus.Idle;
                            new Thread(delegate()
                            {
                                WorkerFinishedJobs(this, EventArgs.Empty);
                            }).Start();
                            break;
                        }
                    }

                    refreshAll();
                }));
                t.IsBackground = true;
                t.Start();
            }
            else // job is not complete yet
            {
                try
                {
                    if (pw.IsHandleCreated && pw.Visible) // the window is there, send the update to the window
                    {
                        pw.BeginInvoke(new UpdateStatusCallback(pw.UpdateStatus), su);
                    }
                }
                catch (Exception e)
                {
                    mainForm.Log.LogValue("Error trying to update status while a job is running", e, ImageType.Warning);
                }

                progress = su.PercentageDoneExact ?? 0;
                updateProgress();
            }
        }
コード例 #3
0
ファイル: Save.cs プロジェクト: andyvand/ProcessHacker
        public static void SaveToFile(IWin32Window owner)
        {
            SaveFileDialog sfd = new SaveFileDialog();

            // HTML Files (*.htm;*.html)|*.htm;*.html
            sfd.Filter = "Process Hacker Dump Files (*.phi)|*.phi|Text Files (*.txt;*.log)|*.txt;*.log|" + 
                "Comma-separated values (*.csv)|*.csv|All Files (*.*)|*.*";

            //if (Program.HackerWindow.SelectedPid == -1)
            //{
            //    sfd.FileName = "Process List.txt";
            //}
            //else
            //{
            //    string processName = Windows.GetProcessName(Program.HackerWindow.SelectedPid);

            //    if (processName != null)
            //        sfd.FileName = processName + ".txt";
            //    else
            //        sfd.FileName = "Process Info.txt";
            //}
            sfd.FileName = "phdump-" + DateTime.Now.ToString("ddMMyy") + ".phi";

            if (sfd.ShowDialog() == DialogResult.OK)
            {
                FileInfo fi = new FileInfo(sfd.FileName);
                string ext = fi.Extension.ToLowerInvariant();

                if (ext == ".phi")
                {
                    ThreadTask dumpTask = new ThreadTask();

                    dumpTask.RunTask += delegate(object result, ref object param)
                    {
                        var mfs = Dump.BeginDump(fi.FullName, ProcessHacker.Native.Mfs.MfsOpenMode.OverwriteIf);

                        Dump.DumpProcesses(mfs, Program.ProcessProvider);
                        Dump.DumpServices(mfs);

                        mfs.Dispose();
                    };

                    ProgressWindow progressWindow = new ProgressWindow();

                    progressWindow.CloseButtonVisible = false;
                    progressWindow.ProgressBarStyle = ProgressBarStyle.Marquee;
                    progressWindow.ProgressText = "Creating the dump file...";

                    dumpTask.Completed += (result) =>
                    {
                        progressWindow.SetCompleted();

                        if (progressWindow.IsHandleCreated)
                            progressWindow.BeginInvoke(new MethodInvoker(progressWindow.Close));
                    };

                    dumpTask.Start();

                    if (dumpTask.Running)
                        progressWindow.ShowDialog(owner);

                    if (dumpTask.Exception != null)
                        PhUtils.ShowException("Unable to create the dump file", dumpTask.Exception);

                    return;
                }

                try
                {
                    using (StreamWriter sw = new StreamWriter(fi.FullName))
                    {
                        Program.HackerWindow.ProcessTree.Tree.ExpandAll();

                        if (ext == ".htm" || ext == ".html")
                        {

                        }
                        else if (ext == ".csv")
                        {
                            sw.Write(GetProcessTreeText(false));
                        }
                        else
                        {
                            sw.Write(GetEnvironmentInfo());
                            sw.WriteLine();
                            sw.Write(GetProcessTreeText(true));
                            sw.WriteLine();

                            if (Program.HackerWindow.SelectedPid != -1)
                            {
                                sw.Write(GetProcessDetailsText(Program.HackerWindow.SelectedPid));
                                sw.WriteLine();
                            }
                        }
                    }
                }
                catch (IOException ex)
                {
                    PhUtils.ShowException("Unable to save the process list", ex);
                }
            }
        }
コード例 #4
0
        /// <summary>
        /// updates the actual GUI with the status information received as parameter
        /// If the StatusUpdate indicates that the job has ended, the Progress window is closed
        /// and the logging messages from the StatusUpdate object are added to the log tab
        /// if the job mentioned in the statusupdate has a next job name defined, the job is looked
        /// up and processing of that job starts - this applies even in queue encoding mode
        /// the linked jobs will always be encoded first, regardless of their position in the queue
        /// If we're in queue encoding mode, the next nob in the queue is also started
        /// </summary>
        /// <param name="su">StatusUpdate object containing the current encoder stats</param>
        private void UpdateGUIStatus(StatusUpdate su)
        {
            if (su.IsComplete)
            {
                // so we don't lock up the GUI, we start a new thread
                Thread t = new Thread(new ThreadStart(delegate
                {
                    TaggedJob job = mainForm.Jobs.ByName(su.JobName);

                    copyInfoIntoJob(job, su);
                    progress = 0;
                    //ensureProgressWindowClosed();
                    HideProcessWindow();
                    currentProcessor = null;
                    currentJob       = null;

                    // Logging
                    addToLog("Processing ended at " + DateTime.Now.ToLongTimeString() + "\r\n");
                    addToLog("------------------------------------------------------" +
                             "\r\n\r\nLog for job " + su.JobName + "\r\n\r\n" + su.Log +
                             "\r\n------------------------------------------------------\r\n");

                    // Postprocessing
                    bool jobCompletedSuccessfully = (job.Status == JobStatus.DONE);
                    if (jobCompletedSuccessfully)
                    {
                        postprocessJob(job.Job);
                    }

                    if (jobCompletedSuccessfully && mainForm.Settings.DeleteCompletedJobs)
                    {
                        mainForm.Jobs.RemoveCompletedJob(job);
                    }

                    addToLog("End of log for " + job.Name + "\r\n" +
                             "------------------------------------------------------\r\n\r\n");

                    if (shutdownWorkerIfJobsCompleted())
                    {
                    }
                    else if (job.Status == JobStatus.ABORTED)
                    {
                        addToLog("The current job was aborted. Stopping queue mode\r\n");
                        status = JobWorkerStatus.Idle;
                    }
                    else if (status == JobWorkerStatus.Stopping)
                    {
                        addToLog("Told to stop. Stopping queue mode.\r\n");
                        status = JobWorkerStatus.Idle;
                    }
                    else
                    {
                        switch (startNextJobInQueue())
                        {
                        case JobStartInfo.JOB_STARTED:
                            break;

                        case JobStartInfo.COULDNT_START:
                            status = JobWorkerStatus.Idle;
                            break;

                        case JobStartInfo.NO_JOBS_WAITING:
                            status = JobWorkerStatus.Idle;
                            new Thread(delegate()
                            {
                                WorkerFinishedJobs(this, EventArgs.Empty);
                            }).Start();
                            break;
                        }
                    }

                    refreshAll();
                }));
                t.IsBackground = true;
                t.Start();
            }
            else // job is not complete yet
            {
                try
                {
                    if (pw.IsHandleCreated && pw.Visible) // the window is there, send the update to the window
                    {
                        pw.BeginInvoke(new UpdateStatusCallback(pw.UpdateStatus), su);
                    }
                }
                catch (Exception e)
                {
                    mainForm.addToLog("Exception when trying to update status while a job is running. Text: " + e.Message + " stacktrace: " + e.StackTrace);
                }

                progress = su.PercentageDoneExact ?? 0;
                updateProgress();

                /*
                 * string percentage = (su.PercentageDoneExact ?? 0M).ToString("##.##");
                 * if (percentage.IndexOf(".") != -1 && percentage.Substring(percentage.IndexOf(".")).Length == 1)
                 *  percentage += "0";
                 * mainForm.TitleText = "MeGUI " + su.JobName + " " + percentage + "% ";
                 * if (mainForm.Settings.AfterEncoding == AfterEncoding.Shutdown)
                 *  mainForm.TitleText += "- SHUTDOWN after encode";
                 * this.jobProgress.Value = su.PercentageDone;*/
            }
        }