-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAboutF.cs
More file actions
150 lines (125 loc) · 3.82 KB
/
AboutF.cs
File metadata and controls
150 lines (125 loc) · 3.82 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
using System;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Windows.Forms;
namespace creaturevisualizer
{
sealed class AboutF
: Form
{
#region Fields (static)
static string Info;
#endregion Fields (static)
#region Fields
string L = Environment.NewLine;
#endregion Fields
#region cTor
internal AboutF()
{
InitializeComponent();
if (Info == null)
{
Info = "Creature Visualizer" + L
+ "a toolset plugin for Neverwinter Nights 2" + L + L
+ "code by kevL's and the Ancestors" + L + L;
var ass = Assembly.GetExecutingAssembly();
var an = ass.GetName();
Info += an.Version.Major + "."
+ an.Version.Minor + "."
+ an.Version.Build + "."
+ an.Version.Revision;
#if DEBUG
Info += " debug";
#else
Info += " release";
#endif
Info += Environment.NewLine
+ String.Format(CultureInfo.CurrentCulture,
"{0:yyyy MMM d} {0:HH}:{0:mm}:{0:ss} UTC",
ass.GetLinkerTime());
Info += L;
}
tb_help.Text = Info;
tb_help.SelectionStart =
tb_help.SelectionLength = 0;
}
#endregion cTor
#region Handlers (override)
protected override void OnKeyDown(KeyEventArgs e)
{
if (e.KeyCode == Keys.Escape)
Close();
}
#endregion Handlers (override)
#region Designer
TextBox tb_help;
/// <summary>
/// This method is required for Windows Forms designer support.
/// Do not change the method contents inside the source code editor. The
/// Forms designer might not be able to load this method if it was
/// changed manually.
/// </summary>
private void InitializeComponent()
{
this.tb_help = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// tb_help
//
this.tb_help.Dock = System.Windows.Forms.DockStyle.Fill;
this.tb_help.Location = new System.Drawing.Point(0, 0);
this.tb_help.Margin = new System.Windows.Forms.Padding(0);
this.tb_help.Multiline = true;
this.tb_help.Name = "tb_help";
this.tb_help.ReadOnly = true;
this.tb_help.Size = new System.Drawing.Size(292, 114);
this.tb_help.TabIndex = 0;
this.tb_help.WordWrap = false;
//
// AboutF
//
this.ClientSize = new System.Drawing.Size(292, 114);
this.Controls.Add(this.tb_help);
this.Font = new System.Drawing.Font("Consolas", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.KeyPreview = true;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "AboutF";
this.ShowInTaskbar = false;
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "About";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion Designer
}
/// <summary>
/// Lifted from StackOverflow.com:
/// https://stackoverflow.com/questions/1600962/displaying-the-build-date#answer-1600990
/// - what a fucking pain in the ass.
/// </summary>
static class DateTimeExtension
{
/// <summary>
/// Gets the time/date of build timestamp.
/// </summary>
/// <param name="assembly"></param>
/// <param name="target"></param>
/// <returns></returns>
internal static DateTime GetLinkerTime(this Assembly assembly, TimeZoneInfo target = null)
{
var filePath = assembly.Location;
const int c_PeHeaderOffset = 60;
const int c_LinkerTimestampOffset = 8;
var buffer = new byte[2048];
using (var stream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
stream.Read(buffer, 0, 2048);
var offset = BitConverter.ToInt32(buffer, c_PeHeaderOffset);
var secondsSince1970 = BitConverter.ToInt32(buffer, offset + c_LinkerTimestampOffset);
var epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
return epoch.AddSeconds(secondsSince1970);
}
}
}