MCPcopy Create free account
hub / github.com/CodeCavePro/revitless-toolkit / GetFormatFromFile

Method GetFormatFromFile

src/OLE/RevitFileInfo.cs:85–117  ·  view source on GitHub ↗
(string filePath)

Source from the content-addressed store, hash-verified

83 #region Methods
84
85 public static int GetFormatFromFile(string filePath)
86 {
87 if (string.IsNullOrWhiteSpace(filePath) || !File.Exists(filePath))
88 throw new ArgumentException("Please supply a valid path to a Revit document", nameof(filePath));
89
90 try
91 {
92 var basicInfo = OleDataReader.GetRawBytes(filePath, RevitFileMap.OleStreams.BASIC_FILE_INFO);
93 var properties = GetProperties(basicInfo);
94 var formatFromBasicInfo = properties.GetFormat();
95 if (formatFromBasicInfo > 0)
96 return formatFromBasicInfo;
97 }
98 catch
99 {
100 // TODO ad logging
101 // Trying to read
102 }
103
104 try
105 {
106 var partAtom = PartAtom.GetFromFile(filePath);
107 var formatFromPartAtom = partAtom?.Link?.Files?.FirstOrDefault()?.ProductVersion;
108 if (formatFromPartAtom != null)
109 return formatFromPartAtom.GetValueOrDefault();
110 }
111 catch (Exception ex)
112 {
113 throw new InvalidDataException($"Couldn't read format information from the followin file: '{filePath}'", ex);
114 }
115
116 return -1;
117 }
118
119 /// <summary>
120 /// Gets a <see cref="RevitFileInfo" /> instance from the given file path.

Callers

nothing calls this directly

Calls 3

GetRawBytesMethod · 0.80
GetFormatMethod · 0.80
GetFromFileMethod · 0.45

Tested by

no test coverage detected