Exemplo n.º 1
0
        /// <summary>
        /// Opens current entry in file list
        /// </summary>
        public void OpenSelectedEntry()
        {
            if (fileListView.SelectedItems.Count == 1)
            {
                Cursor = Cursors.WaitCursor;

                ListViewItem currentItem = fileListView.SelectedItems[0];
                Object       tag         = currentItem.Tag;

                try
                {
                    if (tag is FileSystemInfo)
                    {
                        // File or directory
                        string path = ((tag as FileSystemInfo).FullName);

                        try
                        {
                            _Refresh(path);
                            CurrentFolder = path;
                        }
                        catch (NotImplementedException ex)
                        {
                            // Not applicable -> entry will be opened with default assos
                            __SystemRun(path);
                        }
                    }
                    else if (tag is PackedFile)
                    {
                        // Packed file -> it must be extracted first
                        // Reloads BNK to get correct contents
                        Bnk parentBnk = new Bnk {
                            Name = CurrentFolder
                        };
                        parentBnk.Read();

                        PackedFile updatedPackedFile = parentBnk.GetPackedFile((tag as PackedFile).Id);
                        // TODO handle temporary folder
                        string path = @"T:\COMMUN\" + updatedPackedFile.Name;
                        Bnk.Extract(updatedPackedFile, path);

                        // Opens with default file associations for now
                        __SystemRun(path);
                    }
                }

                catch (Exception ex)
                {
                    MessageBox.Show(this, ex.Message);
                }
                finally
                {
                    Cursor = Cursors.Default;
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Recursive method to create file hierarchy on disk
        /// </summary>
        /// <param name="packedEntry"></param>
        /// <param name="lvl"></param>
        /// <param name="currentPath"></param>
        private void _ParseTree(PackedFolder packedEntry, int lvl, string currentPath)
        {
            if (packedEntry.GetType() == typeof(PackedFile))
            {
                // Extracts file
                PackedFile pf = packedEntry as PackedFile;

                if (pf != null)
                {
                    // Has it been selected ?
                    if (contentsLst.SelectedIndices.Contains((int)pf.Id))
                    {
                        string targetFilename = (currentPath + @"\" + pf.Name);

                        Bnk.Extract(pf, targetFilename);
                    }
                }
            }
            else
            {
                // Creates folder only when starting from interesting level, does not create extension directories
                if (lvl >= _DIRECTORY_LVL && !packedEntry.Name.StartsWith("."))
                {
                    currentPath += (@"\" + packedEntry.Name);

                    if (!Directory.Exists(currentPath))
                    {
                        Directory.CreateDirectory(currentPath);
                    }
                }

                // Children
                foreach (PackedFolder child in packedEntry.Children)
                {
                    _ParseTree(child, lvl + 1, currentPath);
                }
            }
        }