Esempio n. 1
0
        public Task Scan(string directory)
        {
            return(Task.Run(() =>
            {
                if (!Directory.Exists(directory))
                {
                    Images = Images.Change(new List <string>());
                }
                string[] allfiles = Directory.GetFiles(directory, "*.*", SearchOption.AllDirectories);

                var status = ProgramStatus.Global.CreateNamedStatus("Scanning Files...");
                var newImages = new List <string>();
                foreach (var item in allfiles)
                {
                    status.Change(new FileInfo(item).Name);
                    using (var stream = File.OpenRead(item))
                    {
                        var mimeType = mimeTypes.GetMimeType(stream);
                        if (mimeType.StartsWith("image"))
                        {
                            newImages.Add(item);
                        }
                    }
                }
                Images = Images.Change(newImages);
                SelectedImage = SelectedImage.Change(newImages.FirstOrDefault());
                ProgramStatus.Global.Change("Scanning Complete!");
            }));
        }