Example #1
0
 private void AttributesMenu_FormClosing(object sender, FormClosingEventArgs e)
 {
     Hide();
     Thread.Sleep(250);
     ExplorerRefresh.RefreshWindowsExplorer();
 }
Example #2
0
        private void AddToFirewall(string operation)
        {
            TryAgain :;
            try
            {
                int dotCount = 0;
                FilesCount = 0;
                Thread thread = new Thread(() => EnumerateFiles())
                {
                    IsBackground = true
                };
                thread.Start();
                progressBar1.Value = 0;
                current            = 0;

                if (operation == Resources.FirewallArgs && RootPath != null)
                {
                    while (CountingFilesOperation)
                    {
                        Thread.Sleep(500);

                        dotCount++;
                        if (dotCount == 2)
                        {
                            label1.Text = Operation;
                        }

                        if (dotCount == 4)
                        {
                            label1.Text = Operation + ".";
                        }

                        if (dotCount == 6)
                        {
                            label1.Text = Operation + "..";
                        }
                        if (dotCount == 8)
                        {
                            label1.Text = Operation + "...";
                            dotCount    = 0;
                        }
                        Application.DoEvents();
                    }
                    label1.Text = Resources.Blocking + Resources.outbound;
                    foreach (string item in RootPath)
                    {
                        try
                        {
                            while (PauseOperation)
                            {
                                Thread.Sleep(500);
                            }

                            current++;
                            string path      = Path.GetDirectoryName(item);
                            string title     = Path.GetFileName(path) + " - " + Path.GetFileName(item);
                            string arguments = "advfirewall firewall add rule name=" + "\"" + MainFolderName + " - " + title + "\"" + " dir=out program=" + "\"" + item + "\"" + " action=block";
                            progressBar1.Value = (current * 100) / FilesCount;
                            try
                            {
                                Text = Resources.BlockingFilesTitle + progressBar1.Value + Resources.Percentage;
                            }
                            catch (ArgumentOutOfRangeException ex)
                            {
                                EasyLogger.Error(ex);
                                continue;
                            }
                            label2.Text = Path.GetFileName(Path.GetDirectoryName(item)) + ": " + Path.GetFileName(item);
                            Application.DoEvents();
                            StartProcess.StartInfo("netsh.exe", arguments, true, true, true);
                        }
                        catch (ArgumentOutOfRangeException ex)
                        {
                            EasyLogger.Error(ex);
                            continue;
                        }
                    }
                    current            = 0;
                    progressBar1.Value = 0;
                    label1.Text        = Resources.Blocking + Resources.inbound;
                    foreach (string item in RootPath)
                    {
                        try
                        {
                            while (PauseOperation)
                            {
                                Thread.Sleep(500);
                            }

                            current++;
                            string path      = Path.GetDirectoryName(item);
                            string title     = Path.GetFileName(path) + " - " + Path.GetFileName(item);
                            string arguments = "advfirewall firewall add rule name=" + "\"" + MainFolderName + " - " + title + "\"" + " dir=in program=" + "\"" + item + "\"" + " action=block";
                            progressBar1.Value = (current * 100) / FilesCount;
                            try
                            {
                                Text = Resources.BlockingFilesTitle + progressBar1.Value + Resources.Percentage;
                            }
                            catch (ArgumentOutOfRangeException ex)
                            {
                                EasyLogger.Error(ex);
                                continue;
                            }
                            label2.Text = Path.GetFileName(Path.GetDirectoryName(item)) + ": " + Path.GetFileName(item);
                            Application.DoEvents();
                            StartProcess.StartInfo("netsh.exe", arguments, true, true, true);
                        }
                        catch (ArgumentOutOfRangeException ex)
                        {
                            EasyLogger.Error(ex);
                            continue;
                        }
                    }
                    Thread.Sleep(1500);
                    if (current > 0 && NoMoreThreads)
                    {
                        Hide();

                        DialogResult results = MessageForm(Resources.DialogMessageBlockFolder, Resources.DialogTitleSuccess, MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button2);
                        if (results == DialogResult.Yes)
                        {
                            StartProcess.StartInfo("wf.msc");
                        }
                    }
                    else if (current == 0)
                    {
                        Hide();

                        MessageForm(Resources.DialogMessageFail, Resources.DialogTitleFail, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                ThreadRunning = false;
                if (NoMoreThreads)
                {
                    ExplorerRefresh.RefreshWindowsExplorer();
                    Environment.Exit(0);
                }
            }
            catch (Exception ex)
            {
                EasyLogger.Error(ex);
                goto TryAgain;
            }
        }
Example #3
0
 private void Button1_Click(object sender, EventArgs e)
 {
     ExplorerRefresh.RefreshWindowsExplorer();
 }
Example #4
0
        public Main(string[] args)
        {
            try
            {
                InitializeComponent();

                Shown += Main_Shown;

                if (args.Length == 0)
                {
                    Settings settings = new Settings();
                    using (settings)
                    {
                        settings.ShowDialog();
                    }
                }
                if (args.Length > 0)
                {
                    // Refresh Explorer
                    if (args[0] == Resources.RefreshArgs)
                    {
                        ExplorerRefresh.RefreshWindowsExplorer();
                    }
                    // Install
                    if (args[0] == Resources.InstallArgs || args[0] == Resources.InstallArgsShort)
                    {
                        if (IsElevated)
                        {
                            Installation.InstallerElevated();
                        }
                        else
                        {
                            Installation.InstallerUnelevated();
                        }
                    }
                    // Uninstall
                    if (args[0] == Resources.UninstallArgs || args[0] == Resources.UninstallArgsShort)
                    {
                        if (IsElevated)
                        {
                            Installation.InstallerElevated();
                        }
                        else
                        {
                            Installation.InstallerUnelevated();
                        }
                    }
                    // Settings
                    if (args[0] == Resources.SettingArgs || args[0] == Resources.SettingArgsShort)
                    {
                        Settings settings = new Settings();
                        using (settings)
                        {
                            settings.ShowDialog();
                        }
                    }
                }
                if (args.Length > 1)
                {
                    ExecuteCommands(args);
                }
                if (!KeepAlive)
                {
                    Environment.Exit(0);
                }
            }
            catch (Exception ex)
            {
                MessageForm(ex.Message + Environment.NewLine + ex.StackTrace + Environment.NewLine + ex.Source + Environment.NewLine + ex.GetBaseException() + Environment.NewLine + ex.TargetSite, "xMenuTools", MessageBoxButtons.OK, MessageBoxIcon.Error);

                Environment.Exit(0);
            }
        }