Example #1
0
    IEnumerator M_LoadConfig(Action onComplete, Action onError)
    {
        string url    = GameConfig.HOST_RES() + "ab/" + GameConfig.LOCAL_CONFIG_FILE + "?t=" + TimeUtils.CurLocalTimeMilliSecond();
        WWW    loader = new WWW(url);

        yield return(loader);

        if (string.IsNullOrEmpty(loader.error))
        {
            VersionBundleConfig config = JsonFx.Json.JsonReader.Deserialize <VersionBundleConfig>(loader.text);
            m_loadedConfig = config;
            M_CacheBundles();
            if (onComplete != null)
            {
                onComplete();
            }
        }
        else
        {
            JZLog.LogError(loader.error);
            if (onError != null)
            {
                onError();
            }
        }
    }
Example #2
0
    /// <summary>
    /// 写入版本配置文件
    /// </summary>
    /// <param name="url"></param>
    /// <param name="config"></param>
    private void M_Write(string name, VersionBundleConfig config)
    {
#if !UNITY_WEBPLAYER
        string path = PathUtils.MakeFilePath(name, PathUtils.PathType.MobileDiskWrite);
        Debug.LogWarning("write path: " + path);
        try
        {
            StreamWriter sw;
            FileInfo     fInfo = new FileInfo(path);
            if (!fInfo.Exists)
            {
                string directoryPath = path.Substring(0, path.LastIndexOf('/'));
                if (!Directory.Exists(directoryPath))
                {
                    Directory.CreateDirectory(directoryPath);
                }
                sw = fInfo.CreateText();
            }
            else
            {
                fInfo.Delete();
                fInfo = new FileInfo(path);
                sw    = fInfo.CreateText();
            }
            string content = JsonFx.Json.JsonWriter.Serialize(config);
            sw.Write(content);
            sw.Close();
            sw.Dispose();
        }
        catch (Exception error)
        {
            JZLog.LogError("VersionManager:Write - " + "Error: " + error.Message);
        }
#endif
    }
Example #3
0
    public static VersionBundleConfig ReadConfig(string configFilePath)
    {
        VersionBundleConfig config = new VersionBundleConfig();

        if (File.Exists(configFilePath))
        {
            StreamReader sr      = new StreamReader(configFilePath);
            string       content = sr.ReadToEnd();
            sr.Close();
            config = JsonFx.Json.JsonReader.Deserialize <VersionBundleConfig>(content);
        }
        else
        {
            Debug.LogError("目标路径没有配置文件: " + configFilePath);
        }
        return(config);
    }
Example #4
0
    public static void WriteConfig(string configFilePath, VersionBundleConfig config)
    {
        if (null == config)
        {
            Debug.LogError("配置文件不能为空,请检查一下");
            return;
        }

#if UNITY_EDITOR
        if (EditorUtility.DisplayDialog("路径检测", "是否保存配置文件到: " + configFilePath, "确定", "取消"))
        {
            if (File.Exists(configFilePath))
            {
                File.Delete(configFilePath);
            }

            File.WriteAllText(configFilePath, JsonFx.Json.JsonWriter.Serialize(config));
        }
#endif
    }
Example #5
0
    /// <summary>
    /// 加载版本文件
    /// </summary>
    /// <param name="onComplete"></param>
    /// <param name="onError"></param>
    public void LoadVersion(Action onComplete, Action onError)
    {
        string url = GameConfig.HOST_RES() + GameConfig.LOCAL_HTTP_CONFIG_FILE + "?t=" + TimeUtils.CurLocalTimeMilliSecond();

        BestHTTP.HTTPRequest request = new BestHTTP.HTTPRequest(new Uri(url), (req, resp) => {
            if (resp != null)
            {
                Loom.RunAsync(() =>
                {
                    m_httpConfig = JsonFx.Json.JsonReader.Deserialize <VersionBundleConfig>(resp.DataAsText);
                    M_CacheHttpBundles();

                    string infoFilePath = PathUtils.MakeFilePath(GameConfig.LOCAL_DOWNLOAD_INFO_FILE, PathUtils.PathType.MobileDiskWrite);
                    if (File.Exists(infoFilePath))
                    {
                        using (FileStream infoStream = File.OpenRead(infoFilePath))
                        {
                            if (infoStream != null)
                            {
                                byte[] index = new byte[infoStream.Length];
                                infoStream.Read(index, 0, index.Length);
                                string content = System.Text.Encoding.Default.GetString(index);
                                DownloadFileInfo downloadFileInfo = JsonFx.Json.JsonReader.Deserialize <DownloadFileInfo>(content);
                                ResHelper.Instance().lastZipIndex = downloadFileInfo.totalSize;
                                for (int i = 0; i < downloadFileInfo.ids.Length; i++)
                                {
                                    ResHelper.Instance().downloadedFiles.Add(downloadFileInfo.ids[i], 1);
                                }
                            }
                        }
                    }

                    if (GameConfig.useLocalRes)
                    {
                        m_version         = new VersionConfig();
                        m_version.version = "0.0.0";
                        Loom.QueueOnMainThread(() => {
                            if (onComplete != null)
                            {
                                onComplete();
                            }
                        });
                    }
                    else
                    {
                        url = GameConfig.HOST_RES_ZIP() + "zip/" + GameConfig.LOCAL_VERSION_FILE + "?t=" + TimeUtils.CurLocalTimeMilliSecond();
                        BestHTTP.HTTPRequest zipRequest = new BestHTTP.HTTPRequest(new Uri(url), (zipReq, zipResp) => {
                            if (zipResp != null)
                            {
                                m_version = JsonFx.Json.JsonReader.Deserialize <VersionConfig>(zipResp.DataAsText);
                                if (null != onComplete)
                                {
                                    onComplete();
                                }
                            }
                            else
                            {
                                if (null != onError)
                                {
                                    onError();
                                }
                            }
                        });
                        zipRequest.Send();
                    }
                });
            }
            else
            {
                if (null != onError)
                {
                    onError();
                }
            }
        });
        request.DisableCache = true;
        request.Send();
    }
Example #6
0
    void M_CacheHttpBundles()
    {
        m_httpBundles.Clear();
        string path = "file://" + PathUtils.MakeFilePath(GameConfig.LOCAL_HTTP_CONFIG_FILE, PathUtils.PathType.MobileDiskStreamAssert);

        if (Application.platform == RuntimePlatform.Android)
        {
            path = "jar:" + path;
        }

        try
        {
            Stream stream = new FileStream(path, FileMode.Open, FileAccess.Read);
            if (stream != null && stream.Length > 0)
            {
                byte[] data = new byte[stream.Length];
                stream.Read(data, 0, data.Length);
                stream.Close();
                string content = System.Text.Encoding.Default.GetString(data);
                m_localHttpConfig = JsonFx.Json.JsonReader.Deserialize <VersionBundleConfig>(content);
            }
            else
            {
                m_localHttpConfig = null;
            }
        }
        catch (Exception e)
        {
            m_loadedConfig = null;
        }


        VersionBundle vb = null;
        Dictionary <string, VersionBundle> temp = new Dictionary <string, VersionBundle>();

        if (null != m_localHttpConfig && null != m_localHttpConfig)
        {
            for (int i = 0; i < m_localHttpConfig.bundles.Length; i++)
            {
                vb = m_localHttpConfig.bundles[i];
                temp.Add(vb.id, vb);
            }
        }

        if (null != m_httpConfig && null != m_httpConfig.bundles)
        {
            for (int i = 0; i < m_httpConfig.bundles.Length; i++)
            {
                vb = m_httpConfig.bundles[i];
                if (temp.ContainsKey(vb.id))
                {
                    if (temp[vb.id].versionValue < vb.versionValue)
                    {
                        m_httpBundles.Add(vb.id, vb);
                    }
                }
                else
                {
                    m_httpBundles.Add(vb.id, vb);
                }
            }
        }
    }
Example #7
0
    IEnumerator ReadLocalConfig(Action onComplete, Action onError)
    {
        string path = PathUtils.MakeFilePath(GameConfig.LOCAL_CONFIG_FILE, PathUtils.PathType.MobileDiskWrite);

        try
        {
            if (File.Exists(path))
            {
                Loom.RunAsync(() => {
                    StreamReader sr = null;
                    sr             = File.OpenText(path);
                    string content = sr.ReadToEnd();
                    sr.Close();
                    m_localConfig = JsonFx.Json.JsonReader.Deserialize <VersionBundleConfig>(content);
                    if (null != onComplete)
                    {
                        Loom.QueueOnMainThread(() => {
                            onComplete();
                        });
                    }
                });
                yield break;
            }
        }
        catch (Exception error)
        {
            JZLog.LogError("VersionManager:Read - " + "Error: " + error.Message);
            if (null != onError)
            {
                onError();
            }
        }

        path = "file://" + PathUtils.MakeFilePath(GameConfig.LOCAL_CONFIG_FILE, PathUtils.PathType.MobileDiskStreamAssert);
        if (Application.platform == RuntimePlatform.Android)
        {
            path = "jar:" + path;
        }
        WWW www = new WWW(path);

        yield return(www);

        if (null != www && null == www.error)
        {
            JZLog.Log("load config success");
            string content = System.Text.Encoding.Default.GetString(www.bytes);
            Loom.RunAsync(() => {
                m_localConfig = JsonFx.Json.JsonReader.Deserialize <VersionBundleConfig>(content);
                if (null != onComplete)
                {
                    Loom.QueueOnMainThread(() =>
                    {
                        onComplete();
                    });
                }
            });
        }
        else
        {
            JZLog.LogError("VersionManager:Read - " + "Error: " + www.error);
            if (null != onError)
            {
                onError();
            }
        }
    }