Пример #1
0
        public async Task DisconnectFromRipple()
        {
            Logger.Info("Disconnecting from Ripple");
            await hostsFile.Parse();

            hostsFile.semaphore.Wait();
            try
            {
                Logger.Info("Removing hosts file entries");
                hostsFile.Entries.RemoveAll(x => x is HostsEntry && ((HostsEntry)x).domain.Contains(".ppy.sh"));
                await hostsFile.Write();
            }
            finally
            {
                hostsFile.semaphore.Release();
            }
            Logger.Info("Hosts file entries removed. Now re-parsing hosts file");
            await hostsFile.Parse();

            if (IsConnectedToRipple())
            {
                throw new HumanReadableException("Can't delete entries. Disable antivirus.", "The hosts file looks writable, but Ripple Server Switcher wasn't able to delete the entries from it and switch back to osu!. There is most likely a software blocking access to the hosts file. Please disable your antivirus, third party firewall or any similar software that may block edits on the hosts file.");
            }
            Logger.Info("Successfully disconected from Ripple");
        }
        private async Task updateHostsFileStatus()
        {
            HostsFile h = new HostsFile();

            try
            {
                await h.Parse();

                hostsFileReadableLabel.Text      = "YES";
                hostsFileReadableLabel.ForeColor = Color.Green;
            }
            catch
            {
                hostsFileReadableLabel.Text      = "NO";
                hostsFileReadableLabel.ForeColor = Color.Red;
            }

            ArbitraryHostsEntry testEntry = new ArbitraryHostsEntry(String.Format("# rss test {0}", Guid.NewGuid().ToString()));

            hostsFileWritableLabel.Text      = "...";
            hostsFileWritableLabel.ForeColor = Color.Blue;

            try
            {
                h.Entries.Add(testEntry);
                await h.Write();

                await h.Parse();

                if (!h.Entries.Any(x => x is ArbitraryHostsEntry && ((ArbitraryHostsEntry)x).Equals(testEntry)))
                {
                    throw new Exception();
                }
                h.Entries.RemoveAll(x => x.ToString() == testEntry.ToString());
                await h.Write();

                await h.Parse();

                hostsFileWritableLabel.Text      = "YES";
                hostsFileWritableLabel.ForeColor = Color.Green;
            }
            catch
            {
                hostsFileWritableLabel.Text      = "NO";
                hostsFileWritableLabel.ForeColor = Color.Red;
            }

            bool ripple = Program.Switcher.IsConnectedToRipple();

            hostsFileRippleLabel.Text      = ripple ? "YES" : "NO";
            hostsFileRippleLabel.ForeColor = ripple ? Color.Green : Color.Yellow;
        }