private static void CreateInstance(AppInfoFactory appInfoFactory) { if (appInfoFactory != null && !SettingsManager.XmlData.GamePath.IsNullOrWhitespace()) { var directoryInfo = new DirectoryInfo(SettingsManager.XmlData.GamePath); Context.Value = appInfoFactory.CreateInfo(directoryInfo); Logger.Debug("Found AppInfo.dll. Using AppInfo instance: {0}", Context.Value.AppName); return; } Logger.Error("Cannot find AppInfo.dll. Using default AppInfo instance."); Context.Value = DefaultAppInfo; }
public LaunchManager() { //the following is needed on linux... the current directory must be the Mono executable, which is bad. Environment.CurrentDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); try { FormIcon = Icon.FromHandle(Resources.IconSmall.GetHicon()); if (File.Exists(_pathLogFile)) { File.Delete(_pathLogFile); } XmlPreferences prefs = new XmlPreferences(); try { prefs = _prefsSerializer.Deserialize(_pathPrefsFile, new XmlPreferences()); } catch (Exception ex) { Command_Display_Error("Read preferences file", _pathPrefsFile, ex, "Special preferences will be reset"); } Preferences = prefs; Logger = new LoggerConfiguration().WriteTo.File(_pathLogFile, LogEventLevel.Verbose).MinimumLevel.Is(Preferences.MinimumEventLevel).CreateLogger(); var settings = new XmlSettings(); var history = new XmlHistory(); ; try { history = _historySerializer.Deserialize(_pathHistoryXml, new XmlHistory()); } catch (Exception ex) { Command_Display_Error("Load patching history", _pathHistoryXml, ex, "If the launcher was terminated unexpectedly last time, it may not be able to recover."); } try { settings = _settingsSerializer.Deserialize(_pathSettings, new XmlSettings()); } catch (Exception ex) { Command_Display_Error("Read settings file", _pathSettings, ex, "Patch list and other settings will be reset."); } #if DEBUG settings.BaseFolder = @"D:\Program Files (x86)\GOG Galaxy\Games\Pillars of Eternity II Deadfire"; settings.ModFolder = @"D:\Program Files (x86)\GOG Galaxy\Games\Pillars of Eternity II Deadfire\Mods"; #endif // Folder dialog string folderDialogReason = null; if (settings.BaseFolder == null) { folderDialogReason = "(no game folder has been specified)"; } else if (!Directory.Exists(settings.BaseFolder)) { folderDialogReason = "(the previous game folder does not exist)"; } if (folderDialogReason != null) { if (!Command_SetGameFolder_Dialog(folderDialogReason)) { Command_ExitApplication(); } } else { BaseFolder = settings.BaseFolder; } // Mod dialog string modFolderDialogReason = null; if (settings.ModFolder == null) { modFolderDialogReason = "(no mod folder has been specified)"; } else if (!Directory.Exists(settings.ModFolder)) { modFolderDialogReason = "(the previous mod folder does not exist)"; } if (modFolderDialogReason != null) { if (!Command_SetModFolder_Dialog(modFolderDialogReason)) { Command_ExitApplication(); } } else { ModFolder = settings.ModFolder; } _home = new guiHome(this) { Icon = FormIcon }; var defaultAppInfo = new AppInfo() { AppName = "No AppInfo.dll", }; AppInfoFactory gameInfoFactory = File.Exists(_pathGameInfoAssembly) ? PatchingHelper.LoadAppInfoFactory(_pathGameInfoAssembly) : null; AppInfo = gameInfoFactory?.CreateInfo(new DirectoryInfo(BaseFolder)) ?? defaultAppInfo; AppInfo.AppVersion = AppInfo.AppVersion ?? "version??"; var icon = TryOpenIcon(AppInfo.IconLocation) ?? _home.Icon.ToBitmap(); ProgramIcon = icon; Instructions = new DisposingBindingList <PatchInstruction>(); var instructions = new List <XmlInstruction>(); foreach (var xmlPatch in settings.Instructions) { try { Command_Direct_AddPatch(xmlPatch.PatchPath, xmlPatch.IsEnabled); } catch { instructions.Add(xmlPatch); } } var patchList = instructions.Select(x => x.PatchPath).Join(Environment.NewLine); if (patchList.Length > 0) { Command_Display_Error("Load patches on startup.", patchList); } try { PatchingHelper.RestorePatchedFiles(AppInfo, history.Files); } catch (Exception ex) { Command_Display_Error("Restore files", ex: ex); } _home.Closed += (sender, args) => Command_ExitApplication(); _icon = new NotifyIcon { Icon = FormIcon, Visible = false, Text = "Patchwork Launcher", ContextMenu = new ContextMenu { MenuItems = { new MenuItem("Quit", (o, e) => Command_ExitApplication()) } } }; File.Delete(_pathHistoryXml); } catch (Exception ex) { Command_Display_Error("Launch the application", ex: ex, message: "The application will now exit."); Command_ExitApplication(); } }