Exemplo n.º 1
0
        void writeTextFile(Func <Book, string> nameFunc, string dir)
        {
            if (AaxFileItem is null)
            {
                return;
            }
            var    afi      = AaxFileItem;
            string filename = $"{nameFunc (Book)}.txt";
            string path     = Path.Combine(dir, filename);

            Log(3, this, () => $"\"{path.SubstitUser ()}\"");
            try {
                using (var osm = new StreamWriter(path, false)) {
                    osm.WriteLine($"{R.HdrAuthor}: {Book.AuthorTag}");
                    osm.WriteLine($"{R.HdrTitle}: {Book.TitleTag}");
                    osm.WriteLine($"{R.HdrDuration}: {Duration.ToStringHMS ()}");
                    osm.WriteLine($"{R.HdrNarrator}: {afi.Narrator}");
                    osm.WriteLine($"{R.HdrGenre}: {Book.CustomNames?.GenreTag ?? TagAndFileNamingHelper.GetGenre (Settings, afi)}");
                    osm.WriteLine($"{R.HdrYear}: {Book.CustomNames?.YearTag?.Year ?? afi.PublishingDate?.Year}");
                    osm.WriteLine($"{R.HdrPublisher}: {afi.Publisher}");
                    osm.WriteLine($"{R.HdrCopyright}: {afi.Copyright}");
                    osm.WriteLine($"{R.HdrSampleRate}: {afi.SampleRate} Hz");
                    osm.WriteLine($"{R.HdrBitRate}: {afi.AvgBitRate} kb/s");
                    osm.WriteLine();

                    string[] words = afi.Abstract?.Split();
                    if (words is null)
                    {
                        return;
                    }

                    int n = 0;
                    for (int i = 0; i < words.Length; i++)
                    {
                        string word = words[i];
                        if (n + 1 + word.Length > 80)
                        {
                            osm.WriteLine();
                            n = 0;
                        }

                        if (n > 0)
                        {
                            osm.Write(' ');
                            n++;
                        }
                        osm.Write(word);
                        n += word.Length;
                    }
                    osm.WriteLine();
                }
            } catch (Exception exc) {
                Log(1, this, exc.ToShortString());
            }
        }
Exemplo n.º 2
0
        void writeTextFile(Func <Book, string> nameFunc)
        {
            var    afi      = AaxFileItem;
            string filename = $"{nameFunc(Book)}.txt";
            string path     = Path.Combine(Book.OutDirectoryLong, filename);

            using (var osm = new StreamWriter(path, false)) {
                osm.WriteLine($"{R.HdrAuthor}: {Book.AuthorTag}");
                osm.WriteLine($"{R.HdrTitle}: {Book.TitleTag}");
                osm.WriteLine($"{R.HdrDuration}: {Duration.ToString (@"hh\:mm\:ss")}");
                osm.WriteLine($"{R.HdrNarrator}: {afi.Narrator}");
                osm.WriteLine($"{R.HdrGenre}: {Book.CustomNames?.GenreTag ?? TagAndFileNamingHelper.GetGenre(Settings, afi)}");
                osm.WriteLine($"{R.HdrYear}: {Book.CustomNames?.YearTag?.Year ?? afi.PublishingDate?.Year}");
                osm.WriteLine($"{R.HdrPublisher}: {afi.Publisher}");
                osm.WriteLine($"{R.HdrCopyright}: {afi.Copyright}");
                osm.WriteLine($"{R.HdrSampleRate}: {afi.SampleRate} Hz");
                osm.WriteLine($"{R.HdrBitRate}: {afi.AvgBitRate} kb/s");
                osm.WriteLine();

                string[] words = afi.Abstract?.Split();
                if (words is null)
                {
                    return;
                }

                int n = 0;
                for (int i = 0; i < words.Length; i++)
                {
                    string word = words[i];
                    if (n + 1 + word.Length > 80)
                    {
                        osm.WriteLine();
                        n = 0;
                    }

                    if (n > 0)
                    {
                        osm.Write(' ');
                        n++;
                    }
                    osm.Write(word);
                    n += word.Length;
                }
                osm.WriteLine();
            }
        }