예제 #1
0
        private void menuSave_Click(object sender, EventArgs e)
        {
            _saveCurrentIcon();

            var tga = new Targa();

            try
            {
                var images = _getImagesFromList();

                // generate full tga image
                var data = tga.CreateTga(images);
                // get icons
                var icons = _getIconItemsFromList();

                // save to file
                var bni = new BniFile();
                bni.Save(icons, data, FileName);

                HasModified = false;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
예제 #2
0
        private void menuOpen_Click(object sender, EventArgs e)
        {
            var d = new OpenFileDialog();

            d.InitialDirectory = Environment.CurrentDirectory;
            d.Filter           = "BNI Archive (*.bni)|*.bni";
            if (d.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            // set global filename
            if (string.IsNullOrEmpty(FileName = d.FileName))
            {
                return;
            }

            try
            {
                customDrawListBox1.Items.Clear();

                var tga = new Targa();
                var bni = new BniFile();

                // load file to structure
                var bn = bni.Load(FileName);
                // get icon images
                var images = tga.SplitImage(bn.Data, 14);

                if (bn.Icons.Length != images.Length)
                {
                    MessageBox.Show(String.Format("Icons count ({0}) is not equals with images count ({1})", bn.Icons.Length, images.Length), "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                if (bn.Icons.Length == 0)
                {
                    throw new Exception(String.Format("No icons found"));
                }


                // put each image corresponding to it icon in bni structure
                for (int i = 0; i < bn.Icons.Length; i++)
                {
                    bn.Icons[i].Image = images[i];
                    customDrawListBox1.Items.Add(bn.Icons[i]);
                }

                // set first icon
                customDrawListBox1.SelectedIndex = 0;

                HasModified = false;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                FileName = null;
            }
        }
예제 #3
0
        private void menuSaveAs_Click(object sender, EventArgs e)
        {
            _saveCurrentIcon();

            var d = new SaveFileDialog();

            d.InitialDirectory = Environment.CurrentDirectory;
            d.Filter           = "BNI Archive (*.bni)|*.bni";
            d.CheckPathExists  = true;

            if (d.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            var fileName = d.FileName;

            var tga = new Targa();

            try
            {
                var images = _getImagesFromList();

                // generate full tga image
                var data = tga.CreateTga(images);
                // get icons
                var icons = _getIconItemsFromList();

                // save to file
                var bni = new BniFile();
                bni.Save(icons, data, fileName);

                HasModified = false;
                MessageBox.Show(string.Format("File saved to {0}", fileName), "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }