示例#1
0
        public MainWindow()
        {
            InitializeComponent();

            // Initialize the program on startup, setting all the info to its values.
            WrapPanel  = wrapMahepanel;
            StackPanel = StackMahePanel;

            // Loads the game stored on disk
            GameAdder gA = new GameAdder();

            gA.SearchForSavedGames();

            // Loads the hours into its positions
            SetHours();

            // Loads the user preferences
            List <Cuenta> defaultUser = new List <Cuenta>();
            string        folder      = System.IO.Path.GetDirectoryName(@"Data\userConfig\");
            string        extension   = "*.txt";

            string[] filesCache = Directory.GetFiles(folder, extension);
            bool     hasFile    = false;

            foreach (var file in filesCache)
            {
                if (file.Equals(@"Data\userConfig\preferences.txt"))
                {
                    hasFile = true;
                    break;
                }
            }
            // If user doesn't have preferences, creates ones.
            if (!hasFile)
            {
                Cuenta preferences = new Cuenta()
                {
                    preferencia = new Preferencia()
                    {
                        minimizarAlCerrar = 0, actualizacionesAutomaticas = 0, inicioAutomatico = 0
                    }
                };

                File.WriteAllText(@"Data\userConfig\preferences.txt", JsonConvert.SerializeObject(preferences));
            }

            //Draws the icon of the notification Windows menu.
            ni.Icon         = new System.Drawing.Icon(System.IO.Path.Combine(System.Windows.Forms.Application.StartupPath + @"\Data\", "Gamecher.ico"));
            ni.Visible      = true;
            ni.DoubleClick +=
                delegate(object sender, EventArgs args)
            {
                this.Show();
                this.WindowState = System.Windows.WindowState.Normal;
            };
            ni.ContextMenu = new System.Windows.Forms.ContextMenu();

            ni.ContextMenu.MenuItems.Add("Exit", (s, e) => { ni.Visible = false; Application.Current.Shutdown(); });
        }
示例#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();
                });
            });
        }