Exemple #1
0
        public static FileTree GetPath([NotNull] this Folder folder, [NotNull] IEnumerator <string> path)
        {
            FileTree item = folder;

            while (path.MoveNext())
            {
                if (!(item is Folder f))
                {
                    throw new InvalidOperationException("trying to get item child from file");
                }
                item = f.Get(path.Current ?? throw new InvalidOperationException("path path is null"));
                if (item is null)
                {
                    return(null);
                }
            }
            path.Dispose();

            return(item);
        }
Exemple #2
0
        public static FileTree Load([NotNull] FileTree data)
        {
            if (data is File)
            {
                return(data);
            }
            if (!(data is Folder folder))
            {
                throw new InvalidOperationException();
            }

            List <ModAsset> assets = null;

            if (folder.TryGetFile("meta.json", out var meta))
            {
                using (var sr = new StreamReader(meta.Data))
                    using (var jr = new JsonTextReader(sr))
                        assets = new JsonSerializer().Deserialize <List <ModAsset> >(jr);
            }

            SetProcessors(folder, folder, assets ?? new List <ModAsset>(), "/");

            return(folder);
        }