示例#1
0
        /// <summary>
        /// 解压后的文件整合到预定义的目录结构
        /// </summary>
        /// <param name="info"></param>
        /// <param name="zipName"></param>
        private void FileMoveTo(FilePatchInfo info, string zipName)
        {
            ActionState(State.ApplyPatchZip);
            Dictionary <string, FileDetailInfo> dic;

            if (!patchCache.TryGetValue(info.fileUrl, out dic))
            {
                Debug.LogError("不存在的补丁包!");
                return;
            }

            var folderName = zipName.Replace(Path.GetExtension(zipName), "");
            var list       =
                Directory.GetFiles(folderName, "*.*", SearchOption.AllDirectories)
                .Select(p => p.Replace("\\", "/"))
                .OrderByDescending(p => p.Length)
                .ToList();

            foreach (string s in list)
            {
                var file = s.Replace(folderName + "/", Access.PersistentDataTempPath);
                FileHelper.CreateDirectory(file);
                if (File.Exists(file))
                {
                    File.Delete(file);
                }
                File.Move(s, file);
            }
            Directory.Delete(folderName, true);
        }
示例#2
0
        /// <summary>
        /// 下载记录主资源或补丁列表的文件列表
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        private IEnumerator GetFilePatchCache(FilePatchInfo info)
        {
            if (info.isNeedDownFile)
            {
                ActionState(State.DownPathList);
                yield return(Access.FromRemote(info.fileUrl, res =>
                {
                    if (res == null)
                    {
                        return;
                    }
                    var hash = res.MD5();
                    if (info.IsEncrypt())
                    {
                        if (hash != info.encrypt_hash)
                        {
                            return;
                        }
                    }
                    else
                    {
                        if (hash != info.content_hash)
                        {
                            return;
                        }
                    }
                    File.WriteAllBytes(info.fileLocal, res);
                }));
            }

            ActionState(State.GetPatchList);
            MinVersion = Math.Min(MinVersion, info.firstVersion);
            MaxVersion = Math.Max(MaxVersion, info.lastVersion);

            if (File.Exists(info.fileLocal))
            {
                byte[] bytes = File.ReadAllBytes(info.fileLocal);
                if (bytes.Length == 0)
                {
                    yield break;
                }

                ActionState(State.ApplyPatchList);
                string content = info.IsEncrypt() ? bytes.AES_Dencrypt() : Encoding.UTF8.GetString(bytes);
                patchCache[info.fileUrl] = Library.Helper.JsonHelper.ToObject <FileVersion.FileDetailInfo[]>(
                    content.Trim())
                                           .Select(p => new FileDetailInfo(info, p))
                                           .ToDictionary(p => p.path);
            }
            else
            {
                Debug.LogError("file is not exist! " + info.fileLocal);
            }
        }
示例#3
0
        public FileDetailInfo(FilePatchInfo info, FileVersion.FileDetailInfo fileInfo)
        {
            this.dataType = DataType.PersistentDataPath;
            patchInfo     = info;

            path         = fileInfo.path;
            version      = fileInfo.version;
            is_delete    = fileInfo.is_delete;
            content_size = fileInfo.content_size;
            content_hash = fileInfo.content_hash;

            if (patchInfo.IsEncrypt())
            {
                is_ready = false;
            }
            if (content_hash == localhash)
            {
                is_ready = true;
            }

            name = Path.GetFileName(path);
            url  = string.Format("{0}?v={1}", path, version);
        }
示例#4
0
 /// <summary>
 /// 下载记录主资源压缩包
 /// </summary>
 /// <param name="info"></param>
 /// <returns></returns>
 public IEnumerator GetRemoteZip(FilePatchInfo info)
 {
     ActionState(State.DownPatchZip);
     yield return(Access.FromRemote(info.path + ".zip", res =>
     {
         if (res == null || res.MD5() != info.zip_hash)
         {
             return;
         }
         var zipName = Access.PersistentDataPatchPath + info.path + ".zip";
         File.WriteAllBytes(zipName, res);
         ActionState(State.UnMakePatchZip);
         string msg = Library.Compress.DecompressUtils.UnMakeZipFile(zipName, "", true);
         if (string.IsNullOrEmpty(msg))
         {
             File.Delete(zipName);
             FileMoveTo(info, zipName);
         }
         else
         {
             Debug.LogError("解压文件失败!" + msg);
         }
     }));
 }