示例#1
0
        private void LoadMultipleAsync(string[] fileNames)
        {
            toolStripProgressBar1.Visible = true;
            openToolStripButton.Enabled   = false;
            saveToolStripButton.Enabled   = false;

            Task.Run(() =>
            {
                var stopwatch = Stopwatch.StartNew();
                var ntex      = new NTX();
                var failed    = 0;

                foreach (var fileName in fileNames)
                {
                    Invoke((MethodInvoker) delegate
                    {
                        toolStripProgressBar1.Visible = false;
                        toolStripStatusLabel1.Text    = $@"Loading {Path.GetFileNameWithoutExtension(fileName)}...";

                        openToolStripButton.Enabled = true;
                        saveToolStripButton.Enabled = true;
                    });

                    try
                    {
                        ntex.Load(fileName);
                    }
                    catch (Exception)
                    {
                        failed++;
                    }
                }

                Invoke((MethodInvoker) delegate
                {
                    textureViewer1.LoadTex(ntex);

                    stopwatch.Stop();

                    toolStripProgressBar1.Visible = false;
                    toolStripStatusLabel1.Text    =
                        $@"Loaded {ntex.Textures.Count} out of {fileNames.Length} NTX Files ({
                                failed
                            } failed) Textures in {stopwatch.ElapsedMilliseconds} ms!";

                    openToolStripButton.Enabled = true;
                    saveToolStripButton.Enabled = true;
                });
            });
        }
示例#2
0
        private void LoadNtxAsync(string fileName)
        {
            toolStripProgressBar1.Visible = true;
            openToolStripButton.Enabled   = false;
            saveToolStripButton.Enabled   = false;
            toolStripStatusLabel1.Text    = $@"Loading {Path.GetFileNameWithoutExtension(fileName)}...";

            Task.Run(() =>
            {
                var stopwatch = Stopwatch.StartNew();
                var ntex      = new NTX();
                try
                {
                    ntex.Load(fileName);
                    textureViewer1.LoadTex(ntex);

                    stopwatch.Stop();

                    Invoke((MethodInvoker) delegate
                    {
                        toolStripProgressBar1.Visible = false;
                        toolStripStatusLabel1.Text    =
                            $@"Loaded {ntex.Textures.Count} Textures in {stopwatch.ElapsedMilliseconds} ms!";

                        openToolStripButton.Enabled = true;
                        saveToolStripButton.Enabled = true;
                    });
                }
                catch (Exception)
                {
                    stopwatch.Stop();

                    Invoke((MethodInvoker) delegate
                    {
                        toolStripProgressBar1.Visible = false;
                        toolStripStatusLabel1.Text    = $@"Load failed. Invalid file?";
                        openToolStripButton.Enabled   = true;
                        MessageBox.Show(@"This is not a valid GameBryo NTX file!", @"GameBryo NTX Viewer",
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                    });
                }
            });
        }
示例#3
0
        public void LoadTex(NTX ntex)
        {
            listBox1.Items.Clear();
            comboBox1.Items.Clear();
            OpenedFile        = null;
            pictureBox1.Image = null;
            _textureFiles     = new Dictionary <int, List <NTX.TextureFile> >();

            var categories = new List <object>();

            foreach (var fileTexture in ntex.Textures)
            {
                var cat = fileTexture.TextureName.Remove(0, fileTexture.TextureName.IndexOf("_", StringComparison.Ordinal));
                if (_textureFiles.ContainsKey(categories.IndexOf(cat)))
                {
                    _textureFiles[categories.IndexOf(cat)].Add(fileTexture);
                }
                else
                {
                    categories.Add(cat);
                    var key = categories.Count - 1;
                    //var key = comboBox1.Items.Add(cat);
                    _textureFiles.Add(key, new List <NTX.TextureFile>()
                    {
                        fileTexture
                    });
                }
            }
            comboBox1.Invoke((MethodInvoker) delegate
            {
                comboBox1.Items.AddRange(categories.ToArray());
                if (comboBox1.Items.Count > 0)
                {
                    comboBox1.SelectedIndex = 0;
                }
                comboBox1.Enabled = true;
            });
        }