/// <summary> /// Copies Source folder and its contents to Destination folder. /// </summary> static private void CopyFolder(DirectoryInfo Source, DirectoryInfo Destination, bool Overwrite = true) { if (!Source.Exists) { return; } DirectoryInfo[] SourceSubFolders = Source.GetDirectories(); FileInfo[] SourceFiles = Source.GetFiles(); if (!Destination.Exists) { Destination.Create(); } foreach (DirectoryInfo SourceSubFolder in SourceSubFolders) { CopyFolder(SourceSubFolder, new DirectoryInfo(Path.Combine(Destination.FullName, SourceSubFolder.Name)), Overwrite); } foreach (FileInfo SourceFile in SourceFiles) { SourceFile.CopyTo(Path.Combine(Destination.FullName, SourceFile.Name), Overwrite); } }
private bool CopyAll(DirectoryInfo Source, DirectoryInfo Target) { try { if (Token.IsCancellationRequested) { return(false); } Directory.CreateDirectory(Target.FullName); // Copy each file into the new directory. foreach (FileInfo SourceFile in Source.GetFiles()) { Logger.Info(string.Format(@"Copying file to {0}{1}\{2}", Address, Target.FullName, SourceFile.Name)); SourceFile.CopyTo(Path.Combine(Target.FullName, SourceFile.Name), true); if (Token.IsCancellationRequested) { return(false); } Callback.OnFileDeployed(this, SourceFile.FullName); } // Copy each subdirectory using recursion. foreach (DirectoryInfo diSourceSubDir in Source.GetDirectories()) { DirectoryInfo nextTargetSubDir = Target.CreateSubdirectory(diSourceSubDir.Name); if (!CopyAll(diSourceSubDir, nextTargetSubDir)) { return(false); } } return(true); } catch (Exception e) { Logger.Error(string.Format("Failed to copy files from source {0} to destination {1}. {0}", Source.FullName, Target.FullName, e.Message)); } return(false); }
/// <summary> /// Copy a Directory, SubDirectories and Files Given a Source and Destination DirectoryInfo /// Object, Given a SubDirectory Filter and a File Filter. /// IMPORTANT: The search strings for SubDirectories and Files applies to every Folder and /// File within the Source Directory. /// <param name="SourceDirectory">A DirectoryInfo Object Pointing to the Source Directory</param> /// <param name="DestinationDirectory">A DirectoryInfo Object Pointing to the Destination Directory</param> /// <param name="SourceDirectoryFilter">Search String on SubDirectories (Example: "System*" will return /// all subdirectories starting with "System")</param> /// <param name="SourceFileFilter">File Filter: Standard DOS-Style Format (Examples: "*.txt" or "*.exe")</param> /// <param name="Overwrite">Whether or not to Overwrite Copied Files in the Destination Directory</param> /// </summary> public static void Copy(DirectoryInfo SourceDirectory, DirectoryInfo DestinationDirectory, string SourceDirectoryFilter, string SourceFileFilter, bool Overwrite) { DirectoryInfo[] SourceSubDirectories; FileInfo[] SourceFiles; //Check for File Filter if (SourceFileFilter != null) { SourceFiles = SourceDirectory.GetFiles(SourceFileFilter.Trim()); } else { SourceFiles = SourceDirectory.GetFiles(); } // Check for Folder Filter if (SourceDirectoryFilter != null) { SourceSubDirectories = SourceDirectory.GetDirectories(SourceDirectoryFilter.Trim()); } else { SourceSubDirectories = SourceDirectory.GetDirectories(); } // Create the Destination Directory if (!DestinationDirectory.Exists) { DestinationDirectory.Create(); } // Recursively Copy Every SubDirectory and it's Contents (according to folder filter) foreach (DirectoryInfo SourceSubDirectory in SourceSubDirectories) { Copy(SourceSubDirectory, new DirectoryInfo(DestinationDirectory.FullName + @"\" + SourceSubDirectory.Name), SourceDirectoryFilter, SourceFileFilter, Overwrite); } //Copy Every File to Destination Directory (according to file filter) foreach (FileInfo SourceFile in SourceFiles) { SourceFile.CopyTo(DestinationDirectory.FullName + @"\" + SourceFile.Name, Overwrite); } }
/// <summary> /// Copy the source file to the target file /// </summary> public void CopyToTargetNow() { if (Copied) { return; } SourceFile.CopyTo(TargetFile.FullName, true); // ReSharper disable once ConditionIsAlwaysTrueOrFalse if (TestLinuxSystemInfo.SHOW_TRACE_MESSAGES) #pragma warning disable 162 { Console.WriteLine("{0:HH:mm:ss.fff}: Copied file from {1} to {2}", DateTime.Now, SourceFile.FullName, TargetFile.FullName); } #pragma warning restore 162 Copied = true; }
public static void CopyDirectory(DirectoryInfo sourceDirectory, DirectoryInfo targetDirectory) { if (!Directory.Exists(targetDirectory.FullName)) { Directory.CreateDirectory(targetDirectory.FullName); } foreach (FileInfo SourceFile in sourceDirectory.GetFiles()) { string f = Path.Combine(targetDirectory.FullName, SourceFile.Name); if (!File.Exists(f)) { SourceFile.CopyTo(f, false); } } foreach (DirectoryInfo SourceSubDir in sourceDirectory.GetDirectories()) { DirectoryInfo TargetDir = targetDirectory.CreateSubdirectory(SourceSubDir.Name); CopyDirectory(SourceSubDir, TargetDir); } }
public Dictionary <string, double> Backup(string SourcePath, string DestinationPath, bool Recurse = false) //Need to add error handling { if (SourcePath == DestinationPath) { throw new ArgumentException("Source and Destination can't be the same."); } Stopwatch StopWatch = new Stopwatch(); StopWatch.Reset(); StopWatch.Start(); try { if (!Support.CheckPath(SourcePath, PathType.Directory)) { logger.WriteToLogFile("Source Folder does not exist", Severity.Error); throw new ArgumentException("Source Folder does not exist"); } } catch { throw; } try { if (!Support.CheckPath(DestinationPath, PathType.Directory)) { try { Support.CreateFolder(DestinationPath); logger.WriteToLogFile("Created Destination Folder: " + DestinationPath, Severity.Info); } catch { logger.WriteToLogFile("Unable to create destination folder. Issue may be a typo in path, or improper permissions", Severity.Error); throw; } } } catch { throw; } string DestinationSubFolderPath = BuildDestinationSubFolderPath(SourcePath, DestinationPath); try { if (!Support.CheckPath(DestinationSubFolderPath, PathType.Directory)) { try { Support.CreateFolder(DestinationSubFolderPath); logger.WriteToLogFile("Created Destination Sub-Folder: " + DestinationSubFolderPath, Severity.Info); } catch { logger.WriteToLogFile("Unable to create destination source subfolder: " + DestinationSubFolderPath + " . Issue may be a typo in path, or improper permissions", Severity.Error); throw; } } } catch { throw; } DirectoryInfo SourceDirectory = new DirectoryInfo(SourcePath); FileInfo[] SourceFiles = SourceDirectory.GetFiles(); try { foreach (FileInfo SourceFile in SourceFiles) { string DestinationFilePath = Path.Combine(DestinationSubFolderPath, SourceFile.Name); if (File.Exists(DestinationFilePath)) { FileInfo ExistingFileInDestination = new FileInfo(DestinationFilePath); if (ExistingFileInDestination.LastWriteTime < SourceFile.LastWriteTime) { SourceFile.CopyTo(DestinationFilePath, true); fileCount++; totalCopySize += SourceFile.Length; netCopySize += SourceFile.Length - ExistingFileInDestination.Length; } } else { SourceFile.CopyTo(DestinationFilePath, true); fileCount++; totalCopySize += SourceFile.Length; netCopySize += SourceFile.Length; } } } catch (Exception EX) { logger.WriteToLogFile("There was an issue with the backup between: " + SourcePath + " and " + DestinationPath + ". The Exception thrown is: " + EX.Message, Severity.Critical); } stopWatchTime += StopWatch.ElapsedMilliseconds; try { DirectoryInfo[] ChildSourceDirectories = SourceDirectory.GetDirectories(); foreach (DirectoryInfo ChildSourceDirectory in ChildSourceDirectories) { Backup(ChildSourceDirectory.FullName, DestinationSubFolderPath, true); } } catch (Exception EX) { logger.WriteToLogFile("There was an issue getting the sub directories of: " + SourceDirectory.FullName + ". The Exception thrown is: " + EX.Message, Severity.Critical); throw EX; } if (Recurse == false) { if (fileCount == 0) { logger.WriteToLogFile("Successful check, all files are in sync between: " + SourcePath + " and " + DestinationPath, Severity.Info); return(Support.TimeConverter(stopWatchTime)); } else { string LogMsg = "Succesfully copied:" + fileCount.ToString() + " files from: " + SourcePath + " to: " + DestinationSubFolderPath + " for a Total Size: " + totalCopySize.ToString() + " and Net Size: " + netCopySize.ToString() + " In: " + stopWatchTime.ToString() + "ms"; logger.WriteToLogFile(LogMsg, Severity.Info); fileCount = 0; totalCopySize = 0; netCopySize = 0; return(Support.TimeConverter(stopWatchTime)); } } return(Support.TimeConverter(stopWatchTime)); }
/// <summary> /// /// </summary> /// <param name="ProjectFile"></param> /// <param name="Executable"></param> /// <param name="StageDirectory"></param> /// <param name="PlatformType"></param> public static void GenerateAssetCatalog(FileReference ProjectFile, string Executable, string StageDirectory, UnrealTargetPlatform PlatformType) { // Initialize the toolchain. IOSProjectSettings ProjectSettings = ((IOSPlatform)UEBuildPlatform.GetBuildPlatform(PlatformType)).ReadProjectSettings(null); IOSToolChain ToolChain = new IOSToolChain(ProjectFile, ProjectSettings); // Determine whether the user has modified icons that require a remote Mac to build. CppPlatform Platform = PlatformType == UnrealTargetPlatform.IOS ? CppPlatform.IOS : CppPlatform.TVOS; bool bUserImagesExist = false; ToolChain.GenerateAssetCatalog(Platform, ref bUserImagesExist); // Don't attempt to do anything remotely if the user is using the default UE4 images. if (!bUserImagesExist) { return; } // Also don't attempt to use a remote Mac if packaging for TVOS on PC. if (Platform == CppPlatform.TVOS && BuildHostPlatform.Current.Platform != UnrealTargetPlatform.Mac) { return; } // Save off the current bUseRPCUtil setting to restore at the end of this function. // At this time, iPhonePackager needs to be called with bUseRPCUtil == true. bool bSaveUseRPCUtil = RemoteToolChain.bUseRPCUtil; // Initialize the remote calling environment, taking into account the user's SSH setting. ToolChain.SetUpGlobalEnvironment(false); // Build the asset catalog ActionGraph. ActionGraph ActionGraph = new ActionGraph(); List <FileItem> OutputFiles = new List <FileItem>(); ToolChain.CompileAssetCatalog(FileItem.GetItemByPath(Executable), Platform, ActionGraph, OutputFiles); ActionGraph.FinalizeActionGraph(); // I'm not sure how to derive the UE4Game and Development arguments programmatically. string[] Arguments = new string[] { "UE4Game", (PlatformType == UnrealTargetPlatform.IOS ? "IOS" : "TVOS"), "Development", "-UniqueBuildEnvironment" }; // Perform all of the setup necessary to actually execute the ActionGraph instance. ReadOnlyBuildVersion Version = new ReadOnlyBuildVersion(BuildVersion.ReadDefault()); List <string[]> TargetSettings = new List <string[]>(); TargetSettings.Add(Arguments); var Targets = new List <UEBuildTarget>(); Dictionary <UEBuildTarget, CPPHeaders> TargetToHeaders = new Dictionary <UEBuildTarget, CPPHeaders>(); List <TargetDescriptor> TargetDescs = new List <TargetDescriptor>(); foreach (string[] TargetSetting in TargetSettings) { TargetDescs.AddRange(TargetDescriptor.ParseCommandLine(TargetSetting, ref ProjectFile)); } foreach (TargetDescriptor TargetDesc in TargetDescs) { UEBuildTarget Target = UEBuildTarget.CreateTarget(TargetDesc, Arguments, false, Version); if (Target == null) { continue; } Targets.Add(Target); TargetToHeaders.Add(Target, null); } bool bIsRemoteCompile = BuildHostPlatform.Current.Platform != UnrealTargetPlatform.Mac; // Create the build configuration object, and read the settings BuildConfiguration BuildConfiguration = new BuildConfiguration(); XmlConfig.ApplyTo(BuildConfiguration); CommandLine.ParseArguments(Arguments, BuildConfiguration); BuildConfiguration.bUseUBTMakefiles = false; Action[] PrerequisiteActions; { HashSet <Action> PrerequisiteActionsSet = new HashSet <Action>(); foreach (FileItem OutputFile in OutputFiles) { ActionGraph.GatherPrerequisiteActions(OutputFile, ref PrerequisiteActionsSet); } PrerequisiteActions = PrerequisiteActionsSet.ToArray(); } // Copy any asset catalog files to the remote Mac, if necessary. foreach (UEBuildTarget Target in Targets) { UEBuildPlatform.GetBuildPlatform(Target.Platform).PreBuildSync(); } // Begin execution of the ActionGraph. Dictionary <UEBuildTarget, List <FileItem> > TargetToOutdatedPrerequisitesMap; List <Action> ActionsToExecute = ActionGraph.GetActionsToExecute(BuildConfiguration, PrerequisiteActions, Targets, TargetToHeaders, true, true, out TargetToOutdatedPrerequisitesMap); string ExecutorName = "Unknown"; bool bSuccess = ActionGraph.ExecuteActions(BuildConfiguration, ActionsToExecute, bIsRemoteCompile, out ExecutorName, "", EHotReload.Disabled); if (bSuccess) { if (bIsRemoteCompile) { // Copy the remotely built AssetCatalog directory locally. foreach (FileItem OutputFile in OutputFiles) { string RemoteDirectory = System.IO.Path.GetDirectoryName(OutputFile.AbsolutePath).Replace("\\", "/"); FileItem LocalExecutable = ToolChain.RemoteToLocalFileItem(FileItem.GetItemByPath(Executable)); string LocalDirectory = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(LocalExecutable.AbsolutePath), "AssetCatalog"); LocalDirectory = StageDirectory; RPCUtilHelper.CopyDirectory(RemoteDirectory, LocalDirectory, RPCUtilHelper.ECopyOptions.DoNotReplace); } } else { // Copy the built AssetCatalog directory to the StageDirectory. foreach (FileItem OutputFile in OutputFiles) { string SourceDirectory = System.IO.Path.GetDirectoryName(OutputFile.AbsolutePath).Replace("\\", "/"); System.IO.DirectoryInfo SourceDirectoryInfo = new System.IO.DirectoryInfo(SourceDirectory); if (!System.IO.Directory.Exists(StageDirectory)) { System.IO.Directory.CreateDirectory(StageDirectory); } System.IO.FileInfo[] SourceFiles = SourceDirectoryInfo.GetFiles(); foreach (System.IO.FileInfo SourceFile in SourceFiles) { string DestinationPath = System.IO.Path.Combine(StageDirectory, SourceFile.Name); SourceFile.CopyTo(DestinationPath, true); } } } } // Restore the former bUseRPCUtil setting. RemoteToolChain.bUseRPCUtil = bSaveUseRPCUtil; }
public override void Perform() { SourceFile.CopyTo(DestinationFile.FullName, false); }