public static string GetFilePath(this DatabaseJsonType jsonType) { switch (jsonType) { case DatabaseJsonType.Customs: return(Path.Combine("data", "customs.json")); case DatabaseJsonType.Dlcs: return(Path.Combine("data", "dlcs.json")); case DatabaseJsonType.Dlcs3DS: return(Path.Combine("data", "dlcs3ds.json")); case DatabaseJsonType.Games: return(Path.Combine("data", "games.json")); case DatabaseJsonType.Games3DS: return(Path.Combine("data", "games3ds.json")); case DatabaseJsonType.GamesWii: return(Path.Combine("data", "gamesWii.json")); case DatabaseJsonType.Injections: return(Path.Combine("data", "injections.json")); case DatabaseJsonType.Updates: return(Path.Combine("data", "updates.json")); case DatabaseJsonType.Updates3DS: return(Path.Combine("data", "updates3ds.json")); default: return(null); } }
public void AddTitles(ICollection <EshopTitle> gameTitles, DatabaseJsonType jsonType = DatabaseJsonType.None, bool overwrite = true) { foreach (EshopTitle title in gameTitles) { AddTitle(title, jsonType, overwrite); } }
public void AddTitle(EshopTitle title, DatabaseJsonType jsonType = DatabaseJsonType.None, bool overwrite = true) { if (jsonType != DatabaseJsonType.None) { // override so that titles read from disk stay in their respective files title.JsonType = jsonType; } else { // if passed type is None, try to determine it by titleID jsonType = title.JsonType; // if it's still None, we have nowhere to save the title if (jsonType == DatabaseJsonType.None) { return; } } if (overwrite) { titleSets[jsonType].Titles.Remove(title); } titleSets[jsonType].Titles.Add(title); titleSets[jsonType].Modified = true; }
// == I/O == public void ReadDatabaseFile(DatabaseJsonType jsonType) { if (jsonType != DatabaseJsonType.None) { AddTitles(DatabaseJsonIO.ReadTitlesFromJsonFile(jsonType.GetFilePath()), jsonType); titleSets[jsonType].Modified = false; } }
public void WriteDatabaseFile(DatabaseJsonType jsonType) { if (jsonType != DatabaseJsonType.None) { TitleSet titleSet = GetTitleSet(jsonType); if (titleSet.Modified) { DatabaseJsonIO.WriteTitlesToJsonFile(titleSet.Titles, jsonType); } } }
public static void WriteTitlesToJsonFile(ICollection <EshopTitle> titles, DatabaseJsonType jsonType) { List <EshopTitle> titleList = titles.ToList(); titleList.Sort(); JArray json = new JArray(titleList.Select(t => JObject.FromObject(t)).ToArray()); string filePath = jsonType.GetFilePath(); DialogResult shouldCreateBackup = MessageBox.Show(String.Format("Do you want to create a backup of {0} ?", filePath), "Question", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (shouldCreateBackup == DialogResult.Cancel) { return; } else if (shouldCreateBackup == DialogResult.Yes) { string backupFilePath = jsonType.GetBackupFilePath(); if (File.Exists(backupFilePath)) { if (MessageBox.Show("The backup file already exists.\nDo you want to overwrite it?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { File.Delete(backupFilePath); } else { return; } } File.Move(filePath, backupFilePath); } string jsonString = JsonArrayToString(json); File.WriteAllText(filePath, jsonString); Console.WriteLine("Wrote {0,5} titles to database file {1}", titleList.Count, filePath); }
public static string GetBackupFilePath(this DatabaseJsonType jsonType) { return(jsonType.GetFilePath() + ".bak"); }
// == Database == public TitleSet GetTitleSet(DatabaseJsonType jsonType) { return(titleSets[jsonType]); }