Replaced hardcoded save path with prop.txt loading

This commit is contained in:
Mercurio 2024-09-05 14:27:42 +02:00
parent 1e8fe94e3e
commit 0fc9a8cedf
17 changed files with 43 additions and 81 deletions

View file

@ -11,11 +11,11 @@ class Program
private static readonly string WebsocketAddress = "localhost"; private static readonly string WebsocketAddress = "localhost";
private static readonly int WebsocketPort = 10573; private static readonly int WebsocketPort = 10573;
private static Process? _ffmpegProcess; private static Process? _ffmpegProcess;
private static string _ffmpegFolderPath = "E:\\autorecording"; // Output folder path private static string _ffmpegFolderPath = GetFolderPath(); // Output folder path
private static WasapiCapture? _waveSource; private static WasapiCapture? _waveSource;
private static WaveFileWriter _writer; private static WaveFileWriter _writer = null!;
private static string _audioFilePath; private static string _audioFilePath = null!;
private static string _videoFilePath; private static string _videoFilePath = null!;
private static async Task Main(string[] args) private static async Task Main(string[] args)
{ {
@ -32,6 +32,41 @@ class Program
} }
} }
private static string GetFolderPath()
{
const string filePath = "prop.txt";
if (File.Exists(filePath))
{
var fileContent = File.ReadAllText(filePath);
var lines = fileContent.Split('\n');
foreach (var line in lines)
{
if (line.StartsWith("path:"))
{
var path = line["path:".Length..].Trim();
if (Directory.Exists(path))
{
return path;
}
Console.WriteLine($"The path specified in {filePath} does not exist.");
}
}
}
else
{
Console.WriteLine($"The file {filePath} does not exist.");
}
return GetDefaultVideosFolderPath();
}
private static string GetDefaultVideosFolderPath()
{
var userName = Environment.UserName;
var defaultPath = Path.Combine($@"C:\Users\{userName}", "Videos");
return defaultPath;
}
private static async Task ConnectWebSocket() private static async Task ConnectWebSocket()
{ {
var tickerUri = new Uri($"ws://{WebsocketAddress}:{WebsocketPort}"); var tickerUri = new Uri($"ws://{WebsocketAddress}:{WebsocketPort}");
@ -129,11 +164,11 @@ private static async Task ConnectWebSocket()
{ {
try try
{ {
string date = DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss"); var date = DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss");
_audioFilePath = $"{_ffmpegFolderPath}\\{songName}_{date}.wav"; _audioFilePath = $"{_ffmpegFolderPath}\\{songName}_{date}.wav";
// Ensure the output folder exists // Ensure the output folder exists
string outputFolder = Path.GetDirectoryName(_audioFilePath); var outputFolder = Path.GetDirectoryName(_audioFilePath)!;
Directory.CreateDirectory(outputFolder); Directory.CreateDirectory(outputFolder);
// Set up the WasapiLoopbackCapture // Set up the WasapiLoopbackCapture
@ -150,7 +185,7 @@ private static async Task ConnectWebSocket()
_waveSource.RecordingStopped += (sender, args) => _waveSource.RecordingStopped += (sender, args) =>
{ {
_writer.Dispose(); _writer.Dispose();
_writer = null; _writer = null!;
_waveSource.Dispose(); _waveSource.Dispose();
_waveSource = null; _waveSource = null;
}; };
@ -207,7 +242,7 @@ private static async Task ConnectWebSocket()
if (_writer != null) if (_writer != null)
{ {
_writer.Dispose(); _writer.Dispose();
_writer = null; _writer = null!;
} }
Console.WriteLine("Audio recording stopped."); Console.WriteLine("Audio recording stopped.");

View file

@ -1,4 +0,0 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v8.0", FrameworkDisplayName = ".NET 8.0")]

View file

@ -1,22 +0,0 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using System;
using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("2dxAutoClip")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+a57c1c2131efda17587033bc71e491a80341c7a5")]
[assembly: System.Reflection.AssemblyProductAttribute("2dxAutoClip")]
[assembly: System.Reflection.AssemblyTitleAttribute("2dxAutoClip")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
// Generated by the MSBuild WriteCodeFragment class.

View file

@ -1 +0,0 @@
3e6cb3d517cf16f5024618620589e2a0f678470e27b98cc7a5015180d535c471

View file

@ -1,13 +0,0 @@
is_global = true
build_property.TargetFramework = net8.0
build_property.TargetPlatformMinVersion =
build_property.UsingMicrosoftNETSdkWeb =
build_property.ProjectTypeGuids =
build_property.InvariantGlobalization =
build_property.PlatformNeutralAssembly =
build_property.EnforceExtendedAnalyzerRules =
build_property._SupportedPlatformList = Linux,macOS,Windows
build_property.RootNamespace = _2dxAutoClip
build_property.ProjectDir = E:\csharpcazzo\2dxAutoClip\2dxAutoClip\
build_property.EnableComHosting =
build_property.EnableGeneratedComInterfaceComImportInterop =

View file

@ -1,8 +0,0 @@
// <auto-generated/>
global using global::System;
global using global::System.Collections.Generic;
global using global::System.IO;
global using global::System.Linq;
global using global::System.Net.Http;
global using global::System.Threading;
global using global::System.Threading.Tasks;

View file

@ -1 +0,0 @@
0830f1c6b30f5c8085083f5a29432e6cf789b459174976f5fd1eba8751b79c8b

View file

@ -1,23 +0,0 @@
E:\csharpcazzo\2dxAutoClip\2dxAutoClip\bin\Debug\net8.0\2dxAutoClip.exe
E:\csharpcazzo\2dxAutoClip\2dxAutoClip\bin\Debug\net8.0\2dxAutoClip.deps.json
E:\csharpcazzo\2dxAutoClip\2dxAutoClip\bin\Debug\net8.0\2dxAutoClip.runtimeconfig.json
E:\csharpcazzo\2dxAutoClip\2dxAutoClip\bin\Debug\net8.0\2dxAutoClip.dll
E:\csharpcazzo\2dxAutoClip\2dxAutoClip\bin\Debug\net8.0\2dxAutoClip.pdb
E:\csharpcazzo\2dxAutoClip\2dxAutoClip\obj\Debug\net8.0\2dxAutoClip.GeneratedMSBuildEditorConfig.editorconfig
E:\csharpcazzo\2dxAutoClip\2dxAutoClip\obj\Debug\net8.0\2dxAutoClip.AssemblyInfoInputs.cache
E:\csharpcazzo\2dxAutoClip\2dxAutoClip\obj\Debug\net8.0\2dxAutoClip.AssemblyInfo.cs
E:\csharpcazzo\2dxAutoClip\2dxAutoClip\obj\Debug\net8.0\2dxAutoClip.csproj.CoreCompileInputs.cache
E:\csharpcazzo\2dxAutoClip\2dxAutoClip\obj\Debug\net8.0\2dxAutoClip.dll
E:\csharpcazzo\2dxAutoClip\2dxAutoClip\obj\Debug\net8.0\refint\2dxAutoClip.dll
E:\csharpcazzo\2dxAutoClip\2dxAutoClip\obj\Debug\net8.0\2dxAutoClip.pdb
E:\csharpcazzo\2dxAutoClip\2dxAutoClip\obj\Debug\net8.0\2dxAutoClip.genruntimeconfig.cache
E:\csharpcazzo\2dxAutoClip\2dxAutoClip\obj\Debug\net8.0\ref\2dxAutoClip.dll
E:\csharpcazzo\2dxAutoClip\2dxAutoClip\bin\Debug\net8.0\websocket-sharp.dll
E:\csharpcazzo\2dxAutoClip\2dxAutoClip\obj\Debug\net8.0\2dxAutoClip.csproj.AssemblyReference.cache
E:\csharpcazzo\2dxAutoClip\2dxAutoClip\obj\Debug\net8.0\2dxAutoC.C938E204.Up2Date
E:\csharpcazzo\2dxAutoClip\2dxAutoClip\bin\Debug\net8.0\NAudio.dll
E:\csharpcazzo\2dxAutoClip\2dxAutoClip\bin\Debug\net8.0\NAudio.Asio.dll
E:\csharpcazzo\2dxAutoClip\2dxAutoClip\bin\Debug\net8.0\NAudio.Core.dll
E:\csharpcazzo\2dxAutoClip\2dxAutoClip\bin\Debug\net8.0\NAudio.Midi.dll
E:\csharpcazzo\2dxAutoClip\2dxAutoClip\bin\Debug\net8.0\NAudio.Wasapi.dll
E:\csharpcazzo\2dxAutoClip\2dxAutoClip\bin\Debug\net8.0\NAudio.WinMM.dll

View file

@ -1 +0,0 @@
933adfe8fcac950842cb6e0074b7d293d2c3bc81a0f62d83339a699d54d8969c