Exemplo n.º 1
0
        private void ABProcess()
        {
            LogMgr.UnityLog("ABProcess # " + mIdx + " Started ..");
            while (!isExit)
            {
                int               count     = 0;
                DownloadedItem    item      = null;
                string            mSaveFile = null;
                AssetBundleConfig mConfig   = null;

                lock (HttpDownload.shareObject)
                {
                    count = HttpDownload.downloadedQueue.Count;
                    if (count > 0)
                    {
                        item = HttpDownload.downloadedQueue[0];
                        HttpDownload.downloadedQueue.RemoveAt(0);
                    }
                }
                LogMgr.UnityLog("ABProcessor mid: " + mIdx);
                if (null != item)
                {
                    mSaveFile = item.saveFile;
                    mConfig   = item.config;

                    string outFilePath = mSaveFile.Replace("_Compress", "");
                    if (File.Exists(outFilePath))
                    {
                        File.Delete(outFilePath);
                    }
                    LZMATool.DecompressFileLZMA(mSaveFile, outFilePath);
                    if (File.Exists(mSaveFile))
                    {
                        File.Delete(mSaveFile);
                    }

                    if (null != mConfig)
                    {
                        List <AssetBundleConfig> bundleConfigGroup = new List <AssetBundleConfig>();
                        bundleConfigGroup.Add(mConfig);

                        XMLTool.SaveABConfig(HttpDownloadTask.configPath, bundleConfigGroup);
                        LogMgr.UnityLog("HttpDownLoad SaveABConfig: " + count + "," + mConfig.RelativePath
                                        + "," + mConfig.ABName + "," + mConfig.Build + "," + Thread.CurrentThread.ManagedThreadId + ",@" + mIdx
                                        );
                    }
                }
                else
                {
                    LogMgr.UnityLog("ABProcessor continue " + mIdx);
                    Thread.Sleep(10);
                }
            }
        }
Exemplo n.º 2
0
        private void DoDecompress(byte[] data, string file)
        {
            string streamFile = string.Format("{0}/{1}/Inner{2}", Application.persistentDataPath, BundleCommon.ResVersion, file);
            string streamTmp  = streamFile + "_Compress";

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

            File.WriteAllBytes(streamTmp, data);
            LZMATool.DecompressFileLZMA(streamTmp, streamFile);
            File.Delete(streamTmp);
        }
Exemplo n.º 3
0
        private void DoDecompress()
        {
            string streamTmp = file + "_Compress";

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

            File.WriteAllBytes(streamTmp, data);
            LZMATool.DecompressFileLZMA(streamTmp, file);
            File.Delete(streamTmp);

            if (null != finishCallback)
            {
                mDispatcher.AddAction(finishCallback);
            }
        }
Exemplo n.º 4
0
        private void OnGetStreamABList(bool success, byte[] data)
        {
            if (success)
            {
                string streamUserPath = BundleCommon.StreamUserVersionPath;
                string streamTmp      = streamUserPath + "_Compress";
                if (File.Exists(streamTmp))
                {
                    File.Delete(streamTmp);
                }

                File.WriteAllBytes(streamTmp, data);
                LZMATool.DecompressFileLZMA(streamTmp, streamUserPath);
                File.Delete(streamTmp);
            }

            GetRemoteVersion();
        }
Exemplo n.º 5
0
        private void OnDownManifest(bool success, byte[] bytes)
        {
            if (success)
            {
                string localFilePath = Application.persistentDataPath + "/" + BundleCommon.ResVersion + "/Out/assetbundle_Compress";
                string localFileDir  = localFilePath.Remove(localFilePath.LastIndexOf("/"));

                if (!Directory.Exists(localFileDir))
                {
                    Directory.CreateDirectory(localFileDir);
                }
                if (File.Exists(localFilePath))
                {
                    File.Delete(localFilePath);
                }
                File.WriteAllBytes(localFilePath, bytes);

                string outFilePath = localFilePath.Replace("_Compress", "");
                if (File.Exists(outFilePath))
                {
                    File.Delete(outFilePath);
                }

                LZMATool.DecompressFileLZMA(localFilePath, outFilePath);
                if (File.Exists(localFilePath))
                {
                    File.Delete(localFilePath);
                }

                DownloadConfig();
            }
            else
            {
                DownloadManifest();
            }
        }
Exemplo n.º 6
0
        private void DownLoadFile()
        {
            bool bExit    = false;
            bool bTask    = false;
            bool bPause   = false;
            bool bProcess = false;

            lock (mLockObject)
            {
                bExit = mIsExit;
            }
            while (!bExit)
            {
                lock (mLockObject)
                {
                    bTask    = mHasTask;
                    bPause   = mIsPause;
                    bExit    = mIsExit;
                    bProcess = mIsProcess;
                }

                if (!bTask || bPause || bProcess)
                {
                    //LogMgr.UnityLog("DownLoadFile continue: ");
                    Thread.Sleep(10);
                    continue;
                }

                try
                {
                    lock (mLockObject)
                    {
                        bProcess = true;
                    }

                    string localFileDir = mSaveFile.Remove(mSaveFile.LastIndexOf("/"));
                    if (!Directory.Exists(localFileDir))
                    {
                        Directory.CreateDirectory(localFileDir);
                    }

                    HttpWebRequest request    = WebRequest.Create(mUrl + BundleCommon.GetRandomUrl()) as HttpWebRequest;
                    WebResponse    response   = request.GetResponse();
                    Stream         stream     = response.GetResponseStream();
                    byte[]         buffer     = new byte[mBufferSize];
                    FileStream     fileStream = new FileStream(mSaveFile, FileMode.OpenOrCreate);

                    int readSize = stream.Read(buffer, 0, mBufferSize);
                    while (readSize > 0 && !bPause && !bExit)
                    {
                        fileStream.Write(buffer, 0, readSize);
                        mDownloadedSize += readSize;

                        readSize = stream.Read(buffer, 0, mBufferSize);

                        lock (mLockObject)
                        {
                            bPause = mIsPause;
                            bExit  = mIsExit;
                        }
                    }

                    stream.Close();
                    fileStream.Close();
                    response.Close();

                    DownloadedItem item = new DownloadedItem();
                    item.saveFile = mSaveFile;
                    item.config   = mConfig;
                    lock (shareObject)
                    {
                        downloadedQueue.Add(item);
                    }

                    if (!bPause && !bExit)
                    {
                        string outFilePath = mSaveFile.Replace("_Compress", "");
                        if (File.Exists(outFilePath))
                        {
                            File.Delete(outFilePath);
                        }
                        LZMATool.DecompressFileLZMA(mSaveFile, outFilePath);
                        if (File.Exists(mSaveFile))
                        {
                            File.Delete(mSaveFile);
                        }

                        if (null != mConfig)
                        {
                            List <AssetBundleConfig> bundleConfigGroup = new List <AssetBundleConfig>();
                            bundleConfigGroup.Add(mConfig);
                            lock (mLockObject)
                            {
                                XMLTool.SaveABConfig(HttpDownloadTask.configPath, bundleConfigGroup);
                                LogMgr.UnityLog("HttpDownLoad SaveABConfig: " + mConfig.RelativePath
                                                + "," + mConfig.ABName + "," + mConfig.Build
                                                );
                            }
                        }

                        if (null != mFinishCallback)
                        {
                            mFinishCallback(true);
                        }
                    }
                }
                catch (Exception e)
                {
                    LogMgr.UnityError("download file error:" + e.ToString());
                    if (null != mFinishCallback && !bPause && !bExit)
                    {
                        mFinishCallback(false);
                    }
                }

                lock (mLockObject)
                {
                    bExit = mIsExit;

                    mIsProcess = false;
                    mHasTask   = false;
                }
            }
        }