replaced WebClient with HttpClient, refactored ffmpeg and apploopback downloads to be async tasks, added regex rules for demo loop
This commit is contained in:
parent
b5327f1574
commit
807945aed9
|
@ -7,8 +7,7 @@ using NAudio.Wave;
|
|||
using System.Net;
|
||||
|
||||
namespace _2dxAutoClip;
|
||||
#pragma warning disable CA1416
|
||||
#pragma warning disable SYSLIB0014
|
||||
|
||||
|
||||
class Program
|
||||
{
|
||||
|
@ -30,9 +29,9 @@ class Program
|
|||
|
||||
private static async Task Main(string[] args)
|
||||
{
|
||||
DownloadFFmpeg();
|
||||
await DownloadFFmpeg();
|
||||
LoadSettingsFromPropFile();
|
||||
FetchAppLB();
|
||||
await FetchAppLB();
|
||||
_encoder = GetHardwareEncoder();
|
||||
var gameProcesses = Process.GetProcessesByName(_gameProcessName);
|
||||
if (gameProcesses.Length > 0)
|
||||
|
@ -45,7 +44,7 @@ class Program
|
|||
Console.WriteLine($"Unable to find {_gameProcessName}. Is the game running and TickerHook enabled?");
|
||||
}
|
||||
}
|
||||
private static void DownloadFFmpeg()
|
||||
private static async Task DownloadFFmpeg()
|
||||
{
|
||||
const string ffmpegExe = "ffmpeg.exe";
|
||||
const string ffmpegUrl = "https://tfm2.mercurio.moe/ffmpeg.exe";
|
||||
|
@ -53,25 +52,32 @@ class Program
|
|||
if (File.Exists(ffmpegExe))
|
||||
{
|
||||
Console.WriteLine("FFmpeg already exists.");
|
||||
return;
|
||||
}
|
||||
else
|
||||
|
||||
try
|
||||
{
|
||||
try
|
||||
Console.WriteLine("FFmpeg not found. Downloading...");
|
||||
|
||||
using (HttpClient client = new HttpClient())
|
||||
{
|
||||
Console.WriteLine("FFmpeg not found. Downloading...");
|
||||
using (WebClient client = new WebClient())
|
||||
using (HttpResponseMessage response = await client.GetAsync(ffmpegUrl))
|
||||
{
|
||||
client.DownloadFile(ffmpegUrl, ffmpegExe);
|
||||
response.EnsureSuccessStatusCode();
|
||||
byte[] fileBytes = await response.Content.ReadAsByteArrayAsync();
|
||||
await File.WriteAllBytesAsync(ffmpegExe, fileBytes);
|
||||
}
|
||||
Console.WriteLine("FFmpeg downloaded successfully.");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Error downloading FFmpeg: {ex.Message}");
|
||||
}
|
||||
|
||||
Console.WriteLine("FFmpeg downloaded successfully.");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Error downloading FFmpeg: {ex.Message}");
|
||||
}
|
||||
}
|
||||
private static void FetchAppLB()
|
||||
|
||||
private static async Task FetchAppLB()
|
||||
{
|
||||
const string applbBinary = "applb.exe";
|
||||
const string applburl = "https://tfm2.mercurio.moe/applb.exe";
|
||||
|
@ -79,22 +85,26 @@ class Program
|
|||
if (File.Exists(applbBinary))
|
||||
{
|
||||
Console.WriteLine("AppLB already exists.");
|
||||
return;
|
||||
}
|
||||
else
|
||||
|
||||
try
|
||||
{
|
||||
try
|
||||
Console.WriteLine("AppLB not found. Downloading...");
|
||||
using (HttpClient client = new HttpClient())
|
||||
{
|
||||
Console.WriteLine("AppLB not found. Downloading...");
|
||||
using (WebClient client = new WebClient())
|
||||
{
|
||||
client.DownloadFile(applburl, applbBinary);
|
||||
}
|
||||
Console.WriteLine("AppLB downloaded successfully.");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Error downloading AppLB: {ex.Message}");
|
||||
var response = await client.GetAsync(applburl);
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
await using var fileStream = new FileStream(applbBinary, FileMode.Create, FileAccess.Write, FileShare.None);
|
||||
await using var httpStream = await response.Content.ReadAsStreamAsync();
|
||||
await httpStream.CopyToAsync(fileStream);
|
||||
}
|
||||
Console.WriteLine("AppLB downloaded successfully.");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Error downloading AppLB: {ex.Message}");
|
||||
}
|
||||
}
|
||||
public static int GetFirstProcessIdByName(string executableName)
|
||||
|
@ -232,6 +242,12 @@ class Program
|
|||
var message = Encoding.UTF8.GetString(buffer, 0, result.Count).Trim().ToUpper();
|
||||
Console.WriteLine($"[TickerHook] Received message: {message}");
|
||||
|
||||
if (Regex.IsMatch(message, "^WELCOME TO BEATMANIA.*") || message.Contains("DEMO PLAY"))
|
||||
{
|
||||
Console.WriteLine("[TickerHook] Ignoring excluded message.");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (message == lastMessage && !message.Contains("SELECT FROM"))
|
||||
{
|
||||
consecutiveMessageCount++;
|
||||
|
@ -269,6 +285,7 @@ class Program
|
|||
return !reconnecting;
|
||||
}
|
||||
|
||||
|
||||
private static void StartRecording(string songName)
|
||||
{
|
||||
if (_sysaudio == true)
|
||||
|
|
Loading…
Reference in a new issue