Beispiel #1
0
        public DirMgr(string dir, string refRoot)
        {
            this.Dir   = dir;
            this.Title = Dir.DirLeaf();

            if (File.Exists($"{dir}Notes.html"))
            {
                Notes = File.ReadAllText($"{dir}Notes.html");
            }

            var files = (from f in Directory.GetFiles(Dir).ToArray()
                         let fName = Path.GetFileNameWithoutExtension(f)
                                     let fExt = Path.GetExtension(f.ToLower())
                                                group f by fName into g //var dirNames = Directory.GetDirectories(dir).Select(d => d.Substring(d.LastIndexOf("\\") + 1)).ToList();
                                                select new { FileName = g.Key, Exts = g.Select(f => Path.GetExtension(f)).ToList() }// g.Select(f=>f.FileExt).To}
                         ).ToList();

            Files = new List <FileSet>();
            foreach (var f in files)
            {
                var fs = new FileSet()
                {
                    Title = f.FileName
                };
                foreach (var e in f.Exts)
                {
                    var fname = $"{Dir}{Path.DirectorySeparatorChar}{f.FileName}{e}";

                    if (AudioSuffixes.Contains(e))
                    {
                        fs.AudioFileName = $"{refRoot}{Path.DirectorySeparatorChar}{Path.GetFileName(fname)}";

                        TagLib.File taglibFile = TagLib.File.Create(fname, TagLib.ReadStyle.Average);
                        fs.SecondsDuration = (int)taglibFile.Properties.Duration.TotalSeconds;
                        fs.AudioFileInfo   = new AudioFileInfo
                        {
                            TrackNum = (int)taglibFile.Tag.Track,
                            Album    = taglibFile.Tag.Album,
                            Title    = taglibFile.Tag.Title
                        };
                    }
                    else if (TextSuffixes.Contains(e))
                    {
                        fs.Notes = File.ReadAllText(fname);
                    }
                    else if (ImageSuffixes.Contains(e))
                    {
                        fs.ImageFileName = Path.GetFileName(fname);
                    }
                }
                if (fs.IsUseful)
                {
                    Files.Add(fs);
                }
            }
            //this.Dirs = dirNames.Select(d => new CheckboxItem { ID = d, Text = d }).ToList();
            //
            // TODO: Add constructor logic here
            //
        }