Beispiel #1
0
        /// <summary>
        /// Step 1:获取远程版本信息
        /// </summary>
        private void GetRemoteVersion()
        {
#if UNITY_EDITOR || UNITY_STANDALONE_WIN
            string configUrl = BundleCommon.RemoteUrl + "/" + BundleCommon.MainVersionFile + "_Compress" + BundleCommon.GetRandomUrl();
#else
            string configUrl = Path.Combine(BundleCommon.RemoteUrl, BundleCommon.MainVersionFile + "_Compress") + BundleCommon.GetRandomUrl();
#endif
            new BundleDownLoadTask(configUrl, OnGetRemoteVersionCallback, UpdateLoadCompressProgress);
        }
Beispiel #2
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;
                }
            }
        }