Beispiel #1
0
        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            _kernel.Load(AppDomain.CurrentDomain.GetAssemblies());

            StartupArgumentFlagCollection startupFlags       = new StartupArgumentFlagCollection();
            IApplicationService           applicationService = _kernel.Get <IApplicationService>();
            ApplicationInfo applicationInfo = new ApplicationInfo(Assembly.GetEntryAssembly(), args, startupFlags);

            Directory.SetCurrentDirectory(applicationInfo.BaseDirectory);

            applicationService.ApplicationInfo = applicationInfo;
            //applicationService.TraceListeners.Add(new CrashLogTraceListener());

            if (applicationService.Debug)
            {
                applicationService.TraceListeners.Add(new FileTraceListener(Path.Combine(applicationInfo.BaseDirectory, "debug.log")));
            }

            EnsureDotNet35SP1();

            CuoUri.Initialize(applicationService);

            if (ContainsCuoProtocol(args))
            {
                return;
            }

            using (Mutex mutex = new Mutex(false, MutexName))
            {
                Tracer.Verbose("Entering Mutex {0}", MutexName);

                if (!mutex.WaitOne(1, true))
                {
                    MessageBoxEx.Show(null, "ConnectUO is already running.");
                    return;
                }

                SplashScreen splashScreen = _kernel.Get <SplashScreen>();
                ShellForm    mainForm     = _kernel.Get <IShell>() as ShellForm;

                applicationService.MainForm = mainForm;

                Application.Run(splashScreen);
                Application.Run(mainForm);
            }
        }
Beispiel #2
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();
        }
Beispiel #3
0
        public override void OnClick(IKernel kernel)
        {
            IStorageService storageService = kernel.Get <IStorageService>();
            ShellForm       form           = kernel.Get <ShellForm>();

            Asserter.AssertIsNotNull(form, "form");
            Asserter.AssertIsNotNull(Item.Server, "Item.Server");

            form.SetStatus("Preparing to play {0}...", Item.Server.Name);

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

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

                if (Item.Server.Public)
                {
                    form.SetStatus("Retrieving patching information for {0}...", Item.Server.Name);

                    try
                    {
                        ServerPatch[] patches = storageService.GetPatches((int)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(form, "Unable to get patch information for this server.  See the debug log for details.", "ConnectUO 2.0");
                    }
                }
                else
                {
                    try
                    {
                        LocalPatch[] patches = storageService.GetLocalPatches((int)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(form, "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);

            form.SetStatus(string.Empty);
        }