mm
This commit is contained in:
@@ -3,6 +3,9 @@ local db = {}
|
||||
|
||||
local dbUploadStatus = {}
|
||||
local isUploading = {}
|
||||
local isDownoading = {}
|
||||
local downloadCallback = {}
|
||||
local downloadDir = Utl.chgToSDCard(Path.Combine(Application.persistentDataPath, CLPathCfg.self.basePath, "download"))
|
||||
|
||||
function DBTextures.init()
|
||||
InvokeEx.cancelInvoke(DBTextures.releaseTimeout)
|
||||
@@ -99,4 +102,66 @@ function DBTextures.cancelUpload(path, uploadPath)
|
||||
end
|
||||
end
|
||||
|
||||
function DBTextures.hadDownloaded(name)
|
||||
local localPath = Path.Combine(downloadDir, name)
|
||||
if File.Exists(localPath) then
|
||||
return true, localPath
|
||||
end
|
||||
return false, localPath
|
||||
end
|
||||
|
||||
function DBTextures.download(name, url, callback)
|
||||
downloadCallback[name] = callback
|
||||
if isDownoading[name] then
|
||||
return isDownoading[name]
|
||||
end
|
||||
local localPath = Path.Combine(downloadDir, name)
|
||||
local _url = url
|
||||
if File.Exists(localPath) then
|
||||
_url = Path.Combine("file://", localPath)
|
||||
end
|
||||
local assetType
|
||||
if MyUtl.isImage(name) then
|
||||
assetType = CLAssetType.texture
|
||||
else
|
||||
assetType = CLAssetType.bytes
|
||||
end
|
||||
|
||||
local www =
|
||||
WWWEx.get(
|
||||
_url,
|
||||
nil,
|
||||
CLAssetType.texture,
|
||||
function(content, orgs)
|
||||
isDownoading[name] = nil
|
||||
if content then
|
||||
local bytes
|
||||
if assetType == CLAssetType.texture then
|
||||
bytes = content:GetRawTextureData()
|
||||
else
|
||||
bytes = content
|
||||
end
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(localPath))
|
||||
File.WriteAllBytes(localPath, bytes)
|
||||
Utl.doCallback(downloadCallback[name], content, localPath)
|
||||
downloadCallback[name] = nil
|
||||
else
|
||||
MyUtl.toastW("下载附件为空")
|
||||
Utl.doCallback(downloadCallback[name], content, nil)
|
||||
downloadCallback[name] = nil
|
||||
end
|
||||
end,
|
||||
function()
|
||||
isDownoading[name] = nil
|
||||
MyUtl.toastW("下载附件失败")
|
||||
Utl.doCallback(downloadCallback[name], nil, nil)
|
||||
downloadCallback[name] = nil
|
||||
end,
|
||||
nil,
|
||||
true,
|
||||
2
|
||||
)
|
||||
isDownoading[name] = www
|
||||
end
|
||||
|
||||
return DBTextures
|
||||
|
||||
Reference in New Issue
Block a user