private void unregisterFileType_Click(object sender, EventArgs e)
 {
     if (SG.Utilities.Forms.Elevation.IsElevationRequired && !SG.Utilities.Forms.Elevation.IsElevated)
     {
         if (SG.Utilities.Forms.Elevation.RestartElevated("?#FILEUNREG " + textBoxExt.Text + " " + Handle.ToString()) == int.MinValue)
         {
             MessageBox.Show("Failed to start elevated Process. Most likely a security conflict.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
     else
     {
         FileTypeRegistration.UnregisterDataFileType(this, textBoxExt.Text);
     }
 }
コード例 #2
0
 private void button3_Click(object sender, EventArgs e)
 {
     if (SG.Utilities.Forms.Elevation.IsElevationRequired && !SG.Utilities.Forms.Elevation.IsElevated)
     {
         if (SG.Utilities.Forms.Elevation.RestartElevated("?#REG " + Application.ExecutablePath + " " + Handle.ToString()) == int.MinValue)
         {
             MessageBox.Show("Failed to start elevated Process. Most likely a security conflict.",
                             Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
     else
     {
         FileTypeRegistration.Register(this, Application.ExecutablePath);
     }
 }
        private void registerFileType_Click(object sender, EventArgs e)
        {
            if (SG.Utilities.Forms.Elevation.IsElevationRequired && !SG.Utilities.Forms.Elevation.IsElevated)
            {
                // Superugly hack and potential dangerous because of the command length size limit.
                // Correct would be to use the pipes for communication, but I don't care right now.

                System.IO.MemoryStream mem = new System.IO.MemoryStream();

                byte[] blob = Encoding.UTF8.GetBytes(textBoxExt.Text);
                byte[] len  = BitConverter.GetBytes(blob.Length);
                mem.Write(len, 0, len.Length);
                mem.Write(blob, 0, blob.Length);

                blob = Encoding.UTF8.GetBytes(textBoxDescription.Text);
                len  = BitConverter.GetBytes(blob.Length);
                mem.Write(len, 0, len.Length);
                mem.Write(blob, 0, blob.Length);

                blob = Encoding.UTF8.GetBytes(textBoxIconPath.Text);
                len  = BitConverter.GetBytes(blob.Length);
                mem.Write(len, 0, len.Length);
                mem.Write(blob, 0, blob.Length);

                blob = Encoding.UTF8.GetBytes(textBoxOpenCommand.Text);
                len  = BitConverter.GetBytes(blob.Length);
                mem.Write(len, 0, len.Length);
                mem.Write(blob, 0, blob.Length);

                mem.Position = 0;
                string regData = Convert.ToBase64String(mem.ToArray());

                if (SG.Utilities.Forms.Elevation.RestartElevated("?#FILEREG " + regData + " " + Handle.ToString()) == int.MinValue)
                {
                    MessageBox.Show("Failed to start elevated Process. Most likely a security conflict.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                FileTypeRegistration.RegisterDataFileType(this, textBoxExt.Text, textBoxDescription.Text, textBoxIconPath.Text, textBoxOpenCommand.Text);
            }
        }
コード例 #4
0
        /// <summary>
        /// Creates the startup checks to be performed. Startup checks require
        /// the main form to be created and visible.
        /// </summary>
        /// <returns>Array of startup checks</returns>
        private static StartupCheck[] MakeStartupCheckList()
        {
            List <StartupCheck> chks = new List <StartupCheck>();

            chks.Add(new StartupCheck()
            {
                Title       = "MegaMol Console",
                Description = "Test if the path to the MegaMol Console front end binary is known.",
                DoEvaluate  = new Func <StartupCheck, bool>((StartupCheck sc) => {
                    sc.EvaluateComment = Properties.Settings.Default.MegaMolBin;
                    return(!String.IsNullOrWhiteSpace(Properties.Settings.Default.MegaMolBin));
                }),
                DoFix = new Action <StartupCheck, IWin32Window>((StartupCheck sc, IWin32Window w) => {
                    ApplicationSearchDialog asd = new ApplicationSearchDialog();
                    asd.FileName = Properties.Settings.Default.MegaMolBin;
                    if (asd.ShowDialog(w) == DialogResult.OK)
                    {
                        Properties.Settings.Default.MegaMolBin = asd.FileName;
                        sc.EvaluateComment = asd.FileName;
                        Properties.Settings.Default.Save();
                    }
                })
            });
            chks.Add(new StartupCheck()
            {
                Title       = "MegaMol Config File",
                Description = "There is a MegaMol Config file ready to load.",
                DoEvaluate  = new Func <StartupCheck, bool>((StartupCheck sc) => {
                    List <string> paths = new List <string>();
                    string path         = Environment.GetEnvironmentVariable("MEGAMOLCONFIG");
                    if (!string.IsNullOrWhiteSpace(path))
                    {
                        if (System.IO.Directory.Exists(path))
                        {
                            paths.Add(path);
                        }
                        else if (System.IO.File.Exists(path))
                        {
                            sc.EvaluateComment = path; // config file
                            return(true);
                        }
                    }
                    path = Properties.Settings.Default.MegaMolBin;
                    if (!string.IsNullOrWhiteSpace(path))
                    {
                        path = System.IO.Path.GetDirectoryName(path);
                        if (System.IO.Directory.Exists(path))
                        {
                            paths.Add(path);
                        }
                    }
                    path = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
                    if (System.IO.Directory.Exists(path))
                    {
                        paths.Add(path);
                        path = System.IO.Path.Combine(path, ".megamol");
                        if (System.IO.Directory.Exists(path))
                        {
                            paths.Add(path);
                        }
                    }
                    if (Properties.Settings.Default.UseApplicationDirectoryAsWorkingDirectory)
                    {
                        path = Properties.Settings.Default.WorkingDirectory;
                        if (!string.IsNullOrWhiteSpace(path))
                        {
                            path = System.IO.Path.GetDirectoryName(path);
                            if (System.IO.Directory.Exists(path))
                            {
                                paths.Add(path);
                            }
                        }
                    }
                    string[] filenames = new string[] { "megamolconfig.lua",
                                                        "megamolconfig.xml", "megamol.cfg", ".megamolconfig.xml", ".megamol.cfg" };
                    foreach (string p in paths)
                    {
                        foreach (string f in filenames)
                        {
                            string file = System.IO.Path.Combine(p, f);
                            if (System.IO.File.Exists(file))
                            {
                                sc.EvaluateComment = file;
                                return(true);
                            }
                        }
                    }
                    return(false);
                }),
                DoFix = new Action <StartupCheck, IWin32Window>((StartupCheck sc, IWin32Window w) => {
                    SaveFileDialog sfd = new SaveFileDialog();
                    sfd.DefaultExt     = "cfg";
                    sfd.Filter         = "Config Files|*.cfg|Xml Files|*.xml|All Files|*.*";
                    sfd.Title          = "Write MegaMol Config File...";

                    string path = Environment.GetEnvironmentVariable("MEGAMOLCONFIG");
                    if (!string.IsNullOrWhiteSpace(path))
                    {
                        if (System.IO.Directory.Exists(path))
                        {
                            sfd.FileName = System.IO.Path.Combine(path, "megamol.cfg");
                        }
                        else if (System.IO.File.Exists(path))
                        {
                            sfd.FileName = path;
                        }
                    }
                    path = Properties.Settings.Default.MegaMolBin;
                    if (string.IsNullOrWhiteSpace(sfd.FileName) && !string.IsNullOrWhiteSpace(path))
                    {
                        sfd.FileName = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(path), "megamol.cfg");
                    }

                    try {
                        path = System.IO.Path.GetDirectoryName(sfd.FileName);
                        if (System.IO.Directory.Exists(path))
                        {
                            sfd.InitialDirectory = path;
                        }
                    } catch {}

                    if (sfd.ShowDialog() == DialogResult.OK)
                    {
                        path = sfd.FileName;
                        if (System.IO.File.Exists(path))
                        {
                            if (MessageBox.Show("File \"" + path + "\" will be overwritten. Continue?", Application.ProductName, MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) != DialogResult.OK)
                            {
                                return;
                            }
                        }
                        path = System.IO.Path.GetFileName(sfd.FileName);
                        if (string.IsNullOrWhiteSpace(path))
                        {
                            MessageBox.Show("You must specify a file name", Application.ProductName);
                            return;
                        }
                        if (path.Equals("megamol", StringComparison.CurrentCultureIgnoreCase) ||
                            path.Equals(".megamol", StringComparison.CurrentCultureIgnoreCase))
                        {
                            sfd.FileName = System.IO.Path.ChangeExtension(sfd.FileName, "cfg");
                            path         = System.IO.Path.GetFileName(sfd.FileName);
                        }
                        else if (path.Equals("megamolconfig", StringComparison.CurrentCultureIgnoreCase) ||
                                 path.Equals(".megamolconfig", StringComparison.CurrentCultureIgnoreCase))
                        {
                            sfd.FileName = System.IO.Path.ChangeExtension(sfd.FileName, "xml");
                            path         = System.IO.Path.GetFileName(sfd.FileName);
                        }
                        if (!path.Equals("megamol.cfg", StringComparison.CurrentCultureIgnoreCase) &&
                            !path.Equals(".megamol.cfg", StringComparison.CurrentCultureIgnoreCase) &&
                            !path.Equals("megamolconfig.xml", StringComparison.CurrentCultureIgnoreCase) &&
                            !path.Equals(".megamolconfig.xml", StringComparison.CurrentCultureIgnoreCase) &&
                            !sfd.FileName.Equals(Environment.GetEnvironmentVariable("MEGAMOLCONFIG")))
                        {
                            if (MessageBox.Show("Non-standard MegaMol config file \"" + path + "\" might not work. Continue?", Application.ProductName, MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) != DialogResult.OK)
                            {
                                return;
                            }
                        }

                        try {
                            System.IO.File.WriteAllBytes(sfd.FileName, Properties.Resources.megamol);
                            sc.EvaluateComment = sfd.FileName;
                        } catch (Exception ex) {
                            sc.EvaluateComment = ex.ToString();
                        }
                    }
                })
            });
            chks.Add(new StartupCheck()
            {
                Title       = "Core and Plugins State",
                Description = "A state file is loaded which contains all Modules and Calls in the Core and the known plugins",
                DoEvaluate  = new Func <StartupCheck, bool>((StartupCheck sc) => {
                    List <Data.PluginFile> plgs = Program.MainForm.Plugins;
                    int pc = 0, mc = 0, cc = 0;

                    if ((plgs != null) && (plgs.Count > 0))
                    {
                        foreach (Data.PluginFile p in plgs)
                        {
                            pc++;
                            if (p.Modules != null)
                            {
                                mc += p.Modules.Length;
                            }
                            if (p.Calls != null)
                            {
                                cc += p.Calls.Length;
                            }
                        }
                    }
                    sc.EvaluateComment = pc.ToString() + " Plugins with " + mc.ToString() + " Modules and " + cc.ToString() + " Calls";

                    return((pc + mc + cc) > 0);
                }),
                DoFix = new Action <StartupCheck, IWin32Window>((StartupCheck sc, IWin32Window w) => {
                    Analyze.AnalyzerDialog ad = new Analyze.AnalyzerDialog();

                    ad.MegaMolPath      = Properties.Settings.Default.MegaMolBin;
                    ad.WorkingDirectory = Properties.Settings.Default.WorkingDirectory;

                    if (ad.ShowDialog(w) == DialogResult.OK)
                    {
                        Properties.Settings.Default.MegaMolBin = ad.MegaMolPath;
                        Properties.Settings.Default.Save();

                        Program.MainForm.SetPlugins(ad.Plugins, ad.SaveAfterOk);
                    }
                })
            });
            if (Environment.OSVersion.Platform == PlatformID.Win32NT)
            {
                chks.Add(new StartupCheck()
                {
                    Title       = "Register *.mmprj File Type",
                    Description = "The MMPRJ file type is registered.",
                    DoEvaluate  = new Func <StartupCheck, bool>((StartupCheck sc) => {
                        string[] types    = Microsoft.Win32.Registry.ClassesRoot.GetSubKeyNames();
                        sc.NeedsElevation = SG.Utilities.Forms.Elevation.IsElevationRequired && !SG.Utilities.Forms.Elevation.IsElevated;
                        foreach (string t in types)
                        {
                            if (t.Equals(".mmprj", StringComparison.InvariantCultureIgnoreCase))
                            {
                                return(true);
                            }
                        }
                        return(false);
                    }),
                    DoFix = new Action <StartupCheck, IWin32Window>((StartupCheck sc, IWin32Window w) => {
                        if (SG.Utilities.Forms.Elevation.IsElevationRequired && !SG.Utilities.Forms.Elevation.IsElevated)
                        {
                            if (SG.Utilities.Forms.Elevation.RestartElevated("?#REG " + Application.ExecutablePath + " " + w.Handle.ToString()) == int.MinValue)
                            {
                                MessageBox.Show("Failed to start elevated Process. Most likely a security conflict.",
                                                Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
                        else
                        {
                            FileTypeRegistration.Register(w, Application.ExecutablePath);
                        }
                    })
                });
            }
            return(chks.ToArray());
        }