|
@@ -17,9 +17,19 @@ using Newtonsoft.Json.Linq;
|
|
|
|
|
|
public class COSDownLoad:MonoSingleton<COSDownLoad>
|
|
|
{
|
|
|
- public SuccessCOS successCos;
|
|
|
- QCloudCredentialProvider cosCredentialProvider;
|
|
|
- CosXml cosXml;
|
|
|
+
|
|
|
+
|
|
|
+ * 根据下载的类型 分为 -1 Scene Materail -2 vuforial
|
|
|
+ *
|
|
|
+ */
|
|
|
+
|
|
|
+ public SuccessCOS materialSuccessCos;
|
|
|
+ public SuccessCOS sceneSuccessCos;
|
|
|
+ public SuccessCOS imageSuccessCos;
|
|
|
+
|
|
|
+ CosXml materialCosXml;
|
|
|
+ CosXml sceneCosXml;
|
|
|
+ CosXml imageCosXml;
|
|
|
|
|
|
|
|
|
public void Credential()
|
|
@@ -27,43 +37,109 @@ public class COSDownLoad:MonoSingleton<COSDownLoad>
|
|
|
Credential credential = new Credential();
|
|
|
credential.type = "material";
|
|
|
string data = JsonConvert.SerializeObject(credential);
|
|
|
- Debug.Log("Hjj "+data);
|
|
|
- HttpTool.Instance.Post("/storage/credential/create", data, CredentialCallBack);
|
|
|
+ Debug.Log(data);
|
|
|
+ HttpTool.Instance.Post("/storage/credential/create", data, CredentialMaterialCallBack);
|
|
|
+
|
|
|
+ Credential credential2 = new Credential();
|
|
|
+ credential2.type = "scene";
|
|
|
+ string data2 = JsonConvert.SerializeObject(credential2);
|
|
|
+ HttpTool.Instance.Post("/storage/credential/create", data2, CredentialSceneCallBack);
|
|
|
+
|
|
|
+ Credential credential3 = new Credential();
|
|
|
+ credential3.type = "image";
|
|
|
+ string data3 = JsonConvert.SerializeObject(credential3);
|
|
|
+ HttpTool.Instance.Post("/storage/credential/create", data3, CredentialImageCallBack);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void InitMaterialCos()
|
|
|
+ {
|
|
|
+ CosXmlConfig config = new CosXmlConfig.Builder()
|
|
|
+ .IsHttps(true)
|
|
|
+ .SetRegion(materialSuccessCos.region)
|
|
|
+ .SetDebugLog(true)
|
|
|
+ .Build();
|
|
|
+ QCloudCredentialProvider cosCredentialProvider = new DefaultSessionQCloudCredentialProvider(
|
|
|
+ materialSuccessCos.credentials.tmpSecretId, materialSuccessCos.credentials.tmpSecretKey, materialSuccessCos.expiredTime, materialSuccessCos.credentials.sessionToken);
|
|
|
+
|
|
|
+ materialCosXml = new CosXmlServer(config, cosCredentialProvider);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void InitImageCos()
|
|
|
+ {
|
|
|
+ CosXmlConfig config = new CosXmlConfig.Builder()
|
|
|
+ .IsHttps(true)
|
|
|
+ .SetRegion(imageSuccessCos.region)
|
|
|
+ .SetDebugLog(true)
|
|
|
+ .Build();
|
|
|
+ QCloudCredentialProvider cosCredentialProvider = new DefaultSessionQCloudCredentialProvider(
|
|
|
+ imageSuccessCos.credentials.tmpSecretId, imageSuccessCos.credentials.tmpSecretKey, imageSuccessCos.expiredTime, imageSuccessCos.credentials.sessionToken);
|
|
|
+
|
|
|
+ imageCosXml = new CosXmlServer(config, cosCredentialProvider);
|
|
|
}
|
|
|
|
|
|
- private void InitCos()
|
|
|
+ private void InitSceneCos()
|
|
|
{
|
|
|
CosXmlConfig config = new CosXmlConfig.Builder()
|
|
|
.IsHttps(true)
|
|
|
- .SetRegion(successCos.region)
|
|
|
+ .SetRegion(sceneSuccessCos.region)
|
|
|
.SetDebugLog(true)
|
|
|
.Build();
|
|
|
- cosCredentialProvider = new DefaultSessionQCloudCredentialProvider(
|
|
|
- successCos.credentials.tmpSecretId, successCos.credentials.tmpSecretKey, successCos.expiredTime, successCos.credentials.sessionToken);
|
|
|
+ QCloudCredentialProvider cosCredentialProvider = new DefaultSessionQCloudCredentialProvider(
|
|
|
+ sceneSuccessCos.credentials.tmpSecretId, sceneSuccessCos.credentials.tmpSecretKey, sceneSuccessCos.expiredTime, sceneSuccessCos.credentials.sessionToken);
|
|
|
|
|
|
- cosXml = new CosXmlServer(config, cosCredentialProvider);
|
|
|
+ sceneCosXml = new CosXmlServer(config, cosCredentialProvider);
|
|
|
+ }
|
|
|
|
|
|
+ private void CredentialMaterialCallBack( string msg)
|
|
|
+ {
|
|
|
+ Debug.Log(msg);
|
|
|
+ JObject jObject = JObject.Parse(msg);
|
|
|
|
|
|
-
|
|
|
+ if (jObject["code"].ToString() == "200")
|
|
|
+ {
|
|
|
+ materialSuccessCos = JsonConvert.DeserializeObject<SuccessCOS>(jObject["data"].ToString());
|
|
|
+ InitMaterialCos();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Debug.LogError(msg);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- private void CredentialCallBack( string msg)
|
|
|
+ private void CredentialSceneCallBack(string msg)
|
|
|
{
|
|
|
Debug.Log(msg);
|
|
|
JObject jObject = JObject.Parse(msg);
|
|
|
|
|
|
if (jObject["code"].ToString() == "200")
|
|
|
{
|
|
|
- Debug.Log("Hjj --->"+ jObject["data"].ToString());
|
|
|
- successCos = JsonConvert.DeserializeObject<SuccessCOS>(jObject["data"].ToString());
|
|
|
- InitCos();
|
|
|
+ sceneSuccessCos = JsonConvert.DeserializeObject<SuccessCOS>(jObject["data"].ToString());
|
|
|
+ InitMaterialCos();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Debug.LogError(msg);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void CredentialImageCallBack(string msg)
|
|
|
+ {
|
|
|
+ Debug.Log(msg);
|
|
|
+ JObject jObject = JObject.Parse(msg);
|
|
|
+
|
|
|
+ if (jObject["code"].ToString() == "200")
|
|
|
+ {
|
|
|
+ imageSuccessCos = JsonConvert.DeserializeObject<SuccessCOS>(jObject["data"].ToString());
|
|
|
+ InitImageCos();
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
Debug.LogError(msg);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
}
|
|
|
|
|
|
|
|
@@ -82,19 +158,34 @@ public class COSDownLoad:MonoSingleton<COSDownLoad>
|
|
|
|
|
|
|
|
|
|
|
|
+ TransferManager transferManager;
|
|
|
+ String bucket;
|
|
|
+ switch (downloadMaterial.type)
|
|
|
+ {
|
|
|
+ case "-1":
|
|
|
+ transferManager = new TransferManager(sceneCosXml, transferConfig);
|
|
|
+ bucket = sceneSuccessCos.bucket;
|
|
|
+ break;
|
|
|
+ case "-2":
|
|
|
+ transferManager = new TransferManager(imageCosXml, transferConfig);
|
|
|
+ bucket = imageSuccessCos.bucket;
|
|
|
+ break;
|
|
|
+
|
|
|
+ default:
|
|
|
+ transferManager = new TransferManager(materialCosXml, transferConfig);
|
|
|
+ bucket = materialSuccessCos.bucket;
|
|
|
+ break;
|
|
|
+ }
|
|
|
|
|
|
-
|
|
|
-
|
|
|
- TransferManager transferManager = new TransferManager(cosXml, transferConfig);
|
|
|
-
|
|
|
-
|
|
|
- String bucket = successCos.bucket;
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string localFileName = Path.GetFileName(downloadMaterial.downLoadPath);
|
|
|
- Debug.Log("HJJ ===> " + bucket + " " + downloadMaterial.downLoadPath + " " + localDir + " " + localFileName);
|
|
|
+
|
|
|
+ localDir = downloadMaterial.localLoadPath.Substring(0, downloadMaterial.localLoadPath.Length - localFileName.Length);
|
|
|
|
|
|
COSXMLDownloadTask downloadTask = new COSXMLDownloadTask(bucket, downloadMaterial.downLoadPath,
|
|
|
localDir, localFileName);
|
|
@@ -107,6 +198,7 @@ public class COSDownLoad:MonoSingleton<COSDownLoad>
|
|
|
|
|
|
Debug.Log(downloadMaterial.downLoadPath);
|
|
|
downloadTask.onState += OnState;
|
|
|
+ listDownLoadTask.Add(downloadTask);
|
|
|
try
|
|
|
{
|
|
|
COSXML.Transfer.COSXMLDownloadTask.DownloadTaskResult result = await
|
|
@@ -117,16 +209,16 @@ public class COSDownLoad:MonoSingleton<COSDownLoad>
|
|
|
catch (COSXML.CosException.CosClientException clientEx)
|
|
|
{
|
|
|
|
|
|
- Debug.LogError("Hjj " + downloadMaterial.downLoadPath + " CosClientException: " + clientEx);
|
|
|
+ Debug.LogError(downloadMaterial.downLoadPath + " CosClientException: " + clientEx);
|
|
|
DownloadResManager.Instance.DownLoadFaild(downloadTask.localFileName);
|
|
|
}
|
|
|
catch (COSXML.CosException.CosServerException serverEx)
|
|
|
{
|
|
|
|
|
|
- Debug.LogError("Hjj "+downloadMaterial.downLoadPath+ " CosServerException: " + serverEx.GetInfo());
|
|
|
+ Debug.LogError(downloadMaterial.downLoadPath+ " CosServerException: " + serverEx.GetInfo());
|
|
|
DownloadResManager.Instance.DownLoadFaild(downloadTask.localFileName);
|
|
|
}
|
|
|
- listDownLoadTask.Add(downloadTask);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
private List<COSXML.Transfer.COSXMLDownloadTask.DownloadTaskResult> listResult = new List<COSXMLDownloadTask.DownloadTaskResult>();
|
|
@@ -144,10 +236,10 @@ public class COSDownLoad:MonoSingleton<COSDownLoad>
|
|
|
TransferConfig transferConfig = new TransferConfig();
|
|
|
|
|
|
|
|
|
- TransferManager transferManager = new TransferManager(cosXml, transferConfig);
|
|
|
+ TransferManager transferManager = new TransferManager(materialCosXml, transferConfig);
|
|
|
|
|
|
|
|
|
- string bucket = successCos.bucket;
|
|
|
+ string bucket = materialSuccessCos.bucket;
|
|
|
|
|
|
Debug.Log(listDLMaterial.Count);
|
|
|
|
|
@@ -155,19 +247,19 @@ public class COSDownLoad:MonoSingleton<COSDownLoad>
|
|
|
{
|
|
|
string cosPath = listDLMaterial[i].downLoadPath;
|
|
|
Debug.Log(cosPath);
|
|
|
- if(cosPath.IsNormalized()||cosPath=="")
|
|
|
+ if(cosPath==null||cosPath=="")
|
|
|
{
|
|
|
DownloadResManager.Instance.DownLoadFaild(listDLMaterial[i].localLoadPath);
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
string localFileName = Path.GetFileName(listDLMaterial[i].localLoadPath);
|
|
|
- Debug.Log("HJJ ===> " + bucket + " " + cosPath + " " + localDir + " " + localFileName);
|
|
|
+ Debug.Log(cosPath + " " + localDir + localFileName);
|
|
|
COSXMLDownloadTask downloadTask = new COSXMLDownloadTask(bucket, cosPath,
|
|
|
localDir, localFileName);
|
|
|
downloadTask.failCallback = delegate (CosClientException clientException, CosServerException serverException)
|
|
|
{
|
|
|
- Debug.LogError("HJJ ==clientException.errorCode : " + clientException.errorCode + " serverException.errorCode: " + serverException.errorCode +
|
|
|
+ Debug.LogError("clientException.errorCode : " + clientException.errorCode + " serverException.errorCode: " + serverException.errorCode +
|
|
|
" serverException.errorMessage : " + serverException.errorMessage);
|
|
|
};
|
|
|
downloadTask.onState += OnState;
|
|
@@ -179,13 +271,13 @@ public class COSDownLoad:MonoSingleton<COSDownLoad>
|
|
|
catch (COSXML.CosException.CosClientException clientEx)
|
|
|
{
|
|
|
|
|
|
- Debug.LogError("HJJ ==CosClientException: " + clientEx);
|
|
|
+ Debug.LogError("CosClientException: " + clientEx);
|
|
|
DownloadResManager.Instance.DownLoadFaild(downloadTask.localFileName);
|
|
|
}
|
|
|
catch (COSXML.CosException.CosServerException serverEx)
|
|
|
{
|
|
|
|
|
|
- Debug.LogError("HJJ ==CosServerException: " + serverEx.GetInfo());
|
|
|
+ Debug.LogError("CosServerException: " + serverEx.GetInfo());
|
|
|
DownloadResManager.Instance.DownLoadFaild(downloadTask.localFileName);
|
|
|
}
|
|
|
|
|
@@ -198,7 +290,7 @@ public class COSDownLoad:MonoSingleton<COSDownLoad>
|
|
|
|
|
|
try
|
|
|
{
|
|
|
- string requestURL = cosXml.GetObjectUrl(successCos.bucket, downloadMaterial.LocaDataPath);
|
|
|
+ string requestURL = materialCosXml.GetObjectUrl(materialSuccessCos.bucket, downloadMaterial.LocaDataPath);
|
|
|
return requestURL;
|
|
|
}
|
|
|
catch (COSXML.CosException.CosClientException clientEx)
|
|
@@ -216,30 +308,6 @@ public class COSDownLoad:MonoSingleton<COSDownLoad>
|
|
|
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
- public async void DownloadObjectTrafficLimit(string cosPath, string localDir, string localFileName)
|
|
|
- {
|
|
|
-
|
|
|
- TransferConfig transferConfig = new TransferConfig();
|
|
|
-
|
|
|
-
|
|
|
- TransferManager transferManager = new TransferManager(cosXml, transferConfig);
|
|
|
-
|
|
|
- String bucket = successCos.bucket;
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- GetObjectRequest request = new GetObjectRequest(bucket,
|
|
|
- cosPath, localDir, localFileName);
|
|
|
- request.LimitTraffic(8 * 1000 * 1024);
|
|
|
-
|
|
|
- COSXMLDownloadTask downloadTask = new COSXMLDownloadTask(request);
|
|
|
- await transferManager.DownloadAsync(downloadTask);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
private void OnState(TaskState state)
|
|
|
{
|
|
|
Debug.Log(state);
|