aboutsummaryrefslogtreecommitdiff
path: root/build_msvc/msbuild/tasks/hexdump.targets
blob: 12868a987418158684c5aa5dd6eceef6b7116ba3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <UsingTask
    TaskName="HeaderFromHexdump"
    TaskFactory="CodeTaskFactory"
    AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll" >
    <ParameterGroup>
        <RawFilePath Required="true" />
        <HeaderFilePath Required="true" />
        <SourceHeader Required="true" />
        <SourceFooter Required="true" />
    </ParameterGroup>
    <Task>
      <Using Namespace="System"/>
      <Using Namespace="System.IO"/>
      <Code Type="Fragment" Language="cs">
<![CDATA[
Log.LogMessage("msbuild inline hexdump task for " + RawFilePath + ".");
if(File.Exists(RawFilePath) == false) {
    Log.LogError("hexdump task could not locate " + RawFilePath + ".");
}
else {
    FileInfo inFileInfo = new FileInfo(RawFilePath);
    FileInfo outFileInfo = new FileInfo(HeaderFilePath);

    if (outFileInfo.Exists == false || inFileInfo.LastWriteTime > outFileInfo.LastWriteTime)
    {
      using (Stream inStm = File.OpenRead(RawFilePath))
      {
          using (StreamWriter sw = new StreamWriter(HeaderFilePath))
          {
              sw.WriteLine(SourceHeader);
              int count = 0;
              int rawChar = inStm.ReadByte();
              while(rawChar != -1)
              {
                  sw.Write("0x{0:x2}, ", rawChar);
                  count++;
                  if(count % 8 == 0)
                  {
                      sw.WriteLine();
                  }
                  rawChar = inStm.ReadByte();
              }
              sw.WriteLine(SourceFooter);
          }
      }
   }
}
]]>
      </Code>
    </Task>
  </UsingTask>
</Project>