Files
tianrunCRM/Assets/CoolapeFrame/Editor/Tools/ECLUpgradeBindingServer.cs

509 lines
16 KiB
C#
Raw Normal View History

2020-07-04 14:41:25 +08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using Coolape;
using System.IO;
using System.Net;
2020-10-19 23:34:29 +08:00
using System.Text;
2020-07-04 14:41:25 +08:00
public class ECLUpgradeBindingServer : EditorWindow
{
2020-08-03 23:05:29 +08:00
string contentStr;
2020-08-02 08:47:44 +08:00
Hashtable content;
2020-07-04 14:41:25 +08:00
Hashtable servers;
Hashtable server;
Vector2 scrollPos = Vector2.zero;
ArrayList upgradePkgList;
bool isSelectAll = false;
static int selectedServerIndex = 0;
HotUpgradeServerInfor selectedServer = null;
2020-08-02 08:47:44 +08:00
static bool uploadResult = false;
static bool isFinishUpload = false;
void OnUpdate()
{
if (isFinishUpload)
{
isFinishUpload = false;
//TODO:
Debug.Log("finished");
if (uploadResult)
{
// success
EditorUtility.DisplayDialog("Success", "Success !", "Okey");
}
else
{
EditorUtility.DisplayDialog("Fail", "Failed !", "Okey");
}
}
}
2020-07-04 14:41:25 +08:00
void OnGUI ()
{
if (!ECLProjectSetting.isProjectExit (ECLProjectManager.self)) {
GUIStyle style = new GUIStyle ();
style.fontSize = 20;
style.normal.textColor = Color.yellow;
GUILayout.Label ("The scene is not ready, create it now?", style);
if (GUILayout.Button ("Show Project Manager")) {
EditorWindow.GetWindow<ECLProjectManager> (false, "CoolapeProject", true);
}
Close ();
return;
}
if (ECLProjectManager.data.hotUpgradeServers.Count <= 0) {
GUI.color = Color.red;
GUILayout.Label ("There is no server");
GUI.color = Color.white;
return;
}
if (ECLProjectManager.data.hotUpgradeServers.Count > 0) {
ECLEditorUtl.BeginContents ();
{
List<string> toolbarNames = new List<string> ();
for (int i = 0; i < ECLProjectManager.data.hotUpgradeServers.Count; i++) {
HotUpgradeServerInfor dd = ECLProjectManager.data.hotUpgradeServers [i] as HotUpgradeServerInfor;
toolbarNames.Add (dd.name);
}
int index = GUILayout.Toolbar (selectedServerIndex, toolbarNames.ToArray ());
HotUpgradeServerInfor hsi = ECLProjectManager.data.hotUpgradeServers [index] as HotUpgradeServerInfor;
selectedServer = hsi;
if (selectedServerIndex != index) {
selectedServerIndex = index;
refreshData ();
}
//===================================================
GUILayout.BeginHorizontal ();
{
GUILayout.Label ("Key:", ECLEditorUtl.width200);
GUILayout.TextField (selectedServer.key);
}
GUILayout.EndHorizontal ();
//===================================================
GUILayout.BeginHorizontal ();
{
GUILayout.Label ("URL of get server list:", ECLEditorUtl.width200);
GUILayout.TextField (selectedServer.getServerListUrl);
}
GUILayout.EndHorizontal ();
//===================================================
GUILayout.BeginHorizontal ();
{
GUILayout.Label ("URL of set upgrade pkg md5:", ECLEditorUtl.width200);
GUILayout.TextField (selectedServer.setServerPkgMd5Url);
}
GUILayout.EndHorizontal ();
}
ECLEditorUtl.EndContents ();
}
GUI.color = Color.green;
if (GUILayout.Button ("Refresh")) {
refreshData ();
}
GUI.color = Color.white;
if (servers == null || servers.Count == 0)
return;
GUILayout.Space (5);
EditorGUILayout.BeginHorizontal ();
{
if (GUILayout.Button ("All", GUILayout.Width (30))) {
isSelectAll = !isSelectAll;
foreach (DictionaryEntry cell in servers) {
server = (Hashtable)(cell.Value);
server ["selected"] = isSelectAll;
}
}
EditorGUILayout.LabelField ("SID", GUILayout.Width (80));
EditorGUILayout.LabelField ("SName", GUILayout.Width (100));
GUI.color = Color.yellow;
#if UNITY_ANDROID
EditorGUILayout.LabelField ("UpgradeMd5Ver(Android)", GUILayout.Width (250));
#elif UNITY_IPHONE || UNITY_IOS
EditorGUILayout.LabelField ("UpgradeMd5Ver(ios)", GUILayout.Width (250));
#elif UNITY_STANDALONE_WIN
EditorGUILayout.LabelField ("UpgradeMd5Ver(win)", GUILayout.Width (250));
#elif UNITY_STANDALONE_OSX
EditorGUILayout.LabelField ("UpgradeMd5Ver(osx)", GUILayout.Width (250));
#elif UNITY_WEBGL
EditorGUILayout.LabelField ("UpgradeMd5Ver(webgl)", GUILayout.Width (250));
#endif
EditorGUILayout.LabelField ("UpgradePkg Name", GUILayout.Width (160));
EditorGUILayout.LabelField ("UpgradePkg Mark", GUILayout.Width (250));
GUI.color = Color.white;
#if UNITY_ANDROID
if (GUILayout.Button ("Select Md5(Android)")) {
setUpgradePkgMutlMode ("Android");
}
#elif UNITY_IPHONE || UNITY_IOS
if (GUILayout.Button ("Select Md5(ios)")) {
setUpgradePkgMutlMode ("ios");
}
#elif UNITY_STANDALONE_WIN
if (GUILayout.Button ("Select Md5(win)")) {
setUpgradePkgMutlMode ("win");
}
#elif UNITY_STANDALONE_OSX
if (GUILayout.Button ("Select Md5(osx)")) {
setUpgradePkgMutlMode ("osx");
}
#elif UNITY_WEBGL
if (GUILayout.Button ("Select Md5(webgl)")) {
setUpgradePkgMutlMode ("webgl");
}
#endif
}
EditorGUILayout.EndHorizontal ();
GUILayout.Space (5);
ECLEditorUtl.BeginContents ();
{
scrollPos = EditorGUILayout.BeginScrollView (scrollPos, GUILayout.Width (position.width), GUILayout.Height (position.height - 50));
{
foreach (DictionaryEntry cell in servers) {
server = (Hashtable)(cell.Value);
EditorGUILayout.BeginHorizontal ();
{
server ["selected"] = EditorGUILayout.Toggle (MapEx.getBool (server, "selected"), GUILayout.Width (30));
if (MapEx.getBool (server, "selected")) {
GUI.color = Color.cyan;
} else {
GUI.color = Color.white;
}
2020-08-03 23:05:29 +08:00
EditorGUILayout.TextField (MapEx.getString (server, "id"), GUILayout.Width (80));
2020-08-02 08:47:44 +08:00
EditorGUILayout.TextField (MapEx.getString (server, "name"), GUILayout.Width (100));
2020-07-04 14:41:25 +08:00
GUI.color = Color.yellow;
#if UNITY_ANDROID
2020-08-02 08:47:44 +08:00
EditorGUILayout.TextField (MapEx.getString (server, "androidVer"), GUILayout.Width (250));
2020-07-04 14:41:25 +08:00
#elif UNITY_IPHONE || UNITY_IOS
2020-08-02 08:47:44 +08:00
EditorGUILayout.TextField (MapEx.getString (server, "iosVer"), GUILayout.Width (250));
2020-07-04 14:41:25 +08:00
#elif UNITY_STANDALONE_WIN
EditorGUILayout.TextField (MapEx.getString (server, "winversion"), GUILayout.Width (250));
#elif UNITY_STANDALONE_OSX
EditorGUILayout.TextField (MapEx.getString (server, "osxversion"), GUILayout.Width (250));
#elif UNITY_WEBGL
EditorGUILayout.TextField (MapEx.getString (server, "webglversion"), GUILayout.Width (250));
#endif
2020-08-02 08:47:44 +08:00
EditorGUILayout.TextField (MapEx.getString (server, "pkgName"), GUILayout.Width (160));
2020-07-04 14:41:25 +08:00
EditorGUILayout.TextArea (MapEx.getString (server, "pkgRemark"), GUILayout.Width (250));
GUI.color = Color.white;
#if UNITY_ANDROID
if (GUILayout.Button ("Select Md5(Android)")) {
ECLUpgradeListProc.popup4Select ((Callback)onGetUpgradePkg, ListEx.builder ().Add (cell.Key).Add ("Android").ToList ());
}
#elif UNITY_IPHONE || UNITY_IOS
if (GUILayout.Button ("Select Md5(ios)")) {
ECLUpgradeListProc.popup4Select ((Callback)onGetUpgradePkg, ListEx.builder().Add(cell.Key).Add("ios").ToList());
}
#elif UNITY_STANDALONE_WIN
if (GUILayout.Button ("Select Md5(win)")) {
ECLUpgradeListProc.popup4Select ((Callback)onGetUpgradePkg, ListEx.builder().Add(cell.Key).Add("win").ToList());
}
#elif UNITY_STANDALONE_OSX
if (GUILayout.Button ("Select Md5(osx)")) {
ECLUpgradeListProc.popup4Select ((Callback)onGetUpgradePkg, ListEx.builder().Add(cell.Key).Add("osx").ToList());
}
#elif UNITY_WEBGL
if (GUILayout.Button ("Select Md5(webgl)")) {
ECLUpgradeListProc.popup4Select ((Callback)onGetUpgradePkg, ListEx.builder().Add(cell.Key).Add("wegbl").ToList());
}
#endif
}
EditorGUILayout.EndHorizontal ();
}
}
EditorGUILayout.EndScrollView ();
}
ECLEditorUtl.EndContents ();
}
public void onGetUpgradePkg (params object[] paras)
{
string oldMd5 = "";
Hashtable d = paras [0] as Hashtable;
ArrayList orgsList = paras [1] as ArrayList;
string key = orgsList [0] as string;
string platform = orgsList [1] as string;
Hashtable server = MapEx.getMap (servers, key);
string verKey = "";
string vetType = "1";
if (platform.Equals ("ios")) {
2020-08-02 08:47:44 +08:00
verKey = "iosVer";
2020-07-04 14:41:25 +08:00
vetType = "1";
} else if(platform.Equals("Android"))
{
2020-08-02 08:47:44 +08:00
verKey = "androidVer";
2020-07-04 14:41:25 +08:00
vetType = "2";
}
else if (platform.Equals("win"))
{
verKey = "winversion";
vetType = "3";
}
else if (platform.Equals("osx"))
{
verKey = "osxversion";
vetType = "4";
}
oldMd5 = MapEx.getString (server, verKey);
string newMd5 = MapEx.getString (d, "md5");
if (!newMd5.Equals (oldMd5)) {
if (EditorUtility.DisplayDialog ("Alert", "Really want to upgrade this server!!", "Okay", "Cancel")) {
server [verKey] = newMd5;
server ["pkgName"] = MapEx.getString (d, "name");
server ["pkgRemark"] = MapEx.getString (d, "remark");
servers [key] = server;
2020-08-03 23:05:29 +08:00
saveData (verKey);
2020-07-04 14:41:25 +08:00
}
}
}
public void setUpgradePkgMutlMode (string platform)
{
bool canSetMd5 = false;
foreach (DictionaryEntry cell in servers) {
Hashtable server = cell.Value as Hashtable;
if (MapEx.getBool (server, "selected")) {
canSetMd5 = true;
break;
}
}
if (canSetMd5) {
ECLUpgradeListProc.popup4Select ((Callback)onGetUpgradePkgMultMode, platform);
} else {
Debug.LogError ("Please select some servers!!");
}
}
public void onGetUpgradePkgMultMode (params object[] paras)
{
Hashtable d = paras [0] as Hashtable;
string platform = paras [1] as string;
string oldMd5 = "";
2020-08-03 23:05:29 +08:00
string verKey = "";
string vetType = "1";
if (platform.Equals("ios"))
{
verKey = "iosVer";
vetType = "1";
}
else if (platform.Equals("Android"))
{
verKey = "androidVer";
vetType = "2";
}
else if (platform.Equals("win"))
{
verKey = "winversion";
vetType = "3";
}
else if (platform.Equals("osx"))
{
verKey = "osxversion";
vetType = "4";
}
2020-07-04 14:41:25 +08:00
//
if (EditorUtility.DisplayDialog ("Alert", "Really want to upgrade all selected servers!!", "Okay", "Cancel")) {
foreach (DictionaryEntry cell in servers) {
Hashtable server = cell.Value as Hashtable;
if (MapEx.getBool (server, "selected")) {
oldMd5 = MapEx.getString (server, verKey);
string newMd5 = MapEx.getString (d, "md5");
if (!newMd5.Equals (oldMd5)) {
server [verKey] = newMd5;
server ["pkgName"] = MapEx.getString (d, "name");
server ["pkgRemark"] = MapEx.getString (d, "remark");
}
}
}
2020-08-03 23:05:29 +08:00
saveData(verKey);
2020-07-04 14:41:25 +08:00
}
}
public void getUpgradePkgListData ()
{
string cfgPath = ECLProjectManager.ver4UpgradeList;
string str = "";
string p = Application.dataPath + "/" + cfgPath;
if (File.Exists (p)) {
str = File.ReadAllText (p);
}
ArrayList list = JSON.DecodeList (str);
upgradePkgList = list == null ? new ArrayList () : list;
}
Hashtable getUpgradePkgByMd5 (string md5)
{
if (upgradePkgList == null) {
getUpgradePkgListData ();
}
Hashtable cell = null;
for (int i = 0; i < upgradePkgList.Count; i++) {
cell = (Hashtable)(upgradePkgList [i]);
if (MapEx.getString (cell, "md5") == md5) {
return cell;
}
}
return null;
}
2020-08-03 23:05:29 +08:00
public void saveData (string verkey)
2020-07-04 14:41:25 +08:00
{
2020-08-02 08:47:44 +08:00
/*
2020-07-04 14:41:25 +08:00
string url = selectedServer.setServerPkgMd5Url;
Dictionary<string,object> paras = new Dictionary<string, object> ();
paras ["serverid"] = serverID;
paras ["version"] = version;
paras ["versionType"] = verType;
HttpWebResponse response = HttpEx.CreatePostHttpResponse (url, paras, 10000, System.Text.Encoding.UTF8);
if (response == null)
return;
response.Close ();
2020-08-02 08:47:44 +08:00
*/
2020-08-03 23:05:29 +08:00
Hashtable content = JSON.DecodeMap(contentStr);
Hashtable newservers = MapEx.getMap(content, CLCfgBase.self.appUniqueID.ToString());
//Hashtable server = servers[serverID] as Hashtable;
foreach (DictionaryEntry cell in servers)
{
Hashtable server = cell.Value as Hashtable;
Hashtable server2 = newservers[cell.Key] as Hashtable;
server2[verkey] = server[verkey];
}
2020-08-02 08:47:44 +08:00
string str = JSON.JsonEncode(content);
Debug.Log(str);
string path = Path.Combine(Application.dataPath, CLPathCfg.self.basePath, "serversCfg/servers.json");
2020-10-19 23:34:29 +08:00
File.WriteAllText(path, str, Encoding.UTF8);
2020-08-02 08:47:44 +08:00
ThreadEx.exec(new System.Threading.ParameterizedThreadStart(doUploadServers), path);
}
public void doUploadServers(object serversFilePath)
{
if (selectedServer == null)
{
Debug.LogError("Please select a server!");
return;
}
isFinishUpload = false;
if (selectedServer.useSFTP)
{
RenciSFTPHelper sftp = new RenciSFTPHelper(
selectedServer.host4UploadUpgradePackage,
selectedServer.port4UploadUpgradePackage,
selectedServer.ftpUser,
selectedServer.ftpPassword);
2020-08-03 23:05:29 +08:00
string remotePath = Path.Combine(selectedServer.RemoteBaseDir, Path.GetFileName(serversFilePath.ToString()));
2020-08-02 08:47:44 +08:00
if (sftp.connect())
{
2020-08-03 23:05:29 +08:00
sftp.put(serversFilePath.ToString(), remotePath, (Callback)onftpFinish);
2020-08-02 08:47:44 +08:00
sftp.disConnect();
sftp = null;
}
else
{
Utl.doCallback((Callback)onftpFinish, false);
}
}
else
{
float progress = 0;
FTP ftp = new FTP(
selectedServer.host4UploadUpgradePackage,
selectedServer.ftpUser,
selectedServer.ftpPassword);
bool ret = ftp.Upload(serversFilePath.ToString(),
selectedServer.RemoteBaseDir);
Utl.doCallback((Callback)onftpFinish, ret);
}
}
void onftpFinish(params object[] pars)
{
isFinishUpload = true;
bool ret = (bool)(pars[0]);
ECLUpgradeBindingServer.uploadResult = ret;
2020-07-04 14:41:25 +08:00
}
public void refreshData ()
{
servers = null;
getUpgradePkgListData ();
if (selectedServer == null) {
return;
}
// string __httpBaseUrl = PStr.b ().a ("http://").a (Net.self.gateHost).a (":").a (Net.self.gatePort).e ();
// string url = PStr.b ().a (__httpBaseUrl).a ("/KokDirServer/ServerServlet").e ();
2020-08-02 08:47:44 +08:00
string url = Utl.urlAddTimes(selectedServer.getServerListUrl);
2020-07-04 14:41:25 +08:00
if (string.IsNullOrEmpty (url)) {
return;
}
Dictionary<string,object> paras = new Dictionary<string, object> ();
2020-08-02 08:47:44 +08:00
//paras ["serverType"] = 1;
HttpWebResponse response = HttpEx.CreateGetHttpResponse(url, 10000);
2020-07-04 14:41:25 +08:00
if (response == null)
return;
2020-08-03 23:05:29 +08:00
contentStr = HttpEx.readString (response);
2020-07-04 14:41:25 +08:00
response.Close ();
// Debug.Log (url);
// string str = HttpEx.readString (url, null);
2020-08-03 23:05:29 +08:00
Debug.Log (contentStr);
content = JSON.DecodeMap(contentStr);
servers = MapEx.getMap(content, CLCfgBase.self.appUniqueID.ToString());
2020-07-04 14:41:25 +08:00
Hashtable server = null;
Hashtable pkg = null;
if (servers != null) {
2020-08-02 08:47:44 +08:00
string verKey = "";
2020-07-04 14:41:25 +08:00
foreach (DictionaryEntry cell in servers) {
server = cell.Value as Hashtable;
2020-08-02 08:47:44 +08:00
if (CLPathCfg.self.platform.Equals("ios"))
{
verKey = "iosVer";
}
else if (CLPathCfg.self.platform.Equals("Android"))
{
verKey = "androidVer";
}
else if (CLPathCfg.self.platform.Equals("win"))
{
verKey = "winversion";
}
else if (CLPathCfg.self.platform.Equals("osx"))
{
verKey = "osxversion";
}
pkg = getUpgradePkgByMd5 (MapEx.getString (server, verKey));
2020-07-04 14:41:25 +08:00
server ["pkgName"] = MapEx.getString (pkg, "name");
server ["pkgRemark"] = MapEx.getString (pkg, "remark");
}
}
}
public static void show ()
{
ECLUpgradeBindingServer window = ECLUpgradeBindingServer.GetWindow<ECLUpgradeBindingServer> (true, "Server List", true);
if (window == null) {
window = new ECLUpgradeBindingServer ();
}
// Vector2 size = Handles.GetMainGameViewSize ();
Rect rect = window.position;
rect.x = -Screen.width - Screen.width / 4;
rect.y = Screen.height / 2 - Screen.height / 4;
rect.width = Screen.width;
rect.height = Screen.height / 2;
// rect = new Rect (-size.x/2, size.y / 2 - size.y / 4, size.x / 2, size.y / 2);
window.position = rect;
window.title = "Server List";
window.refreshData ();
window.ShowPopup ();
}
}