示例#1
0
    public static void SaveGroupToLocal(string filename)
    {
        if (!Directory.Exists(localcachepath))
        {
            try
            {
                Directory.CreateDirectory(localcachepath);
            }
            catch (Exception e)
            {
                Log_Debug.LogError(e.ToString());
            }
        }
        string        header   = "ver:";
        StringBuilder in_write = new StringBuilder();

        in_write.Append(header).Append(Version.ToString());
        foreach (KeyValuePair <string, VerGroup> kv in RemoteVersion.RemoteVerGroup)
        {
            VerGroup ver = kv.Value;
            in_write.Append("\r\n").Append(ver.RootName).Append("|").Append(ver.hash).Append("|").Append(ver.filecount);
            ver.SaveLocal(ver.RootName);
        }
        string path = System.IO.Path.Combine(localcachepath, filename);

        using (var s = System.IO.File.Create(path))
        {
            byte[] b = Encoding.UTF8.GetBytes(in_write.ToString());
            s.Write(b, 0, b.Length);
        }
    }
示例#2
0
    public void CreateDownLoad(string path, Action callback)
    {
        Action <WWW, int> load = (www, udata) =>
        {
            if (www.error != null || www.text == null)
            {
                Log_Debug.LogError("www download error");
                return;
            }
            string   info    = www.text;
            string[] splited = info.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
            if (splited.Length <= 1)//数据错误
            {
                DownLoadManager.Instance.ShowLoadingErrTips("服务器下载数据错误");
                return;
            }
            for (int i = 0; i < splited.Length; i++)
            {
                if (i == 0)
                {
                    string[] first     = splited[0].Split(new string[] { "ver:", "|FileCount:" }, StringSplitOptions.RemoveEmptyEntries);
                    int      ver       = int.Parse(first[0]);
                    int      filecount = int.Parse(first[1]);
                    string   hash      = Convert.ToBase64String(DownLoadManager.Instance.sha1.ComputeHash(www.bytes));
                    if (RemoteVersion.Version != ver)
                    {
                        RemoteVersion.Version = ver;
                    }
                    if (this.filecount != filecount)
                    {
                        this.filecount = filecount;
                    }
                    if (this.hash != hash)
                    {
                        this.hash = hash;
                    }
                }
                else
                {
                    string[]  first = splited[i].Split(new string[] { "|", "@" }, StringSplitOptions.RemoveEmptyEntries);
                    RootGroup root  = new RootGroup(first[0], first[1], int.Parse(first[2]));
                    rootlist[first[0]] = root;
                }
            }

            if (callback != null)
            {
                callback();
            }
        };

        DownLoadManager.Instance.AddDownLoadTask(path, load);
    }
示例#3
0
    public void SetEmoji(string resname)
    {
        Sprite s = ResManager.GetResource <Sprite>(resname);

        if (s == null)
        {
            Log_Debug.LogError("is null " + resname);
        }
        else
        {
            emoji.sprite = s;
        }
    }
示例#4
0
 public static void ClearLocalCache()
 {
     try
     {
         if (Directory.Exists(localcachepath))//存在缓存,删除
         {
             Directory.Delete(localcachepath, true);
         }
     }
     catch (Exception e)
     {
         Log_Debug.LogError(e.ToString());
     }
 }
示例#5
0
    public void CreateDownLoad(string path, Action <RootGroup> callback)
    {
        Action <WWW, int> load = (www, udata) =>
        {
            if (www.error != null || www.text == null)
            {
                Log_Debug.LogError("download ab error");
                return;
            }
            string hash   = Convert.ToBase64String(DownLoadManager.Instance.sha1.ComputeHash(www.bytes));
            int    length = www.bytes.Length;
            if (this.hash != hash)
            {
                this.hash = hash;
            }
            if (this.filesize != length)
            {
                this.filesize = length;
            }
            string ab_path  = System.IO.Path.Combine(LocalVersion.localcachepath, FileName);
            string RootPath = System.IO.Path.GetDirectoryName(ab_path);
            try
            {
                if (!Directory.Exists(RootPath))
                {
                    Directory.CreateDirectory(RootPath);
                }
            }
            catch (Exception e)
            {
                Log_Debug.LogError(e.ToString());
            }

            using (var s = File.Create(ab_path))
            {
                byte[] b = www.bytes;
                s.Write(b, 0, b.Length);
            }
            if (callback != null)
            {
                this.needdownload = false;
                callback(this);
            }
        };

        DownLoadManager.Instance.AddDownLoadTask(path, load);
    }
示例#6
0
 void SystemServiceEventHandler(msg_cmd msg)
 {
     if (TcpNet.Instance.Protocol_type == Protocol_Type.protocol_protobuf)
     {
         MsgCallBack call  = TcpNet.ServiceDic[msg.stype].MsgCallBackDic[msg.ctype];
         object      value = null;
         try
         {
             value = DecodeCmd.Deserialize(msg.body, call.msg);
         }
         catch (Exception e)
         {
             Log_Debug.LogError("序列化消息失败");
         }
         call.callback.Method.Invoke(null, new object[] { value });
     }
     else
     {
         string cmd = System.Text.Encoding.UTF8.GetString(msg.body);
     }
 }
示例#7
0
    public void Parse(Action LoadOk)
    {
        if (LoadOk != null)
        {
            LoadResOk = LoadOk;
        }
        InitConfig();
        int ConfigCount = ConfigDic.Count;

        foreach (KeyValuePair <string, Type> type in ConfigDic)
        {
            TextAsset xmlText = ResManager.GetResource <TextAsset>(type.Key);
            if (xmlText == null)
            {
                Log_Debug.LogError("load config err");
            }
            try
            {
                type.Value.GetMethod("Parse").Invoke(null, new object[1] {
                    xmlText
                });
            }
            catch (Exception err)
            {
                Log_Debug.Log(type.Key);
                Log_Debug.LogError("loading config error:" + err.Message);
            }
            ConfigCount--;
            if (ConfigCount <= 0)
            {
                if (LoadResOk != null)
                {
                    LoadResOk();
                }
            }
        }
    }
示例#8
0
    public void BeginDownLoad(string path, Action callback)
    {
        Action CompareDiff = () =>
        {
            foreach (KeyValuePair <string, VerGroup> index in RemoteVersion.RemoteVerGroup)
            {
                if (LocalVersion.LocalVerGroup.ContainsKey(index.Key))//比较hash,size
                {
                    VerGroup local = LocalVersion.LocalVerGroup[index.Key];
                    //if (local.hash != index.Value.hash || local.filecount != index.Value.filecount)
                    //{
                    //    LocalVersion.LocalVerGroup[index.Key] = index.Value;
                    //}
                    foreach (KeyValuePair <string, RootGroup> KV in index.Value.rootlist)
                    {
                        if (local.rootlist.ContainsKey(KV.Key))
                        {
                            RootGroup group = local.rootlist[KV.Key];
                            if (group.hash != KV.Value.hash || group.filesize != KV.Value.filesize)
                            {
                                local.rootlist[KV.Key] = KV.Value;
                                local.rootlist[KV.Key].needdownload = true;
                            }
                        }
                        else
                        {
                            RootGroup g = new RootGroup(KV.Value.FileName, KV.Value.hash, KV.Value.filesize);
                            g.needdownload         = true;
                            local.rootlist[KV.Key] = g;
                        }
                    }
                }
                else
                {
                    VerGroup newgroup = new VerGroup(index.Value.RootName, index.Value.hash, index.Value.filecount);
                    index.Value.SetAllFilesNeedDownLoad();
                    newgroup.rootlist = index.Value.rootlist;
                    LocalVersion.LocalVerGroup[index.Key] = newgroup;
                }
            }
            //LocalVersion.SaveGroupToLocal("allver.ver.txt");
            //TODO::与本地解析比较,找出需要下载的
            if (callback != null)
            {
                callback();
            }
        };
        Action <WWW, int> AllVerCallBack = (www, udata) =>
        {
            if (www.error != null || www.text == null)
            {
                Log_Debug.LogError("www download error");
                return;
            }
            string   info    = www.text;
            string[] splited = info.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
            if (splited.Length <= 1)//数据错误
            {
                ShowLoadingErrTips("服务器下载数据错误");
                return;
            }
            for (int i = 0; i < splited.Length; i++)
            {
                if (i == 0)
                {
                    string[] first = splited[0].Split(new string[] { ":" }, StringSplitOptions.None);
                    int.TryParse(first[1], out RemoteVersion.Version);
                }
                else
                {
                    string[] first = splited[i].Split(new string[] { "|" }, StringSplitOptions.None);
                    VerGroup ver   = new VerGroup(first[0], first[1], int.Parse(first[2]));
                    RemoteVersion.RemoteVerGroup[first[0]] = ver;
                }
            }
            Debug.Log(RootHashDiff());
            if (RemoteVersion.Version > LocalVersion.Version || RootHashDiff())//
            {
                LocalVersion.Version = RemoteVersion.Version;
                foreach (KeyValuePair <string, VerGroup> group in RemoteVersion.RemoteVerGroup)
                {
                    StringBuilder str = new StringBuilder();
                    str.Append(RemoteVersion.remoteurl).Append("/" + group.Key + ".ver.txt");
                    group.Value.CreateDownLoad(str.ToString(), CompareDiff);
                }
            }
            else
            {
                if (callback != null)
                {
                    callback();
                }
            }
        };
        Action MergeLocal = () =>
        {
            RemoteVersion.AddDownLoadTask(path, AllVerCallBack);
        };

        if (DataManager.Instance.IsFirstEnterGame)//首次进入游戏
        {
            LocalVersion.ClearLocalCache();
            RemoteVersion.AddDownLoadTask(path, AllVerCallBack);
        }
        else
        {
            LocalVersion.ReadLocalAllVer(path, MergeLocal);
        }
    }