Ejemplo n.º 1
0
        // Add the images in the folder to the slide show.
        // Return the number of images found.
        public int PopulateFromFolder()
        {
            string mainPath        = Path.GetDirectoryName(iFilePath);
            string subDirectory    = Path.GetFileNameWithoutExtension(iFilePath);
            string slideShowFolder = Path.Combine(mainPath, subDirectory);

            int dayOfPrevSlide = -1;

            foreach (FileInfo file in new DirectoryInfo(slideShowFolder).GetFiles())
            {
                if (IsPhoto(file))
                {
                    string   relativePath = Path.Combine(subDirectory, file.ToString());
                    Caption  caption      = null;
                    DateTime dateTime;
                    if (ParseDateName(file.ToString(), out dateTime))
                    {
                        string day  = dateTime.DayOfWeek.ToString();
                        string date = dateTime.ToLongDateString();
                        caption = new Caption();

                        int thisDay = dateTime.DayOfYear;
                        if (thisDay == dayOfPrevSlide)
                        {
                            // Same day: abbreviated date in caption
                            caption.AddLine(string.Format("{0}, {1:HH}:{1:mm}", day, dateTime));
                        }
                        else
                        {
                            // New day: include full date in caption
                            caption.AddLine(string.Format("{0} {1}", day, date));
                            caption.AddLine(string.Format("{0:HH}:{0:mm}", dateTime));
                            dayOfPrevSlide = thisDay;
                        }
                    }

                    // Add images provided they are not already in the slideshow.
                    // This enables new images to be added to an existing slideshow.
                    if (!IsInShow(file.ToString()))
                    {
                        Add(relativePath, caption);
                    }
                }
            }

            // In case we are adding new slides to an existing show, sort the final set
            // to ensure that the new slides appear in the correct order
            iShow.Sort();

            return(iShow.Count);
        }