Skip to content

Commit

Permalink
Start .net8 Teslalogger if config file exists
Browse files Browse the repository at this point in the history
  • Loading branch information
bassmaster187 committed Oct 22, 2024
1 parent 0a6659f commit 955e4eb
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 0 deletions.
44 changes: 44 additions & 0 deletions TeslaLogger/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Threading.Tasks;
using Newtonsoft.Json;
using System.Security.Cryptography;
using System.Diagnostics;

namespace TeslaLogger
{
Expand Down Expand Up @@ -49,6 +50,8 @@ private static void Main(string[] _)
Logfile.Log(ex.ToString());
}

InitCheckNet8();

InitDebugLogging();

InitStage1();
Expand Down Expand Up @@ -113,6 +116,47 @@ private static void Main(string[] _)
}
}

private static void InitCheckNet8()
{
try
{
if (File.Exists("TESLALOGGERNET8"))
{
var net8version = Tools.GetNET8Version();
if (net8version?.Contains("8.") == true)
{
Logfile.Log("Start Teslalogger.net8");

// Copy settings for .net8
if (!Directory.Exists("data"))
{
Directory.CreateDirectory("data");
File.Copy("settings.json", "data/settings.json");
File.Copy("encryption.txt", "data/encryption.txt");
}

UpdateTeslalogger.Chmod("startnet8.sh", 777, false);

var p = new Process();
p.StartInfo.FileName = "/bin/bash";
p.StartInfo.Arguments = $"startnet8.sh";
p.StartInfo.CreateNoWindow = true;
p.StartInfo.UseShellExecute = false;
p.Start();

Thread.Sleep(5000);

Thread.CurrentThread.Abort();
}
}
}
catch (Exception ex)
{
ex.ToExceptionless().FirstCarUserID().Submit();
Logfile.Log(ex.ToString());
}
}

private static void InitMQTT()
{
try
Expand Down
26 changes: 26 additions & 0 deletions TeslaLogger/Tools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1234,6 +1234,32 @@ public static bool IsUnitTest()
return false;
}

public static bool IsDotnet8()
{
return Environment.Version?.ToString()?.StartsWith("8.0") == true;
}

public static bool IsDockerNET8()
{
try
{
string filename = "/tmp/teslalogger-dockernet8";

if (File.Exists(filename))
{
return true;
}

}
catch (Exception ex)
{
ex.ToExceptionless().FirstCarUserID().Submit();
Logfile.ExceptionWriter(ex, "IsDockerNET8");
}

return false;
}

public static bool IsShareData()
{
try
Expand Down
Binary file modified TeslaLogger/bin/TeslaLogger.exe
Binary file not shown.
5 changes: 5 additions & 0 deletions TeslaLogger/bin/startnet8.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
pkill mono
pkill dotnet
cd /etc/teslalogger/Debug/net8.0
nohup /home/cli/dotnet TeslaLoggerNET8.dll >/etc/teslalogger/nohup.out &

0 comments on commit 955e4eb

Please sign in to comment.