private async void CheckboxConfigSaveAppData_Unchecked(object sender, RoutedEventArgs e)
        {
            if (!_initialized)
            {
                return;
            }
            var path = Config.Instance.ConfigPath;

            Config.Instance.SaveConfigInAppData = false;
            XmlManager <Config> .Save(path, Config.Instance);

            await Helper.MainWindow.Restart();
        }
        private void BtnDeleteDeck_Click(object sender, RoutedEventArgs e)
        {
            var deck = new Deck();

            deck.Cards = new List <Card>();
            if (ComboBoxDecks.SelectedItem.ToString() == "Create New")
            {
                deck.Name = TextBoxDeckName.Text;
                ComboBoxDecks.Items.Add(deck.Name);
                _cardsInDeck          = 0;
                ButtonUseDeck.Content = "Use Deck (" + (_cardsInDeck) + ")";
            }
            else
            {
                deck.Name = ComboBoxDecks.SelectedItem.ToString();
            }


            if (
                MessageBox.Show("Are you Sure?", "Delete " + deck.Name, MessageBoxButton.YesNo, MessageBoxImage.Asterisk) ==
                MessageBoxResult.Yes)
            {
                try
                {
                    _deckList.DecksList.Remove(
                        _deckList.DecksList.First(x => ComboBoxDecks.SelectedItem.ToString().Equals(x.Name)));
                    _xmlManager.Save("PlayerDecks.xml", _deckList);
                    ComboBoxDecks.SelectedIndex = 0;
                    ComboBoxDecks.Items.Remove(deck.Name);
                    _cardsInDeck          = 0;
                    ButtonUseDeck.Content = "Use Deck (" + (_cardsInDeck) + ")";
                }
                catch (Exception)
                {
                    Console.WriteLine("Error deleting deck");
                }
            }
        }
Пример #3
0
        private async void BtnSaveToFile_OnClick(object sender, RoutedEventArgs e)
        {
            var deck = DeckList.Instance.ActiveDeckVersion;

            if (deck == null)
            {
                return;
            }
            var path = Helper.GetValidFilePath("SavedDecks", deck.Name, ".xml");

            XmlManager <Deck> .Save(path, deck);
            await ShowSavedFileMessage(path, "SavedDecks");

            Logger.WriteLine("Saved " + deck.GetDeckInfo() + " to file: " + path, "Export");
        }
Пример #4
0
        private async void BtnSaveToFile_OnClick(object sender, RoutedEventArgs e)
        {
            var deck = Helper.MainWindow.DeckPickerList.SelectedDeck;

            if (deck == null)
            {
                return;
            }
            var path = Helper.GetValidFilePath("SavedDecks", deck.Name, ".xml");

            XmlManager <Deck> .Save(path, deck);

            await Helper.MainWindow.ShowSavedFileMessage(path, "SavedDecks");


            After_Click();
        }
        private async void BtnSaveToFile_OnClick(object sender, RoutedEventArgs e)
        {
            var deck = DeckList.Instance.ActiveDeckVersion;

            if (deck == null)
            {
                return;
            }

            var fileName = Helper.ShowSaveFileDialog(Helper.RemoveInvalidFileNameChars(deck.Name), "xml");

            if (fileName != null)
            {
                XmlManager <Deck> .Save(fileName, deck);

                await this.ShowSavedFileMessage(fileName);

                Logger.WriteLine("Saved " + deck.GetDeckInfo() + " to file: " + fileName, "Export");
            }
        }
 public static void Save()
 {
     XmlManager <Config> .Save(Instance.ConfigPath, Instance);
 }
Пример #7
0
 private static void Save(DeckList instance) => XmlManager <DeckList> .Save(Config.Instance.DataDir + "PlayerDecks.xml", instance);
 public void WriteDecks()
 {
     XmlManager <Decks> .Save(_decksPath, DeckList);
 }
Пример #9
0
        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();
        }
Пример #10
0
 public static void Save() => XmlManager <DeckList> .Save(Config.Instance.DataDir + "PlayerDecks.xml", Instance);
        public static void Save()
        {
            var file = Config.Instance.DataDir + "PlayerDecks.xml";

            XmlManager <DeckList> .Save(file, Instance);
        }
 private void SaveConfigUpdateOverlay()
 {
     _xmlManagerConfig.Save("config.xml", _config);
     _overlay.Dispatcher.BeginInvoke(new Action(_overlay.Update));
 }
        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();
        }