示例#1
0
    public static string ReadStr(string fileName)
    {
        string data = null;

        if (PathTools.ExistsPersistentPath(fileName))
        {
            //bytes = System.IO.File.ReadAllText (PathTools.GetPersistentPath (fileName)).Trim ();
            data = System.IO.File.ReadAllText(PathTools.GetPersistentPath(fileName));

            Debug.LogWarningFormat("ReadRes load >> {0} ", PathTools.GetPersistentPath(fileName));
        }
        else
        {
            if (Application.platform == RuntimePlatform.Android)
            {
                WWW www = new WWW(PathTools.GetAppContentPath(fileName));
                //yield return www;
                while (true)
                {
                    if (www.isDone || !string.IsNullOrEmpty(www.error))
                    {
                        System.Threading.Thread.Sleep(50);
                        if (!string.IsNullOrEmpty(www.error))
                        {
                            Debug.LogError(www.error);
                        }
                        else
                        {
                            data = www.text;
                        }
                        break;
                    }
                }
            }
            else
            {
                data = System.IO.File.ReadAllText(PathTools.GetAppContentPath(fileName));
            }

            Debug.LogFormat("ReadRes load >> {0} ", PathTools.GetPersistentPath(fileName));
        }

        if (data == null)
        {
            Debug.LogErrorFormat("error Read streamingAssetsFile {0} ", fileName);
            return(null);
        }

        return(data);
    }
示例#2
0
        static int _m_ExistsPersistentPath_xlua_st_(RealStatePtr L)
        {
            try {
                {
                    string assetName = LuaAPI.lua_tostring(L, 1);

                    bool __cl_gen_ret = PathTools.ExistsPersistentPath(assetName);
                    LuaAPI.lua_pushboolean(L, __cl_gen_ret);



                    return(1);
                }
            } catch (System.Exception __gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + __gen_e));
            }
        }
示例#3
0
    IEnumerator LoadLocalImage(string path, Image image)
    {
        string streamingAssetsFileName = path;
        WWW    www;

        if (PathTools.ExistsPersistentPath(streamingAssetsFileName))
        {
            www = new WWW("file://" + PathTools.GetPersistentPath(streamingAssetsFileName));
            //fileText = System.IO.File.ReadAllText (PathTools.GetPersistentPath (streamingAssetsFileName)).Trim ();
        }
        else
        {
            if (Application.platform == RuntimePlatform.Android)
            {
                www = new WWW(PathTools.GetAppContentPath(streamingAssetsFileName));
            }
            else
            {
                www = new WWW("file://" + PathTools.GetAppContentPath(streamingAssetsFileName));
            }
        }
        //string filePath = PathTools.GetAssetPath(path);

        Debug.Log("getting local image:" + www.url);
        ///WWW www = new WWW(filePath);
        yield return(www);

        Texture2D texture  = www.texture;
        Sprite    m_sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0, 0));

        image.sprite = m_sprite;
        if (this.isSetNative)
        {
            image.SetNativeSize();
        }
    }
示例#4
0
    /// <summary>
    /// 初始化
    /// </summary>
    static public void Init()
    {
        SetPath();

        string md5filelist = "md5filelist.txt";

        string dataPath = assetsUpdatePath;           //Util.DataPath;  //数据目录
        string resPath  = PathTools.AppContentPath(); //Util.AppContentPath(); //游戏包资源目录

        string localMD5BakFilePath = PathTools.Combine(dataPath, "/md5filelist.txt.bak");

        string infile  = PathTools.Combine(resPath, "md5filelist.txt");
        string outfile = PathTools.Combine(dataPath, "md5filelist.txt");

        Debug.Log(infile);

        if (PathTools.ExistsPersistentPath("md5filelist.txt"))
        {
            Debug.LogWarning("非首次启动!");
        }
        else
        {
            Debug.LogWarning("首次启动!");

            if (!Directory.Exists(dataPath))
            {
                Directory.CreateDirectory(dataPath);
            }

            Debug.LogErrorFormat("localMD5BakFilePath {0} {1}", localMD5BakFilePath, File.Exists(localMD5BakFilePath));

            if (File.Exists(localMD5BakFilePath))
            {
                Debug.LogErrorFormat("本地列表文件 bak 存在!{0}", localMD5BakFilePath);
                File.Delete(localMD5BakFilePath);
            }
            if (File.Exists(localMD5BakFilePath))
            {
                Debug.LogErrorFormat("本地列表文件 bak 删除成功!{0}", localMD5BakFilePath);
            }

            string message = "正在解包文件:>md5filelist.txt";

            if (Application.platform == RuntimePlatform.Android)
            {
                WWW www = new WWW(infile);

                while (true)
                {
                    if (www.isDone || !string.IsNullOrEmpty(www.error))
                    {
                        System.Threading.Thread.Sleep(50);
                        if (!string.IsNullOrEmpty(www.error))
                        {
                            Debug.LogError(www.error);
                        }
                        else
                        {
                            File.WriteAllBytes(outfile, www.bytes);
                            Debug.LogWarning(">>" + outfile);
                        }
                        break;
                    }
                }
            }
            else
            {
                File.Copy(infile, outfile, true);
            }
        }

        string path = PathTools.Combine(PathTools.PersistentDataPath(), md5filelist);

        Debug.LogWarningFormat("热更新步骤 1 【初始化拷贝】完成!{0} {1}", path, System.IO.File.Exists(path));
    }