public static Stream GetStreamingFile(string file)
        {
#if UNITY_ANDROID && !UNITY_EDITOR
            file = _streamingPath + file;
            if (ObbAssetLoad.ExistsFile(file))
            {
                return(ObbAssetLoad.GetFile(file));
            }

            return(StreamingAssetLoad.GetFile(file));
#endif
            throw new NotImplementedException();
        }
Esempio n. 2
0
    public static VersionInfo GetCurrentVerNo()
    {
        VersionInfo curVerInfo = null;

        try
        {
            //获取streamingAssetsPath目录下版本号
            string streamingVerFileUrl  = string.Format("AssetBundles/{0}/{1}", BundleConfig.Instance.BundlePlatformStr, BundleConfig.Instance.VersionFileName);
            string streamingVerFileInfo = null;
            Stream stream = StreamingAssetLoad.GetFile(streamingVerFileUrl);
            if (stream == null)
            {
                LuaInterface.Debugger.LogError("本地版本文件不存在,{0}", streamingVerFileUrl);
            }
            else
            {
                StreamReader st = new StreamReader(stream);
                streamingVerFileInfo = st.ReadToEnd();
                st.Close();
                stream.Close();

                VersionInfo streamingVerInfo = LitJson.JsonMapper.ToObject <VersionInfo>(streamingVerFileInfo);

                //获取persistentDataPath目录下版本文件
                string persistentVerFileUrl = BundleConfig.Instance.BundlesPathForPersist + BundleConfig.Instance.VersionFileName;
                if (File.Exists(persistentVerFileUrl))
                {
                    string      persistentVerFileInfo = File.ReadAllText(persistentVerFileUrl);
                    VersionInfo persistentVerInfo     = LitJson.JsonMapper.ToObject <VersionInfo>(persistentVerFileInfo);

                    Version persistentVer = new Version(persistentVerInfo.VersionNum);
                    Version streamingVer  = new Version(streamingVerInfo.VersionNum);

                    if (persistentVer > streamingVer)
                    {
                        curVerInfo = persistentVerInfo;
                    }
                    else
                    {
                        curVerInfo = streamingVerInfo;
                        string        persistentBundlePath = BundleConfig.Instance.BundlesPathForPersist;
                        DirectoryInfo di = new DirectoryInfo(persistentBundlePath);
                        if (di.Exists)
                        {
                            di.Delete(true);
                        }
                    }
                }
                else
                {
                    curVerInfo = streamingVerInfo;
                    string        persistentBundlePath = BundleConfig.Instance.BundlesPathForPersist;
                    DirectoryInfo di = new DirectoryInfo(persistentBundlePath);
                    if (di.Exists)
                    {
                        di.Delete(true);
                    }
                }
            }
        }
        catch { LuaInterface.Debugger.LogError("FileUtils: get current version fail !"); }

        return(curVerInfo);
    }