context: using System;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Data;
  using System.Drawing;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using System.Windows.Forms;
  using System.IO;
  using System.Collections;
  using System.Diagnostics;
  using System.Runtime.InteropServices;
  
  namespace WindowsFormsApplication1
  {
      public partial class formProgramWindow : Form
      {
  
          //Declarin' me vars
          List<string> listFilePaths = new List<string>();
          List<string> listDestinationFilePaths = new List<string>();
          bool bCopyFiles;
  
          //List<CheckBox> listDoResizeCheckBox = new List<CheckBox>();
          //listDoResizeCheckBox.Add(checkboxDoResize01);
  
          //end
  
          public formProgramWindow()
          {
              InitializeComponent();
          }
  
          private void tableLayoutPanel1_Paint(object sender, PaintEventArgs e)
          {
  
          }
  
          private void listView1_SelectedIndexChanged(object sender, EventArgs e)
          {
  
          }
  
          private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
          {
  
          }
  
          private void label1_Click(object sender, EventArgs e)
          {
  
          }
  
          private void comboBox21_SelectedIndexChanged(object sender, EventArgs e)
          {
  
          }
  
          private void comboboxSourceYRes01_SelectedIndexChanged(object sender, EventArgs e)
          {
  
          }
  
          private void buttonSourceDir_Click(object sender, EventArgs e)
          {
              if (dialogSourceDir.ShowDialog() == DialogResult.OK)
              {
                  textboxSourceDir.Text = dialogSourceDir.SelectedPath;
              }
          }
  
          private void textboxSourceDir_TextChanged(object sender, EventArgs e)
          {
  
          }
  
          private void dialogSourceDir_HelpRequest(object sender, EventArgs e)
          {
  
          }
  
          private void checkboxDoResizeAll_CheckedChanged(object sender, EventArgs e)
          {
  
              //Shitty code as I couldn't figure out why I couldn't add the gui forms to a list variable.
  
              if (checkboxDoResizeAll.Checked)
              {
                  checkboxDoResize01.Checked = true;
                  checkboxDoResize02.Checked = true;
                  checkboxDoResize03.Checked = true;
                  checkboxDoResize04.Checked = true;
                  checkboxDoResize05.Checked = true;
                  checkboxDoResize06.Checked = true;
                  checkboxDoResize07.Checked = true;
                  checkboxDoResize08.Checked = true;
                  checkboxDoResize09.Checked = true;
                  checkboxDoResize10.Checked = true;
                  checkboxDoResize11.Checked = true;
                  checkboxDoResize12.Checked = true;
                  checkboxDoResize13.Checked = true;
                  checkboxDoResize14.Checked = true;
                  checkboxDoResize15.Checked = true;
              }
  
              else
              {
                  checkboxDoResize01.Checked = false;
                  checkboxDoResize02.Checked = false;
                  checkboxDoResize03.Checked = false;
                  checkboxDoResize04.Checked = false;
                  checkboxDoResize05.Checked = false;
                  checkboxDoResize06.Checked = false;
                  checkboxDoResize07.Checked = false;
                  checkboxDoResize08.Checked = false;
                  checkboxDoResize09.Checked = false;
                  checkboxDoResize10.Checked = false;
                  checkboxDoResize11.Checked = false;
                  checkboxDoResize12.Checked = false;
                  checkboxDoResize13.Checked = false;
                  checkboxDoResize14.Checked = false;
                  checkboxDoResize15.Checked = false;
              }
  
          }
  
          private void checkboxDoUseDestinationDir_CheckedChanged(object sender, EventArgs e)
          {
              //Redundant function, as I can't be fagged making it so we can overwrite the files in the same directories
              //that we found them in.
  
              if (checkboxDoUseDestinationDir.Checked)
              {
                  buttonDestinationDir.Visible = true;
                  textboxDestinationDir.Visible = true;
              }
  
              else
              {
                  buttonDestinationDir.Visible = false;
                  textboxDestinationDir.Visible = false;
              }
          }
  
          public void DirSearch(string sDir)
          {
              //Okay, so, we get all subdirectories in a folder via the Directory.GetDirectories() function.
              //We then get the .dds files present in each subfolder by calling Directory.GetFiles() on each
              //subdirectory (which we got from Directory.GetDirectories()
              //
              //The downside to this approach, is that it won't catch any .dds files in the original folder
              //as we're checking for .dds files in the SUBDIRECTORIES!
              //Probably isn't hard to workaround, but, well, don't fix what ain't broken. It works, so I'm good.
  
              try
              {
                  foreach (string strDir in Directory.GetDirectories(sDir))
                  {
                      foreach (string strFile in Directory.GetFiles(strDir, "*.dds"))
                      {
                          listFilePaths.Add(strFile);
                          //MessageBox.Show(this, strFile, "File Path is", MessageBoxButtons.OK, MessageBoxIcon.None);
                      }
                      DirSearch(strDir);
                  }
              }
              catch (System.Exception excpt) //In case there's an invalid folder kicking about.
              {
                  MessageBox.Show(this, excpt.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.None);
                  Console.WriteLine(excpt.Message);
              }
          }
  
          public void GetDDSDimensions(string strDDSFilename, out int iSourceDDSx, out int iSourceDDSy)
          {
              //Pretty simple stuff, aside from the whole "using" thing. Basically, when the function ends @ the } bracket
              //C# takes care of making sure the file is not retained in memory, and that we don't have a zombie file-reading thing.
              //So eh. It works, and saves effort. 10/10 points
  
              using (FileStream fsSourceDDS = new FileStream(strDDSFilename, FileMode.Open, FileAccess.Read))
              using (BinaryReader binaryreaderDDS = new BinaryReader(fsSourceDDS))
              {
                  fsSourceDDS.Seek(0x0c, SeekOrigin.Begin);
                  ushort ushortHeight = binaryreaderDDS.ReadUInt16();
                  fsSourceDDS.Seek(0x10, SeekOrigin.Begin);
                  ushort ushortWidth = binaryreaderDDS.ReadUInt16();
  
                  iSourceDDSx = ushortWidth;
                  iSourceDDSy = ushortHeight;
  
                  //string strMessageWidth;
                  //string strMessageHeight;
  
                  //MessageBox.Show(this, strMessageWidth = iSourceDDSx.ToString(), "Width is");
                  //MessageBox.Show(this, strMessageHeight = iSourceDDSx.ToString(), "Height is");
              }
          }
  
          public bool IsComboBoxTextInteger(ComboBox comboboxToCheckFirst, ComboBox comboboxToCheckSecond, ComboBox comboboxToCheckThird, ComboBox comboboxToCheckFourth)
          {
              Boolean bComboBoxFirst = comboboxToCheckFirst.Text.All(char.IsDigit);
              Boolean bComboBoxSecond = comboboxToCheckSecond.Text.All(char.IsDigit);
              Boolean bComboBoxThird = comboboxToCheckThird.Text.All(char.IsDigit);
              Boolean bComboBoxFourth = comboboxToCheckFourth.Text.All(char.IsDigit);
  
              //Check to make sure we actually have text in the drop-down list, and that it's a number.
  
              if (comboboxToCheckFirst.Text.Length > 0
                  && bComboBoxFirst
                  && comboboxToCheckSecond.Text.Length > 0
                  && bComboBoxSecond
                  && comboboxToCheckThird.Text.Length > 0
                  && bComboBoxThird
                  && comboboxToCheckFourth.Text.Length > 0
                  && bComboBoxFourth)
              {
                  return true;
              }
  
              else
              {
                  return false;
              }
  
          }
  
          public string GetNewMipmapLevels(string strWidth, string strHeight)
          {
              int iWidth = Int32.Parse(strWidth);
              int iHeight = Int32.Parse(strHeight);
              int iResToCheck = 1; // Easier to just set it to 1 to begin with, rather than have the failsafe in an else statement.
  
  
gt:             if (iWidth > iHeight)