예제 #1
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);
        }
예제 #2
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);
        }