public void LocateGameClientFilePath(ConfigModelApp configApp) { if (File.Exists(configApp.GameFilePath)) { // File found vm.SetProblem(ProblemsFlags.GameClientFileNotFound, false); return; } else if (string.IsNullOrWhiteSpace(configApp.GameFilePath)) { using (RegistryKey key = Registry.LocalMachine.OpenSubKey("SOFTWARE\\WOW6432Node\\Wizards of the Coast\\MTGArena")) { if (key != null) { var o = key.GetValue("Path"); if (o != null) { // File deduced configApp.GameFilePath = Path.Combine(o as string, "MTGA.exe"); configApp.Save(); vm.SetProblem(ProblemsFlags.GameClientFileNotFound, false); return; } } } } // File not found vm.SetProblem(ProblemsFlags.GameClientFileNotFound, true); }
public OptionsWindow Init(ConfigModelApp configApp, string[] ratingSources) { var vm = Mapper.Map <OptionsWindowVM>(configApp); vm.ShowLimitedRatingsSources = ratingSources; DataContext = vm; return(this); }
public ServerApiCaller(LogFileZipper zipper, IOptionsMonitor <ConfigModelApp> configApp) { cookieContainer = new CookieContainer(); handler = new HttpClientHandler() { CookieContainer = cookieContainer }; client = new HttpClient(handler) { BaseAddress = baseAddress }; this.zipper = zipper; this.configApp = configApp?.CurrentValue; }
public void LocateLogFilePath(ConfigModelApp configApp) { if (File.Exists(configApp.LogFilePath)) { // File found vm.SetProblem(ProblemsFlags.LogFileNotFound, false); return; } else if (configApp.LogFilePath.StartsWith("E.g.")) { var pathDir = $"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}/../LocalLow/Wizards Of The Coast/MTGA"; if (Directory.Exists(pathDir)) { // File deduced configApp.LogFilePath = Path.GetFullPath($"{pathDir}/output_log.txt"); configApp.Save(); vm.SetProblem(ProblemsFlags.LogFileNotFound, false); return; } } // File not found vm.SetProblem(ProblemsFlags.LogFileNotFound, true); }
public MainWindow( //OptionsWindow optionsWindow, IOptionsMonitor <ConfigModelApp> configApp, ICollection <Card> allCards, MainWindowVM viewModel, ProcessMonitor processMonitor, LogFileZipper zipper, ServerApiCaller api, StartupShortcutManager startupManager, LogSplitter logSplitter, MtgaResourcesLocator resourcesLocator, FileMonitor fileMonitor, DraftHelper draftHelper, //LogProcessor logProcessor, ReaderMtgaOutputLog readerMtgaOutputLog, //CacheSingleton<ICollection<Card>> allCards, InGameTracker inMatchTracker, ExternalProviderTokenManager tokenManager, PasswordHasher passwordHasher, NotifyIconManager notifyIconManager, CacheSingleton <Dictionary <string, DraftRatings> > draftRatings ) { this.configApp = configApp.CurrentValue; //optionsWindow.Init(this.configApp); //optionsWindow.Owner = Window.GetWindow(this); //this.optionsWindow = optionsWindow; this.reader = readerMtgaOutputLog; this.processMonitor = processMonitor; processMonitor.OnProcessMonitorStatusChanged += OnProcessMonitorStatusChanged; this.zipper = zipper; this.api = api; this.startupManager = startupManager; this.logSplitter = logSplitter; this.resourcesLocator = resourcesLocator; this.fileMonitor = fileMonitor; fileMonitor.OnFileSizeChangedNewText += OnFileSizeChangedNewText; this.draftHelper = draftHelper; //this.logProcessor = logProcessor; this.inGameTracker = inMatchTracker; this.tokenManager = tokenManager; this.passwordHasher = passwordHasher; this.notifyIconManager = notifyIconManager; this.draftRatings = draftRatings; this.resourcesLocator.LocateLogFilePath(this.configApp); this.resourcesLocator.LocateGameClientFilePath(this.configApp); fileMonitor.SetFilePath(this.configApp.LogFilePath); //viewModel.ValidateUserId(this.configApp.UserId); viewModel.Opacity = this.configApp.Opacity; vm = viewModel; DataContext = vm; InitializeComponent(); ucWelcome.Init(tokenManager); ucPlaying.Init(vm, this.configApp.WindowSettingsOpponentCards); //trayIcon = new System.Windows.Forms.NotifyIcon { Text = "MTGAHelper Tracker" }; //trayIcon.Icon = new System.Drawing.Icon(Application.GetResourceStream(new Uri("pack://application:,,,/Assets/Images/wcC.ico")).Stream); //trayIcon.MouseClick += new System.Windows.Forms.MouseEventHandler(TrayIcon_MouseClick); //trayIcon.ContextMenu = new System.Windows.Forms.ContextMenu(new System.Windows.Forms.MenuItem[] //{ // new System.Windows.Forms.MenuItem("Quit", new EventHandler(TrayIcon_Quit)) //}); statusBarTop.Init(this, vm /*, draftHelper, logProcessor, this.configApp.UserId,*/); ucReady.Init(this.configApp.GameFilePath); ucDraftHelper.Init(allCards, vm.DraftingVM); //ucPlaying.Init(vm); ucDraftHelper.SetPopupRatingsSource(this.configApp.ShowLimitedRatings, this.configApp.ShowLimitedRatingsSource); this.processMonitor.Start(new System.Threading.CancellationToken()); this.fileMonitor.Start(new System.Threading.CancellationToken()); var timer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(200) }; timer.Tick += (object sender, EventArgs e) => { vm.SetCardsDraftFromBuffered(); vm.SetCardsInMatchTrackingFromBuffered(); }; timer.Start(); var timerTokenRefresh = new DispatcherTimer { Interval = TimeSpan.FromMinutes(9) }; timerTokenRefresh.Tick += (object sender, EventArgs e) => { RefreshAccessToken(); }; timerTokenRefresh.Start(); }
internal void ShowDialogOptions() { try { var ratingSources = draftRatings.Get().Keys.ToArray(); var optionsWindow = new OptionsWindow().Init(this.configApp, ratingSources); optionsWindow.Owner = this; optionsWindow.ShowDialog(); // The code will continue here only when the options window gets closed var newConfig = JsonConvert.DeserializeObject <ConfigModelApp>(JsonConvert.SerializeObject(configApp)); newConfig.LogFilePath = optionsWindow.txtLogFilePath.Text.Trim(); newConfig.GameFilePath = optionsWindow.txtGameFilePath.Text.Trim(); newConfig.RunOnStartup = optionsWindow.chkRunOnStartup.IsChecked.Value; newConfig.ShowOpponentCards = optionsWindow.chkShowOpponentCards.IsChecked.Value; newConfig.MinimizeToSystemTray = optionsWindow.chkMinimizeToSystemTray.IsChecked.Value; newConfig.AutoShowHideForMatch = optionsWindow.chkAutoShowHideForMatch.IsChecked.Value; newConfig.ForceCardPopup = optionsWindow.chkForceCardPopup.IsChecked.Value; newConfig.OrderLibraryCardsBy = optionsWindow.lstOrderLibraryCardsBy.SelectedValue.ToString(); newConfig.ForceCardPopupSide = optionsWindow.lstForceCardPopupSide?.SelectedValue?.ToString() ?? configApp.ForceCardPopupSide; newConfig.ShowLimitedRatingsSource = optionsWindow.lstShowLimitedRatingsSource?.SelectedValue?.ToString() ?? configApp.ShowLimitedRatingsSource; ShowInTaskbar = !newConfig.MinimizeToSystemTray; if (configApp.MinimizeToSystemTray != newConfig.MinimizeToSystemTray) { if (newConfig.MinimizeToSystemTray) { notifyIconManager.AddNotifyIcon(this); } else { notifyIconManager.RemoveNotifyIcon(); } } if (JsonConvert.SerializeObject(configApp) != JsonConvert.SerializeObject(newConfig)) { var oldLimitedRatings = configApp.ShowLimitedRatings; var oldLimitedRatingsSource = configApp.ShowLimitedRatingsSource; newConfig.Save(); configApp = newConfig; if (vm.MainWindowContext == MainWindowContextEnum.Drafting && (configApp.ShowLimitedRatings != oldLimitedRatings || configApp.ShowLimitedRatingsSource != oldLimitedRatingsSource)) { if (configApp.ShowLimitedRatingsSource != oldLimitedRatingsSource) { SetCardsDraft(vm.DraftingVM.CurrentDraftPickProgress); } ucDraftHelper.SetPopupRatingsSource(configApp.ShowLimitedRatings, configApp.ShowLimitedRatingsSource); } resourcesLocator.LocateLogFilePath(configApp); resourcesLocator.LocateGameClientFilePath(configApp); fileMonitor.SetFilePath(newConfig.LogFilePath); //vm.ValidateUserId(newConfig.UserId); //ServerApiGetCollection(); startupManager.ManageRunOnStartup(newConfig.RunOnStartup); ucReady.Init(configApp.GameFilePath); vm.OrderLibraryCardsBy = configApp.OrderLibraryCardsBy == "Converted Mana Cost" ? CardsListOrder.Cmc : CardsListOrder.DrawChance; } UpdateCardPopupPosition(); } catch (Exception ex) { Log.Write(LogEventLevel.Error, ex, "Unexpected error:"); } }
void ConfigureApp() { void RecreateAppSettings(string fileAppSettings) { var defaultSettings = JsonConvert.SerializeObject(new ConfigModelApp()); File.WriteAllText(fileAppSettings, defaultSettings); } var fileAppSettings = Path.Combine(folderForConfigAndLog, "appsettings.json"); string fileContent = ""; if (File.Exists(fileAppSettings) == false || new FileInfo(fileAppSettings).Length == 0) { RecreateAppSettings(fileAppSettings); } try { fileContent = File.ReadAllText(fileAppSettings); var appSettings = JsonConvert.DeserializeObject <ConfigModelApp>(fileContent); } catch (Exception ex) { Log.Error(ex, $"AppSettings file was invalid:{Environment.NewLine}{fileContent}", fileContent); RecreateAppSettings(fileAppSettings); } var configuration = new ConfigurationBuilder() .AddJsonFile(fileAppSettings, optional: false, reloadOnChange: true) .Build(); Log.Logger = new LoggerConfiguration() #if DEBUG || DEBUGWITHSERVER .MinimumLevel.Debug() #else .MinimumLevel.Information() #endif //.Filter.ByExcluding(c => c.Properties.Any(p => p.Value.ToString().Contains("outputLogError"))) .Enrich.With(new RemovePropertiesEnricher()) .WriteTo.File( Path.Combine(folderForConfigAndLog, "log-.txt"), rollingInterval: RollingInterval.Month, outputTemplate: "{Timestamp:dd HH:mm:ss} [{Level:u3}] ({ThreadId}) {Message}{NewLine}{Exception}" ) .CreateLogger(); Log.Write(LogEventLevel.Information, Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)); var serviceCollection = new ServiceCollection(); serviceCollection .RegisterServicesApp(configuration) .RegisterServicesLibOutputLogParser() .RegisterServicesWebModels() .RegisterServicesEntity(); provider = serviceCollection.BuildServiceProvider(); var configAppLib = provider.GetService <IOptionsMonitor <MTGAHelper.Lib.Config.ConfigModelApp> >(); Directory.CreateDirectory(folderData); configAppLib.CurrentValue.FolderData = folderData; configApp = provider.GetService <IOptionsMonitor <ConfigModelApp> >().CurrentValue; filePathAllCards = Path.Combine(folderData, "AllCardsCached.json"); filePathDraftRatings = Path.Combine(folderData, "draftRatings.json"); filePathDateFormats = Path.Combine(folderForConfigAndLog, "data", "dateFormats.json"); }