Beispiel #1
0
 public static bool SaveDataToFile(string path, byte[] buffer)
 {
     if (path.IndexOf(AppConst.StreamingAssets) != -1 && AppConst.UpdateMode)
     {
         if (File.Exists(path))
         {
             File.Delete(path);
         }
         if (Directory.Exists(path))
         {
             Directory.Delete(path);
         }
     }
     if ((!File.Exists(path) && path.IndexOf(AppConst.StreamingAssets) == -1) || !AppConst.UpdateMode)
     {
         Pathtool.CreatePath(path);
     }
     try
     {
         FileStream fs = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write);
         fs.Write(buffer, 0, buffer.Length);
         fs.Close();
     }
     catch (Exception ex)
     {
         LogMgr.LogError("Can't create local resource" + path);
         return(false);
     }
     return(true);
 }
Beispiel #2
0
        public static void DeleteToFile(string path)
        {
            bool flag = File.Exists(path);

            if (flag)
            {
                File.Delete(path);
                Pathtool.CreatePath(path);
            }
        }
        public IEnumerator CheckVersionFile()
        {
            string dataPath         = AppUtil.DataPath;
            string resPath          = AppUtil.AppContentPath();
            bool   hight_res_update = false;
            int    num;
            WWW    www = null;

            for (int index = 0; index < m_pack_name.Count; index = num)
            {
                #region -解压版本文件到持久化路径下
                string pack_name       = m_pack_name[index];
                string db_file         = GetVersionFile(pack_name, true);                    //patchs/assets_main.sydb
                string version_file    = GetVersionFile(pack_name, false);                   //patchs/assets_head.cymzq
                string patch_file_name = GameConfig.Instance["PatchFileName"];               //patchs
                string patchs_path     = string.Format("{0}{1}", dataPath, patch_file_name); //c:/luaframework/patchs
                if (!Directory.Exists(patchs_path))
                {
                    Pathtool.CreatePath(patchs_path);
                }
                string db_path          = string.Format("{0}{1}", dataPath, db_file);      //c:/luaframework/patchs/assets_main.sydb
                string version_path     = string.Format("{0}{1}", dataPath, version_file); //c:/luaframework/patchs/assets_head.cymzq
                string src_db_path      = string.Format("{0}{1}", resPath, db_file);       //G:/Workspace/github/SyEngine/code/u3d/Assets/StreamingAssets/patchs/assets_main.sydb
                string src_version_path = string.Format("{0}{1}", resPath, version_file);  //G:/Workspace/github/SyEngine/code/u3d/Assets/StreamingAssets/patchs/assets_head.cymzq
                bool   pack_change      = GameConfig.Instance.IsPackChange();
                if (pack_change || !File.Exists(db_path) || !File.Exists(version_path))
                {
                    if (Application.platform == RuntimePlatform.Android)
                    {
                        m_version_file_update[pack_name] = true;
                        if (File.Exists(db_path))
                        {
                            File.Delete(db_path);
                        }
                        www = new WWW(src_db_path);
                        yield return(www);

                        if (www.isDone)
                        {
                            File.WriteAllBytes(db_path, www.bytes);
                        }
                        www.Dispose();
                        www = null;
                        yield return(null);

                        if (File.Exists(version_path))
                        {
                            File.Delete(version_path);
                        }
                        www = new WWW(src_version_path);
                        yield return(www);

                        if (www.isDone)
                        {
                            File.WriteAllBytes(version_path, www.bytes);
                        }
                        www.Dispose();
                        www = null;
                        yield return(null);
                    }
                    else
                    {
                        m_version_file_update[pack_name] = true;
                        File.Copy(src_db_path, db_path, true);
                        File.Copy(src_version_path, version_path, true);
                    }
                }
                if (AppConst.IgnoreUpdateState)
                {
                    m_version_file_update[pack_name] = false;
                }
                if (this.m_version_file_update[pack_name])
                {
                    hight_res_update = true;
                }
                #endregion
                yield return(new WaitForEndOfFrame());

                BusinessManager.Instance.SendMessage(ModuleDef.LaunchModule, "SendMessageCommand", "UpdateProgress", (double)(index + 1) * 100.0 / (double)this.m_pack_name.Count);
                num = index + 1;
            }
            www = null;
            Debug.Log("ResUpdateManager@CheckVersionFile: init patchs succeed");
            InitSqlite();
            Debug.Log("init sqlite succeed");
            GameConfig.Instance.WriteVersion();
            yield break;
        }