Exemplo n.º 1
0
        private static void UpdateSubDirectories(string sourceDirectory, string destinationDirectory)
        {
            Tracing.Tracer.LogText("Update sub directories from '{0}' to '{1}'", sourceDirectory, destinationDirectory);
            string[] sourceSubDirectories = Directory.GetDirectories(sourceDirectory);

            // Custom code
            List <string> updatedDestinationSubDirectories = new List <string>();

            foreach (string sourceSubDirectory in sourceSubDirectories)
            {
                string destinationSubDirectory = destinationDirectory + new DirectoryInfo(sourceSubDirectory).Name;
                if (!Directory.Exists(destinationSubDirectory))
                {
                    Directory.CreateDirectory(destinationSubDirectory);
                    Tracing.Tracer.LogText("Directory '{0}' was created.", destinationSubDirectory);
                }
                CopyNewVersion(sourceSubDirectory, destinationSubDirectory);

                // Custom code
                updatedDestinationSubDirectories.Add(destinationSubDirectory);
            }

            // Custom code
            if (UpdaterHelper.DeleteExistingFiles)
            {
                UpdaterHelper.RemoveNotUpdatedDestinationSubDirectories(updatedDestinationSubDirectories.ToArray(), destinationDirectory);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Remove the folders that were not updated, but ignore the ones specified in app.config settings (IgnoredFolders).
        /// </summary>
        public static void RemoveNotUpdatedDestinationSubDirectories(string[] updatedDestinationSubDirectories, string destinationDirectory)
        {
            if (string.IsNullOrEmpty(destinationDirectory) || updatedDestinationSubDirectories == null)
            {
                return;
            }
            string[] destinationSubDirectories        = Directory.GetDirectories(destinationDirectory);
            string[] missingDestinationSubDirectories = destinationSubDirectories.Except(updatedDestinationSubDirectories).ToArray();
            foreach (string missingDestinationSubDirectory in missingDestinationSubDirectories)
            {
                if (UpdaterHelper.IsFolderIgnored(missingDestinationSubDirectory))
                {
                    continue;
                }

                try
                {
                    if (Directory.Exists(missingDestinationSubDirectory))
                    {
                        Directory.Delete(missingDestinationSubDirectory, true);
                        Tracing.Tracer.LogText("The \"{0}\" folder was deleted.", missingDestinationSubDirectory);
                    }
                }
                catch (Exception ex)
                {
                    Tracing.Tracer.LogWarning("Error while deleting the \"{0}\" folder: \"{1}\".", missingDestinationSubDirectory, ex.Message);
                }
            }
        }
Exemplo n.º 3
0
        private static void CopyNewVersion(string sourceDirectory, string destinationDirectory)
        {
            if (Directory.Exists(destinationDirectory))
            {
                // Custom code
                if (UpdaterHelper.IsFolderIgnored(destinationDirectory))
                {
                    return;
                }
                List <string> updatedDestinationFiles = new List <string>();
                Application.DoEvents();

                Tracing.Tracer.LogText("CopyNewVersion from '{0}' to '{1}'", sourceDirectory, destinationDirectory);
                string[]             sourceFiles = Directory.GetFiles(sourceDirectory, "*.*");
                ICollection <string> selfFiles   = GetSelfFiles(sourceDirectory);
                foreach (string sourceFileName in sourceFiles)
                {
                    if (!selfFiles.Contains(sourceFileName) && !UpdaterHelper.IsFileIgnored(sourceFileName))                       // Custom code
                    {
                        string destinationFileName = Path.Combine(destinationDirectory, Path.GetFileName(sourceFileName));
                        if (File.Exists(destinationFileName))
                        {
                            File.SetAttributes(destinationFileName, FileAttributes.Normal);
                        }

                        // Custom code (do not copy unchanged files)
                        Application.DoEvents();
                        DateTime sourceFileModified = File.GetLastWriteTime(sourceFileName);
                        DateTime destFileModified   = DateTime.MinValue;
                        if (File.Exists(destinationFileName))
                        {
                            destFileModified = File.GetLastWriteTime(destinationFileName);
                        }
                        if (sourceFileModified == destFileModified)
                        {
                            form.SetProgressPosition();
                            updatedDestinationFiles.Add(destinationFileName);
                            continue;
                        }

                        File.Copy(sourceFileName, destinationFileName, true);
                        Tracing.Tracer.LogText("The \"{0}\" file was copied to \"{1}\".", sourceFileName, destinationFileName);
                        form.SetProgressPosition();

                        // Custom code
                        updatedDestinationFiles.Add(destinationFileName);
                    }
                }

                // Custom code
                if (UpdaterHelper.DeleteExistingFiles)
                {
                    UpdaterHelper.RemoveNotUpdatedDestinationFiles(destinationDirectory, updatedDestinationFiles);
                }

                UpdateSubDirectories(sourceDirectory, destinationDirectory);
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// Remove the files that were not updated, but ignore the folders and files specified in app.config settings (IgnoredFolders & IgnoredFilePatterns).
 /// </summary>
 public static void RemoveNotUpdatedDestinationFiles(string destinationDirectory, List <string> updatedDestinationFiles)
 {
     //string[] destinationFiles = Directory.GetFiles(sourceDirectory, "DevExpress.*.dll|DevExpress.*.xml");
     string[] destinationFiles           = Directory.GetFiles(destinationDirectory, "*.*");
     string[] additionalDestinationFiles = destinationFiles.Except(updatedDestinationFiles).ToArray();
     foreach (string additionalDestinationFilePath in additionalDestinationFiles)
     {
         if (!UpdaterHelper.IsFileIgnored(additionalDestinationFilePath))
         {
             try
             {
                 if (File.Exists(additionalDestinationFilePath))
                 {
                     File.Delete(additionalDestinationFilePath);
                     Tracing.Tracer.LogText("The \"{0}\" file was deleted.", additionalDestinationFilePath);
                 }
             }
             catch (Exception ex)
             {
                 Tracing.Tracer.LogWarning("Error while deleting the \"{0}\" file: \"{1}\".", additionalDestinationFilePath, ex.Message);
             }
         }
     }
 }