2021-04-08 20:09:59 +08:00
|
|
|
|
//
|
|
|
|
|
// UpdateScreen.cs
|
|
|
|
|
//
|
|
|
|
|
// Author:
|
|
|
|
|
// fjy <jiyuan.feng@live.com>
|
|
|
|
|
//
|
|
|
|
|
// Copyright (c) 2020 fjy
|
|
|
|
|
//
|
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
|
// of this software and associated documentation files (the "Software"), to deal
|
|
|
|
|
// in the Software without restriction, including without limitation the rights
|
|
|
|
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
|
// copies of the Software, and to permit persons to whom the Software is
|
|
|
|
|
// furnished to do so, subject to the following conditions:
|
|
|
|
|
//
|
|
|
|
|
// The above copyright notice and this permission notice shall be included in
|
|
|
|
|
// all copies or substantial portions of the Software.
|
|
|
|
|
//
|
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
|
// THE SOFTWARE.
|
|
|
|
|
|
|
|
|
|
using ET;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
|
|
|
|
namespace libx
|
|
|
|
|
{
|
2021-06-07 13:58:51 +08:00
|
|
|
|
public class UpdateScreen: MonoBehaviour, IUpdater
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
|
|
|
|
public Text version;
|
|
|
|
|
public Slider progressBar;
|
|
|
|
|
public Text progressText;
|
|
|
|
|
public Button btnStart;
|
|
|
|
|
public Button btnClear;
|
|
|
|
|
|
|
|
|
|
private void Start()
|
|
|
|
|
{
|
|
|
|
|
version.text = "APP: 4.0\nRES:1";
|
2021-04-11 19:50:39 +08:00
|
|
|
|
Updater updater = Game.Scene.GetComponent<Updater>();
|
2021-04-08 20:09:59 +08:00
|
|
|
|
updater.listener = this;
|
|
|
|
|
|
2021-06-07 13:58:51 +08:00
|
|
|
|
btnStart.onClick.AddListener(() => { updater.StartUpdate(); });
|
2021-04-08 20:09:59 +08:00
|
|
|
|
|
2021-06-07 13:58:51 +08:00
|
|
|
|
btnClear.onClick.AddListener(() => { updater.OnClear(); });
|
2021-04-08 20:09:59 +08:00
|
|
|
|
}
|
2021-06-07 13:58:51 +08:00
|
|
|
|
|
2021-04-08 20:09:59 +08:00
|
|
|
|
private void DelRes(string dir)
|
|
|
|
|
{
|
2021-06-07 13:58:51 +08:00
|
|
|
|
foreach (string d in Directory.GetFileSystemEntries(dir))
|
|
|
|
|
{
|
|
|
|
|
if (File.Exists(d))
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
2021-06-07 13:58:51 +08:00
|
|
|
|
FileInfo fi = new FileInfo(d);
|
|
|
|
|
if (fi.Attributes.ToString().IndexOf("ReadOnly") != -1)
|
|
|
|
|
fi.Attributes = FileAttributes.Normal;
|
|
|
|
|
File.Delete(d); //直接删除其中的文件
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
DirectoryInfo d1 = new DirectoryInfo(d);
|
|
|
|
|
if (d1.GetFiles().Length != 0)
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
2021-06-07 13:58:51 +08:00
|
|
|
|
DelRes(d1.FullName); ////递归删除子文件夹
|
2021-04-08 20:09:59 +08:00
|
|
|
|
}
|
2021-06-07 13:58:51 +08:00
|
|
|
|
|
|
|
|
|
Directory.Delete(d, true);
|
2021-04-08 20:09:59 +08:00
|
|
|
|
}
|
2021-06-07 13:58:51 +08:00
|
|
|
|
}
|
2021-04-08 20:09:59 +08:00
|
|
|
|
}
|
2021-06-07 13:58:51 +08:00
|
|
|
|
|
2021-04-08 20:09:59 +08:00
|
|
|
|
private void DelSomeRes(string path, int count)
|
|
|
|
|
{
|
|
|
|
|
#if UNITY_STANDALONE
|
2021-06-07 13:58:51 +08:00
|
|
|
|
path += "/TTL";
|
2021-04-08 20:09:59 +08:00
|
|
|
|
FileInfo[] files = new DirectoryInfo(path).GetFiles();
|
|
|
|
|
List<FileInfo> list = new List<FileInfo>(files);
|
2021-06-07 13:58:51 +08:00
|
|
|
|
list.Sort(new Comparison<FileInfo>(delegate(FileInfo a, FileInfo b) { return -a.LastWriteTime.CompareTo(b.LastWriteTime); }));
|
2021-04-08 20:09:59 +08:00
|
|
|
|
foreach (FileInfo f in list)
|
|
|
|
|
{
|
|
|
|
|
if (count <= 0) return;
|
|
|
|
|
count--;
|
|
|
|
|
File.Delete(f.FullName);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
}
|
2021-06-07 13:58:51 +08:00
|
|
|
|
|
|
|
|
|
#region IUpdateManager implementation
|
2021-04-08 20:09:59 +08:00
|
|
|
|
|
|
|
|
|
public void OnStart()
|
|
|
|
|
{
|
|
|
|
|
btnStart.gameObject.SetActive(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnMessage(string msg)
|
|
|
|
|
{
|
|
|
|
|
progressText.text = msg;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnProgress(float progress)
|
|
|
|
|
{
|
|
|
|
|
progressBar.value = progress;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnVersion(string ver)
|
|
|
|
|
{
|
|
|
|
|
version.text = $"客户端版本号:{GlobalConfigComponent.Instance.GlobalProto.ClientVersion}\nres:{ver}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnClear()
|
|
|
|
|
{
|
|
|
|
|
btnStart.gameObject.SetActive(true);
|
|
|
|
|
}
|
2021-06-07 13:58:51 +08:00
|
|
|
|
|
|
|
|
|
#endregion
|
2021-04-08 20:09:59 +08:00
|
|
|
|
}
|
|
|
|
|
}
|