Beispiel #1
0
        private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            UI_StateInfo si = (UI_StateInfo)e.UserState;

            switch (si.UpdateType)
            {
            case UPDATE_TYPE.PROGRESS:
                this.toolStripStatusLabel1.Text  = si.Message;
                this.toolStripProgressBar1.Style = si.StyleInfo;
                break;

            case UPDATE_TYPE.DATA:
                TreeNode t = new TreeNode();
                t.Checked = true;
                t.Text    = si.CheckboxData.ToString();
                t.Tag     = si.CheckboxData;

                this.ImageTree.Nodes.Add(t);
                this.toolStripStatusLabel1.Text = si.CheckboxData.Path;

                if (!CompileBtn.Enabled)
                {
                    CompileBtn.Enabled      = true;
                    LibraryName.Enabled     = true;
                    CancelBtn.Enabled       = true;
                    OutputDir.Enabled       = true;
                    OutputDirBtn.Enabled    = true;
                    Rotate_Checkbox.Enabled = true;
                }
                //this.checkedListBox1.Items.Add(si.CheckboxData, true);
                break;

            case UPDATE_TYPE.CLEAR_IMAGE_TREE:
                ImageTree.Nodes.Clear();
                if (CompileBtn.Enabled)
                {
                    CompileBtn.Enabled      = false;
                    ImageBox.Image          = null;
                    CancelBtn.Enabled       = false;
                    LibraryName.Enabled     = false;
                    OutputDir.Enabled       = false;
                    OutputDirBtn.Enabled    = false;
                    Rotate_Checkbox.Enabled = false;
                }
                break;

            case UPDATE_TYPE.CLEAR_MAP_TREE:
                break;
            }
        }
Beispiel #2
0
        public void FindFiles()
        {
            UI_StateInfo si = new UI_StateInfo();
            si.UpdateType = UPDATE_TYPE.CLEAR_IMAGE_TREE;
            backgroundWorker1.ReportProgress(0, (object)si);
            try
            {
                FileList = Directory.GetFiles(ImageListBaseDir, "*.png", SearchOption.AllDirectories);
                if (FileList.Length == 0)
                {
                    MessageBox.Show("Current directory doesn't contain Images in PNG format.", "Invalid Image Directory", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    si.UpdateType = UPDATE_TYPE.PROGRESS;
                    si.Message = "Ready.";
                    si.StyleInfo = ProgressBarStyle.Blocks;
                    backgroundWorker1.ReportProgress(0, (object)si);
                    return;
                }

                if (FileList != null)
                {
                    foreach (string file in FileList)
                    {
                        display = file.Replace(ImageListBaseDir, ImageListBaseDir.Substring(ImageListBaseDir.LastIndexOf(@"\")+1));
                        display = display.Replace(@"\", ".");

                        si.UpdateType = UPDATE_TYPE.DATA;
                        si.CheckboxData = new Resources(file, display);

                        backgroundWorker1.ReportProgress(0, (object)si);
                    }
                }
            }
            catch (Exception exc)
            {

                Environment.CurrentDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
                si.UpdateType = UPDATE_TYPE.PROGRESS;
                si.Message = exc.Message;
                si.StyleInfo = ProgressBarStyle.Blocks;
                backgroundWorker1.ReportProgress(0, (object)si);
                return;
            }
            si.UpdateType = UPDATE_TYPE.PROGRESS;
            si.Message = "Ready.";
            si.StyleInfo = ProgressBarStyle.Blocks;
            backgroundWorker1.ReportProgress(0, (object)si);

        }
Beispiel #3
0
        public void FindFiles()
        {
            UI_StateInfo si = new UI_StateInfo();

            si.UpdateType = UPDATE_TYPE.CLEAR_IMAGE_TREE;
            backgroundWorker1.ReportProgress(0, (object)si);
            try
            {
                FileList = Directory.GetFiles(ImageListBaseDir, "*.png", SearchOption.AllDirectories);
                if (FileList.Length == 0)
                {
                    MessageBox.Show("Current directory doesn't contain Images in PNG format.", "Invalid Image Directory", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    si.UpdateType = UPDATE_TYPE.PROGRESS;
                    si.Message    = "Ready.";
                    si.StyleInfo  = ProgressBarStyle.Blocks;
                    backgroundWorker1.ReportProgress(0, (object)si);
                    return;
                }

                if (FileList != null)
                {
                    foreach (string file in FileList)
                    {
                        display = file.Replace(ImageListBaseDir, ImageListBaseDir.Substring(ImageListBaseDir.LastIndexOf(@"\") + 1));
                        display = display.Replace(@"\", ".");

                        si.UpdateType   = UPDATE_TYPE.DATA;
                        si.CheckboxData = new Resources(file, display);

                        backgroundWorker1.ReportProgress(0, (object)si);
                    }
                }
            }
            catch (Exception exc)
            {
                Environment.CurrentDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
                si.UpdateType = UPDATE_TYPE.PROGRESS;
                si.Message    = exc.Message;
                si.StyleInfo  = ProgressBarStyle.Blocks;
                backgroundWorker1.ReportProgress(0, (object)si);
                return;
            }
            si.UpdateType = UPDATE_TYPE.PROGRESS;
            si.Message    = "Ready.";
            si.StyleInfo  = ProgressBarStyle.Blocks;
            backgroundWorker1.ReportProgress(0, (object)si);
        }
Beispiel #4
0
        private void backgroundWorker2_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            UI_StateInfo si = (UI_StateInfo)e.UserState;

            switch (si.UpdateType)
            {
            case UPDATE_TYPE.PROGRESS:
                this.toolStripStatusLabel1.Text  = si.Message;
                this.toolStripProgressBar1.Style = si.StyleInfo;
                break;

            case UPDATE_TYPE.TEXT_BOX:
                richTextBox1.AppendText(si.Message);
                richTextBox1.ScrollToCaret();
                break;
            }
        }
Beispiel #5
0
        private void CreateLibrary()
        {
            string unknown = string.Format("{0}\\Unknown.png", ImageListBaseDir);

            if (Array.IndexOf(FileList, unknown) == -1)
            {
                MessageBox.Show("DDD Image Libraries must contain a default image file named Unknown.png.\nPlease include an Unknown.png image at the library's top level.",
                                "Image Library Format Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            UI_StateInfo si = new UI_StateInfo();

            si.UpdateType = UPDATE_TYPE.PROGRESS;
            si.Message    = "Compiling Library ...";
            si.StyleInfo  = ProgressBarStyle.Marquee;
            backgroundWorker2.ReportProgress(0, (object)si);

            List <string> temp_files = new List <string>();

            if (OutputDir.Text != string.Empty)
            {
                if (LibraryName.Text != string.Empty)
                {
                    try
                    {
                        StringBuilder command = new StringBuilder();

                        command.Append(string.Format(base_arguments_str, LibraryName.Text));

                        StreamWriter manifest_stream = File.CreateText(OutputDir.Text + "\\" + "ImageLibrary.mf");
                        StreamWriter batch_file      = File.CreateText(OutputDir.Text + "\\resources.bat");
                        command.Append(string.Format(base_resource_str, "ImageLibrary.mf @resources.bat"));

                        foreach (TreeNode node in ImageTree.Nodes)
                        {
                            if (node.Checked)
                            {
                                Resources file = (Resources)node.Tag;
                                temp_files.Add(file.ResourceName);
                                manifest_stream.WriteLine(string.Format("{0}:{1}", temp_files[temp_files.Count - 1], file.Rotatable));
                                try
                                {
                                    System.IO.File.Copy(file.Path, OutputDir.Text + "\\" + temp_files[temp_files.Count - 1]);
                                }
                                catch (Exception copy_exception)
                                {
                                    si.UpdateType = UPDATE_TYPE.TEXT_BOX;
                                    si.Message    = copy_exception.Message;
                                    backgroundWorker2.ReportProgress(0, (object)si);
                                }
                                batch_file.WriteLine(string.Format(base_resource_str, file.ResourceName));
                            }
                        }
                        manifest_stream.Close();

                        batch_file.Close();

                        si.UpdateType = UPDATE_TYPE.TEXT_BOX;
                        si.Message    = command.ToString() + "\n";
                        backgroundWorker2.ReportProgress(0, (object)si);

                        Environment.CurrentDirectory = OutputDir.Text;

                        System.Diagnostics.Process Compiler = new System.Diagnostics.Process();
                        Compiler.StartInfo.FileName                     = base_command_str;
                        Compiler.StartInfo.Arguments                    = command.ToString();
                        Compiler.StartInfo.UseShellExecute              = false; // because I'm redirecting output.
                        Compiler.StartInfo.CreateNoWindow               = true;
                        Compiler.StartInfo.RedirectStandardError        = true;
                        Compiler.StartInfo.RedirectStandardOutput       = true;
                        Compiler.StartInfo.EnvironmentVariables["Path"] = System.Environment.ExpandEnvironmentVariables("%PATH%");

                        Compiler.Start();
                        StreamReader reader = Compiler.StandardOutput;
                        StreamReader errors = Compiler.StandardError;

                        Compiler.WaitForExit();
                        si.UpdateType = UPDATE_TYPE.TEXT_BOX;
                        si.Message    = reader.ReadToEnd() + "\n";
                        backgroundWorker2.ReportProgress(0, (object)si);

                        si.UpdateType = UPDATE_TYPE.TEXT_BOX;
                        si.Message    = errors.ReadToEnd() + "\n";
                        backgroundWorker2.ReportProgress(0, (object)si);

                        reader.Close();
                        errors.Close();

                        if (System.IO.File.Exists(LibraryName.Text + ".dll"))
                        {
                            si.UpdateType = UPDATE_TYPE.TEXT_BOX;
                            si.Message    = LibraryName.Text + ".dll Successfully Created.\n";
                            backgroundWorker2.ReportProgress(0, (object)si);

                            System.IO.File.Move(LibraryName.Text + ".dll", OutputDir.Text + "\\" + LibraryName.Text + ".dll");
                        }
                    }
                    catch (Exception library_exception)
                    {
                        si.UpdateType = UPDATE_TYPE.TEXT_BOX;
                        si.Message    = library_exception.Message;
                        backgroundWorker2.ReportProgress(0, (object)si);
                    }
                }
                else
                {
                    si.UpdateType = UPDATE_TYPE.TEXT_BOX;
                    si.Message    = "Error, must specify a library name.";
                    backgroundWorker2.ReportProgress(0, (object)si);
                }
                si.UpdateType = UPDATE_TYPE.TEXT_BOX;
                si.Message    = "Cleaning up ...\n";
                backgroundWorker2.ReportProgress(0, (object)si);

                System.IO.File.Delete("resources.bat");
                foreach (string file in temp_files)
                {
                    System.IO.File.Delete(file);
                }
            }

            si.UpdateType = UPDATE_TYPE.PROGRESS;
            si.Message    = "Ready.";
            si.StyleInfo  = ProgressBarStyle.Blocks;
            backgroundWorker2.ReportProgress(0, (object)si);
        }
Beispiel #6
0
        private void CreateLibrary()
        {
            string unknown = string.Format("{0}\\Unknown.png", ImageListBaseDir);

            if (Array.IndexOf(FileList, unknown) == -1)
            {
                MessageBox.Show("DDD Image Libraries must contain a default image file named Unknown.png.\nPlease include an Unknown.png image at the library's top level.",
                    "Image Library Format Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            UI_StateInfo si = new UI_StateInfo();
            si.UpdateType = UPDATE_TYPE.PROGRESS;
            si.Message = "Compiling Library ...";
            si.StyleInfo = ProgressBarStyle.Marquee;
            backgroundWorker2.ReportProgress(0, (object)si);

            List<string> temp_files = new List<string>();
            if (OutputDir.Text != string.Empty)
            {
                if (LibraryName.Text != string.Empty)
                {
                    try
                    {
                        StringBuilder command = new StringBuilder();
                        
                        command.Append(string.Format(base_arguments_str, LibraryName.Text));

                        StreamWriter manifest_stream = File.CreateText(OutputDir.Text + "\\" + "ImageLibrary.mf");
                        StreamWriter batch_file = File.CreateText(OutputDir.Text + "\\resources.bat");
                        command.Append(string.Format(base_resource_str, "ImageLibrary.mf @resources.bat"));

                        foreach (TreeNode node in ImageTree.Nodes)
                        {
                            if (node.Checked)
                            {
                                Resources file = (Resources)node.Tag;
                                temp_files.Add(file.ResourceName);
                                manifest_stream.WriteLine(string.Format("{0}:{1}", temp_files[temp_files.Count - 1], file.Rotatable));
                                try
                                {
                                    System.IO.File.Copy(file.Path, OutputDir.Text + "\\" + temp_files[temp_files.Count - 1]);
                                }
                                catch (Exception copy_exception)
                                {
                                    si.UpdateType = UPDATE_TYPE.TEXT_BOX;
                                    si.Message = copy_exception.Message;
                                    backgroundWorker2.ReportProgress(0, (object)si);
                                }
                                batch_file.WriteLine(string.Format(base_resource_str, file.ResourceName));
                            }
                        }
                        manifest_stream.Close();

                        batch_file.Close();

                        si.UpdateType = UPDATE_TYPE.TEXT_BOX;
                        si.Message = command.ToString() + "\n";
                        backgroundWorker2.ReportProgress(0, (object)si);

                        Environment.CurrentDirectory = OutputDir.Text;

                        System.Diagnostics.Process Compiler = new System.Diagnostics.Process();
                        Compiler.StartInfo.FileName = base_command_str;
                        Compiler.StartInfo.Arguments = command.ToString();
                        Compiler.StartInfo.UseShellExecute = false; // because I'm redirecting output.
                        Compiler.StartInfo.CreateNoWindow = true;
                        Compiler.StartInfo.RedirectStandardError = true;
                        Compiler.StartInfo.RedirectStandardOutput = true;
                        Compiler.StartInfo.EnvironmentVariables["Path"] = System.Environment.ExpandEnvironmentVariables("%PATH%");

                        Compiler.Start();
                        StreamReader reader = Compiler.StandardOutput;
                        StreamReader errors = Compiler.StandardError;

                        Compiler.WaitForExit();
                        si.UpdateType = UPDATE_TYPE.TEXT_BOX;
                        si.Message = reader.ReadToEnd() + "\n";
                        backgroundWorker2.ReportProgress(0, (object)si);

                        si.UpdateType = UPDATE_TYPE.TEXT_BOX;
                        si.Message = errors.ReadToEnd() + "\n";
                        backgroundWorker2.ReportProgress(0, (object)si);

                        reader.Close();
                        errors.Close();

                        if (System.IO.File.Exists(LibraryName.Text + ".dll"))
                        {
                            si.UpdateType = UPDATE_TYPE.TEXT_BOX;
                            si.Message = LibraryName.Text + ".dll Successfully Created.\n";
                            backgroundWorker2.ReportProgress(0, (object)si);

                            System.IO.File.Move(LibraryName.Text + ".dll", OutputDir.Text + "\\" + LibraryName.Text + ".dll");
                        }

                    }
                    catch (Exception library_exception)
                    {
                        si.UpdateType = UPDATE_TYPE.TEXT_BOX;
                        si.Message = library_exception.Message;
                        backgroundWorker2.ReportProgress(0, (object)si);
                    }
                }
                else
                {
                    si.UpdateType = UPDATE_TYPE.TEXT_BOX;
                    si.Message = "Error, must specify a library name.";
                    backgroundWorker2.ReportProgress(0, (object)si);
                }
                si.UpdateType = UPDATE_TYPE.TEXT_BOX;
                si.Message = "Cleaning up ...\n";
                backgroundWorker2.ReportProgress(0, (object)si);

                System.IO.File.Delete("resources.bat");
                foreach (string file in temp_files)
                {
                    System.IO.File.Delete(file);
                }
            }

            si.UpdateType = UPDATE_TYPE.PROGRESS;
            si.Message = "Ready.";
            si.StyleInfo = ProgressBarStyle.Blocks;
            backgroundWorker2.ReportProgress(0, (object)si);

        }