263 lines
8.9 KiB
C#
263 lines
8.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Runtime.InteropServices;
|
|
using Cpp2IlInjected;
|
|
using UnityEngine;
|
|
|
|
namespace BestHTTP.Examples
|
|
{
|
|
// Token: 0x020012BF RID: 4799
|
|
[Token(Token = "0x20012BF")]
|
|
[StructLayout(3)]
|
|
public sealed class LargeFileDownloadSample : MonoBehaviour
|
|
{
|
|
// Token: 0x06007830 RID: 30768 RVA: 0x0018ED74 File Offset: 0x0018CF74
|
|
[Token(Token = "0x6007830")]
|
|
[Address(RVA = "0x1E666B0", Offset = "0x1E650B0", VA = "0x181E666B0")]
|
|
private void Awake()
|
|
{
|
|
if (PlayerPrefs.HasKey("DownloadLength"))
|
|
{
|
|
int @int = PlayerPrefs.GetInt("DownloadProgress");
|
|
int int2 = PlayerPrefs.GetInt("DownloadLength");
|
|
}
|
|
}
|
|
|
|
// Token: 0x06007831 RID: 30769 RVA: 0x0018EDA4 File Offset: 0x0018CFA4
|
|
[Token(Token = "0x6007831")]
|
|
[Address(RVA = "0x1E66730", Offset = "0x1E65130", VA = "0x181E66730")]
|
|
private void OnDestroy()
|
|
{
|
|
HTTPRequest httprequest = this.request;
|
|
if (httprequest != 0 && httprequest.<State>k__BackingField < HTTPRequestStates.Finished)
|
|
{
|
|
int num = 0;
|
|
httprequest.OnProgress = num;
|
|
this.request.<Callback>k__BackingField = num;
|
|
this.request.Abort();
|
|
return;
|
|
}
|
|
}
|
|
|
|
// Token: 0x06007832 RID: 30770 RVA: 0x0018EDEC File Offset: 0x0018CFEC
|
|
[Token(Token = "0x6007832")]
|
|
[Address(RVA = "0x1E66780", Offset = "0x1E65180", VA = "0x181E66780")]
|
|
private void OnGUI()
|
|
{
|
|
Rect clientArea = GUIHelper.ClientArea;
|
|
Action action = delegate
|
|
{
|
|
HTTPRequest httprequest;
|
|
for (;;)
|
|
{
|
|
string text = this.status;
|
|
string text2 = "Request status: " + text;
|
|
GUILayoutOption[] array = Array.Empty<GUILayoutOption>();
|
|
GUILayout.Label(text2, array);
|
|
GUILayout.Space(5f);
|
|
float num = this.progress;
|
|
int num2 = 0;
|
|
int num3 = PlayerPrefs.GetInt("DownloadLength");
|
|
num3 += num2;
|
|
string text3 = string.Format("Progress: {0:P2} of {1:N0}Mb", array, num3);
|
|
GUILayoutOption[] array2 = Array.Empty<GUILayoutOption>();
|
|
GUILayout.Label(text3, array2);
|
|
GUILayoutOption[] array3 = Array.Empty<GUILayoutOption>();
|
|
int num4 = 0;
|
|
float num5 = GUILayout.HorizontalSlider(num, (float)num4, 1f, array3);
|
|
GUILayout.Space(50f);
|
|
httprequest = this.request;
|
|
if (httprequest != 0)
|
|
{
|
|
break;
|
|
}
|
|
string text4 = string.Format("Desired Fragment Size: {0:N} KBytes", httprequest);
|
|
GUILayoutOption[] array4 = Array.Empty<GUILayoutOption>();
|
|
GUILayout.Label(text4, array4);
|
|
GUILayoutOption[] array5 = Array.Empty<GUILayoutOption>();
|
|
float num7;
|
|
float num6 = GUILayout.HorizontalSlider(num7, 4096f, 10485760f, array5);
|
|
this.fragmentSize = array5;
|
|
GUILayout.Space(5f);
|
|
bool flag = PlayerPrefs.HasKey("DownloadProgress");
|
|
string text5 = "Start Download";
|
|
if (flag)
|
|
{
|
|
text5 = "Continue Download";
|
|
}
|
|
GUILayoutOption[] array6 = Array.Empty<GUILayoutOption>();
|
|
if (GUILayout.Button(text5, array6))
|
|
{
|
|
goto Block_4;
|
|
}
|
|
}
|
|
if (httprequest.<State>k__BackingField == HTTPRequestStates.Processing)
|
|
{
|
|
GUILayoutOption[] array7 = Array.Empty<GUILayoutOption>();
|
|
if (GUILayout.Button("Abort Download", array7))
|
|
{
|
|
this.request.Abort();
|
|
}
|
|
}
|
|
return;
|
|
Block_4:
|
|
Uri uri = new Uri("https://uk3.testmy.net/dl-102400");
|
|
OnRequestFinishedDelegate onRequestFinishedDelegate = delegate(HTTPRequest req, HTTPResponse resp)
|
|
{
|
|
if (req.<State>k__BackingField <= HTTPRequestStates.Aborted)
|
|
{
|
|
if (!PlayerPrefs.HasKey("DownloadLength"))
|
|
{
|
|
string firstHeaderValue = resp.GetFirstHeaderValue("content-length");
|
|
if (firstHeaderValue == 0)
|
|
{
|
|
int num12 = int.Parse(firstHeaderValue);
|
|
PlayerPrefs.SetInt("DownloadLength", num12);
|
|
}
|
|
}
|
|
List<byte[]> streamedFragments = resp.GetStreamedFragments();
|
|
this.ProcessFragments(streamedFragments);
|
|
this.status = "Processing";
|
|
if (!resp.IsSuccess)
|
|
{
|
|
int <StatusCode>k__BackingField = resp.<StatusCode>k__BackingField;
|
|
string <Message>k__BackingField = resp.<Message>k__BackingField;
|
|
string dataAsText = resp.DataAsText;
|
|
string text6 = string.Format("Request finished Successfully, but the server sent an error. Status Code: {0}-{1} Message: {2}", <StatusCode>k__BackingField, <Message>k__BackingField, dataAsText);
|
|
this.status = text6;
|
|
Debug.LogWarning(text6);
|
|
}
|
|
List<byte[]> list;
|
|
this.ProcessFragments(list);
|
|
this.status = "Streaming finished!";
|
|
PlayerPrefs.DeleteKey("DownloadProgress");
|
|
PlayerPrefs.Save();
|
|
int num13 = 0;
|
|
this.request = num13;
|
|
}
|
|
};
|
|
HTTPRequest httprequest2 = new HTTPRequest(uri, onRequestFinishedDelegate);
|
|
this.request = httprequest2;
|
|
if (!PlayerPrefs.HasKey("DownloadProgress"))
|
|
{
|
|
int num8 = 0;
|
|
PlayerPrefs.SetInt("DownloadProgress", num8);
|
|
}
|
|
HTTPRequest httprequest3 = this.request;
|
|
int @int = PlayerPrefs.GetInt("DownloadProgress");
|
|
httprequest3.SetRangeHeader(@int);
|
|
ulong num9;
|
|
this.request.DisableCache = num9 != 0UL;
|
|
ulong num10;
|
|
this.request.UseStreaming = num10 != 0UL;
|
|
HTTPRequest httprequest4 = this.request;
|
|
int num11 = this.fragmentSize;
|
|
httprequest4.StreamFragmentSize = num11;
|
|
HTTPRequest httprequest5 = this.request.Send();
|
|
};
|
|
GUIHelper.DrawArea(clientArea, true, action);
|
|
}
|
|
|
|
// Token: 0x06007833 RID: 30771 RVA: 0x0018EE14 File Offset: 0x0018D014
|
|
[Token(Token = "0x6007833")]
|
|
[Address(RVA = "0x1E66940", Offset = "0x1E65340", VA = "0x181E66940")]
|
|
private void StreamLargeFileTest()
|
|
{
|
|
Uri uri = new Uri("https://uk3.testmy.net/dl-102400");
|
|
OnRequestFinishedDelegate onRequestFinishedDelegate = delegate(HTTPRequest req, HTTPResponse resp)
|
|
{
|
|
if (req.<State>k__BackingField <= HTTPRequestStates.Aborted)
|
|
{
|
|
if (!PlayerPrefs.HasKey("DownloadLength"))
|
|
{
|
|
string firstHeaderValue = resp.GetFirstHeaderValue("content-length");
|
|
if (firstHeaderValue == 0)
|
|
{
|
|
int num3 = int.Parse(firstHeaderValue);
|
|
PlayerPrefs.SetInt("DownloadLength", num3);
|
|
}
|
|
}
|
|
List<byte[]> streamedFragments = resp.GetStreamedFragments();
|
|
this.ProcessFragments(streamedFragments);
|
|
this.status = "Processing";
|
|
if (!resp.IsSuccess)
|
|
{
|
|
int <StatusCode>k__BackingField = resp.<StatusCode>k__BackingField;
|
|
string <Message>k__BackingField = resp.<Message>k__BackingField;
|
|
string dataAsText = resp.DataAsText;
|
|
string text = string.Format("Request finished Successfully, but the server sent an error. Status Code: {0}-{1} Message: {2}", <StatusCode>k__BackingField, <Message>k__BackingField, dataAsText);
|
|
this.status = text;
|
|
Debug.LogWarning(text);
|
|
}
|
|
List<byte[]> list;
|
|
this.ProcessFragments(list);
|
|
this.status = "Streaming finished!";
|
|
PlayerPrefs.DeleteKey("DownloadProgress");
|
|
PlayerPrefs.Save();
|
|
int num4 = 0;
|
|
this.request = num4;
|
|
}
|
|
};
|
|
HTTPRequest httprequest = new HTTPRequest(uri, onRequestFinishedDelegate);
|
|
this.request = httprequest;
|
|
if (!PlayerPrefs.HasKey("DownloadProgress"))
|
|
{
|
|
int num = 0;
|
|
PlayerPrefs.SetInt("DownloadProgress", num);
|
|
}
|
|
HTTPRequest httprequest2 = this.request;
|
|
int @int = PlayerPrefs.GetInt("DownloadProgress");
|
|
httprequest2.SetRangeHeader(@int);
|
|
this.request.DisableCache = true;
|
|
this.request.UseStreaming = true;
|
|
HTTPRequest httprequest3 = this.request;
|
|
int num2 = this.fragmentSize;
|
|
httprequest3.StreamFragmentSize = num2;
|
|
HTTPRequest httprequest4 = this.request.Send();
|
|
}
|
|
|
|
// Token: 0x06007834 RID: 30772 RVA: 0x0000220F File Offset: 0x0000040F
|
|
[Token(Token = "0x6007834")]
|
|
[Address(RVA = "0x1E66830", Offset = "0x1E65230", VA = "0x181E66830")]
|
|
private void ProcessFragments(List<byte[]> fragments)
|
|
{
|
|
throw new AnalysisFailedException("CPP2IL failed to recover any usable IL for this method.");
|
|
}
|
|
|
|
// Token: 0x06007835 RID: 30773 RVA: 0x0018EEC4 File Offset: 0x0018D0C4
|
|
[Token(Token = "0x6007835")]
|
|
[Address(RVA = "0x1E67140", Offset = "0x1E65B40", VA = "0x181E67140")]
|
|
public LargeFileDownloadSample()
|
|
{
|
|
string empty = string.Empty;
|
|
this.status = empty;
|
|
this.fragmentSize = (int)((ulong)4096L);
|
|
base..ctor();
|
|
}
|
|
|
|
// Token: 0x040056C1 RID: 22209
|
|
[Token(Token = "0x40056C1")]
|
|
private const string URL = "https://uk3.testmy.net/dl-102400";
|
|
|
|
// Token: 0x040056C2 RID: 22210
|
|
[global::Cpp2IlInjected.FieldOffset(Offset = "0x18")]
|
|
[Token(Token = "0x40056C2")]
|
|
private HTTPRequest request;
|
|
|
|
// Token: 0x040056C3 RID: 22211
|
|
[global::Cpp2IlInjected.FieldOffset(Offset = "0x20")]
|
|
[Token(Token = "0x40056C3")]
|
|
private string status;
|
|
|
|
// Token: 0x040056C4 RID: 22212
|
|
[global::Cpp2IlInjected.FieldOffset(Offset = "0x28")]
|
|
[Token(Token = "0x40056C4")]
|
|
private float progress;
|
|
|
|
// Token: 0x040056C5 RID: 22213
|
|
[global::Cpp2IlInjected.FieldOffset(Offset = "0x2C")]
|
|
[Token(Token = "0x40056C5")]
|
|
private int fragmentSize;
|
|
}
|
|
}
|