Skip to content

Commit e36378f

Browse files
author
Young, Mark
committed
Initial Commit of HexPrintFile
0 parents  commit e36378f

File tree

10 files changed

+754
-0
lines changed

10 files changed

+754
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
bin/*
2+
obj/*

.vscode/launch.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
// Use IntelliSense to find out which attributes exist for C# debugging
3+
// Use hover for the description of the existing attributes
4+
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": ".NET Core Launch (console)",
9+
"type": "coreclr",
10+
"request": "launch",
11+
"preLaunchTask": "build",
12+
// If you have changed target frameworks, make sure to update the program path.
13+
"program": "${workspaceFolder}/bin/Debug/netcoreapp3.1/HexPrintFile.dll",
14+
"args": [
15+
"--help"
16+
],
17+
"cwd": "${workspaceFolder}",
18+
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
19+
"console": "internalConsole",
20+
"stopAtEntry": false
21+
},
22+
{
23+
"name": ".NET Core Attach",
24+
"type": "coreclr",
25+
"request": "attach",
26+
"processId": "${command:pickProcess}"
27+
}
28+
]
29+
}

.vscode/tasks.json

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"label": "build",
6+
"command": "dotnet",
7+
"type": "process",
8+
"args": [
9+
"build",
10+
"${workspaceFolder}/HexPrintFile.csproj",
11+
"/property:GenerateFullPaths=true",
12+
"/consoleloggerparameters:NoSummary"
13+
],
14+
"problemMatcher": "$msCompile"
15+
},
16+
{
17+
"label": "publish",
18+
"command": "dotnet",
19+
"type": "process",
20+
"args": [
21+
"publish",
22+
"${workspaceFolder}/HexPrintFile.csproj",
23+
"/property:GenerateFullPaths=true",
24+
"/consoleloggerparameters:NoSummary"
25+
],
26+
"problemMatcher": "$msCompile"
27+
},
28+
{
29+
"label": "watch",
30+
"command": "dotnet",
31+
"type": "process",
32+
"args": [
33+
"watch",
34+
"run",
35+
"${workspaceFolder}/HexPrintFile.csproj",
36+
"/property:GenerateFullPaths=true",
37+
"/consoleloggerparameters:NoSummary"
38+
],
39+
"problemMatcher": "$msCompile"
40+
}
41+
]
42+
}

Extensions.cs

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
using System;
2+
using System.ComponentModel;
3+
using System.IO;
4+
using System.Reflection;
5+
6+
namespace HexPrintFile
7+
{
8+
static class Extensions
9+
{
10+
/// <summary>
11+
/// Extension Method: Return the DateTime for the build from a given assembly file
12+
/// </summary>
13+
/// <param name="assembly">Assembly</param>
14+
/// <returns>DateTime</returns>
15+
public static DateTime GetLinkerTimestampUtc(this Assembly assembly)
16+
{
17+
var location = assembly.Location;
18+
return GetLinkerTimestampUtcLocation(location);
19+
}
20+
21+
/// <summary>
22+
/// Return the DateTime for the build from a given assembly file
23+
/// </summary>
24+
/// <param name="filePath">Assembly file location</param>
25+
/// <returns>string</returns>
26+
private static DateTime GetLinkerTimestampUtcLocation(string filePath)
27+
{
28+
const int peHeaderOffset = 60;
29+
const int linkerTimestampOffset = 8;
30+
var bytes = new byte[2048];
31+
32+
using (var file = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
33+
{
34+
file.Read(bytes, 0, bytes.Length);
35+
}
36+
37+
var headerPos = BitConverter.ToInt32(bytes, peHeaderOffset);
38+
var secondsSince1970 = BitConverter.ToInt32(bytes, headerPos + linkerTimestampOffset);
39+
var dt = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
40+
return dt.AddSeconds(secondsSince1970);
41+
}
42+
43+
/// <summary>
44+
/// Extension Method to get the description attribute from an Enum value
45+
/// </summary>
46+
/// <param name="value">Enum value</param>
47+
/// <returns>string</returns>
48+
public static string GetDescription(this Enum value)
49+
{
50+
Type type = value.GetType();
51+
string name = Enum.GetName(type, value);
52+
if (name != null)
53+
{
54+
FieldInfo field = type.GetField(name);
55+
if (field != null)
56+
{
57+
DescriptionAttribute attr =
58+
Attribute.GetCustomAttribute(field,
59+
typeof(DescriptionAttribute)) as DescriptionAttribute;
60+
if (attr != null)
61+
{
62+
return attr.Description;
63+
}
64+
}
65+
}
66+
return null;
67+
}
68+
}
69+
}

HexPrintFile.csproj

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>netcoreapp3.1</TargetFramework>
6+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
7+
8+
<!-- Deterministic needs to be false for the build date functionality to work -->
9+
<Deterministic>false</Deterministic>
10+
<AssemblyVersion>1.0.0</AssemblyVersion>
11+
12+
</PropertyGroup>
13+
14+
<ItemGroup>
15+
<PackageReference Include="McMaster.Extensions.CommandLineUtils" Version="3.0.0" />
16+
</ItemGroup>
17+
18+
</Project>

LICENSE.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 Mark Young
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

0 commit comments

Comments
 (0)