예제 #1
0
        // Loads the hours into its positions
        // Basically goes through all the games that are
        // installed and adds the hours, then sets them.
        public void SetHours()
        {
            double?horas = 0;
            Task   t     = Task.Factory.StartNew(() =>
            {
                string folder       = System.IO.Path.GetDirectoryName(@"Data\GamesRegister\");
                string filter       = "*.txt";
                string[] filesCache = Directory.GetFiles(folder, filter);
                foreach (var file in filesCache)
                {
                    if (!file.Equals(@"Data\GamesRegister\ReadMe.txt"))
                    {
                        string[] linesRegistro = File.ReadAllLines(file);
                        string jsonCache       = "";
                        foreach (string line in linesRegistro)
                        {
                            jsonCache += line;
                        }

                        RegistoJuego registro = JsonConvert.DeserializeObject <RegistoJuego>(jsonCache);

                        horas += registro.horasJugadas;
                    }
                }
            }).ContinueWith(tsk =>
            {
                Application.Current.Dispatcher.Invoke((Action) delegate
                {
                    totalHours.Text = horas.ToString();
                });
            });
        }
예제 #2
0
        public void SetManuallyAddedGame(string image, string gamePath)
        {
            string nombre = TextBoxNameOfManualGame.Text;
            Task   t      = Task.Factory.StartNew(() =>
            {
                if (nombre != null || !nombre.Equals(""))
                {
                    Configuracion config = new Configuracion()
                    {
                        pathExe = gamePath,
                        juego   = new Juego()
                        {
                            imageUrl = image,
                            nombre   = nombre
                        }
                    };
                    File.WriteAllText(@"Data\SavedGames\" + nombre + ".txt", JsonConvert.SerializeObject(config));

                    RegistoJuego register = new RegistoJuego()
                    {
                        cuenta = new Cuenta(),
                        juego  = new Juego()
                        {
                            imageUrl = image,
                            nombre   = nombre
                        }
                    };
                    File.WriteAllText(@"Data\GamesRegister\" + nombre + ".txt", JsonConvert.SerializeObject(register));
                }
            }).ContinueWith(tsk =>
            {
                Application.Current.Dispatcher.Invoke((Action) delegate
                {
                    GameAdder gA = new GameAdder();
                    gA.SearchForSavedGames();
                });
            });
        }