Files
Febe/src/Febe.Desktop/Program.cs
T

38 lines
1.5 KiB
C#

using System.Windows;
using Febe.Desktop.Core;
namespace Febe.Desktop;
/// <summary>
/// Entry point of Febe.exe (spec §12). Reads the command line, finds the Data folder (<c>--dati</c>, the folder recorded
/// after a move, or <c>%LOCALAPPDATA%\Febe</c>), makes sure only one Febe runs on it — a second launch asks the first to
/// show its window and exits — and starts the application.
/// </summary>
internal static class Program
{
[STAThread]
public static int Main(string[] args)
{
// The menu of the notification-area icon is Windows Forms: with the visual styles of Windows.
System.Windows.Forms.Application.EnableVisualStyles();
if (!DesktopCommandLine.TryParse(args, out var options, out var problem))
{
MessageBox.Show($"{problem}\n\n{DesktopCommandLine.Usage}", "Febe", MessageBoxButton.OK, MessageBoxImage.Warning);
return 2;
}
var folders = DesktopFolders.Current();
var locations = new RegistryLocationStore();
var dataFolder = options.DataFolder ?? locations.Current ?? folders.DefaultDataFolder;
using var instance = SingleInstanceGuard.TryAcquire(dataFolder);
if (instance is null)
{
SingleInstanceGuard.SignalFirst(dataFolder, InstanceMessages.For(options));
return 0;
}
var application = new DesktopApplication(options, folders, locations, dataFolder, options.DataFolder is not null, instance);
return application.Run();
}
}