Пример #1
0
        /// <summary>
        /// reads the lsx (xml)
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        private Dos2Mod InterpretModMeta(string file)
        {
            Dos2Mod modData = new Dos2Mod();

            try
            {
                using (XmlReader xmlReader = XmlReader.Create(file))
                {
                    XDocument xml = XDocument.Load(xmlReader);
                    LsxTools  ls  = ParentViewModel.lt;

                    //Mod Info
                    XElement        moduleInfo = xml.Descendants("node").FirstOrDefault(x => x.Attribute("id").Value == "ModuleInfo");
                    List <XElement> els        = moduleInfo.Elements().ToList();

                    modData.Name        = ls.GetAttributeByName(els, "Name");
                    modData.UUID        = ls.GetAttributeByName(els, "UUID");
                    modData.Author      = ls.GetAttributeByName(els, "Author");
                    modData.Description = ls.GetAttributeByName(els, "Description");
                    modData.Folder      = ls.GetAttributeByName(els, "Folder");
                    modData.Tags        = ls.GetAttributeByName(els, "Tags");
                    modData.MD5         = ls.GetAttributeByName(els, "MD5");
                    modData.Type        = ls.GetAttributeByName(els, "Type");
                    modData.Version     = ls.GetAttributeByName(els, "Version");

                    //Target Modes
                    XElement targetModes = xml.Descendants("node").FirstOrDefault(x => x.Attribute("id").Value == "TargetModes");
                    var      modes       = targetModes.Elements().First().Elements().ToList();
                    foreach (var item in modes)
                    {
                        var    atts   = item.Elements().ToList();
                        string target = ls.GetAttributeByName(atts, "Object");
                        modData.TargetModes.Add(target);
                    }

                    //Dependencies
                    XElement dependencies = xml.Descendants("node").FirstOrDefault(x => x.Attribute("id").Value == "Dependencies");
                    if (dependencies.HasElements)
                    {
                        var deps = dependencies.Elements().First().Elements().ToList();
                        foreach (var item in deps)
                        {
                            var    atts = item.Elements().ToList();
                            string uuid = ls.GetAttributeByName(atts, "UUID");
                            modData.Dependencies.Add(uuid);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                throw;
            }
            return(modData);
        }
Пример #2
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);
                }
            }
        }
Пример #3
0
        public MainViewModel(IKernel kernel)
        {
            Kernel = kernel;

            #region ViewModels
            Utilities = kernel.Get <UtilitiesViewModel>();

            #endregion

            #region Relay Commands
            ExitCommand    = new RelayCommand(Exit);
            SaveCommand    = new RelayCommand(Save, CanSave);
            RefreshCommand = new RelayCommand(Refresh, CanRefresh);
            RunGameCommand = new RelayCommand(RunGame, CanRunGame);

            LocateDocumentsCommand = new RelayCommand(LocateDocuments, CanLocateDocuments);
            LocateGameCommand      = new RelayCommand(LocateGame, CanLocateGame);
            #endregion

            ModsList = Properties.Settings.Default.ModList;
            Logger   = new DMMLogger();
            Profiles = new ObservableCollection <Dos2ModsSettings>();
            lt       = new LsxTools();
            pt       = new PakTools(this);

            // Get Profile Info


            // FIXME check for changes
            bool initProfiles = GetProfileInfo();
            //check if any profiles were loaded
            // FIXME get all profiles and check if they were loaded
            // FIXME handle the case where profiles are messed up better
            if (initProfiles)
            {
                // Layout
                // mod list is generated in WorkspaceViewModel
                AnchorablesSource = new ObservableCollection <DockableViewModel>()
                {
                    new WorkspaceViewModel(this)
                    {
                        Title     = "Mods",
                        ContentId = "mods",
                    },
                    new LogViewModel()
                    {
                        Title           = "Log",
                        ContentId       = "log",
                        ParentViewModel = this,
                    },
                    new PropertiesViewModel()
                    {
                        Title           = "Properties",
                        ContentId       = "properties",
                        ParentViewModel = this,
                    },
                    new ConflictsViewModel(this)
                    {
                        Title     = "Conflicts List",
                        ContentId = "conflicts",
                    },
                };
            }
        }