Skip to content

Commit

Permalink
build time as resource
Browse files Browse the repository at this point in the history
  • Loading branch information
ClusterM committed May 30, 2021
1 parent c1d1805 commit 08022ea
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 12 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
commit.txt
buildtime.txt

## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
Expand Down
13 changes: 12 additions & 1 deletion FamicomDumper/FamicomDumper.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@

<ItemGroup>
<None Remove="Dumper.proto" />
<None Remove="Resources\buildtime.txt" />
<None Remove="Resources\commit.txt" />
<None Remove="Resources\done.wav" />
<None Remove="Resources\error.wav" />
</ItemGroup>

<ItemGroup>
Expand Down Expand Up @@ -238,6 +242,13 @@
<ProjectReference Include="..\NesContainers\NesContainers.csproj" />
</ItemGroup>

<ItemGroup>
<Resource Include="Resources\buildtime.txt" />
<Resource Include="Resources\commit.txt" />
<Resource Include="Resources\done.wav" />
<Resource Include="Resources\error.wav" />
</ItemGroup>

<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
Expand All @@ -254,7 +265,7 @@
</ItemGroup>

<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
<Exec Command="echo. &gt; NUL 2&gt; &quot;$(ProjectDir)Resources\commit.txt&quot;&#xD;&#xA;&#xD;&#xA;git --version &amp;&amp; (&#xD;&#xA; for /f %25%25i in ('git rev-parse --short HEAD') do (&#xD;&#xA; git diff-index --quiet HEAD -- &amp;&amp; (&#xD;&#xA; echo|set /p=&quot;%25%25i&quot; &gt;&gt; &quot;$(ProjectDir)Resources\commit.txt&quot;&#xD;&#xA; SET ERRORLEVEL=0&#xD;&#xA; ) || (&#xD;&#xA; echo|set /p=&quot;%25%25i (dirty)&quot; &gt;&gt; &quot;$(ProjectDir)Resources\commit.txt&quot;&#xD;&#xA; )&#xD;&#xA; )&#xD;&#xA;) || SET ERRORLEVEL=0" />
<Exec Command="echo. &gt; NUL 2&gt; &quot;$(ProjectDir)Resources\commit.txt&quot;&#xD;&#xA;&#xD;&#xA;git --version &amp;&amp; (&#xD;&#xA; for /f %25%25i in ('git rev-parse --short HEAD') do (&#xD;&#xA; git diff-index --quiet HEAD -- &amp;&amp; (&#xD;&#xA; echo|set /p=&quot;%25%25i&quot; &gt;&gt; &quot;$(ProjectDir)Resources\commit.txt&quot;&#xD;&#xA; SET ERRORLEVEL=0&#xD;&#xA; ) || (&#xD;&#xA; echo|set /p=&quot;%25%25i (dirty)&quot; &gt;&gt; &quot;$(ProjectDir)Resources\commit.txt&quot;&#xD;&#xA; )&#xD;&#xA; )&#xD;&#xA;) || SET ERRORLEVEL=0&#xD;&#xA;&#xD;&#xA;powershell [Math]::Round((Get-Date).ToFileTimeUTC()) &gt;&quot;$(ProjectDir)Resources\buildtime.txt&quot;" />
</Target>

</Project>
28 changes: 19 additions & 9 deletions FamicomDumper/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,17 @@ public class Program
private const string SCRIPT_START_METHOD = "Run";
private const string REPO_PATH = "https://github.com/ClusterM/famicom-dumper-client";
private const int DEFAULT_GRPC_PORT = 26673;
private static DateTime BUILD_TIME = DateTime.FromFileTimeUtc(long.Parse(Properties.Resources.buildtime));

static int Main(string[] args)
{
Console.WriteLine($"Famicom Dumper Client v{Assembly.GetExecutingAssembly().GetName().Version.Major}.{Assembly.GetExecutingAssembly().GetName().Version.Minor}");
Console.WriteLine($" Commit {Properties.Resources.gitCommit} @ {REPO_PATH}");
#if DEBUG
Console.WriteLine($" Debug version, build time: {BUILD_TIME.ToLocalTime()}");
#endif
Console.WriteLine(" (c) Alexey 'Cluster' Avdyukhin / https://clusterrr.com / [email protected]");
Console.WriteLine();
Console.WriteLine("");
var startTime = DateTime.Now;
string port = "auto";
string mapperName = null;
Expand Down Expand Up @@ -447,16 +451,22 @@ static Assembly Compile(string path)
var cacheFile = Path.Combine(cacheDirectory, Path.GetFileNameWithoutExtension(path)) + ".dll";

// Try to load cached assembly
if (File.Exists(cacheFile) && (new FileInfo(cacheFile).LastWriteTime >= new FileInfo(path).LastWriteTime))
;
if (File.Exists(cacheFile))
{
try
{
var rawAssembly = File.ReadAllBytes(cacheFile);
return Assembly.Load(rawAssembly);
}
catch (Exception ex)
var cacheCompileTime = new FileInfo(cacheFile).LastWriteTime;
if ((cacheCompileTime >= new FileInfo(path).LastWriteTime) // recompile if script was changed
&& (cacheCompileTime >= BUILD_TIME.ToLocalTime())) // recompile if our app is newer
{
Console.WriteLine($"Can't load cached compiled script file: {ex.Message}");
try
{
var rawAssembly = File.ReadAllBytes(cacheFile);
return Assembly.Load(rawAssembly);
}
catch (Exception ex)
{
Console.WriteLine($"Can't load cached compiled script file: {ex.Message}");
}
}
}

Expand Down
12 changes: 11 additions & 1 deletion FamicomDumper/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions FamicomDumper/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="buildtime" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\buildtime.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;windows-1251</value>
</data>
<data name="DoneSound" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\resources\done.wav;System.IO.MemoryStream, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
Expand Down
2 changes: 1 addition & 1 deletion NesContainers
3 changes: 3 additions & 0 deletions famicom-dumper.sln
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FamicomDumperConnection", "FamicomDumperConnection\FamicomDumperConnection.csproj", "{BF3EA23E-72F5-4757-AC09-97313B9F8754}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{2E724810-06AF-4142-88A8-EAE7ECA700EE}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down

0 comments on commit 08022ea

Please sign in to comment.