///<summary>
		/// Returns an instance of an ldml in folder writing system reposistory.
		///</summary>
		///<param name="basePath">base location of the global writing system repository</param>
		///<param name="migrationHandler">Callback if during the initialization any writing system id's are changed</param>
		///<param name="loadProblemHandler">Callback if during the initialization any writing systems cannot be loaded</param>
		public static LdmlInFolderWritingSystemRepository Initialize(
			string basePath,
			LdmlVersion0MigrationStrategy.MigrationHandler migrationHandler,
			WritingSystemLoadProblemHandler loadProblemHandler
		)
		{
			return Initialize(basePath, migrationHandler, loadProblemHandler, WritingSystemCompatibility.Strict);
		}
		public WritingSystemSetupDialog(
			string writingSystemRepositoryPath,
			LdmlVersion0MigrationStrategy.MigrationHandler migrationHandler,
			WritingSystemLoadProblemHandler loadProblemHandler
		) : this(LdmlInFolderWritingSystemRepository.Initialize(
			writingSystemRepositoryPath,
			migrationHandler,
			loadProblemHandler
		))
		{
		}
		///<summary>
		/// This initializer is intended for tests as it allows setting of the basePath explicitly.
		///</summary>
		///<param name="basePath">base location of the global writing system repository</param>
		///<param name="migrationHandler">Callback if during the initialization any writing system id's are changed</param>
		internal static GlobalWritingSystemRepository InitializeWithBasePath(string basePath, LdmlVersion0MigrationStrategy.MigrationHandler migrationHandler)
		{
			lock (_padlock)
			{
				if (_instance == null)
				{
					var migrator = new GlobalWritingSystemRepositoryMigrator(basePath, migrationHandler);
					if (migrator.NeedsMigration())
					{
						migrator.Migrate();
					}

					_instance = new GlobalWritingSystemRepository(basePath);
					_instance.LoadAllDefinitions();
				}
			}
			return _instance;
		}
		public LdmlInFolderWritingSystemRepositoryMigrator(
			string ldmlPath,
			LdmlVersion0MigrationStrategy.MigrationHandler migrationHandler,
			WritingSystemCompatibility compatibilityMode
		) : base(WritingSystemDefinition.LatestWritingSystemDefinitionVersion, ldmlPath)
		{
			SearchPattern = "*.ldml";

			//The first versiongetter checks for the palaso:version node.
			//The DefaultVersion is a catchall that identifies any file as version 0 that the first version getter can't identify
			AddVersionStrategy(new WritingSystemLdmlVersionGetter(compatibilityMode));
			AddVersionStrategy(new DefaultVersion(0, 0));

			var auditLog = new WritingSystemChangeLog(
				new WritingSystemChangeLogDataMapper(Path.Combine(ldmlPath, "idchangelog.xml"))
			);
			AddMigrationStrategy(new LdmlVersion0MigrationStrategy(migrationHandler, auditLog, 0, compatibilityMode));
			// Version 0 strategy has been enhanced to also migrate version 1.
			AddMigrationStrategy(new LdmlVersion0MigrationStrategy(migrationHandler, auditLog, 1, compatibilityMode));
		}
		///<summary>
		/// Returns an instance of an ldml in folder writing system reposistory.
		///</summary>
		///<param name="basePath">base location of the global writing system repository</param>
		///<param name="migrationHandler">Callback if during the initialization any writing system id's are changed</param>
		///<param name="loadProblemHandler">Callback if during the initialization any writing systems cannot be loaded</param>
		///<param name="compatibilityMode"></param>
		public static LdmlInFolderWritingSystemRepository Initialize(
			string basePath,
			LdmlVersion0MigrationStrategy.MigrationHandler migrationHandler,
			WritingSystemLoadProblemHandler loadProblemHandler,
			WritingSystemCompatibility compatibilityMode
		)
		{
			var migrator = new LdmlInFolderWritingSystemRepositoryMigrator(basePath, migrationHandler, compatibilityMode);
			migrator.Migrate();

			var instance = new LdmlInFolderWritingSystemRepository(basePath, compatibilityMode);
			instance.LoadAllDefinitions();

			// Call the loadProblemHandler with both migration problems and load problems
			var loadProblems = new List<WritingSystemRepositoryProblem>();
			loadProblems.AddRange(migrator.MigrationProblems);
			loadProblems.AddRange(instance.LoadProblems);
			if (loadProblems.Count > 0 && loadProblemHandler != null)
			{
				loadProblemHandler(loadProblems);
			}

			return instance;
		}
		public LdmlInFolderWritingSystemRepositoryMigrator(
			string ldmlPath,
			LdmlVersion0MigrationStrategy.MigrationHandler onMigrationCallback
		) : this(ldmlPath, onMigrationCallback, WritingSystemCompatibility.Strict)
		{
		}
		///<summary>
		/// Initializes the migrator with the given basePath (i.e. excluding the version), and a callback
		/// for informing the consumer of changes to writing system tags during migration. Applications
		/// should ensure that all writing systems tags they store are updated accordingly when the callback
		/// is called.
		///</summary>
		///<param name="basePath"></param>
		///<param name="migrationHandler"></param>
		public GlobalWritingSystemRepositoryMigrator(string basePath, LdmlVersion0MigrationStrategy.MigrationHandler migrationHandler)
		{
			Guard.AgainstNull(migrationHandler, "migrationHandler must be set");
			_migrationHandler = migrationHandler;
			BasePath = basePath;
		}
		///<summary>
		/// Initializes the global writing system repository.  Migrates any ldml files if required,
		/// notifying of any changes of writing system id that occured during migration.
		///</summary>
		///<param name="migrationHandler"></param>
		public static GlobalWritingSystemRepository Initialize(LdmlVersion0MigrationStrategy.MigrationHandler migrationHandler)
		{
			return InitializeWithBasePath(DefaultBasePath, migrationHandler);
		}