Exemple #1
0
        private void PopulateTreeView(SCI32ResourceDirectoryCollection resourceCollection)
        {
            this.resourceView.Nodes.Clear();
            for (int i = 0; i < resourceCollection.Count; i++)
            {
                SCI32ResourceDirectory dir = resourceCollection[i];
                // these are our directories
                TreeNode dirNode = new TreeNode(dir.GetDirectoryNameByType(dir.Type), Icons.GetIconIndex(Helpers.Icon.ClosedFolder), Icons.GetIconIndex(Helpers.Icon.ClosedFolder));
                dirNode.Name = dir.GetDirectoryNameByType(dir.Type);
                dirNode.Tag  = "Directory";
                for (int j = 0; j < dir.Resources.Count; j++)
                {
                    SCI32Resource res = dir.Resources[j];
                    // We want a filename

                    TreeNode childNode = new TreeNode(res.FileName, Icons.GetIconIndexByType(res.ResourceType), Icons.GetIconIndexByType(res.ResourceType));
                    childNode.Name = res.FileName;
                    childNode.Tag  = "File";
                    // check here for duplicates
                    dirNode.Nodes.Add(childNode);
                }
                dirNode.SortAllChildNodes();
                this.resourceView.Nodes.Add(dirNode);
            }
        }
Exemple #2
0
        private void extractToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TreeNode      node = this.resourceView.SelectedNode;
            SCI32Resource res  = null;

            try
            {
                if (this.ResourceDirectories.TryGetResourceByFilename(node.Name, out res))
                {
                    string ext = SCI32Resource.ExtentionFromResourceType(res.ResourceType);
                    saveFileDialog1.Filter   = string.Format("SCI32 {0}|{1}", res.ResourceType, ext);
                    saveFileDialog1.FileName = res.FileName;
                    DialogResult result = saveFileDialog1.ShowDialog();
                    if (result == System.Windows.Forms.DialogResult.OK)
                    {
                        byte[] file = new byte[res.FileData.Length - 8];
                        Array.Copy(res.FileData, 8, file, 0, file.Length);
                        string _file = Encoding.Default.GetString(file);
                        try
                        {
                            bool compresed = res.CompressedLength != res.UnCompressedLength;
                            if (compresed)
                            {
                                LZWDecoder decoder = new LZWDecoder();
                                string     sfile   = decoder.Decode(_file);
                                //file = Encoding.ASCII.GetBytes(sfile);
                            }
                            File.WriteAllBytes(saveFileDialog1.FileName, file);
                        }
                        catch (Exception ex) { MessageBox.Show(string.Format("Unable to save file {0}, Error was {1}", res.FileName, ex.Message)); }
                    }
                }
            }
            catch { }
        }
 public bool TryGetResourceByFilename(string fileName, out SCI32Resource resource)
 {
     resource = null;
     try
     {
         for (int i = 0; i < this.Count; i++)
         {
             SCI32ResourceDirectory dir = this[i];
             if (dir == null)
             {
                 return(false);
             }
             for (int j = 0; j < dir.Resources.Count; j++)
             {
                 SCI32Resource res = dir.Resources[j];
                 if (res == null)
                 {
                     return(false);
                 }
                 if (res.FileName.ToLower() == fileName.ToLower())
                 {
                     resource = dir.Resources[j];
                 }
             }
         }
     }
     catch { }
     return(resource != null);
 }
 private void PopulateResmapResources()
 {
     // we read our ressci file, in a nested loop
     for (int i = 0; i < this.Count; i++)
     {
         SCI32ResourceDirectory sci32Dir = this[i];
         for (int j = 0; j < this[i].Resources.Count; j++)
         {
             SCI32Resource res = sci32Dir.Resources[j];
             this.ressciReader.Seek(res.Offset, SeekOrigin.Begin);
             // Compare resources
             SCI32ResourceType type = SCI32Resource.GetResourceType(this.ressciReader.ReadByte());
             //if(type != res.ResourceType)
             //{ throw new IOException(string.Format("Type Mismatch {0} for {1} should be {2}.", type, res.ID, res.ResourceType)); }
             ushort id = this.ressciReader.ReadUInt16();
             if (res.ID != id)
             {
                 throw new IOException(string.Format("ID {0} Mismatch for {1}.", id, res.ID));
             }
             try
             {
                 // Ok we passed the compare get our lengths
                 res.SetLengths(this.ressciReader.ReadInt32(), this.ressciReader.ReadInt32());
                 // Are we compressed ?
                 bool compressed = res.UnCompressedLength != res.CompressedLength;
                 if (compressed)
                 {
                     res.AddFileData(this.ressciReader.ReadBytes(res.CompressedLength));
                 }
                 else
                 {
                     res.AddFileData(this.ressciReader.ReadBytes(res.UnCompressedLength));
                 }
             }
             catch (Exception ex) { throw new IOException(string.Format("Unable to load filedata from {0} into resource. Error was {1}", this.RessciFileName, ex.Message)); }
         }
     }
 }
Exemple #5
0
        private void resourceView_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            if (e.Button == System.Windows.Forms.MouseButtons.Right)
            {
                this.resourceView.SelectedNode = e.Node;
                this.nodeMenu.Items[0].Text    = string.Format("Extract {0}.", e.Node.Name);
                this.nodeMenu.Show(System.Windows.Forms.Cursor.Position);
            }
            // Stop the icon change of a directory.
            int currentIndex = -1;

            if (e.Node.Tag.ToString() == "Directory")
            {
                currentIndex = e.Node.ImageIndex; this.nodeOutput.Text = string.Format("Directory {0} contains {1} entries.", e.Node.Name, e.Node.Nodes.Count);
            }
            if (currentIndex != -1)
            {
                e.Node.SelectedImageIndex = currentIndex;
            }
            // Get the resource this node represents
            SCI32Resource res = null;

            if (this.ResourceDirectories.TryGetResourceByFilename(e.Node.Name, out res))
            {
                string fileInfo = string.Format("ID: {0}, at Offset {1} Compressed Length {2}, Uncompressed length {3}, Length {4}, is Compressed ? {5}, Filename: {6}",
                                                res.ID, res.Offset, res.CompressedLength, res.UnCompressedLength, res.FileData.Length, res.CompressedLength == res.UnCompressedLength ? "No" : "Yes", res.FileName);
                this.nodeOutput.Text = fileInfo;
                this.rtfOutput.Clear();
                this.rtfOutput.AppendText(Globals.NiceHexOutput(res.FileData));
                // Show bytes if button selected
                //   if (toolStripViewHex.Checked)
                // {
                //     this.rtfOutput.Clear();
                //    this.rtfOutput.AppendText(Globals.NiceHexOutput(res.FileData));
                //}
            }
        }
        // Fix this
        private void PopulateResmapResourceData(int lengthOfFile)
        {
            // We have our dir's once we begin at the offset of the first dir, then we load the amount of entires we know
            // then move onto the next
            // get our first directory, start there work our way on

            /*
             * SCI32ResourceDirectory dir = this[0];
             * this.resmapReader.Seek(dir.Offset, SeekOrigin.Begin);
             * // start reading
             * while (this.resmapReader.CurrentPosition != this.resmapReader.Length )
             * {
             *  SCI32ResourceType type = SCI32Resource.GetResourceType(this.resmapReader.ReadByte());
             *  if (TryGetDirectoryByType(type, out dir))
             *  {
             *      try
             *      {
             *          dir.AddResource(new SCI32Resource(type, this.resmapReader.ReadUInt16(), this.resmapReader.ReadUInt32()));
             *      }
             *      catch { SCI32Tools.Messageproxy.WriteLine("Erored"); }
             *  }
             * }
             *
             */

            // bad

            // need to generate the lengths of each data block here, its the prior offset - the next one
            long currentOffset = 0;
            long nextOffset    = 0;
            int  length        = 0;

            try
            {
                for (int i = 0; i < this.Count; i++)
                {
                    currentOffset = this[i].Offset;
                    if (this.Count >= i + 2)
                    {
                        nextOffset         = this[i + 1].Offset;
                        length             = (int)(nextOffset - currentOffset);
                        this[i].DataLength = length;
                        this[i].Entries    = length / 6;
                    }
                    else
                    {
                        // EOF
                        nextOffset         = (int)resmapReader.Length;
                        length             = (int)(nextOffset - currentOffset);
                        this[i].DataLength = length;
                        this[i].Entries    = length / 6;
                    }
                }
            }
            catch (Exception ex) { throw new IOException(string.Format("Unable to parse Resource Directories from file {0}. Error was {1}", this.ResmapFileName, ex.Message)); }

            /*
             * List<uint> offsets = new List<uint>();
             * for (int i = 0; i < this.Count; i++)
             * {
             *   offsets.Add(this[i].Offset);
             * }
             *
             * int processed = 0;
             * while (processed != offsets.Count)
             * {
             *   for (int i = 0; i < this.Count; i++)
             *   {
             *       SCI32ResourceDirectory dir = this[i];
             *
             *           if (offsets.Count < (i + 1))
             *           {
             *               dir.DataLength = (int)(offsets[(i + 1)] - offsets[i]);
             *               dir.Entries = dir.DataLength / 6;
             *           }
             *           else
             *           {
             *               dir.DataLength = (int)(lengthOfFile - offsets[i]);
             *               dir.Entries = dir.DataLength / 6;
             *           }
             *           processed++;
             *   }
             * } */
            // Second Stage
            byte[]            resourceData = null;
            SCI32Tools.Reader r            = null;
            for (int i = 0; i < this.Count; i++)
            {
                SCI32ResourceDirectory sci32Dir = this[i];
                try
                {
                    this.resmapReader.Seek(sci32Dir.Offset, SeekOrigin.Begin);
                    resourceData = this.resmapReader.ReadBytes(sci32Dir.DataLength);
                    r            = new SCI32Tools.Reader(resourceData);
                    while (r.CurrentPosition != r.Length)
                    {
                        if (StopProcessing)
                        {
                            break;
                        }
                        SCI32Resource res = new SCI32Resource(sci32Dir.Type, r.ReadUInt16(), r.ReadUInt32());
                        sci32Dir.AddResource(res);
                    }
                }
                catch (Exception ex) { throw new IOException(string.Format("Unable to parse Resources from file {0}. Error was {1}", this.ResmapFileName, ex.Message)); }
            }
        }