|
1 | 1 | using System;
|
2 | 2 | using System.Collections;
|
3 | 3 | using System.Collections.Generic;
|
| 4 | +using System.IO; |
4 | 5 | using UnityEngine;
|
5 | 6 | using LootLocker.Requests;
|
6 | 7 | using LootLocker;
|
@@ -789,6 +790,132 @@ public static void SetPlayerName(string name, Action<PlayerNameResponse> onCompl
|
789 | 790 |
|
790 | 791 | LootLockerAPIManager.SetPlayerName(data, onComplete);
|
791 | 792 | }
|
| 793 | + |
| 794 | + public static void GetPlayerFile(int fileId, Action<LootLockerPlayerFile> onComplete) |
| 795 | + { |
| 796 | + if (!CheckInitialized()) |
| 797 | + { |
| 798 | + onComplete?.Invoke(LootLockerResponseFactory.SDKNotInitializedError<LootLockerPlayerFile>()); |
| 799 | + return; |
| 800 | + } |
| 801 | + |
| 802 | + var endpoint = LootLockerEndPoints.getSingleplayerFile; |
| 803 | + |
| 804 | + endpoint.endPoint = string.Format(endpoint.endPoint, fileId); |
| 805 | + |
| 806 | + LootLockerServerRequest.CallAPI(endpoint, null, onComplete: (serverResponse) => { LootLockerResponse.Serialize(onComplete, serverResponse); }); |
| 807 | + } |
| 808 | + |
| 809 | + public static void GetAllPlayerFiles(Action<LootLockerPlayerFilesResponse> onComplete) |
| 810 | + { |
| 811 | + if (!CheckInitialized()) |
| 812 | + { |
| 813 | + onComplete?.Invoke(LootLockerResponseFactory.SDKNotInitializedError<LootLockerPlayerFilesResponse>()); |
| 814 | + return; |
| 815 | + } |
| 816 | + |
| 817 | + LootLockerServerRequest.CallAPI(LootLockerEndPoints.getplayerFiles, null, onComplete: (serverResponse) => { LootLockerResponse.Serialize(onComplete, serverResponse); }); |
| 818 | + } |
| 819 | + |
| 820 | + public static void UploadPlayerFile(string pathToFile, string filePurpose, Action<LootLockerPlayerFile> onComplete) |
| 821 | + { |
| 822 | + if (!CheckInitialized()) |
| 823 | + { |
| 824 | + onComplete?.Invoke(LootLockerResponseFactory.SDKNotInitializedError<LootLockerPlayerFile>()); |
| 825 | + return; |
| 826 | + } |
| 827 | + |
| 828 | + var body = new Dictionary<string, string>() |
| 829 | + { |
| 830 | + { "purpose", filePurpose } |
| 831 | + }; |
| 832 | + |
| 833 | + |
| 834 | + var fileBytes = new byte[] { }; |
| 835 | + try |
| 836 | + { |
| 837 | + fileBytes = File.ReadAllBytes(pathToFile); |
| 838 | + } |
| 839 | + catch (Exception e) |
| 840 | + { |
| 841 | + DebugMessage($"File error: {e.Message}"); |
| 842 | + return; |
| 843 | + } |
| 844 | + |
| 845 | + LootLockerServerRequest.UploadFile(LootLockerEndPoints.uploadPlayerFile, fileBytes, Path.GetFileName(pathToFile), "multipart/form-data", body, |
| 846 | + onComplete: (serverResponse) => |
| 847 | + { |
| 848 | + LootLockerResponse.Serialize(onComplete, serverResponse); |
| 849 | + }); |
| 850 | + } |
| 851 | + |
| 852 | + public static void UploadPlayerFile(FileStream fileStream, string filePurpose, Action<LootLockerPlayerFile> onComplete) |
| 853 | + { |
| 854 | + if (!CheckInitialized()) |
| 855 | + { |
| 856 | + onComplete?.Invoke(LootLockerResponseFactory.SDKNotInitializedError<LootLockerPlayerFile>()); |
| 857 | + return; |
| 858 | + } |
| 859 | + |
| 860 | + var body = new Dictionary<string, string>() |
| 861 | + { |
| 862 | + { "purpose", filePurpose } |
| 863 | + }; |
| 864 | + |
| 865 | + var fileBytes = new byte[fileStream.Length]; |
| 866 | + try |
| 867 | + { |
| 868 | + fileStream.Read(fileBytes, 0, Convert.ToInt32(fileStream.Length)); |
| 869 | + } |
| 870 | + catch (Exception e) |
| 871 | + { |
| 872 | + DebugMessage($"File error: {e.Message}"); |
| 873 | + return; |
| 874 | + } |
| 875 | + |
| 876 | + LootLockerServerRequest.UploadFile(LootLockerEndPoints.uploadPlayerFile, fileBytes, Path.GetFileName(fileStream.Name), "multipart/form-data", body, |
| 877 | + onComplete: (serverResponse) => |
| 878 | + { |
| 879 | + LootLockerResponse.Serialize(onComplete, serverResponse); |
| 880 | + }); |
| 881 | + } |
| 882 | + |
| 883 | + |
| 884 | + public static void UploadPlayerFile(byte[] fileBytes, string fileName, string filePurpose, Action<LootLockerPlayerFile> onComplete) |
| 885 | + { |
| 886 | + if (!CheckInitialized()) |
| 887 | + { |
| 888 | + onComplete?.Invoke(LootLockerResponseFactory.SDKNotInitializedError<LootLockerPlayerFile>()); |
| 889 | + return; |
| 890 | + } |
| 891 | + |
| 892 | + var body = new Dictionary<string, string>() |
| 893 | + { |
| 894 | + { "purpose", filePurpose } |
| 895 | + }; |
| 896 | + |
| 897 | + LootLockerServerRequest.UploadFile(LootLockerEndPoints.uploadPlayerFile, fileBytes, Path.GetFileName(fileName), "multipart/form-data", body, |
| 898 | + onComplete: (serverResponse) => |
| 899 | + { |
| 900 | + LootLockerResponse.Serialize(onComplete, serverResponse); |
| 901 | + }); |
| 902 | + } |
| 903 | + |
| 904 | + public static void DeletePlayerFile(int fileId, Action<LootLockerResponse> onComplete) |
| 905 | + { |
| 906 | + if (!CheckInitialized()) |
| 907 | + { |
| 908 | + onComplete?.Invoke(LootLockerResponseFactory.SDKNotInitializedError<LootLockerResponse>()); |
| 909 | + return; |
| 910 | + } |
| 911 | + |
| 912 | + var endpoint = LootLockerEndPoints.deletePlayerFile; |
| 913 | + |
| 914 | + endpoint.endPoint = string.Format(endpoint.endPoint, fileId); |
| 915 | + |
| 916 | + LootLockerServerRequest.CallAPI(endpoint, null, onComplete: (serverResponse) => { LootLockerResponse.Serialize(onComplete, serverResponse); }); |
| 917 | + } |
| 918 | + |
792 | 919 | #endregion
|
793 | 920 |
|
794 | 921 | #region Character
|
|
0 commit comments