Пример #1
0
        //生成资源描述文件
        public static void GenResDescFile(List <ResouceElement> resList, string patchPath, string resDescFileName, out uint resDescFileCrc)
        {
            string       tmpFileListPath = patchPath + "/" + resDescFileName;
            FileStream   fs = new FileStream(tmpFileListPath, FileMode.Create, FileAccess.Write);
            MemoryStream ms = new MemoryStream();
            BinaryWriter bw = new BinaryWriter(ms);

            bw.Write(resList.Count);//写入数量

            for (int i = 0; i < resList.Count; i++)
            {
                ResouceElement resElement = resList[i];
                bw.Write(resElement.keyHash);  //写入文件KeyHash
                bw.Write(resElement.fileHash); //写入文件FileHash
                bw.Write((byte)resElement.resType);
                bw.Write(resElement.fileSize);
            }

            bw.Flush();
            ms.WriteTo(fs);
            bw.Close();
            ms.Close();
            fs.Close();

            resDescFileCrc = Crc.Crc32(resDescFileName + ComputeMD5(tmpFileListPath));
            File.Move(tmpFileListPath, $"{patchPath}/{resDescFileCrc}");
        }
Пример #2
0
        //构建资源描述
        public static List <ResouceElement> GetResouceElements(string path, ResouceElement.EResType resType, string prefix)
        {
            List <ResouceElement> tmpElemList = new List <ResouceElement>();
            List <string>         tmpFiles    = GetFiles(path, "*.*", new string[] { ".manifest" });

            for (int i = 0; i < tmpFiles.Count; i++)
            {
                ResouceElement tmpElem = new ResouceElement();
                tmpElem.filePath = tmpFiles[i].Replace("\\", "/");
                tmpElem.key      = prefix + tmpElem.filePath.Replace(path, "");
                tmpElem.keyHash  = Crc.Crc32(tmpElem.key);
                tmpElem.fileHash = Crc.Crc32(tmpElem.key + ComputeMD5(tmpElem.filePath));
                tmpElem.resType  = resType;

                var tmpFileInfo = new FileInfo(tmpFiles[i]);
                tmpElem.fileSize = (ushort)(tmpFileInfo.Length / 1024f);
                tmpElem.fileSize = tmpElem.fileSize > 0 ? tmpElem.fileSize : (ushort)1;

                tmpElemList.Add(tmpElem);
            }

            return(tmpElemList);
        }