private void butRecopy_Click(object sender, EventArgs e) { Version versionCurrent = new Version(Application.ProductVersion); string folderUpdate = ""; if (PrefC.AtoZfolderUsed) { folderUpdate = ODFileUtils.CombinePaths(ImageStore.GetPreferredAtoZpath(), "UpdateFiles"); } else //db { folderUpdate = ODFileUtils.CombinePaths(Path.GetTempPath(), "UpdateFiles"); if (Directory.Exists(folderUpdate)) { Directory.Delete(folderUpdate, true); } DocumentMisc docmisc = DocumentMiscs.GetUpdateFilesZip(); if (docmisc != null) { byte[] rawBytes = Convert.FromBase64String(docmisc.RawBase64); using (ZipFile unzipped = ZipFile.Read(rawBytes)) { unzipped.ExtractAll(folderUpdate); } } } //identify the ideal situation where everything is already in place and no copy is needed. if (Directory.Exists(folderUpdate)) { string filePath = ODFileUtils.CombinePaths(folderUpdate, "Manifest.txt"); if (File.Exists(filePath)) { string fileText = File.ReadAllText(filePath); if (fileText == versionCurrent.ToString(3)) { if (!MsgBox.Show(this, MsgBoxButtons.YesNo, "According to the information in UpdateFiles\\Manifest.txt, the UpdateFiles folder is current. Recopy anyway?")) { return; } } } } Cursor = Cursors.WaitCursor; if (!PrefL.CopyFromHereToUpdateFiles(versionCurrent)) { Cursor = Cursors.Default; return; } Cursor = Cursors.Default; MsgBox.Show(this, "Recopied."); }
///<summary>Called in two places. Once from FormOpenDental.PrefsStartup, and also from FormBackups after a restore.</summary> public static bool CheckProgramVersion() { if (PrefC.GetBool(PrefName.UpdateWindowShowsClassicView)) { return(CheckProgramVersionClassic()); } Version storedVersion = new Version(PrefC.GetString(PrefName.ProgramVersion)); Version currentVersion = new Version(Application.ProductVersion); string database = ""; //string command=""; if (DataConnection.DBtype == DatabaseType.MySql) { database = MiscData.GetCurrentDatabase(); } if (storedVersion < currentVersion) { //There are two different situations where this might happen. if (PrefC.GetString(PrefName.UpdateInProgressOnComputerName) == "") //1. Just performed an update from this workstation on another database. //This is very common for admins when viewing slighly older databases. //There should be no annoying behavior here. So do nothing. { #if !DEBUG //Excluding this in debug allows us to view slightly older databases without accidentally altering them. Prefs.UpdateString(PrefName.ProgramVersion, currentVersion.ToString()); Cache.Refresh(InvalidType.Prefs); #endif return(true); } //and 2a. Just performed an update from this workstation on this database. //or 2b. Just performed an update from this workstation for multiple databases. //In both 2a and 2b, we already downloaded Setup file to correct location for this db, so skip 1 above. //This computer just performed an update, but none of the other computers has updated yet. //So attempt to stash all files that are in the Application directory. if (!CopyFromHereToUpdateFiles(currentVersion)) { Application.Exit(); return(false); } Prefs.UpdateString(PrefName.ProgramVersion, currentVersion.ToString()); Prefs.UpdateString(PrefName.UpdateInProgressOnComputerName, ""); //now, other workstations will be allowed to update. Cache.Refresh(InvalidType.Prefs); } if (storedVersion > currentVersion) { //This is the update sequence for both a direct workstation, and for a ClientWeb workstation. string folderUpdate = ""; if (PrefC.AtoZfolderUsed) { folderUpdate = ODFileUtils.CombinePaths(ImageStore.GetPreferredAtoZpath(), "UpdateFiles"); } else //images in db { folderUpdate = ODFileUtils.CombinePaths(Path.GetTempPath(), "UpdateFiles"); if (Directory.Exists(folderUpdate)) { Directory.Delete(folderUpdate, true); } DocumentMisc docmisc = DocumentMiscs.GetUpdateFilesZip(); if (docmisc != null) { byte[] rawBytes = Convert.FromBase64String(docmisc.RawBase64); using (ZipFile unzipped = ZipFile.Read(rawBytes)) { unzipped.ExtractAll(folderUpdate); } } } //look at the manifest to see if it's the version we need string manifestVersion = ""; try { manifestVersion = File.ReadAllText(ODFileUtils.CombinePaths(folderUpdate, "Manifest.txt")); } catch { //fail silently } if (manifestVersion != storedVersion.ToString(3)) //manifest version is wrong //No point trying the Setup.exe because that's probably wrong too. //Just go straight to downloading and running the Setup.exe. { string manpath = ODFileUtils.CombinePaths(folderUpdate, "Manifest.txt"); if (MessageBox.Show(Lan.g("Prefs", "The expected version information was not found in this file: ") + manpath + ". " + Lan.g("Prefs", "There is probably a permission issue on that folder which should be fixed. ") + "\r\n\r\n" + Lan.g("Prefs", "The suggested solution is to return to the computer where the update was just run. Go to Help | Update | Setup, and click the Recopy button.") + "\r\n\r\n" + Lan.g("Prefs", "If, instead, you click OK in this window, then a fresh Setup file will be downloaded and run."), "", MessageBoxButtons.OKCancel) != DialogResult.OK) //they don't want to download again. { Application.Exit(); return(false); } DownloadAndRunSetup(storedVersion, currentVersion); Application.Exit(); return(false); } //manifest version matches if (MessageBox.Show(Lan.g("Prefs", "Files will now be copied.") + "\r\n" + Lan.g("Prefs", "Workstation version will be updated from ") + currentVersion.ToString(3) + Lan.g("Prefs", " to ") + storedVersion.ToString(3), "", MessageBoxButtons.OKCancel) != DialogResult.OK) //they don't want to update for some reason. { Application.Exit(); return(false); } string tempDir = Path.GetTempPath(); //copy UpdateFileCopier.exe to the temp directory File.Copy(ODFileUtils.CombinePaths(folderUpdate, "UpdateFileCopier.exe"), //source ODFileUtils.CombinePaths(tempDir, "UpdateFileCopier.exe"), //dest true); //overwrite //wait a moment to make sure the file was copied Thread.Sleep(500); //launch UpdateFileCopier to copy all files to here. int processId = Process.GetCurrentProcess().Id; string appDir = Application.StartupPath; string startFileName = ODFileUtils.CombinePaths(tempDir, "UpdateFileCopier.exe"); string arguments = "\"" + folderUpdate + "\"" //pass the source directory to the file copier. + " " + processId.ToString() //and the processId of Open Dental. + " \"" + appDir + "\""; //and the directory where OD is running Process.Start(startFileName, arguments); Application.Exit(); //always exits, whether launch of setup worked or not return(false); } return(true); }