Example #1
0
 /// <summary>
 /// 获取所有的小类信息
 /// </summary>
 public void GetComponentInfo()
 {
     //获取版本信息
     HttpBase.GET(PortClass.Instance.Component, (request, response) =>
     {
         if (response == null || !response.IsSuccess)
         {
             DebugManager.Instance.LogError("请求失败!");
             return;
         }
         JsonData Item = JsonMapper.ToObject(response.DataAsText.Trim());
         if (Item["codeMsg"].ToString() != "SUCCESS")
         {
             return;
         }
         JsonData filejson = Item["data"];
         for (int i = 0; i < filejson.Count; i++)
         {
             JsonData temp            = filejson[i];
             CategoryComponentItem ci = new CategoryComponentItem();
             ParseCateCom(temp, ci);
             JsonClass.Instance.ComponentList.Add(ci);
         }
     });
 }
Example #2
0
    /// <summary>
    /// 获取服务器当前app版本中道具的full.json文件
    /// </summary>
    /// <param name="Message"></param>
    private void GetFullJson(int id)
    {
        List <FilesItem> FIS = new List <FilesItem>();
        var    item          = JsonClass.Instance.ComponentList.SingleOrDefault(t => t.id == id);
        string version       = item.version;

        Debug.Log("获取道具  " + id + "   的最新版本 " + version + "  的full文件");
        //获取版本信息
        HttpBase.GET(PortClass.Instance.FullJsonJson + id + "/full/" + version, (request, response) =>
        {
            if (response == null || !response.IsSuccess)
            {
                DebugManager.Instance.LogError("请求失败!");
                return;
            }
            JsonData Item = JsonMapper.ToObject(response.DataAsText.Trim());
            Debug.Log(response.DataAsText.Trim());
            JsonData filejson = Item["files"];
            for (int i = 0; i < (int)filejson.Count; i++)
            {
                JsonData temp = filejson[i];
                //FilesItem fi = new FilesItem();
                //fi.originalName = temp["originalName"].ToString();
                //fi.url = temp["url"].ToString();
                //fi.type = temp["type"].ToString();
                //fi.op = temp["op"].ToString();
                //fi.md5 = temp["md5"].ToString();
                //fi.size = temp["size"].ToString();                ;
                FIS.Add(ParseFilesItem(temp));
            }

            foreach (var folder in FindFolder(id))
            {
                string fullpath = folder + "/full.json";
                if (!Directory.Exists(Path.GetDirectoryName(fullpath)))
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(fullpath));
                }
                if (!File.Exists(fullpath))
                {
                    FileStream file = new FileStream(fullpath, FileMode.Create, FileAccess.Write); //创建写入文件
                    StreamWriter sw = new StreamWriter(file);
                    sw.WriteLine(JsonMapper.ToJson(FIS));                                          //开始写入值
                    sw.Close();
                    sw.Dispose();
                    file.Close();
                }
                else
                {
                    FileStream file = new FileStream(fullpath, FileMode.Open, FileAccess.Write);
                    StreamWriter sr = new StreamWriter(file);
                    sr.WriteLine(JsonMapper.ToJson(FIS));//开始写入值
                    sr.Close();
                    sr.Dispose();
                    file.Close();
                }
            }
        });
    }
Example #3
0
    /// <summary>
    /// 获取引导页页面  路径为 GUID/id/
    /// </summary>
    public void GetGuidPage()
    {
        string previewSavePath = PublicAttribute.LocalFilePath + "GUID/";

        HttpBase.GET(PortClass.Instance.Guid, ((request, response) =>
        {
            if (response == null || !response.IsSuccess)
            {
                DebugManager.Instance.LogError("请求失败!");
                return;
            }
            JsonData content = JsonMapper.ToObject(response.DataAsText.Trim());
            if (content["codeMsg"].ToString() != "SUCCESS")
            {
                return;
            }
            if (content["data"] == null)
            {
                return;
            }
            JsonData date = content["data"];

            if (date != null && date.Count > 0)
            {
                for (int i = 0; i < date.Count; i++)
                {
                    GUID guid = new GUID();
                    guid.id = int.Parse(date[i]["id"].ToString());
                    if (date[i]["url"] != null)
                    {
                        guid.url = date[i]["url"].ToString();
                    }
                    if (date[i]["des"] != null)
                    {
                        guid.des = date[i]["des"].ToString();
                    }
                    guid.name = date[i]["name"].ToString();
                    guid.pageIndex = int.Parse(date[i]["pageIndex"].ToString());

                    ///若果pageIndex大于100 该引导页图为主页的引导页
                    if (guid.pageIndex > 100)
                    {
                        previewSavePath = PublicAttribute.LocalFilePath + "MainGUID/";
                    }
                    if (!Directory.Exists(previewSavePath + guid.pageIndex))
                    {
                        Directory.CreateDirectory(previewSavePath + guid.pageIndex);
                    }

                    //PreviewSavePath(PortClass.Instance.GetPagePerview, guid.id.ToString(), previewSavePath, guid);
                    JsonClass.Instance.GUIDList.Add(guid);
                }
            }
            ///previewSavePath所有子文件夹集合  用来判断老旧的资源文件 是否需要删除
            var pathlist = Utility.GetFolder(previewSavePath);
            List <string> idlist = JsonClass.Instance.GUIDList.Select(guid => guid.pageIndex.ToString()).ToList();
            foreach (var item in pathlist.Where(item => !idlist.Contains(item)))
            {
                Directory.Delete(Path.Combine(previewSavePath, item));
            }
            //////删除文件夹内多余的图片/视频
        }
                                               ));
    }
Example #4
0
    /// <summary>
    /// 下载用户分享内容
    /// </summary>
    /// <param name="key"></param>
    /// <param name="callback"></param>
    public void GetAudioText(string key, Action <AudioClip, TextType> callback)
    {
        TextType  tt = new TextType();
        AudioClip ac = null;

        if (string.IsNullOrEmpty(key))
        {
            return;
        }

        ////判断key这个文件夹是否存在
        //string filePath = PublicAttribute.LocalFilePath + key;
        //Debug.Log("语音文件地址" + filePath);
        //if (!Directory.Exists(filePath))
        //{
        //    Directory.CreateDirectory(filePath);
        //}

        HttpBase.GET(PortClass.Instance.ShareInfoDownload + key, (request, response) =>
        {
            if (response == null || !response.IsSuccess)
            {
                DebugManager.Instance.LogError("请求失败!");
                return;
            }
            JsonData item = JsonMapper.ToObject(response.DataAsText.Trim());
            if (item["codeMsg"].ToString() != "SUCCESS")
            {
                return;
            }
            JsonData date = JsonMapper.ToObject(item["data"].ToString());
            for (int i = 0; i < date.Count; i++)
            {
                JsonData temp = date[i];
                if (temp["path"] == null)
                {
                    return;
                }
                string pathUrl = temp["path"].ToString();
                //下载音频文件
                HttpBase.GET(PortClass.Instance.ShareDownload + pathUrl, (request1, response1) =>
                {
                    if (response1 == null || !response1.IsSuccess)
                    {
                        DebugManager.Instance.LogError("请求失败!");
                        return;
                    }
                    if (response1.IsSuccess)
                    {
                        if (temp["suffix"].ToString().Contains("json"))
                        {
                            //下载json文件
                            tt = JsonMapper.ToObject <TextType>(response1.DataAsText);
                        }
                        if (temp["suffix"].ToString().Contains("wav"))
                        {
                            ac = WavUtility.ToAudioClip(response1.Data);
                        }
                        callback(ac, tt);
                    }
                });
            }
        });
    }
Example #5
0
    /// <summary>
    ///下载/更新道具  不传version默认为本地没有
    /// </summary>
    /// <param name="id">道具ID</param>
    public void DownloadUpdate(int id, string version = "0.0.0", Action <string> done = null)
    {
        //获取版本信息
        //若是默认的版本号,需要先获取当前道具的最新版本号
        //if (version == "1.0.0")
        //{
        //   var component =  JsonClass.Instance.ComponentList.Single(t => t.id == id);
        //    if (component!=null)
        //    {
        //        version = component.version;
        //    }
        //}
        Debug.Log(PortClass.Instance.CheckUpdate + id + "/" + version);
        HttpBase.GET(PortClass.Instance.CheckUpdate + id + "/" + version, (request, response) =>
        {
            if (response == null || !response.IsSuccess)
            {
                DebugManager.Instance.LogError("请求失败!");
                return;
            }
            JsonData Item = JsonMapper.ToObject(response.DataAsText.Trim());

            if (Item["msg"].ToString() == "服务器中未发现可用版本")
            {
                if (done != null)
                {
                    done("HaveNoUpdate");
                }
                return;
            }

            if (Item["codeMsg"].ToString() != "SUCCESS")
            {
                Debug.Log("请求失败!");
                return;
            }
            JsonData itemm = Item["data"];

            var op = itemm["op"].ToString();
            //如果op是full 需要先删除本地文件
            if (op == "full")
            {
                string fullpath = FindFolder(id)[0] + "full.json";
                //获取本地的full文件  根据本地full文件删除原有的东西
                if (File.Exists(fullpath))
                {
                    StreamReader sr = File.OpenText(fullpath);
                    string input    = sr.ReadToEnd();
                    sr.Close();
                    sr.Dispose();
                    var fullfilejson = JsonMapper.ToObject(input.Trim());
                    for (int i = 0; i < (int)fullfilejson.Count; i++)
                    {
                        JsonData temp = fullfilejson[i];
                        foreach (var item in FindFolder(id))
                        {
                            Debug.Log("需要删除的文件:    " + item + temp["originalName"].ToString());
                            if (File.Exists(item + "/" + temp["originalName"].ToString()))
                            {
                                File.Delete(item + "/" + temp["originalName"].ToString());
                            }
                        }
                    }
                }
                GetFullJson(id);
                ///执行下载
            }
            JsonData filejson = itemm["files"];
            if (filejson != null)
            {
                for (int i = 0; i < (int)filejson.Count; i++)
                {
                    JsonData temp = filejson[i];
                    FilesItem fi  = ParseFilesItem(temp);
                    JsonClass.Instance.CurrentAppUpdateFileJson.files.Add(fi);
                    switch (temp["op"].ToString())
                    {
                    case "add":
                        //_downloadList.Add(
                        //new Downloader.DownloadUnit(
                        //    PublicAttribute.URL + "/" + fi.url,
                        //    PublicAttribute.LocalFilePath + fi.paths[0], fi.originalName, fi.md5));
                        break;

                    case "update":

                        foreach (var path in fi.paths)
                        {
                            if (File.Exists(PublicAttribute.LocalFilePath + path + "/" + fi.originalName))
                            {
                                File.Delete(PublicAttribute.LocalFilePath + path + "/" + fi.originalName);
                            }
                        }
                        //_downloadList.Add(
                        //new Downloader.DownloadUnit(
                        //    PublicAttribute.URL + "/" + fi.url,
                        //    PublicAttribute.LocalFilePath + fi.paths[0], fi.originalName, fi.md5));
                        break;

                    case "remove":
                        foreach (var path in fi.paths)
                        {
                            if (File.Exists(PublicAttribute.LocalFilePath + path + "/" + fi.originalName))
                            {
                                File.Delete(PublicAttribute.LocalFilePath + path + "/" + fi.originalName);
                            }
                        }
                        break;

                    default:
                        break;
                    }
                }
                BatchDownloadFile(FindFolder(id), itemm["version"].ToString(), op, id, done);
            }
            else
            {
                done(FindFolder(id)[0]);
            }
        });
    }