更新页面,目前是强制更新

This commit is contained in:
Caiyanpeng committed 2021-05-11 10:47:04 +08:00
1 parent 6645310601
commit 2c5501a096
25 files changed
+1922 -71

No files matched your search

+22
View File
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Assets.Scripts.Apis.Models
{
public class UpdateModel
{
public bool HasUpdate { get; set; }
public string Url { get; set; }
public string Code { get; set; }
public List<VersionModel> UpdateLog { get; set; }
}
public class VersionModel
{
public string Version { get; set; }
public DateTime CreateTime { get; set; }
public string Desc { get; set; }
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 72e93f3cdcc50a64aa7dbda61c720707
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+6 -4
View File
@@ -8,9 +8,9 @@ using System.Net;
public static class App
{
public static string Host = "http://192.168.0.97:5082/";
public static string Host = "http://192.168.0.101:5082/";
public static string AppVersion = "1.0.0";
public static string AppVersion = Application.version;
public static int RouteIdParam = 0;
public static UserResultModel CurrentUser { get; set; }
@@ -44,7 +44,10 @@ public static class App
public static IPEndPoint UdpAddress { get; private set; } = new IPEndPoint(IPAddress.Parse("192.168.0.97"), 11000);
public static IPEndPoint TcpAddress { get; private set; } = new IPEndPoint(IPAddress.Parse("192.168.0.97"), 21001);
public static UpdateModel UpdateObject { get; set; }
//public static string AppDownloadUrl { get; internal set; }
//public static string AppVersionCode { get; internal set; }
static App()
{
#if !UNITY_EDITOR
@@ -52,6 +55,5 @@ public static class App
UdpAddress = new IPEndPoint(IPAddress.Parse("47.97.84.8"), 21000);
TcpAddress = new IPEndPoint(IPAddress.Parse("47.97.84.8"), 21001);
#endif
}
}
+14 -16
View File
@@ -217,7 +217,7 @@ public class LoginController : MonoBehaviour
{
var info = Instantiate(Resources.Load<GameObject>("UI/Prefab/Login/QuickUserInfo")).transform;
info.GetComponent<QuickLoginUser>().Initial(user, transform);
info.parent = content;
info.SetParent(content);
info.localScale = new Vector3(1, 1, 1);
}
content.Find("empty1").transform.SetSiblingIndex(0);
@@ -459,24 +459,33 @@ public class LoginController : MonoBehaviour
async void Init()
{
GetRotateImage();
UIManager.Instance.ModalsPanel = this.transform.Find("ModalPanel").GetComponent<PFUIPanel>();
userInfos = UIManager.Instance.userInfos;
App.DefaultRotateTexture = Utils.ReadTextureFromPlayerPrefs("rotateImage");
var notifyId = PlayerPrefs.GetInt("notifyId");
App.firstEnter = PlayerPrefs.GetInt("firstEnter");
PlayerPrefs.SetInt("firstEnter", 1);
var notifyId = PlayerPrefs.GetInt("notifyId");
var r = await ConfigHelper.userApi.GetNotify();
if (r.result)
{
//#if !UNITY_EDITOR
var ver = r.data.Value<JObject>("Version").ToObject<UpdateModel>();
if (ver!=null && ver.HasUpdate)
{
App.UpdateObject = ver;
Debug.Log(Application.persistentDataPath + "/PowerFun.exe");
UIManager.ShowDownloadModal();
}
//#endif
App.notifyContent = r.data.Value<string>("Content");
if (r.data.Value<int>("Id") != notifyId)
{
UIManager.ShowNewsModal();
PlayerPrefs.SetInt("notifyId", r.data.Value<int>("Id"));
}
//content.GetComponent<Text>().text
}
GetRotateImage();
}
async void GetRotateImage()
@@ -518,14 +527,6 @@ public class LoginController : MonoBehaviour
private void AdjustWxQrCode()
{
wxBrowser.EvalJSCSP(@"
const f = ()=>{
//if(document.body.style.padding === '0px')
//{
// console.log('停止');
// isFinish();
// return;
//}
console.log('js调整');
document.getElementsByClassName('qrcode')[0].style.marginTop = 0;
document.getElementsByClassName('title')[0].style.display = 'none';
document.getElementById('wx_default_tip').childNodes[3].innerHTML = `""PowerFun""`;
@@ -533,10 +534,7 @@ public class LoginController : MonoBehaviour
document.body.style.overflow = 'hidden';
document.body.style.transformOrigin = 'top left';
document.body.style.transform = 'scale(0.85106382978)';
document.body.style.padding = '0';
}
f();").Done();
document.body.style.padding = '0';").Done();
}
//浏览器加载回调
private async void OnUserScan()
+2 -1
View File
@@ -47,7 +47,7 @@ public class MainController : MonoBehaviour
//{
// UIManager.ShowHomePanel();
//});
if (App.MainSceneParam.ContainsKey("Name") && !string.IsNullOrEmpty(App.MainSceneParam["Name"]) )
if (App.MainSceneParam.ContainsKey("Name") && !string.IsNullOrEmpty(App.MainSceneParam["Name"]))
{
UIManager.PushHome();
if (App.MainSceneParam["Name"] == "MapListPanel")
@@ -59,6 +59,7 @@ public class MainController : MonoBehaviour
{
UIManager.ShowUserInfoPanel();
}
App.MainSceneParam["Name"] = string.Empty;
}
else
{
@@ -127,6 +127,7 @@ public class ConnectDeviceModal : PFUIPanel
//Debug.Log(AntConnector.Instance().discoveredDevices.Count(d => d.Sensor == SensorType));
var devices = new List<AbstractAntDevice>();
var a = AntConnector.Instance().discoveredDevices;
switch (SensorType)
{
case SensorType.Cadence:
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 25494196c8da0294aa28730d63bf7498
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,138 @@
using Assets.Scripts;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Net;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.UI;
public class DownloadController : PFUIPanel
{
// Start is called before the first frame update
Transform Button,Loading,Exit;
ScrollRect scroll;
string path;
[SerializeField] Transform log;
void Start()
{
Button = transform.Find("Panel/BtnConfirm");
Loading = transform.Find("Panel/LoadingContainer");
scroll = transform.Find("Panel/Scroll View").GetComponent<ScrollRect>();
Exit = transform.Find("Panel/Exit");
UIManager.AddEvent(Exit.gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, (b) =>
{
Utils.showToast(gameObject, "Please update to the latest version.");
});
SetType(false);
//Button.GetComponent<Button>().enabled = false;
//Button.GetComponent<Button>().interactable = false;
path = Application.persistentDataPath + "/PowerFun.exe";
UIManager.AddEvent(Button.gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, (b) =>
{
Application.Quit();
Utils.ExecFile(path);
});
//transform
if (App.UpdateObject != null)
{
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(true);
PlayerPrefs.SetString("exeVersion", App.UpdateObject.Code);
new FileInfo(path + ".pfdownload").MoveTo(path);
}
}));
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;
}
}
}
/*下载文件*/
IEnumerator DownLoadExe(string url, string desFileName, Action<double, double, bool> OnDownloadProgressEvent)
{
string version = null;
if (App.UpdateObject != null)
{
version = App.UpdateObject.Code;
}
if (File.Exists(desFileName))
{
//if(PlayerPrefs.GetString("exeVersion")==)
if (version == null)
{
yield break;
}
else
{
if (version == PlayerPrefs.GetString("exeVersion"))
{
Application.Quit();
Utils.ExecFile(desFileName);
yield break;
}
else
{
File.Delete(desFileName);
}
}
//File.Delete(desFileName);
}
if (File.Exists(desFileName + ".pfdownload"))
{
File.Delete(desFileName + ".pfdownload");
}
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
request.Timeout = 5000;
WebResponse response = request.GetResponse();
//UnityWebRequest request = UnityWebRequest.Get(url);
//yield return request.SendWebRequest();
int packLength = 1024 * 20;
int nReadSize = 0;
byte[] nbytes = new byte[packLength];
double dDownloadedLength = 0, dTotalLength = 0;
long countLength = response.ContentLength;
using (FileStream fs = new FileStream(desFileName + ".pfdownload", FileMode.Create))
using (Stream netStream = response.GetResponseStream())
{
nReadSize = netStream.Read(nbytes, 0, packLength);
while (nReadSize > 0)
{
fs.Write(nbytes, 0, nReadSize);
nReadSize = netStream.Read(nbytes, 0, packLength);
dDownloadedLength = fs.Length * 1.0 / (1024 * 1024);
dTotalLength = countLength * 1.0 / (1024 * 1024);
OnDownloadProgressEvent.Invoke(dDownloadedLength, dTotalLength, false);
//string ss = string.Format("已下载 {0:F}M / {1:F}M", dDownloadedLength, dTotalLength);
//Debug.Log(ss);
yield return null;
}
}
OnDownloadProgressEvent.Invoke(dDownloadedLength, dTotalLength, true);
}
void SetType(bool f)
{
// true 显示 button false 显示loading
Button.gameObject.SetActive(f);
Loading.gameObject.SetActive(!f);
}
// Update is called once per frame
void Update()
{
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3722db1a87877f9458f6932efd042b51
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,32 @@
using Assets.Scripts.Apis.Models;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using UnityEngine;
using UnityEngine.UI;
public class DownloadLog : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
public void Initial(VersionModel version)
{
transform.Find("Version").GetComponent<Text>().text = version.Version;
transform.Find("Content").GetComponent<Text>().text = version.Desc;
}
public void HideLine()
{
transform.Find("Image").gameObject.SetActive(false);
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8e370f7cb0f6c044f90aed68484553f1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+13
View File
@@ -83,6 +83,15 @@ public class UIManager : MonoBehaviour
return this.GetPanelInstance("NewsModal", ref this.mNewsContoller);
}
}
private DownloadController mDownloadModal;
public DownloadController DownloadModal
{
get
{
return this.GetPanelInstance("DownloadModal", ref this.mDownloadModal);
}
}
private MapListController mMapListController;
public MapListController MapListPanel
{
@@ -355,6 +364,10 @@ public class UIManager : MonoBehaviour
{
UIManager.Show(UIManager.Instance.NewsModal, null, true);
}
public static void ShowDownloadModal()
{
UIManager.Show(UIManager.Instance.DownloadModal, null, true);
}
public static void ShowFeedBackModal()
{
UIManager.Show(UIManager.Instance.FeedbackModal, null, true);
+20 -1
View File
@@ -228,7 +228,7 @@ namespace Assets.Scripts
}
}
UIManager.Instance.StartCoroutine(DownloadImage(img, url,(texture)=> {
if (cache)
if (cache && !propTextureCache.ContainsKey(url))
{
propTextureCache.Add(url, texture);
}
@@ -419,5 +419,24 @@ namespace Assets.Scripts
}
}
/*文本框/下拉框错误*/
public static void ExecFile(string path)
{
System.Diagnostics.Process proc = null;
try
{
proc = new System.Diagnostics.Process();
proc.StartInfo.FileName = path;
proc.StartInfo.CreateNoWindow = false;
proc.StartInfo.Verb = "runas";
proc.Start();
}
catch (Exception ex)
{
Console.WriteLine("执行批处理的时候出现了异常!");
}
}
/*下载文件*/
}
}