public MainWindow() { Icon = Icon.ExtractAssociatedIcon(Assembly.GetExecutingAssembly().Location); Program.MainSynchronizationContext = SynchronizationContext.Current; Instance = this; InitializeComponent(); InstallDirectoryHelper.Initialize(GetGameDirectory()); SetupTabs(); Task.Run((Action)PopulateStartMenu); #if DEBUG var version = Assembly.GetExecutingAssembly().GetName().Version; #else var version = Assembly.GetExecutingAssembly().GetName().Version.ToString(3); #endif var gameName = InstallDirectoryHelper.GameType.GetFancyGameName(); var installDir = InstallDirectoryHelper.GameDirectory.FullName; Text = $"KK Manager {version} (New downloader edition) - [{gameName}] in {installDir}"; Console.WriteLine($"Game: {gameName} Path: {installDir}"); Settings.Default.Binder.BindControl(checkForUpdatesOnStartupToolStripMenuItem, settings => settings.AutoUpdateSearch, this); Settings.Default.Binder.SendUpdates(this); }
private static void Main(string[] args) { AppDomain.CurrentDomain.UnhandledException += (sender, arg) => Console.WriteLine("UNHANDLED EXCEPTION: " + arg.ExceptionObject); AppDomain.CurrentDomain.UnhandledException += NBug.Handler.UnhandledException; using (LogWriter.StartLogging()) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); const string guidValueName = "-guid:"; var silentInstallGuids = args.Where(x => x.StartsWith(guidValueName)).Select(x => x.Substring(guidValueName.Length).Trim(' ', '"')).ToArray(); args = args.Where(x => !x.StartsWith("-")).Where(x => !string.IsNullOrWhiteSpace(x)).ToArray(); if (args.Length == 0) { MessageBox.Show("Not enough arguments - the following arguments are supported:\n" + "Path to game root directory. This is mandatory and has to be the 1st argument.\n" + "One or more links to update sources. If no update source links are provided then UpdateSources file is used.\n\n" + "You can also add -guid:UPDATE_GUID arguments to not show the mod selection screen, and instead automatically install mods with the specified GUIDs.", "Invalid arguments", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } try { var gameDir = new DirectoryInfo(args[0]); if (!gameDir.Exists) { throw new IOException("Directory doesn't exist"); } InstallDirectoryHelper.Initialize(gameDir); } catch (Exception e) { MessageBox.Show($"Error opening game directory: {args[0]}\n\n{e}", "Invalid arguments", MessageBoxButtons.OK, MessageBoxIcon.Error); Console.WriteLine(e); return; } if (SelfUpdater.CheckForUpdatesAndShowDialog().Result == true) { return; } var updateSources = GetUpdateSources(args.Skip(1).ToArray()); if (updateSources == null || !updateSources.Any()) { return; } var window = ModUpdateProgressDialog.CreateUpdateDialog(updateSources, silentInstallGuids); window.Icon = Icon.ExtractAssociatedIcon(typeof(Program).Assembly.Location); Application.Run(window); } }