Ejemplo n.º 1
0
        public void SetAtlasImageLoader(AtlasImageLoader loader)
        {
            this.loader = loader;

            comboBox1.DataSource = loader.GetImageNames();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Event Function for Tree View - After Select.
        /// Will update the file details based upon selection.
        /// Will update the file image preview if .dds file
        /// </summary>
        /// <param name="sender">The TreeView clicked.</param>
        /// <param name="e">The After Select event args.</param>
        private void _FilesTreeView_AfterSelect(Object sender, TreeViewEventArgs e)
        {
            TreeView treeView = (TreeView)sender;
            TreeNode selectedNode = treeView.SelectedNode;
            NodeObject nodeObject = (NodeObject)selectedNode.Tag;
            PackFileEntry fileEntry = nodeObject.FileEntry;
            AtlasImageLoader loader = new AtlasImageLoader();

            pictureBox1.Image = null;
            pictureBox1.Tag = null;
            loader.ClearImageList();

            textBoxPath.Text = selectedNode.FullPath;

            pictureBox1.Hide();

            if (checkBoxPreview.Checked)
            {
                if (selectedNode.Name.EndsWith(".dds"))
                {
                    _fileManager.BeginAllDatReadAccess();
                    Bitmap bmp = AtlasImageLoader.TextureFromGameFile(selectedNode.FullPath, _fileManager);
                    bmp.Tag = selectedNode.Text.Replace(Path.GetExtension(selectedNode.Text), string.Empty);
                    _fileManager.EndAllDatAccess();

                    pictureBox1.Image = bmp;

                    pictureBox1.Show();
                }
                else if (selectedNode.Name.EndsWith("_atlas.xml"))
                {
                    try
                    {
                        _fileManager.BeginAllDatReadAccess();
                        loader.LoadAtlas(selectedNode.FullPath, _fileManager);
                        _fileManager.EndAllDatAccess();

                        if (loader.ImageCount > 0)
                        {
                            pictureBox1.Image = loader.GetImage(loader.GetImageNames()[0]);
                            pictureBox1.Tag = loader;
                            pictureBox1.Show();
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
            }

            _files_listView.Items.Clear();
            if (nodeObject.IsFolder)  return;

            // no file index means it's either an uncooked file, or a new file
            if (fileEntry == null)
            {
                // todo: this entires if-block is a little dodgy and assumes alot

                // assuming only uncooked at the moment
                Debug.Assert(nodeObject.IsUncookedVersion);

                // if it's the uncooked version, we need to use the parents node path
                TreeNode parentNode = selectedNode.Parent;
                String fileDataPath = parentNode.Name.Replace(".cooked", "");
                String filePath = Path.Combine(Config.HglDir, fileDataPath);

                FileInfo fileInfo;
                try
                {
                    fileInfo = new FileInfo(filePath);
                }
                catch (Exception)
                {
                    // todo remove file from tree as it has been moved(?)
                    return;
                }

                String[] fileDetails = new String[5];
                fileDetails[0] = fileInfo.Name;
                fileDetails[1] = fileInfo.Length.ToString();
                fileDetails[2] = String.Empty;
                fileDetails[3] = fileInfo.LastWriteTime.ToString();
                fileDetails[4] = fileDataPath;

                ListViewItem listViewItem = new ListViewItem(fileDetails);

                _files_listView.Items.Add(listViewItem);
                return;
            }

            _ListView_AddFileItem(fileEntry);

            if (fileEntry.Siblings == null) return;

            foreach (PackFileEntry siblingEntry in fileEntry.Siblings)
            {
                _ListView_AddFileItem(siblingEntry);
            }
        }