mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-01 15:52:40 +08:00
Merge pull request #1801 from zilongshanren/fix-pipeline-issue
add md5Pipe
This commit is contained in:
@@ -923,6 +923,7 @@ proto.setAutoReleaseRecursively = function (assetOrUrlOrUuid, autoRelease) {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* !#en
|
||||
* Returns whether the asset is configured as auto released, despite how "Auto Release Assets" property is set on scene asset.<br>
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2017 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Chukong Aipu reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
var Pipeline = require('./pipeline');
|
||||
|
||||
var ID = 'MD5Pipe';
|
||||
var FilePathRegex = /^(.+)*\.(.+)$/;
|
||||
|
||||
var MD5Pipe = function (md5AssetsMap) {
|
||||
this.id = ID;
|
||||
this.async = false;
|
||||
this.pipeline = null;
|
||||
this.md5AssetsMap = md5AssetsMap;
|
||||
};
|
||||
MD5Pipe.ID = ID;
|
||||
|
||||
MD5Pipe.prototype.handle = function(item) {
|
||||
let hashValue = this.md5AssetsMap[item.url];
|
||||
if (hashValue) {
|
||||
item.url = item.url.replace(FilePathRegex, function(match, p1, p2) {
|
||||
return p1 + '.' + hashValue + '.' + p2;
|
||||
});
|
||||
}
|
||||
return item;
|
||||
};
|
||||
|
||||
|
||||
Pipeline.MD5Pipe = module.exports = MD5Pipe;
|
||||
@@ -29,6 +29,7 @@ var Loader = require('../load-pipeline/CCLoader');
|
||||
var PackDownloader = require('../load-pipeline/pack-downloader');
|
||||
var AutoReleaseUtils = require('../load-pipeline/auto-release-utils');
|
||||
var decodeUuid = require('../utils/decode-uuid');
|
||||
var MD5Pipe = require('../load-pipeline/md5-pipe');
|
||||
|
||||
/**
|
||||
* The asset library which managing loading/unloading assets in project.
|
||||
@@ -274,6 +275,11 @@ var AssetLibrary = {
|
||||
return;
|
||||
}
|
||||
|
||||
var md5AssetsMap = options.md5AssetsMap;
|
||||
if (md5AssetsMap) {
|
||||
cc.loader.insertPipeAfter(cc.loader.assetLoader, new MD5Pipe(md5AssetsMap));
|
||||
}
|
||||
|
||||
// 这里将路径转 url,不使用路径的原因是有的 runtime 不能解析 "\" 符号。
|
||||
// 不使用 url.format 的原因是 windows 不支持 file:// 和 /// 开头的协议,所以只能用 replace 操作直接把路径转成 URL。
|
||||
var libraryPath = options.libraryPath;
|
||||
|
||||
Reference in New Issue
Block a user