This commit is contained in:
2020-08-02 08:47:44 +08:00
parent 4435098171
commit f3ecc018ff
11 changed files with 232 additions and 89 deletions

View File

@@ -8,6 +8,8 @@ using System.Net;
public class ECLUpgradeBindingServer : EditorWindow
{
Hashtable content;
Hashtable servers;
Hashtable server;
Vector2 scrollPos = Vector2.zero;
@@ -15,6 +17,27 @@ public class ECLUpgradeBindingServer : EditorWindow
bool isSelectAll = false;
static int selectedServerIndex = 0;
HotUpgradeServerInfor selectedServer = null;
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");
}
}
}
void OnGUI ()
{
@@ -150,12 +173,12 @@ public class ECLUpgradeBindingServer : EditorWindow
GUI.color = Color.white;
}
EditorGUILayout.TextField (MapEx.getString (server, "idx"), GUILayout.Width (80));
EditorGUILayout.TextField (MapEx.getString (server, "servername"), GUILayout.Width (100));
EditorGUILayout.TextField (MapEx.getString (server, "name"), GUILayout.Width (100));
GUI.color = Color.yellow;
#if UNITY_ANDROID
EditorGUILayout.TextField (MapEx.getString (server, "androidversion"), GUILayout.Width (250));
EditorGUILayout.TextField (MapEx.getString (server, "androidVer"), GUILayout.Width (250));
#elif UNITY_IPHONE || UNITY_IOS
EditorGUILayout.TextField (MapEx.getString (server, "iosversion"), GUILayout.Width (250));
EditorGUILayout.TextField (MapEx.getString (server, "iosVer"), GUILayout.Width (250));
#elif UNITY_STANDALONE_WIN
EditorGUILayout.TextField (MapEx.getString (server, "winversion"), GUILayout.Width (250));
#elif UNITY_STANDALONE_OSX
@@ -163,7 +186,7 @@ public class ECLUpgradeBindingServer : EditorWindow
#elif UNITY_WEBGL
EditorGUILayout.TextField (MapEx.getString (server, "webglversion"), GUILayout.Width (250));
#endif
EditorGUILayout.TextField (MapEx.getString (server, "pkgName"), GUILayout.Width (160));
EditorGUILayout.TextField (MapEx.getString (server, "pkgName"), GUILayout.Width (160));
EditorGUILayout.TextArea (MapEx.getString (server, "pkgRemark"), GUILayout.Width (250));
GUI.color = Color.white;
#if UNITY_ANDROID
@@ -208,11 +231,11 @@ public class ECLUpgradeBindingServer : EditorWindow
string verKey = "";
string vetType = "1";
if (platform.Equals ("ios")) {
verKey = "iosversion";
verKey = "iosVer";
vetType = "1";
} else if(platform.Equals("Android"))
{
verKey = "androidversion";
verKey = "androidVer";
vetType = "2";
}
else if (platform.Equals("win"))
@@ -268,12 +291,12 @@ public class ECLUpgradeBindingServer : EditorWindow
string verKey = "";
string vetType = "1";
if (platform.Equals ("ios")) {
verKey = "iosversion";
verKey = "iosVer";
vetType = "1";
}
else if (platform.Equals("Android"))
{
verKey = "androidversion";
verKey = "androidVer";
vetType = "2";
}
else if (platform.Equals("win"))
@@ -292,7 +315,7 @@ public class ECLUpgradeBindingServer : EditorWindow
server [verKey] = newMd5;
server ["pkgName"] = MapEx.getString (d, "name");
server ["pkgRemark"] = MapEx.getString (d, "remark");
saveData (MapEx.getString (server, "idx"), newMd5, vetType);
saveData (MapEx.getString (server, "id"), newMd5, verKey);
}
}
}
@@ -326,10 +349,9 @@ public class ECLUpgradeBindingServer : EditorWindow
return null;
}
public void saveData (string serverID, string version, string verType)
public void saveData (string serverID, string version, string verKey)
{
// string __httpBaseUrl = PStr.b ().a ("http://").a (Net.self.gateHost).a (":").a (Net.self.gatePort).e ();
// string url = PStr.b ().a (__httpBaseUrl).a ("/KokDirServer/UpdateVerServlet").e ();
/*
string url = selectedServer.setServerPkgMd5Url;
Dictionary<string,object> paras = new Dictionary<string, object> ();
paras ["serverid"] = serverID;
@@ -339,6 +361,62 @@ public class ECLUpgradeBindingServer : EditorWindow
if (response == null)
return;
response.Close ();
*/
Hashtable server = servers[serverID] as Hashtable;
server[verKey] = version;
string str = JSON.JsonEncode(content);
Debug.Log(str);
string path = Path.Combine(Application.dataPath, CLPathCfg.self.basePath, "serversCfg/servers.json");
File.WriteAllText(path, str);
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);
if (sftp.connect())
{
sftp.put(serversFilePath.ToString(), selectedServer.RemoteBaseDir, (Callback)onftpFinish);
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;
}
public void refreshData ()
@@ -350,13 +428,13 @@ public class ECLUpgradeBindingServer : EditorWindow
}
// 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 ();
string url = selectedServer.getServerListUrl;
string url = Utl.urlAddTimes(selectedServer.getServerListUrl);
if (string.IsNullOrEmpty (url)) {
return;
}
Dictionary<string,object> paras = new Dictionary<string, object> ();
paras ["serverType"] = 1;
HttpWebResponse response = HttpEx.CreatePostHttpResponse (url, paras, 10000, System.Text.Encoding.UTF8);
//paras ["serverType"] = 1;
HttpWebResponse response = HttpEx.CreateGetHttpResponse(url, 10000);
if (response == null)
return;
string str = HttpEx.readString (response);
@@ -364,13 +442,31 @@ public class ECLUpgradeBindingServer : EditorWindow
// Debug.Log (url);
// string str = HttpEx.readString (url, null);
Debug.Log (str);
servers = JSON.DecodeMap (str);
content = JSON.DecodeMap(str);
servers = MapEx.getMap(content, CLCfgBase.self.appUniqueID);
Hashtable server = null;
Hashtable pkg = null;
if (servers != null) {
string verKey = "";
foreach (DictionaryEntry cell in servers) {
server = cell.Value as Hashtable;
pkg = getUpgradePkgByMd5 (MapEx.getString (server, "version"));
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));
server ["pkgName"] = MapEx.getString (pkg, "name");
server ["pkgRemark"] = MapEx.getString (pkg, "remark");
}