Ejemplo n.º 1
0
        private async void addCheatButton_Click(object sender, RoutedEventArgs e)
        {
            List <String> cleanedCodes = new List <string>();

            if (this.descriptionBox.Text.Trim() == string.Empty)
            {
                await this.messageService.ShowMessage(this.resources.GetString("cheatsEmptyDescriptionMessage"), this.resources.GetString("errorCaption"));

                return;
            }
            String codes = this.codeBox.Text.Trim();

            if (codes == string.Empty)
            {
                await this.messageService.ShowMessage(this.resources.GetString("cheatsEmptyCodeMessage"), this.resources.GetString("errorCaption"));

                return;
            }
            if (!this.validator.CheckCode(codes, cleanedCodes))
            {
                await this.messageService.ShowMessage(this.resources.GetString("cheatsInvalidCodeMessage"), this.resources.GetString("errorCaption"));

                return;
            }

            foreach (var code in cleanedCodes)
            {
                Utility.CheatData cheat = new Utility.CheatData()
                {
                    CheatCode   = code.Trim(),
                    Description = this.descriptionBox.Text,
                    Enabled     = true
                };
                this.cheatData.Add(new CheatDataWrapper()
                {
                    Data     = cheat,
                    Selected = false
                });
            }

            this.descriptionBox.Text = string.Empty;
            this.codeBox.Text        = string.Empty;
        }
Ejemplo n.º 2
0
        public IAsyncOperation <IList <CheatData> > LoadCheatDataAsync()
        {
            Func <Task <IList <CheatData> > > asyncHelper = async() =>
            {
                IList <CheatData> results = null;
                if (this.currentROM == null)
                {
                    return(new List <CheatData>());
                }

                if (this.currentROM.CheatCache != null)
                {
                    return(this.currentROM.CheatCache);
                }
                else
                {
                    results = new List <CheatData>();
                    this.currentROM.CheatCache = results;
                }

                IStorageFile file = await this.GetFileUsingExtension(CHEAT_FILE_EXTENSION);

                if (file == null)
                {
                    return(results);
                }

                String data = await this.ReadFileToStringAsync(file);

                String[]  lines = data.Split('\n');
                int       i     = 0;
                CheatData cheat = null;
                foreach (var line in lines)
                {
                    if (line.Trim() == string.Empty)
                    {
                        continue;
                    }
                    if (i % 3 == 0)
                    {
                        cheat             = new CheatData();
                        cheat.Description = line;
                    }
                    else if (i % 3 == 1)
                    {
                        cheat.CheatCode = line;
                    }
                    else if (i % 3 == 2)
                    {
                        int enable = 1;
                        int.TryParse(line, out enable);
                        cheat.Enabled = (enable == 1);

                        results.Add(cheat);
                    }
                    i++;
                }

                return(results);
            };
            Func <Task <IList <CheatData> > > exceptionHelper = async() =>
            {
                try
                {
                    return(await asyncHelper());
                }catch (IOException)
                {
                    return(null);
                }
            };

            return(exceptionHelper().AsAsyncOperation());
        }