-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
67 lines (60 loc) · 1.41 KB
/
Program.cs
File metadata and controls
67 lines (60 loc) · 1.41 KB
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
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace MP3te
{
class Program
{
/* Importazione per collegare la console se il programma è lanciato da terminale */
[DllImport("kernel32.dll")]
static extern bool AttachConsole(int dwProcessId);
private const int ATTACH_PARENT_PROCESS = -1;
[STAThread]
static void Main(string[] args)
{
if (args.Length > 0)
{
/* Modalità CLI */
RunCli(args);
}
else
{
/* Modalità GUI */
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
}
}
static void RunCli(string[] args)
{
/* Collega l'output alla console esistente */
AttachConsole(ATTACH_PARENT_PROCESS);
Console.WriteLine("\n[MP3te CLI Mode]");
if (args[0].ToLower() == "--help" || args[0].ToLower() == "-h")
{
Console.WriteLine("Usage: MP3te.exe [file_path] [title] [artist]");
return;
}
if (args.Length >= 3)
{
try
{
string path = args[0];
var meta = TagEngine.ReadTag(path);
meta.Title = args[1];
meta.Artist = args[2];
TagEngine.WriteTag(path, meta);
Console.WriteLine("Successfully updated: " + path);
}
catch (Exception ex)
{
Console.WriteLine("Error: " + ex.Message);
}
}
else
{
Console.WriteLine("Invalid arguments. Use --help for info.");
}
}
}
}