Example #1
0
        /// <summary>
        /// Read group and add it to group list
        /// </summary>
        /// <param name="TES4"></param>
        /// <param name="fileStream"></param>
        /// <param name="size"></param>
        private static void ReadGroup(TES4 TES4, FileStream fileStream, int size)
        {
            var data = new byte[size];

            fileStream.Read(data, 0, data.Length);

            ThreadPool.QueueUserWorkItem(new WaitCallback((object a) =>
            {
                var g = new Group(data);
                TES4.Groups.Add(g);
                Console.WriteLine($"group {g.Label} built total: {TES4.Groups.Count}");
            }));
        }
Example #2
0
        /// <summary>
        /// Reads ESM/ESP from given path
        /// </summary>
        /// <param name="filePath"></param>
        /// <returns></returns>
        public static TES4 TES4Load(string filePath, List <string> filteredGrops = null, List <string> worldSpaceFormId = null)
        {
            if (filteredGrops == null)
            {
                filteredGrops = new List <string>();
            }


            var TES4       = new TES4();
            var fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read);

            TES4.Tes4 = ReadTES4Record(fileStream);

            var         groupHeader = new byte[12];
            List <Task> tasks       = new List <Task>();

            while (fileStream.Position != fileStream.Length)
            {
                var    reader = new ByteReader();
                int    size   = ReadGroupSize(fileStream, reader, groupHeader);
                string type   = ReadGroupType(fileStream, reader, groupHeader);

                if (filteredGrops.Count > 0 && !filteredGrops.Contains(type))
                {
                    fileStream.Position += size;
                    continue;
                }


                var data = new byte[size];
                fileStream.Read(data, 0, data.Length);

                Task task = new Task(() =>
                {
                    var g = new Group(data);
                    TES4.Groups.Add(g);
                    Console.WriteLine($"group {g.Label} built with record count: {g.Records.Count}");
                });
                task.Start();
                tasks.Add(task);
            }

            foreach (Task task in tasks)
            {
                task.Wait();
            }

            return(TES4);
        }