private void jsonToData(string json) { JsonObject state = JsonObject.Parse(json); foreach (var c in state["Categories"].GetArray()) { JsonObject cObj = c.GetObject(); CategoryType category = new CategoryType(cObj["Title"].GetString().Replace(" ", "-"), cObj["Title"].GetString(), "Assets/DarkGray.png", cObj["Description"].GetString(), cObj["Folder"].GetString() ); //DataSource.AddGroup(category); this.AllGroups.Add(category); foreach (var s in cObj["Subcategories"].GetArray()) { JsonObject sObj = s.GetObject(); SubcategoryType subcategory = new SubcategoryType(sObj["Title"].GetString().Replace(" ", "-"), sObj["Title"].GetString(), "Assets/DarkGray.png", sObj["Description"].GetString(), sObj["Folder"].GetString() ); category.Subcategories.Add(subcategory); } foreach (var g in cObj["Games"].GetArray()) { JsonObject gObj = g.GetObject(); ObservableCollection<string> executables = new ObservableCollection<string>(); foreach (var exe in gObj["Executables"].GetArray()) { executables.Add(exe.GetString()); } ObservableCollection<string> textfiles = new ObservableCollection<string>(); foreach (var txt in gObj["Textfiles"].GetArray()) { textfiles.Add(txt.Stringify()); } GameType game = new GameType(gObj["Title"].GetString().Replace(" ", "-"), gObj["Title"].GetString(), "Assets/DarkGray.png", gObj["Description"].GetString(), executables, textfiles, category, category.Subcategories.FirstOrDefault(subcat => gObj["Subcategory"].GetString() == subcat.Title) ); category.Items.Add(game); } } }
private async void makeGame(StorageFolder gf, CategoryType category, SubcategoryType subcategory) { IReadOnlyList<StorageFile> gameFiles = await gf.GetFilesAsync(); ObservableCollection<string> executables, textfiles; try { executables = (ObservableCollection<string>)(from f in gameFiles where f.Name.EndsWith(".exe") select f.Path); } catch (InvalidOperationException e) { executables = null; } try { textfiles = (ObservableCollection<string>)(from f in gameFiles where f.Name.EndsWith(".txt") select f.Path); } catch (InvalidOperationException e) { textfiles = null; } var g = new GameType(gf.Name.Replace(" ", "-"), gf.Name, "Assets/LightGray.png", "A game", executables, textfiles, category, subcategory ); category.Items.Add(g); }