zoukankan      html  css  js  c++  java
  • laya zip更新方案

    1.将要打包的的资源和layaairfiles.txt文件一起打成zip.

    2.预加载阶段,先将zip包通过downfile下载并解压到缓存目录.

    3.设置baseurl,开始预加载所有资源.

    4.下面为node.js编写的自动生成layaairfiles.txt的脚本

    var fs = require("fs");
    
    var cacheData = "";
    var tmp = {};
    var totalSize = 0;
    var nowTime = Date.now();
    var BaseUrl = "https://0.0.3/";
    var BasePath = "./bin/";
    var fileList = fs.readdirSync(BasePath);
    tmp["fileUsedSize"] = totalSize;
    for(var i=0;i<fileList.length;i++){
        var file = fileList[i];
        var stats = fs.statSync(BasePath+file);
        if(stats.isDirectory()){
            readFile(BasePath+file+"/",file+"/");
        }else{
            totalSize += stats.size;
            tmp[BaseUrl+file] = {};
            var data = tmp[BaseUrl+file];
            data["md5"] = prePath+file;
            data["readyUrl"] = BaseUrl+file;
            data["size"] = stats.size;
            data["times"] = nowTime;
            var arr = file.split('.');
            if(arr[1] == "atlas"){
                data["encoding"] = "utf8";
            }else{
                data["encoding"] = "";
            }
        }
    }
    tmp["fileUsedSize"] = totalSize;
    var str = JSON.stringify(tmp);
    fs.writeFileSync('./layaairfiles.txt',str);
    
    function readFile(readurl,prePath){
        var fileList = fs.readdirSync(readurl);
        for(var i=0;i<fileList.length;i++){
            var file = fileList[i];
            var stats = fs.statSync(readurl+file);
            if(stats.isDirectory()){
                readFile(readurl+"/"+file+"/",prePath+file+"/");
            }else{
                totalSize += stats.size;
                tmp[BaseUrl+prePath+file] = {};
                var data = tmp[BaseUrl+prePath+file];
                data["md5"] = prePath+file;
                data["readyUrl"] = BaseUrl+prePath+file;
                data["size"] = stats.size;
                data["times"] = nowTime;
                var arr = file.split('.');
                if(arr[1] == "atlas"){
                    data["encoding"] = "utf8";
                }else{
                    data["encoding"] = "";
                }
            }
        }
    }

    5.将下载下来的zip文件解压到缓存目录

    Laya.MiniAdpter.removeAll();
    wx.getFileSystemManager().unzip({
        zipFilePath: res.tempFilePath,
        targetPath: laya.wx.mini.MiniFileMgr.fileNativeDir,
        success: () => {
            this.unzipSuccess();
        },
        fail: (res) => {
            this.unzipFail(res);
        }
    });

  • 相关阅读:
    nyoj 95 众数问题(set)
    nyoj 93 汉诺塔(三)(stack)
    hdu 1010 Tempter of the Bone
    nyoj 55 懒省事的小明(priority_queue优先队列)
    nyoj 31 5个数求最值
    poj 1256 Anagram
    next_permutation函数
    nyoj 19 擅长排列的小明(深搜,next_permutation)
    nyoj 8 一种排序(用vector,sort,不用set)
    nyoj 5 Binary String Matching(string)
  • 原文地址:https://www.cnblogs.com/wsswlyy/p/10973653.html
Copyright © 2011-2022 走看看