예제 #1
0
 public static void DeCompressFromByte(string targetPath, byte[] content)
 {
     using (MemoryStream ms = new MemoryStream(content))
     {
         CompressHelper.DeCompress(targetPath, ms);
     }
 }
예제 #2
0
 public static void DeCompressFromFile(string zipPath, string targetPath)
 {
     if (File.Exists(zipPath))
     {
         using (FileStream fStream = File.Open(zipPath, FileMode.Open))
         {
             using (MemoryStream ms = new MemoryStream())
             {
                 byte[] array = new byte[4096];
                 int    count;
                 while ((count = fStream.Read(array, 0, array.Length)) != 0)
                 {
                     ms.Write(array, 0, count);
                 }
                 CompressHelper.DeCompress(targetPath, ms);
             }
         }
     }
 }
        private IEnumerator OnExtractResource()
        {
            string dataPath = AppUtil.DataPath;
            string resPath  = AppUtil.AppContentPath();

            if (!Directory.Exists(dataPath))
            {
                Directory.CreateDirectory(dataPath);
            }
            string filename = GameConfig.Instance.GetValue("FireTxt");
            string infile   = resPath + filename;
            string outfile  = dataPath + filename;

            if (File.Exists(outfile))
            {
                File.Delete(outfile);
            }
            LogMgr.Log(infile);
            LogMgr.Log(outfile);
            bool has_data = false;

            if (Application.platform == RuntimePlatform.Android)
            {
                WWW www = new WWW(infile);
                yield return(www);

                if (www.isDone)
                {
                    File.WriteAllBytes(outfile, www.bytes);
                    has_data = true;
                }
                www.Dispose();
                www = null;
            }
            else
            {
                if (File.Exists(infile))
                {
                    File.Copy(infile, outfile, true);
                    has_data = true;
                }
            }

            if (has_data)
            {
                this.m_files = File.ReadAllLines(outfile);
                bool flag7 = this.m_files == null || this.m_files.Length == 0;
                if (flag7)
                {
                    this.m_finish_state = true;
                    this.m_files        = null;
                }
                else
                {
                    foreach (string file in this.m_files)
                    {
                        infile  = resPath + file;
                        outfile = dataPath + file;
                        float process = (float)this.m_file_count * 100f / (float)this.m_files.Length;
                        process = (float)Math.Ceiling((double)process);
                        string message = GameConfig.Instance.GetValue("GameResExtract") + process + "%";
                        BusinessManager.Instance.SendMessage(ModuleDef.LaunchModule, "SendMessageCommand", "UpdateMessage", message);
                        BusinessManager.Instance.SendMessage(ModuleDef.LaunchModule, "SendMessageCommand", "UpdateProgress", process);
                        bool flag8 = File.Exists(outfile);
                        if (flag8)
                        {
                            File.Delete(outfile);
                        }
                        string dir   = Path.GetDirectoryName(outfile);
                        bool   flag9 = !Directory.Exists(dir);
                        if (flag9)
                        {
                            Directory.CreateDirectory(dir);
                        }
                        bool flag10 = Application.platform == RuntimePlatform.Android;
                        if (flag10)
                        {
                            WWW www2 = new WWW(infile);
                            yield return(www2);

                            bool flag11 = www2.isDone && string.IsNullOrEmpty(www2.error);
                            if (flag11)
                            {
                                CompressHelper.DeCompressFromByte(dataPath, www2.bytes);
                            }
                            else
                            {
                                Debug.LogWarning("init data error:" + www2.error);
                            }
                            this.m_file_count++;
                            www2.Dispose();
                            www2 = null;
                            bool lowSystemMode = AppConst.LowSystemMode;
                            if (lowSystemMode)
                            {
                                yield return(new WaitForSeconds(0.2f));
                            }
                            www2 = null;
                        }
                        else
                        {
                            bool flag12 = File.Exists(infile);
                            if (flag12)
                            {
                                File.Copy(infile, outfile, true);
                                CompressHelper.DeCompressFromFile(outfile, dataPath);
                                this.m_file_count++;
                            }
                            bool lowSystemMode2 = AppConst.LowSystemMode;
                            if (lowSystemMode2)
                            {
                                yield return(new WaitForSeconds(0.2f));
                            }
                            else
                            {
                                yield return(new WaitForSeconds(0.05f));
                            }
                        }
                        bool flag13 = File.Exists(outfile);
                        if (flag13)
                        {
                            File.Delete(outfile);
                        }
                        bool flag14 = this.m_file_count >= this.m_files.Length;
                        if (flag14)
                        {
                            this.m_finish_state = true;
                            message             = GameConfig.Instance.GetValue("ExractResSuc");
                            BusinessManager.Instance.SendMessage(ModuleDef.LaunchModule, "SendMessageCommand", "UpdateMessage", GameConfig.Instance.GetValue("ExractResSuc"));
                        }
                        message = null;
                        dir     = null;
                    }
                    string[] array = null;
                }
            }
            else
            {
                this.m_finish_state = true;
            }
            yield break;
        }