您的位置:程序门 -> .net技术 -> c#



如何将多个文件打包成一个文件?(300分求解)


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


如何将多个文件打包成一个文件?(300分求解)
发表于:2007-02-14 15:16:51 楼主
看到许多软件皮肤被打包成一个文件,却可以用zip/rar一类的软件打开。而用zip/rar压缩后却和原来的打包文件大小不一样(估计格式肯定不一样)

我发现有个规律是:被打包的n个文件“在磁盘上所占的大小”==“打包文件的大小”(请仔细理解这句话),也就是说,好像此打包文件是一个“目录”,它里面的文件并没有被压缩,而是按照一定的方式组织起来了(用fat32方式组织的?不知道),所以才有上面的规律。

哪位曾经研究过吗?请帮忙,谢谢了。

如能帮助解决,我愿意另开贴,再送100分。再次谢谢。

帮顶的也送分,结贴时送。

另外200分在此贴:
http://community.csdn.net/expert/topic/5280/5280434.xml?temp=.3603937
结贴时一同给出
发表于:2007-02-14 15:22:161楼 得分:0
沙发,顶!
发表于:2007-02-14 15:23:242楼 得分:0
我觉得用wise打包较好,至于多个文件都不是问题,最后就一个exe
发表于:2007-02-14 15:25:503楼 得分:0
轻轻的我来了
轻轻的我带着分走了
发表于:2007-02-14 15:27:404楼 得分:0
楼主标题没有整对~

看了半天不知道描述的问题主体
发表于:2007-02-14 15:28:575楼 得分:0
http://www.icsharpcode.com/opensource/sharpziplib/default.aspx

http://www.codeproject.com/csharp/vmeasyzipunzip.asp

发表于:2007-02-14 15:29:426楼 得分:0
是那个皮肤压缩软件吗?
发表于:2007-02-15 11:31:277楼 得分:0
你是想问这种打包文件的内部格式吧?
发表于:2007-02-15 12:50:578楼 得分:0
帮、顶
发表于:2007-02-15 13:22:339楼 得分:0
to:jimh(jimmy)  

是啊,怎么设计才能实现那种结构呢
发表于:2007-02-15 13:44:2810楼 得分:0
不就是一个压缩文件吗?可以sharezip开源的c#你去看看吧!
发表于:2007-02-15 14:01:1311楼 得分:0
帮顶
发表于:2007-02-15 15:37:4212楼 得分:0
up
发表于:2007-02-15 15:52:1913楼 得分:0
from   http://www.cnblogs.com/aiyagaze/archive/2006/11/30/576995.html

using   system;
using   system.text;
using   system.runtime.serialization;
using   system.runtime.serialization.formatters.binary;
using   system.collections;
using   system.io;
using   system.io.compression;

namespace   greatchn.gzipcompression
{
        public   class   gzipcompress
        {
                /**////   <summary>
                ///   对目标文件夹进行压缩,将压缩结果保存为指定文件
                ///   </summary>
                ///   <param   name= "dirpath "> 目标文件夹 </param>
                ///   <param   name= "filename "> 压缩文件 </param>
                public   static   void   compress(string   dirpath,   string   filename)
                {
                        arraylist   list   =   new   arraylist();
                        foreach   (string   f   in   directory.getfiles(dirpath))
                        {
                                byte[]   destbuffer   =   file.readallbytes(f);
                                serializefileinfo   sfi   =   new   serializefileinfo(f,   destbuffer);
                                list.add(sfi);
                        }
                        iformatter   formatter   =   new   binaryformatter();
                        using   (stream   s   =   new   memorystream())
                        {
                                formatter.serialize(s,   list);
                                s.position   =   0;
                                createcompressfile(s,   filename);
                        }
                }

                /**////   <summary>
                ///   对目标压缩文件解压缩,将内容解压缩到指定文件夹
                ///   </summary>
                ///   <param   name= "filename "> 压缩文件 </param>
                ///   <param   name= "dirpath "> 解压缩目录 </param>
                public   static   void   decompress(string   filename,   string   dirpath)
                {
                        using   (stream   source   =   file.openread(filename))
                        {
                                using   (stream   destination   =   new   memorystream())
                                {
                                        using   (gzipstream   input   =   new   gzipstream(source,   compressionmode.decompress,   true))
                                        {
                                                byte[]   bytes   =   new   byte[4096];
                                                int   n;
                                                while   ((n   =   input.read(bytes,   0,   bytes.length))   !=   0)
                                                {
                                                        destination.write(bytes,   0,   n);
                                                }
                                        }
                                        destination.flush();
                                        destination.position   =   0;
                                        deserializefiles(destination,   dirpath);
                                }
                        }
                }

                private   static   void   deserializefiles(stream   s,   string   dirpath)
                {
                        binaryformatter   b   =   new   binaryformatter();
                        arraylist   list   =   (arraylist)b.deserialize(s);

                        foreach   (serializefileinfo   f   in   list)
                        {
                                string   newname   =   dirpath   +   path.getfilename(f.filename);
                                using   (filestream   fs   =   new   filestream(newname,   filemode.create,   fileaccess.write))
                                {
                                        fs.write(f.filebuffer,   0,   f.filebuffer.length);
                                        fs.close();
                                }
                        }
                }

                private   static   void   createcompressfile(stream   source,   string   destinationname)
                {
                        using   (stream   destination   =   new   filestream(destinationname,   filemode.create,   fileaccess.write))
                        {
                                using   (gzipstream   output   =   new   gzipstream(destination,   compressionmode.compress))
                                {
                                        byte[]   bytes   =   new   byte[4096];
                                        int   n;
                                        while   ((n   =   source.read(bytes,   0,   bytes.length))   !=   0)
                                        {
                                                output.write(bytes,   0,   n);
                                        }
                                }
                        }
                }

                [serializable]
                class   serializefileinfo
                {
                        public   serializefileinfo(string   name,   byte[]   buffer)
                        {
                                filename   =   name;
                                filebuffer   =   buffer;
                        }

                        string   filename;
                        public   string   filename
                        {
                                get
                                {
                                        return   filename;
                                }
                        }

                        byte[]   filebuffer;
                        public   byte[]   filebuffer
                        {
                                get
                                {
                                        return   filebuffer;
                                }
                        }
                }
        }
}
发表于:2007-02-15 16:05:3814楼 得分:0
up


快速检索

热门点击