示例#1
0
        public Launcher(
            SettingsManager settings,
            VersionsManager versions,
            ProfilesManager profiles,
            HttpClient httpClient,
            TtyhClient ttyhClient,
            GameRunner runner,
            ILauncherUi ui,
            ILogger logger,
            string launcherName)
        {
            var translationsPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Translations");

            _tr = new Translator(new Catalog("core", translationsPath));

            _settings = settings;
            _versions = versions;
            _profiles = profiles;

            _ttyhClient = ttyhClient;
            _runner     = runner;

            _hashChecker = new HashChecker(logger);
            _downloader  = new Downloader(httpClient, logger);

            _ui = ui;

            _logger        = logger;
            _logger.OnLog += _ui.AppendLog;

            _log = new WrappedLogger(logger, launcherName);

            _ui.OnExit += HandleExit;
            _ui.OnPlayButtonClicked += HandlePlayButtonClicked;
            _ui.OnOfflineModeToggle += HandleOfflineModeToggle;

            _ui.OnUploadSkinClicked += HandleSkinUploadClicked;

            _ui.OnEditProfileClicked   += HandleEditProfile;
            _ui.OnAddProfileClicked    += HandleAddProfile;
            _ui.OnRemoveProfileClicked += HandleRemoveProfile;
        }
示例#2
0
        public void Run()
        {
            AppContext.SetSwitch("System.Net.Http.UseSocketsHttpHandler", false);

            const string appName    = "TtyhLauncher2";
            const string appVersion = "0.0.1";
            const string appUrl     = "https://github.com/dngulin/ttyhlauncher2";

            const string storeUrl  = "https://ttyh.ru/files/newstore";
            const string masterUrl = "https://master.ttyh.ru";
            const string directory = "ttyhlauncher2";

            const int logRotateCount = 3;
            const int requestTimeOut = 5;

            var serializer = new JsonSerializer {
                Formatting             = Formatting.Indented,
                ObjectCreationHandling = ObjectCreationHandling.Replace
            };
            var json = new JsonParser(serializer);

            using (var logger = new FileLogger(directory, logRotateCount))
                using (var settings = new SettingsManager(directory, json, logger))
                    using (var httpClient = new HttpClient()) {
                        httpClient.Timeout = TimeSpan.FromSeconds(requestTimeOut);
                        logger.OnLog      += Console.Out.WriteLine;

                        var versions   = new VersionsManager(storeUrl, directory, httpClient, json, logger);
                        var profiles   = new ProfilesManager(directory, json, logger);
                        var ttyhClient = new TtyhClient(masterUrl, appVersion, settings.Ticket, httpClient, serializer, logger);
                        var runner     = new GameRunner(directory, json, logger, appName, appVersion);

                        var ui       = CreateUi(appName, appVersion, appUrl);
                        var launcher = new Launcher(settings, versions, profiles, httpClient, ttyhClient, runner, ui, logger, appName);

                        launcher.Start();
                        RunEventLoop();
                    }
        }