Copy() public method

Copies the specified sourceFileName to destFileName.
public Copy ( string sourceFileName, string destFileName, bool overwrite ) : void
sourceFileName string The file to copy.
destFileName string The name of the destination file.
overwrite bool true if the destination file can be overwritten, otherwise false.
return void
Beispiel #1
0
		/// <summary>
		/// Copies the source to the destination.
		/// </summary>
		/// <remarks>
		/// If the source is a directory, it is copied recursively.
		/// </remarks>
		/// <param name="p_tfmFileManager">The transactional file manager to use to copy the files.</param>
		/// <param name="p_strSource">The path from which to copy.</param>
		/// <param name="p_strDestination">The path to which to copy.</param>
		/// <param name="p_fncCopyCallback">A callback method that notifies the caller when a file has been copied,
		/// and provides the opportunity to cancel the copy operation.</param>
		/// <returns><c>true</c> if the copy operation wasn't cancelled; <c>false</c> otherwise.</returns>
		public static bool Copy(TxFileManager p_tfmFileManager, string p_strSource, string p_strDestination, Func<string, bool> p_fncCopyCallback)
		{
			if (File.Exists(p_strSource))
			{
				if (!Directory.Exists(Path.GetDirectoryName(p_strDestination)))
					p_tfmFileManager.CreateDirectory(Path.GetDirectoryName(p_strDestination));
				p_tfmFileManager.Copy(p_strSource, p_strDestination, true);
				if ((p_fncCopyCallback != null) && p_fncCopyCallback(p_strSource))
					return false;
			}
			else if (Directory.Exists(p_strSource))
			{
				if (!Directory.Exists(p_strDestination))
					p_tfmFileManager.CreateDirectory(p_strDestination);
				string[] strFiles = Directory.GetFiles(p_strSource);
				foreach (string strFile in strFiles)
				{
					p_tfmFileManager.Copy(strFile, Path.Combine(p_strDestination, Path.GetFileName(strFile)), true);
					if ((p_fncCopyCallback != null) && p_fncCopyCallback(strFile))
						return false;
				}
				string[] strDirectories = Directory.GetDirectories(p_strSource);
				foreach (string strDirectory in strDirectories)
					if (!Copy(strDirectory, Path.Combine(p_strDestination, Path.GetFileName(strDirectory)), p_fncCopyCallback))
						return false;
			}
			return true;
		}
Beispiel #2
0
        public void Export(int scanFileID, string userName, string computer, string comment = null)
        {
            //kontrola vstupnich parametru
            if (scanFileID == 0)
                throw new ArgumentException("Neplatný parametr identifikátor souboru.");

            if (String.IsNullOrEmpty(userName))
                throw new ArgumentException("Neplatný parametr jméno uživatele.");

            if (String.IsNullOrEmpty(computer))
                throw new ArgumentException("Neplatný parametr název počítače.");

            ScanFileRepository repository = new ScanFileRepository();

            //kontrola existence naskenovaneho souboru
            ScanFile result = repository.Select(scanFileID);
            if (result == null)
                throw new ApplicationException(String.Format("Soubor (ID={0}) neexistuje.", scanFileID));

            //kontrola ulozenych parametrov
            if (result.Status != StatusCode.Complete)
                throw new ApplicationException(String.Format("Soubor (ID={0}) nemá status dokončeno.", result.ScanFileID));

            //export ALEPH
            TxFileManager fileMgr = new TxFileManager();
            string filePath = null;
            string ftpPath = null;

            using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required))
            {
                try
                {
                    filePath = result.GetScanFilePath();

                    switch (result.PartOfBook)
                    {
                        case PartOfBook.FrontCover:
                            ftpPath = Path.Combine(result.Book.Catalogue.GetDirectoryFTP(true), result.FileName);
                            fileMgr.Copy(filePath, ftpPath, true);
                            break;

                        case PartOfBook.TableOfContents:
                            if (result.UseOCR)
                            {
                                string txtFilePath = Path.Combine(result.Book.Catalogue.GetDirectoryFTP(true), result.TxtFileName);
                                fileMgr.WriteAllText(txtFilePath, result.OcrText);
                            }

                            string pdfFilePath = result.GetOcrFilePath();
                            ftpPath = Path.Combine(result.Book.Catalogue.GetDirectoryFTP(true), result.OcrFileName);
                            fileMgr.Copy(pdfFilePath, ftpPath, true);
                            break;

                        default:
                            break;
                    }
                }
                catch (Exception ex)
                {
                    throw new ApplicationException(String.Format("Nepodařilo se exportovat soubor '{0}' na FTP: {1}.", filePath, ex.Message));
                }

                //ulozenie operace do databazy
                try
                {
                    result.Modified = DateTime.Now;
                    result.Comment = (comment != null ? comment.Left(1000) : null);
                    result.Status = StatusCode.Exported;
                    repository.Update(result);

                    LogOperation(result.ScanFileID, userName, computer, result.Modified, result.Comment, result.Status);

                    ts.Complete();
                }
                catch (Exception ex)
                {
                    throw new ApplicationException(String.Format("Nepodařilo se uložit data souboru (ID={0}) do databáze.", scanFileID), ex);
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// This performs the mirgration.
        /// </summary>
        /// <param name="p_objArgs">The path to the old FOMM installation.</param>
        protected void DoMigration(object p_objArgs)
        {
            string strOldFOMMLocation = (string)p_objArgs;
            TxFileManager tfmFileManager = new TxFileManager();

            //copy the mods
            //do we need to copy?
            #if TRACE
            Trace.Write("Copying Mods (");
            #endif
            if (!Path.Combine(strOldFOMMLocation, "mods").Equals(Program.GameMode.ModDirectory, StringComparison.InvariantCultureIgnoreCase))
            {
                List<string> lstModFiles = new List<string>();
                lstModFiles.AddRange(Directory.GetFiles(Path.Combine(strOldFOMMLocation, "mods"), "*.fomod"));
                lstModFiles.AddRange(Directory.GetFiles(Path.Combine(strOldFOMMLocation, "mods"), "*.xml"));
                m_bwdProgress.ItemMessage = "Copying mods...";
            #if TRACE
                Trace.WriteLine(lstModFiles.Count + "):");
                Trace.Indent();
            #endif
                m_bwdProgress.ItemProgressMaximum = lstModFiles.Count;
                m_bwdProgress.ItemProgress = 0;
                string strModFileName = null;
                foreach (string strMod in lstModFiles)
                {
                    strModFileName = Path.GetFileName(strMod);
                    m_bwdProgress.ItemMessage = "Copying mods (" + strModFileName + ")...";
            #if TRACE
                    Trace.WriteLine(strMod + " => " + Path.Combine(Program.GameMode.ModDirectory, strModFileName));
            #endif
                    tfmFileManager.Copy(strMod, Path.Combine(Program.GameMode.ModDirectory, strModFileName), true);
                    //File.Copy(strMod, Path.Combine(Program.GameMode.ModDirectory, Path.GetFileName(strMod)));
                    m_bwdProgress.StepItemProgress();
                    if (m_bwdProgress.Cancelled())
                    {
            #if TRACE
                        Trace.Unindent();
                        Trace.WriteLine("Cancelled copying Mods.");
            #endif
                        return;
                    }
                }
            }
            #if TRACE
            else
            {
                Trace.WriteLine("No Need).");
            }
            Trace.Unindent();
            Trace.WriteLine("Done copying Mods.");
            #endif

            m_bwdProgress.StepOverallProgress();

            //copy overwrites folder
            //do we need to?
            #if TRACE
            Trace.WriteLine("Copying overwrite files (");
            #endif
            if (!Path.Combine(strOldFOMMLocation, "overwrites").Equals(((Fallout3GameMode)Program.GameMode).OverwriteDirectory, StringComparison.InvariantCultureIgnoreCase))
            {
                string[] strOverwriteFiles = Directory.GetFiles(Path.Combine(strOldFOMMLocation, "overwrites"), "*.*", SearchOption.AllDirectories);
                m_bwdProgress.ItemMessage = "Copying overwrites...";
                m_bwdProgress.ItemProgressMaximum = strOverwriteFiles.Length;
                m_bwdProgress.ItemProgress = 0;
            #if TRACE
                Trace.WriteLine(strOverwriteFiles.Length + "):");
                Trace.Indent();
            #endif
                FileUtil.Copy(tfmFileManager, Path.Combine(strOldFOMMLocation, "overwrites"), ((Fallout3GameMode)Program.GameMode).OverwriteDirectory, OverwriteFileCopied);
            }
            #if TRACE
            else
            {
                Trace.WriteLine("No Need).");
            }
            Trace.Unindent();
            Trace.WriteLine("Done copying overwrite files.");
            #endif

            m_bwdProgress.StepOverallProgress();

            //copy install logs
            //do we need to?
            #if TRACE
            Trace.WriteLine("Copying install logs (");
            #endif
            if (!Path.Combine(strOldFOMMLocation, "fomm").Equals(Program.GameMode.InstallInfoDirectory, StringComparison.InvariantCultureIgnoreCase))
            {
                string[] strMiscFiles = Directory.GetFiles(Path.Combine(strOldFOMMLocation, "fomm"), "InstallLog.xml*");
                m_bwdProgress.ItemMessage = "Copying info files...";
                m_bwdProgress.ItemProgressMaximum = strMiscFiles.Length;
                m_bwdProgress.ItemProgress = 0;
            #if TRACE
                Trace.WriteLine(strMiscFiles.Length + "):");
                Trace.Indent();
            #endif
                foreach (string strFile in strMiscFiles)
                {
            #if TRACE
                    Trace.WriteLine(strFile + " => " + Path.Combine(Program.GameMode.InstallInfoDirectory, Path.GetFileName(strFile)));
            #endif
                    tfmFileManager.Copy(strFile, Path.Combine(Program.GameMode.InstallInfoDirectory, Path.GetFileName(strFile)), true);
                    m_bwdProgress.StepItemProgress();
                    if (m_bwdProgress.Cancelled())
                    {
            #if TRACE
                        Trace.Unindent();
                        Trace.WriteLine("Cancelled copying install logs.");
            #endif
                        return;
                    }
                }
            }
            #if TRACE
            else
            {
                Trace.WriteLine("No Need).");
            }
            Trace.Unindent();
            Trace.WriteLine("Done copying install logs.");
            #endif

            m_bwdProgress.StepOverallProgress();
        }
Beispiel #4
0
    /// <summary>
    ///   This performs the mirgration.
    /// </summary>
    /// <param name="p_objArgs">The path to the old FOMM installation.</param>
    protected void DoMigration(object p_objArgs)
    {
      var strOldFOMMLocation = (string) p_objArgs;
      var tfmFileManager = new TxFileManager();

      //copy the mods
      //do we need to copy?
      if (
        !Path.Combine(strOldFOMMLocation, "mods")
             .Equals(Program.GameMode.ModDirectory, StringComparison.InvariantCultureIgnoreCase))
      {
        var lstModFiles = new List<string>();
        lstModFiles.AddRange(Directory.GetFiles(Path.Combine(strOldFOMMLocation, "mods"), "*.fomod"));
        lstModFiles.AddRange(Directory.GetFiles(Path.Combine(strOldFOMMLocation, "mods"), "*.xml"));
        m_bwdProgress.ItemMessage = "Copying mods...";
        m_bwdProgress.ItemProgressMaximum = lstModFiles.Count;
        m_bwdProgress.ItemProgress = 0;
        foreach (var strMod in lstModFiles)
        {
          var strModFileName = Path.GetFileName(strMod);
          m_bwdProgress.ItemMessage = "Copying mods (" + strModFileName + ")...";
          tfmFileManager.Copy(strMod, Path.Combine(Program.GameMode.ModDirectory, strModFileName), true);
          //File.Copy(strMod, Path.Combine(Program.GameMode.ModDirectory, Path.GetFileName(strMod)));
          m_bwdProgress.StepItemProgress();
          if (m_bwdProgress.Cancelled())
          {
            return;
          }
        }
      }

      m_bwdProgress.StepOverallProgress();

      //copy overwrites folder
      //do we need to?
      if (
        !Path.Combine(strOldFOMMLocation, "overwrites")
             .Equals(Program.GameMode.OverwriteDirectory,
                     StringComparison.InvariantCultureIgnoreCase))
      {
        var strOverwriteFiles = Directory.GetFiles(Path.Combine(strOldFOMMLocation, "overwrites"), "*.*",
                                                   SearchOption.AllDirectories);
        m_bwdProgress.ItemMessage = "Copying overwrites...";
        m_bwdProgress.ItemProgressMaximum = strOverwriteFiles.Length;
        m_bwdProgress.ItemProgress = 0;
        FileUtil.Copy(tfmFileManager, Path.Combine(strOldFOMMLocation, "overwrites"),
                      Program.GameMode.OverwriteDirectory, OverwriteFileCopied);
      }

      m_bwdProgress.StepOverallProgress();

      //copy install logs
      //do we need to?
      if (
        !Path.Combine(strOldFOMMLocation, "fomm")
             .Equals(Program.GameMode.InstallInfoDirectory, StringComparison.InvariantCultureIgnoreCase))
      {
        var strMiscFiles = Directory.GetFiles(Path.Combine(strOldFOMMLocation, "fomm"), "InstallLog.xml*");
        m_bwdProgress.ItemMessage = "Copying info files...";
        m_bwdProgress.ItemProgressMaximum = strMiscFiles.Length;
        m_bwdProgress.ItemProgress = 0;
        foreach (var strFile in strMiscFiles)
        {
          tfmFileManager.Copy(strFile, Path.Combine(Program.GameMode.InstallInfoDirectory, Path.GetFileName(strFile)),
                              true);
          m_bwdProgress.StepItemProgress();
          if (m_bwdProgress.Cancelled())
          {
            return;
          }
        }
      }

      m_bwdProgress.StepOverallProgress();
    }