예제 #1
0
        public async Task SongInfoWriteTest(string binName, string xmlName)
        {
            using FileStream outStream = new FileStream(binName, FileMode.Create, FileAccess.Write);
            Xmb xmb = new Xmb();

            using FileStream stream = new FileStream(xmlName, FileMode.Open, FileAccess.Read);
            xmb.ReadXml(stream);
            await xmb.WriteXmb(outStream);
        }
예제 #2
0
        public async Task AddLyrics(string dirName, IProgress <ProgressData> progress = null)
        {
            DirectoryInfo    dInfo     = new DirectoryInfo(dirName);
            HashSet <string> filenames =
                new HashSet <string>(dInfo.GetFiles("*.xml")
                                     .Select(fInfo => fInfo.Name));

            string               filenameXlsxName = dirName + "/filenames.xlsx";
            XlsxReader           xlsx             = new XlsxReader(filenameXlsxName);
            IEnumerable <Record> records          = xlsx.GetRows("XX", "filenames")
                                                    .Where(record => filenames.Contains((string)record[1]));
            int total = records.Count();
            int count = 0;

            foreach (Record record in records)
            {
                string entryName = (string)record[0];
                string xmlName   = dInfo.FullName + '\\' + (string)record[1];
                count++;
                progress?.Report(new ProgressData {
                    count = count, total = total, filename = entryName
                });
                if (!HasFile(entryName))
                {
                    Xmb xmb = new Xmb();
                    using (FileStream xmlStream = new FileStream(xmlName, FileMode.Open, FileAccess.Read))
                    {
                        xmb.ReadXml(xmlStream);
                    }
                    ZipArchiveEntry entry = zipArchive.CreateEntry(entryName);
                    using Stream entryStream = entry.Open();
                    await xmb.WriteXmb(entryStream);

                    _entries.Add(new PatchZipEntry(entry));
                }
            }
        }