-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForm1.cs
690 lines (598 loc) · 28.2 KB
/
Form1.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
using DiscordRPC;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Text.Json;
using System.Windows.Forms;
using Windows.Media.Control;
using Windows.Storage.Streams;
namespace Media_Info_To_VRChat_Discord
{
public partial class Form1 : Form
{
private AppConfig config = new();
public AppConfig GlobalConfig
{
get { return config; }
set { config = value; }
}
private bool isSettingFormOpen = false;
private enum MediaType
{
Video,
Audio
}
static Mutex mutex;
private CancellationTokenSource? _cancellationTokenSource;
private readonly IPEndPoint _oscEndpoint = new(IPAddress.Parse("127.0.0.1"), 9000);
private static UdpClient? _vrchatUdpClient;
private static DiscordRpcClient? _discordClient;
private static bool discordTimestampsInited = false;
private static Timestamps? startTime;
private int VRC_OSC_Delay_Counter = 0;
private int Discord_Delay_Counter = 0;
private string title_temp = "";
private bool needUpdateThumbnail = true;
private bool needUpdateGUI = true;
private bool needUpdateIdleInfo = false;
private bool needUpdateExportedInfo = false;
private MediaType CurrentMediaType = MediaType.Audio;
private bool isThumbnailExportTaskRunning = false;
private bool isMediaInfoExportTaskRunning = false;
private NotifyIcon trayIcon;
private ContextMenuStrip trayMenu;
Image thumbnailImage = new Bitmap(100, 100);
public Form1(bool isRunningWithSystem)
{
InitializeComponent();
_vrchatUdpClient = new UdpClient();
_discordClient = null;
trayMenu = new ContextMenuStrip();
trayMenu.Items.Add("Exit", null, ExitApp!);
trayIcon = new NotifyIcon
{
Text = "Media Info Transmitter",
Icon = this.Icon,
ContextMenuStrip = trayMenu,
Visible = true
};
trayIcon.MouseDoubleClick += new MouseEventHandler(TrayIcon_MouseDoubleClick!);
this.Resize += new EventHandler(Form1_Resize!);
this.FormClosing += new FormClosingEventHandler(Form1_FormClosing!);
this.Shown += (sender, e) => Form1_Shown(sender!, e, isRunningWithSystem);
}
private void Form1_Shown(object sender, EventArgs e, bool isRunningWithSystem)
{
if (isRunningWithSystem) Hide();
}
private void Form1_Resize(object sender, EventArgs e)
{
if (this.WindowState == FormWindowState.Minimized)
{
this.Hide();
}
}
private void ExitApp(object sender, EventArgs e)
{
trayIcon.Visible = false;
System.Windows.Forms.Application.Exit();
}
protected override void OnFormClosing(FormClosingEventArgs e)
{
if (e.CloseReason == CloseReason.UserClosing)
{
e.Cancel = true;
this.WindowState = FormWindowState.Minimized;
if (!config.HideMinimizedNotification)
{
trayIcon.ShowBalloonTip(1000, "Media Info Transmitter", "Just Notice, the app is still running in the background.", ToolTipIcon.Info);
}
}
}
private void TrayIcon_MouseDoubleClick(object sender, MouseEventArgs e)
{
this.Show();
this.WindowState = FormWindowState.Normal;
needUpdateGUI = true;
}
private void Form1_Load(object sender, EventArgs e)
{
mutex = new Mutex(true, "Global\\MediaInfoTransmitter", out bool isNewInstance);
if (!isNewInstance)
{
Application.Exit();
}
StartBackgroundTask();
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
mutex.ReleaseMutex();
_cancellationTokenSource?.Cancel();
_vrchatUdpClient?.Close();
_discordClient?.Dispose();
}
private void StartBackgroundTask()
{
_cancellationTokenSource = new CancellationTokenSource();
Task.Run(() => BackgroundUpdateTask(_cancellationTokenSource.Token));
}
private async Task BackgroundUpdateTask(CancellationToken token)
{
config = ConfigManager.LoadConfig();
var mediaManager = GlobalSystemMediaTransportControlsSessionManager.RequestAsync().GetAwaiter().GetResult();
while (!token.IsCancellationRequested)
{
try
{
var currentSession = mediaManager.GetCurrentSession();
if (currentSession == null)
{
title_label.BeginInvoke(new Action(() => title_label.Text = "No playing media detected."));
if (needUpdateIdleInfo)
{
SendOSCMessage(BuildMediaInfoMsgForVRC(null, null, null));
if (_discordClient is not null) _discordClient!.ClearPresence();
needUpdateIdleInfo = false;
}
await Task.Delay(2000, token);
continue;
}
needUpdateIdleInfo = true;
var playbackInfo = currentSession.GetPlaybackInfo();
var mediaProperties = await currentSession.TryGetMediaPropertiesAsync();
if (mediaProperties!.AlbumTitle == "") // except for some specific songs, it's basically watching videos
{
if (CurrentMediaType != MediaType.Video)
{
if (_discordClient is not null)
{
_discordClient!.Dispose();
}
CurrentMediaType = MediaType.Video;
}
if (config.IgnoreSongsWithoutAlbum)
{
if (Visible)
{
title_label.BeginInvoke(new Action(() => title_label.Text = "No playing media detected."));
media_title.BeginInvoke(new Action(() => media_title.Text = $""));
media_title.BeginInvoke(new Action(() => media_artist.Text = $""));
media_title.BeginInvoke(new Action(() => media_album.Text = $""));
statusStrip1.BeginInvoke(new MethodInvoker(delegate { PlayStatusLabel.Text = $"Null"; }));
statusStrip1.BeginInvoke(new MethodInvoker(delegate { playtime_label.Text = $"Null"; }));
}
await Task.Delay(2000, token);
continue;
}
}
else
{
if (CurrentMediaType != MediaType.Audio)
{
if (_discordClient is not null)
{
_discordClient!.Dispose();
}
CurrentMediaType = MediaType.Audio;
}
}
Init_discord_RPC(CurrentMediaType);
var timeLine = currentSession.GetTimelineProperties();
var time_string = $"{FormatTime(timeLine.Position)}/{FormatTime(timeLine.EndTime)}";
if (title_temp != mediaProperties.Title)
{
title_temp = mediaProperties.Title;
needUpdateThumbnail = true;
needUpdateGUI = true;
}
if (needUpdateThumbnail)
{
needUpdateThumbnail = false;
try
{
using IRandomAccessStreamWithContentType stream = await mediaProperties.Thumbnail.OpenReadAsync();
using Stream netStream = stream.AsStreamForRead();
thumbnailImage.Dispose();
thumbnailImage = Image.FromStream(netStream);
}
catch
{
thumbnailImage = new Bitmap(100, 100);
}
if (config.EnableThumbnailExport)
{
CheckExportFolder();
_ = Task.Run(() =>
{
if (isThumbnailExportTaskRunning) return;
isThumbnailExportTaskRunning = true;
using Bitmap bitmapCopy = new(thumbnailImage);
if (config.ResizeExportedThumbnail)
{
int width = 100; //, height = 100;
using Bitmap resizedImage = new(width, width, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
using Graphics graphics = Graphics.FromImage(resizedImage);
graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
graphics.Clear(Color.Transparent);
int x = (width - bitmapCopy.Width * width / bitmapCopy.Width) / 2;
int y = (width - bitmapCopy.Height * width / bitmapCopy.Width) / 2;
graphics.DrawImage(bitmapCopy, x, y, width, width);
resizedImage.Save(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "export\\thumbnail.png"), System.Drawing.Imaging.ImageFormat.Png);
}
else
{
bitmapCopy.Save(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "export\\thumbnail.png"), System.Drawing.Imaging.ImageFormat.Png);
}
isThumbnailExportTaskRunning = false;
}, token);
}
}
// export info
if (config.EnableInformationExport)
{
if (playbackInfo.PlaybackStatus == GlobalSystemMediaTransportControlsSessionPlaybackStatus.Playing)
{
needUpdateExportedInfo = true;
}
else
{
needUpdateExportedInfo = false;
}
if (needUpdateExportedInfo)
{
_ = Task.Run(async () =>
{
try
{
if (isMediaInfoExportTaskRunning) return;
isMediaInfoExportTaskRunning = true;
var filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "export\\info.txt");
using FileStream fs = new(filePath, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);
using StreamWriter writer = new(fs);
await writer.WriteAsync(BuildMediaInfoMsgForExport(mediaProperties, playbackInfo, timeLine));
isMediaInfoExportTaskRunning = false;
}
catch (IOException)
{
// file is already opened
}
}, token);
}
}
if (!Visible && ThumbnailBox1.Image is not null)
{
ThumbnailBox1.BeginInvoke(new Action(() => { ThumbnailBox1.Image = null; }));
}
if (this.Visible && needUpdateGUI)
{
if (!needUpdateGUI) return;
needUpdateGUI = false;
try
{
title_label.BeginInvoke(new Action(() => title_label.Text = "Some information of the media:"));
media_title.BeginInvoke(new Action(() => media_title.Text = AdjustLabelText($"Title: {mediaProperties.Title}")));
if (config.IgnoreSongsWithoutAlbum)
{
media_title.BeginInvoke(new Action(() => media_artist.Text = $""));
media_title.BeginInvoke(new Action(() => media_album.Text = $""));
}
else
{
media_title.BeginInvoke(new Action(() => media_artist.Text = AdjustLabelText($"Artist: {mediaProperties.Artist}")));
media_title.BeginInvoke(new Action(() => media_album.Text = mediaProperties.AlbumTitle == "" ? "" : AdjustLabelText($"Album: {mediaProperties.AlbumTitle}")));
}
ThumbnailBox1.BeginInvoke(new Action(() => { ThumbnailBox1.Image = thumbnailImage; }));
}
catch { }
}
if (PlayStatusLabel.Text != $"{playbackInfo.PlaybackStatus}")
{
statusStrip1.BeginInvoke(new MethodInvoker(delegate { PlayStatusLabel.Text = $"{playbackInfo.PlaybackStatus}"; }));
}
if (playtime_label.Text != $"{time_string}")
{
statusStrip1.BeginInvoke(new MethodInvoker(delegate { playtime_label.Text = $"{time_string}"; }));
}
if (config.EnableDiscord_Transfer)
{
if (Discord_Delay_Counter == 2)
{
Discord_Delay_Counter = 1;
SetMediaInfoMsgForDiscord(mediaProperties, playbackInfo, timeLine);
}
else
{
Discord_Delay_Counter++;
}
}
if (config.EnableVRC_Transfer)
{
if (VRC_OSC_Delay_Counter == config.VRC_OSC_Refresh_Delay * 4)
{
VRC_OSC_Delay_Counter = 1;
SendOSCMessage(BuildMediaInfoMsgForVRC(mediaProperties, playbackInfo, timeLine));
}
else
{
VRC_OSC_Delay_Counter++;
}
}
}
catch { }
await Task.Delay(250, token);
}
}
private string BuildMediaInfoMsgForVRC(GlobalSystemMediaTransportControlsSessionMediaProperties? mediaProperties, GlobalSystemMediaTransportControlsSessionPlaybackInfo? playbackinfo, GlobalSystemMediaTransportControlsSessionTimelineProperties? timeline)
{
if (mediaProperties is null || timeline is null)
{
return "No media playing.";
}
var rtn_msg =
config.VRC_Msg_Format!
.Replace("{media.Title}", mediaProperties!.Title)
.Replace("{media.Artist}", mediaProperties!.Artist)
.Replace("{media.CurrentPosition}", FormatTime(timeline!.Position))
.Replace("{media.EndTime}", FormatTime(timeline!.EndTime))
.Replace("{media.StartTime}", FormatTime(timeline!.StartTime))
.Replace("{media.AlbumTitle}", mediaProperties!.AlbumTitle)
.Replace("{media.Subtitle}", mediaProperties!.Subtitle)
.Replace("{media.PlaybackStatus}", $"{playbackinfo!.PlaybackStatus}")
.Replace("{media.TrackNumber}", $"{mediaProperties!.TrackNumber}"
);
return rtn_msg;
}
private string BuildMediaInfoMsgForExport(GlobalSystemMediaTransportControlsSessionMediaProperties? mediaProperties, GlobalSystemMediaTransportControlsSessionPlaybackInfo? playbackinfo, GlobalSystemMediaTransportControlsSessionTimelineProperties? timeline)
{
if (mediaProperties is null || timeline is null)
{
return "No media playing.";
}
var rtn_msg =
config.Export_Msg_Format!
.Replace("{media.Title}", mediaProperties!.Title)
.Replace("{media.Artist}", mediaProperties!.Artist)
.Replace("{media.CurrentPosition}", FormatTime(timeline!.Position))
.Replace("{media.EndTime}", FormatTime(timeline!.EndTime))
.Replace("{media.StartTime}", FormatTime(timeline!.StartTime))
.Replace("{media.AlbumTitle}", mediaProperties!.AlbumTitle)
.Replace("{media.Subtitle}", mediaProperties!.Subtitle)
.Replace("{media.PlaybackStatus}", $"{playbackinfo!.PlaybackStatus}")
.Replace("{media.TrackNumber}", $"{mediaProperties!.TrackNumber}"
);
return rtn_msg;
}
private void SetMediaInfoMsgForDiscord(GlobalSystemMediaTransportControlsSessionMediaProperties? mediaProperties, GlobalSystemMediaTransportControlsSessionPlaybackInfo? playbackinfo, GlobalSystemMediaTransportControlsSessionTimelineProperties? timeline)
{
if (_discordClient is null || _discordClient.IsDisposed)
{
return;
}
if (!discordTimestampsInited)
{
discordTimestampsInited = true;
startTime = Timestamps.Now;
}
string state, details;
if (playbackinfo!.PlaybackStatus == GlobalSystemMediaTransportControlsSessionPlaybackStatus.Stopped ||
playbackinfo.PlaybackStatus == GlobalSystemMediaTransportControlsSessionPlaybackStatus.Closed ||
playbackinfo.PlaybackStatus == GlobalSystemMediaTransportControlsSessionPlaybackStatus.Opened)
{
state = "Idling";
details = "";
}
else
{
if (CurrentMediaType == MediaType.Audio)
{
state = timeline is null ? "0:00 / 0:00" : $"{playbackinfo.PlaybackStatus}: {FormatTime(timeline.Position)} / {FormatTime(timeline.EndTime)}";
details = $"{mediaProperties!.Artist} - {mediaProperties!.Title}";
}
else
{
state = mediaProperties!.Artist != "" ? $"By {mediaProperties!.Artist}" : "Watching video";
details = $"{mediaProperties!.Title}";
}
}
_discordClient!.SetPresence(new RichPresence()
{
State = state,
Details = details,
Timestamps = startTime,
Assets = new Assets()
{
LargeImageKey = CurrentMediaType == MediaType.Audio ? config.Discord_App_Music_Icon_URL : config.Discord_App_Video_Icon_URL,
LargeImageText = state
// SmallImageKey = "Play"
// SmallImageText = "Now playing"
}
});
}
public static string FormatTime(TimeSpan time)
{
int minutes = time.Minutes;
int seconds = time.Seconds;
string formattedMinutes = minutes.ToString().PadLeft(1, '0');
string formattedSeconds = seconds.ToString().PadLeft(2, '0');
return $"{formattedMinutes}:{formattedSeconds}";
}
private void SendOSCMessage(string songInfo)
{
byte[] oscMessage = BuildOscMessage("/chatbox/input", songInfo, true);
_vrchatUdpClient!.Send(oscMessage, oscMessage.Length, _oscEndpoint);
}
private static byte[] BuildOscMessage(string address, string text, bool show)
{
using var stream = new System.IO.MemoryStream();
void WritePaddedString(string str)
{
byte[] bytes = Encoding.UTF8.GetBytes(str);
stream.Write(bytes, 0, bytes.Length);
stream.Write(new byte[4 - (bytes.Length % 4)], 0, 4 - (bytes.Length % 4));
}
WritePaddedString(address);
WritePaddedString(",sT");
WritePaddedString(text);
stream.WriteByte((byte)(show ? 1 : 0));
return stream.ToArray();
}
private void Button1_Click(object sender, EventArgs e)
{
if (!isSettingFormOpen)
{
settingsForm settingForm = new(this);
settingForm.FormClosed += SettingForm_FormClosed!;
settingForm.Show();
isSettingFormOpen = true;
}
}
private void SettingForm_FormClosed(object sender, FormClosedEventArgs e)
{
ConfigManager.SaveConfig(config);
// check run with system
// for all users: %PROGRAMDATA%\Microsoft\Windows\Start Menu\Programs\Startup
string startupFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"Microsoft\Windows\Start Menu\Programs\Startup");
string shortcutPath = Path.Combine(startupFolder, "Media info transmitter.lnk");
if (config.StartWithSystem)
{
string arguments = "runningwithsystem";
CreateShortcut(shortcutPath, Application.ExecutablePath, arguments);
}
else
{
File.Delete(shortcutPath);
}
if (!config.EnableDiscord_Transfer)
{
if (_discordClient is not null) _discordClient!.Dispose();
discordTimestampsInited = false;
}
isSettingFormOpen = false;
}
public static void CreateShortcut(string shortcutPath, string targetPath, string arguments)
{
var shell = Activator.CreateInstance(Type.GetTypeFromProgID("WScript.Shell")!)! as dynamic;
var shortcut = shell.CreateShortcut(shortcutPath);
shortcut.TargetPath = targetPath;
shortcut.Arguments = arguments;
shortcut.Save();
}
private string AdjustLabelText(string fullText, int maxWidth = 340)
{
using Bitmap tempBitmap = new(1, 1);
using Graphics g = Graphics.FromImage(tempBitmap);
SizeF fullTextSize = g.MeasureString(fullText, title_label.Font);
if (fullTextSize.Width <= maxWidth)
{
return fullText;
}
string truncatedText = fullText;
while (truncatedText.Length > 0)
{
truncatedText = truncatedText.Substring(0, truncatedText.Length - 1);
string tempText = truncatedText + "...";
SizeF tempSize = g.MeasureString(tempText, title_label.Font);
if (tempSize.Width <= maxWidth)
{
return tempText;
}
}
return "...";
}
private void Init_discord_RPC(MediaType mediatype)
{
if (_discordClient is null || _discordClient.IsDisposed)
{
Init_discord_Client(mediatype);
}
}
private void Init_discord_Client(MediaType mediatype)
{
if (mediatype == MediaType.Video)
{
_discordClient = new DiscordRpcClient(config.Discord_App_Video_ID);
_discordClient.Initialize();
}
else
{
_discordClient = new DiscordRpcClient(config.Discord_App_Music_ID);
_discordClient.Initialize();
}
}
private static void CheckExportFolder()
{
if (!Directory.Exists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "export")))
{
Directory.CreateDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "export"));
}
}
}
public class AppConfig
{
public AppConfig()
{
StartWithSystem = false;
EnableVRC_Transfer = false;
EnableDiscord_Transfer = false;
HideMinimizedNotification = false;
VRC_OSC_Refresh_Delay = 5;
IgnoreSongsWithoutAlbum = false;
EnableInformationExport = false;
EnableThumbnailExport = false;
ResizeExportedThumbnail = true;
// start with mediaProperties. end with propertie name
VRC_Msg_Format =
"Now Playing: {media.Title}\n" +
"Artist: {media.Artist}\n" +
"Playtime: {media.CurrentPosition}/{media.EndTime}\n";
Export_Msg_Format =
"Now Playing: {media.Title}\n" +
"Artist: {media.Artist}\n" +
"Playtime: {media.CurrentPosition}/{media.EndTime}\n";
Discord_App_Music_ID = "0";
Discord_App_Video_ID = "0";
Discord_App_Music_Icon_URL = "https://assets.desu.life/Media_Info_Transmitter/Images/Music_Icon.png";
Discord_App_Video_Icon_URL = "https://assets.desu.life/Media_Info_Transmitter/Images/Video_Icon.png";
}
public bool StartWithSystem { get; set; }
public bool EnableVRC_Transfer { get; set; }
public bool EnableDiscord_Transfer { get; set; }
public int VRC_OSC_Refresh_Delay { get; set; }
public bool HideMinimizedNotification { get; set; }
public bool IgnoreSongsWithoutAlbum { get; set; }
public bool EnableInformationExport { get; set; }
public bool EnableThumbnailExport { get; set; }
public bool ResizeExportedThumbnail { get; set; }
public string? VRC_Msg_Format { get; set; }
public string? Export_Msg_Format { get; set; }
public string Discord_App_Music_ID { get; set; }
public string Discord_App_Video_ID { get; set; }
public string Discord_App_Music_Icon_URL { get; set; }
public string Discord_App_Video_Icon_URL { get; set; }
}
public class ConfigManager()
{
private static readonly string ConfigFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "media_info_transmitter_config.json");
public static AppConfig LoadConfig()
{
if (File.Exists(ConfigFilePath))
{
string jsonString = File.ReadAllText(ConfigFilePath);
return JsonSerializer.Deserialize<AppConfig>(jsonString)!;
}
else
{
var rtn = new AppConfig();
SaveConfig(rtn);
return rtn;
}
}
public static void SaveConfig(AppConfig config)
{
string jsonString = JsonSerializer.Serialize(config, new JsonSerializerOptions { WriteIndented = true });
File.WriteAllText(ConfigFilePath, jsonString);
}
}
}