示例#1
1
        public MainForm()
        {
            InitializeComponent();

            m_settings = new Settings();
            LoadSettings();

            // default is HS if not selected
            m_stripHS = new Hesari(HS_BASE_ADDRESS);
            m_stripKaleva = new Kaleva(KALEVA_BASE_ADDRESS);

            if (m_settings.SourceSelection == SelectedSource.HS ||
                m_settings.SourceSelection == SelectedSource.NOT_SELECTED)
                m_currentStrip = m_stripHS;
            else
                m_currentStrip = m_stripKaleva;

            //Prepare the fade in/out threads that will be called later
            ThreadStart fadeInStart = new ThreadStart(FadeIn);
            m_fadeIn = new Thread(fadeInStart);

            ThreadStart fadeOutStart = new ThreadStart(FadeOut);
            m_fadeOut = new Thread(fadeOutStart);

            loadResources();

            nextPictureBox.Hide();
            prevPictureBox.Hide();

            this.MouseClick += new MouseEventHandler(MainForm_MouseClick);

            ResizeRedraw = true;
            SetLoadLabel(true);
            LoadCurrent();
        }
示例#2
0
        public override DateTime GetStripDate(Settings settings)
        {
            int index1 = 0, index2 = 0, index3 = 0;
            const string startLocation = "<h1>Fingerpori</h1>";
            const string dateEnd = "</p>";

            string pageSource = GeneralUtilities.Networking.GetPageSource(
                CurrentURL,
                settings.ProxyUserName,
                settings.ProxyPassword,
                settings.Proxy,
                settings.ProxyPort,
                false);

            try
            {
                index1 = pageSource.IndexOf(startLocation, 0, StringComparison.CurrentCulture);
                index2 = index1 + startLocation.Length + 4;
                index3 = pageSource.IndexOf(dateEnd, index2, StringComparison.CurrentCulture);

                string dateString = pageSource.Substring(index2 + dateEnd.Length, index3 - index2 - dateEnd.Length);

                return Convert.ToDateTime(dateString, CultureInfo.CurrentCulture);
            }
            catch (InvalidCastException)
            {
                return DateTime.Today;
            }
        }
示例#3
0
        public override string GetStripAddress(string url, Settings settings)
        {
            string address = String.Empty;
            string pageSource = GeneralUtilities.Networking.GetPageSource(
                url,
                settings.ProxyUserName,
                settings.ProxyPassword,
                settings.Proxy,
                settings.ProxyPort,
                false);

            if (!string.IsNullOrEmpty(pageSource))
            {
                int index2 = 0, index3 = 0, index4 = 0;

                try
                {
                    index2 = pageSource.IndexOf("<div class=\"strip\" style=\"display: block;\">", 0, StringComparison.CurrentCulture);
                    if (index2 != -1) index3 = pageSource.IndexOf("src=\"", index2, StringComparison.CurrentCulture);
                    if (index3 != -1) index4 = pageSource.IndexOf("\"", index3 + 5, StringComparison.CurrentCulture);
                    if (index4 != -1) address = pageSource.Substring(index3 + 5, index4 - index3 - 5);
                }
                catch (ArgumentOutOfRangeException)
                {
                    address = String.Empty;
                }
            }

            return address;
        }
示例#4
0
 public override string GetLinkToStrip(Settings settings)
 {
     return GeneralUtilities.BitLy.ShortenURL(
         GetStripAddress(CurrentURL, settings),
         settings.ProxyUserName,
         settings.ProxyPassword,
         settings.Proxy,
         settings.ProxyPort,
         true);
 }
示例#5
0
        private void LoadSettings()
        {
            try
            {
                using (FileStream fs = new FileStream(Resources.settingsFileName, FileMode.Open, FileAccess.Read))
                {
                    XmlSerializer s = null;
                    s = new XmlSerializer(m_settings.GetType());
                    m_settings = (Settings)s.Deserialize(fs);

                    if (!String.IsNullOrEmpty(m_settings.ProxyPassword))
                        m_settings.ProxyPassword = GeneralUtilities.EncDec.Decrypt(m_settings.ProxyPassword, DECRYPTCODE);

                    nextPictureBox.Show();
                    prevPictureBox.Show();
                }
            }
            catch (FieldAccessException ex)
            {
            #if DEBUG
                MessageBox.Show(ex.Message.ToString(), Resources.errorWindowTitle,
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
            #endif
            }
            catch (ArgumentNullException)
            {
                // do nothing
            }
            catch (FileNotFoundException)
            {
                // do nothing
            }
        }
示例#6
0
 /// <summary>
 /// Get comic strip image address from given URL.
 /// </summary>
 /// <param name="url"></param>
 /// <param name="settings"></param>
 /// <returns>Comic strip image URL.</returns>
 public abstract string GetStripAddress(string url, Settings settings);
示例#7
0
 /// <summary>
 /// Get Bit.ly URL for currently selected comic strip.
 /// </summary>
 /// <param name="settings"></param>
 /// <returns>Shortened URL for comic strip.</returns>
 public abstract string GetLinkToStrip(Settings settings);
示例#8
0
 /// <summary>
 /// Load previous comic strip.
 /// </summary>
 /// <param name="settings"></param>
 public abstract void LoadPrevious(Settings settings);
示例#9
0
 /// <summary>
 /// Load next comic strip.
 /// </summary>
 /// <param name="settings"></param>
 public abstract void LoadNext(Settings settings);
示例#10
0
 /// <summary>
 /// Load comic strip for current date.
 /// </summary>
 /// <param name="settings"></param>
 public abstract void LoadCurrent(Settings settings);
示例#11
0
 /// <summary>
 /// Get the date current comic strip.
 /// </summary>
 /// <param name="settings">Program settings.</param>
 /// <returns>DateTime for comic strip.</returns>
 public abstract DateTime GetStripDate(Settings settings);
示例#12
0
 public override void LoadCurrent(Settings settings)
 {
     CurrentImage = GeneralUtilities.Networking.LoadImage(
         GetStripAddress(BaseAddress, settings),
         settings.ProxyUserName,
         settings.ProxyPassword,
         settings.Proxy,
         settings.ProxyPort);
 }
示例#13
0
        public override void LoadPrevious(Settings settings)
        {
            string url = string.Empty;
            string pageSource = GeneralUtilities.Networking.GetPageSource(
                CurrentURL,
                settings.ProxyUserName,
                settings.ProxyPassword,
                settings.Proxy,
                settings.ProxyPort,
                false);

            int index2 = 0, index3 = 0, index4 = 0;

            if (!string.IsNullOrEmpty(pageSource))
            {
                index2 = pageSource.IndexOf("Edellinen", 0, StringComparison.CurrentCulture);
                if (index2 != -1) index3 = pageSource.IndexOf("href=\"", index2 - 100, StringComparison.CurrentCulture);
                if (index3 != -1) index4 = pageSource.IndexOf("\"", index3 + 6, StringComparison.CurrentCulture);
                if (index4 != -1) url = pageSource.Substring(index3 + 6, index4 - index3 - 6);

                if (url.StartsWith("http://", StringComparison.OrdinalIgnoreCase))
                {
                    CurrentURL = url;
                    NewestImage = GeneralUtilities.Networking.LoadImage(
                        GetStripAddress(url, settings),
                        settings.ProxyUserName,
                        settings.ProxyPassword,
                        settings.Proxy,
                        settings.ProxyPort);
                }
            }
        }