Exemplo n.º 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;
                });
            });
        }
Exemplo n.º 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);
                    });
                }
            });
        }