/* * Native Formats * Number of Bits MATLAB Data Type Data Range * 8 uint8 (unsigned integer) 0 <= y <= 255 * 16 int16 (signed integer) -32768 <= y <= +32767 * 24 int32 (signed integer) -2^23 <= y <= 2^23-1 * 32 single (floating point) -1.0 <= y < +1.0 * * typedef uint8_t u8_t; ///< unsigned 8-bit value (0 to 255) * typedef int8_t s8_t; ///< signed 8-bit value (-128 to +127) * typedef uint16_t u16_t; ///< unsigned 16-bit value (0 to 65535) * typedef int16_t s16_t; ///< signed 16-bit value (-32768 to 32767) * typedef uint32_t u32_t; ///< unsigned 32-bit value (0 to 4294967296) * typedef int32_t s32_t; ///< signed 32-bit value (-2147483648 to +2147483647) */ public static void Read8Bit(BinaryFile waveFile, float[][] sound, int sampleCount, int channels) { for (int i = 0; i < sampleCount; i++) { for (int ic = 0; ic < channels; ic++) { byte b = waveFile.ReadByte(); sound[ic][i] = (float)b / 128.0f - 1.0f; } } }
/* * Native Formats * Number of Bits MATLAB Data Type Data Range * 8 uint8 (unsigned integer) 0 <= y <= 255 * 16 int16 (signed integer) -32768 <= y <= +32767 * 24 int32 (signed integer) -2^23 <= y <= 2^23-1 * 32 single (floating point) -1.0 <= y < +1.0 * * typedef uint8_t u8_t; ///< unsigned 8-bit value (0 to 255) * typedef int8_t s8_t; ///< signed 8-bit value (-128 to +127) * typedef uint16_t u16_t; ///< unsigned 16-bit value (0 to 65535) * typedef int16_t s16_t; ///< signed 16-bit value (-32768 to 32767) * typedef uint32_t u32_t; ///< unsigned 32-bit value (0 to 4294967296) * typedef int32_t s32_t; ///< signed 32-bit value (-2147483648 to +2147483647) */ public static void Read8Bit(BinaryFile wavfile, double[][] sound, int samplecount, int channels) { #if DEBUG Console.Write("Read8Bit...\n"); #endif for (int i = 0; i < samplecount; i++) { for (int ic = 0; ic < channels; ic++) { byte @byte = wavfile.ReadByte(); sound[ic][i] = (double)@byte / 128.0 - 1.0; } } }
/* Function: Load * Loads <Files.nd> and returns whether it was successful. If it wasn't it will still return valid objects, they will just * be empty. */ public bool Load(Path filename, out IDObjects.Manager <File> files) { files = new IDObjects.Manager <File>(Config.Manager.KeySettingsForPaths, false); BinaryFile binaryFile = new BinaryFile(); bool result = true; try { // We'll continue to handle 2.0 files in 2.0.2 since it's easy enough if (binaryFile.OpenForReading(filename, "2.0") == false) { result = false; } else { // [Int32: ID] // [String: Path] // [Byte: Type] // [Int64: Last Modification in Ticks or 0] // (if image) // [UInt32: Width in Pixels or 0 if unknown] // [UInt32: Height in Pixels or 0 if unknown] // ... // [Int32: 0] int id; Path path; FileType type; DateTime lastModification; File file; uint width, height; for (;;) { id = binaryFile.ReadInt32(); if (id == 0) { break; } path = binaryFile.ReadString(); type = (FileType)binaryFile.ReadByte(); lastModification = new DateTime(binaryFile.ReadInt64()); if (type == FileType.Image) { if (binaryFile.Version < "2.0.2") { width = 0; height = 0; } else { width = binaryFile.ReadUInt32(); height = binaryFile.ReadUInt32(); } if (width == 0 || height == 0) { // If this file is from a different version of Natural Docs, no matter which one, reset the last modification // time so they'll be reparsed and take another stab at getting the dimensions if (binaryFile.Version != Engine.Instance.Version) { lastModification = new DateTime(0); } file = new ImageFile(path, lastModification); } else { file = new ImageFile(path, lastModification, width, height); } } else { file = new File(path, type, lastModification); } file.ID = id; files.Add(file); } } } catch { result = false; } finally { binaryFile.Close(); } if (result == false) { files.Clear(); } return(result); }
// Group: Loading Functions // __________________________________________________________________________ /* Function: Load * Loads the information in <Languages.nd> into a <Config> object, returning whether it was successful. If it was not * config will be null. */ public bool Load(Path filename, out Config config) { BinaryFile file = new BinaryFile(); try { if (file.OpenForReading(filename, "2.2") == false) { config = null; return(false); } else { config = new Config(); // [String: Language Name] // [[Language Attributes]] // ... // [String: null] string languageName = file.ReadString(); while (languageName != null) { Language language = new Language(languageName); // [Int32: ID] // [Byte: Type] // [String: Simple Identifier] // [Byte: Enum Values] // [Byte: Case Sensitive (1 or 0)] // [String: Member Operator Symbol] // [String: Line Extender Symbol] language.ID = file.ReadInt32(); byte type = file.ReadByte(); if (Enum.IsDefined(typeof(Language.LanguageType), type)) { language.Type = (Language.LanguageType)type; } else { config = null; return(false); } language.SimpleIdentifier = file.ReadString(); byte enumValues = file.ReadByte(); if (Enum.IsDefined(typeof(Language.EnumValues), enumValues)) { language.EnumValue = (Language.EnumValues)enumValues; } else { config = null; return(false); } language.CaseSensitive = (file.ReadByte() == 1); language.MemberOperator = file.ReadString(); language.LineExtender = file.ReadString(); // [String: Line Comment Symbol] [] ... [String: null] // [String: Opening Block Comment Symbol] [String: Closing Block Comment Symbol] [] [] ... [String: null] // [String: Javadoc First Line Comment Symbol] [String: Javadoc Following Lines Comment Symbol [] [] ... [String: null] // [String: Javadoc Opening Block Comment Symbol] [String: Javadoc Closing Block Comment Symbol] [] [] ... [String: null] // [String: XML Line Comment Symbol] [] ... [String: null] var lineCommentSymbols = ReadSymbolList(file); if (lineCommentSymbols != null) { language.LineCommentSymbols = lineCommentSymbols; } var blockCommentSymbols = ReadBlockCommentSymbolsList(file); if (blockCommentSymbols != null) { language.BlockCommentSymbols = blockCommentSymbols; } var javadocLineCommentSymbols = ReadLineCommentSymbolsList(file); if (javadocLineCommentSymbols != null) { language.JavadocLineCommentSymbols = javadocLineCommentSymbols; } var javadocBlockCommentSymbols = ReadBlockCommentSymbolsList(file); if (javadocBlockCommentSymbols != null) { language.JavadocBlockCommentSymbols = javadocBlockCommentSymbols; } var xmlLineCommentSymbols = ReadSymbolList(file); if (xmlLineCommentSymbols != null) { language.XMLLineCommentSymbols = xmlLineCommentSymbols; } // Prototype Enders: // [Int32: Comment Type ID] // [Byte: Include Line Breaks (1 or 0)] // [String: Prototype Ender Symbol] [] ... [String: null] // ... // [Int32: 0] int commentTypeID = file.ReadInt32(); while (commentTypeID != 0) { bool includeLineBreaks = (file.ReadByte() == 1); var enderSymbols = ReadSymbolList(file); language.AddPrototypeEnders(new PrototypeEnders(commentTypeID, enderSymbols, includeLineBreaks)); commentTypeID = file.ReadInt32(); } config.AddLanguage(language); languageName = file.ReadString(); } // [String: Alias] [Int32: Language ID] [] [] ... [String: Null] string alias = file.ReadString(); while (alias != null) { int languageID = file.ReadInt32(); config.AddAlias(alias, languageID); alias = file.ReadString(); } // [String: File Extension] [Int32: Language ID] [] [] ... [String: Null] string fileExtension = file.ReadString(); while (fileExtension != null) { int languageID = file.ReadInt32(); config.AddFileExtension(fileExtension, languageID); fileExtension = file.ReadString(); } // [String: Shebang String] [Int32: Language ID] [] [] ... [String: Null] string shebangString = file.ReadString(); while (shebangString != null) { int languageID = file.ReadInt32(); config.AddShebangString(shebangString, languageID); shebangString = file.ReadString(); } } } catch { config = null; return(false); } finally { file.Close(); } return(true); }
/* Function: Load * Loads the information in <BuildState.nd> and returns whether it was successful. If not the function will return an empty * BuildState object. */ public bool Load(Path filename, out BuildState buildState, out UnprocessedChanges unprocessedChanges) { // Since we're creating new objects only we have access to them right now and thus we don't need to use Lock() and // Unlock(). buildState = new BuildState(); unprocessedChanges = new UnprocessedChanges(); BinaryFile binaryFile = new BinaryFile(); bool result = true; try { if (binaryFile.OpenForReading(filename, "2.1") == false) { result = false; } else { // [Byte: Need to Build Frame Page (0 or 1)] // [Byte: Need to Build Main Style Files (0 or 1)] // [Byte: Need to Build Menu (0 or 1)] // [Byte: Need to Build Main Search Files (0 or 1)] unprocessedChanges.framePage = (binaryFile.ReadByte() == 1); unprocessedChanges.mainStyleFiles = (binaryFile.ReadByte() == 1); unprocessedChanges.menu = (binaryFile.ReadByte() == 1); unprocessedChanges.mainSearchFiles = (binaryFile.ReadByte() == 1); // [NumberSet: Source File IDs to Rebuild] // [NumberSet: Class IDs to Rebuild] // [NumberSet: Image File IDs to Rebuild] // [NumberSet: Style File IDs to Rebuild] // [NumberSet: Source File IDs with Content] // [NumberSet: Class IDs with Content] // [NumberSet: Used Image File IDs] // [NumberSet: Unchanged Image File Use Check IDs] unprocessedChanges.sourceFiles.ReadFrom(binaryFile); unprocessedChanges.classes.ReadFrom(binaryFile); unprocessedChanges.imageFiles.ReadFrom(binaryFile); unprocessedChanges.styleFiles.ReadFrom(binaryFile); buildState.sourceFilesWithContent.ReadFrom(binaryFile); buildState.classesWithContent.ReadFrom(binaryFile); buildState.usedImageFiles.ReadFrom(binaryFile); unprocessedChanges.unchangedImageFileUseChecks.ReadFrom(binaryFile); // [StringSet: Search Prefixes to Rebuild] // [StringSet: Folders to Check for Deletion] unprocessedChanges.searchPrefixes.ReadFrom(binaryFile); unprocessedChanges.possiblyEmptyFolders.ReadFrom(binaryFile); // [String: Menu Data File Type] [NumberSet: Menu Data File Numbers] // [String: Menu Data File Type] [NumberSet: Menu Data File Numbers] // ... // [String: null] string menuDataFileType = binaryFile.ReadString(); while (menuDataFileType != null) { Hierarchy hierarchy; if (menuDataFileType == "files") { hierarchy = Hierarchy.File; } else if (menuDataFileType == "classes") { hierarchy = Hierarchy.Class; } else if (menuDataFileType == "database") { hierarchy = Hierarchy.Database; } else { throw new NotImplementedException(); } NumberSet menuDataFileNumbers = binaryFile.ReadNumberSet(); buildState.usedMenuDataFiles.Add(hierarchy, menuDataFileNumbers); menuDataFileType = binaryFile.ReadString(); } } } catch { result = false; } finally { binaryFile.Dispose(); } if (result == false) { buildState = new BuildState(); unprocessedChanges = new UnprocessedChanges(); } return(result); }
/* Function: Load * Loads the information in <Config.nd> and returns whether it was successful. If not all the out parameters will still * return objects, they will just be empty. */ public bool Load(Path filename, out Config.ProjectInfo projectInfo, out List <Style> styles, out List <FileSourceInfo> fileSourceInfoList) { projectInfo = new Config.ProjectInfo(); styles = new List <Style>(); fileSourceInfoList = new List <FileSourceInfo>(); BinaryFile binaryFile = new BinaryFile(); bool result = true; try { if (binaryFile.OpenForReading(filename, "2.2") == false) { result = false; } else { // [String: Project Title or null] // [String: Project Subtitle or null] // [String: Project Copyright or null] // [String: Project Timestamp Code or null] projectInfo.Title = binaryFile.ReadString(); projectInfo.TitlePropertyLocation = Config.PropertySource.PreviousRun; projectInfo.Subtitle = binaryFile.ReadString(); projectInfo.SubtitlePropertyLocation = Config.PropertySource.PreviousRun; projectInfo.Copyright = binaryFile.ReadString(); projectInfo.CopyrightPropertyLocation = Config.PropertySource.PreviousRun; projectInfo.TimestampCode = binaryFile.ReadString(); projectInfo.TimestampCodePropertyLocation = Config.PropertySource.PreviousRun; // [String: Style Path] // (properties) // [String: Style Path] // ... // [String: null] string stylePath = binaryFile.ReadString(); while (stylePath != null) { Style style; if (stylePath.EndsWith(".css", StringComparison.OrdinalIgnoreCase)) { style = new Styles.CSSOnly(stylePath); } else { style = new Styles.Advanced(stylePath); } styles.Add(style); // [String: Inherit] ... [String: null] string inheritStatement = binaryFile.ReadString(); while (inheritStatement != null) { // Find the name in the list of styles so we can connect the objects together properly. There should only // be one style per name so we can just compare by name. Also, this list is stored in the order in which // they must be applied, which means inherited styles will appear before the ones that inherit from them, // so we can search the list we've built so far instead of waiting until they're all loaded. Style matchingStyle = null; for (int i = 0; i < styles.Count; i++) { if (string.Compare(inheritStatement, styles[i].Name, StringComparison.OrdinalIgnoreCase) == 0) { matchingStyle = styles[i]; break; } } // If there's no match just add it as null. style.AddInheritedStyle(inheritStatement, Config.PropertySource.PreviousRun, matchingStyle); inheritStatement = binaryFile.ReadString(); } // [String: OnLoad] [Byte: Page Type] ... [String: null] string onLoadStatement = binaryFile.ReadString(); while (onLoadStatement != null) { Engine.Styles.PageType pageType = (Engine.Styles.PageType)binaryFile.ReadByte(); style.AddOnLoad(onLoadStatement, Config.PropertySource.PreviousRun, pageType); onLoadStatement = binaryFile.ReadString(); } // [String: Link] [Byte: Page Type] ... [String: null] string linkStatement = binaryFile.ReadString(); while (linkStatement != null) { Engine.Styles.PageType pageType = (Engine.Styles.PageType)binaryFile.ReadByte(); style.AddLinkedFile(linkStatement, Config.PropertySource.PreviousRun, pageType); linkStatement = binaryFile.ReadString(); } // [String: Home Page or null] string homePage = binaryFile.ReadString(); if (homePage != null) { style.SetHomePage(homePage, Config.PropertySource.PreviousRun); } // Next style path stylePath = binaryFile.ReadString(); } projectInfo.StyleName = styles[styles.Count - 1].Name; projectInfo.StyleNamePropertyLocation = Config.PropertySource.PreviousRun; // [Int32: Source FileSource Number] [String: Source FileSource UniqueIDString] // [Int32: Source FileSource Number] [String: Source FileSource UniqueIDString] // ... // [Int32: 0] FileSourceInfo fileSourceInfo = new FileSourceInfo(); fileSourceInfo.Type = Files.InputType.Source; for (;;) { fileSourceInfo.Number = binaryFile.ReadInt32(); if (fileSourceInfo.Number == 0) { break; } fileSourceInfo.UniqueIDString = binaryFile.ReadString(); fileSourceInfoList.Add(fileSourceInfo); } // [Int32: Image FileSource Number] [String: Image FileSource UniqueIDString] // [Int32: Image FileSource Number] [String: Image FileSource UniqueIDString] // ... // [Int32: 0] fileSourceInfo.Type = Files.InputType.Image; for (;;) { fileSourceInfo.Number = binaryFile.ReadInt32(); if (fileSourceInfo.Number == 0) { break; } fileSourceInfo.UniqueIDString = binaryFile.ReadString(); fileSourceInfoList.Add(fileSourceInfo); } } } catch { result = false; } finally { binaryFile.Dispose(); } if (result == false) { projectInfo = new Config.ProjectInfo(); styles.Clear(); fileSourceInfoList.Clear(); } return(result); }
// Group: Loading Functions // __________________________________________________________________________ /* Function: Load * Loads the information in <Languages.nd>, which is the computed language settings from the last time Natural Docs * was run. Returns whether it was successful. If not all the out parameters will still return objects, they will just be * empty. */ public bool Load(Path filename, out List <Language> languages, out List <KeyValuePair <string, int> > aliases, out List <KeyValuePair <string, int> > extensions, out List <KeyValuePair <string, int> > shebangStrings, out List <string> ignoredExtensions) { languages = new List <Language>(); aliases = new List <KeyValuePair <string, int> >(); extensions = new List <KeyValuePair <string, int> >(); shebangStrings = new List <KeyValuePair <string, int> >(); ignoredExtensions = new List <string>(); BinaryFile file = new BinaryFile(); bool result = true; IDObjects.NumberSet usedLanguageIDs = new IDObjects.NumberSet(); try { if (file.OpenForReading(filename, "2.0") == false) { result = false; } else { // [String: Language Name] // [Int32: ID] // [Byte: Type] // [String: Simple Identifier] // [Byte: Enum Values] // [Byte: Case Sensitive (1 or 0)] // [String: Member Operator Symbol] // [String: Line Extender Symbol] // [String: Line Comment Symbol] [] ... [String: null] // [String: Opening Block Comment Symbol] [String: Closing Block Comment Symbo] [] [] ... [String: null] // [String: Opening Javadoc Line Comment Symbol] [String: Remainder Javadoc Line Comment Symbol [] ... [String: null] // [String: Opening Javadoc Block Comment Symbol] [String: Closing Javadoc Block Comment Symbol] [] [] ... [String: null] // [String: XML Line Comment Symbol] [] ... [String: null] // [Int32: Comment Type ID] // [Byte: Include Line Breaks (1 or 0)] // [String: Prototype Ender Symbol] [] ... [String: null] // ... // [Int32: 0] // ... // [String: null] for (string languageName = file.ReadString(); languageName != null; languageName = file.ReadString()) { Language language = new Language(languageManager, languageName); language.ID = file.ReadInt32(); byte rawTypeValue = file.ReadByte(); if (Enum.IsDefined(typeof(Language.LanguageType), rawTypeValue)) { language.Type = (Language.LanguageType)rawTypeValue; } else { result = false; } language.SimpleIdentifier = file.ReadString(); byte rawEnumValue = file.ReadByte(); if (Enum.IsDefined(typeof(Language.EnumValues), rawEnumValue)) { language.EnumValue = (Language.EnumValues)rawEnumValue; } else { result = false; } language.CaseSensitive = (file.ReadByte() == 1); language.MemberOperator = file.ReadString(); language.LineExtender = file.ReadString(); language.LineCommentStrings = ReadStringArray(file); language.BlockCommentStringPairs = ReadStringArray(file); language.JavadocLineCommentStringPairs = ReadStringArray(file); language.JavadocBlockCommentStringPairs = ReadStringArray(file); language.XMLLineCommentStrings = ReadStringArray(file); for (int commentTypeID = file.ReadInt32(); commentTypeID != 0; commentTypeID = file.ReadInt32()) { bool includeLineBreaks = (file.ReadByte() == 1); string[] enderSymbols = ReadStringArray(file); language.SetPrototypeEnders(commentTypeID, new PrototypeEnders(enderSymbols, includeLineBreaks)); } languages.Add(language); usedLanguageIDs.Add(language.ID); } // [String: Alias] [Int32: Language ID] [] [] ... [String: Null] for (string alias = file.ReadString(); alias != null; alias = file.ReadString()) { int languageID = file.ReadInt32(); if (usedLanguageIDs.Contains(languageID) == true) { aliases.Add(new KeyValuePair <string, int>(alias, languageID)); } else { result = false; } } // [String: Extension] [Int32: Language ID] [] [] ... [String: Null] for (string extension = file.ReadString(); extension != null; extension = file.ReadString()) { int languageID = file.ReadInt32(); if (usedLanguageIDs.Contains(languageID) == true) { extensions.Add(new KeyValuePair <string, int>(extension, languageID)); } else { result = false; } } // [String: Shebang String] [Int32: Language ID] [] [] ... [String: Null] for (string shebangString = file.ReadString(); shebangString != null; shebangString = file.ReadString()) { int languageID = file.ReadInt32(); if (usedLanguageIDs.Contains(languageID) == true) { shebangStrings.Add(new KeyValuePair <string, int>(shebangString, languageID)); } else { result = false; } } // [String: Ignored Extension] [] ... [String: Null] for (string ignoredExtension = file.ReadString(); ignoredExtension != null; ignoredExtension = file.ReadString()) { ignoredExtensions.Add(ignoredExtension); } } } catch { result = false; } finally { file.Close(); } if (result == false) { // Reset all the objects to empty versions. languages.Clear(); extensions.Clear(); shebangStrings.Clear(); ignoredExtensions.Clear(); } return(result); }
/* Function: Load * Loads the information in <Comments.nd> into a <Config> object, returning whether it was successful. If it was not * config will be null. */ public bool Load(Path filename, out Config config) { BinaryFile file = new BinaryFile(); try { if (file.OpenForReading(filename, "2.2") == false) { config = null; return(false); } else { config = new Config(); // [String: Tag Name] // [Int32: ID] // ... // [String: null] string tagName = file.ReadString(); while (tagName != null) { Tag tag = new Tag(tagName); tag.ID = file.ReadInt32(); config.AddTag(tag); tagName = file.ReadString(); } // [String: Comment Type Name] // [Int32: ID] // [String: Display Name] // [String: Plural Display Name] // [String: Simple Identifier] // [Byte: Scope] // [Byte: Flags] // ... // [String: null] string commentTypeName = file.ReadString(); while (commentTypeName != null) { CommentType commentType = new CommentType(commentTypeName); commentType.ID = file.ReadInt32(); commentType.DisplayName = file.ReadString(); commentType.PluralDisplayName = file.ReadString(); commentType.SimpleIdentifier = file.ReadString(); // We don't have to validate the scope and flag values because they're only used to compare to the text file // versions, which are validated. If these are invalid they'll just show up as changed. commentType.Scope = (CommentType.ScopeValue)file.ReadByte(); commentType.Flags = (CommentType.FlagValue)file.ReadByte(); config.AddCommentType(commentType); commentTypeName = file.ReadString(); } // [String: Keyword] // [Byte: Plural (0 or 1)] // [Int32: Comment Type ID] // [Int32: Language ID or 0 if agnostic] // ... // [String: null] string keywordName = file.ReadString(); while (keywordName != null) { var keywordDefinition = new KeywordDefinition(keywordName); keywordDefinition.Plural = (file.ReadByte() != 0); keywordDefinition.CommentTypeID = file.ReadInt32(); int languageID = file.ReadInt32(); if (languageID != 0) { keywordDefinition.LanguageID = languageID; } config.AddKeywordDefinition(keywordDefinition); keywordName = file.ReadString(); } } } catch { config = null; return(false); } finally { file.Close(); } return(true); }
public bool Read(string filePath) { if (File.Exists(filePath)) { string fileName = Path.GetFileNameWithoutExtension(filePath); PresetName = fileName; BinaryFile bFile = new BinaryFile(filePath, BinaryFile.ByteOrder.BigEndian); string firstChunkID = bFile.ReadString(4); // chunk ID = "FORM" int ckSize = bFile.ReadInt32(); string formType = bFile.ReadString(4); // read first data chunk string chunkID = bFile.ReadString(4); // if chunkID == "COMT" then CommentsChunk if (chunkID.Equals("COMT")) { long curposTmpComt = bFile.GetPosition(); bFile.Seek(curposTmpComt - 4); // CommentsChunk string chunkIDComt = bFile.ReadString(4); // chunk ID = "COMT" int chunkSizeComt = bFile.ReadInt32(); int numComments = bFile.ReadUInt16(); long curposTmpComt2 = bFile.GetPosition(); for (int i = 0; i < numComments; i++) { int commentTimestamp = (int)bFile.ReadUInt32(); string marker = bFile.ReadString(4); int count = (int)bFile.ReadByte(); comments.Add(bFile.ReadString(count)); } bFile.Seek(curposTmpComt2 + chunkSizeComt - 2); } string chunkID2 = bFile.ReadString(4); // if chunkID2 == "COMM" then CommonChunk if (chunkID2.Equals("COMM")) { long curposTmpComm = bFile.GetPosition(); bFile.Seek(curposTmpComm - 4); // CommonChunk string chunkIDComm = bFile.ReadString(4); // chunk ID = "COMM" int chunkSizeComm = bFile.ReadInt32(); channels = bFile.ReadInt16(); numSampleFrames = (int)bFile.ReadUInt32(); bitsPerSample = bFile.ReadInt16(); // read IEEE 80-bit extended double precision byte[] sampleRateBytes = bFile.ReadBytes(0, 10, BinaryFile.ByteOrder.LittleEndian); double sampleRateDouble = IEEE.ConvertFromIeeeExtended(sampleRateBytes); sampleRate = (int)sampleRateDouble; } string chunkID3 = bFile.ReadString(4); // if chunkID3 == "SSND" then SoundDataChunk if (chunkID3.Equals("SSND")) { long curposTmpSsnd = bFile.GetPosition(); bFile.Seek(curposTmpSsnd - 4); // SoundDataChunk string chunkIDSsnd = bFile.ReadString(4); // chunk ID = "SSND" int chunkSizeSsnd = bFile.ReadInt32(); int offset = (int)bFile.ReadUInt32(); int blocksize = (int)bFile.ReadUInt32(); byte[] data = bFile.ReadBytes(offset, chunkSizeSsnd - 8, BinaryFile.ByteOrder.LittleEndian); // swap waveform data WaveformData = SwapAiffEndian(data); } bFile.Close(); return(true); } else { return(false); } }
// Group: File Functions // __________________________________________________________________________ /* Function: LoadBinaryFile * Loads the information in <BuildState.nd> and returns whether it was successful. If not the function will return an empty * BuildState object. */ public static bool LoadBinaryFile(Path filename, out HTMLBuildState buildState) { buildState = new HTMLBuildState(createEmptyObjects: false); BinaryFile binaryFile = new BinaryFile(); bool result = true; try { if (binaryFile.OpenForReading(filename, "2.0") == false) { result = false; } else { // [Byte: Need to Build Frame Page (0 or 1)] // [Byte: Need to Build Main Style Files (0 or 1)] // [Byte: Need to Build Menu (0 or 1)] // [Byte: Need to Build Prefix Index (0 or 1)] buildState.needToBuildFramePage = (binaryFile.ReadByte() == 1); buildState.needToBuildMainStyleFiles = (binaryFile.ReadByte() == 1); buildState.needToBuildMenu = (binaryFile.ReadByte() == 1); buildState.needToBuildPrefixIndex = (binaryFile.ReadByte() == 1); // [NumberSet: Source File IDs to Rebuild] // [NumberSet: Class IDs to Rebuild] // [NumberSet: Source File IDs with Content] // [NumberSet: Class IDs with Content] // [StringSet: Prefixes to Rebuild] // [StringSet: Folders to Check for Deletion] buildState.sourceFilesToRebuild = binaryFile.ReadNumberSet(); buildState.classFilesToRebuild = binaryFile.ReadNumberSet(); buildState.sourceFilesWithContent = binaryFile.ReadNumberSet(); buildState.classFilesWithContent = binaryFile.ReadNumberSet(); buildState.prefixesToRebuild = binaryFile.ReadStringSet(); buildState.foldersToCheckForDeletion = binaryFile.ReadStringSet(Config.Manager.KeySettingsForPaths); // [String: Menu Data File Type] [NumberSet: Menu Data File Numbers] // [String: Menu Data File Type] [NumberSet: Menu Data File Numbers] // ... // [String: null] buildState.usedMenuDataFiles = new StringTable <IDObjects.NumberSet>(); string menuDataFileType = binaryFile.ReadString(); while (menuDataFileType != null) { IDObjects.NumberSet menuDataFileNumbers = binaryFile.ReadNumberSet(); buildState.usedMenuDataFiles.Add(menuDataFileType, menuDataFileNumbers); menuDataFileType = binaryFile.ReadString(); } } } catch { result = false; } finally { binaryFile.Dispose(); } if (result == false) { buildState = new HTMLBuildState(createEmptyObjects: true); } return(result); }
// Group: Loading Functions // __________________________________________________________________________ /* Function: Load * Loads the information in <Project.nd>, returning whether it was successful. */ public bool Load(Path filename, out ProjectConfig projectConfig) { projectConfig = new ProjectConfig(PropertySource.PreviousRun); this.projectConfig = projectConfig; binaryFile = new BinaryFile(); bool result = true; try { // There were no file format changes between 2.0 and 2.0.2 but there were parsing changes and // bug fixes that require a full rebuild. if (binaryFile.OpenForReading(filename, "2.0.2") == false) { result = false; } else { // [Int32: Tab Width] // [Byte: Documented Only (0 or 1)] // [Byte: Auto Group (0 or 1)] // [Byte: Shrink Files (0 or 1)] projectConfig.TabWidth = binaryFile.ReadInt32(); projectConfig.TabWidthPropertyLocation = PropertySource.PreviousRun; projectConfig.DocumentedOnly = (binaryFile.ReadByte() == 1); projectConfig.DocumentedOnlyPropertyLocation = PropertySource.PreviousRun; projectConfig.AutoGroup = (binaryFile.ReadByte() == 1); projectConfig.AutoGroupPropertyLocation = PropertySource.PreviousRun; projectConfig.ShrinkFiles = (binaryFile.ReadByte() == 1); projectConfig.ShrinkFilesPropertyLocation = PropertySource.PreviousRun; // [String: Identifier] // [[Properties]] // ... // [String: null] string identifier = binaryFile.ReadString(); while (identifier != null) { LoadTarget(identifier); identifier = binaryFile.ReadString(); } } } catch { result = false; // Reset everything. projectConfig = new ProjectConfig(PropertySource.PreviousRun); } finally { binaryFile.Close(); } return(result); }
/* Function: Load * Loads the information in <Comments.nd>, which is the computed comment settings from the last time Natural Docs was run. * Returns whether it was successful. If not all the out parameters will still return objects, they will just be empty. */ public bool Load(Path filename, out List <CommentType> binaryCommentTypes, out List <Tag> binaryTags, out List <KeyValuePair <string, int> > binarySingularKeywords, out List <KeyValuePair <string, int> > binaryPluralKeywords, out List <string> binaryIgnoredKeywords) { binaryCommentTypes = new List <CommentType>(); binaryTags = new List <Tag>(); binarySingularKeywords = new List <KeyValuePair <string, int> >(); binaryPluralKeywords = new List <KeyValuePair <string, int> >(); binaryIgnoredKeywords = new List <string>(); BinaryFile file = new BinaryFile(); bool result = true; try { if (file.OpenForReading(filename, "2.0") == false) { result = false; } else { // [String: Tag Name] // [Int32: ID] // ... // [String: null] string tagName = file.ReadString(); while (tagName != null) { Tag tag = new Tag(tagName); tag.ID = file.ReadInt32(); binaryTags.Add(tag); tagName = file.ReadString(); } // [String: Comment Type Name] // [Int32: ID] // [String: Display Name] // [String: Plural Display Name] // [String: Simple Identifier] // [Byte: Index] // [Int32: Index With ID]? // [Byte: Scope] // [Byte: Break Lists] // [UInt16: Flags] // ... // [String: null] string commentTypeName = file.ReadString(); IDObjects.NumberSet commentTypeIDs = new IDObjects.NumberSet(); while (commentTypeName != null) { CommentType commentType = new CommentType(commentTypeName); commentType.ID = file.ReadInt32(); commentType.DisplayName = file.ReadString(); commentType.PluralDisplayName = file.ReadString(); commentType.SimpleIdentifier = file.ReadString(); // We don't have to validate the enum and flag values because they're only used to compare to the config file // versions, which are validated. If these are invalid they'll just show up as changed. commentType.Index = (CommentType.IndexValue)file.ReadByte(); if (commentType.Index == CommentType.IndexValue.IndexWith) { commentType.IndexWith = file.ReadInt32(); } commentType.Scope = (CommentType.ScopeValue)file.ReadByte(); commentType.BreakLists = (file.ReadByte() != 0); commentType.Flags.AllConfigurationProperties = (CommentTypeFlags.FlagValues)file.ReadUInt16(); binaryCommentTypes.Add(commentType); commentTypeIDs.Add(commentType.ID); commentTypeName = file.ReadString(); } // Check the Index With values after they're all entered in. foreach (CommentType commentType in binaryCommentTypes) { if (commentType.Index == CommentType.IndexValue.IndexWith && !commentTypeIDs.Contains(commentType.IndexWith)) { result = false; } } // [String: Singular Keyword] // [Int32: Comment Type ID] // ... // [String: null] string keyword = file.ReadString(); while (keyword != null) { int id = file.ReadInt32(); binarySingularKeywords.Add(new KeyValuePair <string, int>(keyword, id)); if (!commentTypeIDs.Contains(id)) { result = false; } keyword = file.ReadString(); } // [String: Plural Keyword] // [Int32: Comment Type ID] // ... // [String: null] keyword = file.ReadString(); while (keyword != null) { int id = file.ReadInt32(); binaryPluralKeywords.Add(new KeyValuePair <string, int>(keyword, id)); if (!commentTypeIDs.Contains(id)) { result = false; } keyword = file.ReadString(); } // [String: Ignored Keyword] // ... // [String: null] keyword = file.ReadString(); while (keyword != null) { binaryIgnoredKeywords.Add(keyword); keyword = file.ReadString(); } } } catch { result = false; } finally { file.Close(); } if (result == false) { // Reset all the objects to empty versions. binaryCommentTypes.Clear(); binarySingularKeywords.Clear(); binaryPluralKeywords.Clear(); binaryIgnoredKeywords.Clear(); } return(result); }
// Group: Loading Functions // __________________________________________________________________________ /* Function: Load * Loads the information in <Project.nd>, returning whether it was successful. */ public bool Load(Path filename, out ProjectConfig projectConfig) { projectConfig = new ProjectConfig(Source.PreviousRun); this.projectConfig = projectConfig; binaryFile = new BinaryFile(); bool result = true; try { if (binaryFile.OpenForReading(filename, "2.0") == false) { result = false; } else { // [Int32: Tab Width] // [Byte: Documented Only (0 or 1)] // [Byte: Auto Group (0 or 1)] // [Byte: Shrink Files (0 or 1)] projectConfig.TabWidth = binaryFile.ReadInt32(); projectConfig.TabWidthPropertyLocation = Source.PreviousRun; projectConfig.DocumentedOnly = (binaryFile.ReadByte() == 1); projectConfig.DocumentedOnlyPropertyLocation = Source.PreviousRun; projectConfig.AutoGroup = (binaryFile.ReadByte() == 1); projectConfig.AutoGroupPropertyLocation = Source.PreviousRun; projectConfig.ShrinkFiles = (binaryFile.ReadByte() == 1); projectConfig.ShrinkFilesPropertyLocation = Source.PreviousRun; // [String: Identifier] // [[Properties]] // ... // [String: null] string identifier = binaryFile.ReadString(); while (identifier != null) { LoadTarget(identifier); identifier = binaryFile.ReadString(); } } } catch { result = false; // Reset everything. projectConfig = new ProjectConfig(Source.PreviousRun); } finally { binaryFile.Close(); } return(result); }
public static double[][] BMPRead(BinaryFile bmpfile, ref int y, ref int x) { int iy = 0; // various iterators int ix = 0; int ic = 0; int offset = 0; double[][] image; byte zerobytes = new byte(); byte val = new byte(); #if DEBUG Console.Write("BMPRead...\n"); #endif if (Util.ReadUInt16(bmpfile) != 19778) // "BM" format tag check { Console.Error.WriteLine("This file is not in BMP format\n"); Util.ReadUserReturn(); Environment.Exit(1); } bmpfile.Seek(8, SeekOrigin.Current); // skipping useless tags offset = (int)Util.ReadUInt32(bmpfile) - 54; // header offset bmpfile.Seek(4, SeekOrigin.Current); // skipping useless tags x = (int)Util.ReadUInt32(bmpfile); y = (int)Util.ReadUInt32(bmpfile); bmpfile.Seek(2, SeekOrigin.Current); // skipping useless tags if (Util.ReadUInt16(bmpfile) != 24) // Only format supported { Console.Error.WriteLine("Wrong BMP format, BMP images must be in 24-bit colour\n"); Util.ReadUserReturn(); Environment.Exit(1); } bmpfile.Seek(24 + offset, SeekOrigin.Current); // skipping useless tags // image allocation image = new double[y][]; for (iy = 0; iy < y; iy++) { image[iy] = new double[x]; } zerobytes = (byte)(4 - ((x * 3) & 3)); if (zerobytes == 4) { zerobytes = 0; } // backwards reading for (iy = y - 1; iy != -1; iy--) { for (ix = 0; ix < x; ix++) { for (ic = 2; ic != -1; ic--) { val = bmpfile.ReadByte(); image[iy][ix] += (double)val * (1.0 / (255.0 * 3.0)); // Conversion to grey by averaging the three channels } } bmpfile.Seek(zerobytes, SeekOrigin.Current); // skipping padding bytes } bmpfile.Close(); return(image); }