private void UpdateFileAssociationsButtonState() { if (CurrentOS.IsWindows) { #if WIN32 btnAssociateFiles.Visible = true; btnAssociateFiles.Enabled = true; var fileAssociation = new TangraFileAssociations(); if (fileAssociation.Registered) { btnAssociateFiles.Text = "Re-Associate files with Tangra"; } else { btnAssociateFiles.Text = "Associate files with Tangra"; if (!fileAssociation.CanRegisterWithoutElevation) { btnAssociateFiles.FlatStyle = FlatStyle.System; WindowsHelpers.SendMessage(btnAssociateFiles.Handle, WindowsHelpers.BCM_SETSHIELD, 0, (IntPtr)1); } } if (fileAssociation.CanRegisterWithoutElevation) btnAssociateFiles.Tag = fileAssociation; #endif } else btnAssociateFiles.Visible = false; }
static bool ExecuteNonUICommandLineActions() { string action = Environment.GetCommandLineArgs().Length > 1 ? Environment.GetCommandLineArgs()[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; }