private void CheckVersionUpdate(bool bShowTip, bool positiveCheck = false, bool isDebug = false) { UpdateManager.CheckUpdate(new Update_CallBack((tagUpdateInfo updateInfo) => { if (updateInfo.hasNewVer) { if (UpdateManager.DownloadNewVerion(updateInfo)) { if (!positiveCheck) Thread.Sleep(2100); this.Dispatcher.Invoke(new Action(delegate { if (bShowTip) { //UpdateManager.ShowUpdateDialog(updateInfo);//show something to let uer select to continue update this.Dispatcher.Invoke(new Action(delegate { this.m_updateinfo = updateInfo; this.ShowUpdatePanel(true); })); } })); } } else { if (positiveCheck == true) //if prositive check , inform user there is no new version available { this.Dispatcher.Invoke( new Action(delegate { double left = this.Left; this.Left = left - 10; Thread.Sleep(50); this.Left = left; Thread.Sleep(50); this.Left = left + 10; Thread.Sleep(50); this.Left = left; Thread.Sleep(50); this.Left = left - 10; Thread.Sleep(50); this.Left = left; Thread.Sleep(50); this.Left = left + 10; Thread.Sleep(50); this.Left = left; })); } } } ), isDebug); }
public static bool DownloadNewVerion(tagUpdateInfo updateinfo) { if (updateinfo.hasNewVer) { if (updateinfo.newVersionNum > updateinfo.curVerionNum) { string startpath = AppDomain.CurrentDomain.BaseDirectory; string updateFoler = startpath + "update"; string newBinaryFile = updateFoler + "\\" + updateinfo.newBuildName; string localExistBinaryConfig = updateFoler + "\\config.txt"; if (!Directory.Exists(updateFoler)) { Directory.CreateDirectory(updateFoler); } if (File.Exists(newBinaryFile) && File.Exists(localExistBinaryConfig)) { //check the build config file to see if match the latest server version FileStream myFs = new FileStream(localExistBinaryConfig, FileMode.Open); StreamReader fileReader = new StreamReader(myFs); string ver = fileReader.ReadLine(); fileReader.Close(); myFs.Close(); try { int intVer = Int32.Parse(ver); if (intVer == updateinfo.newVersionNum) return true; } catch { } } //delete old files before getting new files if (File.Exists(newBinaryFile)) File.Delete(newBinaryFile); try { if (File.Exists(localExistBinaryConfig)) File.Delete(localExistBinaryConfig); } catch (Exception e) { Console.WriteLine(e.Message); } if (!File.Exists(newBinaryFile)) { //try to download new installer if (!HttpDownloadFile(updateinfo.newVerDownloadUrl, newBinaryFile)) { if (!HttpDownloadFile(updateinfo.newVerDownloadUrl, newBinaryFile)) { Console.WriteLine("download " + updateinfo.newVerDownloadUrl + "failed!"); return false; } } //create corresponding version record file if (File.Exists(localExistBinaryConfig)) { File.Delete(localExistBinaryConfig); } FileStream myFs = new FileStream(localExistBinaryConfig, FileMode.Create); StreamWriter mySw = new StreamWriter(myFs); mySw.Write(String.Format("{0}",updateinfo.newVersionNum)); mySw.Close(); myFs.Close(); } return true; } } return false; }
public static void ShowUpdateDialog(tagUpdateInfo updateInfo) { //Boolean result = false; //SimpleMessageBox uw = new SimpleMessageBox(); //uw.SetCurVersion(updateInfo.curVerionNum); //uw.SetNewVersion(updateInfo.newVersionNum); //uw.SetButton(3, "");//set the check box invisible //result = (Boolean)uw.ShowDialog(); //if (result == true) //{ // UpdateManager.LauchNewInstaller(updateInfo); //} }
private static void CheckUpdateProc(Delegate callback, bool IsDebug) { string updateUrl = GlobalDef.prefixOfServer + "/update/pc/update.ini"; if (IsDebug) updateUrl = GlobalDef.prefixOfServer + "/update/pc/update_debug.ini"; //get update ini to temp folder string tempFolder = System.IO.Path.GetTempPath(); string xphoneUpdateFile = tempFolder + "cleanspaceUpdate.ini"; if (!HttpDownloadFile(updateUrl, xphoneUpdateFile)) { if (!HttpDownloadFile(updateUrl, xphoneUpdateFile)) { return; } } //parse ini file IniFile iniFile = new IniFile(xphoneUpdateFile); string newVer = iniFile.IniReadValue("VersionInfo", "version"); string newDesc = iniFile.IniReadValue("VersionInfo", "description"); string newBuildLink = iniFile.IniReadValue("VersionInfo", "newBuildLink"); string newBuildName = iniFile.IniReadValue("VersionInfo", "newBuildName"); string md5 = iniFile.IniReadValue("VersionInfo", "MD5"); //format new Ver //string temp = newVer.Substring(0,1) + "."+newVer.Substring(1,1) + "." + newVer.Substring(2,1) + "." + newVer.Substring(3,1); //newVer = temp; int intNewVer = Int32.Parse(newVer); //Get current version // string version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(); FileVersionInfo fileversion = System.Diagnostics.FileVersionInfo.GetVersionInfo(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName); string curVer = fileversion.ProductVersion; int intCurVer = fileversion.FileMajorPart * 1000 + fileversion.FileMinorPart * 100 + fileversion.FileBuildPart * 10 + fileversion.FilePrivatePart; tagUpdateInfo updateInfo = new tagUpdateInfo(); if (intNewVer > intCurVer) //new version available { updateInfo.hasNewVer = true; updateInfo.newVersionNum = intNewVer; updateInfo.curVerionNum = intCurVer; updateInfo.newVersionDesc = newDesc; updateInfo.newVersionMd5 = md5; updateInfo.newVerDownloadUrl = newBuildLink; updateInfo.newBuildName = newBuildName; } else { updateInfo.hasNewVer = false; } callback.DynamicInvoke(updateInfo); return; }
public static void LauchNewInstaller(tagUpdateInfo updateinfo) { string startpath = AppDomain.CurrentDomain.BaseDirectory; string updateFoler = startpath + "update"; string newBinaryFile = updateFoler + "\\" + updateinfo.newBuildName; ProcessStart(newBinaryFile, @""); //terminate self ((App)Application.Current).terminate(); }