public static ConfigFile ReadProjectConfigFile(PerforceConnection Perforce, string BranchClientPath, string SelectedClientFileName, string CacheFolder, List <KeyValuePair <string, DateTime> > LocalConfigFiles, TextWriter Log) { List <string> ConfigFilePaths = Utility.GetDepotConfigPaths(BranchClientPath + "/Engine", SelectedClientFileName); ConfigFile ProjectConfig = new ConfigFile(); List <PerforceFileRecord> FileRecords; if (Perforce.Stat("-Ol", ConfigFilePaths, out FileRecords, Log)) { foreach (PerforceFileRecord FileRecord in FileRecords) { List <string> Lines = null; // Skip file records which are still in the workspace, but were synced from a different branch. For these files, the action seems to be empty, so filter against that. if (FileRecord.Action == null) { continue; } // If this file is open for edit, read the local version string LocalFileName = FileRecord.ClientPath; if (LocalFileName != null && File.Exists(LocalFileName) && (File.GetAttributes(LocalFileName) & FileAttributes.ReadOnly) == 0) { try { DateTime LastModifiedTime = File.GetLastWriteTimeUtc(LocalFileName); LocalConfigFiles.Add(new KeyValuePair <string, DateTime>(LocalFileName, LastModifiedTime)); Lines = File.ReadAllLines(LocalFileName).ToList(); } catch (Exception Ex) { Log.WriteLine("Failed to read local config file for {0}: {1}", LocalFileName, Ex.ToString()); } } // Otherwise try to get it from perforce if (Lines == null) { Utility.TryPrintFileUsingCache(Perforce, FileRecord.DepotPath, CacheFolder, FileRecord.Digest, out Lines, Log); } // Merge the text with the config file if (Lines != null) { try { ProjectConfig.Parse(Lines.ToArray()); Log.WriteLine("Read config file from {0}", FileRecord.DepotPath); } catch (Exception Ex) { Log.WriteLine("Failed to read config file from {0}: {1}", FileRecord.DepotPath, Ex.ToString()); } } } } return(ProjectConfig); }
public static ConfigFile ReadProjectConfigFile(PerforceConnection Perforce, string BranchClientPath, string SelectedClientFileName, List <KeyValuePair <string, DateTime> > LocalConfigFiles, TextWriter Log) { List <string> ConfigFilePaths = Utility.GetConfigFileLocations(BranchClientPath, SelectedClientFileName, '/'); List <PerforceFileRecord> OpenFiles; Perforce.GetOpenFiles(String.Format("{0}/....ini", BranchClientPath), out OpenFiles, Log); ConfigFile ProjectConfig = new ConfigFile(); foreach (string ConfigFilePath in ConfigFilePaths) { List <string> Lines = null; // If this file is open for edit, read the local version if (OpenFiles != null && OpenFiles.Any(x => x.ClientPath.Equals(ConfigFilePath, StringComparison.InvariantCultureIgnoreCase))) { try { string LocalFileName; if (Perforce.ConvertToLocalPath(ConfigFilePath, out LocalFileName, Log)) { DateTime LastModifiedTime = File.GetLastWriteTimeUtc(LocalFileName); LocalConfigFiles.Add(new KeyValuePair <string, DateTime>(LocalFileName, LastModifiedTime)); Lines = File.ReadAllLines(LocalFileName).ToList(); } } catch (Exception Ex) { Log.WriteLine("Failed to read local config file for {0}: {1}", ConfigFilePath, Ex.ToString()); } } // Otherwise try to get it from perforce if (Lines == null) { Perforce.Print(ConfigFilePath, out Lines, Log); } // Merge the text with the config file if (Lines != null) { try { ProjectConfig.Parse(Lines.ToArray()); Log.WriteLine("Read config file from {0}", ConfigFilePath); } catch (Exception Ex) { Log.WriteLine("Failed to read config file from {0}: {1}", ConfigFilePath, Ex.ToString()); } } } return(ProjectConfig); }
bool UpdateZippedBinaries() { // Get the path to the config file string ClientConfigFileName = PerforceUtils.GetClientOrDepotDirectoryName(SelectedClientFileName) + "/Build/UnrealGameSync.ini"; // Find the most recent change to that file (if the file doesn't exist, we succeed and just get 0 changes). List <PerforceChangeSummary> ConfigFileChanges; if (!Perforce.FindChanges(ClientConfigFileName, 1, out ConfigFileChanges, LogWriter)) { return(false); } // Update the zipped binaries path if it's changed int NewZippedBinariesConfigChangeNumber = (ConfigFileChanges.Count > 0)? ConfigFileChanges[0].Number : 0; if (NewZippedBinariesConfigChangeNumber != ZippedBinariesConfigChangeNumber) { string NewZippedBinariesPath = null; if (NewZippedBinariesConfigChangeNumber != 0) { List <string> Lines; if (!Perforce.Print(ClientConfigFileName, out Lines, LogWriter)) { return(false); } ConfigFile NewConfigFile = new ConfigFile(); NewConfigFile.Parse(Lines.ToArray()); ConfigSection ProjectSection = NewConfigFile.FindSection(SelectedProjectIdentifier); if (ProjectSection != null) { NewZippedBinariesPath = ProjectSection.GetValue("ZippedBinariesPath", null); } } ZippedBinariesPath = NewZippedBinariesPath; ZippedBinariesConfigChangeNumber = NewZippedBinariesConfigChangeNumber; } SortedList <int, string> NewChangeNumberToZippedBinaries = new SortedList <int, string>(); if (ZippedBinariesPath != null) { List <PerforceFileChangeSummary> Changes; if (!Perforce.FindFileChanges(ZippedBinariesPath, 100, out Changes, LogWriter)) { return(false); } foreach (PerforceFileChangeSummary Change in Changes) { if (Change.Action != "purge") { string[] Tokens = Change.Description.Split(' '); if (Tokens[0].StartsWith("[CL") && Tokens[1].EndsWith("]")) { int OriginalChangeNumber; if (int.TryParse(Tokens[1].Substring(0, Tokens[1].Length - 1), out OriginalChangeNumber) && !NewChangeNumberToZippedBinaries.ContainsKey(OriginalChangeNumber)) { NewChangeNumberToZippedBinaries[OriginalChangeNumber] = String.Format("{0}#{1}", ZippedBinariesPath, Change.Revision); } } } } } if (!ChangeNumberToZippedBinaries.SequenceEqual(NewChangeNumberToZippedBinaries)) { ChangeNumberToZippedBinaries = NewChangeNumberToZippedBinaries; if (OnUpdateMetadata != null && Changes.Count > 0) { OnUpdateMetadata(); } } return(true); }
static ConfigFile ReadProjectConfigFile(string LocalRootPath, string SelectedLocalFileName, TextWriter Log) { // Find the valid config file paths List<string> ProjectConfigFileNames = new List<string>(); ProjectConfigFileNames.Add(Path.Combine(LocalRootPath, "Engine", "Programs", "UnrealGameSync", "UnrealGameSync.ini")); if(SelectedLocalFileName.EndsWith(".uproject", StringComparison.InvariantCultureIgnoreCase)) { ProjectConfigFileNames.Add(Path.Combine(Path.GetDirectoryName(SelectedLocalFileName), "Build", "UnrealGameSync.ini")); } // Read them in ConfigFile ProjectConfig = new ConfigFile(); foreach(string ProjectConfigFileName in ProjectConfigFileNames) { if(File.Exists(ProjectConfigFileName)) { try { string[] Lines = File.ReadAllLines(ProjectConfigFileName); ProjectConfig.Parse(Lines); Log.WriteLine("Read config file from {0}", ProjectConfigFileName); } catch(Exception Ex) { Log.WriteLine("Failed to read config file from {0}: {1}", ProjectConfigFileName, Ex.ToString()); } } } return ProjectConfig; }