Пример #1
0
        public static ResourcePackList FromJson(JArray serializedState, IServiceProvider services, string searchPath)
        {
            if (!Directory.Exists(searchPath))
            {
                return(new ResourcePackList());
            }
            List <ResourcePack> list = new List <ResourcePack>();

            foreach (ResourcePackEntry item2 in CreatePackEntryListFromJson(serializedState))
            {
                if (item2.FileName == null)
                {
                    continue;
                }
                string text = Path.Combine(searchPath, item2.FileName);
                try
                {
                    if (File.Exists(text) || Directory.Exists(text))
                    {
                        ResourcePack item = new ResourcePack(services, text)
                        {
                            IsEnabled    = item2.Enabled,
                            SortingOrder = item2.SortingOrder
                        };
                        list.Add(item);
                    }
                }
                catch (Exception arg)
                {
                    Console.WriteLine("Failed to read resource pack {0}: {1}", text, arg);
                }
            }
            string[] files = Directory.GetFiles(searchPath, "*.zip");
            string   fileName;

            foreach (string text2 in files)
            {
                try
                {
                    fileName = Path.GetFileName(text2);
                    if (list.All((ResourcePack pack) => pack.FileName != fileName))
                    {
                        list.Add(new ResourcePack(services, text2));
                    }
                }
                catch (Exception arg2)
                {
                    Console.WriteLine("Failed to read resource pack {0}: {1}", text2, arg2);
                }
            }
            files = Directory.GetDirectories(searchPath);
            string folderName;

            foreach (string text3 in files)
            {
                try
                {
                    folderName = Path.GetFileName(text3);
                    if (list.All((ResourcePack pack) => pack.FileName != folderName))
                    {
                        list.Add(new ResourcePack(services, text3));
                    }
                }
                catch (Exception arg3)
                {
                    Console.WriteLine("Failed to read resource pack {0}: {1}", text3, arg3);
                }
            }
            return(new ResourcePackList(list));
        }
Пример #2
0
        public static ResourcePackList FromJson(
            JArray serializedState,
            IServiceProvider services,
            string searchPath)
        {
            if (!Directory.Exists(searchPath))
            {
                return(new ResourcePackList());
            }
            List <ResourcePack> source = new List <ResourcePack>();

            foreach (ResourcePackList.ResourcePackEntry resourcePackEntry in ResourcePackList.CreatePackEntryListFromJson(serializedState))
            {
                if (resourcePackEntry.FileName != null)
                {
                    string path = Path.Combine(searchPath, resourcePackEntry.FileName);
                    try
                    {
                        if (!File.Exists(path))
                        {
                            if (!Directory.Exists(path))
                            {
                                continue;
                            }
                        }
                        ResourcePack resourcePack = new ResourcePack(services, path)
                        {
                            IsEnabled    = resourcePackEntry.Enabled,
                            SortingOrder = resourcePackEntry.SortingOrder
                        };
                        source.Add(resourcePack);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Failed to read resource pack {0}: {1}", (object)path, (object)ex);
                    }
                }
            }
            foreach (string file in Directory.GetFiles(searchPath, "*.zip"))
            {
                try
                {
                    string fileName = Path.GetFileName(file);
                    if (source.All <ResourcePack>((Func <ResourcePack, bool>)(pack => pack.FileName != fileName)))
                    {
                        source.Add(new ResourcePack(services, file));
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Failed to read resource pack {0}: {1}", (object)file, (object)ex);
                }
            }
            foreach (string directory in Directory.GetDirectories(searchPath))
            {
                try
                {
                    string folderName = Path.GetFileName(directory);
                    if (source.All <ResourcePack>((Func <ResourcePack, bool>)(pack => pack.FileName != folderName)))
                    {
                        source.Add(new ResourcePack(services, directory));
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Failed to read resource pack {0}: {1}", (object)directory, (object)ex);
                }
            }
            return(new ResourcePackList((IEnumerable <ResourcePack>)source));
        }