Beispiel #1
0
        private void LoadDefault()
        {
            //////////////////////////////////////////////////////////////////////////
            // add whole config value in here!!!
            //////////////////////////////////////////////////////////////////////////

            // basics
            defaultConfig["FirstRun"]             = "True";
            defaultConfig["ShowToolbar"]          = "True";
            defaultConfig["FormWidth"]            = "800";
            defaultConfig["FormHeight"]           = "600";
            defaultConfig["SaveFolder"]           = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures) + "\\" + "ImageRaker";
            defaultConfig["CompareMethod"]        = ImageRakerThumnbnailListViewItemComparer.CompareMethod.ByOriginal.ToString();
            defaultConfig["SortOrder"]            = ImageRakerThumnbnailListViewItemComparer.SortOrder.Ascending.ToString();
            defaultConfig["FileNameMakingMethod"] = FilePathMaker.GetDefaultFileNameMakingMethod().ToString();
            //defaultConfig["Overwrite"] = "True";	// 일반 저장시 파일이 있어도 덮어쓰기
            defaultConfig["HelpAboutAutoSave"] = "True";

            // min image size
            defaultConfig["MinSize"] = "200";

            // performances
            defaultConfig["NumOfThreads"] = "4";

            // thumbnails
            defaultConfig["ThumbnailSize"]    = "180";
            defaultConfig["ThumbnailQuality"] = "High";                 // Low or High

            // features
            defaultConfig["ShowAutoSaveButton"] = "True";                       // instant save and auto save
            defaultConfig["ExitOnComplete"]     = "True";
            defaultConfig["ImproveProgram"]     = "True";
            defaultConfig["MarkFailed"]         = "True";

            // update
            defaultConfig["CheckForUpdate"]        = "True";
            defaultConfig["UpdateLastCheckedDate"] = DateTime.Now.ToShortDateString();

            // block urls
            defaultConfig["UseBlockUrls"]      = "True";
            defaultConfig["MaxNumOfBlockUrls"] = "100";

            // filters
            defaultConfig["JpgFilterChecked"]  = "True";
            defaultConfig["GifFilterChecked"]  = "True";
            defaultConfig["PngFilterChecked"]  = "True";
            defaultConfig["BmpFilterChecked"]  = "True";
            defaultConfig["EtcFilterChecked"]  = "True";
            defaultConfig["ShowSmallsChecked"] = "False";
        }
Beispiel #2
0
        public ImageRaker(string saveFolder, FilePathMaker.FileNameMakingMethod fileNameMakingMethod, SaveType saveType)
        {
            this.saveFolder = saveFolder;
            this.fileNameMakingMethod = fileNameMakingMethod;
            //this.overwrite = overwrite;
            this.saveType = saveType;

            Directory.CreateDirectory(saveFolder);

            filePathMaker = new FilePathMaker(saveFolder);

            Logger.Log("Imageraker created. savefolder: {0}, filenamemakingmethod: {1}",
                        saveFolder, fileNameMakingMethod);
        }
Beispiel #3
0
        public ImageRaker(string saveFolder, FilePathMaker.FileNameMakingMethod fileNameMakingMethod, SaveType saveType)
        {
            this.saveFolder           = saveFolder;
            this.fileNameMakingMethod = fileNameMakingMethod;
            //this.overwrite = overwrite;
            this.saveType = saveType;

            Directory.CreateDirectory(saveFolder);

            filePathMaker = new FilePathMaker(saveFolder);

            Logger.Log("Imageraker created. savefolder: {0}, filenamemakingmethod: {1}",
                       saveFolder, fileNameMakingMethod);
        }
        public ImageRakerDownloadForm(string saveFolder, List<UrlPair> urls,
            FilePathMaker.FileNameMakingMethod fileNameMakingMethod, bool closeOnSucceed, ImageRaker.SaveType saveType)
        {
            InitializeComponent();

            this.saveFolder = saveFolder;
            this.urls = urls;
            this.fileNameMakingMethod = fileNameMakingMethod;
            this.closeOnSucceed = closeOnSucceed;
            //			this.overwrite = overwrite;
            //			this.transparent = transparent;
            this.saveType = saveType;

            messageLabel.Text = "이미지 다운로드 준비 중";
            progressLabel.Text = "0 / 0";
        }
Beispiel #5
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);
            }
        }
Beispiel #6
0
        // returns num of images to save
        public int OnDocumentComplete(IHTMLDocument2 docRoot, ImageRakerDownloadForm.SaveCompleteDelegate saveCompleteDelegate)
        {
            if (docRoot != null)
            {
                // 프레임의 경우 여러 url으로 이루어져있으므로 우선 combined url을 구한다.
                int    numOfDocs   = 0;
                string combinedUrl = GetCombinedUrl(docRoot, out numOfDocs);

                Logger.Log("autosavemanager - doc complete - numofdocs: {0}, combined url: {1}", numOfDocs, combinedUrl);

                // check visited
                if (savedPages.ContainsKey(combinedUrl))
                {
                    // already visited, skip
                    Logger.Warn("already saved in this url: {0}", combinedUrl);

                    // 이미 방문한 경우...
                    saveCompleteDelegate(ImageRakerDownloadForm.SaveCompleteState.AlreadySaved, 0, 0, 0, 0, 0);

                    return(0);
                }

                savedPages.Add(combinedUrl, 0);

                ImgSrcExtractor extractor = new ImgSrcExtractor();
                extractor.Extract(docRoot);
                ImageRakerThumbnailListViewItem[] items = extractor.GetItems();

                ImageSelecter selecter = new ImageSelecter();
                Dictionary <string, string> selected = selecter.AutoSelect(items, items, true);                 // url, referer

                //List<UrlPair> urlpairs = new List<UrlPair>();
                urlPairs.Clear();

                // make url pair
                foreach (KeyValuePair <string, string> sel in selected)
                {
                    string url     = sel.Key;
                    string referer = sel.Value;

                    // check img url duplication
                    if (!savedUrls.ContainsKey(url))
                    {
                        urlPairs.Add(new UrlPair(url, referer));

                        savedUrls.Add(url, 0);
                    }
                }

                if (urlPairs.Count > 0)
                {
                    Logger.Info("auto save manager - starting ir downloadform...");

                    UsageReporter.Instance.FormLoadTime       = -1;
                    UsageReporter.Instance.SaveCountInSession = -1;

                    FilePathMaker.FileNameMakingMethod fileNameMakingMethod = FilePathMaker.GetFileNameMakingMethodFromConfig();

                    downloadForm = new ImageRakerDownloadForm(saveFolder, urlPairs,
                                                              fileNameMakingMethod, true, ImageRaker.SaveType.ByAuto);

//					downloadForm.TopMost = true;	// 사용할 수 없음.
                    downloadForm.WindowState = FormWindowState.Minimized;
//					downloadForm.Opacity = 0.65;
                    downloadForm.StartPosition = FormStartPosition.CenterScreen;
                    downloadForm.SaveComplete += saveCompleteDelegate;

                    downloadForm.Show();

                    Logger.Log("auto save complete asynchronously");

                    return(urlPairs.Count);
                }
                else
                {
                    Logger.Info("nothing to auto save!");

                    saveCompleteDelegate(ImageRakerDownloadForm.SaveCompleteState.NothingToSave, 0, 0, 0, 0, 0);

                    return(0);
                }
            }
            else
            {
                Logger.DLog("invalid doc!");
            }

            return(0);
        }