コード例 #1
0
 public static void RemoveLocalFenBaoData(AssetDataInfo dataInfo)
 {
     if (LocalFenBao != null)
     {
         LocalFenBao.Remove(dataInfo);
     }
 }
コード例 #2
0
    static void ArchiveAssetpackage()
    {
        if (!Directory.Exists(_fenBaoPath))
        {
            Directory.CreateDirectory(_fenBaoPath);
        }
        else
        {
            DirectoryInfo parent    = new DirectoryInfo(_fenBaoPath);
            FileInfo[]    fileInfos = parent.GetFiles();
            for (int i = 0; i < fileInfos.Length; i++)
            {
                File.Delete(fileInfos[i].FullName);
            }
        }

        for (int i = 0; i < _package_list.Count; i++)
        {
            AssetDataInfo info = new AssetDataInfo();
            if (_package_list[i].Count <= 0)
            {
                continue;
            }

            if (i == 0)  // 首包
            {
                GetFileToZip(_package_list[i], i, ref info);
            }
            else
            {
                GetFileToZip(_package_list[i], i, ref info);
            }
            _fenBaos.Add(info);
        }
    }
コード例 #3
0
 public void Remove(AssetDataInfo oldInfo)
 {
     if (localInfos.ContainsKey(oldInfo.Name))
     {
         localInfos.Remove(oldInfo.Name);
     }
 }
コード例 #4
0
    AssetDataInfo BuildAssetData(string name)
    {
        AssetDataInfo info = new AssetDataInfo();

        info.Name = name;
        return(info);
    }
コード例 #5
0
    protected override void OnDownLoadFileInfoSuccessful(AssetDownInfo downInfo)
    {
        string version = _all_version[downInfo.Index];
        string context = Encoding.Default.GetString(downInfo.Buffer.Bytes);

        //Debug.Log("AssetBundle下载:" + version);

        string[] abInfos = context.Split('\n');

        for (int i = 0; i < abInfos.Length; i++)
        {
            if (abInfos[i] == string.Empty || abInfos[i] == " ")
            {
                continue;   // 写入数据的时候没写好
            }
            string[]      abInfo = abInfos[i].Split('|');
            AssetDataInfo info   = new AssetDataInfo();

            info.Name    = abInfo[0];
            info.MD5     = abInfo[1];
            info.Size    = Convert.ToInt32(abInfo[2]);
            info.Version = version;

            _data_infos[version].Add(info);
        }
    }
コード例 #6
0
 public static void UpdateLocalABData(AssetDataInfo newInfo)
 {
     if (LocalAB != null)
     {
         LocalAB.Update(newInfo);
     }
 }
コード例 #7
0
 public static void UpdateLocalFenBaoData(AssetDataInfo newInfo)
 {
     if (LocalFenBao != null)
     {
         LocalFenBao.Update(newInfo);
     }
 }
コード例 #8
0
 public static void RemoveLocalABData(AssetDataInfo dataInfo)
 {
     if (LocalAB != null)
     {
         LocalAB.Remove(dataInfo);
     }
 }
コード例 #9
0
    static void GetFileToZip(
        List <string> assets,
        int fenBaoIndex,
        ref AssetDataInfo fenBaoInfo)
    {
        fenBaoInfo.Name = AssetBundleServerPath.FenBao.GetPackageFileName(UnpackCommon.DefaultABPath, fenBaoIndex);
        string packPath = AssetBundleServerPath.FenBao.GetPackageFullFileName(UnpackCommon.DefaultABPath, fenBaoIndex);

        Dictionary <string, FileStream> assetFiles = new Dictionary <string, FileStream>();

        for (int i = 0; i < assets.Count; i++)
        {
            string     fileFullName = _sourcePath + "/" + assets[i];
            FileStream info         = File.Open(fileFullName, FileMode.Open);
            assetFiles.Add(assets[i], info);
        }

        using (ZipOutputStream outStream = new ZipOutputStream(File.Create(packPath)))
        {
            outStream.SetLevel(0);
            Crc32         crc        = new Crc32();
            List <byte[]> zipBuffers = new List <byte[]>();

            var  itr       = assetFiles.Keys.GetEnumerator();
            long index     = 0;
            int  totalSize = 0;
            while (itr.MoveNext())
            {
                FileStream fs     = assetFiles[itr.Current];
                byte[]     buffer = new byte[fs.Length];
                fs.Read(buffer, 0, buffer.Length);

                ZipEntry entry = new ZipEntry(itr.Current);
                entry.DateTime     = File.GetLastAccessTime(itr.Current);
                entry.Size         = buffer.Length;
                entry.ZipFileIndex = assetFiles.Count - index++;
                fs.Close();
                crc.Reset();
                crc.Update(buffer);
                entry.Crc = crc.Value;
                outStream.PutNextEntry(entry);
                outStream.Write(buffer, 0, buffer.Length);

                totalSize = (int)outStream.Length;
            }

            outStream.Close();
            itr.Dispose();
        }

        using (FileStream fs = File.Open(packPath, FileMode.Open))
        {
            fenBaoInfo.Size = (int)fs.Length;

            byte[] outBytes = new byte[fenBaoInfo.Size];
            fs.Read(outBytes, 0, outBytes.Length);

            fenBaoInfo.MD5 = FileUtils.GetBytesMD5(outBytes);
        }
    }
コード例 #10
0
    protected override void OnDownLoadFileInfoSuccessful(AssetDownInfo downInfo)
    {
        string version = _all_version[downInfo.Index];
        string context = System.Text.Encoding.Default.GetString(downInfo.Buffer.Bytes);

        string[] fenBaoStrs = context.Split('\n');

        //Debug.Log("分包下载:" + version);

        for (int i = 0; i < fenBaoStrs.Length; i++)
        {
            if (fenBaoStrs[i] == string.Empty || fenBaoStrs[i] == " ")
            {
                continue;
            }
            string[] infoStr = fenBaoStrs[i].Split('|');

            AssetDataInfo info = new AssetDataInfo();
            info.Name    = infoStr[0];
            info.MD5     = infoStr[1];
            info.Size    = System.Convert.ToInt32(infoStr[2]);
            info.Version = version;

            _all_zip[version].Add(info);
        }
    }
コード例 #11
0
 public bool IsCompressed(AssetDataInfo serverInfo)
 {
     if (localInfos.ContainsKey(serverInfo.Name))
     {
         return(localInfos[serverInfo.Name].IsCompressed);
     }
     return(false);
 }
コード例 #12
0
    protected override void OnDownloadSuccessful(AssetDownInfo info, HttpDownLoadAsync loadAsync)
    {
        Debug.Log("Asset下载成功!");
        if (_downLoad_error.Contains(info))
        {
            _downLoad_error.Remove(info);
        }

        if (StageDataBase.CheckVersionIsDownLoadComplete(info.Version))
        {
            // 一个版本下载完毕
            VersionDownLoadComplete(info.Version);
        }

        _current_strategy.TryRemove(info);

        if (IsDone)
        {
            if (_stage_index < (_strategy_bases.Length - 1))
            {
                _stage_index++;
                Debug.Log("换阶段了 STAGE_INDEX=" + _stage_index);
            }
            else
            {
                if (_downLoad_error.Count <= 0)
                {
                    UpdateStageResult.DownLoad.ClearAll();
                }

                OnAllDownLoadComplete();
                if (DownLoadCompleteEvent != null)
                {
                    DownLoadCompleteEvent(this);
                }
                FileManifestManager.WriteABDataByCurrent();

                isDone = true;

                Debug.Log("全部下载完成!!!!!!!");
            }
        }
        else
        {
            AssetDataInfo dataInfo = info.ToAssetDataInfo();
            if (_current_strategy.AssetType == eUpdateAssetType.Zip)
            {
                FileManifestManager.UpdateLocalFenBaoData(dataInfo);
            }
            else
            {
                FileManifestManager.UpdateLocalABData(dataInfo);
            }
        }

        TryStartDownLoad();
    }
コード例 #13
0
    public AssetDataInfo ToAssetDataInfo()
    {
        AssetDataInfo info = new AssetDataInfo();

        info.Name    = AssetName;
        info.MD5     = MD5;
        info.Size    = TotalSize;
        info.Version = Version;
        return(info);
    }
コード例 #14
0
 public void Update(AssetDataInfo newInfo)
 {
     if (localInfos.ContainsKey(newInfo.Name))
     {
         localInfos[newInfo.Name] = newInfo;
     }
     else
     {
         localInfos.Add(newInfo.Name, newInfo);
     }
 }
コード例 #15
0
    public void InitializeData()
    {
        if (_cache_server_data.Count <= 0)
        {
            return;
        }

        int i          = StartIndex;
        int queueIndex = 0;
        Dictionary <string, List <AssetDataInfo> > packages = new Dictionary <string, List <AssetDataInfo> >();

        var itr = _cache_server_data.Keys.GetEnumerator();

        while (itr.MoveNext())
        {
            Queue <AssetDataInfo> datas = _cache_server_data[itr.Current];
            downloadQueue.Add(new Queue <AssetDownInfo>());

            while (datas.Count > 0)
            {
                AssetDataInfo serverInfo = datas.Dequeue();
                UpdateStageResult.DownLoad.TotalSize += serverInfo.Size;
                UpdateStageResult.DownLoad.FileCount++;

                if (IsDownloaded(serverInfo) ||
                    IsCompressed(serverInfo))
                {
                    UpdateStageResult.DownLoad.CurrentSize += serverInfo.Size;
                    UpdateStageResult.DownLoad.CurrentCount++;
                    continue;
                }

                AssetDownInfo download = serverInfo.ToAssetDownInfo(i);
                download.QueueIndex = queueIndex;
                download.Version    = itr.Current;

                if (!VersionRecord.ContainsKey(itr.Current))
                {
                    VersionRecord.Add(itr.Current, 0);
                }
                VersionRecord[itr.Current]++;

                InitDownLoadInfo(download);
                OnAddAssets(itr.Current, download);

                downloadQueue[downloadQueue.Count - 1].Enqueue(download);
                i++;
            }
            queueIndex++;
        }
        itr.Dispose();

        _cache_server_data.Clear();
    }
コード例 #16
0
    protected void WriteToLocal(
        Dictionary <string, AssetDataInfo> infos, bool deleteFile = false)
    {
        FileStream fs = null;

        if (deleteFile)
        {
            if (File.Exists(fileName))
            {
                File.Delete(fileName);
            }
        }

        if (!File.Exists(fileName))
        {
            fs = File.Create(fileName);
        }
        else
        {
            fs = File.Open(fileName, FileMode.Open);
        }

        StringBuilder sb = new StringBuilder();

        var itr   = infos.Values.GetEnumerator();
        int index = 0;

        while (itr.MoveNext())
        {
            AssetDataInfo info = itr.Current;

            if (index == infos.Count - 1)
            {
                sb.Append(info.ToString());
            }
            else
            {
                sb.Append(info.ToString() + "\n");
            }

            ++index;
        }

        itr.Dispose();

        byte[] bytes = Encoding.Default.GetBytes(sb.ToString());

        fs.Write(bytes, 0, bytes.Length);
        fs.Dispose();
        fs.Close();
    }
コード例 #17
0
    public bool IsDownloaded(AssetDataInfo newInfo)
    {
        AssetDataInfo outInfo;

        if (localInfos.TryGetValue(newInfo.Name, out outInfo))
        {
            if (outInfo.MD5 == newInfo.MD5 &&
                outInfo.Size == newInfo.Size)
            {
                return(true);
            }
        }

        return(false);
    }
コード例 #18
0
    public ZipDecompressStage(StageDataBase stage)
    {
        _owner            = stage;
        _decompress_queue = new List <AssetDownInfo>();
        List <AssetDataInfo> localAllZip = FileManifestManager.LocalFenBao.GetAllZip();

        if (localAllZip == null)
        {
            return;
        }

        for (int i = 0; i < localAllZip.Count; i++)
        {
            AssetDataInfo dataInfo = localAllZip[i];
            _decompress_queue.Add(dataInfo.ToAssetDownInfo(i));
        }
        _index = localAllZip.Count;
    }
コード例 #19
0
    public void Read()
    {
        if (!File.Exists(fileName))
        {
            FileStream fs = File.Create(fileName);
            fs.Dispose();
            fs.Close();
        }
        else
        {
            using (FileStream fs = File.Open(fileName, FileMode.Open))
            {
                byte[] bytes = new byte[fs.Length];
                fs.Read(bytes, 0, bytes.Length);

                string context = Encoding.Default.GetString(bytes);
                if (context == string.Empty)
                {
                    fs.Close();
                    return;
                }

                string[] abInfos = context.Split('\n');

                for (int i = 0; i < abInfos.Length; i++)
                {
                    if (abInfos[i] == string.Empty)
                    {
                        continue;
                    }

                    string[] info = abInfos[i].Split('|');

                    AssetDataInfo assetInfo = new AssetDataInfo();
                    assetInfo.Name         = info[0];
                    assetInfo.MD5          = info[1];
                    assetInfo.Size         = System.Convert.ToInt32(info[2]);
                    assetInfo.IsCompressed = info[3] == "True" ? true : false;

                    Update(assetInfo);
                }
            }
        }
    }
コード例 #20
0
 protected override bool IsDownloaded(AssetDataInfo serverInfo)
 {
     return(FileManifestManager.LocalFenBao.IsDownloaded(serverInfo));
 }
コード例 #21
0
 protected override bool IsCompressed(AssetDataInfo info)
 {
     return(FileManifestManager.LocalFenBao.IsCompressed(info));
 }
コード例 #22
0
 public void CompleteADownload(AssetDataInfo dataInfo)
 {
     throw new System.NotImplementedException();
 }
コード例 #23
0
 protected abstract bool IsDownloaded(AssetDataInfo info);
コード例 #24
0
 protected virtual bool IsCompressed(AssetDataInfo info)
 {
     return(false);
 }
コード例 #25
0
    // 开始解压缩
    public void StartDecompress()
    {
        UpdateStageResult.DownLoad.IsEnable    = false;
        UpdateStageResult.Compression.IsEnable = true;
        UpdateStageResult.Compression.ClearAll();

        var deItr = _decompress_queue.GetEnumerator();

        while (deItr.MoveNext())
        {
            UpdateStageResult.Compression.TotalSize += deItr.Current.TotalSize;
            UpdateStageResult.Compression.FileCount++;
        }
        deItr.Dispose();

        string localPath = AssetsCommon.LocalAssetPath;

        if (!Directory.Exists(localPath))
        {
            Directory.CreateDirectory(localPath);
        }

        AssetDownInfo[] tempDatas = new AssetDownInfo[_decompress_queue.Count];
        for (int i = 0; i < tempDatas.Length; i++)
        {
            int index = _decompress_queue[i].Index;
            tempDatas[index] = _decompress_queue[i];
        }

        for (int i = 0; i < tempDatas.Length; i++)
        {
            AssetDownInfo downInfo = tempDatas[i];

            string zipFileName = string.Format("{0}/{1}", localPath, downInfo.AssetName);
            List <AssetDataInfo> assetNames = ZipHelper.Decompress(
                zipFileName,
                localPath);

            AssetDataInfo dataInfo = downInfo.ToAssetDataInfo();
            dataInfo.IsCompressed = true;

            UpdateStageResult.Compression.CurrentCount++;
            FileManifestManager.UpdateLocalFenBaoData(dataInfo);

            for (int j = 0; j < assetNames.Count; j++)
            {
                FileManifestManager.UpdateLocalABData(assetNames[j]);
            }

            if (File.Exists(zipFileName))
            {
                File.Delete(zipFileName);
            }
        }

        UpdateStageResult.Compression.IsEnable = false;

        if (_owner.IsDownLoadAllVersion)
        {
            FileManifestManager.WriteFenBaoDataByServer();
        }
        else
        {
            FileManifestManager.WriteFenBaoDataByCurrent();
        }

        FileManifestManager.WriteABDataByCurrent();
    }
コード例 #26
0
    public static List <AssetDataInfo> Decompress(
        string zipFileName,
        string targetPath)
    {
        List <AssetDataInfo> assetNames = new List <AssetDataInfo>();

        ZipEntry theEntry = null;
        int      size     = 0;

        byte[] bytes = new byte[2048];

        using (ZipInputStream s = new ZipInputStream(File.OpenRead(zipFileName)))
        {
            while ((theEntry = s.GetNextEntry()) != null)
            {
                if (theEntry.Name == string.Empty)
                {
                    continue;
                }

                string fileName = (targetPath + "/" + theEntry.Name);

                if (File.Exists(fileName))
                {
                    File.Delete(fileName);
                }
                AssetDataInfo info = new AssetDataInfo();
                info.Name = theEntry.Name;

                using (FileStream fs = File.Create(fileName))
                {
                    while (true)
                    {
                        size = s.Read(bytes, 0, bytes.Length);
                        if (size <= 0)
                        {
                            break;
                        }
                        fs.Write(bytes, 0, size);
                        UpdateStageResult.Compression.CurrentSize += size;
                    }

                    fs.Close();
                }

                using (FileStream fs = File.Open(fileName, FileMode.Open))
                {
                    info.Size         = (int)fs.Length;
                    info.MD5          = FileUtils.GetFileMD5ByStream(fs);
                    info.IsCompressed = true;

                    fs.Close();
                }

                assetNames.Add(info);
            }
            s.Close();
        }

        return(assetNames);
    }