コード例 #1
0
        public static async Task <List <ItemMaster> > LoadFromFile(this List <ItemMaster> itemMasters, string filePath = "")
        {
            if (string.IsNullOrEmpty(filePath))
            {
                filePath = defaultFilePath;
            }

            if (itemMasters.Count > 0) // clear all existing items so only loaded ones are in list
            {
                itemMasters.Clear();
            }

            using (ZipArchive zip = ZipFile.Open(filePath, ZipArchiveMode.Read))
            {
                foreach (ZipArchiveEntry entry in zip.Entries)
                {
                    using (StreamReader sr = new StreamReader(entry.Open()))
                    {
                        var text = await sr.ReadToEndAsync();

                        var itemMaster = ItemMaster.FromJson(text);
                        itemMasters.Add(itemMaster);
                    }
                }
            }

            return(itemMasters);
        }