diff --git a/cocos2d/core/load-pipeline/CCLoader.js b/cocos2d/core/load-pipeline/CCLoader.js index dfca92742b..90c9d32024 100644 --- a/cocos2d/core/load-pipeline/CCLoader.js +++ b/cocos2d/core/load-pipeline/CCLoader.js @@ -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.
diff --git a/cocos2d/core/load-pipeline/md5-pipe.js b/cocos2d/core/load-pipeline/md5-pipe.js new file mode 100644 index 0000000000..22378521e7 --- /dev/null +++ b/cocos2d/core/load-pipeline/md5-pipe.js @@ -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; diff --git a/cocos2d/core/platform/CCAssetLibrary.js b/cocos2d/core/platform/CCAssetLibrary.js index 549abf303a..60aa81fc80 100644 --- a/cocos2d/core/platform/CCAssetLibrary.js +++ b/cocos2d/core/platform/CCAssetLibrary.js @@ -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;