示例#1
0
        private static string[] MoveCopyOrLeaveFiles(string[] files, string subFolder, string sRootDirExternalLinks,
                                                     IHelpTopicProvider helpTopicProvider)
        {
            try
            {
                if (!Directory.Exists(subFolder))
                {
                    Directory.CreateDirectory(subFolder);
                }
            }
            catch (Exception e)
            {
                Logger.WriteEvent(string.Format("Error creating the directory: '{0}'", subFolder));
                Logger.WriteError(e);
                return(files);
            }

            // Check whether the file is found within the directory.
            if (files.All(f => FileIsInExternalLinksFolder(f, sRootDirExternalLinks)))
            {
                return(files);
            }

            using (var dlg = new MoveOrCopyFilesDlg())
            {
                dlg.Initialize2(subFolder, helpTopicProvider);
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    FileLocationChoice choice = dlg.Choice;
                    return(files.Select(f => PerformMoveCopyOrLeaveFile(f, subFolder, choice)).ToArray());
                }

                return(files);
            }
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Called when the user clicked the OK button and the File Location Options panel is
        /// visible.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private void ApplyFileLocationOptions()
        {
            FileLocationChoice fileLocChoice;

            if (m_rbCopy.Checked)
            {
                fileLocChoice = FileLocationChoice.Copy;
            }
            else
            {
                fileLocChoice = (m_rbMove.Checked ?
                                 FileLocationChoice.Move : FileLocationChoice.Leave);
            }

            // If this dialog is being displayed for the purpose of inserting a new
            // picture or changing which picture is being displayed, remember the user's
            // copy/move/leave choice
            if (m_initialPicture == null || m_initialPicture.PictureFileRA.AbsoluteInternalPath != m_filePath)
            {
                s_defaultFileLocChoiceForSession = fileLocChoice;
            }

            m_picPreview.Image = null;
            m_currentImage.Dispose();
            m_currentImage = null;

            m_filePath = MoveOrCopyFilesController.PerformMoveCopyOrLeaveFile(m_filePath, m_txtDestination.Text, fileLocChoice);
            if (MoveOrCopyFilesController.FileIsInExternalLinksFolder(m_filePath, m_txtDestination.Text))
            {
                s_sExternalLinkDestinationDir = m_txtDestination.Text;
            }
        }
示例#3
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Handles the Click event of the m_btnMove control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
 /// ------------------------------------------------------------------------------------
 private void m_btnMove_Click(object sender, EventArgs e)
 {
     m_fCopyFiles      = false;
     m_fMoveFiles      = true;
     m_fLeaveFiles     = false;
     m_choice          = FileLocationChoice.Move;
     this.DialogResult = DialogResult.OK;
     this.Close();
 }
示例#4
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Handles the Click event of the m_btnCopy control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
		/// ------------------------------------------------------------------------------------
		private void m_btnCopy_Click(object sender, EventArgs e)
		{
			m_fCopyFiles = true;
			m_fMoveFiles = false;
			m_fLeaveFiles = false;
			m_choice = FileLocationChoice.Copy;
			this.DialogResult = DialogResult.OK;
			this.Close();
		}
示例#5
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Performs the action the user requested: move, copy, or leave the file.
        /// </summary>
        /// <param name="sFile">The fully-specified path name of the file.</param>
        /// <param name="sRootDir">The fully-specified path name of the new target directory.
        /// </param>
        /// <param name="action">the action the user chose (copy, move or leave)</param>
        /// <returns>The fully-specified path name of the (possibly newly moved or copied)
        /// file</returns>
        /// ------------------------------------------------------------------------------------
        internal static string PerformMoveCopyOrLeaveFile(string sFile, string sRootDir,
                                                          FileLocationChoice action)
        {
            if (action == FileLocationChoice.Leave)
            {
                return(sFile);                // use original location.
            }
            string sNewFile = Path.Combine(sRootDir, Path.GetFileName(sFile));

            if (File.Exists(sNewFile))
            {
                if (MessageBox.Show(String.Format(FwCoreDlgs.ksAlreadyExists, sNewFile),
                                    FwCoreDlgs.kstidWarning, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) ==
                    DialogResult.No)
                {
                    return(sFile);
                }
                try
                {
                    File.Delete(sNewFile);
                }
                catch
                {
                    MessageBox.Show(FwCoreDlgs.ksDeletePictureBeforeReplacingFile,
                                    FwCoreDlgs.ksCannotReplaceDisplayedPicture);
                    return(sNewFile);
                }
            }
            try
            {
                switch (action)
                {
                case FileLocationChoice.Move:
                    File.Move(sFile, sNewFile);
                    break;

                case FileLocationChoice.Copy:
                    File.Copy(sFile, sNewFile);
                    break;
                }
                return(sNewFile);
            }
            catch (Exception e)
            {
                string sAction = (action == FileLocationChoice.Copy ? "copy" : "mov");
                Logger.WriteEvent(
                    string.Format("Error {0}ing file '{1}' to '{2}'", sAction, sFile, sNewFile));

                Logger.WriteError(e);
                return(sFile);
            }
        }
示例#6
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Performs the action the user requested: move, copy, or leave the file.
		/// </summary>
		/// <param name="sFile">The fully-specified path name of the file.</param>
		/// <param name="sRootDir">The fully-specified path name of the new target directory.
		/// </param>
		/// <param name="action">the action the user chose (copy, move or leave)</param>
		/// <returns>The fully-specified path name of the (possibly newly moved or copied)
		/// file</returns>
		/// ------------------------------------------------------------------------------------
		internal static string PerformMoveCopyOrLeaveFile(string sFile, string sRootDir,
			 FileLocationChoice action)
		{
			if (action == FileLocationChoice.Leave)
				return sFile; // use original location.

			string sNewFile = Path.Combine(sRootDir, Path.GetFileName(sFile));
			if (File.Exists(sNewFile))
			{
				if (MessageBox.Show(String.Format(FwCoreDlgs.ksAlreadyExists, sNewFile),
					FwCoreDlgs.kstidWarning, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) ==
					DialogResult.No)
				{
					return sFile;
				}
				try
				{
					File.Delete(sNewFile);
				}
				catch
				{
					MessageBox.Show(FwCoreDlgs.ksDeletePictureBeforeReplacingFile,
						FwCoreDlgs.ksCannotReplaceDisplayedPicture);
					return sNewFile;
				}
			}
			try
			{
				switch (action)
				{
					case FileLocationChoice.Move:
						File.Move(sFile, sNewFile);
						break;
					case FileLocationChoice.Copy:
						File.Copy(sFile, sNewFile);
						break;
				}
				return sNewFile;
			}
			catch (Exception e)
			{
				string sAction = (action == FileLocationChoice.Copy ? "copy" : "mov");
				Logger.WriteEvent(
					string.Format("Error {0}ing file '{1}' to '{2}'", sAction, sFile, sNewFile));

				Logger.WriteError(e);
				return sFile;
			}
		}
示例#7
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Handles the Click event of the m_btnLeave control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
 /// ------------------------------------------------------------------------------------
 private void m_btnLeave_Click(object sender, EventArgs e)
 {
     m_choice     = FileLocationChoice.Leave;
     DialogResult = DialogResult.OK;
     Close();
 }
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Called when the user clicked the OK button and the File Location Options panel is
		/// visible.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		private void ApplyFileLocationOptions()
		{
			FileLocationChoice fileLocChoice;

			if (m_rbCopy.Checked)
				fileLocChoice = FileLocationChoice.Copy;
			else
			{
				fileLocChoice = (m_rbMove.Checked ?
					FileLocationChoice.Move : FileLocationChoice.Leave);
			}

			// If this dialog is being displayed for the purpose of inserting a new
			// picture or changing which picture is being displayed, remember the user's
			// copy/move/leave choice
			if (m_initialPicture == null || m_initialPicture.PictureFileRA.AbsoluteInternalPath != m_filePath)
				s_defaultFileLocChoiceForSession = fileLocChoice;

			m_picPreview.Image = null;
			m_currentImage.Dispose();
			m_currentImage = null;

			m_filePath = MoveOrCopyFilesDlg.PerformMoveCopyOrLeaveFile(m_filePath,
				m_txtDestination.Text, fileLocChoice);
			if (MoveOrCopyFilesDlg.FileIsInExternalLinksFolder(m_filePath, m_txtDestination.Text))
				s_sExternalLinkDestinationDir = m_txtDestination.Text;
		}
示例#9
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Handles the Click event of the m_btnLeave control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
		/// ------------------------------------------------------------------------------------
		private void m_btnLeave_Click(object sender, EventArgs e)
		{
			m_choice = FileLocationChoice.Leave;
			DialogResult = DialogResult.OK;
			Close();
		}