Index: DamClients/DamUI/trunk/src/Dam/Application/Program.cs =================================================================== diff -u -r6436 -r6903 --- DamClients/DamUI/trunk/src/Dam/Application/Program.cs (.../Program.cs) (revision 6436) +++ DamClients/DamUI/trunk/src/Dam/Application/Program.cs (.../Program.cs) (revision 6903) @@ -20,9 +20,13 @@ // All rights reserved. using System; +using System.Collections.Generic; using System.Drawing; using System.Text; +using System.Windows.Forms; using Deltares.Dam.Data.License; +using Deltares.Dam.Data.Registry; +using Deltares.Dam.Data.Version; using Deltares.Dam.Forms; using Deltares.Geometry.Forms; using Deltares.Geotechnics.Forms; @@ -61,6 +65,8 @@ private static void Start() { + VerifyInstallation(); + DamLicense.CheckoutLicense(dAuthFeature, info.AssemblyVersion); // Parameters are used for splash screen @@ -84,6 +90,55 @@ DamLicense.CheckinLicense(); } + /// + /// Check if the application is properly installed by verifying the required versions + /// of Common Files and DS_Flex in the registry. + /// If not, show an error message and exit the application. + /// + private static void VerifyInstallation() + { + const string requiredVersionCommonFiles = "26.1"; + const string registryPathCommonFiles = "SOFTWARE\\WOW6432Node\\Deltares\\"; + const string registryKeyCommonFiles = "Common Version"; + const string requiredVersionDsFlex = "7.9"; + const string registryPathDsFlex = "SOFTWARE\\WOW6432Node\\WL | Delft Hydraulics\\DS_Flex\\"; + const string registryKeyDsFlex = "InstallerVersion"; + + var errorMessages = new List(); + // Check version of Common Files + string versionCommonFiles = RegistryReader.GetRegistryValueFromLocalMachine(registryPathCommonFiles, registryKeyCommonFiles); + if (string.IsNullOrEmpty(versionCommonFiles)) + { + errorMessages.Add("Common Files not found."); + } else if (!VersionComparer.IsVersionGreaterOrEqual(versionCommonFiles, requiredVersionCommonFiles)) + { + errorMessages.Add("Common files version is outdated: " + versionCommonFiles + + ". Required version is " + requiredVersionCommonFiles + " or higher."); + } + // Check version of DS_Flex + string versionDsFlex = RegistryReader.GetRegistryValueFromLocalMachine(registryPathDsFlex, registryKeyDsFlex); + if (string.IsNullOrEmpty(versionCommonFiles)) + { + errorMessages.Add("DS_Flex not found."); + } else if (!VersionComparer.IsVersionGreaterOrEqual(versionDsFlex, requiredVersionDsFlex)) + { + errorMessages.Add("DS_Flex version is outdated: " + versionDsFlex + + ". Required version is " + requiredVersionDsFlex + " or higher."); + } + if (errorMessages.Count > 0) + { + var errorMessage = new StringBuilder(); + errorMessage.AppendLine("The application cannot be started because it is not properly installed. Please reinstall the application."); + foreach (string msg in errorMessages) + { + errorMessage.AppendLine(msg); + } + + MessageBox.Show(errorMessage.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + Environment.Exit(0); + } + } + private static void MainFormTextChanged(object sender, EventArgs eventArgs) { var mainForm = sender as MainForm;