Beispiel #1
0
        byte[] EndDownLoadDll()
        {
            byte[] buf = null;
            if (_wwwDown.isDone == false || string.IsNullOrEmpty(_wwwDown.error) == false)
            {
                string temp = string.Format("{0} download error: {1}", _wwwDown.url, _wwwDown.error);
                WriteLog(temp);

                FirstRecordMsg.Error(temp, MsgType.DownloadError);
            }
            else
            {
                byte[] bytes = _wwwDown.bytes;
                _MaskData(bytes);
                AssetBundle assetBundle = AssetBundle.LoadFromMemory(bytes);

                Object o = assetBundle.LoadAsset("manager.dll.bytes");
                buf = (o as TextAsset).bytes;

                assetBundle.Unload(false);
                assetBundle = null;

                WriteLog("{0} download ok [{1}]", _wwwDown.url, buf.Length);
            }

            _wwwDown.Dispose();
            _wwwDown = null;
            return(buf);
        }
Beispiel #2
0
        AssetBundle EndLoadAssetBundle()
        {
            AssetBundle ab = null;

            if (!string.IsNullOrEmpty(_wwwDown.error) || _wwwDown.isDone == false)
            {
                string temp = string.Format("WWW Download Error:{0} Error Msg:{1}", _wwwDown.url, _wwwDown.error);

                WriteLog(temp);

                FirstRecordMsg.Error(temp, MsgType.DownloadError);
            }
            else if (_wwwDown.assetBundle == null)
            {
                string temp = string.Format("WWW Download Exception:{0} The File Size:{1}", _wwwDown.url, _wwwDown.bytesDownloaded);
                WriteLog(temp);
                FirstRecordMsg.Error(temp, MsgType.DownloadError);
            }
            else
            {
                WriteLog("WWW Download Ok:{0} The File Size:{1}", _wwwDown.url, _wwwDown.bytesDownloaded);
                ab = _wwwDown.assetBundle;
            }

            _wwwDown.Dispose();
            _wwwDown = null;

            return(ab);
        }
Beispiel #3
0
        private IEnumerator LoadScenes()
        {
#if !UNITY_IOS
            string path = GetPathNoTarget("Managed/manager.dll");
            yield return(BeginDownLoad(path, 0));

            byte[] asset = EndDownLoadDll();
#endif

            Resources.UnloadUnusedAssets();

            try
            {
#if !UNITY_IOS
                System.Reflection.Assembly assembly = System.Reflection.Assembly.Load(asset);
                System.Type script = assembly.GetType("MainControl");
                WriteLog("Load Game Assembly-CSharp Complete...");
                gameObject.AddComponent(script);
                WriteLog("开始切换场景");
                GameObject.Destroy(load);
#else
                GameObject go = GameObject.Find("MainController");
                go.AddComponent <MainControl>();
#endif
            }
            catch (Exception e)
            {
                FirstRecordMsg.Error(e.StackTrace, MsgType.ReflectionDll);
            }
            yield break;
        }
Beispiel #4
0
        string EndDownLoadTxt(string fileName = "")
        {
            string s = "";

            if (_wwwDown.isDone == false || string.IsNullOrEmpty(_wwwDown.error) == false)
            {
                string temp = string.Format("{0} download error: {1}", _wwwDown.url, _wwwDown.error);

                WriteLog(temp, _wwwDown.url, _wwwDown.error);

                FirstRecordMsg.Error(temp, MsgType.DownloadError);
            }
            else
            {
                WriteLog("{0} download ok [{1}]", _wwwDown.url, _wwwDown.bytesDownloaded);

                if (_wwwDown.assetBundle != null)
                {
                    s = string.Copy((_wwwDown.assetBundle.LoadAsset(fileName) as TextAsset).text);
                    _wwwDown.assetBundle.Unload(false);
                }
                else
                {
                    s = _wwwDown.text;
                }
            }
            ProcessPercent += _percentAdd;
            _percentAdd     = 0;

            _wwwDown.Dispose();
            _wwwDown = null;
            return(s);
        }
Beispiel #5
0
        private void InitOutDir()
        {
#if UNITY_IOS
            Device.SetNoBackupFlag(Application.persistentDataPath);
#endif
            if (Directory.Exists(FirstUtil.OutDir)) // 存在out目录
            {
                // 检查packversion

                string packVersionPath = FirstUtil.OutDir + "packversion.txt";
                if (!File.Exists(packVersionPath))
                {
                    WriteOutText("packversion.txt", FirstUtil.PackVersion); //兼容老版本没有packversion
                }

                string outPackVersion = File.ReadAllLines(packVersionPath)[0];
                if (outPackVersion == FirstUtil.PackVersion)
                {
                    WriteLog("PackVersion match ok");
                    return;
                }

                DeleteDir(FirstUtil.OutDir);
            }

            // 重建out目录
            try
            {
                if (Directory.Exists(FirstUtil.OutDir) == false)
                {
                    Directory.CreateDirectory(FirstUtil.OutDir);
                }
            }
            catch (Exception e)
            {
                Debug.LogException(e);

                FirstRecordMsg.Error(e.StackTrace, MsgType.HandleFileException);

                DeleteDir(FirstUtil.OutDir);

                if (Directory.Exists(FirstUtil.OutDir) == false)
                {
                    Directory.CreateDirectory(FirstUtil.OutDir);
                }
            }

#if UNITY_IOS
            Device.SetNoBackupFlag(Path.Combine(Application.persistentDataPath, "out"));
#endif

            WriteOutText("filelist.txt", loccalFileList);
            WriteOutText("version.txt", localVersion);
            WriteOutText("packversion.txt", FirstUtil.PackVersion);
            WriteLog("create out dir {0}", FirstUtil.PackVersion);

            _isNewApk = true;
        }
Beispiel #6
0
        void WriteOutText(string path, string text)
        {
#if !UNITY_WEBPLAYER
            try
            {
                File.WriteAllBytes(FirstUtil.OutDir + path, Encoding.ASCII.GetBytes(text));
                WriteLog("WriteOutText: {0} ok!", path);
            }
            catch (Exception e)
            {
                FirstRecordMsg.Error(e.StackTrace, MsgType.WriteFileError);
            }
#endif
        }
Beispiel #7
0
        void RemoveDir(string path)
        {
#if !UNITY_WEBPLAYER
            try
            {
                if (Directory.Exists(path))
                {
                    Directory.Delete(path, true);
                }
            }
            catch (Exception e)
            {
                Debug.LogException(e);

                FirstRecordMsg.Error(e.StackTrace, MsgType.HandleFileException);
            }
#endif
        }
Beispiel #8
0
        void WriteFileList()
        {
#if !UNITY_WEBPLAYER
            try
            {
                var listFile = File.CreateText(FirstUtil.OutDir + "filelist.txt");
                foreach (var pair in FirstResource.SdFileDic)
                {
                    listFile.WriteLine("{0}\t{1}", pair.Key, pair.Value);
                }
                listFile.Close();
            }
            catch (Exception e)
            {
                FirstRecordMsg.Error(e.StackTrace, MsgType.WriteFileError);
            }
#endif
        }
Beispiel #9
0
        bool WriteTmpFile(string path, byte[] buf)
        {
#if !UNITY_WEBPLAYER
            try
            {
                string tmpPath = OutTmpPath + path;
                FirstUtil.CreateFileDirectory(tmpPath);
                File.WriteAllBytes(tmpPath, buf);
                WriteLog("WriteTmpFile: {0} ok!", path);
                return(true);
            }
            catch (Exception e)
            {
                Debug.LogException(e);

                FirstRecordMsg.Error("Write Error:" + path + ":::Stack:" + e.StackTrace, MsgType.WriteFileError);
            }
            return(false);
#endif
        }
Beispiel #10
0
        byte[] EndDownLoad()
        {
            byte[] buf = null;
            if (_wwwDown.isDone == false || string.IsNullOrEmpty(_wwwDown.error) == false)
            {
                string temp = string.Format("{0} download error: {1}", _wwwDown.url, _wwwDown.error);
                WriteLog(temp);

                FirstRecordMsg.Error(temp, MsgType.DownloadError);
            }
            else
            {
                buf = _wwwDown.bytes;
                WriteLog("{0} download ok [{1}]", _wwwDown.url, buf.Length);
            }
            ProcessPercent += _percentAdd;
            _percentAdd     = 0;

            _wwwDown.Dispose();
            _wwwDown = null;
            return(buf);
        }
Beispiel #11
0
        string getWWWTxt(WWW www, bool showLog = true)
        {
            string result = null;

            if (www.isDone && string.IsNullOrEmpty(www.error))
            {
                result = www.text;
                if (showLog)
                {
                    WriteLog("WWW Value:" + result);
                }
            }
            else
            {
                result = "";
                string msg = "loadError:" + www.error;
                Debug.LogError(msg);
                FirstRecordMsg.Error(msg, MsgType.DownloadError);
            }
            www.Dispose();
            return(result);
        }
Beispiel #12
0
        //删除目录下的所有内容,保留根目录
        bool DeleteDir(string path)
        {
            Debug.Log("delete:" + path);
            try
            {
                if (Directory.Exists(path))
                {
                    string[] dirs  = Directory.GetDirectories(path);
                    string[] files = Directory.GetFiles(path);
                    int      len;
                    len = files.Length;
                    for (int i = 0; i < len; i++)
                    {
                        File.Delete(files[i]);
                    }
                    len = dirs.Length;
                    for (int i = 0; i < len; i++)
                    {
                        string dir = dirs[i];
                        if (Directory.Exists(dir))
                        {
                            Directory.Delete(dir, true);
                        }
                    }
                    return(true);
                }
            }
            catch (Exception e)
            {
                Debug.LogException(e);

                FirstRecordMsg.Error(e.StackTrace, MsgType.HandleFileException);
            }

            return(false);
        }
Beispiel #13
0
        IEnumerator LoadAssetReal(string path)
        {
            if (IsLoadFail)
            {
                yield break;
            }

            if (IsStopUpdate)
            {
                _infoTips = FirstLang.FIRST_MSG_10;
                yield break;
            }

            string fullPath;
            string needCRC = FirstResource.SdFileDic[path];
            string tmpPath = Path.Combine(OutTmpPath, path);

            byte[] buf = null;

#if !UNITY_WEBPLAYER
            if (File.Exists(tmpPath))   // 已经下载过
            {
                buf = File.ReadAllBytes(tmpPath);
                if (FirstUtil.CRC32(buf).ToString("X") == needCRC)   // crc一致
                {
                    //WriteLog("download pass by: {0}", path);

                    HandlerLoadEnd(path);

                    yield break;
                }
            }
#endif

            WriteLog("download file:" + path);
            if (failDic.ContainsKey(path))
            {
                fullPath = loadRootPath + path + "?id=" + (DateTime.Now.ToFileTime() / 10);
            }
            else
            {
                fullPath = loadRootPath + path + "?id=" + needCRC;
            }

            WWW www = new WWW(fullPath);
            loadingDic[path] = www;
            yield return(www);

            RemoveLoading(path);

            if (!string.IsNullOrEmpty(www.error) || !www.isDone)
            {
                string temp = string.Format("{0} download error: {1}", www.url, www.error);
                WriteLog(temp);

                FirstRecordMsg.Error(temp, MsgType.DownloadError);
            }
            else
            {
                buf = www.bytes;
                //WriteLog("{0} download ok [{1}]", www.url, buf.Length);
            }

            www.Dispose();
            www = null;

            if (buf == null)
            {
                HandlerLoadEnd(path, 1);

                yield break;
            }

            string crc = FirstUtil.CRC32(buf).ToString("X");
            if (crc == needCRC || path.Contains("Android/Android"))
            {
                if (WriteTmpFile(path, buf))
                {
                    HandlerLoadEnd(path);
                }
                else
                {
                    HandlerLoadEnd(path, 3);
                }
            }
            else
            {
                string temp = string.Format("{0} crc error! down:{1}  need:{2}", path, crc, needCRC);
                WriteLog(temp);
                FirstRecordMsg.Error(temp, MsgType.CrcError);

                HandlerLoadEnd(path, 2);
                yield break;
            }
        }
Beispiel #14
0
        IEnumerator InitInfos()
        {
            FirstRecordMsg.Init();

            gameObject.AddComponent <FirstPlatform>();

            string path = FirstUtil.GetStreamingAssetsPathNoTarget() + "version.txt";
            WWW    www  = new WWW(path);

            yield return(www);

            localVersion = getWWWTxt(www, false);
            www          = null;

            path = FirstUtil.GetStreamingAssetsPathNoTarget() + "gameDefine.txt";
            www  = new WWW(path);
            yield return(www);

            localGameDefine = getWWWTxt(www, false);
            www             = null;

            path = FirstUtil.GetStreamingAssetsPathNoTarget() + "filelist.txt";
            www  = new WWW(path);
            yield return(www);

            loccalFileList = getWWWTxt(www, false);
            www            = null;

            InitLocalInfo();

            InitOutDir();

            path = GetPathNoTarget("version.txt");
            www  = new WWW(path);
            yield return(www);

            outLocalVersion = getWWWTxt(www);
            www             = null;

            path = GetPathNoTarget("gameDefine.txt");
            www  = new WWW(path);
            yield return(www);

            outLocalGameDefine = getWWWTxt(www);
            www = null;

            path = GetPathNoTarget("filelist.txt");
            www  = new WWW(path);
            yield return(www);

            outloccalFileList = getWWWTxt(www, false);
            www = null;

            path = GetPathNoTarget("FirstLang.txt");
            www  = new WWW(path);
            yield return(www);

            InitLang(getWWWTxt(www, false));
            www = null;

            WriteLog("InitFilstInfo");

            InitData();

            StartCoroutine(CheckUpdate());

            FirstResource.InitAppFileList(loccalFileList);
#if UNITY_EDITOR
            FirstResource.InitSdFileList("");
#else
            FirstResource.InitSdFileList(outloccalFileList);
#endif

            localVersion       = null;
            outLocalVersion    = null;
            localGameDefine    = null;
            outLocalGameDefine = null;
            loccalFileList     = null;
            outloccalFileList  = null;

            StartCoroutine(WorkerUI());
        }