private void ProcessDownloadedFile(DownloadTask task) { // 打开安装对话框。 var path = FilePath.BinaryFilePath() + AppFileName; try { if (File.Exists(path)) { _dialogManager.ShowConfirmBox( string.Format("{0}下载完成", AppName), true, "安装", () => { #if UNITY_ANDROID _android.InstallApk(path); if (!string.IsNullOrEmpty(AwardCode)) { _remoteAPI.RequestAward(AwardCode); } #endif }, false, null, null, true, false, true); } } catch (Exception e) { _dialogManager.ShowToast("发生错误", 2, true); } }
private void DownloadFinish(DownloadTask task) { if (task == null) { return; } var www = task.Downloader; if (www == null) { return; } if (!string.IsNullOrEmpty(www.error)) { MyLog.ErrorWithFrame(name, string.Format("Download failed! url: {0}, error: {1}", task.Url, www.error)); return; } try { var type = task.Type; if (type == ContentType.Image) { // 将下载的图片保存到路径中。 if (!www.texture) { return; } if (string.IsNullOrEmpty(task.FileName)) { return; } var bytes = www.texture.EncodeToPNG(); _filePicManager.SavePic(bytes, task.FileName); } else if (type == ContentType.Bytes) { if (!Directory.Exists(FilePath.BinaryFilePath())) { Directory.CreateDirectory(FilePath.BinaryFilePath()); } var path = FilePath.BinaryFilePath() + task.FileName; File.WriteAllBytes(path, www.bytes); } else if (type == ContentType.Text) { if (!Directory.Exists(FilePath.TextPath())) { Directory.CreateDirectory(FilePath.TextPath()); } var path = FilePath.TextPath() + task.FileName; File.WriteAllBytes(path, www.bytes); } MyLog.InfoWithFrame(name, string.Format("Finish download: {0}", task.FileName)); } catch (Exception e) { MyLog.ErrorWithFrame(name, e.Message); } }