예제 #1
0
    static XGameUpdate.UpdateFileInfo GenFiles(string inputPath, bool isCry)
    {
        if (inputPath == null || inputPath.Equals(""))
        {
            return(null);
        }

        var fi  = new XGameUpdate.UpdateFileInfo();
        var dir = inputPath.Split('/');

        //压缩出来的文件加个随机数
        fi.name = dir[dir.Length - 1];
        int randomNum = UnityEngine.Random.Range(0, 999999999);

        fi.packageName = fi.name + "_" + randomNum;

        ForeachFile(inputPath, (string f) =>
        {
            Debug.LogWarning("genfile " + f);
            if (Path.GetExtension(f).Equals("meta"))
            {
                File.Delete(f);
            }
            else
            {
                if (isCry)
                {
                    CryFile(f);
                }
            }
        });

        var outPath = inputPath + "_" + randomNum + ".zip";

        if (File.Exists(outPath))
        {
            if (File.Exists(outPath + "_bk"))
            {
                File.Delete(outPath + "_bk");
            }
            File.Move(outPath, outPath + "_bk");
        }
        Debug.LogError("zipfile " + inputPath);
        DWTools.FastZipCompress(inputPath, outPath);


        fi.md5    = DWTools.GenMD5(outPath);
        fi.length = GetFileLength(outPath);

        return(fi);
    }
예제 #2
0
    private JsonData Get(string key)
    {
        if (m_localMD5Json == null)
        {
            return(null);
        }

        if (DWTools.JsonDataContainsKey(m_localMD5Json, key))
        {
            return(m_localMD5Json[key]);
        }
        else
        {
            return(null);
        }
    }
예제 #3
0
    static long GenFile(string inputPath, bool isCry)
    {
        if (isCry)
        {
            CryFile(inputPath);
        }
        var filePath = inputPath + ".zip";

        if (File.Exists(filePath))
        {
            File.Delete(filePath);
        }
        DWTools.FastZipCompress(inputPath);
        var fileInfo = new FileInfo(filePath);

        return(fileInfo.Length);
    }
예제 #4
0
    /// <summary>
    /// 更多的检测 因为文件放进来Cache  更容易被删掉
    /// </summary>
    /// <param name="resInfo"></param>
    /// <returns></returns>
    public bool IsResourceExisted(UpdateInfo.ResInfo resInfo)
    {
        var key     = GetKeyForRes(resInfo);
        var zipInfo = Get(key);

        if (!DWTools.JsonDataContainsKey(zipInfo, "md5"))
        {
            return(false);
        }
        if (!resInfo.md5.Equals(zipInfo["md5"].ToString()))
        {
            return(false);
        }
        if (!DWTools.JsonDataContainsKey(zipInfo, "fileList"))
        {
            return(false);
        }
        var      fileList = zipInfo["fileList"];
        JsonData data     = JsonMapper.ToObject(fileList.ToString());

        if (data.IsArray)
        {
            for (int fi = 0; fi < data.Count; fi++)
            {
                var str = data[fi].ToString();
                //如果这个更新需要的文件不存在  那么就需要更新
                if (!File.Exists(str))
                {
                    return(false);
                }
            }
        }
        else
        {
            return(true);
        }

        return(true);
    }
예제 #5
0
    //开始下载
    public void BeginDownLoad()
    {
        m_stop            = false;
        m_hasDownLoadBits = 0;      //用于显示当前的进度
        long       lStartPos = 0;   //打开上次下载的文件或新建文件
        FileStream fs;

        if (File.Exists(m_fileName))
        {
            var md5 = DWTools.GenMD5(m_fileName);
            Debug.Log("get md5:" + md5);
            Debug.Log("need md5:" + m_md5);
            if (m_md5.ToLower() == md5.ToLower())
            {
                m_downLoadStatus = EnumDownLoadStatus.EDLS_SUCCESS;
                return;
            }

            fs        = File.OpenWrite(m_fileName); //打开流
            lStartPos = fs.Length;                  //通过字节流的长度确定当前的下载位置
            fs.Seek(lStartPos, SeekOrigin.Current); //移动文件流中的当前指针
        }
        else
        {
            fs        = new FileStream(m_fileName, FileMode.Create);
            lStartPos = 0;
        }

        try
        {
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(m_url);
            request.Timeout = 10000;
            if (lStartPos > 0)
            {
                request.AddRange((int)lStartPos);                 //设置Range值
                m_hasDownLoadBits += lStartPos;
            }

            //向服务器请求,获得服务器回应数据流
            Stream ns = request.GetResponse().GetResponseStream();
            ns.ReadTimeout = 10000;
            byte[] nbytes    = new byte[1024 * 1024];
            int    nReadSize = 0;
            nReadSize = ns.Read(nbytes, 0, 1024 * 1024);
            while (nReadSize > 0 || m_stop)
            {
                fs.Write(nbytes, 0, nReadSize);
                m_hasDownLoadBits = m_hasDownLoadBits + nReadSize;
                nReadSize         = ns.Read(nbytes, 0, 1024 * 1024);
            }
            ns.Close();
            fs.Flush();
            if (m_stop)
            {
                Debug.LogError("Stop Success");
                m_downLoadStatus = EnumDownLoadStatus.EDLS_STOP;
                fs.Close();
            }
            else
            {
                //检测MD5
                fs.Close();
                var md5 = DWTools.GenMD5(m_fileName);

                Debug.Log("get md5:" + md5);
                Debug.Log("need md5:" + m_md5);

                if (m_md5.ToLower() == md5.ToLower())
                {
                    m_downLoadStatus = EnumDownLoadStatus.EDLS_SUCCESS;
                }
                else
                {
                    File.Delete(m_fileName);
                    m_downLoadStatus = EnumDownLoadStatus.EDLS_MD5WRONG;
                }
            }
        }
        catch (Exception ex)
        {
            fs.Close();
            m_downLoadStatus = EnumDownLoadStatus.EDLS_NETERROR;
            Debug.LogError(ex.ToString());
        }
    }