本文整理汇总了C#中FileReference.Exists方法的典型用法代码示例。如果您正苦于以下问题:C# FileReference.Exists方法的具体用法?C# FileReference.Exists怎么用?C# FileReference.Exists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileReference
的用法示例。
在下文中一共展示了FileReference.Exists方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateIntermediateTextFile
/// <summary>
/// Creates a text file with the given contents. If the contents of the text file aren't changed, it won't write the new contents to
/// the file to avoid causing an action to be considered outdated.
/// </summary>
public static FileItem CreateIntermediateTextFile(FileReference AbsolutePath, string Contents)
{
// Create the directory if it doesn't exist.
Directory.CreateDirectory(Path.GetDirectoryName(AbsolutePath.FullName));
// Only write the file if its contents have changed.
if (!AbsolutePath.Exists() || !String.Equals(Utils.ReadAllText(AbsolutePath.FullName), Contents, StringComparison.InvariantCultureIgnoreCase))
{
File.WriteAllText(AbsolutePath.FullName, Contents, GetEncodingForString(Contents));
}
return GetItemByFileReference(AbsolutePath);
}
示例2: Execute
/// <summary>
/// Execute the task.
/// </summary>
/// <param name="Job">Information about the current job</param>
/// <param name="BuildProducts">Set of build products produced by this node.</param>
/// <param name="TagNameToFileSet">Mapping from tag names to the set of files they include</param>
/// <returns>True if the task succeeded</returns>
public override bool Execute(JobContext Job, HashSet<FileReference> BuildProducts, Dictionary<string, HashSet<FileReference>> TagNameToFileSet)
{
// Figure out the project that this target belongs to
FileReference ProjectFile = null;
if(Parameters.Project != null)
{
ProjectFile = new FileReference(Parameters.Project);
if(!ProjectFile.Exists())
{
CommandUtils.LogError("Missing project file - {0}", ProjectFile.FullName);
return false;
}
}
// Execute the cooker
using(TelemetryStopwatch CookStopwatch = new TelemetryStopwatch("Cook.{0}.{1}", (ProjectFile == null)? "UE4" : ProjectFile.GetFileNameWithoutExtension(), Parameters.Platform))
{
string[] Maps = (Parameters.Maps == null)? null : Parameters.Maps.Split(new char[]{ '+' });
string Arguments = (Parameters.Versioned ? "" : "-Unversioned ") + "-LogCmds=\"LogSavePackage Warning\" " + Parameters.Arguments;
CommandUtils.CookCommandlet(ProjectFile, "UE4Editor-Cmd.exe", Maps, null, null, null, Parameters.Platform, Arguments);
}
// Find all the cooked files
List<FileReference> CookedFiles = new List<FileReference>();
foreach(string Platform in Parameters.Platform.Split('+'))
{
DirectoryReference PlatformCookedDirectory = DirectoryReference.Combine(ProjectFile.Directory, "Saved", "Cooked", Platform);
if(!PlatformCookedDirectory.Exists())
{
CommandUtils.LogError("Cook output directory not found ({0})", PlatformCookedDirectory.FullName);
return false;
}
List<FileReference> PlatformCookedFiles = PlatformCookedDirectory.EnumerateFileReferences("*", System.IO.SearchOption.AllDirectories).ToList();
if(PlatformCookedFiles.Count == 0)
{
CommandUtils.LogError("Cooking did not produce any files in {0}", PlatformCookedDirectory.FullName);
return false;
}
CookedFiles.AddRange(PlatformCookedFiles);
}
// Apply the optional tag to the build products
foreach(string TagName in FindTagNamesFromList(Parameters.Tag))
{
FindOrAddTagSet(TagNameToFileSet, TagName).UnionWith(CookedFiles);
}
// Add them to the set of build products
BuildProducts.UnionWith(CookedFiles);
return true;
}
示例3: Create
/// <summary>
/// Creates and deserializes the dependency cache at the passed in location
/// </summary>
/// <param name="CachePath">Name of the cache file to deserialize</param>
public static DependencyCache Create(FileReference CacheFile)
{
// See whether the cache file exists.
if (CacheFile.Exists())
{
if (BuildConfiguration.bPrintPerformanceInfo)
{
Log.TraceInformation("Loading existing IncludeFileCache: " + CacheFile.FullName);
}
DateTime TimerStartTime = DateTime.UtcNow;
// Deserialize cache from disk if there is one.
DependencyCache Result = Load(CacheFile);
if (Result != null)
{
// Successfully serialize, create the transient variables and return cache.
Result.UpdateTimeUtc = DateTime.UtcNow;
TimeSpan TimerDuration = DateTime.UtcNow - TimerStartTime;
if (BuildConfiguration.bPrintPerformanceInfo)
{
Log.TraceInformation("Loading IncludeFileCache took " + TimerDuration.TotalSeconds + "s");
}
return Result;
}
}
// Fall back to a clean cache on error or non-existance.
return new DependencyCache(CacheFile);
}
示例4: ExecuteBuild
public override void ExecuteBuild()
{
// Get the plugin filename
string PluginParam = ParseParamValue("Plugin");
if(PluginParam == null)
{
throw new AutomationException("Missing -Plugin=... argument");
}
// Check it exists
FileReference PluginFile = new FileReference(PluginParam);
if (!PluginFile.Exists())
{
throw new AutomationException("Plugin '{0}' not found", PluginFile.FullName);
}
// Get the output directory
string PackageParam = ParseParamValue("Package");
if (PackageParam == null)
{
throw new AutomationException("Missing -Package=... argument");
}
// Make sure the packaging directory is valid
DirectoryReference PackageDir = new DirectoryReference(PackageParam);
if (PluginFile.IsUnderDirectory(PackageDir))
{
throw new AutomationException("Packaged plugin output directory must be different to source");
}
if (PackageDir.IsUnderDirectory(DirectoryReference.Combine(CommandUtils.RootDirectory, "Engine")))
{
throw new AutomationException("Output directory for packaged plugin must be outside engine directory");
}
// Clear the output directory of existing stuff
if (PackageDir.Exists())
{
CommandUtils.DeleteDirectoryContents(PackageDir.FullName);
}
else
{
PackageDir.CreateDirectory();
}
// Create a placeholder FilterPlugin.ini with instructions on how to use it
FileReference SourceFilterFile = FileReference.Combine(PluginFile.Directory, "Config", "FilterPlugin.ini");
if (!SourceFilterFile.Exists())
{
List<string> Lines = new List<string>();
Lines.Add("[FilterPlugin]");
Lines.Add("; This section lists additional files which will be packaged along with your plugin. Paths should be listed relative to the root plugin directory, and");
Lines.Add("; may include \"...\", \"*\", and \"?\" wildcards to match directories, files, and individual characters respectively.");
Lines.Add(";");
Lines.Add("; Examples:");
Lines.Add("; /README.txt");
Lines.Add("; /Extras/...");
Lines.Add("; /Binaries/ThirdParty/*.dll");
SourceFilterFile.Directory.CreateDirectory();
CommandUtils.WriteAllLines_NoExceptions(SourceFilterFile.FullName, Lines.ToArray());
}
// Create a host project for the plugin. For script generator plugins, we need to have UHT be able to load it, which can only happen if it's enabled in a project.
FileReference HostProjectFile = FileReference.Combine(PackageDir, "HostProject", "HostProject.uproject");
FileReference HostProjectPluginFile = CreateHostProject(HostProjectFile, PluginFile);
// Read the plugin
CommandUtils.Log("Reading plugin from {0}...", HostProjectPluginFile);
PluginDescriptor Plugin = PluginDescriptor.FromFile(HostProjectPluginFile, false);
// Compile the plugin for all the target platforms
List<UnrealTargetPlatform> HostPlatforms = ParseParam("NoHostPlatform")? new List<UnrealTargetPlatform>() : new List<UnrealTargetPlatform> { BuildHostPlatform.Current.Platform };
List<UnrealTargetPlatform> TargetPlatforms = GetTargetPlatforms(this, BuildHostPlatform.Current.Platform).Where(x => IsCodeTargetPlatform(BuildHostPlatform.Current.Platform, x)).ToList();
FileReference[] BuildProducts = CompilePlugin(HostProjectFile, HostProjectPluginFile, Plugin, HostPlatforms, TargetPlatforms, "");
// Package up the final plugin data
PackagePlugin(HostProjectPluginFile, BuildProducts, PackageDir);
// Remove the host project
if(!ParseParam("NoDeleteHostProject"))
{
CommandUtils.DeleteDirectory(HostProjectFile.Directory.FullName);
}
}
示例5: Execute
/// <summary>
/// Execute the task.
/// </summary>
/// <param name="Job">Information about the current job</param>
/// <param name="BuildProducts">Set of build products produced by this node.</param>
/// <param name="TagNameToFileSet">Mapping from tag names to the set of files they include</param>
/// <returns>True if the task succeeded</returns>
public override bool Execute(JobContext Job, HashSet<FileReference> BuildProducts, Dictionary<string, HashSet<FileReference>> TagNameToFileSet)
{
// Set the Engine directory
DirectoryReference EngineDir = DirectoryReference.Combine(CommandUtils.RootDirectory, "Engine");
if (!String.IsNullOrEmpty(Parameters.EngineDir))
{
EngineDir = DirectoryReference.Combine(CommandUtils.RootDirectory, Parameters.EngineDir);
}
// Set the Project directory
DirectoryReference ProjectDir = DirectoryReference.Combine(CommandUtils.RootDirectory, "Engine");
if (!String.IsNullOrEmpty(Parameters.ProjectDir))
{
ProjectDir = DirectoryReference.Combine(CommandUtils.RootDirectory, Parameters.ProjectDir);
}
// Resolve the input list
IEnumerable<FileReference> TargetFiles = ResolveFilespec(CommandUtils.RootDirectory, Parameters.Files, TagNameToFileSet);
HashSet<FileReference> Files = new HashSet<FileReference>();
HashSet<string> WildcardDependencies = new HashSet<string>();
foreach (FileReference TargetFile in TargetFiles)
{
// check all files are .target files
if (TargetFile.GetExtension() != ".target")
{
CommandUtils.LogError("Invalid file passed to TagReceipt task ({0})",TargetFile.FullName);
continue;
}
// Read the receipt
TargetReceipt Receipt;
if (!TargetReceipt.TryRead(TargetFile.FullName, out Receipt))
{
CommandUtils.LogWarning("Unable to load file using TagReceipt task ({0})", TargetFile.FullName);
continue;
}
// Convert the paths to absolute
Receipt.ExpandPathVariables(EngineDir, ProjectDir);
if (Parameters.BuildProducts)
{
foreach (BuildProduct BuildProduct in Receipt.BuildProducts)
{
if (String.IsNullOrEmpty(Parameters.BuildProductType) || BuildProduct.Type == BuildProductType)
{
Files.Add(new FileReference(BuildProduct.Path));
}
}
}
if (Parameters.RuntimeDependencies)
{
foreach (RuntimeDependency RuntimeDependency in Receipt.RuntimeDependencies)
{
if (String.IsNullOrEmpty(Parameters.StagedFileType) || RuntimeDependency.Type == StagedFileType)
{
// If it doesn't contain any wildcards, just add the pattern directly
if (FileFilter.FindWildcardIndex(RuntimeDependency.Path) == -1)
{
// Only add files that exist as dependencies are assumed to always exist
FileReference DependencyPath = new FileReference(RuntimeDependency.Path);
if (DependencyPath.Exists())
{
Files.Add(DependencyPath);
}
else
{
// Give a warning about files that don't exist so that we can clean up build.cs files
CommandUtils.LogWarning("File listed as RuntimeDependency in {0} does not exist ({1})", TargetFile.FullName, DependencyPath.FullName);
}
}
else
{
WildcardDependencies.Add(RuntimeDependency.Path);
}
}
}
}
if (Parameters.PrecompiledBuildDependencies)
{
foreach(string PrecompiledBuildDependency in Receipt.PrecompiledBuildDependencies)
{
// If it doesn't contain any wildcards, just add the pattern directly
if (FileFilter.FindWildcardIndex(PrecompiledBuildDependency) == -1)
{
// Only add files that exist as dependencies are assumed to always exist
FileReference DependencyPath = new FileReference(PrecompiledBuildDependency);
if (DependencyPath.Exists())
{
Files.Add(DependencyPath);
//.........这里部分代码省略.........
示例6: AddOptionalBuildProduct
/// <summary>
/// Adds a build product to the output list if it exists
/// </summary>
/// <param name="BuildProduct">The build product to add</param>
/// <param name="BuildProducts">List of output build products</param>
public static void AddOptionalBuildProduct(FileReference BuildProduct, HashSet<FileReference> BuildProducts)
{
if(BuildProduct.Exists())
{
BuildProducts.Add(BuildProduct);
}
}
示例7: WriteTokenFile
/// <summary>
/// Attempts to write an owner to a token file transactionally
/// </summary>
/// <returns>True if the lock was acquired, false otherwise</returns>
public bool WriteTokenFile(FileReference Location, string Signature)
{
// Check it doesn't already exist
if(Location.Exists())
{
return false;
}
// Make sure the directory exists
Location.Directory.CreateDirectory();
// Create a temp file containing the owner name
string TempFileName;
for(int Idx = 0;;Idx++)
{
TempFileName = String.Format("{0}.{1}.tmp", Location.FullName, Idx);
try
{
byte[] Bytes = Encoding.UTF8.GetBytes(Signature);
using (FileStream Stream = File.Open(TempFileName, FileMode.CreateNew, FileAccess.Write, FileShare.None))
{
Stream.Write(Bytes, 0, Bytes.Length);
}
break;
}
catch(IOException)
{
if(!File.Exists(TempFileName))
{
throw;
}
}
}
// Try to move the temporary file into place.
try
{
File.Move(TempFileName, Location.FullName);
return true;
}
catch
{
if(!File.Exists(TempFileName))
{
throw;
}
return false;
}
}
示例8: ReadTokenFile
/// <summary>
/// Reads the contents of the given token
/// </summary>
/// <returns>Contents of the token, or null if it does not exist</returns>
public string ReadTokenFile(FileReference Location)
{
return Location.Exists()? File.ReadAllText(Location.FullName) : null;
}