SIL.FieldWorks.FieldWorks.CheckForMovingExternalLinkDirectory C# (CSharp) Méthode

CheckForMovingExternalLinkDirectory() private méthode

private CheckForMovingExternalLinkDirectory ( FwApp app ) : void
app SIL.FieldWorks.Common.Framework.FwApp
Résultat void
		private static void CheckForMovingExternalLinkDirectory(FwApp app)
		{
			// Don't crash here if we have a data problem -- that may be due to another issue that
			// would be masked by throwing at this point.  (See FWR-3849.)
			// app.Cache will be null if we couldn't open the project (FWNX-684)
			if (app == null || app.Cache == null || app.Cache.ProjectId == null || !app.Cache.ProjectId.IsLocal)
				return;
			// Check that we're on the ninth launch of either Flex or TE, and that neither has been
			// launched nine or more times already.
			var launchesFlex = 0;
			var launchesTe = 0;
			if (RegistryHelper.KeyExists(FwRegistryHelper.FieldWorksRegistryKey, "Language Explorer"))
			{
				using (var keyFlex = FwRegistryHelper.FieldWorksRegistryKey.CreateSubKey("Language Explorer"))
				{
					if (keyFlex != null)
						Int32.TryParse(keyFlex.GetValue("launches", "0") as string, out launchesFlex);
				}
			}
			if (RegistryHelper.KeyExists(FwRegistryHelper.FieldWorksRegistryKey, FwSubKey.TE))
			{
				using (var keyTe = FwRegistryHelper.FieldWorksRegistryKey.CreateSubKey(FwSubKey.TE))
				{
					if (keyTe != null)
						Int32.TryParse(keyTe.GetValue("launches", "0") as string, out launchesTe);
				}
			}
			if ((Math.Max(launchesFlex, launchesTe) != 9) || (Math.Min(launchesFlex, launchesTe) >= 9))
				return;
			using (var rk = Registry.LocalMachine.OpenSubKey("Software\\SIL\\FieldWorks"))
			{
				string oldDir = null;
				if (rk != null)
					oldDir = rk.GetValue("RootDataDir") as string;
				if (oldDir == null)
				{
					// e.g. "C:\\ProgramData\\SIL\\FieldWorks"
					oldDir = DirectoryFinder.CommonAppDataFolder("FieldWorks");
				}
				oldDir = oldDir.TrimEnd(new [] {Path.PathSeparator});
				var newDir = app.Cache.LangProject.LinkedFilesRootDir;
				newDir = newDir.TrimEnd(new [] {Path.PathSeparator});
				// This isn't foolproof since the currently open project on the 9th time may
				// not even be one that was migrated. But it will probably work for most users.
				if (newDir.ToLowerInvariant() != oldDir.ToLowerInvariant())
					return;
				DialogResult res;
				if (app == s_teApp)
				{
					// TE doesn't have a help topic for this insane dialog box.
					res = MessageBox.Show(Properties.Resources.ksProjectLinksStillOld,
						Properties.Resources.ksReviewLocationOfLinkedFiles,
						MessageBoxButtons.YesNo);
				}
				else
				{
					// TODO-Linux: Help is not implemented in Mono
					const string helpTopic = "/User_Interface/Menus/File/Project_Properties/Review_the_location_of_Linked_Files.htm";
					res = MessageBox.Show(Properties.Resources.ksProjectLinksStillOld,
						Properties.Resources.ksReviewLocationOfLinkedFiles,
						MessageBoxButtons.YesNo, MessageBoxIcon.None,
						MessageBoxDefaultButton.Button1, 0, app.HelpFile,
						"/User_Interface/Menus/File/Project_Properties/Review_the_location_of_Linked_Files.htm");
				}
				if (res != DialogResult.Yes)
					return;
				MoveExternalLinkDirectoryAndFiles(app);
			}
		}
FieldWorks