Skip to content

Commit 48dd250

Browse files
authored
Merge pull request #846 from PlayEveryWare/fix/file-transfer-data
Better data handling in file transfers
2 parents 1187482 + a9e9ec1 commit 48dd250

File tree

3 files changed

+38
-30
lines changed

3 files changed

+38
-30
lines changed

Assets/Scripts/EOSPlayerDataStorageManager.cs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -188,16 +188,16 @@ public bool StartFileDataUpload(string fileName, Action fileCreatedCallback = nu
188188
CancelCurrentTransfer();
189189
CurrentTransferHandle = req;
190190

191-
EOSTransferInProgress newTransfer = new EOSTransferInProgress();
192-
newTransfer.Download = false;
193-
194-
newTransfer.TotalSize = (uint)fileData.Length;
195-
if (newTransfer.TotalSize > 0)
191+
EOSTransferInProgress newTransfer = new()
196192
{
197-
byte[] utf8ByteArray = System.Text.Encoding.UTF8.GetBytes(fileData);
193+
Download = false
194+
};
198195

199-
newTransfer.Data = utf8ByteArray;
196+
if (null != fileData)
197+
{
198+
newTransfer.Data = System.Text.Encoding.UTF8.GetBytes(fileData);
200199
}
200+
201201
newTransfer.CurrentIndex = 0;
202202

203203
TransfersInProgress[fileName] = newTransfer;
@@ -376,14 +376,9 @@ private ReadResult ReceiveData(string fileName, ArraySegment<byte> data, uint to
376376
}
377377

378378
// First update
379-
if (transfer.CurrentIndex == 0 && transfer.TotalSize == 0)
379+
if (transfer.CurrentIndex == 0)
380380
{
381-
transfer.TotalSize = totalSize;
382-
383-
if (transfer.TotalSize == 0)
384-
{
385-
return ReadResult.ContinueReading;
386-
}
381+
transfer.Data = new byte[totalSize];
387382
}
388383

389384
// If more data has been received than was anticipated, fail the request

Assets/Scripts/EOSTitleStorageManager.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -370,14 +370,9 @@ private ReadResult ReceiveData(string fileName, ArraySegment<byte> data, uint to
370370
}
371371

372372
// First update
373-
if (transfer.CurrentIndex == 0 && transfer.TotalSize == 0)
373+
if (transfer.CurrentIndex == 0)
374374
{
375-
transfer.TotalSize = totalSize;
376-
377-
if (transfer.TotalSize == 0)
378-
{
379-
return ReadResult.RrContinuereading;
380-
}
375+
transfer.Data = new byte[totalSize];
381376
}
382377

383378
// Make sure we have enough space

Assets/Scripts/EOSTransferInProgress.cs

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626

2727
namespace PlayEveryWare.EpicOnlineServices.Samples
2828
{
29+
using Editor.Utility;
30+
2931
/// <summary>
3032
/// Class <c>EOSTransferInProgress</c> is used in <c>EOSTitleStorageManager</c> and <c>EOSPlayerDataStorageManager</c> to keep track of downloaded cached file data.
3133
/// </summary>
@@ -37,24 +39,40 @@ public class EOSTransferInProgress
3739

3840
public bool Download = true;
3941
public uint CurrentIndex = 0;
40-
public byte[] Data;
41-
private uint transferSize = 0;
42+
private byte[] _data;
4243

43-
public uint TotalSize
44+
public byte[] Data
4445
{
4546
get
4647
{
47-
return transferSize;
48+
return _data;
4849
}
4950
set
5051
{
51-
transferSize = value;
52-
53-
if (transferSize > FileMaxSizeBytes)
52+
// If the file sizer is larger than the maximum allowable size,
53+
// then log an error, but do not throw an exception, since
54+
// throwing an exception from a property setter is a little
55+
// confusing, and there will be an opportunity to catch the
56+
// mistake when EOS returns an error code.
57+
if (null != value && value.Length > FileMaxSizeBytes)
5458
{
55-
Debug.LogError("[EOS SDK] Player data storage: data transfer size exceeds max file size.");
56-
transferSize = FileMaxSizeBytes;
59+
Debug.LogError($"Maximum file size is 200MB.");
5760
}
61+
62+
_data = value;
63+
}
64+
}
65+
66+
public uint TotalSize
67+
{
68+
get
69+
{
70+
if (null == _data)
71+
return 0;
72+
73+
_ = SafeTranslatorUtility.TryConvert(_data.Length, out uint totalSize);
74+
75+
return totalSize;
5876
}
5977
}
6078

0 commit comments

Comments
 (0)