Beispiel #1
0
        private void btnAssociateFiles_Click(object sender, EventArgs e)
        {
#if WIN32
            TangraFileAssociations fileAssocHelper = btnAssociateFiles.Tag as TangraFileAssociations;
            if (fileAssocHelper != null)
            {
                fileAssocHelper.Associate(true);
                UpdateFileAssociationsButtonState();
            }
            else
            {
                // Launch itself as administrator passing the right parameter the do the job
                var proc = new ProcessStartInfo();
                proc.UseShellExecute  = true;
                proc.WorkingDirectory = Environment.CurrentDirectory;
                proc.FileName         = Application.ExecutablePath;
                proc.Arguments        = TangraFileAssociations.COMMAND_LINE_ASSOCIATE;
                proc.Verb             = "runas";

                btnAssociateFiles.Enabled = false;
                try
                {
                    Process newProcess = new Process()
                    {
                        StartInfo = proc
                    };
                    newProcess.Start();
                    newProcess.WaitForExit();
                }
                catch
                {
                    // The user refused to allow privileges elevation.
                    // Do nothing and return directly ...
                    return;
                }
                finally
                {
                    UpdateFileAssociationsButtonState();
                }
            }
#endif
        }
Beispiel #2
0
        static bool ExecuteNonUICommandLineActions()
        {
            string[] args   = Environment.GetCommandLineArgs();
            string   action = args.Length > 1 ? args[1].Trim('"') : null;

            if (CurrentOS.IsWindows)
            {
#if WIN32
                bool isRegisterAssociationsCommand = TangraFileAssociations.COMMAND_LINE_ASSOCIATE.Equals(action, StringComparison.InvariantCultureIgnoreCase);

                try
                {
                    var fileAssociation = new TangraFileAssociations();
                    if (!fileAssociation.Registered || isRegisterAssociationsCommand)
                    {
                        fileAssociation.Associate(false);
                    }
                }
                catch (Exception ex)
                {
                    if (isRegisterAssociationsCommand)
                    {
                        Trace.WriteLine(ex.GetFullStackTrace());
                    }
                }


                return(isRegisterAssociationsCommand);
#else
                return(false);
#endif
            }
            else
            {
                return(false);
            }
        }