修改细节

This commit is contained in:
Caiyanpeng committed 2021-07-28 14:59:21 +08:00
1 parent ca938ab6f5
commit 952e5038ed
19 files changed
+1542 -286

No files matched your search

@@ -1,4 +1,6 @@
using Assets.Scripts;
using Assets.Scripts.Apis.Models;
using Newtonsoft.Json.Linq;
using System;
using System.Collections;
using System.Collections.Generic;
@@ -15,6 +17,19 @@ public class DownloadWorkoutsController : PFUIPanel
ScrollRect scroll;
string path;
[SerializeField] Transform log;
AppDownloadInfo wpf;
public override void Show()
{
base.Show();
Btn = transform.Find("Panel/BtnConfirm");
BtnStart = transform.Find("Panel/BtnStart");
Loading = transform.Find("Panel/LoadingContainer");
scroll = transform.Find("Panel/Scroll View").GetComponent<ScrollRect>();
Exit = transform.Find("Panel/Exit");
BtnStart.GetComponent<Button>().enabled = true;
BtnStart.GetComponent<Button>().interactable = true;
SetType(1);
}
void Start()
{
Btn = transform.Find("Panel/BtnConfirm");
@@ -22,63 +37,102 @@ public class DownloadWorkoutsController : PFUIPanel
Loading = transform.Find("Panel/LoadingContainer");
scroll = transform.Find("Panel/Scroll View").GetComponent<ScrollRect>();
Exit = transform.Find("Panel/Exit");
SetType(1);
UIManager.AddEvent(Exit.gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, (b) =>
{
Utils.showToast(gameObject, "Please update to the latest version.");
//UIManager.CloseConfirm();
if (request != null)
{
request.Abort();
}
if (_fs != null)
{
_fs.Close();
}
if (_netStream != null)
{
_netStream.Close();
}
gameObject.SetActive(false);
});
SetType(1);
//Button.GetComponent<Button>().enabled = false;
//Button.GetComponent<Button>().interactable = false;
path = Application.persistentDataPath + "/PowerFun.exe";
path = Application.persistentDataPath + "/PowerFunWorkouts.exe";
UIManager.AddEvent(Btn.gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, (b) =>
{
Application.Quit();
//Application.Quit();
Utils.ExecFile(path);
});
UIManager.AddEvent(BtnStart.gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, (_base) =>
UIManager.AddEvent(BtnStart.gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick,async (_base) =>
{
if (App.UpdateObject != null)
var res = await ConfigHelper.userApi.GetAppVersion();
if (res.result)
{
BtnStart.GetComponent<Button>().enabled = false;
BtnStart.GetComponent<Button>().interactable = false;
StartCoroutine(DownLoadExe(App.UpdateObject.Url, path, (a, b, isComplete) =>
wpf = res.data.WPF;
if (wpf != null)
{
transform.Find("Panel/LoadingContainer/Text").GetComponent<Text>().text = $"Downloaded {a.ToString("#0")}M / {b.ToString("#0")}M";// string.Format(, a, b);
transform.Find("Panel/LoadingContainer/Loading").GetComponent<Image>().fillAmount = (float)(a / b);
if (isComplete)
BtnStart.GetComponent<Button>().enabled = false;
BtnStart.GetComponent<Button>().interactable = false;
Debug.Log(path);
StartCoroutine(DownLoadExe(wpf.Url, path, (a, b, isComplete) =>
{
SetType(3);
PlayerPrefs.SetString("exeVersion", App.UpdateObject.Code);
new FileInfo(path + ".pfdownload").MoveTo(path);
}
}));
Debug.Log($"{a} {b} {isComplete}");
transform.Find("Panel/LoadingContainer/Text").GetComponent<Text>().text = $"Downloaded {a.ToString("#0")}M / {b.ToString("#0")}M";// string.Format(, a, b);
transform.Find("Panel/LoadingContainer/Loading").GetComponent<Image>().fillAmount = (float)(a / b);
if (isComplete)
{
SetType(3);
PlayerPrefs.SetString("exeVersion_w", wpf.Version);
new FileInfo(path + ".pfdownload").MoveTo(path);
}
}));
}
}
//if (App.UpdateObject != null)
//{
// BtnStart.GetComponent<Button>().enabled = false;
// BtnStart.GetComponent<Button>().interactable = false;
// StartCoroutine(DownLoadExe(App.UpdateObject.Url, path, (a, b, isComplete) =>
// {
// transform.Find("Panel/LoadingContainer/Text").GetComponent<Text>().text = $"Downloaded {a.ToString("#0")}M / {b.ToString("#0")}M";// string.Format(, a, b);
// transform.Find("Panel/LoadingContainer/Loading").GetComponent<Image>().fillAmount = (float)(a / b);
// if (isComplete)
// {
// SetType(3);
// PlayerPrefs.SetString("exeVersion", App.UpdateObject.Code);
// new FileInfo(path + ".pfdownload").MoveTo(path);
// }
// }));
//}
});
//transform
if (App.UpdateObject != null)
{
for (var i = 0; i < App.UpdateObject.UpdateLog.Count; i++)
{
var newLog = Instantiate<Transform>(log);
newLog.GetComponent<DownloadLog>().Initial(App.UpdateObject.UpdateLog[i]);
if (i == App.UpdateObject.UpdateLog.Count - 1)
{
newLog.GetComponent<DownloadLog>().HideLine();
}
newLog.SetParent(scroll.content);
newLog.localScale = Vector3.one;
}
}
//if (App.UpdateObject != null)
//{
// for (var i = 0; i < App.UpdateObject.UpdateLog.Count; i++)
// {
// var newLog = Instantiate<Transform>(log);
// newLog.GetComponent<DownloadLog>().Initial(App.UpdateObject.UpdateLog[i]);
// if (i == App.UpdateObject.UpdateLog.Count - 1)
// {
// newLog.GetComponent<DownloadLog>().HideLine();
// }
// newLog.SetParent(scroll.content);
// newLog.localScale = Vector3.one;
// }
//}
}
bool stop = false;
HttpWebRequest request;
Stream _fs, _netStream;
/*下载文件*/
IEnumerator DownLoadExe(string url, string desFileName, Action<double, double, bool> OnDownloadProgressEvent)
{
string version = null;
if (App.UpdateObject != null)
if (wpf != null)
{
version = App.UpdateObject.Code;
version = wpf.Version;
}
if (File.Exists(desFileName))
{
@@ -89,9 +143,9 @@ public class DownloadWorkoutsController : PFUIPanel
}
else
{
if (version == PlayerPrefs.GetString("exeVersion"))
if (version == PlayerPrefs.GetString("exeVersion_w"))
{
Application.Quit();
//Application.Quit();
Utils.ExecFile(desFileName);
yield break;
}
@@ -108,8 +162,9 @@ public class DownloadWorkoutsController : PFUIPanel
File.Delete(desFileName + ".pfdownload");
}
SetType(2);
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
request = (HttpWebRequest)HttpWebRequest.Create(url);
request.Timeout = 5000;
WebResponse response = request.GetResponse();
//UnityWebRequest request = UnityWebRequest.Get(url);
//yield return request.SendWebRequest();
@@ -121,6 +176,8 @@ public class DownloadWorkoutsController : PFUIPanel
using (FileStream fs = new FileStream(desFileName + ".pfdownload", FileMode.Create))
using (Stream netStream = response.GetResponseStream())
{
_fs = fs;
_netStream = netStream;
nReadSize = netStream.Read(nbytes, 0, packLength);
while (nReadSize > 0)
{