Example #1
0
        private void SetTitleText()
        {
            if (this.appWorkspace == null)
            {
                return;
            }

            if (this.appWorkspace.ActiveDocumentWorkspace == null)
            {
                this.Text = PdnInfo.GetAppName();
            }
            else
            {
                string appTitle     = PdnInfo.GetAppName();
                string ratio        = string.Empty;
                string title        = string.Empty;
                string friendlyName = this.appWorkspace.ActiveDocumentWorkspace.GetFriendlyName();
                string text;

                if (this.WindowState != FormWindowState.Minimized)
                {
                    string format = PdnResources.GetString("MainForm.Title.Format.Normal");
                    text = string.Format(format, friendlyName, appWorkspace.ActiveDocumentWorkspace.ScaleFactor, appTitle);
                }
                else
                {
                    string format = PdnResources.GetString("MainForm.Title.Format.Minimized");
                    text = string.Format(format, friendlyName, appTitle);
                }

                if (appWorkspace.ActiveDocumentWorkspace.Document != null)
                {
                    title = text;
                }

                this.Text = title;
            }
        }
Example #2
0
        public MainForm(string[] args)
        {
            bool canSetCurrentDir = true;

            this.StartPosition = FormStartPosition.WindowsDefaultLocation;

            bool          splash    = false;
            List <string> fileNames = new List <string>();

            // Parse command line arguments
            foreach (string argument in args)
            {
                if (0 == string.Compare(argument, "/dontForceGC"))
                {
                    Utility.AllowGCFullCollect = false;
                }
                else if (0 == string.Compare(argument, "/splash", true))
                {
                    splash = true;
                }
                else if (0 == string.Compare(argument, "/test", true))
                {
                    // This lets us use an alternate update manifest on the web server so that
                    // we can test manifests on a small scale before "deploying" them to everybody
                    PdnInfo.IsTestMode = true;
                }
                else if (0 == string.Compare(argument, "/profileStartupTimed", true))
                {
                    // profileStartupTimed and profileStartupWorkingSet compete, which
                    // ever is last in the args list wins.
                    PdnInfo.StartupTest = StartupTestType.Timed;
                }
                else if (0 == string.Compare(argument, "/profileStartupWorkingSet", true))
                {
                    // profileStartupTimed and profileStartupWorkingSet compete, which
                    // ever is last in the args list wins.
                    PdnInfo.StartupTest = StartupTestType.WorkingSet;
                }
                else if (argument.Length > 0 && argument[0] != '/')
                {
                    try
                    {
                        string fullPath = Path.GetFullPath(argument);
                        fileNames.Add(fullPath);
                    }

                    catch (Exception)
                    {
                        fileNames.Add(argument);
                        canSetCurrentDir = false;
                    }

                    splash = true;
                }
            }

            if (canSetCurrentDir)
            {
                try
                {
                    Environment.CurrentDirectory = PdnInfo.GetApplicationDir();
                }

                catch (Exception ex)
                {
                    Tracing.Ping("Exception while trying to set Environment.CurrentDirectory: " + ex.ToString());
                }
            }

            // make splash, if warranted
            if (splash)
            {
                this.splashForm         = new SplashForm();
                this.splashForm.TopMost = true;
                this.splashForm.Show();
                this.splashForm.Update();
            }

            InitializeComponent();

            this.Icon = PdnInfo.AppIcon;

            // Does not load window location/state
            LoadSettings();

            foreach (string fileName in fileNames)
            {
                this.queuedInstanceMessages.Add(fileName);
            }

            // no file specified? create a blank image
            if (fileNames.Count == 0)
            {
                Size newSize = this.appWorkspace.GetNewDocumentSize();
                this.appWorkspace.CreateBlankDocumentInNewWorkspace(newSize, true);
                this.appWorkspace.ActiveDocumentWorkspace.IncrementJustPaintWhite();
                this.appWorkspace.ActiveDocumentWorkspace.Document.Dirty = false;
                this.appWorkspace.ActiveDocumentWorkspace.ZoomIn(8);
            }

            LoadWindowState();

            deferredInitializationTimer.Enabled = true;

            Application.Idle += new EventHandler(Application_Idle);
        }
Example #3
0
        private static void WriteCrashLog(Exception ex, TextWriter stream)
        {
            string headerFormat;

            try
            {
                headerFormat = PdnResources.GetString("CrashLog.HeaderText.Format");
            }

            catch (Exception ex13)
            {
                headerFormat =
                    InvariantStrings.CrashLogHeaderTextFormatFallback +
                    ", --- Exception while calling PdnResources.GetString(\"CrashLog.HeaderText.Format\"): " +
                    ex13.ToString() +
                    Environment.NewLine;
            }

            string header = string.Empty;

            stream.WriteLine(header);

            const string noInfoString = "err";

            string fullAppName = noInfoString;
            string timeOfCrash = noInfoString;
            string appUptime   = noInfoString;
            string osVersion   = noInfoString;
            string osRevision  = noInfoString;
            string osType      = noInfoString;
            string processorNativeArchitecture = noInfoString;
            string clrVersion            = noInfoString;
            string fxInventory           = noInfoString;
            string processorArchitecture = noInfoString;
            string cpuName            = noInfoString;
            string cpuCount           = noInfoString;
            string cpuSpeed           = noInfoString;
            string cpuFeatures        = noInfoString;
            string totalPhysicalBytes = noInfoString;
            string dpiInfo            = noInfoString;
            string localeName         = noInfoString;
            string updaterInfo        = noInfoString;
            string featuresInfo       = noInfoString;
            string assembliesInfo     = noInfoString;

            try
            {
                try
                {
                    fullAppName = PdnInfo.GetFullAppName();
                }

                catch (Exception ex1)
                {
                    fullAppName = Application.ProductVersion + ", --- Exception while calling PdnInfo.GetFullAppName(): " + ex1.ToString() + Environment.NewLine;
                }

                try
                {
                    timeOfCrash = DateTime.Now.ToString();
                }

                catch (Exception ex2)
                {
                    timeOfCrash = "--- Exception while populating timeOfCrash: " + ex2.ToString() + Environment.NewLine;
                }

                try
                {
                    appUptime = (DateTime.Now - startupTime).ToString();
                }

                catch (Exception ex13)
                {
                    appUptime = "--- Exception while populating appUptime: " + ex13.ToString() + Environment.NewLine;
                }

                try
                {
                    osVersion = System.Environment.OSVersion.Version.ToString();
                }

                catch (Exception ex3)
                {
                    osVersion = "--- Exception while populating osVersion: " + ex3.ToString() + Environment.NewLine;
                }

                try
                {
                    osRevision = OS.Revision;
                }

                catch (Exception ex4)
                {
                    osRevision = "--- Exception while populating osRevision: " + ex4.ToString() + Environment.NewLine;
                }

                try
                {
                    osType = OS.Type.ToString();
                }

                catch (Exception ex5)
                {
                    osType = "--- Exception while populating osType: " + ex5.ToString() + Environment.NewLine;
                }

                try
                {
                    processorNativeArchitecture = Processor.NativeArchitecture.ToString().ToLower();
                }

                catch (Exception ex6)
                {
                    processorNativeArchitecture = "--- Exception while populating processorNativeArchitecture: " + ex6.ToString() + Environment.NewLine;
                }

                try
                {
                    clrVersion = System.Environment.Version.ToString();
                }

                catch (Exception ex7)
                {
                    clrVersion = "--- Exception while populating clrVersion: " + ex7.ToString() + Environment.NewLine;
                }

                try
                {
                    fxInventory =
                        (SystemLayer.OS.IsDotNetVersionInstalled(2, 0, 0, false) ? "2.0 " : "") +
                        (SystemLayer.OS.IsDotNetVersionInstalled(2, 0, 1, false) ? "2.0SP1 " : "") +
                        (SystemLayer.OS.IsDotNetVersionInstalled(2, 0, 2, false) ? "2.0SP2 " : "") +
                        (SystemLayer.OS.IsDotNetVersionInstalled(3, 0, 0, false) ? "3.0 " : "") +
                        (SystemLayer.OS.IsDotNetVersionInstalled(3, 0, 1, false) ? "3.0SP1 " : "") +
                        (SystemLayer.OS.IsDotNetVersionInstalled(3, 0, 2, false) ? "3.0SP2 " : "") +
                        (SystemLayer.OS.IsDotNetVersionInstalled(3, 5, 0, false) ? "3.5 " : "") +
                        (SystemLayer.OS.IsDotNetVersionInstalled(3, 5, 1, false) ? "3.5SP1 " : "") +
                        (SystemLayer.OS.IsDotNetVersionInstalled(3, 5, 1, true) ? "3.5SP1_Client " : "") +
                        (SystemLayer.OS.IsDotNetVersionInstalled(3, 5, 2, false) ? "3.5SP2 " : "") +
                        (SystemLayer.OS.IsDotNetVersionInstalled(4, 0, 0, false) ? "4.0 " : "") +
                        (SystemLayer.OS.IsDotNetVersionInstalled(4, 0, 1, false) ? "4.0SP1 " : "") +
                        (SystemLayer.OS.IsDotNetVersionInstalled(4, 0, 2, false) ? "4.0SP2 " : "")
                        .Trim();
                }

                catch (Exception ex30)
                {
                    fxInventory = "--- Exception while populating fxInventory: " + ex30.ToString() + Environment.NewLine;
                }

                try
                {
                    processorArchitecture = Processor.Architecture.ToString().ToLower();
                }

                catch (Exception ex8)
                {
                    processorArchitecture = "--- Exception while populating processorArchitecture: " + ex8.ToString() + Environment.NewLine;
                }

                try
                {
                    cpuName = SystemLayer.Processor.CpuName;
                }

                catch (Exception ex9)
                {
                    cpuName = "--- Exception while populating cpuName: " + ex9.ToString() + Environment.NewLine;
                }

                try
                {
                    cpuCount = SystemLayer.Processor.LogicalCpuCount.ToString() + "x";
                }

                catch (Exception ex10)
                {
                    cpuCount = "--- Exception while populating cpuCount: " + ex10.ToString() + Environment.NewLine;
                }

                try
                {
                    cpuSpeed = "@ ~" + SystemLayer.Processor.ApproximateSpeedMhz.ToString() + "MHz";
                }

                catch (Exception ex16)
                {
                    cpuSpeed = "--- Exception while populating cpuSpeed: " + ex16.ToString() + Environment.NewLine;
                }

                try
                {
                    cpuFeatures = string.Empty;
                    string[] featureNames = Enum.GetNames(typeof(ProcessorFeature));
                    bool     firstFeature = true;

                    for (int i = 0; i < featureNames.Length; ++i)
                    {
                        string           featureName = featureNames[i];
                        ProcessorFeature feature     = (ProcessorFeature)Enum.Parse(typeof(ProcessorFeature), featureName);

                        if (Processor.IsFeaturePresent(feature))
                        {
                            if (firstFeature)
                            {
                                cpuFeatures  = "(";
                                firstFeature = false;
                            }
                            else
                            {
                                cpuFeatures += ", ";
                            }

                            cpuFeatures += featureName;
                        }
                    }

                    if (cpuFeatures.Length > 0)
                    {
                        cpuFeatures += ")";
                    }
                }

                catch (Exception ex17)
                {
                    cpuFeatures = "--- Exception while populating cpuFeatures: " + ex17.ToString() + Environment.NewLine;
                }

                try
                {
                    totalPhysicalBytes = ((SystemLayer.Memory.TotalPhysicalBytes / 1024) / 1024) + " MB";
                }

                catch (Exception ex11)
                {
                    totalPhysicalBytes = "--- Exception while populating totalPhysicalBytes: " + ex11.ToString() + Environment.NewLine;
                }

                try
                {
                    float xScale;

                    try
                    {
                        xScale = UI.GetXScaleFactor();
                    }

                    catch (Exception)
                    {
                        using (Control c = new Control())
                        {
                            UI.InitScaling(c);
                            xScale = UI.GetXScaleFactor();
                        }
                    }

                    dpiInfo = string.Format("{0} dpi ({1}x scale)", (96.0f * xScale).ToString("F2"), xScale.ToString("F2"));
                }

                catch (Exception ex19)
                {
                    dpiInfo = "--- Exception while populating dpiInfo: " + ex19.ToString() + Environment.NewLine;
                }

                try
                {
                    localeName =
                        "pdnr.c: " + PdnResources.Culture.Name +
                        ", hklm: " + Settings.SystemWide.GetString(SettingNames.LanguageName, "n/a") +
                        ", hkcu: " + Settings.CurrentUser.GetString(SettingNames.LanguageName, "n/a") +
                        ", cc: " + CultureInfo.CurrentCulture.Name +
                        ", cuic: " + CultureInfo.CurrentUICulture.Name;
                }

                catch (Exception ex14)
                {
                    localeName = "--- Exception while populating localeName: " + ex14.ToString() + Environment.NewLine;
                }

                try
                {
                    string autoCheckForUpdates = Settings.SystemWide.GetString(SettingNames.AutoCheckForUpdates, noInfoString);

                    string lastUpdateCheckTimeInfo;

                    try
                    {
                        string   lastUpdateCheckTimeString = Settings.CurrentUser.Get(SettingNames.LastUpdateCheckTimeTicks);
                        long     lastUpdateCheckTimeTicks  = long.Parse(lastUpdateCheckTimeString);
                        DateTime lastUpdateCheckTime       = new DateTime(lastUpdateCheckTimeTicks);
                        lastUpdateCheckTimeInfo = lastUpdateCheckTime.ToShortDateString();
                    }

                    catch (Exception)
                    {
                        lastUpdateCheckTimeInfo = noInfoString;
                    }

                    updaterInfo = string.Format(
                        "{0}, {1}",
                        (autoCheckForUpdates == "1") ? "true" : (autoCheckForUpdates == "0" ? "false" : (autoCheckForUpdates ?? "null")),
                        lastUpdateCheckTimeInfo);
                }

                catch (Exception ex17)
                {
                    updaterInfo = "--- Exception while populating updaterInfo: " + ex17.ToString() + Environment.NewLine;
                }

                try
                {
                    StringBuilder featureSB = new StringBuilder();

                    IEnumerable <string> featureList = SystemLayer.Tracing.GetLoggedFeatures();

                    bool first = true;
                    foreach (string feature in featureList)
                    {
                        if (!first)
                        {
                            featureSB.Append(", ");
                        }

                        featureSB.Append(feature);

                        first = false;
                    }

                    featuresInfo = featureSB.ToString();
                }

                catch (Exception ex18)
                {
                    featuresInfo = "--- Exception while populating featuresInfo: " + ex18.ToString() + Environment.NewLine;
                }

                try
                {
                    StringBuilder assembliesInfoSB = new StringBuilder();

                    Assembly[] loadedAssemblies = AppDomain.CurrentDomain.GetAssemblies();

                    foreach (Assembly assembly in loadedAssemblies)
                    {
                        assembliesInfoSB.AppendFormat("{0}    {1} @ {2}", Environment.NewLine, assembly.FullName, assembly.Location);
                    }

                    assembliesInfo = assembliesInfoSB.ToString();
                }

                catch (Exception ex16)
                {
                    assembliesInfo = "--- Exception while populating assembliesInfo: " + ex16.ToString() + Environment.NewLine;
                }
            }

            catch (Exception ex12)
            {
                stream.WriteLine("Exception while gathering app and system info: " + ex12.ToString());
            }

            stream.WriteLine("Application version: " + fullAppName);
            stream.WriteLine("Time of crash: " + timeOfCrash);
            stream.WriteLine("Application uptime: " + appUptime);

            stream.WriteLine("OS Version: " + osVersion + (string.IsNullOrEmpty(osRevision) ? "" : (" " + osRevision)) + " " + osType + " " + processorNativeArchitecture);
            stream.WriteLine(".NET version: CLR " + clrVersion + " " + processorArchitecture + ", FX " + fxInventory);
            stream.WriteLine("Processor: " + cpuCount + " \"" + cpuName + "\" " + cpuSpeed + " " + cpuFeatures);
            stream.WriteLine("Physical memory: " + totalPhysicalBytes);
            stream.WriteLine("UI DPI: " + dpiInfo);
            stream.WriteLine("Updates: " + updaterInfo);
            stream.WriteLine("Locale: " + localeName);
            stream.WriteLine("Features log: " + featuresInfo);
            stream.WriteLine("Loaded assemblies: " + assembliesInfo);
            stream.WriteLine();

            stream.WriteLine("Exception details:");

            if (ex == null)
            {
                stream.WriteLine("(null)");
            }
            else
            {
                stream.WriteLine(ex.ToString());

                // Determine if there is any 'secondary' exception to report
                Exception[] otherEx = null;

                if (ex is System.Reflection.ReflectionTypeLoadException)
                {
                    otherEx = ((System.Reflection.ReflectionTypeLoadException)ex).LoaderExceptions;
                }

                if (otherEx != null)
                {
                    for (int i = 0; i < otherEx.Length; ++i)
                    {
                        stream.WriteLine();
                        stream.WriteLine("Secondary exception details:");

                        if (otherEx[i] == null)
                        {
                            stream.WriteLine("(null)");
                        }
                        else
                        {
                            stream.WriteLine(otherEx[i].ToString());
                        }
                    }
                }
            }

            stream.WriteLine("------------------------------------------------------------------------------");
            stream.Flush();
        }