当前位置: 首页>>代码示例>>C#>>正文


C# FileStream.extractPiece方法代码示例

本文整理汇总了C#中System.IO.FileStream.extractPiece方法的典型用法代码示例。如果您正苦于以下问题:C# FileStream.extractPiece方法的具体用法?C# FileStream.extractPiece怎么用?C# FileStream.extractPiece使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.FileStream的用法示例。


在下文中一共展示了FileStream.extractPiece方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Unpack

        private void Unpack()
        {
            if (_FILEPATH == null) return;

            using (FileStream fs = new FileStream(_FILEPATH, FileMode.Open))
            { 
                int fileNum = fs.extractPiece(0, 4, 4).extractInt32() + 1;
                int headerSize = fs.extractPiece(0, 4).extractInt32() * 0x800;
                int[] offsets = new int[fileNum];
                string fileName = Path.GetFileNameWithoutExtension(_FILEPATH);
                byte[] data;

                MemoryStream header = new MemoryStream(fs.extractPiece(0, headerSize, 0));
                header.Position = 8;

                for (int i = 0; i < fileNum; i++)
                {
                    offsets[i] = header.extractPiece(0, 4).extractInt32() * 0x800;
                    _INDEX.Add(new Indexes(offsets[i]));
                }

                string basePath = Path.Combine(Path.GetDirectoryName(_FILEPATH), fileName);
                for (int i = 0; i < fileNum - 1; i++)
                {
                    
                    List<TreeNode> tn = new List<TreeNode>();

                    data = fs.extractPiece(0, offsets[i + 1] - offsets[i]);
                    if (data[3] == 0x01 && data[2] < 0x10)
                    {

                        int timNum = data.extractInt32(4);
                        int[] timOffsets = new int[timNum + 1];

                        for (int x = 0; x < timNum; x++)
                        {
                            timOffsets[x] = (data.extractInt32((4 * x) + 8) * 4) + 4;
                            _INDEX[i].subOffsets.Add(timOffsets[x]);
                        }
                        _INDEX[i].subOffsets.Add(data.Length);
                        timOffsets[timOffsets.Length - 1] = data.Length;
                        

                        for (int x = 0; x < timOffsets.Length - 1; x++)
                        {
                            string timPath = Path.Combine(basePath, String.Format("{0}_{1}", fileName, i));

                            string ext = (data[timOffsets[x]] == 0x10) ? "TIM" : "BIN";
                                TreeNode tree = new TreeNode(String.Format("{0}_{1}_{2}.{3}", fileName, i, x, ext));
                                if (ext == "TIM")
                                {
                                    tree.ImageIndex = tree.SelectedImageIndex = 1;
                                    tree.Tag = x;
                                    tn.Add(tree);
                                }
                        }
                    }
                    if (tn != null && tn.Count > 0)
                    {
                        TreeNode tree = new TreeNode(String.Format("{0}_{1}.BIN", fileName, i), tn.ToArray());
                        tree.Tag = i;
                        treeView1.Nodes.Add(tree);

                    }             
                }

            }
        }
开发者ID:NetoRpg,项目名称:TIMViwer,代码行数:68,代码来源:Main.cs

示例2: CreateTIM

        void CreateTIM()
        {
            if (_INDEX.Count == 0) return;

            if (treeView1.SelectedNode != null && treeView1.SelectedNode.Parent != null)
            {
                if (treeView1.SelectedNode.SelectedImageIndex == 0) return;

                using (FileStream fs = new FileStream(_FILEPATH, FileMode.Open))
                {
                    if (_INDEX.Count == 0) return;

                    int parentIndex = (int)treeView1.SelectedNode.Parent.Tag;
                    int childrenIndex = (int)treeView1.SelectedNode.Tag;

                    int size = _INDEX[parentIndex].subOffsets[childrenIndex + 1] - _INDEX[parentIndex].subOffsets[childrenIndex];
                    int offset = _INDEX[parentIndex].offset + _INDEX[parentIndex].subOffsets[childrenIndex];

                    tim = new TIM(fs.extractPiece(0, size, offset));

                    changeBPP(bitpp[tim.bpp]);

                }
            }
            ShowTIM();
        }
开发者ID:NetoRpg,项目名称:TIMViwer,代码行数:26,代码来源:Main.cs


注:本文中的System.IO.FileStream.extractPiece方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。