Exemple #1
0
        public override DocumentBase CreateInstance(string fileName)
        {
            if (string.IsNullOrEmpty(fileName))
            {
                return DesignerManager.Instance.CreateDocument(null, CsfDesigner.Extension);
            }
            else
            {
                DevFileLocation fl = new DevFileLocation(fileName);

                BinaryWriter bw = new BinaryWriter(fl.GetStream, Encoding.Default);
                bw.Write((int)StringTableCsfFormat.CsfID);
                bw.Write((int)3);

                bw.Write((int)0);
                bw.Write((int)0);
                bw.Write((int)0);
                bw.Close();

                return DesignerManager.Instance.CreateDocument(fl, CsfDesigner.Extension);
            }
        }
Exemple #2
0
        public override DocumentBase CreateInstance(string fileName)
        {
            if (string.IsNullOrEmpty(fileName))
            {
                return(DesignerManager.Instance.CreateDocument(null, CsfDesigner.Extension));
            }
            else
            {
                DevFileLocation fl = new DevFileLocation(fileName);

                BinaryWriter bw = new BinaryWriter(fl.GetStream, Encoding.Default);
                bw.Write((int)StringTableCsfFormat.CsfID);
                bw.Write((int)3);

                bw.Write((int)0);
                bw.Write((int)0);
                bw.Write((int)0);
                bw.Close();

                return(DesignerManager.Instance.CreateDocument(fl, CsfDesigner.Extension));
            }
        }
Exemple #3
0
        private void okButton_Click(object sender, EventArgs e)
        {
            propertyGrid1.Enabled = false;
            fileListView.Enabled  = false;

            addButton.Enabled    = false;
            removeButton.Enabled = false;
            okButton.Enabled     = false;
            cancelButton.Enabled = false;

            converter.Parameters  = conParams;
            converter.ProgressCBK = new ProgressCBK(this);

            progressBar1.Maximum = fileListView.Items.Count;

            for (int i = 0; i < fileListView.Items.Count; i++)
            {
                string fileName     = (string)fileListView.Items[i].Tag;
                string destFileName = Path.Combine(Path.GetDirectoryName(fileName), Path.GetFileNameWithoutExtension(fileName) + ".tdmp");

                DevFileLocation sfl = new DevFileLocation(fileName);
                DevFileLocation dfl = new DevFileLocation(destFileName);

                converter.Convert(sfl, dfl);
                progressBar1.Value = i + 1;

                Application.DoEvents();
            }

            propertyGrid1.Enabled = true;
            fileListView.Enabled  = true;

            addButton.Enabled    = true;
            removeButton.Enabled = true;
            okButton.Enabled     = true;
            cancelButton.Enabled = true;
        }
Exemple #4
0
        private void button4_Click(object sender, EventArgs e)
        {
            button1.Enabled = false;
            button2.Enabled = false;
            button3.Enabled = false;
            button4.Enabled = false;
            
            DevFileLocation fl = new DevFileLocation(textBox1.Text);

            ContentBinaryWriter bw = new ContentBinaryWriter(fl);

            bw.Write(LpkArchive.FileId);

            int count = listView1.Items.Count;
            bw.Write(count);
            progressBar1.Value = 0; 
            progressBar1.Maximum = count;

            int oldPos = (int)bw.BaseStream.Position;

            ListView.ListViewItemCollection coll = listView1.Items;

           
            LpkArchiveEntry[] entries = new LpkArchiveEntry[count];


            for (int i = 0; i < count; i++)
            {   
                entries[i].Name = Path.GetFileName(coll[i].Text);

                bw.WriteStringUnicode(entries[i].Name);
                bw.Write(entries[i].CompressedSize);
                bw.Write(entries[i].Offset);
                bw.Write(entries[i].Size);
                bw.Write(entries[i].Flag);
            }


            #region 打包文件

            for (int i = 0; i < count; i++)
            {
                FileStream fs = new FileStream(coll[i].Text, FileMode.Open, FileAccess.Read);
                BinaryReader br = new BinaryReader(fs);

                entries[i].Offset = (int)bw.BaseStream.Position;
                entries[i].Size = (int)br.BaseStream.Length;
                entries[i].CompressedSize = entries[i].Size;
                entries[i].Flag = 0;

                bw.Write(br.ReadBytes(entries[i].Size));

                br.Close();

                fs.Close();

                Application.DoEvents(); 
                progressBar1.Value = i + 1;
            }


            CoderPropID[] propIDs = 
            { 
                CoderPropID.DictionarySize,
                CoderPropID.Algorithm
            };
            object[] properties = 
            {
                1048576*8,
                2
            };
            SevenZip.Compression.LZMA.Encoder encoder = new SevenZip.Compression.LZMA.Encoder();

            encoder.SetCoderProperties(propIDs, properties);

            System.IO.MemoryStream propms = new System.IO.MemoryStream();
            encoder.WriteCoderProperties(propms);
            bw.Write((int)propms.Length);
            propms.Close();
            bw.Write(propms.ToArray());

            for (int i = 0; i < count; i++)
            {
                entries[i].Offset = (int)bw.BaseStream.Position;

                FileStream fs = new FileStream(coll[i].Text, FileMode.Open, FileAccess.Read);
                System.IO.MemoryStream ms = new System.IO.MemoryStream((int)fs.Length / 2);

                encoder.Code(fs, ms, -1, -1, null);

                entries[i].Size = (int)fs.Length;

                fs.Close();
                ms.Close();

                byte[] buffer = ms.ToArray();
                bw.Write(buffer);
                entries[i].CompressedSize = buffer.Length;
                entries[i].Flag = 0;

                Application.DoEvents();
                progressBar1.Value = i + 1;
            }
            #endregion


            bw.Seek(oldPos, SeekOrigin.Begin);

            for (int i = 0; i < count; i++)
            {
                bw.WriteStringUnicode(entries[i].Name);
                bw.Write(entries[i].CompressedSize);
                bw.Write(entries[i].Offset);
                bw.Write(entries[i].Size);
                bw.Write(entries[i].Flag);
            }

            bw.Close();

            button1.Enabled = true;
            button2.Enabled = true;
            button3.Enabled = true;
            button4.Enabled = true;
        }
Exemple #5
0
        private void button4_Click(object sender, EventArgs e)
        {
            button1.Enabled = false;
            button2.Enabled = false;
            button3.Enabled = false;
            button4.Enabled = false;

            DevFileLocation fl = new DevFileLocation(textBox1.Text);

            ContentBinaryWriter bw = new ContentBinaryWriter(fl);

            bw.Write(PakArchive.FileId);

            int count = listView1.Items.Count;

            bw.Write(count);
            progressBar1.Value   = 0;
            progressBar1.Maximum = count;

            int oldPos = (int)bw.BaseStream.Position;

            ListView.ListViewItemCollection coll = listView1.Items;


            PakArchiveEntry[] entries = new PakArchiveEntry[count];


            for (int i = 0; i < count; i++)
            {
                entries[i].Name = Path.GetFileName(coll[i].Text);

                bw.WriteStringUnicode(entries[i].Name);
                bw.Write(entries[i].Offset);
                bw.Write(entries[i].Size);
                bw.Write(entries[i].Flag);
            }


            #region 打包文件

            for (int i = 0; i < count; i++)
            {
                FileStream   fs = new FileStream(coll[i].Text, FileMode.Open, FileAccess.Read);
                BinaryReader br = new BinaryReader(fs);

                entries[i].Offset = (int)bw.BaseStream.Position;
                entries[i].Size   = (int)br.BaseStream.Length;
                entries[i].Flag   = 0;

                bw.Write(br.ReadBytes(entries[i].Size));

                br.Close();

                fs.Close();

                Application.DoEvents();
                progressBar1.Value = i + 1;
            }


            //CoderPropID[] propIDs =
            //{
            //    CoderPropID.DictionarySize,
            //    CoderPropID.Algorithm
            //};
            //object[] properties =
            //{
            //    1048576*8,
            //    2
            //};
            //SevenZip.Compression.LZMA.Encoder encoder = new SevenZip.Compression.LZMA.Encoder();

            //encoder.SetCoderProperties(propIDs, properties);

            //System.IO.MemoryStream propms = new System.IO.MemoryStream();
            //encoder.WriteCoderProperties (propms);
            //bw.Write((int)propms.Length);
            //propms.Close();
            //bw.Write(propms.ToArray());

            //for (int i = 0; i < count; i++)
            //{
            //    entries[i].Offset = (int)bw.BaseStream.Position;

            //    FileStream fs = new FileStream(coll[i].Text, FileMode.Open, FileAccess.Read);
            //    System.IO.MemoryStream ms = new System.IO.MemoryStream((int)fs.Length / 2);

            //    encoder.Code(fs, ms, -1, -1, null);

            //    entries[i].Size = (int)fs.Length;

            //    fs.Close();
            //    ms.Close();

            //    byte[] buffer = ms.ToArray();
            //    bw.Write(buffer);
            //    entries[i].CompressedSize = buffer.Length;
            //    entries[i].Flag = 0;

            //    Application.DoEvents();
            //    progressBar1.Value = i + 1;
            //}
            #endregion


            bw.Seek(oldPos, SeekOrigin.Begin);

            for (int i = 0; i < count; i++)
            {
                bw.WriteStringUnicode(entries[i].Name);
                bw.Write(entries[i].Offset);
                bw.Write(entries[i].Size);
                bw.Write(entries[i].Flag);
            }

            bw.Close();

            button1.Enabled = true;
            button2.Enabled = true;
            button3.Enabled = true;
            button4.Enabled = true;
        }
Exemple #6
0
        private void okButton_Click(object sender, EventArgs e)
        {
            propertyGrid1.Enabled = false;
            fileListView.Enabled = false;

            addButton.Enabled = false;
            removeButton.Enabled = false;
            okButton.Enabled = false;
            cancelButton.Enabled = false;

            converter.Parameters = conParams;
            converter.ProgressCBK = new ProgressCBK(this);

            progressBar1.Maximum = fileListView.Items.Count;

            for (int i = 0; i < fileListView.Items.Count; i++)
            {
                string fileName = (string)fileListView.Items[i].Tag;
                string destFileName = Path.Combine(Path.GetDirectoryName(fileName), Path.GetFileNameWithoutExtension(fileName) + ".tdmp");

                DevFileLocation sfl = new DevFileLocation(fileName);
                DevFileLocation dfl = new DevFileLocation(destFileName);

                converter.Convert(sfl, dfl);
                progressBar1.Value = i + 1;

                Application.DoEvents();
            }

            propertyGrid1.Enabled = true;
            fileListView.Enabled = true;

            addButton.Enabled = true;
            removeButton.Enabled = true;
            okButton.Enabled = true;
            cancelButton.Enabled = true;
        }