Example #1
0
 public static bool SafeDeleteFile(string file)
 {
     try
     {
         return(DeleteFile(file));
     }
     catch
     {
         LogFile.AddVerboseLine("ERROR: Unable to remove file: <" + file + ">");
         return(false);
     }
 }
Example #2
0
 public static void SafeFileCopyWithLogging(string inName, string outName, bool overwrite)
 {
     try
     {
         FileCopyWithLogging(inName, outName, overwrite);
     }
     catch
     {
         LogFile.AddVerboseLine("ERROR  : unable to copy <" + inName + "> to <" + outName +
                                "> <" + overwrite.ToString() + ">");
     }
 }
Example #3
0
 public static void FileCopyWithLogging(string inName, string outName, bool overwrite)
 {
     System.IO.FileInfo fi = new System.IO.FileInfo(inName);
     if (fi.Length > 0)
     {
         if (LogFile.IsLogging())
         {
             LogFile.AddVerboseLine("Copying: <" + inName + "> to <" + outName +
                                    "> <" + overwrite.ToString() + ">");
         }
         File.Copy(inName, outName, overwrite);
     }
     else
     {
         LogFile.AddVerboseLine("Not Copying (Zero size): <" + inName + "> to <" + outName +
                                "> <" + overwrite.ToString() + ">");
     }
 }
Example #4
0
        /// <summary>
        /// </summary>
        public static bool DeleteFile(string file)
        {
            bool rval = false;

            if (File.Exists(file))
            {
                File.SetAttributes(file, FileAttributes.Normal);
                File.Delete(file);
                rval = true;
                if (LogFile.IsLogging())
                {
                    LogFile.AddVerboseLine("Removed file:<" + file + ">");
                }
            }
            else
            {
                if (LogFile.IsLogging())
                {
                    LogFile.AddVerboseLine("Tried to delete file that didn't exist:<" + file + ">");
                }
            }
            return(rval);
        }
Example #5
0
        /// <summary>
        /// Create the "original" (backup) copy of the file to be modified,
        /// if it doesn't already exist.
        /// </summary>
        /// <param name="inputFilespec">This is the file to make a copy of.</param>
        public static void BackupOrig(string inputFilespec)
        {
            if (!File.Exists(inputFilespec))
            {
                LogFile.AddVerboseLine("No Orig to back up: <" + inputFilespec);
                return;
            }

            string outputFilespec = CreateNewFileName(inputFilespec, original);

            if (!File.Exists(outputFilespec))
            {
                try
                {
                    FileCopyWithLogging(inputFilespec, outputFilespec, true);
                }
                catch
                {
                    LogFile.AddErrorLine("Error creating " + original + " copy: " + inputFilespec);
                    throw new LDExceptions(ErrorCodes.FileWrite);
                }
            }
        }