/// <summary> /// Helper function that will check to see if a file has a read only /// attribute set. If it does, then the attribute is removed. /// </summary> /// <param name="configuration">Main program configuration</param> /// <param name="fullFileName">File Name to check for read only attribute</param> public static void RemoveReadOnlyAttribute( BuildControlParameters configuration, string fullFileName) { FileInfo f = new FileInfo(fullFileName); if ((f.Attributes & FileAttributes.ReadOnly) != 0) { if (configuration.SourceDepotOnlineMode) { ProcessOperations.SDEdit(configuration, fullFileName); } else { f.Attributes = f.Attributes & ~FileAttributes.ReadOnly; } } }
/// <summary> /// Modifies the build version files. /// </summary> /// <param name="configuration">The configuration.</param> /// <param name="results">The results.</param> /// <returns></returns> private static bool ModifyBuildVersionFiles( BuildControlParameters configuration, DailyBuildFullResults results) { bool allCompletedWithSuccess = true; string heroAppSource = FindHeroAppSourceFolder(configuration); if (!String.IsNullOrEmpty(heroAppSource)) { DateTime currentTime = DateTime.Now; for (Int32 i = 0; i < configuration.Projects.Length; i++) { results.BuildTargets[i].BuildStartTime = currentTime; string appFolder = Path.Combine(heroAppSource, configuration.Projects[i].ProjectPath); string assemblyFile = Path.Combine(appFolder, configuration.Projects[i].AssemblyFilePathAndNameFromProjectRoot); if (File.Exists(assemblyFile)) { try { ProcessInformation process = ProcessOperations.SDEdit(configuration, assemblyFile); CheckForErrorFromSDOperation(process, results, results.BuildTargets[i].ModifyVersion); string[] assemblyFileContents = File.ReadAllLines(assemblyFile); for (Int32 j = 0; j < assemblyFileContents.Length; j++) { if (assemblyFileContents[j].ToLower().Contains(RevisionFileStringBase.ToLower())) { string v = assemblyFileContents[j]; string[] versions = v.Split('.'); if (versions.Length >= 3) { versions[2] = CreateDateTimeFormatString(currentTime); } v = ""; for (Int32 k = 0; k < versions.Length; k++) { v += versions[k] + "."; } assemblyFileContents[j] = v.TrimEnd('.'); break; } } File.WriteAllLines(assemblyFile, assemblyFileContents); results.BuildTargets[i].ModifyVersion.Success = true; } catch (Exception e) { results.BuildTargets[i].ModifyVersion.SetResults(false, e.Message); ProgramExecutionLog.AddEntry( "Failed to modify file " + assemblyFile + " Exception information was " + e.ToString()); allCompletedWithSuccess = false; } } else { string errorMessage = "Assembly File did not exist. Path was " + assemblyFile; results.BuildTargets[i].ModifyVersion.SetResults(false, errorMessage); ProgramExecutionLog.AddEntry(errorMessage); allCompletedWithSuccess = false; } } } else { return(false); } return(allCompletedWithSuccess); }