Esempio n. 1
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Displays the Project Location Sharing dialog box
		/// </summary>
		/// <param name="dialogOwner">The form that should be used as the dialog owner.</param>
		/// <param name="fwApp">The FieldWorks application from with this command was initiated.
		/// </param>
		/// ------------------------------------------------------------------------------------
		internal static void FileProjectSharingLocation(Form dialogOwner, FwApp fwApp)
		{
			Debug.Assert(fwApp.Cache.ProjectId.IsLocal);

			using (ProjectLocationSharingDlg dlg = new ProjectLocationSharingDlg(fwApp, fwApp.Cache))
			{
			if (dlg.ShowDialog(dialogOwner) != DialogResult.OK)
				return;
			string projectPath = fwApp.Cache.ProjectId.Path;
			string parentDirectory = Path.GetDirectoryName(fwApp.Cache.ProjectId.ProjectFolder);
			string projectsDirectory = FwDirectoryFinder.ProjectsDirectory;
				if (!MiscUtils.IsUnix)
				{
					parentDirectory = parentDirectory.ToLowerInvariant();
					projectsDirectory = projectsDirectory.ToLowerInvariant();
				}

			if (dlg.ProjectsSharedChecked)
			{
				// We now want projects shared. The only way we would be allowed to change the project folder is if it
				// previously was not shared. If that's the case, change it before we switch.
				if (!ClientServerServices.Current.Local.ShareMyProjects)
					UpdateProjectsLocation(dlg.ProjectsFolder, fwApp, projectPath);
					if (!MiscUtils.IsUnix)
						projectsDirectory = FwDirectoryFinder.ProjectsDirectory.ToLowerInvariant();
				if (UpdateProjectsSharing(true, dialogOwner, fwApp, projectPath, parentDirectory, projectsDirectory))
				{
					using (var dlgShare = new ShareProjectsFolderDlg())
						dlgShare.ShowDialog();
				}
			}
			else
			{
				// We don't now want projects shared. Make sure we turn it off before possibly also changing the directory.
				UpdateProjectsSharing(false, dialogOwner, fwApp, projectPath, parentDirectory, projectsDirectory);
				UpdateProjectsLocation(dlg.ProjectsFolder, fwApp, projectPath);
			}
		}
		}
Esempio n. 2
0
		/// <summary>
		/// Check that the projects directory can be found and is not compressed or encrypted.
		/// If it is not found, offer to let the user choose a new one.
		/// Return true if we end up with a valid data directory.
		/// </summary>
		public static bool CheckProjectDirectory(Form f, IHelpTopicProvider helpTopicProvider)
		{
			string warning = null;
			string dataDirectory = FwDirectoryFinder.ProjectsDirectory;

			// Get the database directory attributes:
			var dir = new DirectoryInfo(dataDirectory);

			// See if the dirctory is missing, compressed or encrypted:
			while (!dir.Exists)
			{
				if (MessageBox.Show(string.Format(FwCoreDlgs.ksNLPFolderDoesNotExist, dataDirectory),
									FwCoreDlgs.ksNLPFolderError, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No)
					return false; // can't go on.
				using (var dlg = new ProjectLocationSharingDlg(helpTopicProvider))
				{
					if (dlg.ShowDialog(f) != DialogResult.OK)
						return false; // can't go on.
					if (FwDirectoryFinder.ProjectsDirectoryLocalMachine == dlg.ProjectsFolder)
					{
						//Remove the user override since they reset to the default.
						FwDirectoryFinder.ProjectsDirectory = null;
					}
					else
					{
						FwDirectoryFinder.ProjectsDirectory = dlg.ProjectsFolder;
					}
				}
				dataDirectory = FwDirectoryFinder.ProjectsDirectory;
				dir = new DirectoryInfo(dataDirectory);
				// loop on the offchance it didn't get created.
			}
			if ((dir.Attributes & FileAttributes.Compressed) == FileAttributes.Compressed)
				warning = FwCoreDlgs.ksNLPFolderCompressed;
			else if ((dir.Attributes & FileAttributes.Encrypted) == FileAttributes.Encrypted)
				warning = FwCoreDlgs.ksNLPFolderEncrypted;

			if (warning != null)
			{
				MessageBox.Show(string.Format(warning, dataDirectory),
								FwCoreDlgs.ksNLPFolderError, MessageBoxButtons.OK, MessageBoxIcon.Warning);

				return false; // Cannot continue from here.
			}
			return true; // all is well.
		}