예제 #1
0
        /// <summary>
        /// 获取dict更新地址
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public static UpdateEnt GetUpdateInfo(string url)
        {
            UpdateEnt c = new UpdateEnt();

            try
            {
                c.DictVersion = Win.WinInput.DictVersion;

                IAASResponse reponse = IAASRequest.Reauest(url, RequestMethod.GET, "", "", "");
                if (reponse.StatusCode == HttpStatusCode.OK)
                {
                    if (reponse.Content.IndexOf("}") < 0)
                    {
                        reponse.Content = "{" + reponse.Content + "}";
                    }

                    if (reponse.Content.IndexOf("srb_ver_info_s") > 0)
                    {
                        c.DictVersion = reponse.Content.Substring(reponse.Content.IndexOf("srb_ver_info_s"), reponse.Content.IndexOf("srb_ver_info_e") - reponse.Content.IndexOf("srb_ver_info_s")).Replace("=", "").Replace("srb_ver_info_s", "");
                        c.DictDownUrl = reponse.Content.Substring(reponse.Content.IndexOf("srb_down_info_s"), reponse.Content.IndexOf("srb_down_info_e") - reponse.Content.IndexOf("srb_down_info_s")).Replace("=", "").Replace("srb_down_info_s", "");
                    }
                    else
                    {
                        c = JsonToObj <UpdateEnt>(reponse.Content);
                    }
                }
            }
            catch
            {
            }
            return(c);
        }
예제 #2
0
        public static void UpdataDict(bool flag = false)
        {
            try
            {
                UpdateEnt data = ApiClient.GetUpdateInfo(Win.WinInput.ApiDictUrl);
                if (Win.WinInput.DictVersion != data.DictVersion)
                {
                    //现在就可升级词库
                    #region 实现升级
                    bool   updataok = false;
                    string du       = data.DictDownUrl;
                    ///下载新词库
                    if (MessageBox.Show("有新词库,是否下载!\r\n", "有新词库", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        Win.Login info = new Win.Login(false, Core.Win.WinInput.Input, 0);
                        info.TopMost = true;
                        info.Show();

                        try
                        {
                            WebClient client   = new WebClient();
                            string    filename = System.IO.Path.Combine(Win.WinInput.Input.AppPath, DateTime.Now.Ticks.ToString() + ".zip");
                            client.DownloadFile(du, filename);
                            Thread.Sleep(200);

                            if (File.Exists(filename))
                            {
                                //下载完成解压
                                updataok = ZipClass.UnZip(filename, System.IO.Path.Combine(Win.WinInput.Input.AppPath, "dict", InputMode.CDPath), "");
                                Thread.Sleep(500);
                                File.Delete(filename);//解压完成,删除下载的文件
                                updataok = true;

                                Win.WinInput.DictVersion = data.DictVersion;
                                Program.MIme.SaveDictSetting();

                                Program.MIme.InputIni();
                                info.Close();
                            }
                        }
                        catch
                        {
                            updataok = false;
                        }
                    }


                    #endregion
                    return;
                }
            }
            catch (Exception ex) { string ss = ex.ToString(); }
        }