/// <summary>
        /// Builds a preference entry for the provided parent based on the provided XElement node
        /// </summary>
        /// <param name="parent">The parent.</param>
        /// <param name="foundEntry">The found entry.</param>
        /// <returns></returns>
        private IPreferenceEntry BuildPreferenceEntry(IPreference parent, XElement foundEntry)
        {
            var name                = XElementHelper.ReadStringValue(foundEntry, "name");
            var friendlyName        = XElementHelper.ReadStringValue(foundEntry, "friendlyName");
            var description         = XElementHelper.ReadStringValue(foundEntry, "description", false);
            var isSelectedByDefault = XElementHelper.ReadBoolValue(foundEntry, "isDefault", false);

            if (isSelectedByDefault && parent.HasDirectlyEditableValue)
            {
                /*
                 * This preference has both a list of pre-defined entries - one of which are selected by default -
                 * and a default value specified in the config file. There is really no obvious way to know which
                 * the user actually wanted to be the default value, so log this as a warning, and let the
                 * pre-defined option override the directly specified default value.
                 */

                parent.Value = name;
            }

            var entry = new PreferenceEntry(name, friendlyName, description, parent)
            {
                IsSelected = isSelectedByDefault
            };

            return(entry);
        }
        private ModFile ReadModFolder()
        {
            ModFile modFolder = new ModFile();;

            var configFileName = "Configuration.xml";
            var config         = XmlHelper.ReadXmlFile(configFileName);

            if (config == null)
            {
                // Throw new invalid xml exception?
                return(null);
            }

            try
            {
                var foundModFolder = config.Descendants("folderName").First();

                modFolder.FileName   = XElementHelper.ReadStringValue(foundModFolder, "fileName");
                modFolder.SourcePath = XElementHelper.ReadStringValue(foundModFolder, "sourcePath");
                modFolder.TargetPath = XElementHelper.ReadStringValue(foundModFolder, "targetPath");
            }
            catch
            {
            }

            return(modFolder);
        }
        private IList <ModFile> ReadConfigurationFiles()
        {
            var files          = new List <ModFile>();
            var configFileName = "Configuration.xml";

            var config = XmlHelper.ReadXmlFile(configFileName);

            if (config == null)
            {
                // Throw new invalid xml exception?
                return(null);
            }

            try
            {
                var foundFiles = config.Descendants("converterModFile");

                foreach (var file in foundFiles)
                {
                    var fileName   = XElementHelper.ReadStringValue(file, "fileName");
                    var sourcePath = XElementHelper.ReadStringValue(file, "sourcePath");
                    var targetPath = XElementHelper.ReadStringValue(file, "targetPath");

                    files.Add(new ModFile()
                    {
                        FileName = fileName, SourcePath = sourcePath, TargetPath = targetPath
                    });
                }
            }
            catch
            {
            }

            return(files);
        }
Ejemplo n.º 4
0
        /// <summary>
        ///     Builds a preference entry for the provided parent based on the provided XElement node
        /// </summary>
        /// <param name="parent">The parent.</param>
        /// <param name="foundEntry">The found entry.</param>
        /// <returns></returns>
        private TPreferenceEntry BuildPreferenceEntry <TPreferenceEntry>(IPreference parent, XElement foundEntry)
            where TPreferenceEntry : class, IPreferenceEntry
        {
            // Rather ugly way of reading shared properties + returning the newly created entry
            // Several unplesant compromises here
            Func <IPreferenceEntry, TPreferenceEntry> readSharedProperties = entry =>
            {
                entry.FriendlyName = XElementHelper.ReadStringValue(foundEntry, "friendlyName");
                entry.Description  = XElementHelper.ReadStringValue(foundEntry, "description", false);
                entry.IsSelected   = XElementHelper.ReadBoolValue(foundEntry, "isDefault", false);

                //if (isSelectedByDefault && parent.HasDirectlyEditableValue)
                //{
                //    /*
                //     * This preference has both a list of pre-defined entries - one of which are selected by default -
                //     * and a default value specified in the config file. There is really no obvious way to know which
                //     * the user actually wanted to be the default value, so log this as a warning, and let the
                //     * pre-defined option override the directly specified default value.
                //     */

                //    parent.Value = name;
                //}

                return(entry as TPreferenceEntry);
            };

            if (parent is INumericPreference)
            {
                var entry = new NumericPreferenceEntry
                {
                    Parent = (INumericPreference)parent,
                    Name   = XElementHelper.ReadDoubleValue(foundEntry, "name")
                };

                return(readSharedProperties(entry));
            }
            if (parent is IDatePreference)
            {
                var dateFormat = ((IDatePreference)parent).DateFormat;

                var entry = new DatePreferenceEntry
                {
                    Parent = (IDatePreference)parent,
                    Name   = XElementHelper.ReadDateValue(foundEntry, "name", dateFormat)
                };

                return(readSharedProperties(entry));
            }
            if (parent is IStringPreference)
            {
                var entry = new StringPreferenceEntry
                {
                    Parent = (IStringPreference)parent,
                    Name   = XElementHelper.ReadStringValue(foundEntry, "name")
                };

                return(readSharedProperties(entry));
            }
            throw new NotSupportedException("Invalid parent object");
        }
Ejemplo n.º 5
0
        protected override T OnBuildElement <T>(XElement element)
        {
            var name                  = XElementHelper.ReadStringValue(element, "name");
            var friendlyName          = XElementHelper.ReadStringValue(element, "friendlyName");
            var currentModTagName     = XElementHelper.ReadStringValue(element, "currentModTagName", false);
            var supportedModsAsString = element.Descendants("supportedMod");

            var gameConfig = new GameConfiguration
            {
                Name              = name,
                FriendlyName      = friendlyName,
                CurrentModTagName = currentModTagName
            };

            // Dummy item so that the user can undo selecting a mod
            var dummyMod = new Mod {
                Name = "No mod", IsDummyItem = true
            };

            gameConfig.SupportedMods.Add(dummyMod);
            gameConfig.CurrentMod = dummyMod;

            // Add proper mods
            if (supportedModsAsString.Count() > 0)
            {
                supportedModsAsString.ForEach(
                    m => gameConfig.SupportedMods.Add(new Mod {
                    Name = XElementHelper.ReadStringValue(m, "modName")
                }));
            }

            return(gameConfig as T);
        }
Ejemplo n.º 6
0
        public static bool HasXProjectXElement(this VisualStudioProjectFileXDocument visualStudioProjectFileXDocument, out XElement xProjectXElement)
        {
            xProjectXElement = visualStudioProjectFileXDocument.Value.Element(ProjectFileXmlElementName.Project);

            var hasXProjectXElement = XElementHelper.WasFound(xProjectXElement);

            return(hasXProjectXElement);
        }
        public static bool HasItemGroupElementWithChildFirstOrDefault(this ProjectXElement projectXElement, string childName, out XElement itemGroupElement)
        {
            itemGroupElement = projectXElement.GetItemGroupElementWithChildFirstOrDefault(childName);

            var hasPropertyGroupElementWithChildFirstOrDefault = XElementHelper.WasFound(itemGroupElement);

            return(hasPropertyGroupElementWithChildFirstOrDefault);
        }
        public static bool HasPropertyGroupElementWithChildSingleOrDefault(this ProjectXElement projectXElement, string childName, out XElement propertyGroupElement)
        {
            propertyGroupElement = projectXElement.GetPropertyGroupElementWithChildSingleOrDefault(childName);

            var hasPropertyGroupElementWithChildSingleOrDefault = XElementHelper.WasFound(propertyGroupElement);

            return(hasPropertyGroupElementWithChildSingleOrDefault);
        }
Ejemplo n.º 9
0
        private IAlternativePath ReadWindowsUserFolderPath(XElement xmlElement, string tagName, string friendlyName)
        {
            var subFolderLocation = XElementHelper.ReadStringValue(xmlElement, "subFolderLocation");
            var userFolder        = environmentProxy.GetUsersFolder();
            var absolutePath      = Path.Combine(userFolder, subFolderLocation);

            return(BuildAlternativePathObject(absolutePath, tagName, friendlyName));
        }
Ejemplo n.º 10
0
        private IAlternativePath ReadSteamPath(XElement xmlElement, string steamId, string tagName, string friendlyName)
        {
            var installationPath  = ReadSteamFolder(steamId);
            var subFolderLocation = XElementHelper.ReadStringValue(xmlElement, "subFolderLocation", false);
            var absolutePath      = Path.Combine(installationPath, subFolderLocation);

            return(BuildAlternativePathObject(absolutePath, tagName, friendlyName));
        }
        /// <summary>
        ///     Builds a preference entry for the provided parent based on the provided XElement node
        /// </summary>
        /// <param name="parent">The parent.</param>
        /// <param name="foundEntry">The found entry.</param>
        /// <returns></returns>
        private TPreferenceEntry BuildPreferenceEntry <TPreferenceEntry>(IPreference parent, XElement foundEntry)
            where TPreferenceEntry : class, IPreferenceEntry
        {
            // Rather ugly way of reading shared properties + returning the newly created entry
            // Several unplesant compromises here
            Func <IPreferenceEntry, TPreferenceEntry> readSharedProperties = entry =>
            {
                entry.FriendlyName = XElementHelper.ReadStringValue(foundEntry, "friendlyName");
                entry.Description  = XElementHelper.ReadStringValue(foundEntry, "description", false);
                entry.IsSelected   = XElementHelper.ReadBoolValue(foundEntry, "isDefault", false);

                return(entry as TPreferenceEntry);
            };

            if (parent is INumericPreference)
            {
                var entry = new NumericPreferenceEntry
                {
                    Parent = (INumericPreference)parent,
                    Name   = XElementHelper.ReadDoubleValue(foundEntry, "name")
                };

                return(readSharedProperties(entry));
            }
            if (parent is IDatePreference)
            {
                var dateFormat = ((IDatePreference)parent).DateFormat;

                var entry = new DatePreferenceEntry
                {
                    Parent = (IDatePreference)parent,
                    Name   = XElementHelper.ReadDateValue(foundEntry, "name", dateFormat)
                };

                return(readSharedProperties(entry));
            }
            if (parent is IStringListPreference)
            {
                var entry = new StringListPreferenceEntry
                {
                    Parent = (IStringListPreference)parent,
                    Name   = XElementHelper.ReadStringValue(foundEntry, "name")
                };

                return(readSharedProperties(entry));
            }
            if (parent is IStringPreference)
            {
                var entry = new StringPreferenceEntry
                {
                    Parent = (IStringPreference)parent,
                    Name   = XElementHelper.ReadStringValue(foundEntry, "name")
                };

                return(readSharedProperties(entry));
            }
            throw new NotSupportedException("Invalid parent object");
        }
        public static bool HasPropertyElement(this ProjectXElement projectXElement, string propertyElementName, out XElement xPropertyElement)
        {
            xPropertyElement = projectXElement.GetPropertyGroupElementWithChildSingleOrDefault(propertyElementName)
                               ?.GetChild(propertyElementName); // If default, then not found, else child must exist since the property group element with child WAS found.

            var hasPropertyElement = XElementHelper.WasFound(xPropertyElement);

            return(hasPropertyElement);
        }
Ejemplo n.º 13
0
        private IAlternativePath ReadConverterPath(XElement xmlElement, string tagName, string friendlyName, string predefinedFileName)
        {
            var subFolderLocation = XElementHelper.ReadStringValue(xmlElement, "subFolderLocation");

            // If a predefined file name is set, include it in the absolute path (and hence the alternativepath.exists check)
            var absolutePath = string.IsNullOrEmpty(predefinedFileName) ?
                               Path.Combine(environmentProxy.GetFrontendWorkingDirectory(), subFolderLocation) :
                               Path.Combine(environmentProxy.GetFrontendWorkingDirectory(), subFolderLocation, predefinedFileName);

            return(BuildAlternativePathObject(absolutePath, tagName, friendlyName));
        }
Ejemplo n.º 14
0
        /// <summary>
        ///     Builds the ConverterSettings object given by the xml element (XElement)
        /// </summary>
        /// <typeparam name="T">The type of object to create. In this case, it'll be ConverterSettings</typeparam>
        /// <param name="element">The xml node to generate the ConverterSettings object from</param>
        /// <returns>The generated convertersettings object</returns>
        protected override T OnBuildElement <T>(XElement element)
        {
            var name                     = XElementHelper.ReadStringValue(element, "name");
            var friendlyName             = XElementHelper.ReadStringValue(element, "friendlyName");
            var defaultConfigurationFile = XElementHelper.ReadStringValue(element, "defaultConfigurationFile");
            var additionalInformation    = XElementHelper.ReadStringValue(element, "informationText", false);

            // Build game configuration models
            var sourceGameName = XElementHelper.ReadStringValue(element, "sourceGame");
            var targetGameName = XElementHelper.ReadStringValue(element, "targetGame");
            var sourceGame     = GameConfigurations.FirstOrDefault(g => g.Name.Equals(sourceGameName));
            var targetGame     = GameConfigurations.FirstOrDefault(g => g.Name.Equals(targetGameName));

            var requiredFolders = RequiredFolderFactory.BuildConfiguration <IRequiredFolder>(element);
            var requiredFiles   = RequiredFileFactory.BuildConfiguration <IRequiredFile>(element);

            var errorMessage = "Could not find game configuration for {0}. Could not find game in " +
                               AbsoluteGameConfigurationPath + " with name {1}. ";

            // Build preference categories
            var categories = PreferenceCategoryFactory.BuildModels <IPreferenceCategory>(defaultConfigurationFile);

            if (sourceGame == null)
            {
                EventAggregator.PublishOnUIThread(
                    new LogEntry(string.Format(errorMessage, "source game", sourceGameName), LogEntrySeverity.Error,
                                 LogEntrySource.UI, AbsoluteGameConfigurationPath));
            }

            if (targetGame == null)
            {
                EventAggregator.PublishOnUIThread(
                    new LogEntry(string.Format(errorMessage, "target game", targetGameName), LogEntrySeverity.Error,
                                 LogEntrySource.UI, AbsoluteGameConfigurationPath));
            }

            var settings = new ConverterSettings(EventAggregator)
            {
                Name                     = name,
                FriendlyName             = friendlyName,
                DefaultConfigurationFile = Path.Combine(Environment.CurrentDirectory, defaultConfigurationFile),
                SourceGame               = sourceGame,
                TargetGame               = targetGame,
                Categories               = categories,
                AdditionalInformation    = additionalInformation
            };

            requiredFolders.ForEach(f => settings.RequiredItems.Add(f));
            requiredFiles.ForEach(f => settings.RequiredItems.Add(f));

            return(settings as T);
        }
Ejemplo n.º 15
0
        public IRequiredFolder ReadFolder(XElement xmlElement)
        {
            var directoryTagName = XElementHelper.ReadStringValue(xmlElement, "tag", false);
            var internalTagName  = XElementHelper.ReadStringValue(xmlElement, "internalTag", false);
            var friendlyName     = XElementHelper.ReadStringValue(xmlElement, "friendlyName");
            var description      = XElementHelper.ReadStringValue(xmlElement, "description");
            var isMandatory      = XElementHelper.ReadBoolValue(xmlElement, "isMandatory", false);
            var hidden           = XElementHelper.ReadBoolValue(xmlElement, "hidden", false);
            var alternativePaths = ReadDefaultLocationPaths(xmlElement, directoryTagName, friendlyName);

            return(BuildRequiredFolderObject(directoryTagName, alternativePaths, friendlyName, description,
                                             internalTagName, isMandatory, hidden));
        }
        public static bool RemoveProjectReference(this ProjectReferencesItemGroupXElement projectReferencesItemGroupXElement, IProjectReference projectReference)
        {
            var xProjectReference = projectReferencesItemGroupXElement.GetProjectReferenceXElementsWhereProjectFilePath(projectReference.ProjectFilePath)
                                    .SingleOrDefault();

            var wasFound = XElementHelper.WasFound(xProjectReference);

            if (wasFound)
            {
                xProjectReference.Remove();
            }

            return(wasFound);
        }
        public static bool RemovePackageReference(this PackageReferencesItemGroupXElement packageReferencesItemGroupXElement, IPackageReference packageReference)
        {
            var xPackageReference = packageReferencesItemGroupXElement.GetPackageReferenceXElementsWhereName(packageReference.Name)
                                    .SingleOrDefault();

            var wasFound = XElementHelper.WasFound(xPackageReference);

            if (wasFound)
            {
                xPackageReference.Remove();
            }

            return(wasFound);
        }
Ejemplo n.º 18
0
        protected IList <IAlternativePath> ReadDefaultLocationPaths(XElement xmlElement, string tagName,
                                                                    string friendlyName, string predefinedFileName = null)
        {
            var alternatives = new List <IAlternativePath>();

            var alternativeTags = XElementHelper.ReadEnumerable(xmlElement, "alternative");

            foreach (var tag in alternativeTags)
            {
                var defaultLocationTypeAsString = XElementHelper.ReadStringValue(tag, "defaultLocationType");

                if (defaultLocationTypeAsString.Equals(RelativeFolderLocationRoot.Folder.ToString()))
                {
                    string location = XElementHelper.ReadStringValue(xmlElement, "location");
                    alternatives.Add(BuildAlternativePathObject(location));
                }
                else if (defaultLocationTypeAsString.Equals(RelativeFolderLocationRoot.ConverterFolder.ToString()))
                {
                    alternatives.Add(ReadConverterPath(tag, predefinedFileName));
                }
                else if (defaultLocationTypeAsString.Equals(RelativeFolderLocationRoot.WindowsUsersFolder.ToString()))
                {
                    alternatives.Add(ReadWindowsUserFolderPath(tag));
                }
                else if (defaultLocationTypeAsString.Equals(RelativeFolderLocationRoot.SteamFolder.ToString()))
                {
                    // If we can find the folder using steam id, do that
                    var steamId = XElementHelper.ReadStringValue(tag, "autoDetectFromSteamId", false);
                    alternatives.Add(ReadSteamPath(tag, steamId));
                }
                else
                {
                    EventAggregator.PublishOnUIThread(
                        new LogEntry(
                            "Invalid DefaultLocationType. This is either a problem for the developer, or you messed up the .XML file somehow. ",
                            LogEntrySeverity.Error,
                            LogEntrySource.UI));
                }
            }

            // Hack: need some way to make alternative paths aware that their required file/folder is hidden/not mandatory, in which case
            // this check/logging isn't needed
            if (alternatives.All(a => !a.Exists) && !tagName.Equals("faq"))
            {
                alternatives.ForEach(a => this.LogExistenceError(a, friendlyName));
            }

            return(alternatives);
        }
        private void PrettifyChildren(XElement xElement, int level)
        {
            var nodeIsLeaf = XElementHelper.IsLeaf(xElement);

            if (nodeIsLeaf)
            {
                return;
            }

            var newLine = this.GetNewLine();

            var indentBeforeElement = this.GetIndentForLevel(level);
            var beforeElementText   = $"{newLine}{indentBeforeElement}";

            var childXElements = xElement.Elements().ToList();

            foreach (var childXElement in childXElements)
            {
                var priorNode = childXElement.PreviousNode;
                if (!priorNode.IsText())
                {
                    // Add a blank-line XText element just before the element.
                    var xText = new XText(beforeElementText);
                    childXElement.AddBeforeSelf(xText);
                }
            }

            var indentAfterElement = this.GetIndentForLevel(level - 1);
            var afterElementText   = $"{newLine}{indentAfterElement}";

            var lastNode = xElement.LastNode;

            if (!lastNode.IsText())
            {
                // Add a blank line after the last node.
                var xText = new XText(afterElementText);
                lastNode.AddAfterSelf(xText);
            }

            // Now format each child element, recursively.
            foreach (var childXElement in childXElements)
            {
                this.PrettifyChildren(childXElement, level + 1);
            }
        }
Ejemplo n.º 20
0
        /// <summary>
        ///     Essentially a filter method, this method excludes any disabled element in the xml configuration file
        /// </summary>
        /// <remarks>
        ///     For now, this only looks for the isEnabled=false tag. With time, a proper filter may be implemented.
        ///     Todo:
        ///     Simplify
        ///     Rename to something descriptive?
        /// </remarks>
        /// <typeparam name="T">The type of element</typeparam>
        /// <param name="config">The configuration file</param>
        /// <returns>The model objects</returns>
        public ObservableCollection <T> BuildConfiguration <T>(XDocument config) where T : class
        {
            var elements = new ObservableCollection <T>();

            var foundElements = config.Descendants(xmlElementIdentifier);

            foreach (var element in foundElements) //.Where(e => this.filter(e)))
            {
                var isEnabled = XElementHelper.ReadBoolValue(element, "isEnabled", false, true);

                if (isEnabled)
                {
                    elements.Add(OnBuildElement <T>(element));
                }
            }

            return(elements);
        }
Ejemplo n.º 21
0
        public IRequiredFolder ReadFolder(XElement xmlElement)
        {
            var directoryTagName = XElementHelper.ReadStringValue(xmlElement, "tag", false);
            var internalTagName  = XElementHelper.ReadStringValue(xmlElement, "internalTag", false);

            // TODO: Sanity check
            //if (directoryTagName == null && internalTagName == null)
            //{
            //    this.EventAggregator.PublishOnUIThread(new LogEntry("Invalid XML - no tag or internal tag found for item "))
            //}

            var friendlyName     = XElementHelper.ReadStringValue(xmlElement, "friendlyName");
            var description      = XElementHelper.ReadStringValue(xmlElement, "description");
            var isMandatory      = XElementHelper.ReadBoolValue(xmlElement, "isMandatory", false);
            var hidden           = XElementHelper.ReadBoolValue(xmlElement, "hidden", false);
            var alternativePaths = ReadDefaultLocationPaths(xmlElement, directoryTagName, friendlyName);

            //var installationPath = string.IsNullOrEmpty(steamId) ? this.ReadWindowsUserFolderPath(xmlElement) : this.ReadSteamPath(xmlElement, steamId);
            //var installationPath = this.ReadDefaultLocationPaths(xmlElement);

            return(BuildRequiredFolderObject(directoryTagName, alternativePaths, friendlyName, description,
                                             internalTagName, isMandatory, hidden));
        }
Ejemplo n.º 22
0
        ///// <summary>
        ///// The required folder factory self-resolving property
        ///// </summary>
        //protected RequiredFolderFactory RequiredFolderFactory
        //{
        //    get
        //    {
        //        return this.requiredFolderFactory ?? (this.requiredFolderFactory = new RequiredFolderFactory(this.EventAggregator));
        //    }
        //}

        ///// <summary>
        ///// The required file factory self-resolving property
        ///// </summary>
        //protected RequiredFileFactory RequiredFileFactory
        //{
        //    get
        //    {
        //        return this.requiredFileFactory ?? (this.requiredFileFactory = new RequiredFileFactory(this.EventAggregator));
        //    }
        //}

        //protected override void OnConfigLoaded(XDocument config)
        //{
        //    base.OnConfigLoaded(config);
        //    this.config = config;
        //}

        protected override T OnBuildElement <T>(XElement element)
        {
            var name         = XElementHelper.ReadStringValue(element, "name");
            var friendlyName = XElementHelper.ReadStringValue(element, "friendlyName");
            //var steamId = XElementHelper.ReadStringValue(element, "steamId");

            //var requiredFolders = this.RequiredFolderFactory.BuildConfiguration<IRequiredFolder>(this.config);
            //var requiredFiles = this.RequiredFileFactory.BuildConfiguration<IRequiredFile>(this.config);

            //var requiredFilesAndFolders = requiredFiles.Union(requiredFolders);

            // Installation directory related
            //var installationFolder = SteamHelper.GetSteamInstallationFolder(this.EventAggregator, steamId);
            //var installationDirectoryTagName = XElementHelper.ReadStringValue(element, "installationDirectoryTagName");
            //var iconFile = XElementHelper.ReadStringValue(element, "iconFile", false);

            // Save game related
            //var saveGameFolderTypeAsString = XElementHelper.ReadStringValue(element, "defaultSaveGameLocationType");
            //var saveGameFolderType = saveGameFolderTypeAsString.Equals(RelativeFolderLocationRoot.SteamFolder.ToString()) ? RelativeFolderLocationRoot.SteamFolder : RelativeFolderLocationRoot.WindowsUsersFolder;
            //var saveGameExtension = XElementHelper.ReadStringValue(element, "saveGameExtension");
            //var saveGameLocation = (saveGameFolderType == RelativeFolderLocationRoot.SteamFolder ? installationFolder : DirectoryHelper.GetUsersFolder()) + XElementHelper.ReadStringValue(element, "defaultSaveGameSubLocation");

            // Mod related
            //var defaultModFolderLocationTypeAsString = XElementHelper.ReadStringValue(element, "defaultModFolderLocationType", false);
            //var defaultModFolderLocationType = defaultModFolderLocationTypeAsString.Equals(RelativeFolderLocationRoot.SteamFolder.ToString()) ? RelativeFolderLocationRoot.SteamFolder : RelativeFolderLocationRoot.WindowsUsersFolder;
            //var modDirectoryTagName = XElementHelper.ReadStringValue(element, "modDirectoryTagName", false);
            var currentModTagName = XElementHelper.ReadStringValue(element, "currentModTagName", false);
            //var absoluteModPath = (defaultModFolderLocationType == RelativeFolderLocationRoot.SteamFolder ? installationFolder : DirectoryHelper.GetUsersFolder()) + XElementHelper.ReadStringValue(element, "defaultModFolderLocation", false);
            var supportedModsAsString = element.Descendants("supportedMod");

            // Temp directory
            //var tempDirectoryLocationTypeAsString = XElementHelper.ReadStringValue(element, "defaultTempDirectoryLocationType", false);
            //var tempDirectoryLocationType = tempDirectoryLocationTypeAsString.Equals(RelativeFolderLocationRoot.SteamFolder.ToString()) ? RelativeFolderLocationRoot.SteamFolder : RelativeFolderLocationRoot.WindowsUsersFolder;
            //var tempDirectoryAbsolutePath = (tempDirectoryLocationType == RelativeFolderLocationRoot.SteamFolder ? installationFolder : DirectoryHelper.GetUsersFolder()) + XElementHelper.ReadStringValue(element, "defaultTempFolderLocation", false);
            //var tempDirectoryTagName = XElementHelper.ReadStringValue(element, "tempDirectoryTagName", false);

            var gameConfig = new GameConfiguration
            {
                Name         = name,
                FriendlyName = friendlyName,
                //SteamId = steamId,
                //SaveGameExtension = saveGameExtension,
                //AbsoluteInstallationPath = installationFolder,
                //InstallationDirectoryTagName = installationDirectoryTagName,
                //ModDirectoryTagName = modDirectoryTagName,
                //AbsoluteSaveGamePath = saveGameLocation,
                CurrentModTagName = currentModTagName
                                    //AbsoluteModPath = absoluteModPath/*,
                                    //AbsoluteTempDirectoryPath = tempDirectoryAbsolutePath,
                                    //TempDirectoryTagName = tempDirectoryTagName
            };

            // Dummy item so that the user can undo selecting a mod
            var dummyMod = new Mod {
                Name = "No mod", IsDummyItem = true
            };

            gameConfig.SupportedMods.Add(dummyMod);
            gameConfig.CurrentMod = dummyMod;

            // Add proper mods
            if (supportedModsAsString.Count() > 0)
            {
                supportedModsAsString.ForEach(
                    m => gameConfig.SupportedMods.Add(new Mod {
                    Name = XElementHelper.ReadStringValue(m, "modName")
                }));
            }

            return(gameConfig as T);
        }
        /// <summary>
        /// Reads the category configuration.
        /// </summary>
        /// <returns></returns>
        private IList <PreferenceCategory> ReadCategoryConfig()
        {
            var categories     = new List <PreferenceCategory>();
            var configFileName = "Configuration.xml";

            var config = XmlHelper.ReadXmlFile(configFileName);

            if (config == null)
            {
                return(null);
            }

            try
            {
                // Read the list of categories from the xml
                var foundCategories = config.Descendants("category");

                // For each category, store the values in a new PreferenceCategory object.
                foreach (var foundCategory in foundCategories)
                {
                    var category = new PreferenceCategory();
                    category.FriendlyName = XElementHelper.ReadStringValue(foundCategory, "friendlyName");
                    categories.Add(category);

                    // Read the list of Preference tags
                    var foundPreferences = XElementHelper.ReadEnumerable(foundCategory, "preference");

                    // For each preference Tag, store the values into a new Preference object
                    foreach (var foundPreference in foundPreferences)
                    {
                        IPreference preference = new Preference();

                        preference.Name                     = XElementHelper.ReadStringValue(foundPreference, "name");
                        preference.FriendlyName             = XElementHelper.ReadStringValue(foundPreference, "friendlyName");
                        preference.Description              = XElementHelper.ReadStringValue(foundPreference, "description", false);
                        preference.MinValue                 = XElementHelper.ReadDoubleValue(foundPreference, "minValue", false);
                        preference.MaxValue                 = XElementHelper.ReadDoubleValue(foundPreference, "maxValue", false);
                        preference.Value                    = XElementHelper.ReadStringValue(foundPreference, "value", false);
                        preference.HasDirectlyEditableValue = XElementHelper.ReadBoolValue(foundPreference, "hasDirectlyEditableValue", false);

                        category.Preferences.Add(preference);

                        // Read the list of entryOption tags
                        var foundEntries = XElementHelper.ReadEnumerable(foundPreference, "entryOption", false);

                        // For each tag, read the values into a new PreferenceEntry object
                        foreach (var entry in foundEntries)
                        {
                            preference.Entries.Add(this.BuildPreferenceEntry(preference, entry));
                        }
                    }
                }
            }
            ////catch (MissingRequiredXMLPropertyException ex)
            ////{
            ////}
            ////catch (MalformedXMLException ex)
            ////{
            ////}
            ////catch (UnParsableDataValueException ex)
            ////{
            ////}
            catch (XMLParseExceptionBase ex)
            {
                this.ShowMalformedOrMissingXMLElementError(configFileName, ex);
            }
            catch (Exception ex)
            {
                this.options.Logger.AddLogEntry(new LogEntry(ex.Message + " - " + ex.InnerException, LogEntrySeverity.Error, LogEntrySource.UI));
            }

            return(categories);
        }
        protected override T OnBuildElement <T>(XElement element)
        {
            var category = new PreferenceCategory();

            category.FriendlyName = XElementHelper.ReadStringValue(element, "friendlyName");

            // Read the list of Preference tags
            var foundPreferences = XElementHelper.ReadEnumerable(element, "preference");

            // For each preference Tag, store the values into a new Preference object
            foreach (var foundPreference in foundPreferences)
            {
                // Ugly way of reading shared properties without duplicating code.
                Action <IPreference> readSharedProperties = preference =>
                {
                    preference.Name         = XElementHelper.ReadStringValue(foundPreference, "name");
                    preference.FriendlyName = XElementHelper.ReadStringValue(foundPreference, "friendlyName");
                    preference.Description  = XElementHelper.ReadStringValue(foundPreference, "description", false);

                    preference.HasDirectlyEditableValue = XElementHelper.ReadBoolValue(foundPreference,
                                                                                       "hasDirectlyEditableValue", false);

                    preference.useCurlyBraces = XElementHelper.ReadBoolValue(foundPreference,
                                                                             "useCurlyBraces", false);

                    preference.AllowMultipleSelections = XElementHelper.ReadBoolValue(foundPreference, "allowMultipleSelections", false);

                    category.Preferences.Add(preference);
                };

                // Determine preference type
                var isDate    = XElementHelper.ReadBoolValue(foundPreference, "isDate", false);
                var isNumeric = XElementHelper.ReadBoolValue(foundPreference, "isNumeric", false);
                var allowsMultipleSelections = XElementHelper.ReadBoolValue(foundPreference, "allowMultipleSelections", false);

                if (isDate)
                {
                    var preference = new DatePreference();

                    preference.DateFormat = XElementHelper.ReadStringValue(foundPreference, "dateFormat");
                    preference.MinValue   = XElementHelper.ReadDateValue(foundPreference, "minDateValue",
                                                                         preference.DateFormat, false);
                    preference.MaxValue = XElementHelper.ReadDateValue(foundPreference, "maxDateValue",
                                                                       preference.DateFormat, false);
                    preference.Value = XElementHelper.ReadDateValue(foundPreference, "value", preference.DateFormat,
                                                                    true);

                    // Read the list of entryOption tags
                    var foundEntries = XElementHelper.ReadEnumerable(foundPreference, "entryOption", false);

                    // For each tag, read the values into a new PreferenceEntry object
                    foreach (var entry in foundEntries)
                    {
                        preference.Entries.Add(BuildPreferenceEntry <IDatePreferenceEntry>(preference, entry));
                    }

                    readSharedProperties(preference);
                }
                else if (isNumeric)
                {
                    var preference = new NumericPreference();

                    preference.MinValue = XElementHelper.ReadDoubleValue(foundPreference, "minValue", false);
                    preference.MaxValue = XElementHelper.ReadDoubleValue(foundPreference, "maxValue", false);
                    preference.Value    = XElementHelper.ReadDoubleValue(foundPreference, "value", true);

                    // Read the list of entryOption tags
                    var foundEntries = XElementHelper.ReadEnumerable(foundPreference, "entryOption", false);

                    // For each tag, read the values into a new PreferenceEntry object
                    foreach (var entry in foundEntries)
                    {
                        preference.Entries.Add(BuildPreferenceEntry <INumericPreferenceEntry>(preference, entry));
                    }

                    readSharedProperties(preference);
                }
                else if (allowsMultipleSelections)
                {
                    var preference = new StringListPreference();

                    //preference.MinValue = XElementHelper.ReadStringValue(foundPreference, "minValue", false);
                    //preference.MaxValue = XElementHelper.ReadStringValue(foundPreference, "maxValue", false);
                    //preference.Value = XElementHelper.ReadStringValue(foundPreference, "value", false);

                    // Read the list of entryOption tags
                    var foundEntries = XElementHelper.ReadEnumerable(foundPreference, "entryOption", false);

                    // For each tag, read the values into a new PreferenceEntry object
                    foreach (var entry in foundEntries)
                    {
                        preference.Entries.Add(BuildPreferenceEntry <IStringListPreferenceEntry>(preference, entry));
                    }

                    readSharedProperties(preference);
                }
                else
                {
                    var preference = new StringPreference();

                    preference.MinValue = XElementHelper.ReadStringValue(foundPreference, "minValue", false);
                    preference.MaxValue = XElementHelper.ReadStringValue(foundPreference, "maxValue", false);
                    preference.Value    = XElementHelper.ReadStringValue(foundPreference, "value", false);

                    // Read the list of entryOption tags
                    var foundEntries = XElementHelper.ReadEnumerable(foundPreference, "entryOption", false);

                    // For each tag, read the values into a new PreferenceEntry object
                    foreach (var entry in foundEntries)
                    {
                        preference.Entries.Add(BuildPreferenceEntry <IStringPreferenceEntry>(preference, entry));
                    }

                    readSharedProperties(preference);
                }
            }

            return(category as T);
        }
        /// <summary>
        /// Reads the game configuration for a particular xml node name.
        /// </summary>
        /// <param name="xmlNodeName">Name of the XML node.</param>
        /// <returns></returns>
        private IList <GameConfiguration> ReadGameConfig(string xmlNodeName)
        {
            IList <GameConfiguration> gameConfigurations = new List <GameConfiguration>();

            // Read file to memory
            var config = XmlHelper.ReadXmlFile("Configuration.xml");

            if (config == null)
            {
                return(null);
            }

            // Read the games. Most likely only one (source or target), but the code here supports multiple
            var foundGames = config.Descendants(xmlNodeName);

            // For each game, read the various properties we need, and store the result in a new GameConfiguration object
            foreach (var game in foundGames)
            {
                // Save game related
                var saveGameFolderTypeAsString = XElementHelper.ReadStringValue(game, "defaultSaveGameLocationType");
                var saveGameFolderType         = saveGameFolderTypeAsString.Equals(RelativeFolderLocationRoot.SteamFolder.ToString()) ? RelativeFolderLocationRoot.SteamFolder : RelativeFolderLocationRoot.WindowsUsersFolder;
                var saveGameExtension          = XElementHelper.ReadStringValue(game, "saveGameExtension");

                // Installation directory related
                var steamId = XElementHelper.ReadStringValue(game, "steamId");
                var nonsteamRegistryName = XElementHelper.ReadStringValue(game, "nonsteamRegistryName", false);
                var installationFolder   = this.GetSteamInstallationFolder(steamId);
                if (String.IsNullOrEmpty(installationFolder))
                {
                    installationFolder = this.GetNonSteamInstallationFolder(nonsteamRegistryName);
                }
                var configurationFileDirectoryTagName = XElementHelper.ReadStringValue(game, "configurationFileDirectoryTagName");

                // Mod related
                var defaultModFolderLocationTypeAsString = XElementHelper.ReadStringValue(game, "defaultModFolderLocationType", false);
                var defaultModFolderLocationType         = defaultModFolderLocationTypeAsString.Equals(RelativeFolderLocationRoot.SteamFolder.ToString()) ? RelativeFolderLocationRoot.SteamFolder : RelativeFolderLocationRoot.WindowsUsersFolder;
                var configurationFileModDirectoryTagName = XElementHelper.ReadStringValue(game, "configurationFileModDirectoryTagName", false);
                var currentModTagName = XElementHelper.ReadStringValue(game, "currentModTagName", false);

                //if (defaultModFolderLocationType == RelativeFolderLocationRoot.SteamFolder)
                //{
                //    this.options.Logger.AddLogEntry(new LogEntry("The \"defaultModFolderLocationType\" tag cannot have the value \"SteamFolder\". This value isn't supported in the frontend yet.", LogEntrySeverity.Error, LogEntrySource.UI));
                //}

                var supportedModsAsString = game.Descendants("supportedMod");

                var gameConfig = new GameConfiguration()
                {
                    Name         = XElementHelper.ReadStringValue(game, "name"),
                    FriendlyName = XElementHelper.ReadStringValue(game, "friendlyName"),
                    SaveGamePath = (saveGameFolderType == RelativeFolderLocationRoot.SteamFolder ? installationFolder : this.GetUsersFolder()) + XElementHelper.ReadStringValue(game, "defaultSaveGameSubLocation"),
                    SteamId      = steamId,
                    ConfigurationFileDirectoryTagName = configurationFileDirectoryTagName,
                    SaveGameExtension = saveGameExtension,
                    ConfigurationFileModDirectoryTagName = configurationFileModDirectoryTagName,
                    CurrentModTagName = currentModTagName,
                    ModPath           = (defaultModFolderLocationType == RelativeFolderLocationRoot.SteamFolder ? installationFolder : GetUsersFolder()) + XElementHelper.ReadStringValue(game, "defaultModFolderLocation", false),
                    InstallationPath  = installationFolder
                };

                // Dummy item so that the user can undo selecting a mod
                var dummyMod = new SupportedMod()
                {
                    Name = "No mod", IsDummyItem = true
                };
                gameConfig.SupportedMods.Add(dummyMod);
                gameConfig.CurrentMod = dummyMod;

                // Add proper mods
                if (supportedModsAsString.Count() > 0)
                {
                    supportedModsAsString.ForEach(m => gameConfig.SupportedMods.Add(new SupportedMod()
                    {
                        Name = XElementHelper.ReadStringValue(m, "modName")
                    }));
                }

                gameConfigurations.Add(gameConfig);
            }

            return(gameConfigurations);
        }
Ejemplo n.º 26
0
 /// <summary>
 ///     TODO:
 /// </summary>
 /// <param name="config"></param>
 protected override void OnConfigLoaded(XDocument config)
 {
     this.config = config;
     relativeGameConfigurationPath = XElementHelper.ReadStringValue(config.Descendants("configuration").First(),
                                                                    "gameConfigurationFile");
 }
Ejemplo n.º 27
0
        /// <summary>
        ///     Builds the ConverterSettings object given by the xml element (XElement)
        /// </summary>
        /// <typeparam name="T">The type of object to create. In this case, it'll be ConverterSettings</typeparam>
        /// <param name="element">The xml node to generate the ConverterSettings object from</param>
        /// <returns>The generated convertersettings object</returns>
        protected override T OnBuildElement <T>(XElement element)
        {
            var name                     = XElementHelper.ReadStringValue(element, "name");
            var friendlyName             = XElementHelper.ReadStringValue(element, "friendlyName");
            var defaultConfigurationFile = XElementHelper.ReadStringValue(element, "defaultConfigurationFile");
            //var converterExeName = XElementHelper.ReadStringValue(element, "converterExeName");
            //var userConfigurationFile = XElementHelper.ReadStringValue(element, "userConfigurationFile");
            var additionalInformation = XElementHelper.ReadStringValue(element, "informationText", false);

            // Build game configuration models
            var sourceGameName = XElementHelper.ReadStringValue(element, "sourceGame");
            var targetGameName = XElementHelper.ReadStringValue(element, "targetGame");
            var sourceGame     = GameConfigurations.FirstOrDefault(g => g.Name.Equals(sourceGameName));
            var targetGame     = GameConfigurations.FirstOrDefault(g => g.Name.Equals(targetGameName));

            var requiredFolders = RequiredFolderFactory.BuildConfiguration <IRequiredFolder>(element);
            var requiredFiles   = RequiredFileFactory.BuildConfiguration <IRequiredFile>(element);

            // Native export directory.
            //var nativeExportDirectory = XElementHelper.ReadStringValue(element, "nativeParadoxExportDirectory", false);
            //var nativeParadoxExportDirectoryLocationTypeAsString = XElementHelper.ReadStringValue(element, "nativeParadoxExportDirectoryLocationType", false);
            //var nativeParadoxExportDirectoryLocationType = nativeParadoxExportDirectoryLocationTypeAsString.Equals(RelativeFolderLocationRoot.SteamFolder.ToString()) ? RelativeFolderLocationRoot.SteamFolder : RelativeFolderLocationRoot.WindowsUsersFolder;
            //string nativeExportDirectoryTag = XElementHelper.ReadStringValue(element, "nativeParadoxExportDirectoryTag", false);

            //string nativeExportDirectoryAbsolutePath = string.Empty;
            //if (nativeParadoxExportDirectoryLocationType.Equals(RelativeFolderLocationRoot.WindowsUsersFolder))
            //{
            //    nativeExportDirectoryAbsolutePath = DirectoryHelper.GetUsersFolder() + XElementHelper.ReadStringValue(element, "nativeParadoxExportDirectory", false);
            //}
            //else
            //{
            //    //HACK: This is bad, and needs fixing.
            //    throw new NotSupportedException("The native export directory cannot be a steam subfolder.");
            //}

            var errorMessage = "Could not find game configuration for {0}. Could not find game in " +
                               AbsoluteGameConfigurationPath + " with name {1}. ";

            // Build preference categories
            var categories = PreferenceCategoryFactory.BuildModels <IPreferenceCategory>(defaultConfigurationFile);

            if (sourceGame == null)
            {
                EventAggregator.PublishOnUIThread(
                    new LogEntry(string.Format(errorMessage, "source game", sourceGameName), LogEntrySeverity.Error,
                                 LogEntrySource.UI, AbsoluteGameConfigurationPath));
            }

            if (targetGame == null)
            {
                EventAggregator.PublishOnUIThread(
                    new LogEntry(string.Format(errorMessage, "target game", targetGameName), LogEntrySeverity.Error,
                                 LogEntrySource.UI, AbsoluteGameConfigurationPath));
            }

            //var relativeConverterPath = XElementHelper.ReadStringValue(element, "subfolderName");

            var settings = new ConverterSettings(EventAggregator)
            {
                Name                     = name,
                FriendlyName             = friendlyName,
                DefaultConfigurationFile = Path.Combine(Environment.CurrentDirectory, defaultConfigurationFile),
                //ConverterExeName = converterExeName,
                SourceGame = sourceGame,
                TargetGame = targetGame,
                //AbsoluteConverterPath = Path.Combine(Environment.CurrentDirectory, relativeConverterPath),

                /*NativeParadoxExportDirectoryTag = nativeExportDirectoryTag,
                 * NativeParadoxExportDirectory = nativeExportDirectoryAbsolutePath,*/
                //UserConfigurationFile = userConfigurationFile
                Categories            = categories,
                AdditionalInformation = additionalInformation
            };

            requiredFolders.ForEach(f => settings.RequiredItems.Add(f));
            requiredFiles.ForEach(f => settings.RequiredItems.Add(f));

            return(settings as T);
        }