protected void CopyResourcesToTargetDir() { string TargetPath = Path.Combine(OutputPath, BuildResourceSubPath); string SourcePath = Path.Combine(IntermediatePath, BuildResourceSubPath); // If the target resource folder doesn't exist yet, create it if (!CreateCheckDirectory(TargetPath)) { return; } // Find all copies of the resource file in both target and source directories (could be up to one for each culture and the default, but must have at least the default). var TargetResourceInstances = Directory.EnumerateFiles(TargetPath, "*.*", SearchOption.AllDirectories); var SourceResourceInstances = Directory.EnumerateFiles(SourcePath, "*.*", SearchOption.AllDirectories); // Remove any target files that aren't part of the source file list foreach (string TargetResourceFile in TargetResourceInstances) { // Ignore string tables (the only non-binary resources that will be present) if (!TargetResourceFile.Contains(".resw")) { //@todo always delete for cultures we aren't staging bool bRelativeSourceFileFound = false; foreach (string SourceResourceFile in SourceResourceInstances) { string SourceRelativeFile = SourceResourceFile.Substring(SourcePath.Length + 1); string TargetRelativeFile = TargetResourceFile.Substring(TargetPath.Length + 1); if (SourceRelativeFile.Equals(TargetRelativeFile)) { bRelativeSourceFileFound = true; break; } } if (!bRelativeSourceFileFound) { try { File.Delete(TargetResourceFile); } catch (Exception E) { Log.TraceError("Could not remove stale resource file {0} - {1}.", TargetResourceFile, E.Message); } } } } // Copy new resource files only if they differ from the destination foreach (string SourceResourceFile in SourceResourceInstances) { //@todo only copy files for cultures we are staging string TargetResourcePath = Path.Combine(TargetPath, SourceResourceFile.Substring(SourcePath.Length + 1)); CompareAndReplaceModifiedTarget(SourceResourceFile, TargetResourcePath); } }
protected bool CopyAndReplaceBinaryIntermediate(string ResourceFileName, bool AllowEngineFallback = true) { string TargetPath = Path.Combine(IntermediatePath, BuildResourceSubPath); string SourcePath; bool bFileExists = FindResourceBinaryFile(out SourcePath, ResourceFileName, AllowEngineFallback); // At least the default culture entry for any resource binary must always exist if (!bFileExists) { return(false); } // If the target resource folder doesn't exist yet, create it if (!CreateCheckDirectory(TargetPath)) { return(false); } // Find all copies of the resource file in the source directory (could be up to one for each culture and the default). IEnumerable <string> SourceResourceInstances = Directory.EnumerateFiles(SourcePath, ResourceFileName, SearchOption.AllDirectories); // Copy new resource files foreach (string SourceResourceFile in SourceResourceInstances) { //@todo only copy files for cultures we are staging string TargetResourcePath = Path.Combine(TargetPath, SourceResourceFile.Substring(SourcePath.Length + 1)); if (!CreateCheckDirectory(Path.GetDirectoryName(TargetResourcePath))) { Log.TraceError("Unable to create intermediate directory {0}.", Path.GetDirectoryName(TargetResourcePath)); continue; } if (!File.Exists(TargetResourcePath)) { try { File.Copy(SourceResourceFile, TargetResourcePath); // File.Copy also copies the attributes, so make sure the new file isn't read only FileAttributes Attrs = File.GetAttributes(TargetResourcePath); if (Attrs.HasFlag(FileAttributes.ReadOnly)) { File.SetAttributes(TargetResourcePath, Attrs & ~FileAttributes.ReadOnly); } } catch (Exception) { Log.TraceError("Unable to copy file {0} to {1}.", SourceResourceFile, TargetResourcePath); return(false); } } } return(true); }