Example #1
0
        private void ManageInstalls(object sender, RoutedEventArgs e)
        {
            HostDialog host = new HostDialog(Launcher.Instance.Window);

            host.Content = new ChooseInstallDialog(host);
            host.Show();
            this.SelectedVersion.Text = Launcher.Instance.Config.SelectedInstall?.Path;
        }
        public void UpdateGameInfo()
        {
            string exePath = Path.Combine(this.Config.SelectedInstall.Path, "GTA5.exe");

            if (File.Exists(exePath))
            {
                this.UiManager.GtaVersion = "GTA V " + FileVersionInfo.GetVersionInfo(exePath).FileVersion;
            }

            if (this.Config.SelectedInstall.Type == InstallType.Steam)
            {
                this.UiManager.GtaType = I18n.Localize("Label", "SteamVersion");
            }
            else if (this.Config.SelectedInstall.Type == InstallType.Retail)
            {
                this.UiManager.GtaType = I18n.Localize("Label", "RetailVersion");
            }
            else if (this.Config.SelectedInstall.Type == InstallType.Epic)
            {
                this.UiManager.GtaType = I18n.Localize("Label", "EpicVersion");
            }
            else
            {
                this.UiManager.GtaType = "";
            }

            if (Directory.Exists(this.Config.SelectedInstall.Path))
            {
                DirectoryInfo     dir = new DirectoryInfo(this.Config.SelectedInstall.Path);
                DirectorySecurity sec = dir.GetAccessControl();

                IdentityReference id = new SecurityIdentifier(WellKnownSidType.BuiltinUsersSid, null);
                bool hasPerms        = false;

                foreach (FileSystemAccessRule rule in sec.GetAccessRules(true, true, typeof(SecurityIdentifier)))
                {
                    if (rule.IdentityReference == id && rule.FileSystemRights == FileSystemRights.FullControl && rule.AccessControlType == AccessControlType.Allow)
                    {
                        hasPerms = true;
                        break;
                    }
                }

                if (!hasPerms)
                {
                    Log.Warn("The launcher doesn't have full control over the game's directory!");

                    if (User.HasElevatedPrivileges)
                    {
                        Log.Info("The launcher is running with elevated privileges. Getting full control...");
                        sec.SetAccessRule(new FileSystemAccessRule(id, FileSystemRights.FullControl, AccessControlType.Allow));
                        dir.SetAccessControl(sec);
                    }
                    else
                    {
                        Log.Info("Asking for elevated privileges...");

                        if (LocalizedCMessage.Show(this.Window, "LauncherNeedsPerms", "Info", DialogIcon.Shield, new DialogButton("Ok", true), "Cancel") == "Ok")
                        {
                            ProcessBuilder builder = new ProcessBuilder(Assembly.GetEntryAssembly().Location);
                            builder.LaunchAsAdmin = true;
                            builder.StartProcess();
                        }

                        Environment.Exit(0);
                    }
                }
            }
            else
            {
                HostDialog host = new HostDialog(this.Window);
                host.Content = new ChooseInstallDialog(host);
                host.Show();
            }
        }