private static void Main(string[] args) { try { string ProjType = args[0]; string binaryFilePath = args[1]; string ProjectPath = args[2]; string OutIncludePath = args[3]; string OutFileExt = args[5].Substring(1); string OutBinaryPath = args[4].Replace("{gen_type}", OutFileExt); if (ProjType == "application") { Console.WriteLine("无需操作"); } Directory.CreateDirectory(GetDirectory(OutIncludePath)); Directory.CreateDirectory(GetDirectory(OutBinaryPath)); File.Copy(binaryFilePath, OutBinaryPath, true); Dictionary <string, HeaderFile> dict = new Dictionary <string, Program.HeaderFile>(); List <HeaderFile> list = new List <HeaderFile>(); foreach (var file in Directory.GetFiles(ProjectPath)) { if (file.EndsWith(".h")) { var header = new HeaderFile(file); dict.Add(file, header); list.Add(header); } } var HasTop = list.Aggregate(false, (bool all, HeaderFile next) => { return(all || next.isTop); }); if (!HasTop) { Console.WriteLine("[警告]可能出现了环形包含,建议检查代码"); } StreamWriter streamWriter = new StreamWriter(OutIncludePath, false, Encoding.UTF8); var topHeaders = list.Where(e => e.isTop); AppendFileToStream(topHeaders, dict, streamWriter); var headers = list.Where(e => !e.loaded); Program.AppendFileToStream(headers, dict, streamWriter); streamWriter.Close(); Console.WriteLine("OK."); } catch (Exception ex) { Console.WriteLine("=================================================="); Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); Console.WriteLine("=================================================="); throw; } }
/// <summary> /// Compresses the LZB file. /// </summary> /// <param name="clean">True for cleaning up the remains of the decompression.</param> /// <returns></returns> public bool Compress(bool clean = true) { if (DecompressedFile == null || HeaderFile == null) { return(false); } if (!DecompressedFile.Exists() || !HeaderFile.Exists()) { return(false); } byte[] buffer; using (BinaryReader reader = new BinaryReader(new FileStream(HeaderFile.FilePath, FileMode.Open))) { buffer = new byte[16]; reader.Read(buffer, 0, 16); LZSSHeader.Load(buffer); } using (BinaryReader reader = new BinaryReader(new FileStream(DecompressedFile.FilePath, FileMode.Open))) { int bufferLength = (int)reader.BaseStream.Length; buffer = new byte[bufferLength]; reader.Read(buffer, 0, bufferLength); LZSSHeader.UncompressedSize = (uint)bufferLength; } byte mode = LZSSHeader.Mode; if (clean) { DecompressedFile.Delete(); DecompressedFile = null; HeaderFile.Delete(); HeaderFile = null; } switch (mode) { default: MessageBox.Show("Not a valid LZSS-bu2 mode number!\nOnly possible modes are 0, 1 and 2.", "Sorry!"); return(false); case 0: compress_Mode0(buffer); break; case 1: compress_Mode(buffer, 1, 256); break; case 2: compress_Mode(buffer, 2, 4096); break; } return(true); }
private Markup WriteDefaultMarkup() { Markup markup = new Markup(); try { HeaderFile[] headerfiles = new HeaderFile[1]; HeaderFile header = new HeaderFile(); header.IfcProject = GUIDUtil.CreateGUID(m_doc.ProjectInformation); header.Filename = m_doc.Title; header.Date = DateTime.Now; headerfiles[0] = header; markup.Header = headerfiles; Topic topic = new Topic(); topic.Guid = Guid.NewGuid().ToString(); topic.Title = "Color Schemes Editor"; BimSnippet bimSnippet = new BimSnippet(); string currentAssembly = System.Reflection.Assembly.GetAssembly(this.GetType()).Location; string schemaPath = Path.GetDirectoryName(currentAssembly) + "\\Resources\\colorscheme.xsd"; bimSnippet.ReferenceSchema = schemaPath; bimSnippet.Reference = "colorscheme.xml"; topic.BimSnippet = bimSnippet; markup.Topic = topic; Comment[] comments = new Comment[1]; Comment comment = new Comment(); comment.Guid = Guid.NewGuid().ToString(); comment.Date = header.Date; comment.Author = Environment.UserName; comment.Comment1 = "Color Schemes and Color Filters by Add-Ins"; CommentTopic commentTopic = new CommentTopic(); commentTopic.Guid = topic.Guid; comment.Topic = commentTopic; comments[0] = comment; markup.Comment = comments; } catch (Exception ex) { MessageBox.Show("Failed to wirte the default Markup.\n" + ex.Message, "Write Default Markup", MessageBoxButton.OK, MessageBoxImage.Warning); } return(markup); }
private void ReadHeaderIdentify() { loadWaitWorker.ReportProgress(-1, "Reading header data..."); if (!File.Exists(Path.Combine(DataPath, "header.bin"))) { throw new GameDataManagerException("File header.bin could not be found."); } Header = new HeaderFile(this, Path.Combine(DataPath, "header.bin")); switch (Header.GameCode) { case "AKYP": Version = Versions.European; MainFontFilename = "data\\Data\\Tex\\Font\\Font14x11_00"; SmallFontFilename = "data\\Data\\Tex\\Font\\Font10x9_00"; MainFontInfoOffset = 0xB79B4; SmallFontInfoOffset = MainFontInfoOffset + 0x180; break; case "AKYE": Version = Versions.American; MainFontFilename = "data\\Data\\Tex\\Font\\Font10x5_00"; SmallFontFilename = "data\\Data\\Tex\\Font\\Font8x4_00"; MainFontInfoOffset = 0xD5C04; SmallFontInfoOffset = MainFontInfoOffset + 0xC0; break; case "AKYJ": Version = Versions.Japanese; MainFontFilename = "data\\Data\\Tex\\Font\\Font10x10_00"; SmallFontFilename = "data\\Data\\Tex\\Font\\Font8x8_00"; MainFontInfoOffset = SmallFontInfoOffset = -1; break; default: throw new GameDataManagerException("Unsupported game data."); } Program.Logger.LogMessage("Identified game '{0} {1}' as {2} version.", Header.GameTitle, Header.GameCode, Version); }
public void RandomizeAllFiles(string directory, string outDir) { // Every .h foreach (string str in Directory.EnumerateFiles(string.Concat(directory, "src/"), "*.h", SearchOption.AllDirectories)) { string str1 = str.Replace(string.Concat(directory, "src/"), ""); Directory.CreateDirectory(string.Concat(outDir, Path.GetDirectoryName(str1))); HeaderFile headerFile = new HeaderFile(str); headerFile.AddJunkCode(); File.WriteAllText(string.Concat(outDir, str1), headerFile.GetData()); } // Every .cpp foreach (string str2 in Directory.EnumerateFiles(string.Concat(directory, "src/"), "*.cpp", SearchOption.AllDirectories)) { string str3 = str2.Replace(string.Concat(directory, "src/"), ""); Directory.CreateDirectory(string.Concat(outDir, Path.GetDirectoryName(str3))); CppFile cppFile = new CppFile(str2); cppFile.AddJunkCode(); File.WriteAllText(string.Concat(outDir, str3), cppFile.GetData()); } }
/// <summary> /// /// </summary> private void ReadTemplate() { if (cmbTemplate.SelectedIndex != 0) { if (Template.FieldsTemplate.Count != 0) { var header = Template.FieldsTemplate.Where(m => m.Destination.Equals("SDSDNM")) .Select(m => m.Source).FirstOrDefault(); if (!string.IsNullOrWhiteSpace(header)) { if (HeaderFile.Contains(header)) { cmbNameField.Text = header; } else { cmbNameField.SelectedIndex = 0; } } else { cmbNameField.SelectedIndex = 0; } cmbNameField.Enabled = false; header = Template.FieldsTemplate.Where(m => m.Destination.Equals("SDSDON")) .Select(m => m.Source).FirstOrDefault(); if (!string.IsNullOrWhiteSpace(header)) { if (HeaderFile.Contains(header)) { cmbOldCodeField.Text = header; } else { cmbOldCodeField.SelectedIndex = 0; } } else { cmbOldCodeField.SelectedIndex = 0; } cmbOldCodeField.Enabled = false; header = Template.FieldsTemplate.Where(m => m.Destination.Equals("SDADD1")) .Select(m => m.Source).FirstOrDefault(); if (!string.IsNullOrWhiteSpace(header)) { if (HeaderFile.Contains(header)) { cmbAdd1Field.Text = header; } else { cmbAdd1Field.SelectedIndex = 0; } } else { cmbAdd1Field.SelectedIndex = 0; } cmbAdd1Field.Enabled = false; header = Template.FieldsTemplate.Where(m => m.Destination.Equals("SDADD2")) .Select(m => m.Source).FirstOrDefault(); if (!string.IsNullOrWhiteSpace(header)) { if (HeaderFile.Contains(header)) { cmbAdd2Field.Text = header; } else { cmbAdd2Field.SelectedIndex = 0; } } else { cmbAdd2Field.SelectedIndex = 0; } cmbAdd2Field.Enabled = false; header = Template.FieldsTemplate.Where(m => m.Destination.Equals("SDCITY")) .Select(m => m.Source).FirstOrDefault(); if (!string.IsNullOrWhiteSpace(header)) { if (HeaderFile.Contains(header)) { cmbCityField.Text = header; } else { cmbCityField.SelectedIndex = 0; } } else { cmbCityField.SelectedIndex = 0; } cmbCityField.Enabled = false; header = Template.FieldsTemplate.Where(m => m.Destination.Equals("SDZPCD")) .Select(m => m.Source).FirstOrDefault(); if (!string.IsNullOrWhiteSpace(header)) { if (HeaderFile.Contains(header)) { cmbZipCodeField.Text = header; } else { cmbZipCodeField.SelectedIndex = 0; } } else { cmbZipCodeField.SelectedIndex = 0; } cmbZipCodeField.Enabled = false; header = Template.FieldsTemplate.Where(m => m.Destination.Equals("SDPHN1")) .Select(m => m.Source).FirstOrDefault(); if (!string.IsNullOrWhiteSpace(header)) { if (HeaderFile.Contains(header)) { cmbPhone1Field.Text = header; } else { cmbPhone1Field.SelectedIndex = 0; } } else { cmbPhone1Field.SelectedIndex = 0; } cmbPhone1Field.Enabled = false; header = Template.FieldsTemplate.Where(m => m.Destination.Equals("SDFAX1")) .Select(m => m.Source).FirstOrDefault(); if (!string.IsNullOrWhiteSpace(header)) { if (HeaderFile.Contains(header)) { cmbFax1Field.Text = header; } else { cmbFax1Field.SelectedIndex = 0; } } else { cmbFax1Field.SelectedIndex = 0; } cmbFax1Field.Enabled = false; } } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void BackgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { if (sender == bgwWorker) { if (!e.Cancelled) { Flag idx = Flag.IDLE; try { idx = (Flag)e.Result; if (idx != Flag.IDLE) { switch (idx) { case Flag.FormLoading: btnBrowse.Enabled = true; tspProgress.Visible = false; tsxStatus.Text = MasterModule.Handler.Resources.GetString("Ready"); break; case Flag.FileLoading: cmbSheet.DataSource = new BindingSource(Processor.GetSheets(), null); cmbSheet.DisplayMember = "Value"; cmbSheet.ValueMember = "Key"; cmbSheet.SelectedIndex = 0; break; case Flag.SheetLoading: if (HeaderFile != null) { HeaderFile.Clear(); } HeaderFile = Processor.GetHeaders(cmbSheet.SelectedValue.ToString()); HeaderFile.Insert(0, string.Format(MasterModule.Handler.Resources.GetString("Select_Item"), string.Empty)); cmbOldCodeField.DataSource = new List <string>(HeaderFile); cmbNameField.DataSource = new List <string>(HeaderFile); cmbAdd1Field.DataSource = new List <string>(HeaderFile); cmbAdd2Field.DataSource = new List <string>(HeaderFile); cmbCityField.DataSource = new List <string>(HeaderFile); cmbZipCodeField.DataSource = new List <string>(HeaderFile); cmbPhone1Field.DataSource = new List <string>(HeaderFile); cmbFax1Field.DataSource = new List <string>(HeaderFile); cmbTemplate.DataSource = Templates; //cmbTemplate.ValueMember = "Code"; if (Templates.Count == 1) { if (!string.IsNullOrWhiteSpace(Templates[0].Code)) { cmbTemplate.Enabled = true; } } else { cmbTemplate.Enabled = true; } cmbTemplate.SelectedIndex = 0; cmbSheet.Enabled = pnlField.Enabled = btnShowData.Enabled = true; crlFieldLoading.Visible = false; break; case Flag.TemplateLoading: ReadTemplate(); break; case Flag.DataLoading: if (MappingValid()) { if (MappingValue()) { dgvData.DataSource = null; dgvData.DataSource = new BindingList <SubdepoDto>(Data); pnlData.Enabled = true; if (Data.Count != 0) { btnSave.Enabled = true; } MappingTemplate(); } } else { pnlData.Enabled = false; } pnlField.Enabled = btnShowData.Enabled = true; crlDataLoading.Visible = false; break; case Flag.DataSaving: if (TResult.Equals("0")) { if (cmbTemplate.SelectedIndex == 0) { if (MessageBox.Show(this, "Do you want to save this template?", MasterModule.Name, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { TResult = string.Empty; tsxStatus.Text = "Saving Template..."; tspProgress.Visible = true; tspProgress.Value = 0; if (!bgwWorker.IsBusy) { bgwWorker.RunWorkerAsync(Flag.TemplateSaving); } } else { this.Close(); } } else { this.Close(); } } break; case Flag.TemplateSaving: if (TResult.Equals("0")) { tsxStatus.Text = "Complete all task"; tspProgress.Visible = false; try { Thread.Sleep(1000); } catch { } this.Close(); } break; } } } catch (Exception ex) { MessageBox.Show(ex.Message); } } else { MessageBox.Show(e.Result.ToString()); } } }
public override void ExecuteBuild() { string[] ProjectParams = ParseParamValues("Project"); string UpdateDirParam = ParseParamValue("UpdateDir", null); if (UpdateDirParam == null) { throw new AutomationException("Missing -UpdateDir=... parameter"); } DirectoryReference UpdateDir = new DirectoryReference(UpdateDirParam); bool bWrite = ParseParam("Write"); // Get all the root dirs HashSet <DirectoryReference> RootDirs = new HashSet <DirectoryReference>(); RootDirs.Add(EngineDirectory); // Add the enterprise edirectory DirectoryReference EnterpriseDirectory = DirectoryReference.Combine(RootDirectory, "Enterprise"); if (DirectoryReference.Exists(EnterpriseDirectory)) { RootDirs.Add(EnterpriseDirectory); } // Add the project directories foreach (string ProjectParam in ProjectParams) { FileReference ProjectLocation = new FileReference(ProjectParam); if (!FileReference.Exists(ProjectLocation)) { throw new AutomationException("Unable to find project '{0}'", ProjectLocation); } RootDirs.Add(ProjectLocation.Directory); } // Find all the modules HashSet <DirectoryReference> ModuleDirs = new HashSet <DirectoryReference>(); foreach (DirectoryReference RootDir in RootDirs) { // Find all the modules from the source folder DirectoryReference SourceDir = DirectoryReference.Combine(RootDir, "Source"); if (DirectoryReference.Exists(SourceDir)) { foreach (FileReference ModuleFile in DirectoryReference.EnumerateFiles(SourceDir, "*.Build.cs", SearchOption.AllDirectories)) { ModuleDirs.Add(ModuleFile.Directory); } } // Find all the modules under the plugins folder DirectoryReference PluginsDir = DirectoryReference.Combine(RootDir, "Plugins"); foreach (FileReference PluginFile in DirectoryReference.EnumerateFiles(PluginsDir, "*.uplugin", SearchOption.AllDirectories)) { DirectoryReference PluginSourceDir = DirectoryReference.Combine(PluginFile.Directory, "Source"); if (DirectoryReference.Exists(PluginSourceDir)) { foreach (FileReference PluginModuleFile in DirectoryReference.EnumerateFiles(PluginSourceDir, "*.Build.cs", SearchOption.AllDirectories)) { ModuleDirs.Add(PluginModuleFile.Directory); } } } } // Find a mapping from old to new include paths Dictionary <string, Tuple <string, FileReference> > RemapIncludePaths = new Dictionary <string, Tuple <string, FileReference> >(StringComparer.InvariantCultureIgnoreCase); foreach (DirectoryReference ModuleDir in ModuleDirs) { DirectoryReference ModulePublicDir = DirectoryReference.Combine(ModuleDir, "Public"); if (DirectoryReference.Exists(ModulePublicDir)) { foreach (FileReference HeaderFile in DirectoryReference.EnumerateFiles(ModulePublicDir, "*.h", SearchOption.AllDirectories)) { string BaseIncludeFile = HeaderFile.GetFileName(); Tuple <string, FileReference> ExistingIncludeName; if (RemapIncludePaths.TryGetValue(BaseIncludeFile, out ExistingIncludeName)) { LogWarning("Multiple include paths for {0}: {1}, {2}", BaseIncludeFile, ExistingIncludeName.Item2, HeaderFile); } else { RemapIncludePaths.Add(BaseIncludeFile, Tuple.Create(HeaderFile.MakeRelativeTo(ModulePublicDir).Replace('\\', '/'), HeaderFile)); } } } } // List of folders to exclude from updates string[] ExcludeFoldersFromUpdate = { "Intermediate", "ThirdParty" }; // Enumerate all the files to update HashSet <FileReference> UpdateFiles = new HashSet <FileReference>(); foreach (FileReference UpdateFile in DirectoryReference.EnumerateFiles(UpdateDir, "*", SearchOption.AllDirectories)) { if (!UpdateFile.ContainsAnyNames(ExcludeFoldersFromUpdate, UpdateDir)) { if (UpdateFile.HasExtension(".cpp") | UpdateFile.HasExtension(".h") || UpdateFile.HasExtension(".inl")) { UpdateFiles.Add(UpdateFile); } } } // Process all the source files Dictionary <FileReference, string[]> ModifiedFiles = new Dictionary <FileReference, string[]>(); foreach (FileReference UpdateFile in UpdateFiles) { bool bModifiedFile = false; string[] Lines = FileReference.ReadAllLines(UpdateFile); for (int Idx = 0; Idx < Lines.Length; Idx++) { Match Match = Regex.Match(Lines[Idx], "^(\\s*#\\s*include\\s+\\\")([^\"]+)(\\\".*)$"); if (Match.Success) { string IncludePath = Match.Groups[2].Value; Tuple <string, FileReference> NewIncludePath; if (RemapIncludePaths.TryGetValue(IncludePath, out NewIncludePath)) { if (IncludePath != NewIncludePath.Item1) { // Log("{0}: Changing {1} -> {2}", UpdateFile, IncludePath, NewIncludePath.Item1); Lines[Idx] = String.Format("{0}{1}{2}", Match.Groups[1].Value, NewIncludePath.Item1, Match.Groups[3].Value); bModifiedFile = true; } } } } if (bModifiedFile) { ModifiedFiles.Add(UpdateFile, Lines); } } // Output them all to disk if (bWrite && ModifiedFiles.Count > 0) { LogInformation("Updating {0} files...", ModifiedFiles.Count); List <FileReference> FilesToCheckOut = new List <FileReference>(); foreach (FileReference ModifiedFile in ModifiedFiles.Keys) { if ((FileReference.GetAttributes(ModifiedFile) & FileAttributes.ReadOnly) != 0) { FilesToCheckOut.Add(ModifiedFile); } } if (FilesToCheckOut.Count > 0) { if (!P4Enabled) { throw new AutomationException("{0} files have been modified, but are read only. Run with -P4 to enable Perforce checkout.\n{1}", FilesToCheckOut.Count, String.Join("\n", FilesToCheckOut.Select(x => " " + x))); } LogInformation("Checking out files from Perforce"); int ChangeNumber = P4.CreateChange(Description: "Updating source files"); P4.Edit(ChangeNumber, FilesToCheckOut.Select(x => x.FullName).ToList(), false); } foreach (KeyValuePair <FileReference, string[]> FileToWrite in ModifiedFiles) { LogInformation("Writing {0}", FileToWrite.Key); FileReference.WriteAllLines(FileToWrite.Key, FileToWrite.Value); } } }
/// <summary> /// Checks if the makefile is valid for the current set of source files. This is done separately to the Load() method to allow pre-build steps to modify source files. /// </summary> /// <param name="Makefile">The makefile that has been loaded</param> /// <param name="ProjectFile">Path to the project file</param> /// <param name="WorkingSet">The current working set of source files</param> /// <param name="ReasonNotLoaded">If the makefile is not valid, is set to a message describing why</param> /// <returns>True if the makefile is valid, false otherwise</returns> public static bool IsValidForSourceFiles(TargetMakefile Makefile, FileReference ProjectFile, ISourceFileWorkingSet WorkingSet, out string ReasonNotLoaded) { using (Timeline.ScopeEvent("TargetMakefile.IsValidForSourceFiles()")) { // Check if any source files have been added or removed foreach (KeyValuePair <DirectoryItem, FileItem[]> Pair in Makefile.DirectoryToSourceFiles) { DirectoryItem InputDirectory = Pair.Key; if (!InputDirectory.Exists || InputDirectory.LastWriteTimeUtc > Makefile.CreateTimeUtc) { FileItem[] SourceFiles = UEBuildModuleCPP.GetSourceFiles(InputDirectory); if (SourceFiles.Length < Pair.Value.Length) { ReasonNotLoaded = "source file removed"; return(false); } else if (SourceFiles.Length > Pair.Value.Length) { ReasonNotLoaded = "source file added"; return(false); } else if (SourceFiles.Intersect(Pair.Value).Count() != SourceFiles.Length) { ReasonNotLoaded = "source file modified"; return(false); } } } // Check if any of the additional dependencies has changed foreach (FileItem AdditionalDependency in Makefile.AdditionalDependencies) { if (!AdditionalDependency.Exists) { Log.TraceLog("{0} has been deleted since makefile was built.", AdditionalDependency.Location); ReasonNotLoaded = string.Format("{0} deleted", AdditionalDependency.Location.GetFileName()); return(false); } if (AdditionalDependency.LastWriteTimeUtc > Makefile.CreateTimeUtc) { Log.TraceLog("{0} has been modified since makefile was built.", AdditionalDependency.Location); ReasonNotLoaded = string.Format("{0} modified", AdditionalDependency.Location.GetFileName()); return(false); } } // Check that no new plugins have been added foreach (FileReference PluginFile in Plugins.EnumeratePlugins(ProjectFile)) { FileItem PluginFileItem = FileItem.GetItemByFileReference(PluginFile); if (!Makefile.PluginFiles.Contains(PluginFileItem)) { Log.TraceLog("{0} has been added", PluginFile.GetFileName()); ReasonNotLoaded = string.Format("{0} has been added", PluginFile.GetFileName()); return(false); } } // We do a check to see if any modules' headers have changed which have // acquired or lost UHT types. If so, which should be rare, // we'll just invalidate the entire makefile and force it to be rebuilt. // Get all H files in processed modules newer than the makefile itself HashSet <FileItem> HFilesNewerThanMakefile = new HashSet <FileItem>(); foreach (UHTModuleHeaderInfo ModuleHeaderInfo in Makefile.UObjectModuleHeaders) { foreach (FileItem HeaderFile in ModuleHeaderInfo.SourceFolder.EnumerateFiles()) { if (HeaderFile.HasExtension(".h") && HeaderFile.LastWriteTimeUtc > Makefile.CreateTimeUtc) { HFilesNewerThanMakefile.Add(HeaderFile); } } } // Get all H files in all modules processed in the last makefile build HashSet <FileItem> AllUHTHeaders = new HashSet <FileItem>(Makefile.UObjectModuleHeaders.SelectMany(x => x.HeaderFiles)); // Check whether any headers have been deleted. If they have, we need to regenerate the makefile since the module might now be empty. If we don't, // and the file has been moved to a different module, we may include stale generated headers. foreach (FileItem HeaderFile in AllUHTHeaders) { if (!HeaderFile.Exists) { Log.TraceLog("File processed by UHT was deleted ({0}); invalidating makefile", HeaderFile); ReasonNotLoaded = string.Format("UHT file was deleted"); return(false); } } // Makefile is invalid if: // * There are any newer files which contain no UHT data, but were previously in the makefile // * There are any newer files contain data which needs processing by UHT, but weren't not previously in the makefile SourceFileMetadataCache MetadataCache = SourceFileMetadataCache.CreateHierarchy(ProjectFile); foreach (FileItem HeaderFile in HFilesNewerThanMakefile) { bool bContainsUHTData = MetadataCache.ContainsReflectionMarkup(HeaderFile); bool bWasProcessed = AllUHTHeaders.Contains(HeaderFile); if (bContainsUHTData != bWasProcessed) { Log.TraceLog("{0} {1} contain UHT types and now {2} , ignoring it", HeaderFile, bWasProcessed ? "used to" : "didn't", bWasProcessed ? "doesn't" : "does"); ReasonNotLoaded = string.Format("new files with reflected types"); return(false); } } // If adaptive unity build is enabled, do a check to see if there are any source files that became part of the // working set since the Makefile was created (or, source files were removed from the working set.) If anything // changed, then we'll force a new Makefile to be created so that we have fresh unity build blobs. We always // want to make sure that source files in the working set are excluded from those unity blobs (for fastest possible // iteration times.) // Check if any source files in the working set no longer belong in it foreach (FileItem SourceFile in Makefile.WorkingSet) { if (!WorkingSet.Contains(SourceFile) && SourceFile.LastWriteTimeUtc > Makefile.CreateTimeUtc) { Log.TraceLog("{0} was part of source working set and now is not; invalidating makefile", SourceFile.AbsolutePath); ReasonNotLoaded = string.Format("working set of source files changed"); return(false); } } // Check if any source files that are eligible for being in the working set have been modified foreach (FileItem SourceFile in Makefile.CandidatesForWorkingSet) { if (WorkingSet.Contains(SourceFile) && SourceFile.LastWriteTimeUtc > Makefile.CreateTimeUtc) { Log.TraceLog("{0} was part of source working set and now is not", SourceFile.AbsolutePath); ReasonNotLoaded = string.Format("working set of source files changed"); return(false); } } } ReasonNotLoaded = null; return(true); }
private void OpenImages_button_Click(object sender, EventArgs e) { OpenFileDialog opd1 = new OpenFileDialog(); opd1.Filter = "Header files (*.imgh)|*.imgh|All files (*.*)|*.*"; //opd1.InitialDirectory = AppDomain.CurrentDomain.BaseDirectory; opd1.Multiselect = true; opd1.Title = "Browse multiple Image/Header"; if (opd1.ShowDialog() == DialogResult.OK) { // Directory of the data files string DataDir = ""; // String List containing header text readout from the selected file. List <string> TextReadout = new List <string>(); // Double list containing image frame delays in ms: // delay = Internal_delay + GDT_delay, where // Internal_delay = string #16 // GDT_delay = string #17 List <double> Delays = new List <double>(); // Image size-X: strings #9, 10 Int32 SizeX = 0; // Image size-Y: strings #11, 12 Int32 SizeY = 0; // Height of sub-ROI-Y for calculation of emission profile in the beam edge (top Sub-ROI) and closer to the beam axis (bottom Sub-ROI) string SubROI_str = SubROIY_comboBox.SelectedItem.ToString(); Int32 SubROI = 0; try { if (SubROI_str.Substring(0, 4) != "Full") { SubROI = Convert.ToInt32(SubROI_str.Substring(0, 2)); } } catch (Exception ex) { MessageBox.Show("Cannot read Sub-ROI Y-size. Original error: " + ex.Message); } foreach (string HeaderFile in opd1.FileNames) { try { System.IO.StreamReader sr = System.IO.File.OpenText(HeaderFile); DataDir = System.IO.Path.GetDirectoryName(HeaderFile); TextReadout.Clear(); // Read the image header string str = ""; while ((str = sr.ReadLine()) != null) { TextReadout.Add(str); } sr.Close(); Delays.Add(Convert.ToDouble(TextReadout.ElementAt(16)) + Convert.ToDouble(TextReadout.ElementAt(17))); SizeX = Convert.ToInt32(TextReadout.ElementAt(10)) - Convert.ToInt32(TextReadout.ElementAt(9)) + 1; SizeY = Convert.ToInt32(TextReadout.ElementAt(12)) - Convert.ToInt32(TextReadout.ElementAt(11)) + 1; // Read the image, the file name = the header file name with the last symbol cut (.imgh -> .img) string ImageFileName = HeaderFile.Substring(0, HeaderFile.Length - 1); System.IO.BinaryReader br = new System.IO.BinaryReader(System.IO.File.Open(ImageFileName, System.IO.FileMode.Open)); // Image data List <UInt16> ImageData = new List <UInt16>(); while (br.BaseStream.Position != br.BaseStream.Length) { ImageData.Add(br.ReadUInt16()); } br.Close(); int ReadoutLength = ImageData.Count; //MessageBox.Show("Image samples read: " + (ImageData.Count()-4).ToString() + ", SizeX*SizeY: " + (SizeX*SizeY).ToString() ); // Remove 4 last elements ImageData.RemoveRange(ReadoutLength - 5, 4); double fovx = Convert.ToDouble(FOVX_numericUpDown.Value); double fovy = Convert.ToDouble(FOVY_numericUpDown.Value); // Create curve(s) if (SubROI == 0) // Full size { MakeCurveFromROIdata crv = new MakeCurveFromROIdata(ImageData, SizeX, SizeY); crv.FOVX = fovx; crv.FOVY = fovy; crv.ScaleDimAxis(); // Write point pairs to the text file (.txt) string CurveFileName = ImageFileName.Substring(0, ImageFileName.Length - 3) + "txt"; System.IO.StreamWriter sw = new System.IO.StreamWriter(CurveFileName); sw.Write(crv.Coord + "\n"); for (int ip = 0; ip < crv.Npoints; ip++) { sw.Write(crv.Dimpoints.ElementAt(ip) + " " + crv.Curve.ElementAt(ip) + "\n"); } sw.Close(); } else { if (SizeX > SizeY) // X-profile { // Top sub-ROIY MakeCurveFromROIdata crv1 = new MakeCurveFromROIdata(ImageData.GetRange(0, SizeX * SubROI), SizeX, SubROI); crv1.FOVX = fovx; crv1.FOVY = fovy * SubROI / SizeY; crv1.ScaleDimAxis(); // Bottom sub-ROIY MakeCurveFromROIdata crv2 = new MakeCurveFromROIdata(ImageData.GetRange(SizeX * SizeY - SizeX * SubROI, SizeX * SubROI), SizeX, SubROI); crv2.FOVX = fovx; crv2.FOVY = fovy * SubROI / SizeY; crv2.ScaleDimAxis(); // Write point pairs to the text files (.txt) string CurveFileName1 = ImageFileName.Substring(0, ImageFileName.Length - 4) + "-top.txt"; System.IO.StreamWriter sw1 = new System.IO.StreamWriter(CurveFileName1); sw1.Write(crv1.Coord + "\n"); for (int ip = 0; ip < crv1.Npoints; ip++) { sw1.Write(crv1.Dimpoints.ElementAt(ip) + " " + crv1.Curve.ElementAt(ip) + "\n"); } sw1.Close(); string CurveFileName2 = ImageFileName.Substring(0, ImageFileName.Length - 4) + "-bottom.txt"; System.IO.StreamWriter sw2 = new System.IO.StreamWriter(CurveFileName2); sw2.Write(crv2.Coord + "\n"); for (int ip = 0; ip < crv2.Npoints; ip++) { sw2.Write(crv2.Dimpoints.ElementAt(ip) + " " + crv2.Curve.ElementAt(ip) + "\n"); } sw2.Close(); } else // Y-profile { MessageBox.Show("Y-profiles from two sub-ROIX: not implemented yet."); } } } catch (Exception ex) { MessageBox.Show("Cannot open header/image file. Original error: " + ex.Message); } } // Write the timing file try { System.IO.StreamWriter sw = new System.IO.StreamWriter(DataDir + "\\timing.txt"); foreach (double del in Delays) { sw.Write(del + "\n"); } sw.Close(); } catch (Exception ex) { MessageBox.Show("Cannot create the file for timing entries. Original error: " + ex.Message); } MessageBox.Show("Images processed: " + opd1.FileNames.Count() + ", sub-ROI mode: " + SubROI_str + " (sub-ROI size: " + SubROI.ToString() + ")"); } }