Skip to content

Commit

Permalink
Code refactoring, bug fixes, lots of changes to get ready for raspi/l…
Browse files Browse the repository at this point in the history
…inux again, new log/crashlog viewer
  • Loading branch information
nicko88 committed Feb 9, 2022
1 parent df0d6ab commit 01676cc
Show file tree
Hide file tree
Showing 35 changed files with 681 additions and 319 deletions.
6 changes: 3 additions & 3 deletions FanTrayIcon/TrayIcon.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using Microsoft.Win32;
using System;
using System;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using Microsoft.Win32;

namespace FanTrayIcon
{
Expand Down Expand Up @@ -43,7 +43,7 @@ public TrayIcon(string IP)
itemWebUI.Click += new EventHandler(itemWebUI_Click);

itemConsole = new ToolStripMenuItem();
itemConsole.Text = "Show Console Window";
itemConsole.Text = "Show Console Window (Log)";
itemConsole.CheckOnClick = true;
itemConsole.Click += new EventHandler(itemConsole_Click);

Expand Down
7 changes: 3 additions & 4 deletions HTFanControl/Controllers/LIRCController.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using HTFanControl.Util;

namespace HTFanControl.Controllers
{
class LIRCController : IController
{
private Socket _lircSocket;
private Dictionary<string, string> _lircMapping;
private readonly string _rootPath = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName);

private Settings _settings;

Expand Down Expand Up @@ -154,10 +153,10 @@ private bool SendLIRCBytes(byte[] cmd)
private void LoadLIRCMapping()
{
_lircMapping = null;
if (File.Exists(Path.Combine(_rootPath, "lircmapping.txt")))
if (File.Exists(Path.Combine(ConfigHelper._rootPath, "lircmapping.txt")))
{
_lircMapping = new Dictionary<string, string>();
string[] mappingFile = File.ReadAllLines(Path.Combine(_rootPath, "lircmapping.txt"));
string[] mappingFile = File.ReadAllLines(Path.Combine(ConfigHelper._rootPath, "lircmapping.txt"));

foreach (string s in mappingFile)
{
Expand Down
3 changes: 2 additions & 1 deletion HTFanControl/Controllers/MQTTController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using MQTTnet.Client.Options;
using System;
using System.Threading;
using HTFanControl.Util;

namespace HTFanControl.Controllers
{
Expand Down Expand Up @@ -38,6 +39,7 @@ public bool Connect()

IMqttClientOptions options = new MqttClientOptionsBuilder()
.WithTcpServer(_settings.MQTT_IP, port)
.WithCredentials(_settings.MQTT_User, _settings.MQTT_Pass)
.Build();

IAsyncResult result = _mqttClient.ConnectAsync(options);
Expand Down Expand Up @@ -114,7 +116,6 @@ public bool SendCMD(string cmd)
else
{
mqttPayload = "";
Console.WriteLine("(Ignored OFF Command)");
}
}

Expand Down
22 changes: 11 additions & 11 deletions HTFanControl/HTFanControl.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
<ApplicationIcon>htfancontrol.ico</ApplicationIcon>
<Configurations>Debug;ReleaseWin;ReleaseLinux</Configurations>
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
<AssemblyVersion>0.2.1.0</AssemblyVersion>
<FileVersion>0.2.1.0</FileVersion>
<Version>0.2.0</Version>
<AssemblyVersion>0.3.0.0</AssemblyVersion>
<FileVersion>0.3.0.0</FileVersion>
<Version>0.3.0</Version>
<Description>4D Theater Wind Effect - DIY Home Theater Project</Description>
<Copyright>nicko88</Copyright>
<Authors>nicko88</Authors>
Expand Down Expand Up @@ -37,16 +37,16 @@
</ItemGroup>

<ItemGroup>
<None Remove="html\50-cloud-init.yaml" />
<None Remove="html\add.html" />
<None Remove="html\checkupdate.html" />
<None Remove="html\crashlogs.html" />
<None Remove="html\download.html" />
<None Remove="html\downloadlist.html" />
<None Remove="html\edit.html" />
<None Remove="html\fantester.html" />
<None Remove="html\loadedwindtrack.html" />
<None Remove="html\logviewer.html" />
<None Remove="html\manage.html" />
<None Remove="html\raspiwifi.html" />
<None Remove="html\selectaudiodevice.html" />
<None Remove="html\selectplexplayer.html" />
<None Remove="html\selectvideo.html" />
Expand All @@ -55,8 +55,9 @@
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="html\50-cloud-init.yaml" />
<EmbeddedResource Include="html\checkupdate.html" />
<EmbeddedResource Include="html\crashlogs.html" />
<EmbeddedResource Include="html\logviewer.html" />
<EmbeddedResource Include="html\loadedwindtrack.html" />
<EmbeddedResource Include="html\selectaudiodevice.html" />
<EmbeddedResource Include="html\selectplexplayer.html" />
Expand All @@ -66,19 +67,18 @@
<EmbeddedResource Include="html\edit.html" />
<EmbeddedResource Include="html\manage.html" />
<EmbeddedResource Include="html\downloadlist.html" />
<EmbeddedResource Include="html\raspiwifi.html" />
<EmbeddedResource Include="html\settings.html" />
<EmbeddedResource Include="html\selectvideo.html" />
<EmbeddedResource Include="html\status.html" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="HtmlAgilityPack" Version="1.11.39" />
<PackageReference Include="HtmlAgilityPack" Version="1.11.42" />
<PackageReference Include="Microsoft.Win32.Registry" Version="5.0.0" />
<PackageReference Include="MQTTnet" Version="3.1.1" />
<PackageReference Include="MQTTnet" Version="3.1.2" />
<PackageReference Include="OpenTK.OpenAL" Version="4.6.7" />
<PackageReference Include="SoundFingerprinting" Version="7.16.0" />
<PackageReference Include="SoundFingerprinting.Emy" Version="7.16.0" />
<PackageReference Include="SoundFingerprinting" Version="8.4.0" />
<PackageReference Include="SoundFingerprinting.Emy" Version="8.3.0" />
</ItemGroup>

<ItemGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseWin|AnyCPU' Or '$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand Down
15 changes: 0 additions & 15 deletions HTFanControl/Log.cs

This file was deleted.

69 changes: 35 additions & 34 deletions HTFanControl/HTFanControl.cs → HTFanControl/Main/HTFanControl.cs
Original file line number Diff line number Diff line change
@@ -1,32 +1,30 @@
using HTFanControl.Players;
using System;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading;
using HTFanControl.Timers;
using System.IO.Compression;
using HTFanControl.Controllers;
using HTFanControl.Players;
using HTFanControl.Util;

namespace HTFanControl
namespace HTFanControl.Main
{
class HTFanControl
{
public readonly string _rootPath = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName);

public string _errorStatus;
public string _windtrackError;
public long _loadedVideoTime = 0;
public long _loadedVideoTime;
public string _loadedVideoFilename;
public string _currentWindtrackPath;
public string _windTrackHeader;
public int _curCmdIndex = -1;
public int _nextCmdIndex = 0;
public int _nextCmdIndex;
public bool _isPlaying = false;
public bool _isEnabled = true;
public bool _hasOffset = false;
public double _offset = 0;
public double _offset;
public bool _offsetEnabled = false;

public List<Tuple<TimeSpan, string>> _videoTimeCodes;
Expand All @@ -39,8 +37,12 @@ class HTFanControl

public Settings _settings;

public Log _log;

public HTFanControl()
{
_log = new Log();

_settings = Settings.LoadSettings();
Settings.SaveSettings(_settings);

Expand Down Expand Up @@ -115,7 +117,7 @@ private void SelectSyncSource()

public async void SelectVideo(string fileName)
{
ExtractWindtrack(Path.Combine(_rootPath, "windtracks", fileName + ".zip"), true);
ExtractWindtrack(Path.Combine(ConfigHelper._rootPath, "windtracks", fileName + ".zip"), true);

_loadedVideoFilename = "Loading Video Fingerprints...";
_windTrackHeader = "Loading Windtrack...";
Expand Down Expand Up @@ -153,11 +155,11 @@ public void ToggleFan()
{
_errorStatus = _fanController.ErrorStatus;
}
Console.WriteLine("Fans Disabled");
_log.LogMsg("Fans Disabled");
}
else
{
Console.WriteLine("Fans Enabled");
_log.LogMsg("Fans Enabled");

_isEnabled = true;

Expand All @@ -171,7 +173,7 @@ public void ToggleFan()
{
_errorStatus = _fanController.ErrorStatus;
}
Console.WriteLine($"Sent CMD: {_videoTimeCodes[_curCmdIndex].Item1.ToString("G").Substring(2, 12)},{_videoTimeCodes[_curCmdIndex].Item2}");
_log.LogMsg($"Sent CMD: {_videoTimeCodes[_curCmdIndex].Item1.ToString("G").Substring(2, 12)},{_videoTimeCodes[_curCmdIndex].Item2}");
}
}
catch { }
Expand Down Expand Up @@ -262,11 +264,11 @@ private void SendCmd(PositionTimer videoTimer, (string cmd, int index) command)

try
{
Console.WriteLine($"Sent CMD: {_videoTimeCodes[i].Item1.ToString("G").Substring(2, 12)},{fanCmd}");
_log.LogMsg($"Sent CMD: {_videoTimeCodes[i].Item1.ToString("G").Substring(2, 12)},{fanCmd}");
}
catch
{
Console.WriteLine($"Sent CMD: {fanCmd}");
_log.LogMsg($"Sent CMD: {fanCmd}");
}

if (_isEnabled)
Expand All @@ -287,20 +289,20 @@ private string GetWindtrackFilePath(string fileName, string filePath)
//look for windtrack .txt in tmp folder
try
{
if (File.Exists(Path.Combine(_rootPath, "tmp", fileName + ".txt")))
if (File.Exists(Path.Combine(ConfigHelper._rootPath, "tmp", fileName + ".txt")))
{
validFilePath = Path.Combine(_rootPath, "tmp", fileName + ".txt");
validFilePath = Path.Combine(ConfigHelper._rootPath, "tmp", fileName + ".txt");
}
}
catch { }

//look for windtrack .zip archive in windtracks folder
try
{
if (string.IsNullOrEmpty(validFilePath) && File.Exists(Path.Combine(_rootPath, "windtracks", fileName + ".zip")))
if (string.IsNullOrEmpty(validFilePath) && File.Exists(Path.Combine(ConfigHelper._rootPath, "windtracks", fileName + ".zip")))
{
ExtractWindtrack(Path.Combine(_rootPath, "windtracks", fileName + ".zip"), false);
validFilePath = Path.Combine(_rootPath, "tmp", fileName + ".txt");
ExtractWindtrack(Path.Combine(ConfigHelper._rootPath, "windtracks", fileName + ".zip"), false);
validFilePath = Path.Combine(ConfigHelper._rootPath, "tmp", fileName + ".txt");
}
}
catch { }
Expand All @@ -311,17 +313,17 @@ private string GetWindtrackFilePath(string fileName, string filePath)
if (string.IsNullOrEmpty(validFilePath) && File.Exists(Path.Combine(filePath, fileName + ".zip")))
{
ExtractWindtrack(Path.Combine(filePath, fileName + ".zip"), false);
validFilePath = Path.Combine(_rootPath, "tmp", fileName + ".txt");
validFilePath = Path.Combine(ConfigHelper._rootPath, "tmp", fileName + ".txt");
}
}
catch { }

//LEGACY look in windtrack folder
try
{
if (string.IsNullOrEmpty(validFilePath) && File.Exists(Path.Combine(_rootPath, "windtracks", fileName + ".txt")))
if (string.IsNullOrEmpty(validFilePath) && File.Exists(Path.Combine(ConfigHelper._rootPath, "windtracks", fileName + ".txt")))
{
validFilePath = Path.Combine(_rootPath, "windtracks", fileName + ".txt");
validFilePath = Path.Combine(ConfigHelper._rootPath, "windtracks", fileName + ".txt");
}
}
catch { }
Expand Down Expand Up @@ -412,14 +414,7 @@ private void LoadVideoTimecodes(string fileName, string filePath)
double? timeCode = null;
try
{
if (isFanCmd)
{
timeCode = TimeSpan.Parse(lineData[0]).TotalMilliseconds - _settings.GlobalOffsetMS;
}
else
{
timeCode = TimeSpan.Parse(lineData[0]).TotalMilliseconds;
}
timeCode = TimeSpan.Parse(lineData[0]).TotalMilliseconds;
}
catch
{
Expand All @@ -444,6 +439,11 @@ private void LoadVideoTimecodes(string fileName, string filePath)
}
}

if (isFanCmd)
{
timeCode = timeCode - _settings.GlobalOffsetMS;
}

rawPrevTime = (double)timeCode;

if (isFanCmd)
Expand Down Expand Up @@ -506,7 +506,7 @@ private void LoadVideoTimecodes(string fileName, string filePath)

private void ExtractWindtrack(string filePath, bool extractFingerprint)
{
DirectoryInfo tmp = new DirectoryInfo(Path.Combine(_rootPath, "tmp"));
DirectoryInfo tmp = new DirectoryInfo(Path.Combine(ConfigHelper._rootPath, "tmp"));
foreach (FileInfo file in tmp.GetFiles())
{
file.Delete();
Expand All @@ -518,11 +518,12 @@ private void ExtractWindtrack(string filePath, bool extractFingerprint)
{
using ZipArchive archive = ZipFile.OpenRead(filePath);

archive.Entries.Where(e => e.Name.Equals("commands.txt")).Single().ExtractToFile(Path.Combine(_rootPath, "tmp", fileName + ".txt"), true);
archive.Entries.Where(e => e.Name.Equals("commands.txt")).Single().ExtractToFile(Path.Combine(ConfigHelper._rootPath, "tmp", fileName + ".txt"), true);

if (extractFingerprint)
{
archive.Entries.Where(e => e.Name.Equals("full.fingerprints")).Single().ExtractToFile(Path.Combine(_rootPath, "tmp", fileName + ".fingerprints"), true);
Directory.CreateDirectory(Path.Combine(ConfigHelper._rootPath, "tmp", "fingerprint"));
archive.Entries.Where(e => e.Name.Equals("full.fingerprints")).Single().ExtractToFile(Path.Combine(new string[] { ConfigHelper._rootPath, "tmp", "fingerprint", "audio" }), true);
}
}
catch
Expand Down
Loading

0 comments on commit 01676cc

Please sign in to comment.