Exemple #1
0
        private void file_browser_AfterSelect(object sender, TreeViewEventArgs e)
        {
            if (e.Node == null)
            {
                return;
            }
            if (((CacheItemNode)e.Node).SubArchive != -1)
            {
                saveCurrentToolStripMenuItem.Enabled = true;
            }
            else
            {
                saveCurrentToolStripMenuItem.Enabled = false;
            }
            if (e.Node.Nodes.Count > 0 || ((CacheItemNode)e.Node).FileIndex == -1)
            {
                return;
            }

            selected_node     = (CacheItemNode)e.Node;
            btnImport.Enabled = true;
            btnExport.Enabled = true;
            if (selected_node.SubArchive != -1)
            {
                btnRename.Enabled = true;
            }
            else
            {
                btnRename.Enabled = false;
                saveCurrentToolStripMenuItem.Enabled = false;
            }

            DeterminePlugins();
            UpdateFileInfo();
        }
Exemple #2
0
 private void PopulateFileBrowser()
 {
     file_browser.Nodes.Clear();
     for (int i = 0; i < 5; i++)
     {
         CacheItemNode node = new CacheItemNode(Cache.Archives[i].ArchiveName + " (" + Cache.Archives[i].GetFileCount() + " files)", Cache.Archives[i].ArchiveName, i, -1, -1, 0);
         for (int k = 0; k < Cache.Archives[i].GetFileCount(); k++)
         {
             if (i > 0)
             {
                 node.Nodes.Add(NewNode(i, -1, k));
             }
             else
             {
                 byte[] buf = Cache.Archives[0].ExtractFile(k);
                 Cache.SubArchives.Add(new SubArchive(Cache.Archives[0].ExtractFile(k)));
                 string s_name = "Sub-archive " + k;
                 if (k < Cache.SubNames.Length)
                 {
                     s_name = Cache.SubNames[k];
                 }
                 CacheItemNode sub = new CacheItemNode(s_name + " (" + Cache.SubArchives[k].FileCount + " files)", s_name, i, k, -1, 0);
                 for (int j = 0; j < Cache.SubArchives[k].FileCount; j++)
                 {
                     sub.Nodes.Add(NewNode(i, k, j));
                 }
                 node.Nodes.Add(sub);
             }
         }
         file_browser.Nodes.Add(node);
     }
 }
Exemple #3
0
        private bool WriteFile(string filename, int archive, int sub_archive, CacheItemNode n)
        {
            string ext = Path.GetExtension(filename).ToLower();

            foreach (IPlugin plugin in Plugins.Plugins)
            {
                if (plugin.FileExtensions != "")
                {
                    string[] tes = plugin.FileExtensions.Split('|');
                    foreach (string s in tes)
                    {
                        if (s.Replace("*", "").ToLower() == ext.ToLower())
                        {
                            CacheItemNode temp = plugin.Node;
                            plugin.Node  = n;
                            plugin.Cache = Cache;
                            bool b = plugin.OnImport(filename);
                            if (b)
                            {
                                plugin.Node.Size = plugin.Data.Buffer.Length;
                                plugin.Node.Text = plugin.Node.Name + " (" + GetSizeLabel(plugin.Node.Size) + ")";
                            }
                            plugin.Node = temp;
                            return(b);
                        }
                    }
                }
            }

            return(false);
        }
Exemple #4
0
 private void file_browser_DragLeave(object sender, EventArgs e)
 {
     if (last_highlight_node != null)
     {
         last_highlight_node.BackColor = last_highlight_color;
         last_highlight_node           = null;
     }
 }
Exemple #5
0
 private void ResetSearch(CacheItemNode node)
 {
     node.BackColor = SystemColors.Window;
     foreach (CacheItemNode n in node.Nodes)
     {
         ResetSearch(n);
     }
 }
Exemple #6
0
 public void WriteFile(CacheItemNode node, byte[] data)
 {
     if(node.SubArchive != -1)
     {
         SubArchives[node.SubArchive].WriteFile(node.FileIndex, data);
     }
     else if(node.Archive != -1)
     {
         Archives[node.Archive].WriteFile(node.FileIndex, data, data.Length);
     }
 }
Exemple #7
0
        private void file_browser_DragOver(object sender, DragEventArgs e)
        {
            Point         relative = file_browser.PointToClient(new Point(e.X, e.Y));
            CacheItemNode node     = (CacheItemNode)file_browser.GetNodeAt(relative.X, relative.Y);

            if (node != null && node != last_highlight_node)
            {
                if (last_highlight_node != null && last_highlight_node != node)
                {
                    last_highlight_node.BackColor = last_highlight_color;
                }
                last_highlight_color = node.BackColor;
                last_highlight_node  = node;
                node.BackColor       = SystemColors.ButtonShadow;
            }
        }
Exemple #8
0
 private byte[] GetNodeData(CacheItemNode node)
 {
     byte[] b = null;
     if (node.SubArchive == 0)
     {
         return(new byte[0]);
     }
     if (node.SubArchive == -1)
     {
         b = Cache.Archives[node.Archive].ExtractFile(node.FileIndex);
     }
     else
     {
         b = Cache.SubArchives[node.SubArchive].ExtractFile(node.FileIndex).Buffer;
     }
     return(b);
 }
Exemple #9
0
        private void file_browser_DragDrop(object sender, DragEventArgs e)
        {
            Point         relative = file_browser.PointToClient(new Point(e.X, e.Y));
            CacheItemNode node     = (CacheItemNode)file_browser.GetNodeAt(relative.X, relative.Y);

            file_browser_DragLeave(this, null);

            string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
            if (node.FileIndex == -1 || files.Length > 1)
            {
                for (int i = 0; i < files.Length; i++)
                {
                    try
                    {
                        CreateAndWriteFile(files[i], node.Archive, node.SubArchive);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("An error occurred when importing file. It may still be imported but one or more plugins may be broken.", "Error Importing", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
            else if (files.Length == 1 && node.FileIndex != -1)
            {
                try
                {
                    if (!WriteFile(files[0], node.Archive, node.SubArchive, node))
                    {
                        MessageBox.Show("Failed to find plugin.", "Error Importing", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        if (node == selected_node)
                        {
                            DeterminePlugins();
                            UpdateFileInfo();
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("An error occurred when importing file. It may still be imported but one or more plugins may be broken.", "Error Importing", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Exemple #10
0
        private void newFileToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (file_browser.SelectedNode == null)
            {
                return;
            }
            CacheItemNode c = (CacheItemNode)file_browser.SelectedNode;

            if (c.SubArchive == -1 && c.Archive != -1)
            {
                if (!Cache.Archives[c.Archive].CreateFile())
                {
                    MessageBox.Show("Failed to create file.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                int    k    = Cache.Archives[c.Archive].GetFileCount() - 1;
                string name = "File " + k;
                if (c.Archive == 4)
                {
                    Point p = Map.GetCoordinates(Cache.SubArchives[5], k);
                    if (p.X >= 0 && p.Y >= 0)
                    {
                        name = p.X + ", " + p.Y;
                    }
                }
                file_browser.Nodes[c.Archive].Nodes.Add(new CacheItemNode(name + " (" + GetSizeLabel(Cache.Archives[c.Archive].GetFileSize(k)) + ")", name, c.Archive, -1, k, Cache.Archives[c.Archive].GetFileSize(k)));
                file_browser.SelectedNode = file_browser.Nodes[c.Archive].Nodes[k];
                string f = file_browser.Nodes[c.Archive].Text.Substring(0, file_browser.Nodes[c.Archive].Text.IndexOf('('));
                file_browser.Nodes[c.Archive].Text = f + "(" + Cache.Archives[c.Archive].GetFileCount() + " files)";
            }
            else if (c.SubArchive != -1)
            {
                string name = "File " + Cache.SubArchives[c.SubArchive].FileCount;
                Cache.SubArchives[c.SubArchive].CreateFile(name);
                int size = Cache.SubArchives[c.SubArchive].UncompressedFileSizes[Cache.SubArchives[c.SubArchive].FileCount - 1];
                file_browser.Nodes[0].Nodes[c.SubArchive].Nodes.Add(new CacheItemNode(name + " (" + GetSizeLabel(size) + ")", name, c.Archive, c.SubArchive, Cache.SubArchives[c.SubArchive].FileCount - 1, size));
                file_browser.SelectedNode = file_browser.Nodes[0].Nodes[c.SubArchive].Nodes[file_browser.Nodes[0].Nodes[c.SubArchive].Nodes.Count - 1];
                string f = file_browser.Nodes[c.Archive].Nodes[c.SubArchive].Text.Substring(0, file_browser.Nodes[c.Archive].Nodes[c.SubArchive].Text.IndexOf('('));
                file_browser.Nodes[c.Archive].Nodes[c.SubArchive].Text = f + "(" + Cache.SubArchives[c.SubArchive].FileCount + " files)";
            }
        }
Exemple #11
0
        private bool Search(CacheItemNode node, int file, int archive, int sub, string file_text)
        {
            if (node.FileIndex != -1)
            {
                if ((node.SubArchive != -1 && Cache.SubArchives[node.SubArchive].GetFileIndex(file) == node.FileIndex) || node.Name.ToLower().Contains(file_text))
                {
                    node.BackColor = Color.Cyan;
                    //node.Text = search_box.GetText(0).ToLower();
                    search_count++;
                    if (search_count == 1)
                    {
                        file_browser.SelectedNode = node;
                    }
                    return(true);
                }
                return(false);
            }

            if (archive != -1 && node.Archive != archive)
            {
                return(false);
            }
            if (sub != -1 && node.SubArchive != sub && node.SubArchive != -1)
            {
                return(false);
            }

            bool found = false;

            foreach (CacheItemNode archive_node in node.Nodes)
            {
                if (Search(archive_node, file, archive, sub, file_text))
                {
                    node.BackColor = Color.Cyan;
                    found          = true;
                }
            }

            return(found);
        }
Exemple #12
0
 private void file_browser_DragOver(object sender, DragEventArgs e)
 {
     Point relative = file_browser.PointToClient(new Point(e.X, e.Y));
     CacheItemNode node = (CacheItemNode)file_browser.GetNodeAt(relative.X, relative.Y);
     if (node != null && node != last_highlight_node)
     {
         if (last_highlight_node != null && last_highlight_node != node)
         {
             last_highlight_node.BackColor = last_highlight_color;
         }
         last_highlight_color = node.BackColor;
         last_highlight_node = node;
         node.BackColor = SystemColors.ButtonShadow;
     }
 }
Exemple #13
0
        //ugh this function is a nightmare
        private void CreateAndWriteFile(string filename, int archive, int sub_archive = -1)
        {
            if (archive == -1 && sub_archive == -1)
            {
                return;
            }

            bool found = false;

            if (sub_archive == -1 && archive > 0)
            {
                if (!Cache.Archives[archive].CreateFile())
                {
                    MessageBox.Show("Failed to create file.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
            else if (sub_archive != -1)
            {
                if (!Cache.SubArchives[sub_archive].FileExists(Path.GetFileName(filename)))
                {
                    Cache.SubArchives[sub_archive].CreateFile(Path.GetFileName(filename));
                }
                else
                {
                    if (MessageBox.Show(Path.GetFileName(filename) + " already exists. Would you like to replace it?", "Confirm Replacement", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != System.Windows.Forms.DialogResult.Yes)
                    {
                        return;
                    }
                    found = true;
                }
            }
            else
            {
                return;
            }

            CacheItemNode n = null;

            if (sub_archive == -1)
            {
                n = NewNode(archive, sub_archive, Cache.Archives[archive].GetFileCount() - 1);
            }
            else
            {
                if (!found)
                {
                    n      = NewNode(0, sub_archive, Cache.SubArchives[sub_archive].FileCount - 1);
                    n.Name = Path.GetFileName(filename);
                }
                else
                {
                    int name = Cache.SubArchives[sub_archive].GetHashCode(Path.GetFileName(filename));
                    foreach (CacheItemNode node in file_browser.Nodes[0].Nodes[sub_archive].Nodes)
                    {
                        if (Cache.SubArchives[sub_archive].FileNames[node.FileIndex] == name)
                        {
                            n = node;
                            break;
                        }
                    }
                }
            }

            if (WriteFile(filename, archive, sub_archive, n))
            {
                if (sub_archive != -1)
                {
                    if (!found)
                    {
                        file_browser.Nodes[archive].Nodes[sub_archive].Nodes.Add(n);
                        string f = file_browser.Nodes[archive].Nodes[sub_archive].Text.Substring(0, file_browser.Nodes[archive].Nodes[sub_archive].Text.IndexOf('('));
                        file_browser.Nodes[archive].Nodes[sub_archive].Text = f + "(" + Cache.SubArchives[sub_archive].FileCount + " files)";
                    }
                    else
                    {
                        string f = n.Text.Substring(0, n.Text.LastIndexOf('('));
                        n.Text = f + "(" + GetSizeLabel(n.Size) + ")";
                    }
                }
                else
                {
                    file_browser.Nodes[archive].Nodes.Add(n);
                    string f = file_browser.Nodes[archive].Text.Substring(0, file_browser.Nodes[archive].Text.IndexOf('('));
                    file_browser.Nodes[archive].Text = f + "(" + Cache.Archives[archive].GetFileCount() + " files)";
                }
            }
            else
            {
                MessageBox.Show("Failed to find plugin.", "Error Importing", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            if (n == selected_node)
            {
                DeterminePlugins();
                UpdateFileInfo();
            }
        }
Exemple #14
0
 private byte[] GetNodeData(CacheItemNode node)
 {
     byte[] b = null;
     if (node.SubArchive == 0)
         return new byte[0];
     if (node.SubArchive == -1)
     {
         b = Cache.Archives[node.Archive].ExtractFile(node.FileIndex);
     }
     else
     {
         b = Cache.SubArchives[node.SubArchive].ExtractFile(node.FileIndex).Buffer;
     }
     return b;
 }
Exemple #15
0
        private bool Search(CacheItemNode node, int file, int archive, int sub, string file_text)
        {
            if (node.FileIndex != -1)
            {
                if ((node.SubArchive != -1 && Cache.SubArchives[node.SubArchive].GetFileIndex(file) == node.FileIndex) || node.Name.ToLower().Contains(file_text))
                {
                    node.BackColor = Color.Cyan;
                    //node.Text = search_box.GetText(0).ToLower();
                    search_count++;
                    if (search_count == 1)
                        file_browser.SelectedNode = node;
                    return true;
                }
                return false;
            }

            if (archive != -1 && node.Archive != archive)
                return false;
            if (sub != -1 && node.SubArchive != sub && node.SubArchive != -1)
                return false;

            bool found = false;
            foreach (CacheItemNode archive_node in node.Nodes)
            {
                if (Search(archive_node, file, archive, sub, file_text))
                {
                    node.BackColor = Color.Cyan;
                    found = true;
                }
            }

            return found;
        }
Exemple #16
0
 private void file_browser_DragLeave(object sender, EventArgs e)
 {
     if (last_highlight_node != null)
     {
         last_highlight_node.BackColor = last_highlight_color;
         last_highlight_node = null;
     }
 }
Exemple #17
0
 private void PopulateFileBrowser()
 {
     file_browser.Nodes.Clear();
     for (int i = 0; i < 5; i++)
     {
         CacheItemNode node = new CacheItemNode(Cache.Archives[i].ArchiveName + " (" + Cache.Archives[i].GetFileCount() + " files)", Cache.Archives[i].ArchiveName, i, -1, -1, 0);
         for (int k = 0; k < Cache.Archives[i].GetFileCount(); k++)
         {
             if (i > 0)
             {
                 node.Nodes.Add(NewNode(i, -1, k));
             }
             else
             {
                 byte[] buf = Cache.Archives[0].ExtractFile(k);
                 Cache.SubArchives.Add(new SubArchive(Cache.Archives[0].ExtractFile(k)));
                 string s_name = "Sub-archive " + k;
                 if (k < Cache.SubNames.Length)
                 {
                     s_name = Cache.SubNames[k];
                 }
                 CacheItemNode sub = new CacheItemNode(s_name + " (" + Cache.SubArchives[k].FileCount + " files)", s_name, i, k, -1, 0);
                 for (int j = 0; j < Cache.SubArchives[k].FileCount; j++)
                 {
                     sub.Nodes.Add(NewNode(i, k, j));
                 }
                 node.Nodes.Add(sub);
             }
         }
         file_browser.Nodes.Add(node);
     }
 }
Exemple #18
0
        public bool Write(Cache cache, CacheItemNode node, DataBuffer original)
        {
            try
            {
                DataBuffer index_data = cache.SubArchives[node.SubArchive].ExtractFile("index.dat");
                original.Location = 0;
                index_data.Location = original.ReadShort() + 4;
                byte pcount = index_data.ReadByte();
                if (pcount >= Palette.Length)
                    index_data.Location -= 5;
                else //move to back
                {
                    index_data.Location = index_data.Buffer.Length;
                    byte[] temp = new byte[index_data.Buffer.Length + 12 + Palette.Length * 3];
                    Array.Copy(index_data.Buffer, temp, index_data.Buffer.Length);
                    index_data.Buffer = temp;
                }
                IndexLocation = index_data.Location;
                index_data.WriteShort(WholeWidth);
                index_data.WriteShort(WholeHeight);
                index_data.WriteByte((byte)Palette.Length);
                for (int i = 0; i < Palette.Length - 1; i++)
                {
                    index_data.WriteByte(Palette[i].R);
                    index_data.WriteByte(Palette[i].G);
                    index_data.WriteByte(Palette[i].B);
                }
                index_data.WriteByte((byte)XOffset);
                index_data.WriteByte((byte)YOffset);
                index_data.WriteShort(Width);
                index_data.WriteShort(Height);

                index_data.WriteByte(0); //x, y (1 is y, x)
                byte[] data = new byte[Width * Height + 2];
                data[0] = (byte)(IndexLocation >> 8);
                data[1] = (byte)IndexLocation;
                for (int i = 0; i < Width * Height; i++)
                {
                    //todo: optimize
                    Color c = Pixels[i];
                    for (int k = 0; k < Palette.Length; k++)
                    {
                        if (Palette[k].R == c.R && Palette[k].G == c.G && Palette[k].B == c.B && Palette[k].A == c.A)
                        {
                            if (c.A == 0)
                                data[i + 2] = 0;
                            else
                                data[i + 2] = (byte)(k + 1);
                        }
                    }
                }

                cache.SubArchives[node.SubArchive].WriteFile("index.dat", index_data.Buffer);
                cache.SubArchives[node.SubArchive].WriteFile(node.FileIndex, data);
                cache.SubArchives[node.SubArchive].RewriteArchive();
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
Exemple #19
0
 public RSImage(Cache cache, CacheItemNode node, DataBuffer image_data, int sprite_index = 0)
     : this(cache.SubArchives[node.SubArchive], image_data, sprite_index)
 {
 }
Exemple #20
0
        private bool WriteFile(string filename, int archive, int sub_archive, CacheItemNode n)
        {
            string ext = Path.GetExtension(filename).ToLower();
            foreach (IPlugin plugin in Plugins.Plugins)
            {
                if (plugin.FileExtensions != "")
                {
                    string[] tes = plugin.FileExtensions.Split('|');
                    foreach (string s in tes)
                    {
                        if (s.Replace("*", "").ToLower() == ext.ToLower())
                        {
                            CacheItemNode temp = plugin.Node;
                            plugin.Node = n;
                            plugin.Cache = Cache;
                            bool b = plugin.OnImport(filename);
                            if (b)
                            {
                                plugin.Node.Size = plugin.Data.Buffer.Length;
                                plugin.Node.Text = plugin.Node.Name + " (" + GetSizeLabel(plugin.Node.Size) + ")";
                            }
                            plugin.Node = temp;
                            return b;
                        }
                    }
                }
            }

            return false;
        }
Exemple #21
0
        private void DeterminePlugins()
        {
            tbPlugins.TabPages.Clear();
            CacheItemNode node = (CacheItemNode)file_browser.SelectedNode;

            foreach (IPlugin p in Plugins.Plugins)
            {
                if (p.Classifications != null)
                {
                    if (p.Classifications.Archives.Length != 0 && !p.Classifications.Archives.Any(node.Archive.Equals))
                    {
                        continue;
                    }
                    if (p.Classifications.SubArchives.Length != 0 && !p.Classifications.SubArchives.Any(node.SubArchive.Equals))
                    {
                        continue;
                    }
                    if (p.Classifications.Filenames.Length != 0)
                    {
                        bool found = false;
                        foreach (string s in p.Classifications.Filenames)
                        {
                            if (node.Name.ToLower() == s.ToLower())
                            {
                                found = true;
                                break;
                            }
                        }
                        if (!found)
                        {
                            continue;
                        }
                    }
                    if (p.Classifications.FileExtensions.Length != 0)
                    {
                        int ext = node.Name.LastIndexOf(".");
                        if (ext == -1)
                        {
                            continue;
                        }
                        string s     = node.Name.Substring(ext + 1).ToLower();
                        bool   found = false;
                        foreach (string e in p.Classifications.FileExtensions)
                        {
                            if (e.ToLower() != s)
                            {
                                continue;
                            }
                            found = true;
                            break;
                        }
                        if (!found)
                        {
                            continue;
                        }
                    }
                }

                p.Cache = Cache;
                p.Data  = new DataBuffer(GetNodeData(node));
                p.Node  = node;
                PluginTabPage page = new PluginTabPage(p.Name, p);
                foreach (Control c in p.Controls)
                {
                    page.Controls.Add(c);
                }

                if (p.Dominant)
                {
                    tbPlugins.TabPages.Insert(0, page);
                }
                else
                {
                    tbPlugins.TabPages.Add(page);
                }
            }
            tbPlugins.SelectedIndex = (tbPlugins.TabPages.Count > 0 ? 0 : -1);
            file_browser.Focus();
            tbPlugins_SelectedIndexChanged(this, null);
        }
Exemple #22
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (txtExt.Text.Length == 0)
            {
                txtExt.Text = c_plugins[cboType.SelectedIndex].Extension;
            }

            IPlugin p = c_plugins[cboType.SelectedIndex].Plugin;
            p.Cache = Cache;
            int archive = (rbArchive.Checked ? cboArchive.SelectedIndex : 0);
            int sub = (rbSub.Checked ? cboSub.SelectedIndex : -1);

            if (p.Classifications != null)
            {
                if (p.Classifications.Archives.Length != 0 && !p.Classifications.Archives.Any(archive.Equals))
                    goto Failed;
                if (p.Classifications.SubArchives.Length != 0 && !p.Classifications.SubArchives.Any(sub.Equals))
                    goto Failed;
            }

            try
            {
                CacheItemNode n = new CacheItemNode("", "", archive, sub, 0, 0);

                if (rbArchive.Checked)
                {
                    progressBar1.Maximum = Cache.Archives[cboArchive.SelectedIndex].GetFileCount();
                    progressBar1.Value = 0;
                    for (int i = 0; i < Cache.Archives[cboArchive.SelectedIndex].GetFileCount(); i++)
                    {
                        string filename = txtDest.Text + System.IO.Path.DirectorySeparatorChar + txtExt.Text;
                        filename = filename.Replace("*", i.ToString());
                        n.FileIndex = i;
                        p.Node = n;
                        p.Data = new DataBuffer(Cache.Archives[cboArchive.SelectedIndex].ExtractFile(i));
                        if (p.Data.Buffer != null && p.Data.Buffer.Length > 0)
                            p.OnExport(filename);
                        else
                        {
                            try
                            {
                                System.IO.File.Create(filename);
                            }
                            catch (Exception)
                            {
                            }
                        }

                        progressBar1.Value++;
                        Application.DoEvents();
                    }
                }
                else
                {
                    progressBar1.Maximum = Cache.SubArchives[cboSub.SelectedIndex].FileCount;
                    progressBar1.Value = 0;
                    for (int i = 0; i < Cache.SubArchives[cboSub.SelectedIndex].FileCount; i++)
                    {
                        string name;
                        if (!FilesLoader.Files.TryGetValue(Cache.SubArchives[sub].FileNames[i], out name))
                        {
                            name = i.ToString();
                        }
                        string filename = txtDest.Text + System.IO.Path.DirectorySeparatorChar + txtExt.Text;
                        filename = filename.Replace("*", name);
                        n.FileIndex = i;
                        p.Node = n;
                        p.Data = Cache.SubArchives[sub].ExtractFile(i);
                        if (p.Data.Buffer != null && p.Data.Buffer.Length > 0)
                            p.OnExport(filename);

                        progressBar1.Value++;
                        Application.DoEvents();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error dumping data.\n\n" + ex.Message + "\n\n" + ex.StackTrace, "Error Dumping Data", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            progressBar1.Value = 0;
            return;

            Failed:
            MessageBox.Show("The export type is not supported for the selected files.", "Cannot Dump", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
Exemple #23
0
 private void ResetSearch(CacheItemNode node)
 {
     node.BackColor = SystemColors.Window;
     foreach (CacheItemNode n in node.Nodes)
         ResetSearch(n);
 }
Exemple #24
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (txtExt.Text.Length == 0)
            {
                txtExt.Text = c_plugins[cboType.SelectedIndex].Extension;
            }

            IPlugin p = c_plugins[cboType.SelectedIndex].Plugin;

            p.Cache = Cache;
            int archive = (rbArchive.Checked ? cboArchive.SelectedIndex : 0);
            int sub     = (rbSub.Checked ? cboSub.SelectedIndex : -1);

            if (p.Classifications != null)
            {
                if (p.Classifications.Archives.Length != 0 && !p.Classifications.Archives.Any(archive.Equals))
                {
                    goto Failed;
                }
                if (p.Classifications.SubArchives.Length != 0 && !p.Classifications.SubArchives.Any(sub.Equals))
                {
                    goto Failed;
                }
            }

            try
            {
                CacheItemNode n = new CacheItemNode("", "", archive, sub, 0, 0);

                if (rbArchive.Checked)
                {
                    progressBar1.Maximum = Cache.Archives[cboArchive.SelectedIndex].GetFileCount();
                    progressBar1.Value   = 0;
                    for (int i = 0; i < Cache.Archives[cboArchive.SelectedIndex].GetFileCount(); i++)
                    {
                        string filename = txtDest.Text + System.IO.Path.DirectorySeparatorChar + txtExt.Text;
                        filename    = filename.Replace("*", i.ToString());
                        n.FileIndex = i;
                        p.Node      = n;
                        p.Data      = new DataBuffer(Cache.Archives[cboArchive.SelectedIndex].ExtractFile(i));
                        if (p.Data.Buffer != null && p.Data.Buffer.Length > 0)
                        {
                            p.OnExport(filename);
                        }
                        else
                        {
                            try
                            {
                                System.IO.File.Create(filename);
                            }
                            catch (Exception)
                            {
                            }
                        }

                        progressBar1.Value++;
                        Application.DoEvents();
                    }
                }
                else
                {
                    progressBar1.Maximum = Cache.SubArchives[cboSub.SelectedIndex].FileCount;
                    progressBar1.Value   = 0;
                    for (int i = 0; i < Cache.SubArchives[cboSub.SelectedIndex].FileCount; i++)
                    {
                        string name;
                        if (!FilesLoader.Files.TryGetValue(Cache.SubArchives[sub].FileNames[i], out name))
                        {
                            name = i.ToString();
                        }
                        string filename = txtDest.Text + System.IO.Path.DirectorySeparatorChar + txtExt.Text;
                        filename    = filename.Replace("*", name);
                        n.FileIndex = i;
                        p.Node      = n;
                        p.Data      = Cache.SubArchives[sub].ExtractFile(i);
                        if (p.Data.Buffer != null && p.Data.Buffer.Length > 0)
                        {
                            p.OnExport(filename);
                        }

                        progressBar1.Value++;
                        Application.DoEvents();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error dumping data.\n\n" + ex.Message + "\n\n" + ex.StackTrace, "Error Dumping Data", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            progressBar1.Value = 0;
            return;

Failed:
            MessageBox.Show("The export type is not supported for the selected files.", "Cannot Dump", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
Exemple #25
0
        private void file_browser_AfterSelect(object sender, TreeViewEventArgs e)
        {
            if (e.Node == null)
                return;
            if (((CacheItemNode)e.Node).SubArchive != -1)
                saveCurrentToolStripMenuItem.Enabled = true;
            else
                saveCurrentToolStripMenuItem.Enabled = false;
            if (e.Node.Nodes.Count > 0 || ((CacheItemNode)e.Node).FileIndex == -1)
                return;

            selected_node = (CacheItemNode)e.Node;
            btnImport.Enabled = true;
            btnExport.Enabled = true;
            if (selected_node.SubArchive != -1)
            {
                btnRename.Enabled = true;
            }
            else
            {
                btnRename.Enabled = false;
                saveCurrentToolStripMenuItem.Enabled = false;
            }

            DeterminePlugins();
            UpdateFileInfo();
        }