Exemple #1
0
 private void btnLocalServer_MouseClick(object sender, MouseEventArgs e)
 {
     ViewState = ServerListViewState.LocalServers;
     editLocalShardControl1.Visible = false;
 }
        private void OnShardListControlButtonClicked(object sender, ShardListItemButtonClickedEventArgs e)
        {
            if (e.Button is AddToFavoritesShardListItemButton)
            {
                e.Item.Server.Favorite = true;
                _storageService.SaveChanges();

                ViewState = ServerListViewState.FavoritesServers;
            }
            else if (e.Button is PlayShardListItemButton)
            {
                if (e.Item.Server == null)
                {
                    throw new ArgumentNullException("e.Item.Server");
                }

                Tracer.Verbose("Preparing to play {0}...", e.Item.Server.Name);
                lblStatus.Text = string.Format("Preparing to play {0}...", e.Item.Server.Name);

                string uri = CuoUri.BuildPlayString(e.Item.Server);

                if (e.Item.Server.HasPatches)
                {
                    Tracer.Verbose("Server has patches, checking...");

                    if (e.Item.Server.Public)
                    {
                        Tracer.Verbose("Retrieving patching information for {0}...", e.Item.Server.Name);
                        lblStatus.Text = string.Format("Retrieving patching information for {0}...", e.Item.Server.Name);

                        try
                        {
                            ServerPatch[] patches = _storageService.GetPatches((int)e.Item.Server.Id);

                            Tracer.Verbose("Found {0} patches...", patches.Length);

                            StringBuilder sb = new StringBuilder();

                            for (int i = 0; i < patches.Length; i++)
                            {
                                sb.AppendFormat("{0}|{1}{2}", patches[i].PatchUrl, patches[i].Version, i + 1 < patches.Length ? ";" : "");
                            }

                            uri = string.Join(string.Format("&{0}=", CuoUri.PatchesTolken), new string[] { uri, sb.ToString() });
                        }
                        catch (Exception ex)
                        {
                            Tracer.Error(ex);
                            MessageBoxEx.Show(this, "Unable to get patch information for this server.  See the debug log for details.", "ConnectUO 2.0");
                        }
                    }
                    else
                    {
                        try
                        {
                            LocalPatch[] patches = _storageService.GetLocalPatches((int)e.Item.Server.Id);

                            Tracer.Verbose("Found {0} patches...", patches.Length);

                            StringBuilder sb = new StringBuilder();

                            for (int i = 0; i < patches.Length; i++)
                            {
                                sb.AppendFormat("{0}|{1}{2}", patches[i].PatchUrl, patches[i].Version, i + 1 < patches.Length ? ";" : "");
                            }

                            uri = string.Join(string.Format("&{0}=", CuoUri.PatchesTolken), new string[] { uri, sb.ToString() });
                        }
                        catch (Exception ex)
                        {
                            Tracer.Error(ex);
                            MessageBoxEx.Show(this, "Unable to get patch information for this server.  See the debug log for details.", "ConnectUO 2.0");
                        }
                    }
                }

                Tracer.Verbose("Play URI: {0}", uri);
                uri = string.Format("cuo://{0}", Uri.EscapeDataString(Convert.ToBase64String(Encoding.UTF8.GetBytes(uri))));

                _kernel.Get<CuoUri>().Play(uri);

                lblStatus.Text = "";
            }
            else if (e.Button is RemoveFavoriteShardListItemButton)
            {
                e.Item.Server.Favorite = false;
                _storageService.SaveChanges();
                RefreshServerView();
            }
            //else if (e.Button is HideListItemButton)
            //{
            //    //_storageService.HideServer(e.Item.Server);
            //    RefreshServerView();
            //}
            else if (e.Button is RemoveCustomShardListItemButton)
            {
                if (MessageBoxEx.Show(this, "Are you sure you want to remove this server?",
                    "ConnectUO 2.0", MessageBoxButtons.YesNoCancel) == DialogResult.Yes)
                {
                    _storageService.DeleteServer(e.Item.Server);
                    RefreshServerView();
                }
            }
            else if (e.Button is EditLocalShardListItemButton)
            {
                editLocalShardControl1.Server = e.Item.Server;
                editLocalShardControl1.Visible = true;
            }
            else if (e.Button is ResetPatchesListItemButton)
            {
                if (MessageBoxEx.Show(this, "This will remove all applied patches for this server from your computer.  Are you sure you want to continue?",
                    "ConnectUO 2.0", MessageBoxButtons.YesNoCancel) == DialogResult.Yes)
                {
                    if (_storageService.ServerIsCurrentlyBeingPlayed(e.Item.Server))
                    {
                        MessageBoxEx.Show(this,
                            "ConnectUO has detected that you are currently playing this server and cannot reset the patches until the Ultima Online client connected bas been closed.", "ConnectUO 2.0");
                        return;
                    }
                    else
                    {
                        _storageService.ResetPatches((int)e.Item.Server.Id);

                        try
                        {
                            string serverDirectory = Path.Combine(_settingsService.PatchDirectory, Uri.EscapeDataString(e.Item.Server.Name));

                            if (Directory.Exists(serverDirectory))
                            {
                                FileInfo[] files = new DirectoryInfo(serverDirectory).GetFiles();

                                for (int i = 0; i < files.Length; i++)
                                {
                                    try
                                    {
                                        files[i].Delete();
                                    }
                                    catch (Exception ex)
                                    {
                                        //These aren't crucial, thus i just log as info...
                                        Tracer.Info(ex);
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            //These aren't crucial, thus i just log as info...
                            Tracer.Info(ex);
                        }
                    }

                    MessageBoxEx.Show(this, "Patch Reset Complete.", "ConnectUO 2.0");
                }
            }
            else if (e.Button is WebsiteListItemButton)
            {
                Process.Start(e.Item.Server.Url);
            }
            else
            {
                MessageBoxEx.Show(this, String.Format("No click statement for {0}", e.Button.GetType()), "ConnectUO 2.0");
            }

            shardListControl.Invalidate();
        }
Exemple #3
0
        private void OnShardListControlButtonClicked(object sender, ShardListItemButtonClickedEventArgs e)
        {
            if (e.Button is AddToFavoritesShardListItemButton)
            {
                e.Item.Server.Favorite = true;
                _storageService.SaveChanges();

                ViewState = ServerListViewState.FavoritesServers;
            }
            else if (e.Button is PlayShardListItemButton)
            {
                if (e.Item.Server == null)
                {
                    throw new ArgumentNullException("e.Item.Server");
                }

                Tracer.Verbose("Preparing to play {0}...", e.Item.Server.Name);
                lblStatus.Text = string.Format("Preparing to play {0}...", e.Item.Server.Name);

                string uri = CuoUri.BuildPlayString(e.Item.Server);

                if (e.Item.Server.HasPatches)
                {
                    Tracer.Verbose("Server has patches, checking...");

                    if (e.Item.Server.Public)
                    {
                        Tracer.Verbose("Retrieving patching information for {0}...", e.Item.Server.Name);
                        lblStatus.Text = string.Format("Retrieving patching information for {0}...", e.Item.Server.Name);

                        try
                        {
                            ServerPatch[] patches = _storageService.GetPatches((int)e.Item.Server.Id);

                            Tracer.Verbose("Found {0} patches...", patches.Length);

                            StringBuilder sb = new StringBuilder();

                            for (int i = 0; i < patches.Length; i++)
                            {
                                sb.AppendFormat("{0}|{1}{2}", patches[i].PatchUrl, patches[i].Version, i + 1 < patches.Length ? ";" : "");
                            }

                            uri = string.Join(string.Format("&{0}=", CuoUri.PatchesTolken), new string[] { uri, sb.ToString() });
                        }
                        catch (Exception ex)
                        {
                            Tracer.Error(ex);
                            MessageBoxEx.Show(this, "Unable to get patch information for this server.  See the debug log for details.", "ConnectUO 2.0");
                        }
                    }
                    else
                    {
                        try
                        {
                            LocalPatch[] patches = _storageService.GetLocalPatches((int)e.Item.Server.Id);

                            Tracer.Verbose("Found {0} patches...", patches.Length);

                            StringBuilder sb = new StringBuilder();

                            for (int i = 0; i < patches.Length; i++)
                            {
                                sb.AppendFormat("{0}|{1}{2}", patches[i].PatchUrl, patches[i].Version, i + 1 < patches.Length ? ";" : "");
                            }

                            uri = string.Join(string.Format("&{0}=", CuoUri.PatchesTolken), new string[] { uri, sb.ToString() });
                        }
                        catch (Exception ex)
                        {
                            Tracer.Error(ex);
                            MessageBoxEx.Show(this, "Unable to get patch information for this server.  See the debug log for details.", "ConnectUO 2.0");
                        }
                    }
                }

                Tracer.Verbose("Play URI: {0}", uri);
                uri = string.Format("cuo://{0}", Uri.EscapeDataString(Convert.ToBase64String(Encoding.UTF8.GetBytes(uri))));

                _kernel.Get <CuoUri>().Play(uri);

                lblStatus.Text = "";
            }
            else if (e.Button is RemoveFavoriteShardListItemButton)
            {
                e.Item.Server.Favorite = false;
                _storageService.SaveChanges();
                RefreshServerView();
            }
            //else if (e.Button is HideListItemButton)
            //{
            //    //_storageService.HideServer(e.Item.Server);
            //    RefreshServerView();
            //}
            else if (e.Button is RemoveCustomShardListItemButton)
            {
                if (MessageBoxEx.Show(this, "Are you sure you want to remove this server?",
                                      "ConnectUO 2.0", MessageBoxButtons.YesNoCancel) == DialogResult.Yes)
                {
                    _storageService.DeleteServer(e.Item.Server);
                    RefreshServerView();
                }
            }
            else if (e.Button is EditLocalShardListItemButton)
            {
                editLocalShardControl1.Server  = e.Item.Server;
                editLocalShardControl1.Visible = true;
            }
            else if (e.Button is ResetPatchesListItemButton)
            {
                if (MessageBoxEx.Show(this, "This will remove all applied patches for this server from your computer.  Are you sure you want to continue?",
                                      "ConnectUO 2.0", MessageBoxButtons.YesNoCancel) == DialogResult.Yes)
                {
                    if (_storageService.ServerIsCurrentlyBeingPlayed(e.Item.Server))
                    {
                        MessageBoxEx.Show(this,
                                          "ConnectUO has detected that you are currently playing this server and cannot reset the patches until the Ultima Online client connected bas been closed.", "ConnectUO 2.0");
                        return;
                    }
                    else
                    {
                        _storageService.ResetPatches((int)e.Item.Server.Id);

                        try
                        {
                            string serverDirectory = Path.Combine(_settingsService.PatchDirectory, Uri.EscapeDataString(e.Item.Server.Name));

                            if (Directory.Exists(serverDirectory))
                            {
                                FileInfo[] files = new DirectoryInfo(serverDirectory).GetFiles();

                                for (int i = 0; i < files.Length; i++)
                                {
                                    try
                                    {
                                        files[i].Delete();
                                    }
                                    catch (Exception ex)
                                    {
                                        //These aren't crucial, thus i just log as info...
                                        Tracer.Info(ex);
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            //These aren't crucial, thus i just log as info...
                            Tracer.Info(ex);
                        }
                    }

                    MessageBoxEx.Show(this, "Patch Reset Complete.", "ConnectUO 2.0");
                }
            }
            else if (e.Button is WebsiteListItemButton)
            {
                Process.Start(e.Item.Server.Url);
            }
            else
            {
                MessageBoxEx.Show(this, String.Format("No click statement for {0}", e.Button.GetType()), "ConnectUO 2.0");
            }

            shardListControl.Invalidate();
        }
 private void btnPublicServers_MouseClick(object sender, MouseEventArgs e)
 {
     ViewState = ServerListViewState.PublicServers;
     editLocalShardControl1.Visible = false;
 }