Ejemplo n.º 1
0
        private void Run(DirectoryInfo gamePath, ClientLanguage language, Process gameProcess)
        {
            Log.Information("[HOOKS] DalamudLauncher::Run(gp:{0}, cl:{1}, d:{2}", gamePath.FullName, language);

            if (!CheckVcRedist())
            {
                return;
            }

            var ingamePluginPath  = Path.Combine(Paths.RoamingPath, "installedPlugins");
            var defaultPluginPath = Path.Combine(Paths.RoamingPath, "devPlugins");

            Directory.CreateDirectory(ingamePluginPath);
            Directory.CreateDirectory(defaultPluginPath);


            Thread.Sleep((int)App.Settings.DalamudInjectionDelayMs);

            if (DalamudUpdater.State != DalamudUpdater.DownloadState.Done)
            {
                DalamudUpdater.ShowOverlay();
            }

            while (DalamudUpdater.State != DalamudUpdater.DownloadState.Done)
            {
                if (DalamudUpdater.State == DalamudUpdater.DownloadState.Failed)
                {
                    DalamudUpdater.CloseOverlay();
                    return;
                }

                if (DalamudUpdater.State == DalamudUpdater.DownloadState.NoIntegrity)
                {
                    DalamudUpdater.CloseOverlay();

                    MessageBox.Show(Loc.Localize("DalamudAntivirusHint",
                                                 "The in-game addon ran into an error.\n\nThis is most likely caused by your antivirus. Please whitelist the quarantined files or disable the in-game addon."));
                    return;
                }

                Thread.Yield();
            }

            if (!DalamudUpdater.Runner.Exists)
            {
                CustomMessageBox.Show(
                    "Could not launch the in-game addon successfully. This might be caused by your antivirus.\nTo prevent this, please add an exception for the folder \"%AppData%\\XIVLauncher\\addons\".",
                    "XIVLauncher Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            if (!ReCheckVersion(gamePath))
            {
                DalamudUpdater.SetOverlayProgress(DalamudLoadingOverlay.DalamudLoadingProgress.Unavailable);
                DalamudUpdater.ShowOverlay();
                Log.Error("[HOOKS] ReCheckVersion fail.");

                return;
            }

            var startInfo = new DalamudStartInfo
            {
                Language               = language,
                PluginDirectory        = ingamePluginPath,
                DefaultPluginDirectory = defaultPluginPath,
                ConfigurationPath      = DalamudSettings.configPath,
                AssetDirectory         = DalamudUpdater.AssetDirectory.FullName,
                GameVersion            = Repository.Ffxiv.GetVer(gamePath),
                OptOutMbCollection     = _optOutMbCollection
            };

            var parameters = Convert.ToBase64String(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(startInfo)));

            var process = new Process
            {
                StartInfo =
                {
                    FileName  = DalamudUpdater.Runner.FullName,               WindowStyle      = ProcessWindowStyle.Hidden, CreateNoWindow = true,
                    Arguments = gameProcess.Id.ToString() + " " + parameters, WorkingDirectory = DalamudUpdater.Runner.DirectoryName
                }
            };

            process.Start();

            _overlay.Dispatcher.Invoke(() =>
            {
                _overlay.Hide();
                _overlay.Close();
            });

            DalamudUpdater.CloseOverlay();

            Serilog.Log.Information("[HOOKS] Started dalamud!");

            // Reset security protocol after updating
            ServicePointManager.SecurityProtocol = SecurityProtocolType.SystemDefault;
        }
 public static void CloseOverlay()
 {
     overlay.Dispatcher.Invoke(() => overlay.Close());
 }