Exemple #1
0
        /// <summary>
        /// Checks if the build is expired, and displays a dialog box that takes the user to
        /// the Paint.NET website if necessary.
        /// </summary>
        /// <returns>true if the user should be allowed to continue, false if the build has expired</returns>
        public static bool HandleExpiration(IWin32Window owner)
        {
            if (IsExpired)
            {
                string expiredMessage = PdnResources.GetString("ExpiredDialog.Message");

                DialogResult result = MessageBox.Show(expiredMessage, PdnInfo.GetProductName(true),
                                                      MessageBoxButtons.OKCancel);

                if (result == DialogResult.OK)
                {
                    string expiredRedirect = InvariantStrings.ExpiredPage;
                    PdnInfo.LaunchWebSite(owner, expiredRedirect);
                }

                return(false);
            }

            return(true);
        }
Exemple #2
0
        /// <summary>
        /// Returns a version string that is presentable without the Paint.NET name. example: "version 2.5 Beta 5"
        /// </summary>
        /// <returns></returns>
        public static string GetFriendlyVersionString()
        {
            Version version       = PdnInfo.GetVersion();
            string  versionFormat = PdnResources.GetString("PdnInfo.FriendlyVersionString.Format");
            string  configFormat  = PdnResources.GetString("PdnInfo.FriendlyVersionString.ConfigWithSpace.Format");
            string  config        = string.Format(configFormat, GetConfigurationString());
            string  configText;

            if (PdnInfo.IsFinalBuild)
            {
                configText = string.Empty;
            }
            else
            {
                configText = config;
            }

            string versionText = string.Format(versionFormat, GetVersionNumberString(version, 2), configText);

            return(versionText);
        }
Exemple #3
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;
            }
        }
        public ControlShadow()
        {
            this.SetStyle(ControlStyles.Opaque, true);
            this.SetStyle(ControlStyles.UserPaint, true);
            this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);

            this.Dock           = DockStyle.Fill;
            this.DoubleBuffered = true;
            this.ResizeRedraw   = true;

            // This call is required by the Windows.Forms Form Designer.
            InitializeComponent();
            BackColor = Color.Transparent;

            this.roundedEdgeUL = ImageResource.Get("Images.RoundedEdgeUL.png").Reference;
            this.roundedEdgeUR = ImageResource.Get("Images.RoundedEdgeUR.png").Reference;
            this.roundedEdgeLL = ImageResource.Get("Images.RoundedEdgeLL.png").Reference;
            this.roundedEdgeLR = ImageResource.Get("Images.RoundedEdgeLR.png").Reference;

            if (!PdnInfo.IsFinalBuild && !betaTagDone)
            {
                betaTagDone = true;

                string betaTagStringFormat = PdnResources.GetString("ControlShadow.BetaTag.Text.Format");
                string appName             = PdnInfo.GetFullAppName();
                string expiredDateString   = PdnInfo.ExpirationDate.ToShortDateString();
                this.betaTagString = string.Format(betaTagStringFormat, appName, expiredDateString);

                this.betaTagStart          = DateTime.Now;
                this.betaTagTimer          = new Timer();
                this.betaTagTimer.Interval = 100;
                this.betaTagTimer.Tick    += new EventHandler(BetaTagTimer_Tick);
                this.betaTagTimer.Enabled  = true;
            }
        }
Exemple #5
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;

            try
            {
                header = string.Format(headerFormat, InvariantStrings.CrashlogEmail);
            }

            catch
            {
                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 inkInfo            = 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
                {
                    inkInfo = Ink.IsAvailable() ? "yes" : "no";
                }

                catch (Exception ex15)
                {
                    inkInfo = "--- Exception while populating inkInfo: " + ex15.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("Tablet PC: " + inkInfo);
            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();
        }
Exemple #6
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)
            {
                MeasurementUnit units   = Document.DefaultDpuUnit;
                double          dpu     = Document.GetDefaultDpu(units);
                Size            newSize = this.appWorkspace.GetNewDocumentSize();
                this.appWorkspace.CreateBlankDocumentInNewWorkspace(newSize, units, dpu, true);
                this.appWorkspace.ActiveDocumentWorkspace.IncrementJustPaintWhite();
                this.appWorkspace.ActiveDocumentWorkspace.Document.Dirty = false;
            }

            LoadWindowState();

            deferredInitializationTimer.Enabled = true;

            Application.Idle += new EventHandler(Application_Idle);
        }
Exemple #7
0
        protected override void OnDragDrop(DragEventArgs drgevent)
        {
            Activate();

            if (!IsCurrentModalForm || !Enabled)
            {
                // do nothing
            }
            else if (drgevent.Data.GetDataPresent(DataFormats.FileDrop))
            {
                string[] allFiles = (string[])drgevent.Data.GetData(DataFormats.FileDrop);

                if (allFiles == null)
                {
                    return;
                }

                string[] files = PruneDirectories(allFiles);

                bool importAsLayers = true;

                if (files.Length == 0)
                {
                    return;
                }
                else
                {
                    TaskButton openTB = new TaskButton(
                        ImageResource.Get("Icons.MenuFileOpenIcon.png").Reference,
                        PdnResources.GetString("DragDrop.OpenOrImport.OpenButton.ActionText"),
                        PdnResources.GetString("DragDrop.OpenOrImport.OpenButton.ExplanationText"));

                    string importLayersExplanation;
                    if (this.appWorkspace.DocumentWorkspaces.Length == 0)
                    {
                        importLayersExplanation = PdnResources.GetString("DragDrop.OpenOrImport.ImportLayers.ExplanationText.NoImagesYet");
                    }
                    else
                    {
                        importLayersExplanation = PdnResources.GetString("DragDrop.OpenOrImport.ImportLayers.ExplanationText");
                    }

                    TaskButton importLayersTB = new TaskButton(
                        ImageResource.Get("Icons.MenuLayersImportFromFileIcon.png").Reference,
                        PdnResources.GetString("DragDrop.OpenOrImport.ImportLayers.ActionText"),
                        importLayersExplanation);

                    TaskButton clickedTB = TaskDialog.Show(
                        this,
                        new Icon(PdnResources.GetResourceStream("Icons.Question.ico")),
                        PdnInfo.GetBareProductName(),
                        null,
                        false,
                        PdnResources.GetString("DragDrop.OpenOrImport.InfoText"),
                        new TaskButton[] { openTB, importLayersTB, TaskButton.Cancel },
                        null,
                        TaskButton.Cancel);

                    if (clickedTB == openTB)
                    {
                        importAsLayers = false;
                    }
                    else if (clickedTB == importLayersTB)
                    {
                        importAsLayers = true;
                    }
                    else
                    {
                        return;
                    }
                }

                if (!importAsLayers)
                {
                    // open files into new tabs
                    this.appWorkspace.OpenFilesInNewWorkspace(files);
                }
                else
                {
                    // no image open? we will have to create one
                    if (this.appWorkspace.ActiveDocumentWorkspace == null)
                    {
                        Size newSize = this.appWorkspace.GetNewDocumentSize();

                        this.appWorkspace.CreateBlankDocumentInNewWorkspace(
                            newSize,
                            Document.DefaultDpuUnit,
                            Document.GetDefaultDpu(Document.DefaultDpuUnit),
                            false);
                    }

                    ImportFromFileAction action = new ImportFromFileAction();
                    HistoryMemento       ha     = action.ImportMultipleFiles(this.appWorkspace.ActiveDocumentWorkspace, files);

                    if (ha != null)
                    {
                        this.appWorkspace.ActiveDocumentWorkspace.History.PushNewMemento(ha);
                    }
                }
            }

            base.OnDragDrop(drgevent);
        }
Exemple #8
0
        public static void MainImpl(string[] args)
        {
            //System.Windows.Forms.MessageBox.Show(Environment.CommandLine);

            // Syntax:
            //     SetupNgen </cleanUpStaging | </install | /delete> DESKTOPSHORTCUT=<0|1> PDNUPDATING=<0|1> SKIPCLEANUP=<0|1> PROGRAMSGROUP=relativeName QUEUENGEN=<0|1>>

            if (args.Length >= 2 && args[0] == "/cleanUpStaging")
            {
                // SetupNgen.exe is overloaded for cleaning up the "Staging" directory
                string stagingPath = args[1];

                // Sanity check: staging directory must ALWAYS have the word Staging in it (capitalized that way too)
                // It must exist, too.
                if (Directory.Exists(stagingPath) &&
                    -1 != stagingPath.IndexOf("Staging"))
                {
                    foreach (string filePath in Directory.GetFiles(stagingPath, "*.msi"))
                    {
                        try
                        {
                            Console.WriteLine("delete: " + filePath);
                            System.IO.File.Delete(filePath);
                        }

                        catch
                        {
                        }
                    }

                    try
                    {
                        Console.WriteLine("rmdir: " + stagingPath);
                        Directory.Delete(stagingPath);
                    }

                    catch
                    {
                    }
                }
            }
            else
            {
                bool delete = false;

                if (args.Length < 5)
                {
                    return;
                }

                if (args[0] == "/delete")
                {
                    delete = true;
                }

                // otherwise we assume args[0] == "/install"

                bool queueNgen;

                if (args[5] == "QUEUENGEN=1")
                {
                    queueNgen = true;
                }
                else
                {
                    queueNgen = false;
                }

                // Pre-JIT via ngen. These are in alphabetical order.
                string[] names =
                    new string[]
                {
                    "ICSharpCode.SharpZipLib.dll",
                    "PaintDotNet.Data.dll",
                    "PaintDotNet.Effects.dll",
                    "PaintDotNet.exe",
                    "PaintDotNet.Resources.dll",
                    "PaintDotNet.StylusReader.dll",
                    "PaintDotNet.SystemLayer.dll",
                    "PdnLib.dll"
                };

                string[] names32 =
                    new string[]
                {
                    "Interop.WIA.dll",
                    "WiaProxy32.exe"
                };

                foreach (string name in names)
                {
                    try
                    {
                        InstallAssembly(name, delete, queueNgen, false);
                    }

                    // We don't raise a stink if ngen fails.
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex);
                    }
                }

                foreach (string name in names32)
                {
                    try
                    {
                        InstallAssembly(name, delete, queueNgen, true);
                    }

                    // We don't raise a stink if ngen fails.
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex);
                    }
                }

                // Create desktop shortcut
                bool createDesktopShortcut = false;
                bool updating    = false;
                bool skipCleanup = false;

                if (args[1] == "DESKTOPSHORTCUT=1")
                {
                    createDesktopShortcut = true;
                }

                if (args[2] == "PDNUPDATING=1")
                {
                    updating = true;
                }

                if (args[3] == "SKIPCLEANUP=1")
                {
                    skipCleanup = true;
                }

                string       programsShortcutGroup = string.Empty;
                const string programsGroup         = "PROGRAMSGROUP";
                if (args[4].StartsWith(programsGroup + "=")) // starts with "PROGRAMSGROUP="
                {
                    programsShortcutGroup = args[4].Substring(1 + programsGroup.Length);
                }

                // Create shortcuts

                // Set up out strings
                string desktopDir  = GetSpecialFolderPath(CSIDL_COMMON_DESKTOPDIRECTORY);
                string programsDir = GetSpecialFolderPath(CSIDL_COMMON_PROGRAMS);

                string linkName            = PaintDotNet.PdnResources.GetString("Setup.DesktopShortcut.LinkName");
                string description         = PaintDotNet.PdnResources.GetString("Setup.DesktopShortcut.Description");
                string desktopLinkPath     = Path.Combine(desktopDir, linkName) + ".lnk"; // if we just use ChangeExtension it will overwrite the .NET part of Mono Paint :)
                string programsShortcutDir = Path.Combine(programsDir, programsShortcutGroup);
                string programsLinkPath    = Path.Combine(programsShortcutDir, linkName) + ".lnk";
                string workingDirectory    = PdnInfo.GetApplicationDir();
                string targetPath          = Path.Combine(workingDirectory, "PaintDotNet.exe");

                // Desktop shortcut
                if ((delete && !skipCleanup) || (!createDesktopShortcut && skipCleanup))
                {
                    if (System.IO.File.Exists(desktopLinkPath))
                    {
                        Console.WriteLine("delete: " + desktopLinkPath);

                        try
                        {
                            System.IO.File.Delete(desktopLinkPath);
                        }

                        catch
                        {
                        }
                    }
                }
                else if (createDesktopShortcut && !delete && !updating)
                {
                    CreateShortcut(desktopLinkPath, targetPath, workingDirectory, description);
                }

                // Programs shortcut
                const string programsShortcutPathKey = "ProgramsShortcutPath";
                const string pdnKey = @"SOFTWARE\Mono Paint";

                if (delete && !skipCleanup)
                {
                    string path = programsLinkPath;

                    // For the purposes of deleting the shortcut, we actually store the file's location in the registry
                    using (RegistryKey hklmPDN = Registry.LocalMachine.OpenSubKey(pdnKey, false))
                    {
                        if (hklmPDN != null)
                        {
                            object pathObj = hklmPDN.GetValue(programsShortcutPathKey, programsLinkPath);

                            if (pathObj is string)
                            {
                                path = (string)pathObj;
                            }
                        }
                    }

                    // Do some quick checks to make sure we don't delete something we don't want to
                    bool allowDelete = true;

                    // Verify that it is a .lnk file
                    allowDelete &= (Path.GetExtension(path) == ".lnk");

                    // Verify that it is in a subdirectory of Programs
                    allowDelete &= IsPathInDirectory(path, programsDir);

                    // Delete it
                    if (allowDelete && System.IO.File.Exists(path))
                    {
                        Console.WriteLine("delete: " + path);
                        System.IO.File.Delete(path);

                        // If we're the last shortcut, then delete that directory.
                        string dir = Path.GetDirectoryName(path);

                        try
                        {
                            System.IO.Directory.Delete(dir, false);
                        }

                        catch
                        {
                        }
                    }
                }
                else if (!delete && !updating)
                {
                    // Create it
                    if (!Directory.Exists(programsShortcutDir))
                    {
                        Directory.CreateDirectory(programsShortcutDir);
                    }

                    CreateShortcut(programsLinkPath, targetPath, workingDirectory, description);

                    // Save the location to the registry
                    using (RegistryKey hklmPDN = Registry.LocalMachine.CreateSubKey(pdnKey))
                    {
                        if (hklmPDN != null)
                        {
                            hklmPDN.SetValue(programsShortcutPathKey, programsLinkPath);
                        }
                    }
                }

                // Register shell extension
                const string shellExtensionName_x86 = "ShellExtension_x86.dll";
                const string shellExtensionName_x64 = "ShellExtension_x64.dll";
                const string shellExtensionGuid     = "{D292F82A-50BE-4351-96CC-E86F3F8049DA}";
                const string regKeyName             = @"CLSID\" + shellExtensionGuid;
                const string regKeyWow64Name        = @"Wow6432Node\" + regKeyName;
                const string shellExtension_regName = "Mono Paint Shell Extension";
                const string inProcServer32         = "InProcServer32";
                const string threadingModel         = "ThreadingModel";
                const string apartment = "Apartment";

                string[] shellExtensionFileNames;
                string[] regKeyNames;

                if (UIntPtr.Size == 4)
                {
                    shellExtensionFileNames = new string[1] {
                        shellExtensionName_x86
                    };
                    regKeyNames = new string[1] {
                        regKeyName
                    };
                }
                else
                {
                    Platform platform     = GetPlatform();
                    string   dll64bitName = shellExtensionName_x64;

                    shellExtensionFileNames = new string[2] {
                        dll64bitName, shellExtensionName_x86
                    };
                    regKeyNames = new string[2] {
                        regKeyName, regKeyWow64Name
                    };
                }

                string[] shellExtensionPaths = new string[shellExtensionFileNames.Length];

                for (int i = 0; i < shellExtensionFileNames.Length; ++i)
                {
                    shellExtensionPaths[i] = Path.Combine(ourPath, shellExtensionFileNames[i]);
                }

                if (!delete)
                {
                    // Register the shell extension
                    try
                    {
                        for (int i = 0; i < shellExtensionPaths.Length; ++i)
                        {
                            RegistryKey clsidKey = Registry.ClassesRoot.CreateSubKey(regKeyNames[i], RegistryKeyPermissionCheck.ReadWriteSubTree);
                            RegistryKey ips32key = clsidKey.CreateSubKey(inProcServer32);

                            clsidKey.SetValue(null, shellExtension_regName);
                            ips32key.SetValue(threadingModel, apartment);
                            ips32key.SetValue(null, shellExtensionPaths[i]);
                        }
                    }

                    catch
                    {
                    }
                }
                else
                {
                    // Unregister the shell extension
                    try
                    {
                        for (int i = 0; i < regKeyNames.Length; ++i)
                        {
                            Registry.ClassesRoot.DeleteSubKeyTree(regKeyNames[i]);
                        }
                    }

                    catch
                    {
                    }
                }
            }
        }
Exemple #9
0
 public PdnFileType()
     : base(PdnInfo.GetBareProductName(), true, true, true, true, true, new string[] { ".pdn" })
 {
 }
Exemple #10
0
        private static void UnhandledException(Exception ex)
        {
            string       dir      = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
            const string fileName = "pdncrash.log";
            string       fullName = Path.Combine(dir, fileName);

            using (StreamWriter stream = new System.IO.StreamWriter(fullName, true))
            {
                stream.AutoFlush = true;

                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;

                try
                {
                    header = string.Format(headerFormat, InvariantStrings.FeedbackEmail);
                }

                catch
                {
                    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 fxVersion             = noInfoString;
                string processorArchitecture = noInfoString;
                string cpuName            = noInfoString;
                string cpuCount           = noInfoString;
                string totalPhysicalBytes = noInfoString;
                string localeName         = noInfoString;
                string inkInfo            = 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
                    {
                        fxVersion = System.Environment.Version.ToString();
                    }

                    catch (Exception ex7)
                    {
                        fxVersion = "--- Exception while populating fxVersion: " + ex7.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
                    {
                        totalPhysicalBytes = ((SystemLayer.Memory.TotalPhysicalBytes / 1024) / 1024) + " MB";
                    }

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

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

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

                    try
                    {
                        inkInfo = Ink.IsAvailable() ? "yes" : "no";
                    }

                    catch (Exception ex15)
                    {
                        inkInfo = "--- Exception while populating inkInfo: " + ex15.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 + " " + osRevision + " " + osType + " " + processorNativeArchitecture);
                stream.WriteLine(".NET Framework version: " + fxVersion + " " + processorArchitecture);
                stream.WriteLine("Processor: " + cpuCount + " " + cpuName);
                stream.WriteLine("Physical memory: " + totalPhysicalBytes);
                stream.WriteLine("Tablet PC: " + inkInfo);
                stream.WriteLine("Locale: " + localeName);
                stream.WriteLine();

                stream.WriteLine("Exception details:");
                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("------------------------------------------------------------------------------");
            }

            string errorFormat;
            string errorText;

            try
            {
                errorFormat = PdnResources.GetString("Startup.UnhandledError.Format");
            }

            catch (Exception)
            {
                errorFormat = InvariantStrings.StartupUnhandledErrorFormatFallback;
            }

            errorText = string.Format(errorFormat, fileName);
            Utility.ErrorBox(null, errorText);
        }