Exemplo n.º 1
0
        private void UpdateHostsFile()
        {
            foreach (var option in Config.BlockOptions)
            {
                var remoteFileSize = Common.GetRemoteFileSize(option.IpUrl);
                var localFileSize  = File.Exists(option.IpFileName) ? new FileInfo(option.IpFileName).Length : 0;
                if (remoteFileSize != localFileSize)
                {
                    var answer = MessageBox.Show($"A new {option.Tag} ip file was released, do you want to update it ?", "Update", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                    if (answer == DialogResult.Yes)
                    {
                        var frm = new FormDownload(option.IpUrl, option.IpFileName);
                        frm.ShowDialog(this);
                    }
                }

                remoteFileSize = Common.GetRemoteFileSize(option.DomainsUrl);
                localFileSize  = File.Exists(option.DomainsFileName) ? new FileInfo(option.DomainsFileName).Length : 0;
                if (remoteFileSize != localFileSize)
                {
                    var answer = MessageBox.Show($"A new {option.Tag} domains file was released, do you want to update it ?", "Update", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                    if (answer == DialogResult.Yes)
                    {
                        var frm = new FormDownload(option.DomainsUrl, option.DomainsFileName);
                        frm.ShowDialog(this);
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void FormRemoveoLoad(object sender, EventArgs e)
        {
            if (Config.BlockOptions.All(o => !File.Exists(o.IpFileName) && !File.Exists(o.DomainsFileName)) && !File.Exists(Config.CustomOption.IpFileName) && !File.Exists(Config.CustomOption.DomainsFileName))
            {
                var answer = MessageBox.Show("No hosts file found. Download hosts file ?", "Hosts not found", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                if (answer == DialogResult.OK)
                {
                    foreach (var option in Config.BlockOptions)
                    {
                        var remoteFileSize = Common.GetRemoteFileSize(option.IpUrl);
                        var localFileSize  = File.Exists(option.IpFileName) ? new FileInfo(option.IpFileName).Length : 0;
                        if (remoteFileSize != localFileSize)
                        {
                            var frm = new FormDownload(option.IpUrl, option.IpFileName);
                            frm.ShowDialog(this);
                        }

                        remoteFileSize = Common.GetRemoteFileSize(option.DomainsUrl);
                        localFileSize  = File.Exists(option.DomainsFileName) ? new FileInfo(option.DomainsFileName).Length : 0;
                        if (remoteFileSize != localFileSize)
                        {
                            var frm = new FormDownload(option.DomainsUrl, option.DomainsFileName);
                            frm.ShowDialog(this);
                        }
                    }
                }
                else
                {
                    BeginInvoke((MethodInvoker)(() => Close()));
                    return;
                }
            }

            if (!Firewall.Initialize(out var errorMessage))
            {
                Common.Error(errorMessage);
                BeginInvoke((MethodInvoker)(() => Close()));
                return;
            }

            if (!Firewall.IsFirewallEnabled(out errorMessage))
            {
                Common.Error(errorMessage);
                BeginInvoke((MethodInvoker)(() => Close()));
                return;
            }

            if (Config.Activated /*&& Firewall.IsRuleEnabled("removeo")*/)
            {
                SetStatus("Removeo activated", Color.Blue);
            }
            else
            {
                Config.Activated         = false;
                buttonDeactivate.Enabled = false;
                SetStatus("Removeo deactivated", Color.Red);
            }
        }