Exemplo n.º 1
0
        private static void Update()
        {
            string versionC = Global.getVersion();
            string versionS = "";
            string url      = "http://" + Global.HOST + "/user.do?action=update&schoolid=" + Global.getSchoolID() + "&classid=" + Global.getClassID() + "&version=" + Global.getVersion();
            //string json = HTTPReq.doGet(url,1000);
            string json = HTTPReq.HttpGet(url);

            if (json.Length == 0)
            {
                return;
            }
            Log.Info("Update, ret=" + json);
            try
            {
                UpdateInfo resp = JsonOper.DeserializeJsonToObject <UpdateInfo>(json.Replace("(", "").Replace(")", ""));
                if (resp == null)
                {
                    return;
                }


                foreach (UpdateItem item in resp.updateinfolist)
                {
                    Log.Info(item.toJson());
                    if (item.type == 1)//
                    {
                        versionS = item.version;
                        Log.Info("versionC=" + versionC + ", versionS=" + versionS);
                        string[] szVerS  = versionS.Split('.');
                        string[] szVerC  = versionC.Split('.');
                        string   zipurl  = item.path;
                        bool     bUpdate = false;
                        for (int i = 0; i < szVerS.Length; i++)
                        {
                            int nS = Util.toInt(szVerS[i]);
                            int nC = Util.toInt(szVerC[i]);
                            if (nS > nC)
                            {
                                bUpdate = true;
                                break;
                            }
                            else if (nS < nC)
                            {
                                return;
                            }
                            else
                            {
                                continue;
                            }
                        }

                        if (bUpdate)
                        {
                            string update  = Application.StartupPath + "\\RueUpdate.exe";
                            string update2 = Application.StartupPath + "\\RueUpdate2.exe";
                            Log.Info(update);
                            Log.Info(update2);
                            if (File.Exists(update2))
                            {
                                Log.Info("copy...");
                                KillProcess("RueUpdate.exe");
                                try
                                {
                                    File.Delete(update);
                                    File.Copy(update2, update, true);
                                    Log.Info("delete update2...");
                                    File.Delete(update2);
                                }
                                catch (Exception e)
                                {
                                    Log.Info("File.copy(update2,update) and File.Delete exception. " + e.Message);
                                }
                            }
                            else if (File.Exists(update))
                            {
                                string param = versionS + " " + zipurl;
                                Log.Info("run update.exe now..." + param);
                                Process.Start(update, param);
                            }
                        }
                    }
                    else if (item.type == 2)
                    {
                        Global.setRyktUpdateInfo(item);
                    }
                }
            }
            catch (Exception e)
            {
                Log.Error(e.Message);
            }
        }