public OpponentWindow(Config config, ObservableCollection<Card> opponentDeck)
 {
     InitializeComponent();
     _config = config;
     ListViewOpponent.ItemsSource = opponentDeck;
     opponentDeck.CollectionChanged += OpponentDeckOnCollectionChanged;
     Height = (_config.OpponentWindowHeight == 0) ? 400 : _config.OpponentWindowHeight;
     Topmost = _config.WindowsTopmost;
     if (_config.WindowsBackgroundHex != "")
     {
         try
         {
             var convertFromString = ColorConverter.ConvertFromString(_config.WindowsBackgroundHex);
             if (convertFromString != null)
             {
                 var bgColor = (Color)convertFromString;
                 ListViewOpponent.Background = new SolidColorBrush(bgColor);
             }
         }
         catch (Exception)
         {
             //... no valid hex
         }
     }
 }
        public PlayerWindow(Config config, ObservableCollection<Card> playerDeck, bool forScreenshot = false)
        {
            InitializeComponent();
            _forScreenshot = forScreenshot;
            _config = config;
            ListViewPlayer.ItemsSource = playerDeck;
            playerDeck.CollectionChanged += PlayerDeckOnCollectionChanged;
            Height = _config.PlayerWindowHeight;
            if(_config.PlayerWindowLeft.HasValue)
                Left = _config.PlayerWindowLeft.Value;
            if(_config.PlayerWindowTop.HasValue)
                Top = _config.PlayerWindowTop.Value;
            Topmost = _config.WindowsTopmost;

            LblDrawChance1.Visibility = _config.HideDrawChances ? Visibility.Collapsed : Visibility.Visible;
            LblDrawChance2.Visibility = _config.HideDrawChances ? Visibility.Collapsed : Visibility.Visible;
            LblCardCount.Visibility = _config.HidePlayerCardCount ? Visibility.Collapsed : Visibility.Visible;
            LblDeckCount.Visibility = _config.HidePlayerCardCount ? Visibility.Collapsed : Visibility.Visible;
            ListViewPlayer.Visibility = _config.HidePlayerCards ? Visibility.Collapsed : Visibility.Visible;

            if(forScreenshot)
            {
                StackPanelDraw.Visibility = Visibility.Collapsed;
                StackPanelCount.Visibility = Visibility.Collapsed;

                Height = 34 * ListViewPlayer.Items.Count;
                Scale();
            }
        }
        public TimerWindow(Config config)
        {
            InitializeComponent();
            _config = config;

            Height = _config.TimerWindowHeight;
            Width = _config.TimerWindowWidth;

            if(_config.TimerWindowLeft.HasValue)
                Left = config.TimerWindowLeft.Value;
            if(_config.TimerWindowTop.HasValue)
                Top = config.TimerWindowTop.Value;
            Topmost = _config.TimerWindowTopmost;

            var titleBarCorners = new[]
                {
                    new Point((int)Left + 5, (int)Top + 5),
                    new Point((int)(Left + Width) - 5, (int)Top + 5),
                    new Point((int)Left + 5, (int)(Top + TitlebarHeight) - 5),
                    new Point((int)(Left + Width) - 5, (int)(Top + TitlebarHeight) - 5)
                };
            if(!Screen.AllScreens.Any(s => titleBarCorners.Any(c => s.WorkingArea.Contains(c))))
            {
                Top = 100;
                Left = 100;
            }
        }
		public OpponentWindow(GameV2 game, Config config, ObservableCollection<Card> opponentDeck)
		{
			InitializeComponent();
		    _game = game;
		    _config = config;
			ListViewOpponent.ItemsSource = opponentDeck;
			opponentDeck.CollectionChanged += OpponentDeckOnCollectionChanged;
			Height = _config.OpponentWindowHeight;
			if(_config.OpponentWindowLeft.HasValue)
				Left = _config.OpponentWindowLeft.Value;
			if(_config.OpponentWindowTop.HasValue)
				Top = _config.OpponentWindowTop.Value;
			Topmost = _config.WindowsTopmost;

			var titleBarCorners = new[]
			{
				new Point((int)Left + 5, (int)Top + 5),
				new Point((int)(Left + Width) - 5, (int)Top + 5),
				new Point((int)Left + 5, (int)(Top + TitlebarHeight) - 5),
				new Point((int)(Left + Width) - 5, (int)(Top + TitlebarHeight) - 5)
			};
			if(!Screen.AllScreens.Any(s => titleBarCorners.Any(c => s.WorkingArea.Contains(c))))
			{
				Top = 100;
				Left = 100;
			}
			Update();
		}
 public OptionsWindow(Config config, OverlayWindow overlay, XmlManager<Config> xmlManagerConfig, PlayerWindow playerWindow, OpponentWindow opponentWindow)
 {
     InitializeComponent();
     _config = config;
     _overlay = overlay;
     _xmlManagerConfig = xmlManagerConfig;
     _playerWindow = playerWindow;
     _opponentWindow = opponentWindow;
     LoadConfig();
     _initialized = true;
 }
        public TimerWindow(Config config)
        {
            InitializeComponent();
            _config = config;

            Height = _config.TimerWindowHeight;
            Width = _config.TimerWindowWidth;

            if(_config.TimerWindowLeft.HasValue)
                Left = config.TimerWindowLeft.Value;
            if(_config.TimerWindowTop.HasValue)
                Top = config.TimerWindowTop.Value;
            Topmost = _config.TimerWindowTopmost;
        }
        public TimerWindow(Config config)
        {
            InitializeComponent();
            _config = config;

            if (_config.TimerWindowLeft >= 0)
            {
                Left = config.TimerWindowLeft;
            }
            if (_config.TimerWindowTop >= 0)
            {
                Top = config.TimerWindowTop;
            }
            Topmost = _config.TimerWindowTopmost;
        }
        public OpponentWindow(Config config, ObservableCollection<Card> opponentDeck)
        {
            InitializeComponent();
            _config = config;
            ListViewOpponent.ItemsSource = opponentDeck;
            opponentDeck.CollectionChanged += OpponentDeckOnCollectionChanged;
            Height = _config.OpponentWindowHeight;
            if(_config.OpponentWindowLeft.HasValue)
                Left = _config.OpponentWindowLeft.Value;
            if(_config.OpponentWindowTop.HasValue)
                Top = _config.OpponentWindowTop.Value;
            Topmost = _config.WindowsTopmost;

            LblOpponentDrawChance1.Visibility = _config.HideOpponentDrawChances ? Visibility.Collapsed : Visibility.Visible;
            LblOpponentDrawChance2.Visibility = _config.HideOpponentDrawChances ? Visibility.Collapsed : Visibility.Visible;
            LblOpponentCardCount.Visibility = _config.HideOpponentCardCount ? Visibility.Collapsed : Visibility.Visible;
            LblOpponentDeckCount.Visibility = _config.HideOpponentCardCount ? Visibility.Collapsed : Visibility.Visible;
            ListViewOpponent.Visibility = _config.HideOpponentCards ? Visibility.Collapsed : Visibility.Visible;
        }
		public PlayerWindow(GameV2 game, Config config, ObservableCollection<Card> playerDeck, bool forScreenshot = false)
		{
			InitializeComponent();
		    _game = game;
		    _forScreenshot = forScreenshot;
			_config = config;
			ListViewPlayer.ItemsSource = playerDeck;
			playerDeck.CollectionChanged += PlayerDeckOnCollectionChanged;
			Height = _config.PlayerWindowHeight;
			if(_config.PlayerWindowLeft.HasValue)
				Left = _config.PlayerWindowLeft.Value;
			if(_config.PlayerWindowTop.HasValue)
				Top = _config.PlayerWindowTop.Value;
			Topmost = _config.WindowsTopmost;

			var titleBarCorners = new[]
			{
				new Point((int)Left + 5, (int)Top + 5),
				new Point((int)(Left + Width) - 5, (int)Top + 5),
				new Point((int)Left + 5, (int)(Top + TitlebarHeight) - 5),
				new Point((int)(Left + Width) - 5, (int)(Top + TitlebarHeight) - 5)
			};
			if(!Screen.AllScreens.Any(s => titleBarCorners.Any(c => s.WorkingArea.Contains(c))))
			{
				Top = 100;
				Left = 100;
			}


			if(forScreenshot)
			{
				CanvasPlayerChance.Visibility = Visibility.Collapsed;
				CanvasPlayerCount.Visibility = Visibility.Collapsed;
				LblWins.Visibility = Visibility.Collapsed;
				LblDeckTitle.Visibility = Visibility.Collapsed;

				Height = 34 * ListViewPlayer.Items.Count;
				Scale();
			}
			else
				Update();
		}
        public OverlayWindow(Config config, Hearthstone hearthstone)
        {
            InitializeComponent();
            _config = config;
            _hearthstone = hearthstone;

            ListViewPlayer.ItemsSource = _hearthstone.PlayerDeck;
            ListViewOpponent.ItemsSource = _hearthstone.EnemyCards;
            Scaling = 1.0;
            OpponentScaling = 1.0;
            ShowInTaskbar = _config.ShowInTaskbar;
            if (_config.VisibleOverlay)
            {
                Background = (SolidColorBrush)new BrushConverter().ConvertFrom("#4C0000FF");
            }
            _offsetX = _config.OffsetX;
            _offsetY = _config.OffsetY;
            _customWidth = _config.CustomWidth;
            _customHeight = _config.CustomHeight;
        }
        public MainWindow()
        {
            InitializeComponent();

            Helper.CheckForUpdates();

            //check for log config and create if not existing
            try
            {
                if (!File.Exists(_logConfigPath))
                {
                    File.Copy("Files/log.config", _logConfigPath);
                }
                else
                {
                    //update log.config if newer
                    var localFile = new FileInfo(_logConfigPath);
                    var file = new FileInfo("Files/log.config");
                    if (file.LastWriteTime > localFile.LastWriteTime)
                    {

                        File.Copy("Files/log.config", _logConfigPath, true);

                    }
                }
            }
            catch (UnauthorizedAccessException e)
            {
                MessageBox.Show(
                       e.Message + "\n\n" + e.InnerException +
                       "\n\n Please restart the tracker as administrator",
                       "Error writing log.config");
                Close();
                return;
            }
            catch (Exception e)
            {
                MessageBox.Show(
                       e.Message + "\n\n" + e.InnerException +
                       "\n\n What happend here? ",
                       "Error writing log.config");
                Close();
                return;
            }

            //load config
            _config = new Config();
            _xmlManagerConfig = new XmlManager<Config> {Type = typeof (Config)};
            try
            {
                _config = _xmlManagerConfig.Load("config.xml");
            }
            catch (Exception e)
            {
                MessageBox.Show(
                    e.Message + "\n\n" + e.InnerException +
                    "\n\n If you don't know how to fix this, please overwrite config with the default one.",
                    "Error loading config.xml");
                Close();
                return;
            }

            //load saved decks
            if (!File.Exists("PlayerDecks.xml"))
            {
                //avoid overwriting decks file with new releases.
                using (var sr = new StreamWriter("PlayerDecks.xml", false))
                {
                    sr.WriteLine("<Decks></Decks>");
                }
            }
            _xmlManager = new XmlManager<Decks> {Type = typeof (Decks)};
            try
            {
                _deckList = _xmlManager.Load("PlayerDecks.xml");
            }
            catch (Exception e)
            {
                MessageBox.Show(
                    e.Message + "\n\n" + e.InnerException +
                    "\n\n If you don't know how to fix this, please delete PlayerDecks.xml (this will cause you to lose your decks).",
                    "Error loading PlayerDecks.xml");
                Close();
                return;
            }

            ListboxDecks.ItemsSource = _deckList.DecksList;

            //hearthstone, loads db etc
            _hearthstone = new Hearthstone();
            _newDeck = new Deck();
            ListViewNewDeck.ItemsSource = _newDeck.Cards;

            //create overlay
            _overlay = new OverlayWindow(_config, _hearthstone) {Topmost = true};
            _overlay.Show();

            _playerWindow = new PlayerWindow(_config, _hearthstone.PlayerDeck);
            _opponentWindow = new OpponentWindow(_config, _hearthstone.EnemyCards);

            LoadConfig();

            //find hs directory
            if (!File.Exists(_config.HearthstoneDirectory + @"\Hearthstone.exe"))
            {
                MessageBox.Show("Please specify your Hearthstone directory", "Hearthstone directory not found",
                                MessageBoxButton.OK);
                var dialog = new OpenFileDialog();
                dialog.Title = "Select Hearthstone.exe";
                dialog.DefaultExt = "Hearthstone.exe";
                dialog.Filter = "Hearthstone.exe|Hearthstone.exe";
                var result = dialog.ShowDialog();
                if (result != true)
                {
                    return;
                }
                _config.HearthstoneDirectory = Path.GetDirectoryName(dialog.FileName);
                _xmlManagerConfig.Save("config.xml", _config);
            }

            //log reader
            _logReader = new HsLogReader(_config.HearthstoneDirectory, _config.UpdateDelay);
            _logReader.CardMovement += LogReaderOnCardMovement;
            _logReader.GameStateChange += LogReaderOnGameStateChange;
            _logReader.Analyzing += LogReaderOnAnalyzing;

            UpdateDbListView();

            _updateThread = new Thread(Update);
            _updateThread.Start();
            ListboxDecks.SelectedItem =
                _deckList.DecksList.FirstOrDefault(d => d.Name != null && d.Name == _config.LastDeck);

            _initialized = true;

            UpdateDeckList(ListboxDecks.SelectedItem as Deck);
            UseDeck(ListboxDecks.SelectedItem as Deck);

            _logReader.Start();
        }
예제 #12
0
		private async Task<string> InputDeckURL()
		{
			var settings = new MetroDialogSettings();
			var clipboard = Clipboard.ContainsText() ? Clipboard.GetText() : "";
			var validUrls = new[]
			{
				"hearthstats",
				"hss.io",
				"hearthpwn",
				"hearthhead",
				"hearthstoneplayers",
				"tempostorm",
				"hearthstonetopdeck",
				"hearthnews.fr",
				"arenavalue",
				"hearthstone-decks",
				"heartharena",
				"hearthstoneheroes",
				"elitedecks",
				"icy-veins",
				"hearthbuilder"
			};
			if(validUrls.Any(clipboard.Contains))
				settings.DefaultText = clipboard;

			if(Config.Instance.DisplayNetDeckAd)
			{
				var result =
					await
					this.ShowMessageAsync("NetDeck",
					                      "For easier (one-click!) web importing check out the NetDeck Chrome Extension!\n\n(This message will not be displayed again, no worries.)",
					                      MessageDialogStyle.AffirmativeAndNegative,
					                      new MetroDialogSettings {AffirmativeButtonText = "Show me!", NegativeButtonText = "No thanks"});

				if(result == MessageDialogResult.Affirmative)
				{
					Process.Start("https://chrome.google.com/webstore/detail/netdeck/lpdbiakcpmcppnpchohihcbdnojlgeel");
					var enableOptionResult =
						await
						this.ShowMessageAsync("Enable one-click importing?",
						                      "Would you like to enable one-click importing via NetDeck?\n(options > other > importing)",
						                      MessageDialogStyle.AffirmativeAndNegative,
						                      new MetroDialogSettings {AffirmativeButtonText = "Yes", NegativeButtonText = "No"});
					if(enableOptionResult == MessageDialogResult.Affirmative)
					{
						Options.OptionsTrackerImporting.CheckboxImportNetDeck.IsChecked = true;
						Config.Instance.NetDeckClipboardCheck = true;
						Config.Save();
					}
				}

				Config.Instance.DisplayNetDeckAd = false;
				Config.Save();
			}


			//import dialog
			var url =
				await this.ShowInputAsync("Import deck", "Supported websites:\n" + validUrls.Aggregate((x, next) => x + ", " + next), settings);
			return url;
		}
예제 #13
0
 public DeckExporter(Config config)
 {
     _config = config;
 }
예제 #14
0
        // Logic for dealing with legacy config file semantics
        // Use difference of versions to determine what should be done
        private void ConvertLegacyConfig(Version currentVersion, Version configVersion)
        {
            var converted = false;

            var v0_3_21 = new Version(0, 3, 21, 0);

            if (configVersion == null)            // Config was created prior to version tracking being introduced (v0.3.20)
            {
                Config.Instance.ResetAll();
                Config.Instance.CreatedByVersion = currentVersion.ToString();
                converted = true;
            }
            else
            {
                if (configVersion <= v0_3_21)
                {
                    // Config must be between v0.3.20 and v0.3.21 inclusive
                    // It was still possible in 0.3.21 to see (-32000, -32000) window positions
                    // under certain circumstances (GitHub issue #135).
                    if (Config.Instance.TrackerWindowLeft == -32000)
                    {
                        Config.Instance.Reset("TrackerWindowLeft");
                        converted = true;
                    }
                    if (Config.Instance.TrackerWindowTop == -32000)
                    {
                        Config.Instance.Reset("TrackerWindowTop");
                        converted = true;
                    }

                    if (Config.Instance.PlayerWindowLeft == -32000)
                    {
                        Config.Instance.Reset("PlayerWindowLeft");
                        converted = true;
                    }
                    if (Config.Instance.PlayerWindowTop == -32000)
                    {
                        Config.Instance.Reset("PlayerWindowTop");
                        converted = true;
                    }

                    if (Config.Instance.OpponentWindowLeft == -32000)
                    {
                        Config.Instance.Reset("OpponentWindowLeft");
                        converted = true;
                    }
                    if (Config.Instance.OpponentWindowTop == -32000)
                    {
                        Config.Instance.Reset("OpponentWindowTop");
                        converted = true;
                    }

                    if (Config.Instance.TimerWindowLeft == -32000)
                    {
                        Config.Instance.Reset("TimerWindowLeft");
                        converted = true;
                    }
                    if (Config.Instance.TimerWindowTop == -32000)
                    {
                        Config.Instance.Reset("TimerWindowTop");
                        converted = true;
                    }

                    //player scaling used to be increased by a very minimal about to circumvent some problem,
                    //should no longer be required. not sure is the increment is actually noticeable, but resetting can't hurt
                    if (Config.Instance.OverlayOpponentScaling > 100)
                    {
                        Config.Instance.OverlayOpponentScaling = 100;
                        converted = true;
                    }
                    if (Config.Instance.OverlayPlayerScaling > 100)
                    {
                        Config.Instance.OverlayPlayerScaling = 100;
                        converted = true;
                    }
                }


                if (configVersion <= new Version(0, 5, 1, 0))
                {
#pragma warning disable 612
                    Config.Instance.SaveConfigInAppData = Config.Instance.SaveInAppData;
                    Config.Instance.SaveDataInAppData   = Config.Instance.SaveInAppData;
                    converted = true;
#pragma warning restore 612
                }
                if (configVersion <= new Version(0, 6, 6, 0))
                {
                    if (Config.Instance.ExportClearX == 0.86)
                    {
                        Config.Instance.Reset("ExportClearX");
                        converted = true;
                    }
                    if (Config.Instance.ExportClearY == 0.16)
                    {
                        Config.Instance.Reset("ExportClearY");
                        converted = true;
                    }
                    if (Config.Instance.ExportClearCheckYFixed == 0.2)
                    {
                        Config.Instance.Reset("ExportClearCheckYFixed");
                        converted = true;
                    }
                }
                if (configVersion <= new Version(0, 7, 6, 0))
                {
                    if (Config.Instance.ExportCard1X != 0.04)
                    {
                        Config.Instance.Reset("ExportCard1X");
                        converted = true;
                    }
                    if (Config.Instance.ExportCard2X != 0.2)
                    {
                        Config.Instance.Reset("ExportCard2X");
                        converted = true;
                    }
                    if (Config.Instance.ExportCardsY != 0.168)
                    {
                        Config.Instance.Reset("ExportCardsY");
                        converted = true;
                    }
                }
            }

            if (converted)
            {
                Logger.WriteLine("changed config values", "ConvertLegacyConfig");
                Config.SaveBackup();
                Config.Save();
            }

            if (configVersion != null && currentVersion > configVersion)
            {
                _updatedVersion = currentVersion;
            }
        }
        public OverlayWindow(Config config, Game game)
        {
            InitializeComponent();
            _config = config;
            _game = game;

            ListViewPlayer.ItemsSource = _game.IsUsingPremade
                                             ? _game.PlayerDeck
                                             : _game.PlayerDrawn;
            ListViewOpponent.ItemsSource = _game.OpponentCards;
            Scaling = 1.0;
            OpponentScaling = 1.0;
            ShowInTaskbar = _config.ShowInTaskbar;
            if (_config.VisibleOverlay)
            {
                Background = (SolidColorBrush) new BrushConverter().ConvertFrom("#4C0000FF");
            }
            _offsetX = _config.OffsetX;
            _offsetY = _config.OffsetY;
            _customWidth = _config.CustomWidth;
            _customHeight = _config.CustomHeight;

            _cardLabels = new List<HearthstoneTextBlock>
                {
                    LblCard0,
                    LblCard1,
                    LblCard2,
                    LblCard3,
                    LblCard4,
                    LblCard5,
                    LblCard6,
                    LblCard7,
                    LblCard8,
                    LblCard9,
                };
            _cardMarkLabels = new List<HearthstoneTextBlock>
                {
                    LblCardMark0,
                    LblCardMark1,
                    LblCardMark2,
                    LblCardMark3,
                    LblCardMark4,
                    LblCardMark5,
                    LblCardMark6,
                    LblCardMark7,
                    LblCardMark8,
                    LblCardMark9,
                };
            _stackPanelsMarks = new List<StackPanel>
                {
                    Marks0,
                    Marks1,
                    Marks2,
                    Marks3,
                    Marks4,
                    Marks5,
                    Marks6,
                    Marks7,
                    Marks8,
                    Marks9,
                };

            UpdateScaling();
        }
예제 #16
0
        public static string Load()
        {
            var foundConfig = false;
            try
            {
                if(File.Exists("config.xml"))
                {
                    _config = XmlManager<Config>.Load("config.xml");
                    foundConfig = true;
                }
                else if(File.Exists(Instance.AppDataPath + @"\config.xml"))
                {
                    _config = XmlManager<Config>.Load(Instance.AppDataPath + @"\config.xml");
                    foundConfig = true;
                }
                else if(!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)))
                    //save locally if appdata doesn't exist (when e.g. not on C)
                    Instance.SaveInAppData = false;
            }
            catch(Exception e)
            {
                MessageBox.Show(
                    e.Message + "\n\n" + e.InnerException +
                    "\n\n If you don't know how to fix this, please delete " + Instance.ConfigPath,
                    "Error loading config.xml");
                Application.Current.Shutdown();
            }

            var configPath = Instance.ConfigPath;

            if(!foundConfig)
            {
                if(Instance.HomeDir != string.Empty)
                    Directory.CreateDirectory(Instance.HomeDir);
                using(var sr = new StreamWriter(Instance.ConfigPath, false))
                    sr.WriteLine("<Config></Config>");
            }
            else if(Instance.SaveInAppData) //check if config needs to be moved
            {
                if(File.Exists("config.xml"))
                {
                    Directory.CreateDirectory(Instance.HomeDir);
                    SaveBackup(true); //backup in case the file already exists
                    File.Move("config.xml", Instance.ConfigPath);
                    Logger.WriteLine("Moved config to appdata");
                }
            }
            else if(File.Exists(Instance.AppDataPath + @"\config.xml"))
            {
                SaveBackup(true); //backup in case the file already exists
                File.Move(Instance.AppDataPath + @"\config.xml", Instance.ConfigPath);
                Logger.WriteLine("Moved config to local");
            }

            return configPath;
        }
예제 #17
0
		public static void Load()
		{
			var foundConfig = false;
			Environment.CurrentDirectory = AppDomain.CurrentDomain.BaseDirectory;
			try
			{
				if(File.Exists("config.xml"))
				{
					_config = XmlManager<Config>.Load("config.xml");
					foundConfig = true;
				}
				else if(File.Exists(AppDataPath + @"\config.xml"))
				{
					_config = XmlManager<Config>.Load(AppDataPath + @"\config.xml");
					foundConfig = true;
				}
				else if(!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)))
					//save locally if appdata doesn't exist (when e.g. not on C)
					Instance.SaveConfigInAppData = false;
			}
			catch(Exception e)
			{
				MessageBox.Show(
				                e.Message + "\n\n" + e.InnerException + "\n\n If you don't know how to fix this, please delete "
				                + Instance.ConfigPath, "Error loading config.xml");
				Application.Current.Shutdown();
			}

			if(!foundConfig)
			{
				if(Instance.ConfigDir != string.Empty)
					Directory.CreateDirectory(Instance.ConfigDir);
				Save();
			}
			else if(Instance.SaveConfigInAppData != null)
			{
				if(Instance.SaveConfigInAppData.Value) //check if config needs to be moved
				{
					if(File.Exists("config.xml"))
					{
						Directory.CreateDirectory(Instance.ConfigDir);
						SaveBackup(true); //backup in case the file already exists
						File.Move("config.xml", Instance.ConfigPath);
						Log.Info("Moved config to appdata");
					}
				}
				else if(File.Exists(AppDataPath + @"\config.xml"))
				{
					SaveBackup(true); //backup in case the file already exists
					File.Move(AppDataPath + @"\config.xml", Instance.ConfigPath);
					Log.Info("Moved config to local");
				}
			}
		}
예제 #18
0
		public static void Load()
		{
			var foundConfig = false;
			Environment.CurrentDirectory = AppDomain.CurrentDomain.BaseDirectory;
			try
			{
				var config = Path.Combine(AppDataPath, "config.xml");
#if(SQUIRREL)
				if(File.Exists(config))
				{
					_config = XmlManager<Config>.Load(config);
					foundConfig = true;
				}
#else
				if(File.Exists("config.xml"))
				{
					_config = XmlManager<Config>.Load("config.xml");
					foundConfig = true;
				}
				else if(File.Exists(config))
				{
					_config = XmlManager<Config>.Load(config);
					foundConfig = true;
				}
				else if(!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)))
					//save locally if appdata doesn't exist (when e.g. not on C)
					Instance.SaveConfigInAppData = false;
#endif
			}
			catch(Exception ex)
			{
				Log.Error(ex);
				try
				{
					if(File.Exists("config.xml"))
					{
						File.Move("config.xml", Helper.GetValidFilePath(".", "config_corrupted", "xml"));
					}
					else if(File.Exists(AppDataPath + @"\config.xml"))
					{
						File.Move(AppDataPath + @"\config.xml", Helper.GetValidFilePath(AppDataPath, "config_corrupted", "xml"));
					}
				}
				catch(Exception ex1)
				{
					Log.Error(ex1);
				}
				_config = BackupManager.TryRestore<Config>("config.xml");
			}

			if(!foundConfig)
			{
				if(Instance.ConfigDir != string.Empty)
					Directory.CreateDirectory(Instance.ConfigDir);
				Save();
			}
#if(!SQUIRREL)
			else if(Instance.SaveConfigInAppData != null)
			{
				if(Instance.SaveConfigInAppData.Value) //check if config needs to be moved
				{
					if(File.Exists("config.xml"))
					{
						Directory.CreateDirectory(Instance.ConfigDir);
						SaveBackup(true); //backup in case the file already exists
						File.Move("config.xml", Instance.ConfigPath);
						Log.Info("Moved config to appdata");
					}
				}
				else if(File.Exists(AppDataPath + @"\config.xml"))
				{
					SaveBackup(true); //backup in case the file already exists
					File.Move(AppDataPath + @"\config.xml", Instance.ConfigPath);
					Log.Info("Moved config to local");
				}
			}
#endif
		}
예제 #19
0
        public static void Load()
        {
            var foundConfig = false;

            Environment.CurrentDirectory = AppDomain.CurrentDomain.BaseDirectory;
            try
            {
                if (File.Exists("config.xml"))
                {
                    _config = XmlManager <Config> .Load("config.xml");

                    foundConfig = true;
                }
                else if (File.Exists(Instance.AppDataPath + @"\config.xml"))
                {
                    _config = XmlManager <Config> .Load(Instance.AppDataPath + @"\config.xml");

                    foundConfig = true;
                }
                else if (!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)))
                {
                    //save locally if appdata doesn't exist (when e.g. not on C)
                    Instance.SaveConfigInAppData = false;
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(
                    e.Message + "\n\n" + e.InnerException + "\n\n If you don't know how to fix this, please delete "
                    + Instance.ConfigPath, "Error loading config.xml");
                Application.Current.Shutdown();
            }

            if (!foundConfig)
            {
                if (Instance.ConfigDir != string.Empty)
                {
                    Directory.CreateDirectory(Instance.ConfigDir);
                }
                using (var sr = new StreamWriter(Instance.ConfigPath, false))
                    sr.WriteLine("<Config></Config>");
            }
            else if (Instance.SaveConfigInAppData != null)
            {
                if (Instance.SaveConfigInAppData.Value)                //check if config needs to be moved
                {
                    if (File.Exists("config.xml"))
                    {
                        Directory.CreateDirectory(Instance.ConfigDir);
                        SaveBackup(true);                         //backup in case the file already exists
                        File.Move("config.xml", Instance.ConfigPath);
                        Logger.WriteLine("Moved config to appdata", "Config");
                    }
                }
                else if (File.Exists(Instance.AppDataPath + @"\config.xml"))
                {
                    SaveBackup(true);                     //backup in case the file already exists
                    File.Move(Instance.AppDataPath + @"\config.xml", Instance.ConfigPath);
                    Logger.WriteLine("Moved config to local", "Config");
                }
            }
        }
        private async void BtnResetOverlay_Click(object sender, RoutedEventArgs e)
        {
            var result =
                await
                this.ShowMessageAsync("Resetting overlay to default",
                                      "Positions of: Player Deck, Opponent deck, Timers and Secrets will be reset to default. Are you sure?",
                                      MessageDialogStyle.AffirmativeAndNegative);
            if (result != MessageDialogResult.Affirmative)
                return;

            if ((string)BtnUnlockOverlay.Content == "Lock")
            {
                await Overlay.UnlockUI();
                BtnUnlockOverlay.Content = "Unlock";
            }

            var defaultConfig = new Config();

            Config.Instance.PlayerDeckTop = defaultConfig.PlayerDeckTop;
            Config.Instance.PlayerDeckLeft = defaultConfig.PlayerDeckLeft;
            Config.Instance.PlayerDeckHeight = defaultConfig.PlayerDeckHeight;

            Config.Instance.OpponentDeckTop = defaultConfig.OpponentDeckTop;
            Config.Instance.OpponentDeckLeft = defaultConfig.OpponentDeckLeft;
            Config.Instance.OpponentDeckHeight = defaultConfig.OpponentDeckHeight;

            Config.Instance.TimersHorizontalPosition = defaultConfig.TimersHorizontalPosition;
            Config.Instance.TimersHorizontalSpacing = defaultConfig.TimersHorizontalSpacing;

            Config.Instance.SecretsTop = defaultConfig.SecretsTop;
            Config.Instance.SecretsLeft = defaultConfig.SecretsLeft;

            SaveConfig(true);
        }
		public MainWindow()
		{
			InitializeComponent();

			var version = Helper.CheckForUpdates(out _newVersion);
			if (version != null)
			{
				TxtblockVersion.Text = string.Format("Version: {0}.{1}.{2}", version.Major, version.Minor,
													 version.Build);
			}

			#region load config
			_config = new Config();
			_xmlManagerConfig = new XmlManager<Config> { Type = typeof(Config) };

			bool foundConfig = false;
			try
			{
				if (File.Exists("config.xml"))
				{
					_config = _xmlManagerConfig.Load("config.xml");
					foundConfig = true;
				}
				else if (File.Exists(_config.AppDataPath + @"\config.xml"))
				{
					_config = _xmlManagerConfig.Load(_config.AppDataPath + @"\config.xml");
					foundConfig = true;
				}
				else if (!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)))

				//save locally if appdata doesn't exist (when e.g. not on C)
				{
					_config.SaveInAppData = false;
				}

			}
			catch (Exception e)
			{
				MessageBox.Show(
					e.Message + "\n\n" + e.InnerException +
					"\n\n If you don't know how to fix this, please delete " + _config.ConfigPath,
					"Error loading config.xml");
				Application.Current.Shutdown();
			}
			_configPath = _config.ConfigPath;
			if (!foundConfig)
			{
				if (_config.HomeDir != string.Empty)
					Directory.CreateDirectory(_config.HomeDir);
				using (var sr = new StreamWriter(_config.ConfigPath, false))
				{
					sr.WriteLine("<Config></Config>");
				}
			}
			else
			{
				//check if config needs to be moved
				if (_config.SaveInAppData)
				{
					if (File.Exists("config.xml"))
					{
						Directory.CreateDirectory(_config.HomeDir);
						if (File.Exists(_config.ConfigPath))
						{
							//backup in case the file already exists
							File.Move(_configPath, _configPath + DateTime.Now.ToFileTime());
						}
						File.Move("config.xml", _config.ConfigPath);
						Logger.WriteLine("Moved config to appdata");
					}
				}
				else
				{
					if (File.Exists(_config.AppDataPath + @"\config.xml"))
					{
						if (File.Exists(_config.ConfigPath))
						{
							//backup in case the file already exists
							File.Move(_configPath, _configPath + DateTime.Now.ToFileTime());
						}
						File.Move(_config.AppDataPath + @"\config.xml", _config.ConfigPath);
						Logger.WriteLine("Moved config to local");
					}
				}
			}
			#endregion

			if (_config.SelectedTags.Count == 0)
				_config.SelectedTags.Add("All");

			_config.Debug = IS_DEBUG;

			if (_config.GenerateLog)
			{
				Directory.CreateDirectory("Logs");
				var listener = new TextWriterTraceListener(_config.LogFilePath);
				Trace.Listeners.Add(listener);
				Trace.AutoFlush = true;
			}

			#region find hearthstone dir
			if (string.IsNullOrEmpty(_config.HearthstoneDirectory) || !File.Exists(_config.HearthstoneDirectory + @"\Hearthstone.exe"))
			{
				using (var hsDirKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Hearthstone"))
				{
					if (hsDirKey != null)
					{
						var hsDir = (string)hsDirKey.GetValue("InstallLocation");

						//verify the installlocation actually is correct (possibly moved?)
						if (File.Exists(hsDir + @"\Hearthstone.exe"))
						{
							_config.HearthstoneDirectory = hsDir;
							WriteConfig();
							_foundHsDirectory = true;
						}
					}
				}
			}
			else
			{
				_foundHsDirectory = true;
			}

			if (_foundHsDirectory)
			{

				//check for log config and create if not existing
				try
				{
					//always overwrite is true by default. 
					if (!File.Exists(_logConfigPath))
					{
						_updatedLogConfig = true;
						File.Copy("Files/log.config", _logConfigPath, true);
						Logger.WriteLine(string.Format("Copied log.config to {0} (did not exist)", _configPath));
					}
					else
					{
						//update log.config if newer
						var localFile = new FileInfo(_logConfigPath);
						var file = new FileInfo("Files/log.config");
						if (file.LastWriteTime > localFile.LastWriteTime)
						{
							_updatedLogConfig = true;
							File.Copy("Files/log.config", _logConfigPath, true);
							Logger.WriteLine(string.Format("Copied log.config to {0} (file newer)", _configPath));
						}
						else if (_config.AlwaysOverwriteLogConfig)
						{
							File.Copy("Files/log.config", _logConfigPath, true);
							Logger.WriteLine(string.Format("Copied log.config to {0} (AlwaysOverwriteLogConfig)", _configPath));
						}
					}
				}
				catch (Exception e)
				{
					if (_updatedLogConfig)
					{
						MessageBox.Show(
							e.Message + "\n\n" + e.InnerException +
							"\n\n Please manually copy the log.config from the Files directory to \"%LocalAppData%/Blizzard/Hearthstone\".",
							"Error writing log.config");
						Application.Current.Shutdown();
					}
				}
			}
			#endregion

			string languageTag = _config.SelectedLanguage;
			//hearthstone, loads db etc - needs to be loaded before playerdecks, since cards are only saved as ids now
			_game = Helper.LanguageDict.ContainsValue(languageTag) ? new Game(languageTag) : new Game("enUS");
			_game.Reset();

			#region playerdecks
			_decksPath = _config.HomeDir + "PlayerDecks.xml";

			if (_config.SaveInAppData)
			{
				if (File.Exists("PlayerDecks.xml"))
				{
					if (File.Exists(_decksPath))
					{
						//backup in case the file already exists
						File.Move(_decksPath, _decksPath + DateTime.Now.ToFileTime());
					}
					File.Move("PlayerDecks.xml", _decksPath);
					Logger.WriteLine("Moved decks to appdata");
				}
			}
			else
			{
				var appDataPath = _config.AppDataPath + @"\PlayerDecks.xml";
				if (File.Exists(appDataPath))
				{
					if (File.Exists(_decksPath))
					{
						//backup in case the file already exists
						File.Move(_decksPath, _decksPath + DateTime.Now.ToFileTime());
					}
					File.Move(appDataPath, _decksPath);
					Logger.WriteLine("Moved decks to local");
				}
			}

			//load saved decks
			if (!File.Exists(_decksPath))
			{
				//avoid overwriting decks file with new releases.
				using (var sr = new StreamWriter(_decksPath, false))
				{
					sr.WriteLine("<Decks></Decks>");
				}
			}
			else
			{
				//the new playerdecks.xml wont work with versions below 0.2.19, make copy
				if (!File.Exists(_decksPath + ".old"))
				{
					File.Copy(_decksPath, _decksPath + ".old");
				}
			}

			_xmlManager = new XmlManager<Decks> { Type = typeof(Decks) };
			try
			{
				_deckList = _xmlManager.Load(_decksPath);
			}
			catch (Exception e)
			{
				MessageBox.Show(
					e.Message + "\n\n" + e.InnerException +
					"\n\n If you don't know how to fix this, please delete " + _decksPath + " (this will cause you to lose your decks).",
					"Error loading PlayerDecks.xml");
				Application.Current.Shutdown();
			}
			#endregion

			foreach (var deck in _deckList.DecksList)
			{
				DeckPickerList.AddDeck(deck);
			}
			DeckPickerList.SelectedDeckChanged += DeckPickerListOnSelectedDeckChanged;

			_notifyIcon = new System.Windows.Forms.NotifyIcon();
			_notifyIcon.Icon = new Icon(@"Images/HearthstoneDeckTracker.ico");
			_notifyIcon.MouseDoubleClick += NotifyIconOnMouseDoubleClick;
			_notifyIcon.Visible = false;

			_xmlManagerDeck = new XmlManager<Deck>();
			_xmlManagerDeck.Type = typeof(Deck);

			_newDeck = new Deck();
			ListViewNewDeck.ItemsSource = _newDeck.Cards;


			//create overlay
			_overlay = new OverlayWindow(_config, _game) { Topmost = true };
			if (_foundHsDirectory)
			{
				_overlay.Show();
			}
			_playerWindow = new PlayerWindow(_config, _game.IsUsingPremade ? _game.PlayerDeck : _game.PlayerDrawn);
			_opponentWindow = new OpponentWindow(_config, _game.OpponentCards);
			_timerWindow = new TimerWindow(_config);

			if (_config.WindowsOnStartup)
			{
				_playerWindow.Show();
				_opponentWindow.Show();
			}
			if (_config.TimerWindowOnStartup)
			{
				_timerWindow.Show();
			}
			if (!_deckList.AllTags.Contains("All"))
			{
				_deckList.AllTags.Add("All");
				WriteDecks();
			}
			if (!_deckList.AllTags.Contains("Arena"))
			{
				_deckList.AllTags.Add("Arena");
				WriteDecks();
			}
			if (!_deckList.AllTags.Contains("Constructed"))
			{
				_deckList.AllTags.Add("Constructed");
				WriteDecks();
			}

			ComboboxAccent.ItemsSource = ThemeManager.Accents;
			ComboboxTheme.ItemsSource = ThemeManager.AppThemes;
			ComboboxLanguages.ItemsSource = Helper.LanguageDict.Keys;

			ComboboxKeyPressGameStart.ItemsSource = EventKeys.Split(',');
			ComboboxKeyPressGameEnd.ItemsSource = EventKeys.Split(',');

			LoadConfig();

			_deckImporter = new DeckImporter(_game);
			_deckExporter = new DeckExporter(_config);

			//this has to happen before reader starts
			var lastDeck = _deckList.DecksList.FirstOrDefault(d => d.Name == _config.LastDeck);
			DeckPickerList.SelectDeck(lastDeck);

			//deck options flyout button events
			DeckOptionsFlyout.BtnDeleteDeck.Click += DeckOptionsFlyoutBtnDeleteDeck_Click;
			DeckOptionsFlyout.BtnExportHs.Click += DeckOptionsFlyoutBtnExportHs_Click;
			DeckOptionsFlyout.BtnNotes.Click += DeckOptionsFlyoutBtnNotes_Click;
			DeckOptionsFlyout.BtnScreenshot.Click += DeckOptionsFlyoutBtnScreenhot_Click;
			DeckOptionsFlyout.BtnCloneDeck.Click += DeckOptionsFlyoutCloneDeck_Click;
			DeckOptionsFlyout.BtnTags.Click += DeckOptionsFlyoutBtnTags_Click;
			DeckOptionsFlyout.BtnSaveToFile.Click += DeckOptionsFlyoutBtnSaveToFile_Click;
			DeckOptionsFlyout.BtnClipboard.Click += DeckOptionsFlyoutBtnClipboard_Click;

			DeckOptionsFlyout.DeckOptionsButtonClicked += CloseDeckOptionsFlyout;

			//deck import flyout button events
			DeckImportFlyout.BtnWeb.Click += DeckImportFlyoutBtnWebClick;
			DeckImportFlyout.BtnArenavalue.Click += DeckImportFlyoutBtnArenavalue_Click;
			DeckImportFlyout.BtnFile.Click += DeckImportFlyoutBtnFile_Click;
			DeckImportFlyout.BtnIdString.Click += DeckImportFlyoutBtnIdString_Click;

			DeckImportFlyout.DeckOptionsButtonClicked += CloseDeckImportFlyout;

			//log reader
			_logReader = new HsLogReader(_config.HearthstoneDirectory, _config.UpdateDelay);
			_logReader.CardMovement += LogReaderOnCardMovement;
			_logReader.GameStateChange += LogReaderOnGameStateChange;
			_logReader.Analyzing += LogReaderOnAnalyzing;
			_logReader.TurnStart += LogReaderOnTurnStart;
			_logReader.CardPosChange += LogReaderOnCardPosChange;
			_logReader.SecretPlayed += LogReaderOnSecretPlayed;

			_turnTimer = new TurnTimer(90);
			_turnTimer.TimerTick += TurnTimerOnTimerTick;

			TagControlFilter.HideStuffToCreateNewTag();
			TagControlNewDeck.OperationSwitch.Visibility = Visibility.Collapsed;
			TagControlMyDecks.OperationSwitch.Visibility = Visibility.Collapsed;

			TagControlNewDeck.NewTag += TagControlOnNewTag;
			TagControlNewDeck.SelectedTagsChanged += TagControlOnSelectedTagsChanged;
			TagControlNewDeck.DeleteTag += TagControlOnDeleteTag;
			TagControlMyDecks.NewTag += TagControlOnNewTag;
			TagControlMyDecks.SelectedTagsChanged += TagControlOnSelectedTagsChanged;
			TagControlMyDecks.DeleteTag += TagControlOnDeleteTag;
			TagControlFilter.SelectedTagsChanged += TagControlFilterOnSelectedTagsChanged;
			TagControlFilter.OperationChanged += TagControlFilterOnOperationChanged;


			UpdateDbListView();

			_doUpdate = _foundHsDirectory;
			UpdateOverlayAsync();

			_initialized = true;

			DeckPickerList.UpdateList();
			if (lastDeck != null)
			{
				DeckPickerList.SelectDeck(lastDeck);
				UpdateDeckList(lastDeck);
				UseDeck(lastDeck);
			}

			if (_foundHsDirectory)
			{
				_logReader.Start();
			}

			Helper.SortCardCollection(ListViewDeck.Items, _config.CardSortingClassFirst);

		}
        public MainWindow()
        {
            InitializeComponent();

            Helper.CheckForUpdates();

            //check for log config and create if not existing
            try
            {
                if (!File.Exists(_logConfigPath))
                {
                    File.Copy("Files/log.config", _logConfigPath);
                }
                else
                {
                    //update log.config if newer
                    var localFile = new FileInfo(_logConfigPath);
                    var file = new FileInfo("Files/log.config");
                    if (file.LastWriteTime > localFile.LastWriteTime)
                    {

                        File.Copy("Files/log.config", _logConfigPath, true);

                    }
                }
            }
            catch (UnauthorizedAccessException ex)
            {
                Console.WriteLine("Not authorized write " + _logConfigPath + ". Start as admin(?)");
                Console.WriteLine(ex.Message);
            }
            catch (IOException ex)
            {
                Console.WriteLine(ex.Message);
            }

            //load config
            _config = new Config();
            _xmlManagerConfig = new XmlManager<Config> {Type = typeof (Config)};
            _config = _xmlManagerConfig.Load("config.xml");

            //load saved decks
            if (!File.Exists("PlayerDecks.xml"))
            {
                //avoid overwriting decks file with new releases.
                using (var sr = new StreamWriter("PlayerDecks.xml", false))
                {
                    sr.WriteLine("<Decks></Decks>");
                }
            }
            _xmlManager = new XmlManager<Decks> {Type = typeof (Decks)};
            _deckList = _xmlManager.Load("PlayerDecks.xml");

            //add saved decks to gui
            foreach (var deck in _deckList.DecksList)
            {
                ComboBoxDecks.Items.Add(deck.Name);
            }
            ComboBoxDecks.SelectedItem = _config.LastDeck;

            //hearthstone, loads db etc
            _hearthstone = new Hearthstone();

            //create overlay
            _overlay = new OverlayWindow(_config, _hearthstone) { Topmost = true };
            _overlay.Show();

            _playerWindow = new PlayerWindow(_config, _hearthstone.PlayerDeck);
            _opponentWindow = new OpponentWindow(_config, _hearthstone.EnemyCards);

            LoadConfig();

            //find hs directory
            if (!File.Exists(_config.HearthstoneDirectory + @"\Hearthstone.exe"))
            {
                MessageBox.Show("Please specify your Hearthstone directory", "Hearthstone directory not found",
                                MessageBoxButton.OK);
                var dialog = new OpenFileDialog();
                dialog.Title = "Select Hearthstone.exe";
                dialog.DefaultExt = "Hearthstone.exe";
                dialog.Filter = "Hearthstone.exe|Hearthstone.exe";
                var result = dialog.ShowDialog();
                if (result != true)
                {
                    return;
                }
                _config.HearthstoneDirectory = Path.GetDirectoryName(dialog.FileName);
                _xmlManagerConfig.Save("config.xml", _config);
            }

            //log reader
            _logReader = new HsLogReader(_config.HearthstoneDirectory);
            _logReader.CardMovement += LogReaderOnCardMovement;
            _logReader.GameStateChange += LogReaderOnGameStateChange;

            UpdateDbListView();

            _options = new OptionsWindow(_config, _overlay, _xmlManagerConfig, _playerWindow, _opponentWindow);

            _updateThread = new Thread(Update);
            _updateThread.Start();

            _initialized = true;

            UpdateDeckList();
            UseSelectedDeck();

            _logReader.Start();
        }