Exemplo n.º 1
0
 private void UxFixHeight()
 {
     if (Elevated.IsElevated())
     {
         Height -= 45;
     }
 }
Exemplo n.º 2
0
    private void UxFixButtonText()
    {
        if (!Elevated.IsElevated())
        {
            uxbtnEdit.Text = @"|Open &Hosts File";
        }

        uxbtnEdit.Text             = uxbtnEdit.Text.Replace("|", Environment.NewLine);
        uxbtnDisableHostsFile.Text = uxbtnDisableHostsFile.Text.Replace("|", Environment.NewLine);
        uxbtnEnableHostsFile.Text  = uxbtnEnableHostsFile.Text.Replace("|", Environment.NewLine);
        uxbtnFlushDNS.Text         = uxbtnFlushDNS.Text.Replace("|", Environment.NewLine);
    }
Exemplo n.º 3
0
    private void uxMenuEnableHostsFile_Click(object sender, EventArgs e)
    {
        if (!Elevated.IsElevated())
        {
            return;
        }

        if (uxMenuEnableHostsFile.Checked)
        {
            HostsFile.EnableHostsFile();
        }
        else
        {
            HostsFile.DisableHostsFile();
        }

        if (Visible)
        {
            UxRefresh();
        }
    }
Exemplo n.º 4
0
    private void UxRefresh()
    {
        uxlblEnabled.Text = @"Hosts file is " + (HostsFile.IsEnabled()
            ? "enabled."
            : "disabled.");

        uxlblHostsFileSize.Text = HostsFile
                                  .HostsFileSize()
                                  .ToString("##,###0") + @" byte(s)";

        uxlblHostsCount.Text =
            HostsFile
            .HostsCount()
            .ToString("##,###0");

        var hostsEnabled = HostsFile.IsEnabled();

        uxMenuEnableHostsFile.Checked = hostsEnabled;

        var hostOrHosts = HostsFile
                          .HostsCount() > 1
            ? "hosts"
            : "host";

        uxNotifyIcon.Text = @"Hosts Manager" + (hostsEnabled
            ? " (" + uxlblHostsCount.Text + " " + hostOrHosts + " enabled)"
            : " (disabled)");

        // button state
        if (Elevated.IsElevated())
        {
            // Elevated, set button state appropriately
            uxbtnRunAsAdmin.Enabled     =
                uxbtnRunAsAdmin.Visible =
                    uxlblSep.Visible    = false;

            uxbtnEdit.Enabled =
                uxbtnDisableHostsFile.Enabled = hostsEnabled;

            uxbtnEnableHostsFile.Enabled = !hostsEnabled;

            uxbtnFlushDNS.Enabled = true;

            // Indicate that we are running as admin.
            if (!Text.Contains("[Administrator]"))
            {
                Text += @" [Administrator]";
            }
        }
        else
        {
            // Not elevated, disable all except Run As Admin
            uxbtnDisableHostsFile.Enabled         =
                uxbtnEnableHostsFile.Enabled      =
                    uxMenuEnableHostsFile.Enabled =
                        uxbtnFlushDNS.Enabled     = false;

            // When Not elevated "edit/open" should only be available when the hosts file itself is enabled
            uxbtnEdit.Enabled = hostsEnabled;

            Elevated.AddShieldToButton(uxbtnRunAsAdmin);
        }
    }