private static String GetLastestFile(String RootPath) { String LastestScriptStr = null; Int64 LastestFileDate = Properties.Settings.Default.LastestScriptDate; if (Directory.Exists(RootPath)) { //Console.WriteLine("FOUND FILE: " + RootPath); String[] ScriptList = Directory.GetFiles(RootPath); Int64 TempName = 0; foreach (String ThisFile in ScriptList) { String TempFileNameStr = ThisFile.Replace(RootPath + "\\", ""); TempFileNameStr = TempFileNameStr.Replace(".txt", ""); Int64.TryParse(TempFileNameStr, out TempName); if (LastestFileDate < TempName) { LastestScriptStr = ThisFile; } } } else { Directory.CreateDirectory(RootPath); } return(LastestScriptStr); }
private ObservableCollection <string> _filenames(FileNameType fType, ThisFile tf) { ObservableCollection <string> temp = new ObservableCollection <string>(); foreach (ConversionFileInfo fi in this) { temp.Add((fType == FileNameType.FullName ? (tf == ThisFile.Source ? fi.Source.FullName : fi.Target.FullName) : (fType == FileNameType.Path ? (tf == ThisFile.Source ? fi.Source.DirectoryName : fi.Target.DirectoryName) : (fType == FileNameType.Name ? (tf == ThisFile.Source ? fi.Source.Name : fi.Target.Name) : (fType == FileNameType.Extension ? (tf == ThisFile.Source ? fi.Source.Extension : fi.Target.Extension) : ""))))); } return(temp); }
public override void ExecuteBuild() { LogInformation("************************* Reworking stats code"); var Wildcards = new List <string>() { "*.h", "*.cpp", "*.inl" }; // @todo: Add support for STATCAT_ var DeclareStrings = new List <string>() { "DECLARE_CYCLE_STAT", "DECLARE_FLOAT_COUNTER_STAT", "DECLARE_DWORD_COUNTER_STAT", "DECLARE_FLOAT_ACCUMULATOR_STAT", "DECLARE_DWORD_ACCUMULATOR_STAT", "DECLARE_MEMORY_STAT", "DECLARE_MEMORY_STAT_POOL", "DECLARE_STATS_GROUP" }; DirectoryInfo DirInfo = new DirectoryInfo(CmdEnv.LocalRoot); var TopLevelDirs = DirInfo.GetDirectories(); var Dirs = new List <string>(); foreach (var TopLevelDir in TopLevelDirs) { if (DirectoryExists_NoExceptions(CombinePaths(TopLevelDir.FullName, "Source"))) { Dirs.Add(CombinePaths(TopLevelDir.FullName, "Source")); } } var AllFiles = new List <string>(); foreach (var Dir in Dirs) { foreach (var Wildcard in Wildcards) { foreach (var ThisFile in CommandUtils.FindFiles_NoExceptions(Wildcard, true, Dir)) { if ( !ThisFile.Contains(@"Runtime\Core\Public\Stats\Stats2") && !ThisFile.Contains(@"\ThirdParty\") ) { LogInformation("Source File: {0}", ThisFile); AllFiles.Add(ThisFile); } } } } var DeclareFiles = new Dictionary <string, string>(); var DeclareLines = new Dictionary <string, string>(); var EnumFiles = new Dictionary <string, string>(); var EnumLines = new Dictionary <string, string>(); var Broken = new Dictionary <string, string>(); foreach (var ThisFile in AllFiles) { var FileText = ReadAllText(ThisFile); if (FileText.Contains("STAT_") || FileText.Contains("STATGROUP_")) { var Lines = ReadAllLines(ThisFile); foreach (var LineWithWS in Lines) { var Line = LineWithWS.Trim(); if (Line.Contains("STAT_") || Line.Contains("STATGROUP_")) { string TypeString = "STAT_"; if (!Line.Contains(TypeString) || Line.Contains("DECLARE_STATS_GROUP")) { TypeString = "STATGROUP_"; } bool bDeclareLine = false; foreach (var DeclareString in DeclareStrings) { if (Line.Contains(DeclareString)) { bDeclareLine = true; break; } } var Cut = Line; string Exception = "DECLARE_MEMORY_STAT_POOL"; if (Line.StartsWith(Exception)) { Cut = Line.Substring(Exception.Length); } Cut = Cut.Substring(Cut.IndexOf(TypeString)); int End = Cut.IndexOf(","); if (End < 0) { End = Cut.Length; } int EndEq = Cut.IndexOf("="); int EndParen = Cut.IndexOf(")"); int EndParen2 = Cut.IndexOf("("); if (EndEq > 0 && EndEq < End) { End = EndEq; } if (EndParen > 0 && EndParen < End) { End = EndParen; } if (EndParen2 > 0 && EndParen2 < End) { End = EndParen2; } string StatName = Cut.Substring(0, End).Trim(); bool bEnumLine = false; if (!bDeclareLine) { if ((Line.EndsWith(",") || Line == StatName) && Line.StartsWith(TypeString)) { bEnumLine = true; } } if (bEnumLine || bDeclareLine) { LogInformation("{0} {1} Line: {2} : {3}", bEnumLine ? "Enum" : "Declare", TypeString, StatName, Line); if (bEnumLine) { if (EnumFiles.ContainsKey(StatName)) { if (!Broken.ContainsKey(StatName)) { Broken.Add(StatName, Line); } } else { EnumFiles.Add(StatName, ThisFile); EnumLines.Add(StatName, Line); } } else { if (DeclareFiles.ContainsKey(StatName)) { if (!Broken.ContainsKey(StatName)) { Broken.Add(StatName, Line); } } else { DeclareFiles.Add(StatName, ThisFile); DeclareLines.Add(StatName, Line); } } } } } } } var AllGoodStats = new List <string>(); var AllGoodGroups = new List <string>(); foreach (var DeclareLine in DeclareLines) { if (!Broken.ContainsKey(DeclareLine.Key)) { if (EnumFiles.ContainsKey(DeclareLine.Key)) { if (DeclareLine.Key.StartsWith("STATGROUP_")) { AllGoodGroups.Add(DeclareLine.Key); } else { AllGoodStats.Add(DeclareLine.Key); } } else { Broken.Add(DeclareLine.Key, DeclareLine.Value); } } } var ToCheckOuts = new HashSet <string>(); LogInformation("Stats *************************"); foreach (var AllGoodStat in AllGoodStats) { LogInformation("{0}", AllGoodStat); ToCheckOuts.Add(DeclareFiles[AllGoodStat]); ToCheckOuts.Add(EnumFiles[AllGoodStat]); } LogInformation("Groups *************************"); foreach (var AllGoodGroup in AllGoodGroups) { LogInformation("{0}", AllGoodGroup); ToCheckOuts.Add(DeclareFiles[AllGoodGroup]); ToCheckOuts.Add(EnumFiles[AllGoodGroup]); } LogInformation("Broken *************************"); foreach (var BrokenItem in Broken) { LogInformation("{0}", BrokenItem.Key); } LogInformation("*************************"); int WorkingCL = -1; if (P4Enabled) { WorkingCL = P4.CreateChange(P4Env.Client, "Stat code surgery"); LogInformation("Working in {0}", WorkingCL); } else { throw new AutomationException("this command needs to run with P4."); } var CheckedOuts = new HashSet <string>(); foreach (var ToCheckOut in ToCheckOuts) { if (P4.Edit_NoExceptions(WorkingCL, ToCheckOut)) { CheckedOuts.Add(ToCheckOut); } } LogInformation("Checked Out *************************"); foreach (var CheckedOut in CheckedOuts) { LogInformation("{0}", CheckedOut); } LogInformation("Failed to check out *************************"); foreach (var ToCheckOut in ToCheckOuts) { if (!CheckedOuts.Contains(ToCheckOut)) { LogInformation("{0}", ToCheckOut); } } LogInformation("*************************"); foreach (var AllGoodStat in AllGoodStats) { if (EnumFiles[AllGoodStat].EndsWith(".cpp", StringComparison.InvariantCultureIgnoreCase)) { var DeclareFileText = ReadAllText(DeclareFiles[AllGoodStat]); DeclareFileText = DeclareFileText.Replace(DeclareLines[AllGoodStat], ""); WriteAllText(DeclareFiles[AllGoodStat], DeclareFileText); var EnumFileText = ReadAllText(EnumFiles[AllGoodStat]); EnumFileText = EnumFileText.Replace(EnumLines[AllGoodStat], DeclareLines[AllGoodStat]); WriteAllText(EnumFiles[AllGoodStat], EnumFileText); } else { var DeclareFileText = ReadAllText(DeclareFiles[AllGoodStat]); DeclareFileText = DeclareFileText.Replace(DeclareLines[AllGoodStat], "DEFINE_STAT(" + AllGoodStat + ");"); WriteAllText(DeclareFiles[AllGoodStat], DeclareFileText); var EnumFileText = ReadAllText(EnumFiles[AllGoodStat]); var ExternDeclare = DeclareLines[AllGoodStat]; int Paren = ExternDeclare.IndexOf("("); ExternDeclare = ExternDeclare.Substring(0, Paren) + "_EXTERN" + ExternDeclare.Substring(Paren); Paren = ExternDeclare.LastIndexOf(")"); ExternDeclare = ExternDeclare.Substring(0, Paren) + ", " + ExternDeclare.Substring(Paren); EnumFileText = EnumFileText.Replace(EnumLines[AllGoodStat], ExternDeclare); WriteAllText(EnumFiles[AllGoodStat], EnumFileText); } } foreach (var AllGoodGroup in AllGoodGroups) { var DeclareFileText = ReadAllText(DeclareFiles[AllGoodGroup]); DeclareFileText = DeclareFileText.Replace(DeclareLines[AllGoodGroup], ""); WriteAllText(DeclareFiles[AllGoodGroup], DeclareFileText); var EnumFileText = ReadAllText(EnumFiles[AllGoodGroup]); EnumFileText = EnumFileText.Replace(EnumLines[AllGoodGroup], DeclareLines[AllGoodGroup]); WriteAllText(EnumFiles[AllGoodGroup], EnumFileText); } LogInformation("*************************"); }
/// <summary> /// Runs UAT recursively /// </summary> /// <param name="Env">Environment to use.</param> /// <param name="CommandLine">Commandline to pass on to the executable</param> public static string RunUAT(CommandEnvironment Env, string CommandLine) { // this doesn't do much, but it does need to make sure log folders are reasonable and don't collide string BaseLogSubdir = "Recur"; if (!String.IsNullOrEmpty(CommandLine)) { int Space = CommandLine.IndexOf(" "); if (Space > 0) { BaseLogSubdir = BaseLogSubdir + "_" + CommandLine.Substring(0, Space); } else { BaseLogSubdir = BaseLogSubdir + "_" + CommandLine; } } int Index = 0; BaseLogSubdir = BaseLogSubdir.Trim(); string DirOnlyName = BaseLogSubdir; string LogSubdir = CombinePaths(CmdEnv.LogFolder, DirOnlyName, ""); while (true) { var ExistingFiles = FindFiles(DirOnlyName + "*", false, CmdEnv.LogFolder); if (ExistingFiles.Length == 0) { break; } Index++; if (Index == 1000) { throw new AutomationException("Couldn't seem to create a log subdir {0}", LogSubdir); } DirOnlyName = String.Format("{0}_{1}_", BaseLogSubdir, Index); LogSubdir = CombinePaths(CmdEnv.LogFolder, DirOnlyName, ""); } string LogFile = CombinePaths(CmdEnv.LogFolder, DirOnlyName + ".log"); Log("Recursive UAT Run, in log folder {0}, main log file {1}", LogSubdir, LogFile); CreateDirectory(LogSubdir); CommandLine = CommandLine + " -NoCompile"; string App = CmdEnv.UATExe; Log("Running {0} {1}", App, CommandLine); var OSEnv = new Dictionary <string, string>(); OSEnv.Add(AutomationTool.EnvVarNames.LogFolder, LogSubdir); OSEnv.Add("uebp_UATMutexNoWait", "1"); if (!IsBuildMachine) { OSEnv.Add(AutomationTool.EnvVarNames.LocalRoot, ""); // if we don't clear this out, it will think it is a build machine; it will rederive everything } ProcessResult Result = Run(App, CommandLine, null, ERunOptions.Default, OSEnv); if (Result.Output.Length > 0) { WriteToFile(LogFile, Result.Output); } else { WriteToFile(LogFile, "[None!, no output produced]"); } Log("Flattening log folder {0}", LogSubdir); var Files = FindFiles("*", true, LogSubdir); string MyLogFolder = CombinePaths(CmdEnv.LogFolder, ""); foreach (var ThisFile in Files) { if (!ThisFile.StartsWith(MyLogFolder, StringComparison.InvariantCultureIgnoreCase)) { throw new AutomationException("Can't rebase {0} because it doesn't start with {1}", ThisFile, MyLogFolder); } string NewFilename = ThisFile.Substring(MyLogFolder.Length).Replace("/", "_").Replace("\\", "_"); NewFilename = CombinePaths(CmdEnv.LogFolder, NewFilename); if (FileExists_NoExceptions(NewFilename)) { throw new AutomationException("Destination log file already exists? {0}", NewFilename); } CopyFile(ThisFile, NewFilename); if (!FileExists_NoExceptions(NewFilename)) { throw new AutomationException("Destination log file could not be copied {0}", NewFilename); } DeleteFile_NoExceptions(ThisFile); } DeleteDirectory_NoExceptions(LogSubdir); if (Result != 0) { throw new AutomationException(String.Format("Recursive UAT Command failed (Result:{3}): {0} {1}. See logfile for details: '{2}' ", App, CommandLine, Path.GetFileName(LogFile), Result.ExitCode)); } return(LogFile); }
/// <summary> /// Runs UAT recursively /// </summary> /// <param name="Env">Environment to use.</param> /// <param name="CommandLine">Commandline to pass on to the executable</param> public static string RunUAT(CommandEnvironment Env, string CommandLine) { // We want to redirect the output from recursive UAT calls into our normal log folder, but prefix everything with a unique identifier. To do so, we set the EnvVarNames.LogFolder environment // variable to a subfolder of it, then copy its contents into the main folder with a prefix after it's finished. Start by finding a base name we can use to identify the output of this run. string BaseLogSubdir = "Recur"; if (!String.IsNullOrEmpty(CommandLine)) { int Space = CommandLine.IndexOf(" "); if (Space > 0) { BaseLogSubdir = BaseLogSubdir + "_" + CommandLine.Substring(0, Space); } else if (CommandLine.Contains("-profile")) { string PathToProfile = CommandLine.Substring(CommandLine.IndexOf('=') + 1); BaseLogSubdir = BaseLogSubdir + "_" + (Path.GetFileNameWithoutExtension(PathToProfile)); } else { BaseLogSubdir = BaseLogSubdir + "_" + CommandLine; } } BaseLogSubdir = BaseLogSubdir.Trim(); // Check if there are already log files which start with this prefix, and try to uniquify it if until there aren't. int Index = 0; string DirOnlyName = BaseLogSubdir; string LogSubdir = CombinePaths(CmdEnv.LogFolder, DirOnlyName, ""); while (true) { var ExistingFiles = FindFiles(DirOnlyName + "*", false, CmdEnv.LogFolder); if (ExistingFiles.Length == 0) { break; } Index++; if (Index == 1000) { throw new AutomationException("Couldn't seem to create a log subdir {0}", LogSubdir); } DirOnlyName = String.Format("{0}_{1}_", BaseLogSubdir, Index); LogSubdir = CombinePaths(CmdEnv.LogFolder, DirOnlyName, ""); } // Get the stdout log file for this run, and create the subdirectory for all the other log output string LogFile = CombinePaths(CmdEnv.LogFolder, DirOnlyName + ".log"); LogVerbose("Recursive UAT Run, in log folder {0}, main log file {1}", LogSubdir, LogFile); CreateDirectory(LogSubdir); // Run UAT with the log folder redirected through the environment string App = CmdEnv.UATExe; Log("Running {0} {1}", App, CommandLine); var OSEnv = new Dictionary <string, string>(); OSEnv.Add(AutomationTool.EnvVarNames.LogFolder, LogSubdir); OSEnv.Add("uebp_UATMutexNoWait", "1"); if (!IsBuildMachine) { OSEnv.Add(AutomationTool.EnvVarNames.LocalRoot, ""); // if we don't clear this out, it will think it is a build machine; it will rederive everything } ProcessResult Result = Run(App, CommandLine, null, ERunOptions.Default, OSEnv); if (Result.Output.Length > 0) { WriteToFile(LogFile, Result.Output); } else { WriteToFile(LogFile, "[None!, no output produced]"); } // Copy everything into the main log folder, using the prefix we decided on earlier. LogVerbose("Flattening log folder {0}", LogSubdir); var Files = FindFiles("*", true, LogSubdir); string MyLogFolder = CombinePaths(CmdEnv.LogFolder, ""); foreach (var ThisFile in Files) { if (!ThisFile.StartsWith(MyLogFolder, StringComparison.InvariantCultureIgnoreCase)) { throw new AutomationException("Can't rebase {0} because it doesn't start with {1}", ThisFile, MyLogFolder); } string NewFilename = ThisFile.Substring(MyLogFolder.Length).Replace("/", "_").Replace("\\", "_"); NewFilename = CombinePaths(CmdEnv.LogFolder, NewFilename); if (FileExists_NoExceptions(NewFilename)) { throw new AutomationException("Destination log file already exists? {0}", NewFilename); } CopyFile(ThisFile, NewFilename); if (!FileExists_NoExceptions(NewFilename)) { throw new AutomationException("Destination log file could not be copied {0}", NewFilename); } DeleteFile_NoExceptions(ThisFile); } DeleteDirectory_NoExceptions(LogSubdir); if (Result != 0) { throw new AutomationException(String.Format("Recursive UAT Command failed (Result:{3}): {0} {1}. See logfile for details: '{2}' ", App, CommandLine, Path.GetFileName(LogFile), Result.ExitCode)); } return(LogFile); }
public override void ExecuteBuild() { Log("************************* UpdateCopyright"); var Wildcards = new List <string>() { "*.h", "*.cpp", "*.inl", "*.cs" }; var Dirs = new List <string>(); Dirs.Add(CombinePaths(CmdEnv.LocalRoot, "Engine", "Plugins")); { DirectoryInfo DirInfo = new DirectoryInfo(CmdEnv.LocalRoot); var TopLevelDirs = DirInfo.GetDirectories(); foreach (var TopLevelDir in TopLevelDirs) { if (DirectoryExists_NoExceptions(CombinePaths(TopLevelDir.FullName, "Source"))) { Dirs.Add(CombinePaths(TopLevelDir.FullName, "Source")); Dirs.Add(CombinePaths(TopLevelDir.FullName, "Build", "Scripts")); } } } { DirectoryInfo DirInfo = new DirectoryInfo(CombinePaths(CmdEnv.LocalRoot, "Samples", "SampleGames")); var TopLevelDirs = DirInfo.GetDirectories(); foreach (var TopLevelDir in TopLevelDirs) { if (DirectoryExists_NoExceptions(CombinePaths(TopLevelDir.FullName, "Source"))) { Dirs.Add(CombinePaths(TopLevelDir.FullName, "Source")); Dirs.Add(CombinePaths(TopLevelDir.FullName, "Build", "Scripts")); } } } { DirectoryInfo DirInfo = new DirectoryInfo(CombinePaths(CmdEnv.LocalRoot, "Samples", "Showcases")); var TopLevelDirs = DirInfo.GetDirectories(); foreach (var TopLevelDir in TopLevelDirs) { if (DirectoryExists_NoExceptions(CombinePaths(TopLevelDir.FullName, "Source"))) { Dirs.Add(CombinePaths(TopLevelDir.FullName, "Source")); Dirs.Add(CombinePaths(TopLevelDir.FullName, "Build", "Scripts")); } } } { DirectoryInfo DirInfo = new DirectoryInfo(CombinePaths(CmdEnv.LocalRoot, "Templates")); var TopLevelDirs = DirInfo.GetDirectories(); foreach (var TopLevelDir in TopLevelDirs) { if (DirectoryExists_NoExceptions(CombinePaths(TopLevelDir.FullName, "Source"))) { Dirs.Add(CombinePaths(TopLevelDir.FullName, "Source")); Dirs.Add(CombinePaths(TopLevelDir.FullName, "Build", "Scripts")); } } } var AllFiles = new List <string>(); foreach (var Dir in Dirs) { foreach (var Wildcard in Wildcards) { foreach (var ThisFile in CommandUtils.FindFiles_NoExceptions(Wildcard, true, Dir)) { if (!ThisFile.Contains(@"\ThirdParty\")) { Log("Source File: {0}", ThisFile); AllFiles.Add(ThisFile); } } } } int WorkingCL = -1; if (P4Enabled) { WorkingCL = P4.CreateChange(P4Env.Client, "Stat code surgery"); Log("Working in {0}", WorkingCL); } else { throw new AutomationException("this command needs to run with P4."); } foreach (var ToCheckOut in AllFiles) { if (P4.Edit_NoExceptions(WorkingCL, ToCheckOut)) { Log("Checked out {0}", ToCheckOut); } else if (ToCheckOut.Contains("CodeSurgery")) { Log("Couldn't check out {0}", ToCheckOut); } else { P4.RevertAll(WorkingCL); throw new AutomationException("Couldn't check out {0}", ToCheckOut); } } var Normal = new HashSet <string>(); var Missing = new HashSet <string>(); foreach (var ThisFile in AllFiles) { var FileText = ReadAllText(ThisFile); if (FileText.Contains("2013 Epic Games, Inc. All Rights Reserved.")) { FileText = FileText.Replace("2013 Epic Games, Inc. All Rights Reserved.", "2014 Epic Games, Inc. All Rights Reserved."); WriteAllText(ThisFile, FileText); Normal.Add(ThisFile); } else { var Lines = new List <string>(ReadAllLines(ThisFile)); Lines.Insert(0, "// Copyright 1998-2014 Epic Games, Inc. All Rights Reserved."); WriteAllLines(ThisFile, Lines.ToArray()); Missing.Add(ThisFile); } } Log("Normal Copyright *************************"); foreach (var ThisFile in Normal) { Log(" {0}", ThisFile); } Log("Missing Copyright *************************"); foreach (var ThisFile in Missing) { Log(" {0}", ThisFile); } }
public static List <string> FindTempStorageManifests(CommandEnvironment Env, string StorageBlockName, bool LocalOnly = false, bool SharedOnly = false, string GameFolder = "") { var Files = new List <string>(); var LocalFiles = LocalTempStorageManifestFilename(Env, StorageBlockName); var LocalParent = Path.GetDirectoryName(LocalFiles); var WildCard = Path.GetFileName(LocalFiles); int IndexOfStar = WildCard.IndexOf("*"); if (IndexOfStar < 0 || WildCard.LastIndexOf("*") != IndexOfStar) { throw new AutomationException("Wildcard {0} either has no star or it has more than one.", WildCard); } string PreStarWildcard = WildCard.Substring(0, IndexOfStar); string PostStarWildcard = Path.GetFileNameWithoutExtension(WildCard.Substring(IndexOfStar + 1)); if (!SharedOnly && DirectoryExists_NoExceptions(LocalParent)) { foreach (var ThisFile in CommandUtils.FindFiles_NoExceptions(WildCard, true, LocalParent)) { Log(" Found local file {0}", ThisFile); int IndexOfWildcard = ThisFile.IndexOf(PreStarWildcard); if (IndexOfWildcard < 0) { throw new AutomationException("File {0} didn't contain {1}.", ThisFile, PreStarWildcard); } int LastIndexOfWildcardTail = ThisFile.LastIndexOf(PostStarWildcard); if (LastIndexOfWildcardTail < 0 || LastIndexOfWildcardTail < IndexOfWildcard + PreStarWildcard.Length) { throw new AutomationException("File {0} didn't contain {1} or it was before the prefix", ThisFile, PostStarWildcard); } string StarReplacement = ThisFile.Substring(IndexOfWildcard + PreStarWildcard.Length, LastIndexOfWildcardTail - IndexOfWildcard - PreStarWildcard.Length); if (StarReplacement.Length < 1) { throw new AutomationException("Dir {0} didn't have any string to fit the star in the wildcard {1}", ThisFile, WildCard); } if (!Files.Contains(StarReplacement)) { Files.Add(StarReplacement); } } } if (!LocalOnly) { var SharedFiles = SharedTempStorageManifestFilename(Env, StorageBlockName, GameFolder); var SharedParent = Path.GetDirectoryName(Path.GetDirectoryName(SharedFiles)); if (DirectoryExists_NoExceptions(SharedParent)) { string[] Dirs = null; try { Dirs = Directory.GetDirectories(SharedParent, Path.GetFileNameWithoutExtension(SharedFiles), SearchOption.TopDirectoryOnly); } catch (Exception Ex) { Log("Unable to Find Directories in {0} with wildcard {1}", SharedParent, Path.GetFileNameWithoutExtension(SharedFiles)); Log(" Exception was {0}", LogUtils.FormatException(Ex)); } if (Dirs != null) { foreach (var ThisSubDir in Dirs) { int IndexOfWildcard = ThisSubDir.IndexOf(PreStarWildcard); if (IndexOfWildcard < 0) { throw new AutomationException("Dir {0} didn't contain {1}.", ThisSubDir, PreStarWildcard); } int LastIndexOfWildcardTail = ThisSubDir.LastIndexOf(PostStarWildcard); if (LastIndexOfWildcardTail < 0 || LastIndexOfWildcardTail < IndexOfWildcard + PreStarWildcard.Length) { throw new AutomationException("Dir {0} didn't contain {1} or it was before the prefix", ThisSubDir, PostStarWildcard); } string StarReplacement = ThisSubDir.Substring(IndexOfWildcard + PreStarWildcard.Length, LastIndexOfWildcardTail - IndexOfWildcard - PreStarWildcard.Length); if (StarReplacement.Length < 1) { throw new AutomationException("Dir {0} didn't have any string to fit the star in the wildcard {1}", ThisSubDir, WildCard); } // these are a bunch of false positives if (StarReplacement.Contains("-")) { continue; } if (!Files.Contains(StarReplacement)) { Files.Add(StarReplacement); } } } } } var OutFiles = new List <string>(); foreach (var StarReplacement in Files) { var NewBlock = StorageBlockName.Replace("*", StarReplacement); if (TempStorageExists(Env, NewBlock, GameFolder, LocalOnly, true)) { OutFiles.Add(StarReplacement); } } return(OutFiles); }
/// <summary> Returns the directory list for this digital resource </summary> /// <param name="Tracer"> Trace object keeps a list of each method executed and important milestones in rendering </param> /// <returns> HTML string with the directory list for this digital resource </returns> public string Directory_String(Custom_Tracer Tracer) { if (Tracer != null) { Tracer.Add_Trace("Tracking_ItemViewer.Directory_String", "Pulling and displaying files in the image directory"); } try { string directory = SobekCM_Library_Settings.Image_Server_Network + CurrentItem.Web.AssocFilePath; string url = SobekCM_Library_Settings.Image_URL + CurrentItem.Web.AssocFilePath; FileInfo[] files = (new DirectoryInfo(directory)).GetFiles(); StringBuilder builder = new StringBuilder(3000); // Get all the file info objects and order by name SortedList <string, FileInfo> sortedFiles = new SortedList <string, FileInfo>(); foreach (FileInfo thisFile in files) { sortedFiles.Add(thisFile.Name.ToUpper(), thisFile); } // Remove the THUMBS.DB file, if it exists if (sortedFiles.ContainsKey("THUMBS.DB")) { sortedFiles.Remove("THUMBS.DB"); } // Start the file table builder.AppendLine("<br />"); builder.AppendLine("<br />"); builder.AppendLine("<blockquote>"); builder.AppendLine(" <a href=\"" + directory + "\">" + directory + "</a>"); builder.AppendLine("</blockquote>"); builder.AppendLine("<blockquote>"); // Add all the page images first List <abstract_TreeNode> nodes = CurrentItem.Divisions.Physical_Tree.Pages_PreOrder; if ((nodes != null) && (nodes.Count > 0)) { builder.AppendLine("<span style=\"font-size:1.4em; color:#888888;\"><b>PAGE FILES</b></span><br />"); builder.AppendLine("<table border=\"0px\" cellspacing=\"0px\" class=\"statsTable\">"); builder.AppendLine("<tr align=\"left\" bgcolor=\"#0022a7\" height=\"20px\" >"); builder.AppendLine("<th align=\"left\"><span style=\"color: White\">NAME</span></th>"); builder.AppendLine("<th width=\"10px\"> </th>"); builder.AppendLine("<th align=\"left\" width=\"170px\"><span style=\"color: White\">DATE MODIFIED</span></th>"); builder.AppendLine("<th align=\"left\" width=\"180px\"><span style=\"color: White\">TYPE</span></th>"); builder.AppendLine("<th width=\"10px\"> </th>"); builder.AppendLine("<th align=\"right\"><span style=\"color: White\">SIZE</span></th>"); builder.AppendLine("</tr>"); List <string> file_names_added = new List <string>(); foreach (Page_TreeNode thisNode in nodes) { // Only show pages with files if (thisNode.Files.Count > 0) { // Ensure that if a page is repeated, it only is written once string[] filename_splitter = thisNode.Files[0].System_Name.Split(".".ToCharArray()); string fileName = filename_splitter[0].ToUpper(); if (filename_splitter.Length > 1) { fileName = filename_splitter[filename_splitter.Length - 2].ToUpper(); } if (!file_names_added.Contains(fileName)) { file_names_added.Add(fileName); builder.AppendLine("<tr align=\"left\" bgcolor=\"#7d90d5\">"); string pageName = thisNode.Label; if (pageName.Length == 0) { pageName = "PAGE"; } builder.AppendLine("<td colspan=\"6\" ><span style=\"color: White\"><b>" + pageName.ToUpper() + "</b></span></td>"); builder.AppendLine("</tr>"); // Now, check for each file foreach (SobekCM_File_Info thisFile in thisNode.Files) { string thisFileUpper = thisFile.System_Name.ToUpper(); if (sortedFiles.ContainsKey(thisFileUpper)) { // string file = SobekCM_Library_Settings.Image_Server_Network + CurrentItem.Web.AssocFilePath + thisFile.System_Name; Add_File_HTML(sortedFiles[thisFileUpper], builder, url, true); sortedFiles.Remove(thisFileUpper); } } // Ensure that there still aren't some page files that exist that were not linked string[] other_page_file_endings = new[] { ".JPG", ".JP2", "THM.JPG", ".TXT", ".PRO", ".QC.JPG" }; foreach (string thisFileEnder in other_page_file_endings) { if (sortedFiles.ContainsKey(fileName.ToUpper() + thisFileEnder)) { //string file = SobekCM_Library_Settings.Image_Server_Network + CurrentItem.Web.AssocFilePath + fileName + thisFileEnder.ToLower(); Add_File_HTML(sortedFiles[fileName.ToUpper() + thisFileEnder], builder, url, true); sortedFiles.Remove(fileName.ToUpper() + thisFileEnder); } } } } } // FInish the table builder.AppendLine("</table>"); builder.AppendLine("<br /><br />"); } // Add all the metadata files builder.AppendLine("<span style=\"font-size:1.4em; color:#888888;\"><b>METADATA FILES</b></span><br />"); builder.AppendLine("<table border=\"0px\" cellspacing=\"0px\" class=\"statsTable\">"); builder.AppendLine("<tr align=\"left\" bgcolor=\"#0022a7\" height=\"20px\" >"); builder.AppendLine("<th align=\"left\"><span style=\"color: White\">NAME</span></th>"); builder.AppendLine("<th width=\"10px\"> </th>"); builder.AppendLine("<th align=\"left\" width=\"170px\"><span style=\"color: White\">DATE MODIFIED</span></th>"); builder.AppendLine("<th align=\"left\" width=\"180px\"><span style=\"color: White\">TYPE</span></th>"); builder.AppendLine("<th width=\"10px\"> </th>"); builder.AppendLine("<th align=\"right\"><span style=\"color: White\">SIZE</span></th>"); builder.AppendLine("</tr>"); // Add each metadata file List <string> files_handled = new List <string>(); foreach (string thisFile in sortedFiles.Keys.Where(ThisFile => (ThisFile.IndexOf(".METS.BAK") > 0) || (ThisFile.IndexOf(".METS.XML") > 0) || (ThisFile == "DOC.XML") || (ThisFile == "MARC.XML") || (ThisFile == "CITATION_METS.XML") || (ThisFile == CurrentItem.BibID.ToUpper() + "_" + CurrentItem.VID + ".HTML"))) { files_handled.Add(thisFile); Add_File_HTML(sortedFiles[thisFile], builder, url, true); } // REmove all handled files foreach (string thisKey in files_handled) { sortedFiles.Remove(thisKey); } // FInish the table builder.AppendLine("</table>"); builder.AppendLine("<br /><br />"); // Finally, add all the remaining files if (sortedFiles.Count > 0) { builder.AppendLine("<span style=\"font-size:1.4em; color:#888888;\"><b>OTHER FILES</b></span><br />"); builder.AppendLine("<table border=\"0px\" cellspacing=\"0px\" class=\"statsTable\">"); builder.AppendLine("<tr align=\"left\" bgcolor=\"#0022a7\" height=\"20px\" >"); builder.AppendLine("<th align=\"left\"><span style=\"color: White\">NAME</span></th>"); builder.AppendLine("<th width=\"10px\"> </th>"); builder.AppendLine("<th align=\"left\" width=\"170px\"><span style=\"color: White\">DATE MODIFIED</span></th>"); builder.AppendLine("<th align=\"left\" width=\"180px\"><span style=\"color: White\">TYPE</span></th>"); builder.AppendLine("<th width=\"10px\"> </th>"); builder.AppendLine("<th align=\"right\"><span style=\"color: White\">SIZE</span></th>"); builder.AppendLine("</tr>"); // Now add all the information foreach (FileInfo thisFile in sortedFiles.Values) { Add_File_HTML(thisFile, builder, url, true); } // FInish the table builder.AppendLine("</table>"); } builder.AppendLine("</blockquote>"); builder.AppendLine("<br />"); return(builder.ToString()); } catch { return("<br /><center><strong>UNABLE TO PULL DIRECTORY INFORMATION</strong></center><br />"); } }
/// <summary> Write the item viewer main section as HTML directly to the HTTP output stream </summary> /// <param name="Output"> Response stream for the item viewer to write directly to </param> /// <param name="Tracer"> Trace object keeps a list of each method executed and important milestones in rendering </param> public override void Write_Main_Viewer_Section(TextWriter Output, Custom_Tracer Tracer) { Tracer.Add_Trace("Directory_ItemViewer.Write_Main_Viewer_Section", ""); // Add the HTML for the image Output.WriteLine("<!-- DIRECTORY ITEM VIEWER OUTPUT -->"); // Start the citation table Output.WriteLine(" <td align=\"left\"><span class=\"sbkTrk_ViewerTitle\">Tracking Information</span></td>"); Output.WriteLine("</tr>"); Output.WriteLine("<tr>"); Output.WriteLine(" <td class=\"sbkTrk_MainArea\">"); // Add the tabs for related admin viewers (if they exist) Tracking_ItemViewer.Write_Tracking_Tabs(Output, CurrentRequest, BriefItem); Tracer.Add_Trace("Directory_ItemViewer.Directory_String", "Pulling and displaying files in the image directory"); try { string directory = SobekFileSystem.Resource_Network_Uri(BriefItem); string url = SobekFileSystem.Resource_Web_Uri(BriefItem); List <SobekFileSystem_FileInfo> files = SobekFileSystem.GetFiles(BriefItem); // Get all the file info objects and order by name SortedList <string, SobekFileSystem_FileInfo> sortedFiles = new SortedList <string, SobekFileSystem_FileInfo>(); foreach (SobekFileSystem_FileInfo thisFile in files) { sortedFiles.Add(thisFile.Name.ToUpper(), thisFile); } // Remove the THUMBS.DB file, if it exists if (sortedFiles.ContainsKey("THUMBS.DB")) { sortedFiles.Remove("THUMBS.DB"); } // Start the file table Output.WriteLine("<br />"); Output.WriteLine("<br />"); Output.WriteLine("<blockquote>"); Output.WriteLine(" <a href=\"" + directory + "\">" + directory + "</a>"); Output.WriteLine("</blockquote>"); Output.WriteLine("<blockquote>"); // Add all the page images first List <BriefItem_FileGrouping> nodes = BriefItem.Images; if ((nodes != null) && (nodes.Count > 0)) { Output.WriteLine("<span style=\"font-size:1.4em; color:#888888;\"><b>PAGE FILES</b></span><br />"); Output.WriteLine("<table border=\"0px\" cellspacing=\"0px\" class=\"statsTable\">"); Output.WriteLine("<tr align=\"left\" bgcolor=\"#0022a7\" height=\"20px\" >"); Output.WriteLine("<th align=\"left\"><span style=\"color: White\">NAME</span></th>"); Output.WriteLine("<th width=\"10px\"> </th>"); Output.WriteLine("<th align=\"left\" width=\"170px\"><span style=\"color: White\">DATE MODIFIED</span></th>"); Output.WriteLine("<th align=\"left\" width=\"180px\"><span style=\"color: White\">TYPE</span></th>"); Output.WriteLine("<th width=\"10px\"> </th>"); Output.WriteLine("<th align=\"right\"><span style=\"color: White\">SIZE</span></th>"); Output.WriteLine("</tr>"); List <string> file_names_added = new List <string>(); foreach (BriefItem_FileGrouping thisNode in nodes) { // Only show pages with files if (thisNode.Files.Count > 0) { // Ensure that if a page is repeated, it only is written once string[] filename_splitter = thisNode.Files[0].Name.Split(".".ToCharArray()); string fileName = filename_splitter[0].ToUpper(); if (filename_splitter.Length > 1) { fileName = filename_splitter[filename_splitter.Length - 2].ToUpper(); } if (!file_names_added.Contains(fileName)) { file_names_added.Add(fileName); Output.WriteLine("<tr align=\"left\" bgcolor=\"#7d90d5\">"); string pageName = thisNode.Label; if (pageName.Length == 0) { pageName = "PAGE"; } Output.WriteLine("<td colspan=\"6\" ><span style=\"color: White\"><b>" + pageName.ToUpper() + "</b></span></td>"); Output.WriteLine("</tr>"); // Now, check for each file foreach (BriefItem_File thisFile in thisNode.Files) { string thisFileUpper = thisFile.Name.ToUpper(); if (sortedFiles.ContainsKey(thisFileUpper)) { // string file = UI_ApplicationCache_Gateway.Settings.Servers.Image_Server_Network + currentItem.Web.AssocFilePath + thisFile.System_Name; Add_File_HTML(sortedFiles[thisFileUpper], Output, url, true); sortedFiles.Remove(thisFileUpper); } } // Ensure that there still aren't some page files that exist that were not linked string[] other_page_file_endings = { ".JPG", ".JP2", "THM.JPG", ".TXT", ".PRO", ".QC.JPG" }; foreach (string thisFileEnder in other_page_file_endings) { if (sortedFiles.ContainsKey(fileName.ToUpper() + thisFileEnder)) { //string file = UI_ApplicationCache_Gateway.Settings.Servers.Image_Server_Network + currentItem.Web.AssocFilePath + fileName + thisFileEnder.ToLower(); Add_File_HTML(sortedFiles[fileName.ToUpper() + thisFileEnder], Output, url, true); sortedFiles.Remove(fileName.ToUpper() + thisFileEnder); } } } } } // FInish the table Output.WriteLine("</table>"); Output.WriteLine("<br /><br />"); } // Add all the metadata files Output.WriteLine("<span style=\"font-size:1.4em; color:#888888;\"><b>METADATA FILES</b></span><br />"); Output.WriteLine("<table border=\"0px\" cellspacing=\"0px\" class=\"statsTable\">"); Output.WriteLine("<tr align=\"left\" bgcolor=\"#0022a7\" height=\"20px\" >"); Output.WriteLine("<th align=\"left\"><span style=\"color: White\">NAME</span></th>"); Output.WriteLine("<th width=\"10px\"> </th>"); Output.WriteLine("<th align=\"left\" width=\"170px\"><span style=\"color: White\">DATE MODIFIED</span></th>"); Output.WriteLine("<th align=\"left\" width=\"180px\"><span style=\"color: White\">TYPE</span></th>"); Output.WriteLine("<th width=\"10px\"> </th>"); Output.WriteLine("<th align=\"right\"><span style=\"color: White\">SIZE</span></th>"); Output.WriteLine("</tr>"); // Add each metadata file List <string> files_handled = new List <string>(); foreach (string thisFile in sortedFiles.Keys.Where(ThisFile => (ThisFile.IndexOf(".METS.BAK") > 0) || (ThisFile.IndexOf(".METS.XML") > 0) || (ThisFile == "DOC.XML") || (ThisFile == "MARC.XML") || (ThisFile == "CITATION_METS.XML") || (ThisFile == BriefItem.BibID.ToUpper() + "_" + BriefItem.VID + ".HTML"))) { files_handled.Add(thisFile); Add_File_HTML(sortedFiles[thisFile], Output, url, true); } // REmove all handled files foreach (string thisKey in files_handled) { sortedFiles.Remove(thisKey); } // FInish the table Output.WriteLine("</table>"); Output.WriteLine("<br /><br />"); // Finally, add all the remaining files if (sortedFiles.Count > 0) { Output.WriteLine("<span style=\"font-size:1.4em; color:#888888;\"><b>OTHER FILES</b></span><br />"); Output.WriteLine("<table border=\"0px\" cellspacing=\"0px\" class=\"statsTable\">"); Output.WriteLine("<tr align=\"left\" bgcolor=\"#0022a7\" height=\"20px\" >"); Output.WriteLine("<th align=\"left\"><span style=\"color: White\">NAME</span></th>"); Output.WriteLine("<th width=\"10px\"> </th>"); Output.WriteLine("<th align=\"left\" width=\"170px\"><span style=\"color: White\">DATE MODIFIED</span></th>"); Output.WriteLine("<th align=\"left\" width=\"180px\"><span style=\"color: White\">TYPE</span></th>"); Output.WriteLine("<th width=\"10px\"> </th>"); Output.WriteLine("<th align=\"right\"><span style=\"color: White\">SIZE</span></th>"); Output.WriteLine("</tr>"); // Now add all the information foreach (SobekFileSystem_FileInfo thisFile in sortedFiles.Values) { Add_File_HTML(thisFile, Output, url, true); } // FInish the table Output.WriteLine("</table>"); } Output.WriteLine("</blockquote>"); Output.WriteLine("<br />"); } catch { Output.WriteLine("<br /><center><strong>UNABLE TO PULL DIRECTORY INFORMATION</strong></center><br />"); } Output.WriteLine(" </td>"); Output.WriteLine(" <!-- END DIRECTORY VIEWER OUTPUT -->"); }