예제 #1
0
    /// <summary>
    /// 启动游戏所需要资源包校验,有需要则下载更新
    /// </summary>
    private void ResourceUpdateVerify()
    {
        CCsvDataManager.Instance.LocalABVerDataMgr.LoadLocalABVerDataFile();
        CCsvDataManager.Instance.SerABVerDataMgr.LoadServerABVerDataFile();

        //校验csv和大厅资源 assetbundle
        bool ResourceNeedUpdate = false;

        ResourceNeedUpdate |= CResVersionCompareUpdate.CompareABVersionAndUpdate(GameDefine.DependenciesAssetBundleName, true);
        ResourceNeedUpdate |= CResVersionCompareUpdate.CompareABVersionAndUpdate(GameDefine.CsvAssetbundleName, true);

#if !ScFish
        ResourceNeedUpdate |= CResVersionCompareUpdate.CompareABVersionAndUpdate(GameDefine.HallAssetbundleName, true);
        ResourceNeedUpdate |= CResVersionCompareUpdate.CompareABVersionAndUpdate(GameDefine.HallConstAssetBundleName, true);
        ResourceNeedUpdate |= CResVersionCompareUpdate.CompareABVersionAndUpdate(GameDefine.PokerAssetBundleName, true);
        ResourceNeedUpdate |= CResVersionCompareUpdate.CompareABVersionAndUpdate(GameDefine.HallBagIconAssetBundleName, true);
        ResourceNeedUpdate |= CResVersionCompareUpdate.CompareABVersionAndUpdate(GameDefine.HallAnimeAssetBundleName, true);
#endif

        //android平台下检测apk是否需要更新
        if (Application.platform == RuntimePlatform.Android)
        {
            bApkNeedUpdate = CResVersionCompareUpdate.CheckApkVerAndUpdate(m_SvrAppVerStr);
        }

        if (ResourceNeedUpdate || bApkNeedUpdate)
        {
            eLuancherState = LUANCHERSTATE.LuancherState_Downloading;
        }
        else
        {
            eLuancherState = LUANCHERSTATE.LuancherState_VerifyMD5;
        }
    }
예제 #2
0
    /// <summary>
    /// 资源MD5检验
    /// </summary>
    private void ResourceMD5Verify()
    {
        //string hallAssetMd5str = GameCommon.GenerateFileMd5(GameDefine.AssetBundleSavePath + GameDefine.HallAssetbundleName);
        List <string> filelist        = DownLoadProcessMgr.Instance.DownloadOverFileNameList;
        bool          md5crcSuccessed = true;

        if (EnableResMD5CRC)
        {
            for (int i = 0; i < filelist.Count; i++)
            {
                CServerABVerData filesvrdata = CCsvDataManager.Instance.SerABVerDataMgr.GetServerABVerData(filelist[i]);

                if (filesvrdata == null)
                {
                    continue;
                }

                string filemd5 = GameCommon.GenerateFileMd5(GameDefine.AssetBundleSavePath + filelist[i]);
                if (filemd5.CompareTo(filesvrdata.AssetbundleMd5Str) != 0)
                {
                    File.Delete(GameDefine.AssetBundleSavePath + filelist[i]);
                    CResVersionCompareUpdate.CompareABVersionAndUpdate(filelist[i], true);
                    Debug.Log(filelist[i] + " md5 CRC fialed");
                    md5crcSuccessed = false;
                }
            }
        }

        DownLoadProcessMgr.Instance.DownloadOverFileNameList.Clear();
        if (md5crcSuccessed)
        {
            //apk更新下载完成执行安装
            if (bApkNeedUpdate)
            {
                eLuancherState = LUANCHERSTATE.LuancherState_InstallAPK;
            }
            else
            {
                eLuancherState = LUANCHERSTATE.LuancherState_StartGame;
            }
        }
        else
        {
            eLuancherState = LUANCHERSTATE.LuancherState_Downloading;
        }
    }
예제 #3
0
    // Use this for initialization
    void Start()
    {
        InitApplicationSetting();
        m_SvrResVerStr = string.Empty;
        m_ServerIP     = string.Empty;
        m_ServerPort   = 0;

        bApkNeedUpdate = false;
        LogFile.InitLog();
        //this.transform.gameObject.AddComponent<LogFile>();
        Transform Imagestriptf = GameObject.Find("Canvas/Root").transform.Find("Main_Loading").Find("ImageStripBG");

        DownloadProcessBarImg         = Imagestriptf.Find("ImageStrip").gameObject.GetComponent <Image>();
        DownloadProcessPercentObj     = Imagestriptf.Find("Text_percent").gameObject;
        DownloadProcessTotalLengthObj = Imagestriptf.Find("Text_length").gameObject;
        DownloadProcessUpdatetextObj  = Imagestriptf.Find("Text_Info").gameObject;
        DownloadProcessPercentObj.SetActive(false);
        DownloadProcessTotalLengthObj.SetActive(false);
        DownloadProcessUpdatetextObj.GetComponent <Text>().text = "校验游戏资源,请稍候...";
        DownloadProcessUpdatetextObj.SetActive(true);
        Imagestriptf.Find("Text_version").GetComponent <Text>().text = Application.version;
        eLuancherState = LUANCHERSTATE.LuancherState_StartVerify;
        RefreshScreenResolution();
    }
예제 #4
0
    IEnumerator UnZip(string fileToUnZip, string zipedFolder, string password, float percent, bool delZipOnEnd)
    {
        FileStream     fs = null;
        ZipInputStream zipStream = null;
        ZipEntry       ent = null;
        string         fileName, directoryName;

        if (!File.Exists(fileToUnZip))
        {
            Debug.Log("zip file not exist!!!!!");
            yield break;
        }

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

        yield return(null);

        float process = 0;

        FileStream srcfs   = File.OpenRead(fileToUnZip);
        int        filelen = (int)srcfs.Length;

        zipStream = new ZipInputStream(srcfs);
        if (!string.IsNullOrEmpty(password))
        {
            zipStream.Password = password;
        }
        while ((ent = zipStream.GetNextEntry()) != null)
        {
            if (!string.IsNullOrEmpty(ent.Name))
            {
                directoryName = Path.GetDirectoryName(ent.Name);
                if (directoryName != String.Empty)
                {
                    Directory.CreateDirectory(zipedFolder + directoryName);
                }

                fileName = Path.Combine(zipedFolder, ent.Name);

                if (!string.IsNullOrEmpty(fileName))
                {
                    fs = File.Create(fileName);
                    int    size = 2048;
                    byte[] data = new byte[size];
                    while (true)
                    {
                        size = zipStream.Read(data, 0, data.Length);
                        if (size > 0)
                        {
                            try
                            {
                                fs.Write(data, 0, size);
                            }
                            catch (Exception ex)
                            {
                                DownloadProcessUpdatetextObj.GetComponent <Text>().text = "存储空间不足,请释放足够空间后重新运行";
                                eLuancherState = LUANCHERSTATE.LuancherState_Over;
                                Debug.Log("unzip asset zip file failed!!!!!");
                                yield break;
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                }
            }


            process = (float)ent.CompressedSize / filelen;
            DownloadProcessBarImg.fillAmount += process * percent;
            DebugLog.Log("unzip process:" + DownloadProcessBarImg.fillAmount + " name:" + ent.Name);

            yield return(null);
        }

        zipStream.Close();

        if (fs != null)
        {
            fs.Close();
            fs.Dispose();
        }
        if (zipStream != null)
        {
            zipStream.Close();
            zipStream.Dispose();
        }
        if (ent != null)
        {
            ent = null;
        }
        GC.Collect();
        GC.Collect(1);

        if (delZipOnEnd)
        {
            File.Delete(fileToUnZip);
        }
    }
예제 #5
0
    IEnumerator UnzipAssetFile()
    {
        string src = GameCommon.GetAppStreamingAssetPath() + GameDefine.AssetsZipFile;
        string des = GameDefine.AssetBundleSavePath + GameDefine.AssetsZipFile;

        Debug.Log("load zip:" + src + "->" + des);

        float percent = 0.5f;

        if (Application.platform == RuntimePlatform.Android)
        {
            WWW www = new WWW(src);

            while (!www.isDone)
            {
                DownloadProcessBarImg.fillAmount = www.progress * percent;

                yield return(null);
            }

            yield return(www);

            if (!string.IsNullOrEmpty(www.error))
            {
                Debug.Log("www.error:" + www.error);
            }
            else
            {
                try
                {
                    if (File.Exists(des))
                    {
                        File.Delete(des);
                    }
                    FileStream fsDes = File.Create(des);
                    fsDes.Write(www.bytes, 0, www.bytes.Length);
                    fsDes.Flush();
                    fsDes.Close();
                    fsDes.Dispose();
                }
                catch (Exception ex)
                {
                    DownloadProcessUpdatetextObj.GetComponent <Text>().text = ex.ToString();
                    eLuancherState = LUANCHERSTATE.LuancherState_Over;
                }
            }
            www.Dispose();
        }
        else if (File.Exists(src))
        {
            yield return(CopyFileToDesPath(src, GameDefine.AssetsZipFile, GameDefine.AssetBundleSavePath, percent));
        }

        percent = 0.4f;
        yield return(UnZip(des, GameDefine.AssetBundleSavePath, null, percent, true));

        DownloadProcessBarImg.fillAmount = 0.9f;

        yield return(null);

        WriteLocalResConfig();

        DownloadProcessBarImg.fillAmount = 0.95f;

        yield return(null);

        DownHotfixAndSerABCsvFile();

        DownloadProcessBarImg.fillAmount = 1f;

        yield return(null);

        ResourceUpdateVerify();
    }
예제 #6
0
    /// <summary>
    /// 检查版本号,与服务器资源进行版本号比对
    /// </summary>
    public void CheckVersionUpdate()
    {
#if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
        if (!UpdateWithLuncher)
        {
            eLuancherState = LUANCHERSTATE.LuancherState_VerifyMD5;
            return;
        }
#endif

        //读取服务器资源及程序版本号
        LoadServerResVersionConfig();

#if ScFish
        eLuancherState = LUANCHERSTATE.LuancherState_StartGame;
        return;
#endif
        if (string.IsNullOrEmpty(m_SvrResVerStr))
        {
            DownloadProcessUpdatetextObj.GetComponent <Text>().text = "连接异常,请检查网络...";
            DownloadProcessUpdatetextObj.SetActive(true);
            return;
        }

        //IOS 检测下程序是否需要更新,需要 则提示跳转app store
        if (Application.platform == RuntimePlatform.IPhonePlayer)
        {
            if (m_SvrAppVerStr.CompareTo(Application.version) != 0)
            {
                DownloadProcessUpdatetextObj.GetComponent <Text>().text = "请至AppStore更新APP...";
                DownloadProcessUpdatetextObj.SetActive(true);
                eLuancherState = LUANCHERSTATE.LuancherState_Over;

#if UNITY_IOS
                WechatPlatfrom_IOS.ShowAppUpdateTips("itms-apps://itunes.apple.com/cn/app/qiu-qiu-dou-di-zhu/id1319175293?mt=8");
#endif
                return;
            }
        }

        //bool bNeedUpdate = false;

        //读取本地资源版本
        string localResVerStr = ReadLocalResConfig();

#if ScFish
        //ScFish游戏下不需要解压资源包
        bAppFirstRun = false;
#endif
        //首次运行解压包里的资源,更新资源

        if (bAppFirstRun)
        {
            eLuancherState = LUANCHERSTATE.LuancherState_UnZip;
            DownloadProcessUpdatetextObj.GetComponent <Text>().text = "正在解压游戏资源(此过程不消耗流量)";
            Debug.Log("unzip processs start-------:");
            bAppFirstRun = false;
            FirstRunAppUnzipAssetbundle();
            //bNeedUpdate = true;
        }
        else
        {
            if (m_SvrResVerStr.CompareTo(localResVerStr) != 0)
            {
                //bNeedUpdate = true;
                WriteLocalResConfig();
                DownHotfixAndSerABCsvFile();
            }
            ResourceUpdateVerify();
        }
    }
예제 #7
0
    // Update is called once per frame
    void Update()
    {
        //防止在start中初始化下载资源登陆场景还没有显示
        if (eLuancherState == LUANCHERSTATE.LuancherState_StartVerify && Time.time > 0.5f)
        {
            Debug.Log("LuancherState_StartVerify process:");
            if (CheckAppRunPermission() == true)
            {
                CheckVersionUpdate();
                //eLuancherState = LUANCHERSTATE.LuancherState_Over;
            }
            else
            {
                DownloadProcessUpdatetextObj.GetComponent <Text>().text = "请授予程序运行必要的权限...";
                DownloadProcessUpdatetextObj.SetActive(true);
                eLuancherState = LUANCHERSTATE.LuancherState_Over;
            }
        }

        //else if(eLuancherState == LUANCHERSTATE.LuancherState_UnZip)
        //{
        //    if (DownloadProcessBarImg.fillAmount == 0.01f)
        //    {
        //        FirstRunAppUnzipAssetbundle();
        //    }
        //    DownloadProcessBarImg.fillAmount += 0.005f;
        //    Debug.Log("unzip process:" + DownloadProcessBarImg.fillAmount);
        //}

        //资源更新下载状态
        else if (eLuancherState == LUANCHERSTATE.LuancherState_Downloading)
        {
            if (DownLoadProcessMgr.Instance.IsDownLoadOver)
            {
                DownloadProcessUpdatetextObj.GetComponent <Text>().text = "正在校验资源...";
                DownloadProcessUpdatetextObj.SetActive(true);
                eLuancherState = LUANCHERSTATE.LuancherState_VerifyMD5;
            }
            else
            {
                if (HttpDownloadMgr.Instance.bDownloadError)
                {
                    DownloadProcessUpdatetextObj.GetComponent <Text>().text = "网络出现异常,正在重试...";
                    DownloadProcessUpdatetextObj.SetActive(true);
                }
                else
                {
                    DownloadProcessBarImg.fillAmount = DownLoadProcessMgr.Instance.GetDownloadProcess();
                    uint percent = DownLoadProcessMgr.Instance.GetDownloadPercent();
                    //Debug.Log("percent:" + percent);
                    DownloadProcessPercentObj.GetComponent <Text>().text = percent.ToString() + "%";

                    //这里有优化空间的,不需要每帧去更新总大小
                    string downlenstr = DownLoadProcessMgr.Instance.GetDownloadFileCurLength().ToString();
                    DownloadProcessTotalLengthObj.GetComponent <Text>().text = downlenstr + "/" + DownLoadProcessMgr.Instance.GetDownloadFileTotalLength().ToString() + "KB";
                    DownloadProcessPercentObj.SetActive(true);
                    DownloadProcessTotalLengthObj.SetActive(true);
                    DownloadProcessUpdatetextObj.GetComponent <Text>().text = "更新资源,请稍候...";
                    DownloadProcessUpdatetextObj.SetActive(true);
                }
            }
        }

        //下载完成调起安装
        else if (eLuancherState == LUANCHERSTATE.LuancherState_InstallAPK)
        {
#if UNITY_ANDROID
#if UKGAME_SDK
            CUKGameSDK.GetUKGameActivity().Call("InstallApk", GameDefine.DownloadApkSavePath + GameDefine.ApkFileName);
#else
            AlipayWeChatPay.GetAndroidActivity().Call("InstallApk", GameDefine.DownloadApkSavePath + GameDefine.ApkFileName);
#endif
#endif
            eLuancherState = LUANCHERSTATE.LuancherState_Over;
        }

        //资源资源进行MD5校验(防止网络异常下载的资源文件内容有错)
        else if (eLuancherState == LUANCHERSTATE.LuancherState_VerifyMD5)
        {
            if (Application.platform == RuntimePlatform.WindowsEditor || Application.platform == RuntimePlatform.OSXEditor)
            {
                eLuancherState = LUANCHERSTATE.LuancherState_StartGame;
            }
            else
            {
                ResourceMD5Verify();
            }
        }

        //启动游戏
        else if (eLuancherState == LUANCHERSTATE.LuancherState_StartGame)
        {
            GameMain.Instance.InitApplication(m_SvrResVerStr, m_ServerIP, m_ServerPort);
            eLuancherState = LUANCHERSTATE.LuancherState_Over;
        }
    }