Esempio n. 1
0
    /**
     * The new lua file loader.
     *
     * @param string strFile - The file name.
     * @return byte[] - The loaded bytes.
     */
    private static byte[] LuaStreamFileLoader(string strFile)
    {
        if (string.IsNullOrEmpty(strFile))
        {
            return(null);
        }

        strFile.Replace(".", "/");
        strFile += YwPathMng.FILE_AFFIX_LUA;

        string strLuaPath  = YwPathMng.DATA_CATAGORY_LUA + Path.DirectorySeparatorChar + strFile;
        string strFullPath = YwPathMng.Instance.GetLoadUrl(strLuaPath);

        // Read from file.
        YwArchiveBinFile cArc = new YwArchiveBinFile();

        if (!cArc.Open(strFullPath, FileMode.Open, FileAccess.Read))
        {
            return(null);
        }

        if (!cArc.IsValid())
        {
            return(null);
        }

        int nContentLength = (int)cArc.GetStream().Length;

        byte[] aContents = new byte[nContentLength];
        cArc.ReadBuffer(ref aContents, nContentLength);
        cArc.Close();

        return(aContents);
    }
    /**
     * Computer a md5 hash from file.
     *
     * @param string strFilePath - The file path.
     * @return string - The md5 hash.
     */
    public string ComputeHash(string strFilePath)
    {
        if (string.IsNullOrEmpty(strFilePath))
        {
            return(string.Empty);
        }

        YwArchiveBinFile cFileArc = new YwArchiveBinFile();

        if (!cFileArc.Open(strFilePath, FileMode.Open, FileAccess.Read))
        {
            return(string.Empty);
        }

        if (!cFileArc.IsValid())
        {
            return(string.Empty);
        }

        string strMd5Hash = ComputeHash(cFileArc.GetStream());

        cFileArc.Close();

        return(strMd5Hash);
    }
Esempio n. 3
0
    /**
     * The new lua file loader.
     *
     * @param string strFile - The file name.
     * @return byte[] - The loaded bytes.
     */
    private static byte[] LuaStreamFileLoader(string strFile)
    {
        if (string.IsNullOrEmpty(strFile))
        {
            return null;
        }

        strFile.Replace(".", "/");
        strFile += YwPathMng.FILE_AFFIX_LUA;

        string strLuaPath = YwPathMng.DATA_CATAGORY_LUA + Path.DirectorySeparatorChar + strFile;
        string strFullPath = YwPathMng.Instance.GetLoadUrl(strLuaPath);

        // Read from file.
        YwArchiveBinFile cArc = new YwArchiveBinFile();
        if (!cArc.Open(strFullPath, FileMode.Open, FileAccess.Read))
        {
            return null;
        }

        if (!cArc.IsValid())
        {
            return null;
        }

        int nContentLength = (int)cArc.GetStream().Length;
        byte[] aContents = new byte[nContentLength];
        cArc.ReadBuffer(ref aContents, nContentLength);
        cArc.Close();

        return aContents;
    }
Esempio n. 4
0
    /**
     * The lua file loader from streaming asset folder.
     *
     * @param string strFile - The file name.
     * @return byte[] - The loaded bytes.
     */
    private static byte[] LuaStreamFileLoader(string strFile)
    {
        if (string.IsNullOrEmpty(strFile))
        {
            return null;
        }

        string strFinalFile = strFile.Replace('.', YwPathMng.PATH_SEPARATE_CHAR_SLASH);
        strFinalFile += YwPathMng.FILE_AFFIX_LUA;

        string strLuaPath = YwPathMng.DATA_CATAGORY_LUA + Path.DirectorySeparatorChar + strFinalFile;
        string strFullPath = YwPathMng.Instance.GetLoadUrl(strLuaPath);

        // Get bytes from file.
        byte[] aContents = null;
        if (strFullPath.StartsWith(YwPathMng.JAR_URL_PREFIX))
        {
            // Read from www. (Android platform.)
            WWW cDataPack = new WWW(strFullPath);
            while (!cDataPack.isDone)
            {
            }

            if (!string.IsNullOrEmpty(cDataPack.error))
            {
                Debug.LogError(cDataPack.error);
                return null;
            }

            int nDataLength = cDataPack.bytes.Length;
            if (0 == nDataLength)
            {
                Debug.LogError("No content in file: " + strFullPath);
            }

            aContents = new byte[nDataLength];
            Buffer.BlockCopy(cDataPack.bytes, 0, aContents, 0, nDataLength);

            cDataPack.Dispose();
            cDataPack = null;
        }
        else
        {
            // Read from file.
            YwArchiveBinFile cArc = new YwArchiveBinFile();
            if (!cArc.Open(strFullPath, FileMode.Open, FileAccess.Read))
            {
                return null;
            }

            if (!cArc.IsValid())
            {
                return null;
            }

            int nContentLength = (int)cArc.GetStream().Length;
            aContents = new byte[nContentLength];
            cArc.ReadBuffer(ref aContents, nContentLength);
            cArc.Close();
        }

        return aContents;
    }
Esempio n. 5
0
    /**
     * Computer a md5 hash from file.
     * 
     * @param string strFilePath - The file path.
     * @return string - The md5 hash.
     */
    public string ComputeHash(string strFilePath)
    {
        if (string.IsNullOrEmpty(strFilePath))
        {
            return string.Empty;
        }

        YwArchiveBinFile cFileArc = new YwArchiveBinFile();
        if (!cFileArc.Open(strFilePath, FileMode.Open, FileAccess.Read))
        {
            return string.Empty;
        }

        if (!cFileArc.IsValid())
        {
            return string.Empty;
        }

        string strMd5Hash = ComputeHash(cFileArc.GetStream());
        cFileArc.Close();

        return strMd5Hash;
    }
Esempio n. 6
0
    /**
     * The lua file loader from streaming asset folder.
     *
     * @param string strFile - The file name.
     * @return byte[] - The loaded bytes.
     */
    private static byte[] LuaStreamFileLoader(string strFile)
    {
        if (string.IsNullOrEmpty(strFile))
        {
            return(null);
        }

        string strFinalFile = strFile.Replace('.', YwPathMng.PATH_SEPARATE_CHAR_SLASH);

        strFinalFile += YwPathMng.FILE_AFFIX_LUA;

        string strLuaPath  = YwPathMng.DATA_CATAGORY_LUA + Path.DirectorySeparatorChar + strFinalFile;
        string strFullPath = YwPathMng.Instance.GetLoadUrl(strLuaPath);

        // Get bytes from file.
        byte[] aContents = null;
        if (strFullPath.StartsWith(YwPathMng.JAR_URL_PREFIX))
        {
            // Read from www. (Android platform.)
            WWW cDataPack = new WWW(strFullPath);
            while (!cDataPack.isDone)
            {
            }

            if (!string.IsNullOrEmpty(cDataPack.error))
            {
                Debug.LogError(cDataPack.error);
                return(null);
            }

            int nDataLength = cDataPack.bytes.Length;
            if (0 == nDataLength)
            {
                Debug.LogError("No content in file: " + strFullPath);
            }

            aContents = new byte[nDataLength];
            Buffer.BlockCopy(cDataPack.bytes, 0, aContents, 0, nDataLength);

            cDataPack.Dispose();
            cDataPack = null;
        }
        else
        {
            // Read from file.
            YwArchiveBinFile cArc = new YwArchiveBinFile();
            if (!cArc.Open(strFullPath, FileMode.Open, FileAccess.Read))
            {
                return(null);
            }

            if (!cArc.IsValid())
            {
                return(null);
            }

            int nContentLength = (int)cArc.GetStream().Length;
            aContents = new byte[nContentLength];
            cArc.ReadBuffer(ref aContents, nContentLength);
            cArc.Close();
        }

        return(aContents);
    }