Ejemplo n.º 1
0
        private void ChangeActiveProfile(Dos2ModsSettings profile)
        {
            // FIXME bad check
            if (profile == null)
            {
                return;
            }

            //get old profile
            var id = profile.UUID;

            Profiles.FirstOrDefault(x => x.IsActive).IsActive   = false;
            Profiles.FirstOrDefault(x => x.UUID == id).IsActive = true;

            //write to the lsb
            // FIXME I don't want this here

            //go into workspace view model and apply view
            if (AnchorablesSource != null)
            {
                WorkspaceViewModel wvm = (WorkspaceViewModel)AnchorablesSource.First(x => x.ContentId == "mods");
                if (wvm != null)
                {
                    wvm.ApplyModSettings(ActiveProfile);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Applies Profile Settings to ModList
        /// </summary>
        #region Appply Mod Settings
        /// <summary>
        /// Change Load Order and enables mods depending on active profile
        /// </summary>
        public void ApplyModSettings(Dos2ModsSettings activeSettings)
        {
            //Dos2ModsSettings activeSettings = ParentViewModel.Profiles.FirstOrDefault(x => x.IsActive);
            foreach (var mod in ModsList)
            {
                mod.IsEnabled = activeSettings.ActiveMods.Contains(mod.UUID);
                //find index of mod by UUID
                mod.LoadOrder = activeSettings.ModLoadOrder.FindIndex(x => x == mod.UUID);
            }
            var uncategorized = ModsList.Where(x => x.LoadOrder < 0).ToList();

            foreach (var item in uncategorized)
            {
                // give highest load order index
                int maxLoadOrder = ModsList.Max(x => x.LoadOrder);
                item.LoadOrder = maxLoadOrder + 1;
            }

            SortCollectionByProperty("LoadOrder");
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets Data from profile lsbs and lsx
        /// </summary>
        #region GetProfileData
        /// <summary>
        /// Gets Data from profile lsbs and lsx and returns the UUID of the active profile.
        /// </summary>
        /// <param name="activeProfileID"></param>
        /// <returns></returns>
        private bool GetProfileInfo()
        {
            Logger.Status = "Fetching Profile Data...";
            Logger.LogString("Fetching Profile Data...");

            Profiles.Clear(); //FIXME check for changes

            //get active profile ID
            string            profileDir    = Path.Combine(Path.GetDirectoryName(Dos2.ModManager.Properties.Settings.Default.Mods), @"PlayerProfiles");
            string            fileName      = Path.Combine(profileDir, @"playerprofiles.lsb");
            DOS2_UserProfiles playerProfile = lt.GetActiveProfile(fileName);

            //checks
            if (!File.Exists(fileName) || playerProfile == null || String.IsNullOrEmpty(playerProfile.ActiveProfile))
            {
                MessageBoxResult result = MessageBox.Show(
                    "No active profile found. Please check your paths or start the game once.",
                    "Error", MessageBoxButton.OK, MessageBoxImage.Warning);
                Logger.Status = "Finished With Errors.";
                Logger.LogString("No active profile found. Please check your paths or start the game once.");
                return(false);
            }
            else if (!Directory.Exists(profileDir) || !Directory.GetDirectories(profileDir).ToList().Any())
            {
                MessageBoxResult result = MessageBox.Show(
                    "No profile data found. Please check your paths or start the game once.",
                    "Error", MessageBoxButton.OK, MessageBoxImage.Warning);
                Logger.Status = "Finished With Errors.";
                Logger.LogString("No profile data found. Please check your paths or start the game once.");
                return(false);
            }
            else
            {
                //get data from profiles
                try
                {
                    var profileDirList = Directory.GetDirectories(profileDir).ToList();
                    foreach (var dir in profileDirList)
                    {
                        var profile           = Directory.GetFiles(dir).FirstOrDefault(x => Path.GetFileName(x).Equals("profile.lsb"));
                        DOS2_PlayerProfile pp = lt.GetProfile(profile);
                        if (pp == null || String.IsNullOrEmpty(pp.PlayerProfileID))
                        {
                            continue;
                        }

                        //Get profile Info for Mods
                        var settings = new Dos2ModsSettings()
                        {
                            Name     = Path.GetFileNameWithoutExtension(dir),
                            UUID     = pp.PlayerProfileID,
                            IsActive = (pp.PlayerProfileID == playerProfile.ActiveProfile)
                        };

                        //read modsettings file
                        var modsettings = Directory.GetFiles(dir).FirstOrDefault(x => Path.GetFileName(x).Equals("modsettings.lsx"));

                        using (XmlReader xmlReader = XmlReader.Create(modsettings))
                        {
                            XDocument xml = XDocument.Load(xmlReader);
                            LsxTools  lt  = new LsxTools();

                            //Mod Order
                            XElement modOrder = xml.Descendants("node").FirstOrDefault(x => x.Attribute("id").Value == "ModOrder");
                            if (modOrder.HasElements)
                            {
                                var children = modOrder.Elements().First().Elements().ToList();
                                foreach (var module in children)
                                {
                                    var    atts  = module.Elements().ToList();
                                    string modID = lt.GetAttributeByName(atts, "UUID");
                                    settings.ModLoadOrder.Add(modID);
                                }
                            }

                            //Active Mods
                            var activeMods = xml.Descendants("node").Where(x => x.Attribute("id").Value == "ModuleShortDesc").ToList();
                            if (activeMods.Any())
                            {
                                foreach (var item in activeMods)
                                {
                                    var    atts  = item.Elements().ToList();
                                    string modID = lt.GetAttributeByName(atts, "UUID");
                                    settings.ActiveMods.Add(modID);
                                }
                            }
                        }
                        Profiles.Add(settings);
                    }

                    //FIXME should be redundant, but isn't in the case of refresh...
                    ActiveProfile = Profiles.FirstOrDefault(x => x.IsActive);

                    Logger.Status = "Finished.";
                    Logger.LogString("Finished loading profile data.");
                    return(true);
                }
                catch (Exception e)
                {
                    MessageBoxResult result = MessageBox.Show(
                        "Something went wrong when trying to load profile data. Please check your paths or start the game once.",
                        "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    Logger.Status = "Finished With Errors.";
                    Logger.LogString("Something went wrong when trying to load profile data. Please check your paths or start the game once.");
                    Logger.LogString(e.ToString());
                    return(false);
                }
            }
        }