Пример #1
0
        static void Main(string[] args)
        {
            // Check if the program was started from a QuickSwitch Shortcut (argument is set) and its not a special parameter (- in front)
            if (args.Length > 0 && !args[0].StartsWith("-"))
            {
                // Load all servers
                QuickSwitch.LoadServers();

                // Identify the server
                Server server = Switcher.Servers.FirstOrDefault(x => x.UID == args[0]);

                if (server != null)
                {
                    // Switch the server
                    QuickSwitch.Switch(server);

                    // If the switcher is running update the UI to not get out of sync (switcher shows connect button even though you just connected)
                    WinApi.SendMessage((IntPtr)NativeMethods.HWND_BROADCAST, NativeMethods.UOSS_UPDATE, 0, 0);
                }

                return;
            }

            // Fix DPI scaling problems and blurry texts on some devices/screens/windows screen settings
            if (Environment.OSVersion.Version.Major >= 6)
            {
                SetProcessDPIAware();
            }

            // Fix https://github.com/MinisBett/ultimate-osu-server-switcher/issues/9
            // (Windows 7 only)
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;


            // https://stackoverflow.com/questions/19147/what-is-the-correct-way-to-create-a-single-instance-wpf-application
            // Create mutex for single instance checks
            Mutex mutex = new Mutex(true, "UltimateOsuServerSwitcher");

            // Check if the mutex is owned by another process
            if (mutex.WaitOne(TimeSpan.Zero, true))
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                bool silent = args.Length > 0 && args[0] == "-silent";

                Application.Run(new MainForm(silent));

                // Release the mutex for clean up
                mutex.ReleaseMutex();
            }
            else
            {
                // If the mutex is owned by another process (a switcher instance is already running)
                // sent the WM_WAKEUP message to all processes to put the current instance in the foreground
                WinApi.SendMessage((IntPtr)NativeMethods.HWND_BROADCAST, NativeMethods.UOSS_WAKEUP, 0, 0);
            }
        }
Пример #2
0
        private void lnklblCreateShortcut_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            // let the user decide where to save the shortcut
            SaveFileDialog sfd = new SaveFileDialog();

            sfd.Filter   = "Shortcut|*.lnk";
            sfd.FileName = $"Play on {m_currentSelectedServer.ServerName}.lnk";
            if (sfd.ShowDialog() == DialogResult.OK)
            {
                // Save the shortcut
                QuickSwitch.CreateShortcut(sfd.FileName, m_currentSelectedServer);
            }
        }
        private void lblCreateShortcut_Click(object sender, EventArgs e)
        {
            SaveFileDialog sfd = new SaveFileDialog()
            {
                InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory),
                Filter           = "Shortcut|*.lnk",
                FileName         = GetSelectedServer().ServerName
            };

            if (sfd.ShowDialog() == DialogResult.OK)
            {
                QuickSwitch.CreateShortcut(GetSelectedServer(), sfd.FileName);
            }
        }
        static void Main(string[] args)
        {
            Process current = Process.GetCurrentProcess();

            Process[] instances = Process.GetProcessesByName(current.ProcessName).Where(x => x.Id != current.Id).ToArray();
            if (instances.Any())
            {
                return;
            }

            // Fix https://github.com/MinisBett/ultimate-osu-server-switcher/issues/9
            // (Windows 7 only)
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

            if (args.Length == 1)
            {
                QuickSwitch.Switch(args[0]);
                return;
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new MainForm());
        }
        private void BtnConnect_Click(object sender, EventArgs e)
        {
            bool osuWasRunning = m_osuRunning;

            if (m_osuRunning)
            {
                Process p = Process.Start(new ProcessStartInfo()
                {
                    FileName        = "taskkill",
                    Arguments       = "/IM osu!.exe",
                    CreateNoWindow  = true,
                    UseShellExecute = false
                });

                p.WaitForExit();
            }
            lblCurrentServer.Text = "Connecting...";
            Application.DoEvents();
            Server selectedServer = GetSelectedServer();

            CertificateManager.UninstallAllCertificates(m_servers);
            List <string> hosts = HostsUtil.GetHosts().ToList();

            hosts.RemoveAll(x => x.Contains(".ppy.sh"));
            HostsUtil.SetHosts(hosts.ToArray());

            if (!selectedServer.IsBancho)
            {
                string[] osu_domains = new string[]
                {
                    //"delta.ppy.sh",
                    "osu.ppy.sh",
                    "c.ppy.sh",
                    "c1.ppy.sh",
                    "c2.ppy.sh",
                    "c3.ppy.sh",
                    "c4.ppy.sh",
                    "c5.ppy.sh",
                    "c6.ppy.sh",
                    "ce.ppy.sh",
                    "a.ppy.sh",
                    //"s.ppy.sh",
                    "i.ppy.sh",
                    //"bm6.ppy.sh",
                };

                hosts = HostsUtil.GetHosts().ToList();
                foreach (string domain in osu_domains)
                {
                    hosts.Add(selectedServer.ServerIP + " " + domain);
                }
                HostsUtil.SetHosts(hosts.ToArray());

                if (!selectedServer.IsLocalhost)
                {
                    CertificateManager.InstallCertificate(selectedServer);
                }
            }

            if (osuWasRunning)
            {
                Process.Start(QuickSwitch.GetOsuExecutablePath());
            }

            UpdateServerUI();
        }