private void ConfigurePackBtn_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.Title = "Choose .ydk (YGOPRO Deck) File to convert!"; ofd.ShowDialog(); SaveFileDialog sfd = new SaveFileDialog(); sfd.RestoreDirectory = true; sfd.InitialDirectory = ygopro_db_path; sfd.Title = "Save your resulting pack file!"; sfd.ShowDialog(); List <String> lines = new List <string>(); lines.AddRange(File.ReadAllLines(ofd.FileName)); List <YGOJSONStruct> output_json = new List <YGOJSONStruct>(); String rarity = "Common"; foreach (String line in lines) { String card = line.TrimEnd(new char[] { '\n', '\r', '\t', ' ' }); YGOPROCard card_obj = null; if (line.Contains("!side")) { rarity = "Rare"; continue; } else if (line.Contains("#")) { continue; } else { int id = Int32.Parse(card); card_obj = getFromIDAndSetRarity(rarity, id); } YGOJSONStruct output_json_struct = new YGOJSONStruct(); output_json_struct.name = card_obj.m_card_name; output_json_struct.rarity = card_obj.m_rarity; output_json_struct.set_number = "Created-From-YDK-To-JSON"; output_json.Add(output_json_struct); } String json = JsonConvert.SerializeObject(output_json, Formatting.Indented); File.WriteAllText(sfd.FileName, json); }
List <String> extractRarityList(List <YGOJSONStruct> json_list, String rarity) { List <String> list = new List <String>(); foreach (YGOJSONStruct ygo in json_list) { YGOJSONStruct ygo_var = ygo; if (ygo_var.rarity.Contains("\n")) { ygo_var.rarity = ygo_var.rarity.Split('\n')[0]; } if (ygo_var.rarity.ToLower().Equals(rarity)) { list.Add(ygo.name); } } return(list); }
public static List <YGOPROCard> query_ygopro_ids(List <YGOJSONStruct> json_list, String ygopro_path) { List <YGOPROCard> cards = new List <YGOPROCard>(); List <int> ids = new List <int>(); try { using (SQLiteConnection connect = new SQLiteConnection("Data Source=" + ygopro_path)) { connect.Open(); foreach (YGOJSONStruct json_struct in json_list) { String new_name = json_struct.name.Replace("'", "''"); using (SQLiteCommand fmd = connect.CreateCommand()) { fmd.CommandText = "SELECT id from texts where name is '" + new_name + "'"; fmd.CommandType = CommandType.Text; SQLiteDataReader r = fmd.ExecuteReader(); try { if (r.Read()) { int a = r.GetInt32(0); ids.Add(a); } else { fmd.CommandText = "SELECT id from texts where name like '%" + new_name + "%'"; fmd.CommandType = CommandType.Text; r = fmd.ExecuteReader(); if (r.Read()) { int a = r.GetInt32(0); //ids.Add(a); ids.Add(a); } } } catch { } } } } } catch { } for (int idx = 0; idx < ids.Count; idx++) { int id = ids[idx]; YGOPROCard card = QueryFromID(id, ygopro_path); YGOJSONStruct json_struct = json_list[idx]; card.m_rarity = json_struct.rarity; cards.Add(card); } return(cards); }