Example #1
0
        /// <summary>
        /// Searches the cache description for HTML IMG tags and downloads the file
        /// to the local file system
        /// </summary>
        public void GrabImages()
        {
            string baseURL = String.Empty;

            if (m_cache.URL != null)
            {
                baseURL = m_cache.URL.Scheme + "://" + m_cache.URL.Host;
            }
            const string    IMG     = "(<[Ii][Mm][Gg])([^sS][^rR]*)([Ss][Rr][Cc]\\s?=\\s?)\"([^\"]*)\"([^>]*>)";
            MatchCollection matches = Regex.Matches(m_Win.CacheList.SelectedCache.LongDesc, IMG);

            if (matches.Count == 0)
            {
                MessageDialog mdlg = new MessageDialog(null, DialogFlags.Modal, MessageType.Info, ButtonsType.Ok, Catalog.GetString("No Images Found."));
                mdlg.Run();
                mdlg.Hide();
                return;
            }

            List <string> files        = new List <string>();
            string        imagesFolder = GetImagesFolder();

            if (!Directory.Exists(imagesFolder))
            {
                Directory.CreateDirectory(imagesFolder);
            }

            foreach (Match match in matches)
            {
                string url = match.Groups[4].Value;
                if (!url.Contains("://"))
                {
                    if (url.StartsWith("/"))
                    {
                        url = baseURL + url;
                    }
                    else
                    {
                        url = baseURL + "/" + url;
                    }
                }
                files.Add(url);
            }

            FileDownloadProgress dlg = new FileDownloadProgress();

            dlg.Icon = m_Win.Icon;
            dlg.Start(files, imagesFolder);
            SetCache(m_Win.CacheList.SelectedCache);
        }
        protected virtual void OnGrabImagesClick(object sender, System.EventArgs e)
        {
            const string IMG = "(<[Ii][Mm][Gg])([^sS][^rR]*)([Ss][Rr][Cc]\\s?=\\s?)\"([^\"]*)\"([^>]*>)";
            MatchCollection matches = Regex.Matches(m_monitor.SelectedCache.LongDesc, IMG);
            if (matches.Count == 0)
            {
                MessageDialog mdlg = new MessageDialog(null, DialogFlags.Modal, MessageType.Info, ButtonsType.Ok, Catalog.GetString("No Images Found."));
                mdlg.Run();
                mdlg.Hide();
                return;
            }

            List<string> files = new List<string>();
            string imagesFolder = GetImagesFolder();
            if (!Directory.Exists(imagesFolder))
                Directory.CreateDirectory(imagesFolder);
            foreach(Match match in matches)
            {
                files.Add(match.Groups[4].Value);
            }

            FileDownloadProgress dlg = new FileDownloadProgress();
            dlg.Start(files, imagesFolder);
            UpdateCaceheInfo();
        }
        public void GrabImagesMulti()
        {
            string baseURL = String.Empty;
            Dictionary<string,string[]> files = new Dictionary<string,string[]>();
            foreach(Geocache cache in CacheList.UnfilteredCaches)
            {
                ScanForImages (files,cache);
            }
            if (files.Count <=0)
            {
                MessageDialog mdlg = new MessageDialog(null, DialogFlags.Modal, MessageType.Info, ButtonsType.Ok, Catalog.GetString("No Images Found."));
                mdlg.Run();
                mdlg.Hide();
                return;
            }

            FileDownloadProgress dlg = new FileDownloadProgress();
            dlg.Icon = this.Icon;
            dlg.Start(files);
            CacheInfo.SetCache(CacheList.SelectedCache);
        }
        /// <summary>
        /// Searches the cache description for HTML IMG tags and downloads the file
        /// to the local file system
        /// </summary>
        public void GrabImages()
        {
            string baseURL = String.Empty;
            if (m_cache.URL != null)
                baseURL = m_cache.URL.Scheme + "://" + m_cache.URL.Host;
            const string IMG = "(<[Ii][Mm][Gg])([^sS][^rR]*)([Ss][Rr][Cc]\\s?=\\s?)\"([^\"]*)\"([^>]*>)";
            MatchCollection matches = Regex.Matches(m_Win.CacheList.SelectedCache.LongDesc, IMG);
            if (matches.Count == 0)
            {
                MessageDialog mdlg = new MessageDialog(null, DialogFlags.Modal, MessageType.Info, ButtonsType.Ok, Catalog.GetString("No Images Found."));
                mdlg.Run();
                mdlg.Hide();
                return;
            }

            List<string> files = new List<string>();
            string imagesFolder = GetImagesFolder();
            if (!Directory.Exists(imagesFolder))
                Directory.CreateDirectory(imagesFolder);

            foreach(Match match in matches)
            {
                string url = match.Groups[4].Value;
                if (!url.Contains("://"))
                {
                    if (url.StartsWith("/"))
                        url = baseURL + url;
                    else
                        url = baseURL + "/" + url;
                }
                files.Add(url);
            }

            FileDownloadProgress dlg = new FileDownloadProgress();
            dlg.Icon = m_Win.Icon;
            dlg.Start(files, imagesFolder);
            SetCache(m_Win.CacheList.SelectedCache);
        }