/// ------------------------------------------------------------------------------------
        /// <summary>
        /// Because of a bug in version 3.3.0 to 3.3.2, the feature overrides file may contain
        /// phones whose overridden features are the same as the phone's default features.
        /// This method will clean out the feature overrides file of phones whose features
        /// really aren't overridden.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private static void RemoveFeatureOverridesThatAreNotOverridden(PaProject project)
        {
            var newOverrideList = new List <FeatureOverride>();

            foreach (var phoneInfo in project.PhoneCache.Values)
            {
                var foverride = project.FeatureOverrides.GetOverridesForPhone(phoneInfo.Phone);
                if (foverride == null)
                {
                    continue;
                }

                if (!phoneInfo.HasAFeatureOverrides && foverride.AFeatureNames.Count() > 0)
                {
                    foverride.AFeatureNames = new List <string>(0);
                }

                if (!phoneInfo.HasBFeatureOverrides && foverride.BFeatureNames.Count() > 0)
                {
                    foverride.BFeatureNames = new List <string>(0);
                }

                if (foverride.AFeatureNames.Count() > 0 || foverride.BFeatureNames.Count() > 0)
                {
                    newOverrideList.Add(foverride);
                }
            }

            var filePath = FeatureOverrides.GetFileForProject(project.ProjectPathFilePrefix);

            FeatureOverrides.BuildXmlForOverrides(newOverrideList, project.DistinctiveFeatureSet).Save(filePath);
            project.LoadFeatureOverrides();
        }
        /// ------------------------------------------------------------------------------------
        protected override void InternalMigration()
        {
            var filepath = FeatureOverrides.GetFileForProject(_projectPathPrefix);

            if (File.Exists(filepath))
            {
                MigrateFeatureOverrides(filepath);
            }

            filepath = SearchQueryGroupList.GetFileForProject(_projectPathPrefix);
            if (File.Exists(filepath))
            {
                MigrateSearchQueries(filepath);
            }

            filepath = DistributionChart.GetFileForProject(_projectPathPrefix);
            if (File.Exists(filepath))
            {
                MigrateDistributionCharts(filepath);
            }

            if (File.Exists(App.GetPathToRecentlyUsedSearchQueriesFile()))
            {
                MigrateRecentlyUsedSearchQueries(App.GetPathToRecentlyUsedSearchQueriesFile());
            }

            filepath = SearchClassList.GetFileForProject(_projectPathPrefix);
            if (File.Exists(filepath))
            {
                MigrateSearchClasses(filepath);
            }

            if (File.Exists(_projectFilePath))
            {
                MigrateProjectFile();
                UpdateProjectFileToLatestVersion();
            }

            s_performPostProjectLoadMigration = true;

            var msg = LocalizationManager.GetString("ProjectMessages.Migrating.VerifyUpdatedFeatureOverridesMsg",
                                                    "Important Note: Some features in Phonology Assistant have changed and this has implications " +
                                                    "for the feature overrides, search queries and classes for the '{0}' project. These have " +
                                                    "been updated accordingly. However, you may want to verify the accuracy of the results, " +
                                                    "especially if you have overridden some features for this project. To check the feature overrides, " +
                                                    "from the Tools menu, go to 'Descriptive Features' (formerly called articulatory features) and " +
                                                    "'Distinctive Features' (formerly called binary features) and verify the accuracy of overridden " +
                                                    "features. Overridden phones and features will be highlighted in yellow.");

            Utils.MsgBox(string.Format(msg, ProjectName));
        }
        /// ------------------------------------------------------------------------------------
        private void MigrateFeatureOverrides()
        {
            var filepath = FeatureOverrides.GetFileForProject(_projectPathPrefix);

            if (!File.Exists(filepath))
            {
                return;
            }

            var error = TransformFile(filepath, "SIL.Pa.Model.Migration.UpdateFeatureOverridesFile.xslt");

            if (error != null)
            {
                throw error;
            }
        }