Esempio n. 1
0
 protected override void OnShown(EventArgs e)
 {
     if (!DesignMode)
     {
         //Utils.UpdateFont(this, Utils.GetDefaultFont());
         #if !ExtLang
         LanguageManager.Localize(this);
         #endif
     }
     base.OnShown(e);
 }
Esempio n. 2
0
        //public ErrorReport(string msg, Exception ex, Config conf) : this(String.Concat("Error reading from registry: ", msg), ex, conf, null)
        public CrashReport(string msg, Exception ex, SettingsApp settings, ListView lv)
        {
#if LOG
            Log.Write(LogLevel.Info, "ErrorReporting.");
#endif

            InitializeComponent();

#if !ExtLang
            LanguageManager.Localize(this);
#endif

            if (msg == null)
            {
                labelError.Text = LanguageManager.GetString("Crash_UnknownError");//"An unknown error has occurred. WallpaperChanger cannot continue.";
            }
            else
            {
                labelError.Text = msg;
            }

            // Set picturebox to error
            this.pictureBoxErr.Image = SystemIcons.Error.ToBitmap();

            try
            {
                CaptureScreenshot captureScreenshot = new CaptureScreenshot();
                _screenShot = string.Format(@"{0}\{1} Crash Screenshot.png", Path.GetTempPath(), AssemblyHelper.AssemblyTitle);
                captureScreenshot.CaptureScreenToFile(_screenShot, ImageFormat.Png);
            }
            catch (Exception e)
            {
                Debug.Write(e.Message);
            }
            if (File.Exists(_screenShot))
            {
                pictureBoxScreenshot.ImageLocation = _screenShot;
                pictureBoxScreenshot.Show();
            }

            CultureInfo oldCulture = Thread.CurrentThread.CurrentCulture;
            if (oldCulture.Parent.Name != "ru")
            {
                //Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en");
                Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("en");
                // throw new Exception here => Culture is in english
                //MessageBox.Show(new FileNotFoundException().Message);
            }

            StringBuilder sb = new StringBuilder();

            if (ex != null)
            {
                sb.AppendLine(ex.Message);
            }
            sb.AppendLine();

            //programm and versions
            //sb.AppendLine(Application.ProductName);
            sb.AppendLine(AssemblyHelper.AssemblyTitle);
            //sb.AppendLine(Application.ProductVersion);
            sb.AppendLine(string.Format("Version: {0}", AssemblyHelper.AssemblyVersion));
            sb.AppendLine(AssemblyHelper.AssemblyBuildDate);

            Process proc = Process.GetCurrentProcess();
            // dates and time
            sb.AppendLine(string.Format("Current Date/Time: {0}", DateTime.Now.ToString()));
            sb.AppendLine(string.Format("Current UtcDate/Time: {0}", DateTime.UtcNow.ToString()));
            sb.AppendLine(string.Format("Process Date/Time: {0}", proc.StartTime.ToString()));
            //sb.AppendLine(string.Format("Build Date: {0}", Properties.Settings.Default.strBuildTime));
            // os info
            sb.AppendLine(string.Format("OS: {0}", Environment.OSVersion.VersionString));
            sb.AppendLine(string.Format("OS info: {0}", getOSInfo()));
            sb.AppendLine(string.Format(".NET Framework (CLR): {0}", Environment.Version.ToString()));
            sb.AppendLine(string.Format("Language: {0}", Application.CurrentCulture.ToString()));
            sb.AppendLine(string.Format("CurrentCulture: {0}", System.Threading.Thread.CurrentThread.CurrentCulture.ToString()));
            sb.AppendLine(string.Format("CurrentUICulture: {0}", System.Threading.Thread.CurrentThread.CurrentUICulture.ToString()));
            // uptime stats
            sb.AppendLine(string.Format("System Uptime: {0} Days {1} Hours {2} Mins {3} Secs", Math.Round((decimal)Environment.TickCount / 86400000), Math.Round((decimal)Environment.TickCount / 3600000 % 24), Math.Round((decimal)Environment.TickCount / 120000 % 60), Math.Round((decimal)Environment.TickCount / 1000 % 60)));
            sb.AppendLine(string.Format("Program Uptime: {0}", proc.TotalProcessorTime.ToString()));
            // process id
            sb.AppendLine(string.Format("PID: {0}", proc.Id));
            // exe name
            sb.AppendLine(string.Format("Executable: {0}", Application.ExecutablePath));
            sb.AppendLine(string.Format("Process Name: {0}", proc.ToString()));
            sb.AppendLine(string.Format("Main Module Name: {0}", proc.MainModule.ModuleName));
            // exe stats
            sb.AppendLine(string.Format("Module Count: {0}", proc.Modules.Count));
            sb.AppendLine(string.Format("Thread Count: {0}", proc.Threads.Count));
            sb.AppendLine(string.Format("Thread ID: {0}", System.Threading.Thread.CurrentThread.ManagedThreadId));
            sb.AppendLine(string.Format("Is Debugged: {0}", Debugger.IsAttached));

            sb.AppendLine();
            sb.AppendLine("Running processes: ");
            foreach (System.Diagnostics.Process winProc in System.Diagnostics.Process.GetProcesses())
            {
                //sb.AppendLine(string.Format("{0}: {1} {2}", winProc.Id, winProc.ProcessName, winProc.MainWindowTitle));
                sb.Append(string.Format("{0}: {1}, ", winProc.Id, winProc.ProcessName));
            }
            sb.AppendLine();

            if (settings == null)
            {
                sb.AppendLine("Settings unknown.");
                sb.AppendLine();
            }
            else
            {
                sb.AppendLine("Settings:");
                sb.AppendLine(string.Format("IsConfirmDelete: {0}", settings.Fields.IsConfirmDelete));
                sb.AppendLine(string.Format("IsCheckUpdate: {0}", settings.Fields.IsCheckUpdate));
                sb.AppendLine(string.Format("IsOrientationVert: {0}", settings.Fields.IsOrientationVert));
                sb.AppendLine(string.Format("IsSameFileName: {0}", settings.Fields.IsSameFileName));
                sb.AppendLine(string.Format("IsSaveLoadListDub: {0}", settings.Fields.IsSaveLoadListDub));
                sb.AppendLine(string.Format("IsAllowDelAllFiles: {0}", settings.Fields.IsAllowDelAllFiles));
                sb.AppendLine(string.Format("IsDontUpdateSize: {0}", settings.Fields.IsDontUpdateSize));
                sb.AppendLine(string.Format("IsScanMax: {0}", settings.Fields.IsScanMax));
                sb.AppendLine(string.Format("MaxFile: {0}", settings.Fields.MaxFile));
                sb.AppendLine(string.Format("PathHistoryLength: {0}", settings.Fields.PathHistoryLength));
                sb.AppendLine(string.Format("limits: [{0}, {1}]", settings.Fields.limits[0], settings.Fields.limits[1]));
                sb.AppendLine(string.Format("IncludePattern: {0}", settings.Fields.IncludePattern));
                sb.AppendLine(string.Format("ExcludePattern: {0}", settings.Fields.ExcludePattern));
                sb.AppendLine(string.Format("ProgramFont: {0}", settings.Fields.ProgramFont.ToFont().ToString()));
                sb.AppendLine(string.Format("ListRowFont: {0}", settings.Fields.ListRowFont.ToFont().ToString()));
                sb.AppendLine(string.Format("ColorRow1: {0}", settings.Fields.ColorRow1.ToColor().ToString()));
                sb.AppendLine(string.Format("ColorRow2: {0}", settings.Fields.ColorRow2.ToColor().ToString()));
                sb.AppendLine(string.Format("ColorRowError: {0}", settings.Fields.ColorRowError.ToColor().ToString()));
                sb.AppendLine(string.Format("ColorColorRowNotExist: {0}", settings.Fields.ColorRowNotExist.ToColor().ToString()));
                sb.AppendLine(string.Format("Language: {0}", settings.Fields.Language));
                sb.AppendLine(string.Format("LastJob: {0}", settings.Fields.LastJob));
                sb.AppendLine(string.Format("FastCheck: {0}", settings.Fields.FastCheck));
                sb.AppendLine(string.Format("FastCheckFileSizeMb: {0}", settings.Fields.FastCheckFileSizeMb));
                sb.AppendLine(string.Format("FastCheckBufferKb: {0}", settings.Fields.FastCheckBufferKb));
                sb.AppendLine(string.Format("UseDB: {0}", settings.Fields.UseDB));
                sb.AppendLine();
            }

            if (lv != null)
            {
                sb.AppendLine("ListView:");
                sb.AppendLine(string.Format("Name: {0}", lv.Name));
                sb.AppendLine(string.Format("Items: {0}", lv.Items.Count));
                sb.AppendLine(string.Format("Groups: {0}", lv.Groups.Count));
                if (lv.Items.Count > 0)
                {
                    sb.AppendLine(string.Format("lv.Items[0].Name: {0}", lv.Items[0].Name));
                    sb.AppendLine(string.Format("lv.Items[0].Text: {0}", lv.Items[0].Text));
                    sb.AppendLine(string.Format("lv.Items[0].Tag: {0}", lv.Items[0].Tag));
                    sb.AppendLine(string.Format("lv.Items[0].Group: {0}", lv.Items[0].Group));
                    sb.AppendLine(string.Format("lv.Items[0].Checked: {0}", lv.Items[0].Checked));
                    sb.AppendLine(string.Format("lv.Items[0].SubItems.Count: {0}", lv.Items[0].SubItems.Count));
                    for (int i = 0; i < lv.Items[0].SubItems.Count; i++)
                    {
                        sb.AppendLine(string.Format("lv.Items[0].SubItems[{0}].Name: {1}", i, lv.Items[0].SubItems[i].Name));
                        sb.AppendLine(string.Format("lv.Items[0].SubItems[{0}].Text: {1}", i, lv.Items[0].SubItems[i].Text));
                        sb.AppendLine(string.Format("lv.Items[0].SubItems[{0}].Tag: {1}", i, lv.Items[0].SubItems[i].Tag));
                    }
                }
                sb.AppendLine();
            }

            sb.AppendLine(string.Format("User Error: {0}", labelError.Text));
            Exception exep = ex;
            for (int i = 0; exep != null; exep = exep.InnerException, i++)
            {
                sb.AppendLine();
                sb.AppendLine(string.Format("Type #{0} {1}", i, ex.GetType().ToString()));

                foreach (System.Reflection.PropertyInfo propInfo in ex.GetType().GetProperties())
                {
                    string fieldName  = string.Format("{0} №{1}", propInfo.Name, i);
                    string fieldValue = string.Format("{0}", propInfo.GetValue(ex, null));

                    // Ignore stack trace + data

                    /*if (propInfo.Name == "StackTrace"
                    || propInfo.Name == "Data"
                    || string.IsNullOrEmpty(propInfo.Name)
                    || string.IsNullOrEmpty(fieldValue))
                    ||  continue;*/
                    if (propInfo.Name == "StackTrace" ||
                        string.IsNullOrEmpty(propInfo.Name) ||
                        string.IsNullOrEmpty(fieldValue))
                    {
                        continue;
                    }

                    sb.AppendLine(string.Format("{0}: {1}", fieldName, fieldValue));
                }

                if (ex.Data != null)
                {
                    foreach (System.Collections.DictionaryEntry de in ex.Data)
                    {
                        sb.AppendLine(string.Format("Dictionary Entry №{0}: Key: {1} Value: {2}", i, de.Key, de.Value));
                    }
                }
            }

            string st;
            if (ex != null)
            {
                if (ex.StackTrace == null)
                {
                    st = new StackTrace(true).ToString();
                }
                else
                {
                    st = ex.StackTrace;
                }
            }
            else
            {
                st = new StackTrace(true).ToString();
            }
            sb.AppendLine("StackTrace:");
            sb.AppendLine(st);

            textBox.Text = sb.ToString();

            Thread.CurrentThread.CurrentCulture = oldCulture;
        }