コード例 #1
0
        public static void DownloadFile(string titleId, string path, ContentInfo content, Action <bool, string, ContentInfo> callback)
        {
            var currentPlayFabTitleId = PlayFabSettings.TitleId;
            var currentDevKey         = PlayFabSettings.DeveloperSecretKey;

            var title = FindTitle(titleId);

            PlayFabSettings.TitleId            = titleId;
            PlayFabSettings.DeveloperSecretKey = title.SecretKey;

            PlayFabServerAPI.GetContentDownloadUrlAsync(new GetContentDownloadUrlRequest()
            {
                Key        = content.Key,
                HttpMethod = "GET"
            }).ContinueWith((result) =>
            {
                if (result.Result.Error != null)
                {
                    Console.WriteLine(PlayFabUtil.GetErrorReport(result.Result.Error));
                    callback(false, null, null);
                    return;
                }

                if (result.IsCompleted)
                {
                    var folderPathArray = content.Key.Split('/');
                    var fileName        = folderPathArray.ToList().Last();

                    var filePath = string.Format("{0}\\{1}", path, fileName);
                    PlayFabExtensions.DownloadFile(result.Result.Result.URL, filePath, (success) =>
                    {
                        PlayFabSettings.TitleId            = currentPlayFabTitleId;
                        PlayFabSettings.DeveloperSecretKey = currentDevKey;
                        if (success)
                        {
                            callback(true, filePath, content);
                            return;
                        }
                        callback(false, null, null);
                    });
                }
            });
        }
コード例 #2
0
ファイル: PlayFabService.cs プロジェクト: lowasa/PlayFabCLI
        async public static Task <DownloadedFile> DownloadFile(string titleId, string path, ContentInfo content)
        {
            var currentPlayFabTitleId = PlayFabSettings.TitleId;
            var currentDevKey         = PlayFabSettings.DeveloperSecretKey;

            var title = FindTitle(titleId);

            PlayFabSettings.TitleId            = titleId;
            PlayFabSettings.DeveloperSecretKey = title.SecretKey;

            var result = await PlayFabServerAPI.GetContentDownloadUrlAsync(new GetContentDownloadUrlRequest()
            {
                Key        = content.Key,
                HttpMethod = "GET"
            });

            if (result.Error != null)
            {
                Console.WriteLine(PlayFabUtil.GetErrorReport(result.Error));
                return(null);
            }

            var folderPathArray = content.Key.Split('/');
            var fileName        = folderPathArray.ToList().Last();

            var filePath = string.Format("{0}\\{1}", path, fileName);
            var success  = await PlayFabExtensions.DownloadFile(result.Result.URL, filePath);

            PlayFabSettings.TitleId            = currentPlayFabTitleId;
            PlayFabSettings.DeveloperSecretKey = currentDevKey;
            if (!success)
            {
                return(null);
            }
            return(new DownloadedFile()
            {
                Data = content, FilePath = filePath
            });
        }