diff --git a/Tumbl Tool/Common Helpers/FileHelper.cs b/Tumbl Tool/Common Helpers/FileHelper.cs index b1cb5f1..7d3e6a3 100644 --- a/Tumbl Tool/Common Helpers/FileHelper.cs +++ b/Tumbl Tool/Common Helpers/FileHelper.cs @@ -63,7 +63,7 @@ public static List getImageListFromDir(string location) public static string findFile(string dir, string name) { - return Directory.GetFiles(@dir, name + ".*").First(); + return Directory.GetFiles(@dir, name + ".*").FirstOrDefault(); } public static bool isFileInUse(FileInfo file) diff --git a/Tumbl Tool/Common Helpers/ImageHelper.cs b/Tumbl Tool/Common Helpers/ImageHelper.cs index d5b8664..4f2a707 100644 --- a/Tumbl Tool/Common Helpers/ImageHelper.cs +++ b/Tumbl Tool/Common Helpers/ImageHelper.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Drawing; using System.Drawing.Imaging; using System.IO; @@ -9,60 +8,6 @@ namespace Tumblr_Tool.Common_Helpers { public static class ImageHelper { - public static ImageFormat GetImageFormat(this Image img) - { - if (img.RawFormat.Equals(ImageFormat.Jpeg)) - { - img.Dispose(); - return ImageFormat.Jpeg; - } - if (img.RawFormat.Equals(ImageFormat.Bmp)) - { - img.Dispose(); - return ImageFormat.Bmp; - } - if (img.RawFormat.Equals(ImageFormat.Png)) - { - img.Dispose(); - return ImageFormat.Png; - } - if (img.RawFormat.Equals(ImageFormat.Emf)) - { - img.Dispose(); - return ImageFormat.Emf; - } - if (img.RawFormat.Equals(ImageFormat.Exif)) - { - img.Dispose(); - return ImageFormat.Exif; - } - if (img.RawFormat.Equals(ImageFormat.Gif)) - { - img.Dispose(); - return ImageFormat.Gif; - } - if (img.RawFormat.Equals(ImageFormat.Icon)) - { - img.Dispose(); - return ImageFormat.Icon; - } - if (img.RawFormat.Equals(ImageFormat.MemoryBmp)) - { - img.Dispose(); - return ImageFormat.MemoryBmp; - } - if (img.RawFormat.Equals(ImageFormat.Tiff)) - { - img.Dispose(); - return ImageFormat.Tiff; - } - else - { - img.Dispose(); - return ImageFormat.Wmf; - } - } - public static void addImageDescription(string path, string desc) { string _FileDirectory = Path.GetDirectoryName(path); @@ -79,55 +24,46 @@ public static void addImageDescription(string path, string desc) Image newImage; bool added = false; ImageFormat imageFormat = ImageFormat.Jpeg; + string _mimeType = ""; + string filePath = path; - if (_FileExt == null || _FileExt == "") + if (_FileExt == null || _FileExt == "") { - string filePath = FileHelper.findFile(_FileDirectory, _FileName); - - if (File.Exists(filePath)) - { - path = filePath; - _FileName = Path.GetFileNameWithoutExtension(filePath); - _FileExt = Path.GetExtension(filePath); - imageFormat = GetImageFormat(Image.FromFile(path)); - } - + filePath = FileHelper.findFile(_FileDirectory, _FileName); } - - string _mimeType = imageFormat.ToString(); - - if (File.Exists(path)) + if (!string.IsNullOrEmpty(filePath)) { - while (!added) + if (File.Exists(filePath)) { - try + path = filePath; + _FileName = Path.GetFileNameWithoutExtension(filePath); + _FileExt = Path.GetExtension(filePath); + imageFormat = GetImageFormat(Image.FromFile(path)); + + _mimeType = imageFormat.ToString(); + + while (!added) { - using (Stream fileStream = new System.IO.FileStream(path, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite)) + try { - originalImage = File.Exists(path) ? new FileInfo(path) : null; - if (File.Exists(tempLocation)) - File.Delete(tempLocation); + using (Stream fileStream = new System.IO.FileStream(path, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite)) + { + originalImage = File.Exists(path) ? new FileInfo(path) : null; + if (File.Exists(tempLocation)) + File.Delete(tempLocation); - originalImage.CopyTo(tempLocation, true); - tempImage = new FileInfo(tempLocation); - newImage = Image.FromStream(fileStream); - fileStream.Seek(0, SeekOrigin.Begin); + originalImage.CopyTo(tempLocation, true); + tempImage = new FileInfo(tempLocation); + newImage = Image.FromStream(fileStream); + fileStream.Seek(0, SeekOrigin.Begin); - switch (_mimeType) //find mime type of image based on extension - { - case "Jpeg": - try - { - _decoder = new JpegBitmapDecoder(fileStream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad); - _encoder = new JpegBitmapEncoder(); - } - catch - { + switch (_mimeType) //find mime type of image based on extension + { + case "Jpeg": try { - fileStream.Seek(0, SeekOrigin.Begin); - _decoder = new JpegBitmapDecoder(fileStream, BitmapCreateOptions.IgnoreColorProfile, BitmapCacheOption.OnLoad); + _decoder = new JpegBitmapDecoder(fileStream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad); _encoder = new JpegBitmapEncoder(); } catch @@ -135,39 +71,39 @@ public static void addImageDescription(string path, string desc) try { fileStream.Seek(0, SeekOrigin.Begin); - _decoder = new PngBitmapDecoder(fileStream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad); - _encoder = new PngBitmapEncoder(); + _decoder = new JpegBitmapDecoder(fileStream, BitmapCreateOptions.IgnoreColorProfile, BitmapCacheOption.OnLoad); + _encoder = new JpegBitmapEncoder(); } catch { try { fileStream.Seek(0, SeekOrigin.Begin); - _decoder = new PngBitmapDecoder(fileStream, BitmapCreateOptions.IgnoreColorProfile, BitmapCacheOption.OnLoad); + _decoder = new PngBitmapDecoder(fileStream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad); _encoder = new PngBitmapEncoder(); } catch { - _decoder = null; - added = true; + try + { + fileStream.Seek(0, SeekOrigin.Begin); + _decoder = new PngBitmapDecoder(fileStream, BitmapCreateOptions.IgnoreColorProfile, BitmapCacheOption.OnLoad); + _encoder = new PngBitmapEncoder(); + } + catch + { + _decoder = null; + added = true; + } } } } - } - break; + break; - case "Png": - try - { - _decoder = new PngBitmapDecoder(fileStream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad); - _encoder = new PngBitmapEncoder(); - } - catch - { + case "Png": try { - fileStream.Seek(0, SeekOrigin.Begin); - _decoder = new PngBitmapDecoder(fileStream, BitmapCreateOptions.IgnoreColorProfile, BitmapCacheOption.OnLoad); + _decoder = new PngBitmapDecoder(fileStream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad); _encoder = new PngBitmapEncoder(); } catch @@ -175,91 +111,154 @@ public static void addImageDescription(string path, string desc) try { fileStream.Seek(0, SeekOrigin.Begin); - _decoder = new JpegBitmapDecoder(fileStream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad); - _encoder = new JpegBitmapEncoder(); + _decoder = new PngBitmapDecoder(fileStream, BitmapCreateOptions.IgnoreColorProfile, BitmapCacheOption.OnLoad); + _encoder = new PngBitmapEncoder(); } catch { try { fileStream.Seek(0, SeekOrigin.Begin); - _decoder = new JpegBitmapDecoder(fileStream, BitmapCreateOptions.IgnoreColorProfile, BitmapCacheOption.OnLoad); + _decoder = new JpegBitmapDecoder(fileStream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad); _encoder = new JpegBitmapEncoder(); } catch { - _decoder = null; - added = true; + try + { + fileStream.Seek(0, SeekOrigin.Begin); + _decoder = new JpegBitmapDecoder(fileStream, BitmapCreateOptions.IgnoreColorProfile, BitmapCacheOption.OnLoad); + _encoder = new JpegBitmapEncoder(); + } + catch + { + _decoder = null; + added = true; + } } } } - } - break; + break; - default: // Not jpeg or png file - dont add the comments - _decoder = null; - added = true; - break; + default: // Not jpeg or png file - dont add the comments + _decoder = null; + added = true; + break; + } } - } - if (_decoder != null && desc != null) - { - _metadata = (BitmapMetadata)_decoder.Frames[0].Metadata.Clone(); - - if (_mimeType == "Jpeg") - { - _metadata.Comment = desc; - _metadata.SetQuery("/xmp/dc:description", desc); - } - else if (_mimeType == "Png") + if (_decoder != null && desc != null) { - _metadata.SetQuery("/xmp/dc:description", desc); - } - - _fileFrame = BitmapFrame.Create(_decoder.Frames[0], _decoder.Frames[0].Thumbnail, _metadata, _decoder.Frames[0].ColorContexts); - _encoder.Frames.Add(_fileFrame); + _metadata = (BitmapMetadata)_decoder.Frames[0].Metadata.Clone(); - using (Stream fileStreamOut = new FileStream(path, FileMode.Create)) - { - try + if (_mimeType == "Jpeg") { - if (_encoder != null) - _encoder.Save(fileStreamOut); + _metadata.Comment = desc; + _metadata.SetQuery("/xmp/dc:description", desc); } - catch + else if (_mimeType == "Png") + { + _metadata.SetQuery("/xmp/dc:description", desc); + } + + _fileFrame = BitmapFrame.Create(_decoder.Frames[0], _decoder.Frames[0].Thumbnail, _metadata, _decoder.Frames[0].ColorContexts); + _encoder.Frames.Add(_fileFrame); + + using (Stream fileStreamOut = new FileStream(path, FileMode.Create)) { try { - fileStreamOut.Close(); - tempImage.CopyTo(path, true); - - added = true; + if (_encoder != null) + _encoder.Save(fileStreamOut); } catch { + try + { + fileStreamOut.Close(); + tempImage.CopyTo(path, true); + + added = true; + } + catch + { + } } } + added = true; } added = true; + File.Delete(tempLocation); + } + catch (NotSupportedException) + { + added = true; + } + catch (FileFormatException) + { + added = true; + } + catch (IOException) + { + added = false; } - added = true; - File.Delete(tempLocation); - } - catch (NotSupportedException) - { - added = true; - } - catch (FileFormatException) - { - added = true; - } - catch (IOException) - { - added = false; } } } } + + public static ImageFormat GetImageFormat(this Image img) + { + if (img.RawFormat.Equals(ImageFormat.Jpeg)) + { + img.Dispose(); + return ImageFormat.Jpeg; + } + if (img.RawFormat.Equals(ImageFormat.Bmp)) + { + img.Dispose(); + return ImageFormat.Bmp; + } + if (img.RawFormat.Equals(ImageFormat.Png)) + { + img.Dispose(); + return ImageFormat.Png; + } + if (img.RawFormat.Equals(ImageFormat.Emf)) + { + img.Dispose(); + return ImageFormat.Emf; + } + if (img.RawFormat.Equals(ImageFormat.Exif)) + { + img.Dispose(); + return ImageFormat.Exif; + } + if (img.RawFormat.Equals(ImageFormat.Gif)) + { + img.Dispose(); + return ImageFormat.Gif; + } + if (img.RawFormat.Equals(ImageFormat.Icon)) + { + img.Dispose(); + return ImageFormat.Icon; + } + if (img.RawFormat.Equals(ImageFormat.MemoryBmp)) + { + img.Dispose(); + return ImageFormat.MemoryBmp; + } + if (img.RawFormat.Equals(ImageFormat.Tiff)) + { + img.Dispose(); + return ImageFormat.Tiff; + } + else + { + img.Dispose(); + return ImageFormat.Wmf; + } + } } } \ No newline at end of file diff --git a/Tumblr Tool UI/Form1.Designer.cs b/Tumblr Tool UI/Form1.Designer.cs index 8cabe82..4794369 100644 --- a/Tumblr Tool UI/Form1.Designer.cs +++ b/Tumblr Tool UI/Form1.Designer.cs @@ -36,6 +36,7 @@ private void InitializeComponent() this.txt_WorkStatus = new System.Windows.Forms.TextBox(); this.btn_Crawl = new System.Windows.Forms.Button(); this.btn_Browse = new System.Windows.Forms.Button(); + this.img_DisplayImage = new System.Windows.Forms.PictureBox(); this.txt_TumblrURL = new System.Windows.Forms.TextBox(); this.lbl_TumblrURL = new System.Windows.Forms.Label(); this.txt_SaveLocation = new System.Windows.Forms.TextBox(); @@ -93,15 +94,14 @@ private void InitializeComponent() this.getStatsUI_Worker = new System.ComponentModel.BackgroundWorker(); this.fileBackgroundWorker = new System.ComponentModel.BackgroundWorker(); this.lbl_PercentBar = new System.Windows.Forms.Label(); - this.img_DisplayImage = new System.Windows.Forms.PictureBox(); this.tabControl_Main.SuspendLayout(); this.tab_ImageRipper.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.img_DisplayImage)).BeginInit(); this.tab_TumblrStats.SuspendLayout(); this.box_PostStats.SuspendLayout(); this.box_BlogInfo.SuspendLayout(); this.menu_TopMenu.SuspendLayout(); this.status_Strip.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.img_DisplayImage)).BeginInit(); this.SuspendLayout(); // // tabControl_Main @@ -209,6 +209,25 @@ private void InitializeComponent() this.btn_Browse.UseVisualStyleBackColor = true; this.btn_Browse.Click += new System.EventHandler(this.btn_Browse_Click); // + // img_DisplayImage + // + this.img_DisplayImage.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.img_DisplayImage.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.img_DisplayImage.Cursor = System.Windows.Forms.Cursors.Default; + this.img_DisplayImage.ErrorImage = global::Tumblr_Tool.Properties.Resources.Tumblr_logo_by_x_1337_x_d5ikwpp; + this.img_DisplayImage.Image = global::Tumblr_Tool.Properties.Resources.Tumblr_logo_by_x_1337_x_d5ikwpp; + this.img_DisplayImage.InitialImage = null; + this.img_DisplayImage.Location = new System.Drawing.Point(226, 79); + this.img_DisplayImage.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.img_DisplayImage.Name = "img_DisplayImage"; + this.img_DisplayImage.Size = new System.Drawing.Size(183, 243); + this.img_DisplayImage.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; + this.img_DisplayImage.TabIndex = 4; + this.img_DisplayImage.TabStop = false; + this.img_DisplayImage.LoadCompleted += new System.ComponentModel.AsyncCompletedEventHandler(this.imageLoaded); + // // txt_TumblrURL // this.txt_TumblrURL.BackColor = System.Drawing.SystemColors.Control; @@ -643,7 +662,7 @@ private void InitializeComponent() // aboutToolStripMenuItem // this.aboutToolStripMenuItem.Name = "aboutToolStripMenuItem"; - this.aboutToolStripMenuItem.Size = new System.Drawing.Size(152, 22); + this.aboutToolStripMenuItem.Size = new System.Drawing.Size(113, 22); this.aboutToolStripMenuItem.Text = "About"; this.aboutToolStripMenuItem.Click += new System.EventHandler(this.aboutToolStripMenuItem_Click); // @@ -688,7 +707,7 @@ private void InitializeComponent() // toolStripStatusLabel1 // this.toolStripStatusLabel1.Name = "toolStripStatusLabel1"; - this.toolStripStatusLabel1.Size = new System.Drawing.Size(221, 22); + this.toolStripStatusLabel1.Size = new System.Drawing.Size(137, 22); this.toolStripStatusLabel1.Spring = true; // // lbl_PostCount @@ -696,15 +715,16 @@ private void InitializeComponent() this.lbl_PostCount.AutoSize = false; this.lbl_PostCount.Font = new System.Drawing.Font("Century Gothic", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.lbl_PostCount.Name = "lbl_PostCount"; - this.lbl_PostCount.Size = new System.Drawing.Size(221, 22); + this.lbl_PostCount.Size = new System.Drawing.Size(137, 22); this.lbl_PostCount.Spring = true; this.lbl_PostCount.Text = "[Post Count]"; // // lbl_Timer // this.lbl_Timer.Name = "lbl_Timer"; - this.lbl_Timer.Size = new System.Drawing.Size(147, 22); + this.lbl_Timer.Size = new System.Drawing.Size(137, 22); this.lbl_Timer.Spring = true; + this.lbl_Timer.Text = "[Timer]"; this.lbl_Timer.Visible = false; // // lbl_Size @@ -750,25 +770,6 @@ private void InitializeComponent() this.lbl_PercentBar.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; this.lbl_PercentBar.Visible = false; // - // img_DisplayImage - // - this.img_DisplayImage.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.img_DisplayImage.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.img_DisplayImage.Cursor = System.Windows.Forms.Cursors.Default; - this.img_DisplayImage.ErrorImage = global::Tumblr_Tool.Properties.Resources.Tumblr_logo_by_x_1337_x_d5ikwpp; - this.img_DisplayImage.Image = global::Tumblr_Tool.Properties.Resources.Tumblr_logo_by_x_1337_x_d5ikwpp; - this.img_DisplayImage.InitialImage = null; - this.img_DisplayImage.Location = new System.Drawing.Point(226, 79); - this.img_DisplayImage.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); - this.img_DisplayImage.Name = "img_DisplayImage"; - this.img_DisplayImage.Size = new System.Drawing.Size(183, 243); - this.img_DisplayImage.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; - this.img_DisplayImage.TabIndex = 4; - this.img_DisplayImage.TabStop = false; - this.img_DisplayImage.LoadCompleted += new System.ComponentModel.AsyncCompletedEventHandler(this.imageLoaded); - // // mainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 16F); @@ -796,6 +797,7 @@ private void InitializeComponent() this.tabControl_Main.ResumeLayout(false); this.tab_ImageRipper.ResumeLayout(false); this.tab_ImageRipper.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.img_DisplayImage)).EndInit(); this.tab_TumblrStats.ResumeLayout(false); this.tab_TumblrStats.PerformLayout(); this.box_PostStats.ResumeLayout(false); @@ -806,7 +808,6 @@ private void InitializeComponent() this.menu_TopMenu.PerformLayout(); this.status_Strip.ResumeLayout(false); this.status_Strip.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)(this.img_DisplayImage)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); diff --git a/Tumblr Tool UI/Form1.cs b/Tumblr Tool UI/Form1.cs index 9a0fe79..909b6e8 100644 --- a/Tumblr Tool UI/Form1.cs +++ b/Tumblr Tool UI/Form1.cs @@ -36,10 +36,13 @@ public partial class mainForm : Form private TumblrStats tumblrStats; private string version = "Beta 0.14.1127"; + private TimeSpan ts; + public mainForm() { InitializeComponent(); txt_WorkStatus.Visible = false; + lbl_Timer.Text = ""; bar_Progress.Visible = false; fileManager = new FileManager(); @@ -62,6 +65,7 @@ public mainForm(string file) { InitializeComponent(); txt_WorkStatus.Visible = false; + lbl_Timer.Text = ""; lbl_Size.Text = ""; lbl_PostCount.Text = ""; bar_Progress.Visible = false; @@ -165,84 +169,15 @@ private void btn_Crawl_Click(object sender, EventArgs e) ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10); - lbl_Timer.Text = elapsedTime; + this.Invoke((MethodInvoker)delegate + { + lbl_Timer.Text = elapsedTime; + }); if (checkFields()) { - updateStatusText("Initializing ..."); - updateWorkStatusText("Initializing ... "); - updateWorkStatusText("Checking for internet connection ..."); - if (WebHelper.CheckForInternetConnection()) - { - updateWorkStatusText("Internet Connection found ..."); - updateWorkStatusText("Getting Blog info ..."); - tumblrBlog = new Tumblr(); - tumblrBlog.cname = txt_TumblrURL.Text; - ts = stopWatch.Elapsed; + crawl_Worker.RunWorkerAsync(ripper); - // Format and display the TimeSpan value. - elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", - ts.Hours, ts.Minutes, ts.Seconds, - ts.Milliseconds / 10); - - lbl_Timer.Text = elapsedTime; - - ripper = new ImageRipper(tumblrBlog, txt_SaveLocation.Text, optionsForm.parsePhotoSets, optionsForm.parseJPEG, optionsForm.parsePNG, optionsForm.parseGIF, 0); - - if (ripper != null) - { - ripper.setAPIMode(options.apiMode); - ripper.setLogFile(logFile); - - if (ripper.setBlogInfo()) - { - ts = stopWatch.Elapsed; - - // Format and display the TimeSpan value. - elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", - ts.Hours, ts.Minutes, ts.Seconds, - ts.Milliseconds / 10); - - lbl_Timer.Text = elapsedTime; - lbl_PostCount.Text = "0 / 0"; - lbl_PostCount.Visible = false; - txt_WorkStatus.Visible = true; - - txt_WorkStatus.SelectionStart = txt_WorkStatus.Text.Length; - - if (saveFile == null && !saveTumblrFile(ripper.blog.name)) - { - updateWorkStatusText("Unable to save .tumblr file"); - updateStatusText("Error"); - } - else - { - crawl_Worker.RunWorkerAsync(ripper); - - crawl_UpdateUI_Worker.RunWorkerAsync(ripper); - } - } - else - { - updateStatusText("Error"); - updateWorkStatusText("Invalid Tumblr URL: " + txt_TumblrURL.Text); - btn_Crawl.Enabled = true; - lbl_PostCount.Visible = false; - bar_Progress.Visible = false; - img_DisplayImage.Visible = false; - tab_TumblrStats.Enabled = true; - } - } - } - else - { - updateStatusText("Error"); - updateWorkStatusText("No internet connection detected!"); - btn_Crawl.Enabled = true; - lbl_PostCount.Visible = false; - bar_Progress.Visible = false; - img_DisplayImage.Visible = false; - tab_TumblrStats.Enabled = true; - } + crawl_UpdateUI_Worker.RunWorkerAsync(ripper); } else { @@ -257,6 +192,7 @@ private void btn_Crawl_Click(object sender, EventArgs e) private void btn_GetStats_Click(object sender, EventArgs e) { lbl_PostCount.Visible = false; + updateStatusText("Initiliazing..."); if (isValidURL(txt_StatsTumblrURL.Text)) { if (WebHelper.CheckForInternetConnection()) @@ -403,6 +339,11 @@ private void crawlUIWorker_AfterDone(object sender, RunWorkerCompletedEventArgs private void crawlUIWorker_DoWork(object sender, DoWorkEventArgs e) { + while (ripper == null) + { + + } + if (ripper != null) { this.Invoke((MethodInvoker)delegate @@ -413,6 +354,7 @@ private void crawlUIWorker_DoWork(object sender, DoWorkEventArgs e) bar_Progress.Maximum = 100; bar_Progress.Visible = true; lbl_PostCount.Visible = true; + // lbl_Timer.Visible = true; lbl_PostCount.Text = ""; updateWorkStatusText("Indexing Blog ..."); @@ -430,7 +372,10 @@ private void crawlUIWorker_DoWork(object sender, DoWorkEventArgs e) ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10); - lbl_Timer.Text = elapsedTime; + this.Invoke((MethodInvoker)delegate + { + lbl_Timer.Text = elapsedTime; + }); if (ripper.statusCode == postProcessingCodes.Started) { this.Invoke((MethodInvoker)delegate @@ -461,6 +406,7 @@ private void crawlUIWorker_DoWork(object sender, DoWorkEventArgs e) updateStatusText("Crawling..."); // lbl_PostCount.Visible = true; lbl_PercentBar.Visible = true; + lbl_PostCount.Visible = true; lbl_PercentBar.Text = percent.ToString() + "%"; lbl_PostCount.Text = ripper.parsed.ToString() + "/" + ripper.totalPosts.ToString(); bar_Progress.Value = percent; @@ -518,19 +464,121 @@ private void crawlWorker_AfterDone(object sender, RunWorkerCompletedEventArgs e) private void crawlWorker_DoWork(object sender, DoWorkEventArgs e) { - Thread.Sleep(100); - ImageRipper ripper = (ImageRipper)e.Argument; + string elapsedTime; - if (ripper != null) + this.Invoke((MethodInvoker)delegate + { + updateStatusText("Initializing ..."); + updateWorkStatusText("Initializing ... "); + updateWorkStatusText("Checking for internet connection ..."); + }); + + ts = stopWatch.Elapsed; + + // Format and display the TimeSpan value. + elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", + ts.Hours, ts.Minutes, ts.Seconds, + ts.Milliseconds / 10); + + this.Invoke((MethodInvoker)delegate + { + lbl_Timer.Text = elapsedTime; + }); + + if (WebHelper.CheckForInternetConnection()) { - int mode = 0; + this.Invoke((MethodInvoker)delegate + { + updateWorkStatusText("Internet Connection found ..."); + updateWorkStatusText("Getting Blog info ..."); + }); + tumblrBlog = new Tumblr(); + tumblrBlog.cname = txt_TumblrURL.Text; + this.ts = stopWatch.Elapsed; + + // Format and display the TimeSpan value. + elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", + ts.Hours, ts.Minutes, ts.Seconds, + ts.Milliseconds / 10); + this.Invoke((MethodInvoker)delegate { - mode = select_Mode.SelectedIndex + 1; + lbl_Timer.Text = elapsedTime; }); - tumblrBlog = ripper.parseBlogPosts(mode); + this.ripper = new ImageRipper(tumblrBlog, txt_SaveLocation.Text, optionsForm.parsePhotoSets, optionsForm.parseJPEG, optionsForm.parsePNG, optionsForm.parseGIF, 0); + + if (this.ripper != null) + { + this.ripper.setAPIMode(options.apiMode); + this.ripper.setLogFile(logFile); + + if (this.ripper.setBlogInfo()) + { + ts = stopWatch.Elapsed; + + // Format and display the TimeSpan value. + elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", + ts.Hours, ts.Minutes, ts.Seconds, + ts.Milliseconds / 10); + + this.Invoke((MethodInvoker)delegate + { + lbl_Timer.Text = elapsedTime; + + lbl_PostCount.Text = "0 / 0"; + lbl_PostCount.Visible = false; + txt_WorkStatus.Visible = true; + + txt_WorkStatus.SelectionStart = txt_WorkStatus.Text.Length; + }); + + if (saveFile == null && !saveTumblrFile(this.ripper.blog.name)) + { + this.Invoke((MethodInvoker)delegate + { + updateWorkStatusText("Unable to save .tumblr file"); + updateStatusText("Error"); + }); + } + else + { + if (this.ripper != null) + { + int mode = 0; + this.Invoke((MethodInvoker)delegate + { + mode = select_Mode.SelectedIndex + 1; + }); + + tumblrBlog = this.ripper.parseBlogPosts(mode); + } + } + } + else + { + updateStatusText("Error"); + updateWorkStatusText("Invalid Tumblr URL: " + txt_TumblrURL.Text); + btn_Crawl.Enabled = true; + lbl_PostCount.Visible = false; + bar_Progress.Visible = false; + img_DisplayImage.Visible = false; + tab_TumblrStats.Enabled = true; + } + } + } + else + { + updateStatusText("Error"); + updateWorkStatusText("No internet connection detected!"); + btn_Crawl.Enabled = true; + lbl_PostCount.Visible = false; + bar_Progress.Visible = false; + img_DisplayImage.Visible = false; + tab_TumblrStats.Enabled = true; } + + Thread.Sleep(100); } private void downloadUIUpdate_AfterDone(object sender, RunWorkerCompletedEventArgs e) @@ -617,7 +665,10 @@ private void downloadUIUpdate_DoWork(object sender, DoWorkEventArgs e) ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10); - lbl_Timer.Text = elapsedTime; + this.Invoke((MethodInvoker)delegate + { + lbl_Timer.Text = elapsedTime; + }); int c = 0; int f = 0;