Пример #1
0
        // Show the comics in the window
        private void Fillcomics()
        {
            System.IO.FileInfo fi;
            ArrayList          comics;

            fi = new System.IO.FileInfo(_homeDirectory + "\\AvailableComics.xml");

            _comicsViewer.Clear();
            // Show the "Downloading Comics..." item when the updater is running and there are comics to download
            if (SingletonComicsUpdater.Instance.Updating == true && SingletonComicsUpdater.Instance.SubscribedComics.Length != 0)
            {
                ComicListItem item;
                item = new ComicListItem("Downloading Comics... Click to refresh", "");
                item.RelativeBounds = new Rectangle(0, 0, 200, 40);
                _comicsViewer.AddItem(item);
            }

            // Load the comics or show the instructions screen
            try
            {
                comics = ComicsUpdater.LoadComics(fi.FullName);
            }
            catch
            {
                _instructions.Text    = "Please subscribe to comics";
                _instructions.Visible = true;
                return;
            }

            // If there are no subscribed comics, show instructions
            foreach (ComicInfo ci in comics)
            {
                if (ci.Subscribed == true)
                {
                    _instructions.Visible = false;
                    break;
                }
                else
                {
                    _instructions.Visible = true;
                }
            }

            // Get the number of days to keep
            int daysToKeep;

            try
            {
                string sDaysToKeep;

                SingletonConfig.Instance.GetPropertyAsString("Comics.DaysToKeep", out sDaysToKeep);
                daysToKeep = int.Parse(sDaysToKeep);
            }
            catch { daysToKeep = 7; }

            string sSortBy;

            SingletonConfig.Instance.GetPropertyAsString("Comics.SortBy", out sSortBy);
            if (sSortBy == "Date")
            {
                // Retrieve the local image for each comic
                for (int i = 0; i < daysToKeep; i++)
                {
                    foreach (ComicInfo ci in comics)
                    {
                        if (ci.Subscribed == true)
                        {
                            string title, fullName;

                            DateTime dt = DateTime.Now.AddDays(-i);
                            title = ci.DisplayName + " - " + dt.ToString("D", DateTimeFormatInfo.InvariantInfo);
                            // Create the image filename from the format in the XML file
                            char[]   delims         = { '$' };
                            String[] FilenameTokens = ci.ImageFilename.Split(delims, 100);
                            String   ImageFilename  = "";
                            // Parse the String format and form the filename
                            foreach (String s in FilenameTokens)
                            {
                                // Year
                                if (s.Equals("YY"))
                                {
                                    ImageFilename += dt.ToString("yy", DateTimeFormatInfo.InvariantInfo);
                                }
                                // Month
                                else if (s.Equals("MM"))
                                {
                                    ImageFilename += dt.ToString("MM", DateTimeFormatInfo.InvariantInfo);
                                }
                                // Day
                                else if (s.Equals("DD"))
                                {
                                    ImageFilename += dt.ToString("dd", DateTimeFormatInfo.InvariantInfo);
                                }
                                else
                                {
                                    ImageFilename += s;
                                }
                            }
                            fullName = _homeDirectory + "\\" + ci.FolderName + "\\" + ImageFilename + "." + ci.ImageSuffix;
                            bool noComic = true;
                            if (!System.IO.File.Exists(fullName))
                            {
                                noComic = true;
                                // try the Dilbert hack
                                fullName = _homeDirectory + "\\" + ci.FolderName + "\\" + ImageFilename + ".jpg";
                                if (System.IO.File.Exists(fullName))
                                {
                                    noComic = false;
                                }
                            }
                            else
                            {
                                noComic = false;
                            }

                            if (noComic)
                            {
                                continue;
                            }

                            // width is always 600
                            // height is a minimum of 200, maximum of 600
                            Bitmap bmp;
                            float  aspectRatio;
                            int    calculatedHeight, calculatedWidth;

                            bmp = null;
                            try
                            {
                                bmp = new Bitmap(fullName);
                            }
                            catch (Exception e)
                            {
                                SnapStream.Logging.WriteLog("Fillcomics - Could not load the comic: " + ci.DisplayName);
                                SnapStream.Logging.WriteLog(e.ToString());
                                continue;
                            }

                            if (bmp.Size.Height == 0)
                            {
                                SnapStream.Logging.WriteLog("Fillcomics - bitmap had no height: " + ci.DisplayName);
                                continue;
                            }

                            aspectRatio = (float)bmp.Size.Width / (float)bmp.Size.Height;
                            if (aspectRatio > 600 / 200)
                            {
                                calculatedWidth  = 600;
                                calculatedHeight = 200;
                            }
                            else
                            {
                                calculatedWidth  = 600;
                                calculatedHeight = (int)((float)bmp.Size.Width / aspectRatio);
                            }

                            ComicListItem item;
                            item = new ComicListItem(title, fullName);
                            item.RelativeBounds = new Rectangle(0, 0, calculatedWidth, calculatedHeight);
                            _comicsViewer.AddItem(item);
                        }
                    }
                }
            }
            if (sSortBy == "Comic")
            {
                // Retrieve the local image for each comic
                foreach (ComicInfo ci in comics)
                {
                    for (int i = 0; i < daysToKeep; i++)
                    {
                        if (ci.Subscribed == true)
                        {
                            string title, fullName;

                            DateTime dt = DateTime.Now.AddDays(-i);
                            title = ci.DisplayName + " - " + dt.ToString("D", DateTimeFormatInfo.InvariantInfo);
                            // Create the image filename from the format in the XML file
                            char[]   delims         = { '$' };
                            String[] FilenameTokens = ci.ImageFilename.Split(delims, 100);
                            String   ImageFilename  = "";
                            // Parse the String format and form the filename
                            foreach (String s in FilenameTokens)
                            {
                                // Year
                                if (s.Equals("YY"))
                                {
                                    ImageFilename += dt.ToString("yy", DateTimeFormatInfo.InvariantInfo);
                                }
                                // Month
                                else if (s.Equals("MM"))
                                {
                                    ImageFilename += dt.ToString("MM", DateTimeFormatInfo.InvariantInfo);
                                }
                                // Day
                                else if (s.Equals("DD"))
                                {
                                    ImageFilename += dt.ToString("dd", DateTimeFormatInfo.InvariantInfo);
                                }
                                else
                                {
                                    ImageFilename += s;
                                }
                            }
                            fullName = _homeDirectory + "\\" + ci.FolderName + "\\" + ImageFilename + "." + ci.ImageSuffix;
                            bool noComic = true;
                            if (!System.IO.File.Exists(fullName))
                            {
                                noComic = true;
                                // try the Dilbert hack
                                fullName = _homeDirectory + "\\" + ci.FolderName + "\\" + ImageFilename + ".jpg";
                                if (System.IO.File.Exists(fullName))
                                {
                                    noComic = false;
                                }
                            }
                            else
                            {
                                noComic = false;
                            }

                            if (noComic)
                            {
                                continue;
                            }

                            // width is always 600
                            // height is a minimum of 200, maximum of 600
                            Bitmap bmp;
                            float  aspectRatio;
                            int    calculatedHeight, calculatedWidth;

                            bmp = null;
                            try
                            {
                                bmp = new Bitmap(fullName);
                            }
                            catch (Exception e)
                            {
                                SnapStream.Logging.WriteLog("Fillcomics - Could not load the comic: " + ci.DisplayName);
                                SnapStream.Logging.WriteLog(e.ToString());
                                continue;
                            }

                            if (bmp.Size.Height == 0)
                            {
                                SnapStream.Logging.WriteLog("Fillcomics - bitmap had no height: " + ci.DisplayName);
                                continue;
                            }

                            aspectRatio = (float)bmp.Size.Width / (float)bmp.Size.Height;
                            if (aspectRatio > 600 / 200)
                            {
                                calculatedWidth  = 600;
                                calculatedHeight = 200;
                            }
                            else
                            {
                                calculatedWidth  = 600;
                                calculatedHeight = (int)((float)bmp.Size.Width / aspectRatio);
                            }

                            ComicListItem item;
                            item = new ComicListItem(title, fullName);
                            item.RelativeBounds = new Rectangle(0, 0, calculatedWidth, calculatedHeight);
                            _comicsViewer.AddItem(item);
                        }
                    }
                }
            }

            // Start at the first
            _comicsViewer.SelectedIndex = 0;

            return;
        }
Пример #2
0
        // Show the comics in the window
        private void Fillcomics()
        {
            System.IO.FileInfo	fi;
            ArrayList			comics;

            fi = new System.IO.FileInfo( _homeDirectory + "\\AvailableComics.xml" );

            _comicsViewer.Clear();
            // Show the "Downloading Comics..." item when the updater is running and there are comics to download
            if (SingletonComicsUpdater.Instance.Updating == true && SingletonComicsUpdater.Instance.SubscribedComics.Length != 0 )
            {
                ComicListItem	item;
                item = new ComicListItem( "Downloading Comics... Click to refresh", "");
                item.RelativeBounds = new Rectangle( 0, 0, 200, 40 );
                _comicsViewer.AddItem( item );
            }

            // Load the comics or show the instructions screen
            try
            {
                comics = ComicsUpdater.LoadComics( fi.FullName );
            }
            catch
            {
                _instructions.Text = "Please subscribe to comics";
                _instructions.Visible = true;
                return;
            }

            // If there are no subscribed comics, show instructions
            foreach( ComicInfo ci in comics )
            {
                if( ci.Subscribed == true )
                {
                    _instructions.Visible = false;
                    break;
                }
                else
                    _instructions.Visible = true;
            }

            // Get the number of days to keep
            int daysToKeep;
            try
            {
                string	sDaysToKeep;

                SingletonConfig.Instance.GetPropertyAsString( "Comics.DaysToKeep", out sDaysToKeep );
                daysToKeep = int.Parse( sDaysToKeep );
            }
            catch { daysToKeep = 7; }

            string sSortBy;
            SingletonConfig.Instance.GetPropertyAsString( "Comics.SortBy", out sSortBy);
            if (sSortBy == "Date")
            {
                // Retrieve the local image for each comic
                for (int i = 0; i < daysToKeep; i++)
                {
                    foreach( ComicInfo ci in comics )
                    {
                        if (ci.Subscribed == true)
                        {
                            string	title, fullName;

                            DateTime dt = DateTime.Now.AddDays(-i);
                            title = ci.DisplayName + " - " + dt.ToString("D",DateTimeFormatInfo.InvariantInfo);
                            // Create the image filename from the format in the XML file
                            char[] delims = {'$'};
                            String[] FilenameTokens = ci.ImageFilename.Split(delims,100);
                            String ImageFilename = "";
                            // Parse the String format and form the filename
                            foreach( String s in FilenameTokens )
                            {
                                // Year
                                if ( s.Equals("YY") )
                                    ImageFilename += dt.ToString("yy",DateTimeFormatInfo.InvariantInfo);
                                    // Month
                                else if ( s.Equals("MM") )
                                    ImageFilename += dt.ToString("MM",DateTimeFormatInfo.InvariantInfo);
                                    // Day
                                else if ( s.Equals("DD") )
                                    ImageFilename += dt.ToString("dd",DateTimeFormatInfo.InvariantInfo);
                                else
                                    ImageFilename += s;
                            }
                            fullName = _homeDirectory + "\\" + ci.FolderName + "\\" + ImageFilename + "." + ci.ImageSuffix;
                            bool noComic = true;
                            if( !System.IO.File.Exists(fullName) )
                            {
                                noComic = true;
                                // try the Dilbert hack
                                fullName = _homeDirectory + "\\" + ci.FolderName + "\\" + ImageFilename + ".jpg";
                                if( System.IO.File.Exists(fullName) )
                                {
                                    noComic = false;
                                }
                            }
                            else
                                noComic = false;

                            if (noComic) continue;

                            // width is always 600
                            // height is a minimum of 200, maximum of 600
                            Bitmap	bmp;
                            float	aspectRatio;
                            int		calculatedHeight, calculatedWidth;

                            bmp = null;
                            try
                            {
                                bmp = new Bitmap( fullName );
                            }
                            catch( Exception e )
                            {
                                SnapStream.Logging.WriteLog( "Fillcomics - Could not load the comic: " + ci.DisplayName);
                                SnapStream.Logging.WriteLog( e.ToString() );
                                continue;
                            }

                            if( bmp.Size.Height == 0 )
                            {
                                SnapStream.Logging.WriteLog( "Fillcomics - bitmap had no height: " + ci.DisplayName);
                                continue;
                            }

                            aspectRatio = (float)bmp.Size.Width / (float)bmp.Size.Height;
                            if( aspectRatio > 600/200 )
                            {
                                calculatedWidth = 600;
                                calculatedHeight = 200;
                            }
                            else
                            {
                                calculatedWidth = 600;
                                calculatedHeight = (int)( (float)bmp.Size.Width / aspectRatio);
                            }

                            ComicListItem	item;
                            item = new ComicListItem( title, fullName );
                            item.RelativeBounds = new Rectangle( 0, 0, calculatedWidth, calculatedHeight );
                            _comicsViewer.AddItem( item );
                        }
                    }
                }
            }
            if (sSortBy == "Comic")
            {
                // Retrieve the local image for each comic
                foreach( ComicInfo ci in comics )
                {
                    for (int i = 0; i < daysToKeep; i++)
                    {
                        if (ci.Subscribed == true)
                        {
                            string	title, fullName;

                            DateTime dt = DateTime.Now.AddDays(-i);
                            title = ci.DisplayName + " - " + dt.ToString("D",DateTimeFormatInfo.InvariantInfo);
                            // Create the image filename from the format in the XML file
                            char[] delims = {'$'};
                            String[] FilenameTokens = ci.ImageFilename.Split(delims,100);
                            String ImageFilename = "";
                            // Parse the String format and form the filename
                            foreach( String s in FilenameTokens )
                            {
                                // Year
                                if ( s.Equals("YY") )
                                    ImageFilename += dt.ToString("yy",DateTimeFormatInfo.InvariantInfo);
                                    // Month
                                else if ( s.Equals("MM") )
                                    ImageFilename += dt.ToString("MM",DateTimeFormatInfo.InvariantInfo);
                                    // Day
                                else if ( s.Equals("DD") )
                                    ImageFilename += dt.ToString("dd",DateTimeFormatInfo.InvariantInfo);
                                else
                                    ImageFilename += s;
                            }
                            fullName = _homeDirectory + "\\" + ci.FolderName + "\\" + ImageFilename + "." + ci.ImageSuffix;
                            bool noComic = true;
                            if( !System.IO.File.Exists(fullName) )
                            {
                                noComic = true;
                                // try the Dilbert hack
                                fullName = _homeDirectory + "\\" + ci.FolderName + "\\" + ImageFilename + ".jpg";
                                if( System.IO.File.Exists(fullName) )
                                {
                                    noComic = false;
                                }
                            }
                            else
                                noComic = false;

                            if (noComic) continue;

                            // width is always 600
                            // height is a minimum of 200, maximum of 600
                            Bitmap	bmp;
                            float	aspectRatio;
                            int		calculatedHeight, calculatedWidth;

                            bmp = null;
                            try
                            {
                                bmp = new Bitmap( fullName );
                            }
                            catch( Exception e )
                            {
                                SnapStream.Logging.WriteLog( "Fillcomics - Could not load the comic: " + ci.DisplayName);
                                SnapStream.Logging.WriteLog( e.ToString() );
                                continue;
                            }

                            if( bmp.Size.Height == 0 )
                            {
                                SnapStream.Logging.WriteLog( "Fillcomics - bitmap had no height: " + ci.DisplayName);
                                continue;
                            }

                            aspectRatio = (float)bmp.Size.Width / (float)bmp.Size.Height;
                            if( aspectRatio > 600/200 )
                            {
                                calculatedWidth = 600;
                                calculatedHeight = 200;
                            }
                            else
                            {
                                calculatedWidth = 600;
                                calculatedHeight = (int)( (float)bmp.Size.Width / aspectRatio);
                            }

                            ComicListItem	item;
                            item = new ComicListItem( title, fullName );
                            item.RelativeBounds = new Rectangle( 0, 0, calculatedWidth, calculatedHeight );
                            _comicsViewer.AddItem( item );
                        }
                    }
                }
            }

            // Start at the first
            _comicsViewer.SelectedIndex = 0;

            return;
        }