Example #1
0
        /// <summary>
        /// 对比sbf
        /// </summary>
        /// <param name="sbf">对比的sbf</param>
        /// <param name="less">this比sbf少的</param>
        /// <param name="more">this比sbf多的</param>
        /// <param name="diff">this和sbf都拥有 但是md5不一样的</param>
        public void Compare(SBF sbf, out List <SBFItem> diff, out List <SBFItem> more, out List <SBFItem> less)
        {
            diff = new List <SBFItem>();
            more = new List <SBFItem>();
            less = new List <SBFItem>();

            foreach (var pairs in this.itemDict)
            {
                var key   = pairs.Key;
                var value = pairs.Value;
                if (sbf.itemDict.ContainsKey(key))
                {
                    if (sbf.itemDict[key].md5 != value.md5)
                    {
                        diff.Add(value);
                    }
                }
                else
                {
                    more.Add(value);
                }
            }

            foreach (var pair in sbf.itemDict)
            {
                if (!this.itemDict.ContainsKey(pair.Key))
                {
                    less.Add(pair.Value);
                }
            }
        }
Example #2
0
        static void SaveSBF(string path)
        {
            if (File.Exists(path))
            {
                File.Delete(path);
            }

            FileStream   fs = new FileStream(path, FileMode.CreateNew);
            StreamWriter sw = new StreamWriter(fs);

            List <string> strList = new List <string>();

            foreach (var item in sbfDict)
            {
                string file  = item.Key;
                SBF    sbf   = item.Value;
                string value = string.Format("{0}|{1}|{2}", file, sbf.hash, sbf.size);
                if (value.IndexOf("/") != -1)
                {
                    strList.Insert(0, value);
                }
                else
                {
                    strList.Add(value);
                }
            }
            sw.Write(string.Join("\n", strList.ToArray()));

            sw.Close();
            fs.Close();
        }
Example #3
0
        //生成SBF
        static void CreateSBFAdnSave(string folder)
        {
            //清理SBF
            ClearSBF();

            //遍历文件
            string[] files = Directory.GetFiles(folder, "*", SearchOption.AllDirectories);
            foreach (var item in files)
            {
                string path = item.Replace("\\", "/");
                path = path.Replace(folder, "");
                if (path.StartsWith("/"))
                {
                    path = path.Substring(1);
                }
                if (path.EndsWith(".meta") || path.EndsWith(".manifest"))
                {
                    continue;
                }
                SBF sbf = CreateSBF(folder, path);
                AddSBF(path, sbf);
            }

            //保存SBF
            SaveSBF(Combine(folder, ResHelper.SBF_NAME));
            ClearSBF();
        }
Example #4
0
 static void AddSBF(string file, SBF sbf)
 {
     sbfDict.Add(file, sbf);
 }
Example #5
0
        public override IEnumerator UnzipRes()
        {
            //包体内的sbf
            WWW wwwInner = FileUtil.ReadFromStreamingAssets("Res/sbf");
            WWW wwwOuter = FileUtil.ReadFromPersistentData("Res/sbf");

            yield return(wwwInner);

            yield return(wwwOuter);

            SBF sbfInner = new SBF(wwwInner.text);
            SBF sbfOuter = new SBF(wwwOuter.text);

            //外部目录sbf
            List <SBF.SBFItem> diff, more, less;

            sbfInner.Compare(sbfOuter, out diff, out more, out less);

            //把outer中 多的和不一样的 复制出去
            List <SBF.SBFItem> move = new List <SBF.SBFItem>(diff.Count + more.Count);

            move.AddRange(diff);
            move.AddRange(more);

            //复制队列
            Dictionary <SBF.SBFItem, WWW> moveDict = new Dictionary <SBF.SBFItem, WWW>();
            //同时复制的最大数量
            int max = 30;

            //复制资源
            for (int i = 0; i < move.Count; i++)
            {
                //加入队列
                {
                    var item = move[i];
                    var www  = FileUtil.ReadFromStreamingAssets("Res/" + item.path);
                    moveDict.Add(item, www);
                }

                //队列没满
                if (moveDict.Count < max)
                {
                    continue;
                }

                //等等一帧
                yield return(null);

                //遍历下载队列
                while (true)
                {
                    //查找已经完成的
                    List <KeyValuePair <SBF.SBFItem, WWW> > doneList = null;
                    foreach (var pair in moveDict)
                    {
                        if (pair.Value.isDone)
                        {
                            if (doneList == null)
                            {
                                doneList = new List <KeyValuePair <SBF.SBFItem, WWW> >();
                            }
                            doneList.Add(pair);
                        }
                    }

                    if (doneList != null)
                    {
                        foreach (var pair in doneList)
                        {
                            var item = pair.Key;
                            var www  = pair.Value;
                            if (www.error == null)
                            {
                                FileUtil.WriteToPersistentData("Res/" + item.path, www.bytes);
                            }
                            moveDict.Remove(item);
                        }
                    }

                    if (moveDict.Count <= max)
                    {
                        break;
                    }

                    //等等一帧
                    yield return(null);
                }
            }


            //复制sbf
            FileUtil.WriteToPersistentData("Res/sbf", wwwInner.bytes);
            yield break;
        }