예제 #1
0
        private void autoSelectButton_Click(object sender, EventArgs e)
        {
            // get displaying items
            List <ImageRakerThumbnailListViewItem> displayingItems = new List <ImageRakerThumbnailListViewItem>();

            foreach (ListViewItem item in thumbnailListView.Items)
            {
                ImageRakerThumbnailListViewItem myitem = item.Tag as ImageRakerThumbnailListViewItem;
                displayingItems.Add(myitem);
            }

            bool ignoreSmall = !showSmallsCheckBox.Checked;

            ImageSelecter selecter = new ImageSelecter();
            Dictionary <string, string> selected = selecter.AutoSelect(imageItems.ToArray(), displayingItems.ToArray(), ignoreSmall);

            // select items
            originallyAutoSelectedImageItems.Clear();

            foreach (ListViewItem item in thumbnailListView.Items)
            {
                ImageRakerThumbnailListViewItem myitem = item.Tag as ImageRakerThumbnailListViewItem;

                if (selected.ContainsKey(myitem.ImageSource))
                {
                    item.Checked = true;

                    originallyAutoSelectedImageItems.Add(myitem);
                }
                else
                {
                    item.Checked = false;
                }
            }
        }
예제 #2
0
        public void Extract(IHTMLDocument2 rootDoc)
        {
            Logger.Log("starting img src extractor...");

            items    = new List <ImageRakerThumbnailListViewItem>();
            imageDic = new Dictionary <string, IHTMLElement>();

            IHTMLDocument2[] docs = GetHtmlDocumentsByOle(rootDoc);
            int index             = 0;

            foreach (IHTMLDocument2 d in docs)
            {
                IHTMLElementCollection images = d.images;

                for (int i = 0; i < images.length; i++)
                {
                    try
                    {
                        ExceptionTester.Instance.Throw("makethumbnail");

                        IHTMLElement elem = images.item(i, i) as IHTMLElement;

                        string src = elem.getAttribute("src", 0).ToString();

                        // 한번 추가된 이미지는 다시 추가하지 않는다.
                        if (!imageDic.ContainsKey(src))
                        {
                            IHTMLElementRender render = elem as IHTMLElementRender;

                            string filename = src.Substring(src.LastIndexOf('/') + 1);
                            int    orgW     = elem.offsetWidth;
                            int    orgH     = elem.offsetHeight;

                            if (orgW == 0 || orgH == 0)
                            {
//								Logger.DLog("	skip image filename {0}. width or height is zero. {1}*{2}", filename, orgW, orgH);
                                continue;
                            }

                            // thumbnail은 null...
                            ImageRakerThumbnailListViewItem item = new ImageRakerThumbnailListViewItem(
                                filename, render, null, orgW, orgH, src, d.url, index++);

                            Logger.DLog("img src extractor - img found - filename: {0}, size: {1}*{2}, url: {3}",
                                        filename, orgW, orgH, src);

                            items.Add(item);
                            imageDic.Add(src, elem);
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.Warn("unknown error in MakeThumbnailListViewImages!");
                    }
                }
            }

            Logger.Info("img src extractor found {0} images", items.Count);
        }
예제 #3
0
        private void GetItems(object x, object y, out ImageRakerThumbnailListViewItem a, out ImageRakerThumbnailListViewItem b)
        {
            ListViewItem a1 = x as ListViewItem;
            ListViewItem b1 = y as ListViewItem;

            ImageRakerThumbnailListViewItem a2 = a1.Tag as ImageRakerThumbnailListViewItem;
            ImageRakerThumbnailListViewItem b2 = b1.Tag as ImageRakerThumbnailListViewItem;

            a = a2;
            b = b2;

            switch (sortOrder)
            {
            case SortOrder.Ascending:
                a = a2;
                b = b2;
                break;

            case SortOrder.Descending:
                a = b2;
                b = a2;
                break;
            }
        }
예제 #4
0
        private void saveButton_Click(object sender, EventArgs e)
        {
            string saveFolder = Config.Instance.GetConfig("SaveFolder");

            /*
             * save by gdi+
             * 모니터 해상도 크기 이상의 이미지는 저장되지 않는다.
             */

            /*
             * Logger.Log("save images by gdi+");
             * Stopwatch sw = new Stopwatch();
             * sw.Start();
             *
             * FilePathMaker filePathMaker = new FilePathMaker(saveFolder);
             *
             * foreach(ListViewItem item in thumbnailListView.CheckedItems)
             * {
             *      ImageRakerThumbnailListViewItem myitem = item.Tag as ImageRakerThumbnailListViewItem;
             *      //string src = myitem.ImageSource;
             *      //string referer = myitem.RefererUrl;
             *
             *      //urls.Add(new UrlPair(src, referer));
             *
             *      using (Bitmap originalBitmap = new Bitmap(myitem.Width, myitem.Height))
             *      {
             *              using (Graphics g = Graphics.FromImage(originalBitmap))
             *              {
             *                      myitem.Render.DrawToDC(g.GetHdc());
             *              }
             *
             *              Logger.DLog("    save to file: {0} * {1}, url: {2}", myitem.Width, myitem.Height, myitem.ImageSource);
             *
             *              string filepath = filePathMaker.MakeFilePath(myitem.ImageSource, fileNameMakingMethod);
             *
             *              originalBitmap.Save(filepath);
             *      }
             * }
             *
             * sw.Stop();
             * Logger.Log("save images by gdi+ DONE - elapsed: {0}", sw.ElapsedMilliseconds);
             *
             * return;
             */

            // 자동선택됐지만 선택 해제된 아이템들을 블럭. 다시 선택된 애들은 블럭 리스트에서 삭제.
            // 최초 저장시만 사용한다. 두번째 저장부터는 실패한 것일 수 있음.
            if (Config.Instance.GetConfigBool("UseBlockUrls") && saveCount == 0)
            {
                Dictionary <string, long> blockUrls = Config.Instance.GetBlockUrls();
                bool blockUrlsChanged = false;

                foreach (ImageRakerThumbnailListViewItem autoitem in originallyAutoSelectedImageItems)
                {
                    string autourl = autoitem.ImageSource;

                    foreach (ListViewItem item in thumbnailListView.Items)
                    {
                        ImageRakerThumbnailListViewItem myitem = item.Tag as ImageRakerThumbnailListViewItem;

                        if (myitem.ImageSource == autourl)
                        {
                            if (item.Checked == false)
                            {
                                if (!blockUrls.ContainsKey(autourl))
                                {
                                    Logger.DLog("auto selected but unchecked, not added in blocks yet: {0}, ADD TO BLOCK URLS", autourl);

                                    Config.Instance.AddBlockUrl(autourl);
                                    blockUrlsChanged = true;
                                }
                            }
                            else
                            {
                                if (blockUrls.ContainsKey(autourl))
                                {
                                    Logger.DLog("originally auto selected, blocked, but checked again: {0}, REMOVE FROM BLOCK URLS", autourl);

                                    Config.Instance.RemoveBlockUrl(autourl);
                                    blockUrlsChanged = true;
                                }
                            }
                        }
                    }
                }

                if (blockUrlsChanged)
                {
                    Config.Instance.SaveBlockUrls();
                }
            }

            ExceptionTester.Instance.Throw("random_save1");

            // extract urls to save
            List <UrlPair> urls = new List <UrlPair>();

            foreach (ListViewItem item in thumbnailListView.CheckedItems)
            {
                ImageRakerThumbnailListViewItem myitem = item.Tag as ImageRakerThumbnailListViewItem;
                string src     = myitem.ImageSource;
                string referer = myitem.RefererUrl;

                urls.Add(new UrlPair(src, referer));
            }

            // determine selected file name making method
            //FilePathMaker.FileNameMakingMethod fileNameMakingMethod = FilePathMaker.FileNameMakingMethod.FullUrl;
            FilePathMaker.FileNameMakingMethod fileNameMakingMethod = FilePathMaker.GetFileNameMakingMethodFromConfig();
            bool exitOnComplete = Config.Instance.GetConfigBool("ExitOnComplete");

//			bool overwrite = Config.Instance.GetConfigBool("Overwrite");

            UsageReporter.Instance.SaveCountInSession = saveCount++;

            ExceptionTester.Instance.Throw("random_save2");

            ImageRaker.SaveType saveType = ImageRaker.SaveType.ByForm;

            if (instantMode)
            {
                saveType = ImageRaker.SaveType.ByInstant;
            }

            ImageRakerDownloadForm form = new ImageRakerDownloadForm(saveFolder, urls,
                                                                     fileNameMakingMethod, exitOnComplete, saveType);

            DialogResult result = form.ShowDialog();

            ExceptionTester.Instance.Throw("random_save3");

            if (result != DialogResult.Abort)
            {
                bool failed = false;

                // 실패한 이미지 체크 기능
                if (Config.Instance.GetConfigBool("MarkFailed") == true)
                {
                    // reset checked first
                    deselectAllButton.PerformClick();

                    // check on failed urls
                    Logger.Log("check on failed urls...");

                    foreach (UrlPair url in urls)
                    {
                        if (url.Result == UrlPair.SaveResult.Failed ||
                            url.Result == UrlPair.SaveResult.Duplicated)
                        {
                            foreach (ListViewItem item in thumbnailListView.Items)
                            {
                                ImageRakerThumbnailListViewItem myitem = item.Tag as ImageRakerThumbnailListViewItem;

                                if (myitem.ImageSource == url.Url)
                                {
                                    failed       = true;
                                    item.Checked = true;
                                }
                            }
                        }
                    }
                }

                // exit when exit on complete enabled.
                if (!failed && (exitOnComplete && (result == DialogResult.OK || result == DialogResult.Cancel)))
                {
                    // exit the program
                    this.Close();
                }
            }
            else
            {
                Logger.Warn("cannot start downloader! reason: {0}", form.ExceptionMessage);
                Message.Warn("이미지 레이커 다운로더를 실행할 수 없습니다.\n" + form.ExceptionMessage);

                //MessageBox.Show("이미지 레이커 다운로더를 실행할 수 없습니다.\n" + form.ExceptionMessage,
                //    About.AppName, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void GetItems(object x, object y, out ImageRakerThumbnailListViewItem a, out ImageRakerThumbnailListViewItem b)
        {
            ListViewItem a1 = x as ListViewItem;
            ListViewItem b1 = y as ListViewItem;

            ImageRakerThumbnailListViewItem a2 = a1.Tag as ImageRakerThumbnailListViewItem;
            ImageRakerThumbnailListViewItem b2 = b1.Tag as ImageRakerThumbnailListViewItem;

            a = a2;
            b = b2;

            switch (sortOrder)
            {
                case SortOrder.Ascending:
                    a = a2;
                    b = b2;
                    break;

                case SortOrder.Descending:
                    a = b2;
                    b = a2;
                    break;
            }
        }
예제 #6
0
        public void Extract(IHTMLDocument2 rootDoc)
        {
            Logger.Log("starting img src extractor...");

            items = new List<ImageRakerThumbnailListViewItem>();
            imageDic = new Dictionary<string, IHTMLElement>();

            IHTMLDocument2[] docs = GetHtmlDocumentsByOle(rootDoc);
            int index = 0;

            foreach (IHTMLDocument2 d in docs)
            {
                IHTMLElementCollection images = d.images;

                for (int i = 0; i < images.length; i++)
                {
                    try
                    {
                        ExceptionTester.Instance.Throw("makethumbnail");

                        IHTMLElement elem = images.item(i, i) as IHTMLElement;

                        string src = elem.getAttribute("src", 0).ToString();

                        // 한번 추가된 이미지는 다시 추가하지 않는다.
                        if (!imageDic.ContainsKey(src))
                        {
                            IHTMLElementRender render = elem as IHTMLElementRender;

                            string filename = src.Substring(src.LastIndexOf('/') + 1);
                            int orgW = elem.offsetWidth;
                            int orgH = elem.offsetHeight;

                            if (orgW == 0 || orgH == 0)
                            {
            //								Logger.DLog("	skip image filename {0}. width or height is zero. {1}*{2}", filename, orgW, orgH);
                                continue;
                            }

                            // thumbnail은 null...
                            ImageRakerThumbnailListViewItem item = new ImageRakerThumbnailListViewItem(
                                filename, render, null, orgW, orgH, src, d.url, index++);

                            Logger.DLog("img src extractor - img found - filename: {0}, size: {1}*{2}, url: {3}",
                                filename, orgW, orgH, src);

                            items.Add(item);
                            imageDic.Add(src, elem);
                        }

                    }
                    catch (Exception ex)
                    {
                        Logger.Warn("unknown error in MakeThumbnailListViewImages!");
                    }
                }
            }

            Logger.Info("img src extractor found {0} images", items.Count);
        }