Example #1
0
    public bool SaveVersion()
    {
        byte[]       data;
        MemoryStream ms = new MemoryStream(ResManager.RES_NUM * 4 + 4);

        for (int i = 0; i < ResManager.RES_NUM; ++i)
        {
            data = System.BitConverter.GetBytes(m_ResVer[i].ResCrc);
            ms.Write(data, 0, data.Length);
        }
        data = ms.ToArray();
        ms.Close();

        uint crc = Crc.Crc32(data, 0, data.Length);

        byte[]       crcValue = System.BitConverter.GetBytes(crc);
        MemoryStream ms2      = new MemoryStream(data.Length + crcValue.Length);

        ms2.Write(crcValue, 0, crcValue.Length);
        ms2.Write(data, 0, data.Length);
        bool bRet = RuntimeInfo.SaveLocalFile(RuntimeInfo.GetVersionFileName(), ms2.ToArray());

        ms2.Close();
        return(bRet);
    }
Example #2
0
    public void Init()
    {
        //读取自带的版本号
        LoadInnerVersion();

        //读取SD卡的版本
        byte[] data = RuntimeInfo.GetLocalFile(RuntimeInfo.GetVersionFileName());
        if (data == null || data.Length != ResManager.RES_NUM * 4 + 4)
        {
            return;
        }
        uint crc = Crc.Crc32(data, 4, data.Length - 4);

        if (crc != System.BitConverter.ToUInt32(data, 0))
        {
            return;
        }

        for (int i = 0, idx = 4; i < ResManager.RES_NUM; ++i, idx += 4)
        {
            uint     resCrc = System.BitConverter.ToUInt32(data, idx);
            string   path   = RuntimeInfo.GetResPersistentPath((ResType)i);
            FileInfo fi     = new FileInfo(path);
            if (!fi.Exists)
            {
                continue;
            }
            m_ResVer[i].ResSize = (uint)fi.Length;
            m_ResVer[i].ResCrc  = resCrc;
        }
        m_bHasVerFile = true;
    }