make Novetus.Launch use NovetusCore. Add "%compile-date%".

This commit is contained in:
Bitl 2021-08-13 12:41:47 -07:00
parent 00a220195b
commit d65d6c4460
15 changed files with 79 additions and 45 deletions

View File

@ -3,6 +3,7 @@ using System;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Reflection;
#endregion #endregion
namespace Novetus.Launch namespace Novetus.Launch
@ -20,25 +21,7 @@ namespace Novetus.Launch
public static void LaunchApplication(string appName, string args = "") public static void LaunchApplication(string appName, string args = "")
{ {
LaunchApplicationExt(LocalPaths.BinPath, appName, args); LaunchApplicationExt(LocalPaths.FixedBinDir, appName, args);
}
public static string GetVersion(string infopath)
{
//READ
string version;
INIFile ini = new INIFile(infopath);
string section = "ProgramInfo";
bool extendedversionnumber = Convert.ToBoolean(ini.IniReadValue(section, "ExtendedVersionNumber", "False"));
version = (extendedversionnumber ? ini.IniReadValue(section, "ExtendedVersionTemplate", "%version%") : ini.IniReadValue(section, "Branch", "0.0"));
var versionInfo = FileVersionInfo.GetVersionInfo(LocalPaths.BinPath + "\\" + LocalPaths.LauncherName);
string extendedversionrevision = ini.IniReadValue(section, "ExtendedVersionRevision", "1");
version = version.Replace("%version%", ini.IniReadValue(section, "Branch", "0.0"))
.Replace("%build%", versionInfo.ProductBuildPart.ToString())
.Replace("%revision%", versionInfo.FilePrivatePart.ToString())
.Replace("%extended-revision%", extendedversionrevision);
return version;
} }
} }
#endregion #endregion

View File

@ -9,19 +9,19 @@ namespace Novetus.Launch
public class LocalPaths public class LocalPaths
{ {
#region Base Paths public static readonly string FixedBinDir = GlobalPaths.BasePathLauncher + @"\\bin";
public static readonly string RootPathLauncher = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); public static readonly string FixedConfigDir = GlobalPaths.BasePathLauncher + @"\\config";
public static readonly string BasePathLauncher = RootPathLauncher.Replace(@"\", @"\\");
public static readonly string BinPath = BasePathLauncher + @"\\bin";
public static readonly string ConfigPath = BasePathLauncher + @"\\config";
#endregion
#region File Names #region File Names
public static readonly string LauncherName = "Novetus.exe"; public static readonly string LauncherName = "Novetus.exe";
public static readonly string CMDName = "NovetusCMD.exe"; public static readonly string CMDName = "NovetusCMD.exe";
public static readonly string URIName = "NovetusURI.exe"; public static readonly string URIName = "NovetusURI.exe";
public static readonly string DependencyLauncherName = "Novetus_dependency_installer.bat"; public static readonly string DependencyLauncherName = "Novetus_dependency_installer.bat";
public static readonly string LauncherInfoFile = "info.ini"; #endregion
#region File Paths
public static readonly string LauncherPath = FixedBinDir + "\\" + LauncherName;
public static readonly string InfoPath = FixedConfigDir + "\\" + GlobalPaths.InfoName;
#endregion #endregion
} }
#endregion #endregion

View File

@ -18,7 +18,7 @@
<DebugType>full</DebugType> <DebugType>full</DebugType>
<Optimize>false</Optimize> <Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath> <OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants> <DefineConstants>TRACE;DEBUG;BASICLAUNCHER</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
</PropertyGroup> </PropertyGroup>
@ -47,9 +47,6 @@
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="..\NovetusCore\Classes\INIFile.cs">
<Link>INIFile.cs</Link>
</Compile>
<Compile Include="LocalPaths.cs" /> <Compile Include="LocalPaths.cs" />
<Compile Include="LocalFuncs.cs" /> <Compile Include="LocalFuncs.cs" />
<Compile Include="NovetusLaunchForm.cs"> <Compile Include="NovetusLaunchForm.cs">
@ -88,6 +85,7 @@
<Content Include="NovetusIcon.ico" /> <Content Include="NovetusIcon.ico" />
<None Include="Resources\NOVETUS_new_final_smol.png" /> <None Include="Resources\NOVETUS_new_final_smol.png" />
</ItemGroup> </ItemGroup>
<Import Project="..\NovetusCore\NovetusCore.projitems" Label="Shared" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup> <PropertyGroup>
<PostBuildEvent>SET path=$(SolutionDir)build <PostBuildEvent>SET path=$(SolutionDir)build

View File

@ -18,6 +18,8 @@ namespace Novetus.Launch
//use novetus font for label!! //use novetus font for label!!
//https://stackoverflow.com/questions/1297264/using-custom-fonts-on-a-label-on-winforms //https://stackoverflow.com/questions/1297264/using-custom-fonts-on-a-label-on-winforms
GlobalFuncs.ReadInfoFile(LocalPaths.InfoPath, true, LocalPaths.LauncherPath);
PrivateFontCollection pfc = new PrivateFontCollection(); PrivateFontCollection pfc = new PrivateFontCollection();
int fontLength = Properties.Resources.Montserrat_SemiBold.Length; int fontLength = Properties.Resources.Montserrat_SemiBold.Length;
byte[] fontdata = Properties.Resources.Montserrat_SemiBold; byte[] fontdata = Properties.Resources.Montserrat_SemiBold;
@ -26,7 +28,7 @@ namespace Novetus.Launch
pfc.AddMemoryFont(data, fontLength); pfc.AddMemoryFont(data, fontLength);
VersionLabel.Font = new Font(pfc.Families[0], VersionLabel.Font.Size); VersionLabel.Font = new Font(pfc.Families[0], VersionLabel.Font.Size);
VersionLabel.Text = LocalFuncs.GetVersion(LocalPaths.ConfigPath + @"\\" + LocalPaths.LauncherInfoFile).ToUpper(); VersionLabel.Text = GlobalVars.ProgramInformation.Version.ToUpper();
LaunchNovetusButton.Font = new Font(pfc.Families[0], VersionLabel.Font.Size); LaunchNovetusButton.Font = new Font(pfc.Families[0], VersionLabel.Font.Size);
@ -59,7 +61,7 @@ namespace Novetus.Launch
private void DependencyInstallerButton_Click(object sender, EventArgs e) private void DependencyInstallerButton_Click(object sender, EventArgs e)
{ {
LocalFuncs.LaunchApplicationExt(LocalPaths.BasePathLauncher, LocalPaths.DependencyLauncherName); LocalFuncs.LaunchApplicationExt(GlobalPaths.BasePathLauncher, LocalPaths.DependencyLauncherName);
Close(); Close();
} }

View File

@ -21,6 +21,7 @@ Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution GlobalSection(SharedMSBuildProjectFiles) = preSolution
NovetusCore\NovetusCore.projitems*{2070eaa6-7606-4006-a628-5705c24a3644}*SharedItemsImports = 4 NovetusCore\NovetusCore.projitems*{2070eaa6-7606-4006-a628-5705c24a3644}*SharedItemsImports = 4
NovetusCore\NovetusCore.projitems*{bac99c87-f6c1-4ed0-aa2e-05c6ae8979ea}*SharedItemsImports = 4 NovetusCore\NovetusCore.projitems*{bac99c87-f6c1-4ed0-aa2e-05c6ae8979ea}*SharedItemsImports = 4
NovetusCore\NovetusCore.projitems*{d7b467ee-a4b9-42fb-aa83-f487da0f5cb1}*SharedItemsImports = 4
NovetusCore\NovetusCore.projitems*{debcc57d-9a3b-4d7c-8693-fa4aec56c8c1}*SharedItemsImports = 13 NovetusCore\NovetusCore.projitems*{debcc57d-9a3b-4d7c-8693-fa4aec56c8c1}*SharedItemsImports = 13
NovetusCore\NovetusCore.projitems*{f92ffbed-2767-4676-9711-bb89cda58a43}*SharedItemsImports = 4 NovetusCore\NovetusCore.projitems*{f92ffbed-2767-4676-9711-bb89cda58a43}*SharedItemsImports = 4
EndGlobalSection EndGlobalSection

View File

@ -136,7 +136,8 @@ namespace NovetusCMD
if (!LocalVars.PrintHelp) if (!LocalVars.PrintHelp)
{ {
GlobalFuncs.ReadInfoFile(GlobalPaths.ConfigDir + "\\" + GlobalPaths.InfoName, true); GlobalFuncs.ReadInfoFile(GlobalPaths.ConfigDir + "\\" + GlobalPaths.InfoName, true,
GlobalPaths.RootPathLauncher + "\\Novetus.exe");
Console.Title = "Novetus " + GlobalVars.ProgramInformation.Version + " CMD"; Console.Title = "Novetus " + GlobalVars.ProgramInformation.Version + " CMD";
GlobalFuncs.ConsolePrint("NovetusCMD version " + GlobalVars.ProgramInformation.Version + " loaded.", 1); GlobalFuncs.ConsolePrint("NovetusCMD version " + GlobalVars.ProgramInformation.Version + " loaded.", 1);

View File

@ -19,7 +19,7 @@ using System.Xml.Linq;
#region Global Functions #region Global Functions
public class GlobalFuncs public class GlobalFuncs
{ {
public static void ReadInfoFile(string infopath, bool cmd = false) public static void ReadInfoFile(string infopath, bool other = false, string exepath = "")
{ {
//READ //READ
string versionbranch, defaultclient, defaultmap, regclient1, string versionbranch, defaultclient, defaultmap, regclient1,
@ -39,27 +39,38 @@ public class GlobalFuncs
extendedversionnumber = ini.IniReadValue(section, "ExtendedVersionNumber", "False"); extendedversionnumber = ini.IniReadValue(section, "ExtendedVersionNumber", "False");
extendedversioneditchangelog = ini.IniReadValue(section, "ExtendedVersionEditChangelog", "False"); extendedversioneditchangelog = ini.IniReadValue(section, "ExtendedVersionEditChangelog", "False");
extendedversiontemplate = ini.IniReadValue(section, "ExtendedVersionTemplate", "%version%"); extendedversiontemplate = ini.IniReadValue(section, "ExtendedVersionTemplate", "%version%");
extendedversionrevision = ini.IniReadValue(section, "ExtendedVersionRevision", "1"); extendedversionrevision = ini.IniReadValue(section, "ExtendedVersionRevision", "-1");
try try
{ {
GlobalVars.ExtendedVersionNumber = Convert.ToBoolean(extendedversionnumber); GlobalVars.ExtendedVersionNumber = Convert.ToBoolean(extendedversionnumber);
if (GlobalVars.ExtendedVersionNumber) if (GlobalVars.ExtendedVersionNumber)
{ {
if (cmd) if (other)
{ {
var versionInfo = FileVersionInfo.GetVersionInfo(GlobalPaths.RootPathLauncher + "\\Novetus.exe"); if (!string.IsNullOrWhiteSpace(exepath))
GlobalVars.ProgramInformation.Version = extendedversiontemplate.Replace("%version%", versionbranch) {
.Replace("%build%", versionInfo.ProductBuildPart.ToString()) string dateformat = GetLinkerTimestampUtc(exepath).ToString("MM.yyyy");
.Replace("%revision%", versionInfo.FilePrivatePart.ToString()) var versionInfo = FileVersionInfo.GetVersionInfo(exepath);
.Replace("%extended-revision%", extendedversionrevision); GlobalVars.ProgramInformation.Version = extendedversiontemplate.Replace("%version%", versionbranch)
.Replace("%build%", versionInfo.ProductBuildPart.ToString())
.Replace("%revision%", versionInfo.FilePrivatePart.ToString())
.Replace("%extended-revision%", (!extendedversionrevision.Equals("-1") ? extendedversionrevision : ""))
.Replace("%compile-date%", dateformat);
}
else
{
return;
}
} }
else else
{ {
string dateformat = GetLinkerTimestampUtc(Assembly.GetExecutingAssembly()).ToString("MM.yyyy");
GlobalVars.ProgramInformation.Version = extendedversiontemplate.Replace("%version%", versionbranch) GlobalVars.ProgramInformation.Version = extendedversiontemplate.Replace("%version%", versionbranch)
.Replace("%build%", Assembly.GetExecutingAssembly().GetName().Version.Build.ToString()) .Replace("%build%", Assembly.GetExecutingAssembly().GetName().Version.Build.ToString())
.Replace("%revision%", Assembly.GetExecutingAssembly().GetName().Version.Revision.ToString()) .Replace("%revision%", Assembly.GetExecutingAssembly().GetName().Version.Revision.ToString())
.Replace("%extended-revision%", extendedversionrevision); .Replace("%extended-revision%", (!extendedversionrevision.Equals("-1") ? extendedversionrevision : ""))
.Replace("%compile-date%", dateformat);
} }
bool changelogedit = Convert.ToBoolean(extendedversioneditchangelog); bool changelogedit = Convert.ToBoolean(extendedversioneditchangelog);
@ -95,7 +106,7 @@ public class GlobalFuncs
} }
catch (Exception) catch (Exception)
{ {
ReadInfoFile(infopath, cmd); ReadInfoFile(infopath, other);
} }
} }
@ -1696,11 +1707,13 @@ public class GlobalFuncs
return Regex.Replace(lines, @"^\s*$\n|\r", string.Empty, RegexOptions.Multiline).TrimEnd(); return Regex.Replace(lines, @"^\s*$\n|\r", string.Empty, RegexOptions.Multiline).TrimEnd();
} }
#if !BASICLAUNCHER
//task.delay is only available on net 4.5....... //task.delay is only available on net 4.5.......
public static async void Delay(int miliseconds) public static async void Delay(int miliseconds)
{ {
await TaskEx.Delay(miliseconds); await TaskEx.Delay(miliseconds);
} }
#endif
// Credit to Carrot for the original code. Rewote it to be smaller. // Credit to Carrot for the original code. Rewote it to be smaller.
public static string CryptStringWithByte(string word) public static string CryptStringWithByte(string word)
@ -1750,5 +1763,29 @@ public class GlobalFuncs
adjustedSize, adjustedSize,
SizeSuffixes[mag]); SizeSuffixes[mag]);
} }
//https://www.meziantou.net/getting-the-date-of-build-of-a-dotnet-assembly-at-runtime.htm
public static DateTime GetLinkerTimestampUtc(Assembly assembly)
{
var location = assembly.Location;
return GetLinkerTimestampUtc(location);
}
public static DateTime GetLinkerTimestampUtc(string filePath)
{
const int peHeaderOffset = 60;
const int linkerTimestampOffset = 8;
var bytes = new byte[2048];
using (var file = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
file.Read(bytes, 0, bytes.Length);
}
var headerPos = BitConverter.ToInt32(bytes, peHeaderOffset);
var secondsSince1970 = BitConverter.ToInt32(bytes, headerPos + linkerTimestampOffset);
var dt = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
return dt.AddSeconds(secondsSince1970);
}
} }
#endregion #endregion

View File

@ -13,6 +13,7 @@ public class GlobalPaths
public static readonly string RootPath = Directory.GetParent(RootPathLauncher).ToString(); public static readonly string RootPath = Directory.GetParent(RootPathLauncher).ToString();
public static readonly string BasePath = RootPath.Replace(@"\", @"\\"); public static readonly string BasePath = RootPath.Replace(@"\", @"\\");
public static readonly string DataPath = BasePath + @"\\shareddata"; public static readonly string DataPath = BasePath + @"\\shareddata";
public static readonly string BinDir = BasePath + @"\\bin";
public static readonly string ConfigDir = BasePath + @"\\config"; public static readonly string ConfigDir = BasePath + @"\\config";
public static readonly string ConfigDirClients = ConfigDir + @"\\clients"; public static readonly string ConfigDirClients = ConfigDir + @"\\clients";
public static readonly string ConfigDirTemplates = ConfigDir + @"\\itemtemplates"; public static readonly string ConfigDirTemplates = ConfigDir + @"\\itemtemplates";

View File

@ -1,4 +1,5 @@
#region Usings #if !BASICLAUNCHER
#region Usings
using Mono.Nat; using Mono.Nat;
using System; using System;
#endregion #endregion
@ -52,3 +53,4 @@ public static class NetFuncs
} }
} }
#endregion #endregion
#endif

View File

@ -2,7 +2,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Net.PeerToPeer.Collaboration;
using System.Reflection; using System.Reflection;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Windows.Forms; using System.Windows.Forms;

View File

@ -267,10 +267,12 @@ public class SecurityFuncs
return ipAddress; return ipAddress;
} }
#if !BASICLAUNCHER
public static async Task<string> GetExternalIPAddressAsync() public static async Task<string> GetExternalIPAddressAsync()
{ {
var task = Task.Factory.StartNew(() => GetExternalIPAddress()); var task = Task.Factory.StartNew(() => GetExternalIPAddress());
return await task; return await task;
} }
#endif
} }
#endregion #endregion

View File

@ -52,6 +52,7 @@
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "InstallForm"; this.Name = "InstallForm";
this.Text = "Novetus URI Installer"; this.Text = "Novetus URI Installer";
this.Load += new System.EventHandler(this.InstallForm_Load);
this.ResumeLayout(false); this.ResumeLayout(false);
} }

View File

@ -16,6 +16,11 @@ namespace NovetusURI
#endregion #endregion
#region Form Events #region Form Events
private void InstallForm_Load(object sender, EventArgs e)
{
CenterToScreen();
}
private void button1_Click(object sender, EventArgs e) private void button1_Click(object sender, EventArgs e)
{ {
LocalFuncs.RegisterURI(this); LocalFuncs.RegisterURI(this);

View File

@ -94,6 +94,7 @@ namespace NovetusURI
else else
{ {
Visible = true; Visible = true;
CenterToScreen();
if (GlobalVars.UserConfiguration.DiscordPresence) if (GlobalVars.UserConfiguration.DiscordPresence)
{ {
label1.Text = "Starting Discord Rich Presence..."; label1.Text = "Starting Discord Rich Presence...";

View File

@ -20,6 +20,7 @@ namespace NovetusURI
void QuickConfigureLoad(object sender, EventArgs e) void QuickConfigureLoad(object sender, EventArgs e)
{ {
ReadConfigValues(GlobalPaths.ConfigDir + "\\" + GlobalPaths.ConfigName); ReadConfigValues(GlobalPaths.ConfigDir + "\\" + GlobalPaths.ConfigName);
CenterToScreen();
} }
void Button3Click(object sender, EventArgs e) void Button3Click(object sender, EventArgs e)