private string NormalizePath(string path)
 {
     if (string.IsNullOrEmpty(path))
     {
         return(pathProvider.ToAbsolute(ContentPaths.First()));
     }
     return(path);
 }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MapGrhWalls"/> class.
        /// </summary>
        /// <param name="contentPath">The content path.</param>
        /// <param name="createWall">Delegate describing how to create the <see cref="WallEntityBase"/>
        /// from an <see cref="IValueReader"/>.</param>
        public MapGrhWalls(ContentPaths contentPath, CreateWallEntityFromReaderHandler createWall)
        {
            Load(contentPath, createWall);

            // Listen for the addition and removal of walls
            GrhInfo.AddedNew += DeleteGrhDataWalls;
            GrhInfo.Removed  += DeleteGrhDataWalls;
        }
Esempio n. 3
0
        /// <summary>
        /// Gets the default file path for the body info file for the given <see cref="ContentPaths"/>.
        /// </summary>
        /// <param name="contentPath">The <see cref="ContentPaths"/> to get the default body info file path for.</param>
        /// <returns>The default file path for the body info file for the <paramref name="contentPath"/>.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="contentPath"/> is null.</exception>
        public static string GetDefaultFilePath(ContentPaths contentPath)
        {
            if (contentPath == null)
            {
                throw new ArgumentNullException("contentPath");
            }

            return(contentPath.Data.Join("bodies" + EngineSettings.DataFileSuffix));
        }
Esempio n. 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SkeletonManager"/> class.
        /// </summary>
        /// <param name="contentPath">The content path.</param>
        SkeletonManager(ContentPaths contentPath)
        {
            _contentPath = contentPath;

            var keyComparer = StringComparer.OrdinalIgnoreCase;

            _bodyInfoCache = new HashCache <string, SkeletonBodyInfo>(x => new SkeletonBodyInfo(x, ContentPath), keyComparer);
            _setCache      = new HashCache <string, SkeletonSet>(x => new SkeletonSet(x, ContentPath), keyComparer);
        }
        /// <summary>
        /// Saves the <see cref="ParticleEffectManager"/> to file.
        /// </summary>
        /// <param name="contentPath">The <see cref="ContentPaths"/> to save to.</param>
        public void Save(ContentPaths contentPath)
        {
            var filePath = GetFilePath(contentPath);

            using (var writer = GenericValueWriter.Create(filePath, _rootNodeName, EncodingFormat))
            {
                writer.WriteManyNodes(_particleEffectsNodeName, _effects.Values, (w, v) => v.WriteState(w));
            }
        }
        /// <summary>
        /// Saves the quest descriptions to file.
        /// </summary>
        /// <param name="contentPath">The <see cref="ContentPaths"/> to use to get the file path.</param>
        public void Save(ContentPaths contentPath)
        {
            var filePath = GetFilePath(contentPath);

            using (var w = XmlValueWriter.Create(filePath, _rootFileNodeName))
            {
                WriteState(w);
            }
        }
Esempio n. 7
0
        protected virtual Task <BundleManager> CreateRepoIfNotExistent(ContentPaths modPaths,
                                                                       IEnumerable <KeyValuePair <Guid, Uri[]> > remotes)
        {
            var modPath      = modPaths.Path;
            var synqBasePath = modPaths.RepositoryPath;
            var synqPath     = synqBasePath.GetChildDirectoryWithName(Repository.DefaultRepoRootDirectory);

            return(RepositoryHandler.GetBundleManager(synqPath, modPath, remotes));
        }
Esempio n. 8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SkeletonFrame"/> class.
        /// </summary>
        /// <param name="reader">The <see cref="IValueReader"/> to read from.</param>
        /// <param name="contentPath">The <see cref="ContentPaths"/> to use to load from.</param>
        /// <exception cref="InvalidOperationException">The <see cref="Skeleton"/> failed to load.</exception>
        public SkeletonFrame(IValueReader reader, ContentPaths contentPath)
        {
            Read(reader, contentPath);

            if (Skeleton == null)
            {
                throw new InvalidOperationException("Skeleton failed to load.");
            }
        }
Esempio n. 9
0
        public static void Load(ContentPaths contentPath, IContentManager cm)
        {
            if (IsLoaded)
            {
                return;
            }

            _isLoaded = true;

            var path = GetGrhDataFilePath(contentPath);

            if (cm == null)
            {
                throw new ArgumentNullException("cm");
            }

            if (!File.Exists(path))
            {
                throw new FileNotFoundException("GrhData data file not found.", path);
            }

            _isLoading = true;

            try
            {
                // Create the GrhData DArray
                if (_grhDatas == null)
                {
                    _grhDatas = new DArray <GrhData>(256);
                }
                else
                {
                    _grhDatas.Clear();
                }

                _catDic.Clear();
                _grhDatas.ItemAdded   += AddHandler;
                _grhDatas.ItemRemoved += RemoveHandler;

                // Read and add the GrhDatas in order by their type
                var reader = GenericValueReader.CreateFromFile(path, _rootNodeName);

                LoadGrhDatas(reader, _nonAnimatedGrhDatasNodeName, x => StationaryGrhData.Read(x, cm));
                LoadGrhDatas(reader, _animatedGrhDatasNodeName, AnimatedGrhData.Read);
                LoadGrhDatas(reader, _autoAnimatedGrhDatasNodeName, x => AutomaticAnimatedGrhData.Read(x, cm));

                // Trim down the GrhData array, mainly for the client since it will never add/remove any GrhDatas
                // while in the Client, and the Client is what counts, baby!
                _grhDatas.Trim();
            }
            finally
            {
                _isLoading = false;
            }
        }
        /// <summary>
        /// Loads the <see cref="ParticleEffectManager"/> from file.
        /// </summary>
        /// <param name="contentPath">The <see cref="ContentPaths"/> to load from.</param>
        void Load(ContentPaths contentPath)
        {
            _effects.Clear();

            var filePath    = GetFilePath(contentPath);
            var reader      = GenericValueReader.CreateFromFile(filePath, _rootNodeName);
            var readEffects = reader.ReadManyNodes(_particleEffectsNodeName, r => new ParticleEffect(r));

            // Ensure the ParticleEffects were properly loaded into here
            Debug.Assert(readEffects.All(x => _effects[x.Name] == x));
        }
Esempio n. 11
0
        protected override async Task <BundleManager> CreateRepoIfNotExistent(ContentPaths modPaths,
                                                                              IEnumerable <KeyValuePair <Guid, Uri[]> > remotes)
        {
            var bm = await base.CreateRepoIfNotExistent(modPaths, remotes).ConfigureAwait(false);

            Game.WhenAny(x => x.PrimaryContentPath.Path, x => x.Value).Subscribe(x => {
                bm.PackageManager.Settings.GlobalWorkingPath = x;
                bm.PackageManager.Settings.CheckoutType      = CheckoutType.CheckoutWithoutRemoval;
            });
            return(bm);
        }
Esempio n. 12
0
        /// <summary>
        /// Saves the <see cref="NPCChatDialogBase"/>s in this <see cref="NPCChatManagerBase"/> to file.
        /// </summary>
        /// <param name="contentPath">The content path.</param>
        public void Save(ContentPaths contentPath)
        {
            var dialogs = _npcChatDialogs.Where(x => x != null);

            // Write
            var filePath = GetFilePath(contentPath);

            using (var writer = GenericValueWriter.Create(filePath, _rootNodeName, EncodingFormat))
            {
                writer.WriteManyNodes(_chatDialogsNodeName, dialogs, ((w, item) => item.Write(w)));
            }
        }
Esempio n. 13
0
        static void Main(string[] args)
        {
            log.Info("Starting editor...");

            ThreadAsserts.IsMainThread();

#if DEBUG
            WinFormExceptionHelper.AddUnhandledExceptionHooks();
#endif

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            // Check for a valid path to the development content
            if (ContentPaths.Dev == null)
            {
                const string errmsg =
                    @"Could not find the path to the development content (ContentPaths.Dev). The file containing this path should be located at:
    \Content\Data\devpath.txt

The path to the development content is required by the editor. See the file mentioned above for details.";
                MessageBox.Show(errmsg, "Error finding content path", MessageBoxButtons.OK);
                return;
            }

            // Ensure the content is copied over
            if (!ContentPaths.TryCopyContent(userArgs: CommonConfig.TryCopyContentArgs))
            {
                const string errmsg =
                    "Failed to copy the content from the dev to build path." +
                    " Content in the build path will likely not update to reflect changes made in the content in the dev path.";
                if (log.IsErrorEnabled)
                {
                    log.ErrorFormat(errmsg);
                }
                Debug.Fail(errmsg);
            }

            // Initialize stuff
            EngineSettingsInitializer.Initialize();
            GlobalState.Initialize();

            // Get the command-line switches
            var switches   = CommandLineSwitchHelper.GetCommandsUsingEnum <CommandLineSwitch>(args).ToArray();
            var showEditor = !HandleSwitches(switches);

            if (showEditor)
            {
                // Start up the application
                Application.Run(new MainForm());
            }
        }
Esempio n. 14
0
        /// <summary>
        /// Gets the default file path for the <see cref="ToolStateManager"/> settings file.
        /// </summary>
        /// <param name="contentPath">The <see cref="ContentPaths"/> to get the path for.</param>
        /// <param name="profileName">The name of the settings profile to use. Use null for the default profile.</param>
        /// <returns>
        /// The default file path for the <see cref="ToolStateManager"/> settings file.
        /// </returns>
        public static string GetFilePath(ContentPaths contentPath, string profileName)
        {
            var fileName = "EditorToolStates";

            if (!string.IsNullOrEmpty(profileName))
            {
                fileName += "." + profileName;
            }

            fileName += EngineSettings.DataFileSuffix;

            return(contentPath.Settings.Join(fileName));
        }
Esempio n. 15
0
        /// <summary>
        /// Gets the absolute file path for the content asset.
        /// </summary>
        /// <param name="rootPath">The root content path.</param>
        /// <returns>The absolute file path for the content asset.</returns>
        /// <exception cref="ArgumentException">Either zero or more than one files matching this <see cref="ContentAssetName"/>
        /// were found in the <paramref name="rootPath"/>.</exception>
        public string GetAbsoluteFilePath(ContentPaths rootPath)
        {
            var sb = new StringBuilder();

            // Get the root path
            var rootPathStr = rootPath.Root.ToString();

            sb.Append(rootPathStr);

            // Ensure the root ends with a separator
            if (!rootPathStr.EndsWith(Path.DirectorySeparatorChar.ToString()) &&
                !rootPathStr.EndsWith(Path.AltDirectorySeparatorChar.ToString()))
            {
                sb.Append(PathSeparator);
            }

            // Append the name of the file
            var fileName = GetFileName();

            sb.Append(fileName);

            // If the dev path, try to find the suffix
            if (rootPath == ContentPaths.Dev)
            {
                var files = Directory.GetFiles(rootPathStr, fileName + ".*").ToImmutable();
                if (files.Count() == 0)
                {
                    throw new ArgumentException(
                              string.Format("Could not find a file named `{0}` in path `{1}` with a file suffix.", rootPathStr, fileName));
                }
                if (files.Count() > 1)
                {
                    throw new ArgumentException(
                              string.Format("Found multiple suffixes for the file named `{0}` in path `{1}`. Was expecting just one.",
                                            rootPathStr, fileName));
                }

                var fileToUse = files.First();
                var ext       = Path.GetExtension(fileToUse);
                sb.Append(ext);
            }

            // Ensure we use the correct path separator
            sb.Replace(PathSeparator, Path.DirectorySeparatorChar.ToString());

            return(sb.ToString());
        }
Esempio n. 16
0
 static void CopyContent()
 {
     if (ContentPaths.TryCopyContent(userArgs: CommonConfig.TryCopyContentArgs))
     {
         if (log.IsInfoEnabled)
         {
             log.Info("TryCopyContent succeeded");
         }
     }
     else
     {
         if (log.IsInfoEnabled)
         {
             log.Info("TryCopyContent failed");
         }
     }
 }
Esempio n. 17
0
        /// <summary>
        /// Gets the absolute file path for the content asset.
        /// </summary>
        /// <param name="rootPath">The root content path.</param>
        /// <returns>The absolute file path for the content asset.</returns>
        /// <exception cref="ArgumentException">Either zero or more than one files matching this <see cref="ContentAssetName"/>
        /// were found in the <paramref name="rootPath"/>.</exception>
        public string GetAbsoluteFilePath(ContentPaths rootPath)
        {
            var sb = new StringBuilder();

            // Get the root path
            string rootPathStr = rootPath.Root.ToString();

            sb.Append(rootPathStr);

            // Get the relative file path
            string relFilePathStr = GetFileName();

            // Get all of the files in the directory that this file lives in
            string dirPath = Path.GetDirectoryName(Path.Combine(rootPathStr, relFilePathStr));

            string[] dirFiles = Directory.GetFiles(dirPath, "*.*", SearchOption.TopDirectoryOnly);

            // Take all the files in the directory, filter out the markup and suffix, and find which file names match ours
            string targetFileName = Path.GetFileName(relFilePathStr);

            targetFileName = RemoveFileTagsFromFileName(targetFileName);

            string[] contentFilePaths = dirFiles.Where(x =>
            {
                string xFileName = Path.GetFileNameWithoutExtension(x);
                xFileName        = RemoveFileTagsFromFileName(xFileName);
                return(StringComparer.OrdinalIgnoreCase.Equals(xFileName, targetFileName));
            })
                                        .ToArray();

            // Verify we found exactly 1 match
            if (contentFilePaths.Length == 0)
            {
                throw new ArgumentException(string.Format(
                                                "Could not find a file named (without the [] markup and suffix) `{0}` in path `{1}`.",
                                                targetFileName, dirPath));
            }
            if (contentFilePaths.Length > 1)
            {
                throw new ArgumentException(string.Format(
                                                "Found multiple potential matches for the file named (without the [] markup and suffix) `{0}` in path `{1}`. Was expecting just one.",
                                                targetFileName, dirPath));
            }

            return(contentFilePaths[0]);
        }
        protected override void Execute(NativeActivityContext context)
        {
            var waitForAllTrue = WaitForAllTrue.Get(context);
            var paths          = ContentPaths.Get(context);
            var contents       = paths.Select(p => new WfContent {
                Path = p
            }).ToArray();
            var ext = context.GetExtension <ContentWorkflowExtension>();

            var bookMarkName = Guid.NewGuid().ToString();

            var waitIds      = ext.RegisterWaitForMultipleContent(contents, bookMarkName);
            var waitIdString = String.Join(",", waitIds.Select(w => w.ToString()).ToArray());

            notificationIds.Set(context, waitIdString);

            context.CreateBookmark(bookMarkName, new BookmarkCallback(Continue));
        }
Esempio n. 19
0
        /// <summary>
        /// Saves all of the GrhData information to the specified file.
        /// </summary>
        /// <param name="contentPath">ContentPath to save the GrhData to.</param>
        public static void Save(ContentPaths contentPath)
        {
            // Grab the GrhDatas by their type
            var gds = GrhDatas.Where(x => x != null).OrderBy(x => x.Categorization.ToString(), StringComparer.OrdinalIgnoreCase);
            var stationaryGrhDatas   = gds.OfType <StationaryGrhData>().ToImmutable();
            var animatedGrhDatas     = gds.OfType <AnimatedGrhData>().ToImmutable();
            var autoAnimatedGrhDatas = gds.OfType <AutomaticAnimatedGrhData>().ToImmutable();

            // Write
            var path = GetGrhDataFilePath(contentPath);

            using (IValueWriter writer = GenericValueWriter.Create(path, _rootNodeName, EncodingFormat))
            {
                writer.WriteManyNodes(_nonAnimatedGrhDatasNodeName, stationaryGrhDatas, ((w, item) => item.Write(w)));
                writer.WriteManyNodes(_animatedGrhDatasNodeName, animatedGrhDatas, ((w, item) => item.Write(w)));
                writer.WriteManyNodes(_autoAnimatedGrhDatasNodeName, autoAnimatedGrhDatas, ((w, item) => item.Write(w)));
            }
        }
Esempio n. 20
0
        public void Load(ContentPaths contentPath, CreateWallEntityFromReaderHandler createWall)
        {
            var filePath = GetFilePath(contentPath);

            // Clear the old walls in case this isn't the first load
            _walls.Clear();

            if (!File.Exists(filePath))
            {
                return;
            }

            // Read the values
            var reader      = XmlValueReader.CreateFromFile(filePath, _rootNodeName);
            var loadedWalls = reader.ReadManyNodes(_rootNodeName, x => ReadWalls(x, createWall));

            foreach (var wall in loadedWalls)
            {
                _walls[(int)wall.Key] = wall.Value;
            }
        }
Esempio n. 21
0
        public Unit Handle(SaveGameSettingsCommand message)
        {
            var game = _context.Games.Find(message.Settings.GameId);

            ContentPaths modPaths = null;
            var          modding  = game as ISupportModding;

            if (modding != null)
            {
                modPaths = modding.ModPaths;
            }

            _gameMapper.Map(message.Settings, game.Settings);
            _gameMapper.Map(game.Settings, message.Settings);

            if (modding != null)
            {
                HandleNewModPaths(modding, modding.ModPaths, modPaths);
            }

            return(Unit.Value);
        }
Esempio n. 22
0
        // TODO: Domain events should be raised by the domain, not by the application layer,
        // however it is very difficult in the current setup to detect if modpaths were changed due to a profile change or due to a settings change...
        void HandleNewModPaths(ISupportModding game, ContentPaths newPaths, ContentPaths oldPaths)
        {
            if (!newPaths.IsValid || !oldPaths.IsValid)
            {
                return;
            }

            if (!oldPaths.EqualPath(newPaths))
            {
                if (!oldPaths.EqualRepositoryPath(newPaths))
                {
                    Cheat.PublishDomainEvent(new ModAndSynqPathsChangedEvent(game, oldPaths, newPaths));
                }
                else
                {
                    Cheat.PublishDomainEvent(new ModPathChangedEvent(game, oldPaths, newPaths));
                }
            }
            else if (!oldPaths.EqualRepositoryPath(newPaths))
            {
                Cheat.PublishDomainEvent(new SynqPathChangedEvent(game, oldPaths, newPaths));
            }
        }
Esempio n. 23
0
 /// <summary>
 /// Gets the absolute file path to the GrhData file.
 /// </summary>
 /// <param name="contentPath">ContentPath to use.</param>
 /// <returns>The absolute file path to the GrhData file.</returns>
 public static string GetGrhDataFilePath(ContentPaths contentPath)
 {
     return(contentPath.Data.Join("grhdata" + EngineSettings.DataFileSuffix));
 }
Esempio n. 24
0
 /// <summary>
 /// Gets the absolute file path for a SkeletonSet file.
 /// </summary>
 /// <param name="skeletonSetName">The name of the SkeletonSet.</param>
 /// <param name="contentPath">The content path to use.</param>
 /// <returns>The absolute file path for a SkeletonSet file.</returns>
 public static string GetFilePath(string skeletonSetName, ContentPaths contentPath)
 {
     return(contentPath.Skeletons.Join(skeletonSetName + FileSuffix));
 }
Esempio n. 25
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SkeletonSet"/> class.
 /// </summary>
 /// <param name="skeletonSetName">Name of the <see cref="SkeletonSet"/>.</param>
 /// <param name="contentPath">The <see cref="ContentPaths"/> to load from.</param>
 public SkeletonSet(string skeletonSetName, ContentPaths contentPath)
     : this(GenericValueReader.CreateFromFile(GetFilePath(skeletonSetName, contentPath), _rootNodeName), contentPath)
 {
 }
Esempio n. 26
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SkeletonSet"/> class.
 /// </summary>
 /// <param name="reader">The <see cref="IValueReader"/> to read the data from.</param>
 /// <param name="contentPath">The <see cref="ContentPaths"/> to use to load other data.</param>
 public SkeletonSet(IValueReader reader, ContentPaths contentPath)
 {
     Read(reader, contentPath);
 }
Esempio n. 27
0
        public void Read(IValueReader reader, ContentPaths contentPath)
        {
            var loadedFrames = reader.ReadManyNodes(_framesNodeName, x => new SkeletonFrame(x, contentPath));

            _keyFrames = loadedFrames;
        }
Esempio n. 28
0
 /// <summary>
 /// Reads the <see cref="SkeletonFrame"/> from an <see cref="IValueReader"/>.
 /// </summary>
 /// <param name="reader">The <see cref="IValueReader"/> to read from.</param>
 /// <param name="contentPath">The <see cref="ContentPaths"/> to use to load additional assets.</param>
 public void Read(IValueReader reader, ContentPaths contentPath)
 {
     _delay    = reader.ReadFloat(_delayValueKey);
     _fileName = reader.ReadString(_fileNameValueKey);
     _skeleton = new Skeleton(_fileName, contentPath);
 }
Esempio n. 29
0
 /// <summary>
 /// Loads the <see cref="BodyInfoManager"/> from the specified file.
 /// </summary>
 /// <param name="contentPath">The <see cref="ContentPaths"/> to use to load the file from.</param>
 /// <returns>
 /// The loaded <see cref="BodyInfoManager"/>.
 /// </returns>
 static BodyInfoManager Load(ContentPaths contentPath)
 {
     return(Load(GetDefaultFilePath(contentPath)));
 }
Esempio n. 30
0
 void UpdateModPaths() {
     ModPaths = GetModPaths();
 }
Esempio n. 31
0
 /// <summary>
 /// Saves the <see cref="BodyInfoManager"/> data to file.
 /// </summary>
 /// <param name="contentPath">The <see cref="ContentPaths"/> to save to.</param>
 public void Save(ContentPaths contentPath)
 {
     Save(GetDefaultFilePath(contentPath));
 }