private void buttonCheck_Click(object sender, EventArgs e) { string PreviousFolder = m_AppKey.GetValue("PreviousFolder", Application.ExecutablePath) as string; folderBrowserDialog.SelectedPath = PreviousFolder; if (folderBrowserDialog.ShowDialog(this) != DialogResult.OK) { return; } DirectoryInfo Root = new DirectoryInfo(folderBrowserDialog.SelectedPath); if (!Root.Exists) { MessageBox("The selected folder doesn't exist!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } m_AppKey.SetValue("PreviousFolder", folderBrowserDialog.SelectedPath); try { ////////////////////////////////////////////////////////////////////////// // Gather all images in all subdirectories FileInfo[] ImageFilesTGA = Root.GetFiles("*.tga", SearchOption.AllDirectories); FileInfo[] ImageFilesPNG = Root.GetFiles("*.png", SearchOption.AllDirectories); int ImagesCount = ImageFilesPNG.Length + ImageFilesTGA.Length; progressBar.Maximum = ImagesCount; progressBar.Value = 0; progressBar.Visible = true; buttonCancel.Visible = true; buttonCheck.Enabled = false; m_Cancel = false; richTextBoxResults.Text = ""; string Errors = null; int MaxSize = integerTrackbarControlSize.Value; m_ImagesTooLarge.Clear(); // Check for PNGs foreach (FileInfo ImageFilePNG in ImageFilesPNG) { progressBar.Value++; if (progressBar.Value % 20 == 0) { richTextBoxResults.Refresh(); Application.DoEvents(); } if (m_Cancel) { break; } try { using (Image B = Bitmap.FromFile(ImageFilePNG.FullName)) { if (B.Width > MaxSize || B.Height > MaxSize) { richTextBoxResults.Text += "• File " + ImageFilePNG.FullName + " is " + B.Width + "x" + B.Height + "\r\n"; m_ImagesTooLarge.Add(ImageFilePNG); } } } catch (Exception _e) { Errors += "> Failed to open " + ImageFilePNG + ": " + _e.Message + "\r\n"; } } // Check for TGAs foreach (FileInfo ImageFileTGA in ImageFilesTGA) { progressBar.Value++; if (progressBar.Value % 20 == 0) { richTextBoxResults.Refresh(); Application.DoEvents(); } if (m_Cancel) { break; } try { using (ImageUtility.TargaImage B = new ImageUtility.TargaImage(ImageFileTGA.FullName, true)) { if (B.Header.Width > MaxSize || B.Header.Height > MaxSize) { richTextBoxResults.Text += "• File " + ImageFileTGA.FullName + " is " + B.Header.Width + "x" + B.Header.Height + "\r\n"; m_ImagesTooLarge.Add(ImageFileTGA); } } } catch (Exception _e) { Errors += "> Failed to open " + ImageFileTGA + ": " + _e.Message + "\r\n"; } } if (Errors != null) { richTextBoxResults.Text += "\r\n\r\nThe following errors were encountered:\r\n" + Errors; } if (m_Cancel) { richTextBoxResults.Text += "\r\n\r\n>>>>>>> CANCELLED <<<<<<<<<<<<<\r\n"; } MessageBox("Done! " + progressBar.Value + " images were processed and " + m_ImagesTooLarge.Count + " images have been determined as too large...", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception _e) { MessageBox("An error occurred while checking images!\r\nReason: " + _e.Message, MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { progressBar.Visible = false; buttonCheck.Enabled = true; } }
private void buttonCheck_Click( object sender, EventArgs e ) { string PreviousFolder = m_AppKey.GetValue( "PreviousFolder", Application.ExecutablePath ) as string; folderBrowserDialog.SelectedPath = PreviousFolder; if ( folderBrowserDialog.ShowDialog( this ) != DialogResult.OK ) { return; } DirectoryInfo Root = new DirectoryInfo( folderBrowserDialog.SelectedPath ); if ( !Root.Exists ) { MessageBox( "The selected folder doesn't exist!", MessageBoxButtons.OK, MessageBoxIcon.Error ); return; } m_AppKey.SetValue( "PreviousFolder", folderBrowserDialog.SelectedPath ); try { ////////////////////////////////////////////////////////////////////////// // Gather all images in all subdirectories FileInfo[] ImageFilesTGA = Root.GetFiles( "*.tga", SearchOption.AllDirectories ); FileInfo[] ImageFilesPNG = Root.GetFiles( "*.png", SearchOption.AllDirectories ); int ImagesCount = ImageFilesPNG.Length + ImageFilesTGA.Length; progressBar.Maximum = ImagesCount; progressBar.Value = 0; progressBar.Visible = true; buttonCancel.Visible = true; buttonCheck.Enabled = false; m_Cancel = false; richTextBoxResults.Text = ""; string Errors = null; int MaxSize = integerTrackbarControlSize.Value; m_ImagesTooLarge.Clear(); // Check for PNGs foreach ( FileInfo ImageFilePNG in ImageFilesPNG ) { progressBar.Value++; if ( progressBar.Value % 20 == 0 ) { richTextBoxResults.Refresh(); Application.DoEvents(); } if ( m_Cancel ) break; try { using ( Image B = Bitmap.FromFile( ImageFilePNG.FullName ) ) { if ( B.Width > MaxSize || B.Height > MaxSize ) { richTextBoxResults.Text += "• File " + ImageFilePNG.FullName + " is " + B.Width + "x" + B.Height + "\r\n"; m_ImagesTooLarge.Add( ImageFilePNG ); } } } catch ( Exception _e ) { Errors += "> Failed to open " + ImageFilePNG + ": " + _e.Message + "\r\n"; } } // Check for TGAs foreach ( FileInfo ImageFileTGA in ImageFilesTGA ) { progressBar.Value++; if ( progressBar.Value % 20 == 0 ) { richTextBoxResults.Refresh(); Application.DoEvents(); } if ( m_Cancel ) break; try { using ( ImageUtility.TargaImage B = new ImageUtility.TargaImage( ImageFileTGA.FullName, true ) ) { if ( B.Header.Width > MaxSize || B.Header.Height > MaxSize ) { richTextBoxResults.Text += "• File " + ImageFileTGA.FullName + " is " + B.Header.Width + "x" + B.Header.Height + "\r\n"; m_ImagesTooLarge.Add( ImageFileTGA ); } } } catch ( Exception _e ) { Errors += "> Failed to open " + ImageFileTGA + ": " + _e.Message + "\r\n"; } } if ( Errors != null ) richTextBoxResults.Text += "\r\n\r\nThe following errors were encountered:\r\n" + Errors; if ( m_Cancel ) richTextBoxResults.Text += "\r\n\r\n>>>>>>> CANCELLED <<<<<<<<<<<<<\r\n"; MessageBox( "Done! " + progressBar.Value + " images were processed and " + m_ImagesTooLarge.Count + " images have been determined as too large...", MessageBoxButtons.OK, MessageBoxIcon.Information ); } catch ( Exception _e ) { MessageBox( "An error occurred while checking images!\r\nReason: " + _e.Message, MessageBoxButtons.OK, MessageBoxIcon.Error ); } finally { progressBar.Visible = false; buttonCheck.Enabled = true; } }