using System;
using DHT.Utils.Logging;

namespace DHT.Desktop {
	sealed class Arguments {
		private static readonly Log Log = Log.ForType<Arguments>();

		public static Arguments Empty => new(Array.Empty<string>());

		public string? DatabaseFile { get; }
		public ushort? ServerPort { get; }
		public string? ServerToken { get; }

		public Arguments(string[] args) {
			for (int i = 0; i < args.Length; i++) {
				string key = args[i];

				if (i >= args.Length - 1) {
					Log.Warn("Missing value for command line argument: " + key);
					continue;
				}

				string value = args[++i];

				switch (key) {
					case "-db":
						DatabaseFile = value;
						continue;

					case "-port": {
						if (ushort.TryParse(value, out var port)) {
							ServerPort = port;
						}
						else {
							Log.Warn("Invalid port number: " + value);
						}

						continue;
					}

					case "-token":
						ServerToken = value;
						continue;

					default:
						Log.Warn("Unknown command line argument: " + key);
						break;
				}
			}
		}
	}
}

using System;
using DHT.Utils.Logging;

namespace DHT.Desktop {
	sealed class Arguments {
		private static readonly Log Log = Log.ForType<Arguments>();

		public static Arguments Empty => new(Array.Empty<string>());

		public string? DatabaseFile { get; }
		public ushort? ServerPort { get; }
		public string? ServerToken { get; }

		public Arguments(string[] args) {
			for (int i = 0; i < args.Length; i++) {
				string key = args[i];
				string value;

				if (i == 0 && !key.StartsWith('-')) {
					value = key;
					key = "-db";
				}
				else if (i >= args.Length - 1) {
					Log.Warn("Missing value for command line argument: " + key);
					continue;
				}
				else {
					value = args[++i];
				}

				switch (key) {
					case "-db":
						DatabaseFile = value;
						continue;

					case "-port": {
						if (ushort.TryParse(value, out var port)) {
							ServerPort = port;
						}
						else {
							Log.Warn("Invalid port number: " + value);
						}

						continue;
					}

					case "-token":
						ServerToken = value;
						continue;

					default:
						Log.Warn("Unknown command line argument: " + key);
						break;
				}
			}
		}
	}
}

Allow database file path to be passed as the first command line argument to the app
Allow database file path to be passed as the first command line argument to the app

This adds support for directly opening files with the DHT app, for ex. in Windows Explorer by using "Open With", or by associating the ".dht" extension with the app.
