private void ListFilesUsingColor()
        {
            enhmb = new EnhancedMessageBox();
            enhmb.StartPosition = FormStartPosition.Manual;
            enhmb.Location      = new Point(this.Location.X, this.Location.Y);
            enhmb.SetText("Processing files.\nThis may take a few seconds.");
            enhmb.SetCaption("Processing files.");
            enhmb.ProgressBarVisible(true);
            enhmb.button_OK_text("Abort");
            enhmb.Show();

            Cursor.Current = Cursors.WaitCursor;
            Application.DoEvents(); //finish showing the dialog before starting the cpu-intensive operation

            int filescount = this.listView_MainFileList.SelectedItems.Count;

            enhmb.ProgressBarSize(filescount);
            int pb = 0;

            foreach (ListViewItem item in this.listView_MainFileList.SelectedItems)
            {
                pb++;
                enhmb.SetText("Processing files.\nThis may take a few seconds.\n\nFile: " + item.Text);
                enhmb.ProgressBarValue((int)pb);
                Application.DoEvents();
                //accept user input and when the messagebox is closed, stop working
                if (enhmb.Visible == false)
                {
                    break;
                }

                item.Selected = CSHaPer.IsColorUsed(item.Tag.ToString(), (byte)this.uC_EditorPalette1.PaletteSelectedColor);
            }//foreach file
            enhmb.Close();
            Application.DoEvents(); //finish showing the dialog before starting the cpu-intensive operation
            Cursor.Current = Cursors.Default;
            //create result file
            string result = "";

            result  = "Files using color result\r\n";
            result += this.listView_MainFileList.SelectedItems.Count.ToString() + " Files found, using the color [" + this.uC_EditorPalette1.PaletteSelectedColor.ToString() + "]\r\n\r\n";
            for (int i = 0; i < this.listView_MainFileList.SelectedItems.Count; i++)
            {
                result += this.listView_MainFileList.SelectedItems[i].Text + "\r\n";
            }
            System.IO.File.WriteAllText(defaultPath + "#ColorUsage.txt", result);
            System.Diagnostics.Process.Start(defaultPath + "#ColorUsage.txt");
        }
        private void ConvertPalette()
        {
            string schemefile = this.textBox_PaletteConversionScheme.Text;

            if (System.IO.File.Exists(schemefile))
            {
                List <KeyValuePair <byte, byte> > conversions = LoadCSchemeFile(schemefile);
                if (conversions.Count > 0)
                {
                    int filescount = this.listView_MainFileList.SelectedItems.Count;

                    if (filescount > 1)
                    {
                        enhmb = new EnhancedMessageBox();
                        enhmb.StartPosition = FormStartPosition.Manual;
                        enhmb.Location      = new Point(this.Location.X, this.Location.Y);
                        enhmb.SetText("Processing files.\nThis may take a few seconds.");
                        enhmb.SetCaption("Processing files.");
                        enhmb.ProgressBarVisible(true);
                        enhmb.button_OK_text("Abort");
                        enhmb.Show();


                        Cursor.Current = Cursors.WaitCursor;
                        Application.DoEvents(); //finish showing the dialog before starting the cpu-intensive operation

                        enhmb.ProgressBarSize(filescount);
                    }
                    int pb = 0;

                    paletteUsage = new long[256];

                    foreach (ListViewItem item in this.listView_MainFileList.SelectedItems)
                    {
                        pb++;
                        if (filescount > 1)
                        {
                            enhmb.SetText("Processing files.\nThis may take a few seconds.\n\nFile: " + item.Text);
                            enhmb.ProgressBarValue((int)pb);
                            Application.DoEvents();
                            //accept user input and when the messagebox is closed, stop working
                            if (enhmb.Visible == false)
                            {
                                break;
                            }
                        }

                        //CTaMPer tmpfile = new CTaMPer();
                        //tmpfile.LoadTMP(defaultPath + item.Text);
                        //tmpfile.ReplaceColors(conversions);
                        //tmpfile.SaveTMP();
                    }//foreach file
                    if (filescount > 1)
                    {
                        enhmb.Close();
                        Application.DoEvents(); //finish showing the dialog before starting the cpu-intensive operation
                        Cursor.Current = Cursors.Default;
                    }
                }
                else
                {
                    MessageBox.Show("Empty or no [Data] section found in color scheme file.\n\nFile: " + schemefile, "Data not found", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show("Color scheme file not found.\n\nFile: " + this.textBox_PaletteConversionScheme.Text, "File not found", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void AnalyzePaletteUsage(bool writeResultFile)
        {
            int filescount = this.listView_MainFileList.SelectedItems.Count;

            if (filescount > 1)
            {
                enhmb = new EnhancedMessageBox();
                enhmb.StartPosition = FormStartPosition.Manual;
                enhmb.Location      = new Point(this.Location.X, this.Location.Y);
                enhmb.SetText("Processing files.\nThis may take a few seconds.");
                enhmb.SetCaption("Processing files.");
                enhmb.ProgressBarVisible(true);
                enhmb.button_OK_text("Abort");
                enhmb.Show();


                Cursor.Current = Cursors.WaitCursor;
                Application.DoEvents(); //finish showing the dialog before starting the cpu-intensive operation

                enhmb.ProgressBarSize(filescount);
            }
            int pb = 0;

            paletteUsage = new long[256];

            foreach (ListViewItem item in this.listView_MainFileList.SelectedItems)
            {
                pb++;
                if (filescount > 1)
                {
                    enhmb.SetText("Processing files.\nThis may take a few seconds.\n\nFile: " + item.Text);
                    enhmb.ProgressBarValue((int)pb);
                    Application.DoEvents();
                    //accept user input and when the messagebox is closed, stop working
                    if (enhmb.Visible == false)
                    {
                        break;
                    }
                }

                int[] shpPaletteUsage = CSHaPer.GetSHPPaletteUsage(item.Tag.ToString());
                for (int i = 0; i < shpPaletteUsage.Length; i++)
                {
                    paletteUsage[i] += shpPaletteUsage[i];
                }
            }//foreach file
            if (filescount > 1)
            {
                enhmb.Close();
                Application.DoEvents(); //finish showing the dialog before starting the cpu-intensive operation
                Cursor.Current = Cursors.Default;
            }
            this.uC_EditorPalette1.PaletteUsage = paletteUsage;
            //create result file
            if (writeResultFile)
            {
                string result = "";
                result  = "Palette Usage Result\r\n";
                result += "Colorindex = Number of pixel using that color\r\n\r\n";
                for (int i = 0; i < paletteUsage.Length; i++)
                {
                    result += string.Format("{0:000}", i) + " = " + paletteUsage[i].ToString() + "\r\n";
                }
                System.IO.File.WriteAllText(defaultPath + "#PaletteUsage.txt", result);
                System.Diagnostics.Process.Start(defaultPath + "#PaletteUsage.txt");
            }
        }