public static bool LoadCDB(string dir, bool overwrite, bool clearData = false) { if (!File.Exists(dir)) { return(false); } if (clearData) { CardData.Clear(); loadedCDB.Clear(); } SQLiteConnection connection = new SQLiteConnection("Data Source=" + dir); List <string[]> datas = new List <string[]>(); List <string[]> texts = new List <string[]>(); try { connection.Open(); datas = SQLiteCommands.LoadData(connection); texts = SQLiteCommands.LoadText(connection); connection.Close(); } catch (Exception) { connection.Close(); return(false); } int cdbsource = loadedCDB.Count + 1; loadedCDB.Add(cdbsource, new CDBData(clearData ? "Master": Path.GetFileNameWithoutExtension(dir), dir)); foreach (string[] row in datas) { if (overwrite) { CardManager.UpdateOrAddCard(new CardInfos(row, cdbsource)); } else { if (!CardManager.ContainsCard(Int32.Parse(row[0]))) { CardManager.UpdateOrAddCard(new CardInfos(row, cdbsource)); } } } foreach (string[] row in texts) { if (CardManager.ContainsCard(Int32.Parse(row[0]))) { CardManager.GetCard(Int32.Parse(row[0])).SetCardText(row); } } return(true); }
private void DeleteBtn_Click(object sender, EventArgs e) { int cardid; Int32.TryParse(CardID.Text, out cardid); if (cardid == 0) { MessageBox.Show("Invalid card id.", "Error", MessageBoxButtons.OK); return; } if (!CardManager.ContainsCard(cardid)) { MessageBox.Show("Unable to find card to delete.", "Error", MessageBoxButtons.OK); return; } string dir = CardManager.GetDatabaseDir(CardManager.GetCard(cardid).source); var connection = new SQLiteConnection("Data Source=" + dir); connection.Open(); if (SQLiteCommands.ContainsCard(cardid, connection)) { if (MessageBox.Show("Are you sure you want to delete " + CardManager.GetCard(cardid).Name + "?", "Found", MessageBoxButtons.YesNo) == DialogResult.No) { return; } } SQLiteCommands.DeleteCard(cardid, connection); CardManager.RemoveCard(cardid); Clearbtn_Click(null, EventArgs.Empty); }
private void ConvertButton_Click(object sender, EventArgs e) { bool updateCdb = cdbchk.Checked; bool updateScript = patchchk.Checked; bool updateImage = imagechk.Checked; List <string[]> updateCards = UpdateCardsList.Items.OfType <string[]>().ToList(); if (patchchk.Checked) { if (!Directory.Exists("DevPatch")) { Directory.CreateDirectory("DevPatch"); } if (!Directory.Exists("DevPatch\\script")) { Directory.CreateDirectory("DevPatch\\script"); } if (!Directory.Exists("DevPatch\\pics")) { Directory.CreateDirectory("DevPatch\\pics"); } if (!Directory.Exists("DevPatch\\pics\\thumbnail")) { Directory.CreateDirectory("DevPatch\\pics\\thumbnail"); } } foreach (var updateCard in updateCards) { if (updateCdb) { string str = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? ""; string str2 = Path.Combine(str, "cards.cdb"); if (!File.Exists(str2)) { MessageBox.Show("cards.cdb not found."); return; } var connection = new SQLiteConnection("Data Source=" + str2); connection.Open(); SQLiteCommands.UpdateCardId(updateCard[0], updateCard[1], connection); connection.Close(); if (patchchk.Checked) { File.Copy(str2, "DevPatch\\cards.cdb", true); } } if (updateImage) { string mainDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? ""; const string picFolderName = "pics"; const string tumbnailFolderName = "pics\\thumbnail"; string picName = updateCard[0] + ".jpg"; string newPicName = updateCard[1] + ".jpg"; string imagePath = Path.Combine(mainDir, picFolderName, picName); string newImagePath = Path.Combine(mainDir, picFolderName, newPicName); string thumbnailImagePath = Path.Combine(mainDir, tumbnailFolderName, picName); string newthumbnailImagePath = Path.Combine(mainDir, tumbnailFolderName, newPicName); if (File.Exists(imagePath) && !File.Exists(newImagePath)) { File.Move(imagePath, newImagePath); } if (File.Exists(thumbnailImagePath) && !File.Exists(newthumbnailImagePath)) { File.Move(thumbnailImagePath, newthumbnailImagePath); } if (patchchk.Checked) { if (File.Exists(newImagePath)) { File.Copy(newImagePath, Path.Combine("DevPatch\\pics", newPicName), true); } if (File.Exists(newthumbnailImagePath)) { File.Copy(newthumbnailImagePath, Path.Combine("DevPatch\\pics\\thumbnail", newPicName), true); } } } if (updateScript) { string mainDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? ""; const string scriptFolderName = "script"; string scriptName = "c" + updateCard[0] + ".lua"; string newScriptName = "c" + updateCard[1] + ".lua"; string scriptPath = Path.Combine(mainDir, scriptFolderName, scriptName); string newScriptPath = Path.Combine(mainDir, scriptFolderName, newScriptName); if (File.Exists(scriptPath)) { File.Move(scriptPath, newScriptPath); //needs testing id replacing string scriptFile = File.ReadAllText(newScriptPath); scriptFile = scriptFile.Replace(updateCard[0], updateCard[1]); File.WriteAllText(newScriptPath, scriptFile); if (patchchk.Checked) { if (File.Exists(newScriptPath)) { File.Copy(newScriptPath, Path.Combine("DevPatch\\script", newScriptName), true); } } } } Program.CardData.RenameKey(Convert.ToInt32(updateCard[0]), Convert.ToInt32(updateCard[1])); } UpdateCardsList.Items.Clear(); MessageBox.Show("Complete."); }
private bool SaveCardtoCDB(string cdbpath) { int cardid; int cardalias; int atk; int def; int ot = (CardFormats.SelectedItem == null ? 0 : GetCardFormat()); if (chkPre.Checked) { ot |= 0x4; } if (!Int32.TryParse(CardID.Text, out cardid)) { MessageBox.Show("Invalid card id"); return(false); } int updatecard = m_loadedCard == 0 ? cardid : m_loadedCard; if (!Int32.TryParse(Alias.Text, out cardalias)) { cardalias = 0; } if (!Int32.TryParse(ATK.Text, out atk)) { MessageBox.Show("Invalid atk value"); return(false); } if (!Int32.TryParse(DEF.Text, out def)) { MessageBox.Show("Invalid def value"); return(false); } if (CDBSelect.Items.Count == 0) { MessageBox.Show("No loaded database"); return(false); } CardInfos newCardInfo = new CardInfos(new[] { cardid.ToString(CultureInfo.InvariantCulture), (ot.ToString(CultureInfo.InvariantCulture)), cardalias.ToString(CultureInfo.InvariantCulture), GetSetCode().ToString(CultureInfo.InvariantCulture), GetTypeCode().ToString(CultureInfo.InvariantCulture), GetLevelCode().ToString(), (Race.SelectedItem == null ? "0" : (Race.SelectedItem == null ? "0" : m_cardRaces[Race.SelectedIndex].ToString(CultureInfo.InvariantCulture))), (CardAttribute.SelectedItem == null ? "0" : (CardAttribute.SelectedItem == null ? "0" : m_cardAttributes[CardAttribute.SelectedIndex].ToString(CultureInfo.InvariantCulture))), atk.ToString(CultureInfo.InvariantCulture), def.ToString(CultureInfo.InvariantCulture), GetCategoryNumber().ToString(CultureInfo.InvariantCulture) } , CDBSelect.SelectedIndex + 1); var cardtextarray = new List <string> { cardid.ToString(CultureInfo.InvariantCulture), CardName.Text, CardDescription.Text }; for (var i = 0; i < 17; i++) { cardtextarray.Add((i < EffectList.Items.Count ? EffectList.Items[i].ToString() : string.Empty)); } newCardInfo.SetCardText(cardtextarray.ToArray()); if (CardTypeList.CheckedItems.Contains("Link")) { newCardInfo.Def = GetLinkMarkers(); } //check source DB if (CardManager.ContainsCard(cardid)) { if (CardManager.GetCard(cardid).source != newCardInfo.source) { if (MessageBox.Show("Copy to new database?", "", MessageBoxButtons.YesNo) != DialogResult.Yes) { return(false); } } } //save/update card var connection = new SQLiteConnection("Data Source=" + CardManager.GetDatabaseDir(newCardInfo.source)); connection.Open(); //check if card id exsists bool overwrite = SQLiteCommands.ContainsCard(updatecard, connection); if (overwrite) { if (MessageBox.Show("Overwrite current card?", "Found", MessageBoxButtons.YesNo) == DialogResult.No) { connection.Close(); return(false); } } SQLiteCommands.SaveCard(newCardInfo, connection, updatecard, overwrite); connection.Close(); if (cardid != updatecard) { CardManager.RenameKey(updatecard, cardid); } CardManager.UpdateOrAddCard(newCardInfo); MessageBox.Show("Card Saved"); return(true); }
private void ConvertButton_Click(object sender, EventArgs e) { ConvertButton.Enabled = false; bool updateCdb = cdbchk.Checked; bool updateScript = patchchk.Checked; bool updateImage = imagechk.Checked; List <string[]> updateCards = UpdateCardsList.Items.OfType <string[]>().ToList(); if (patchchk.Checked) { if (!Directory.Exists("DevPatch")) { Directory.CreateDirectory("DevPatch"); } if (!Directory.Exists("DevPatch\\script")) { Directory.CreateDirectory("DevPatch\\script"); } if (!Directory.Exists("DevPatch\\pics")) { Directory.CreateDirectory("DevPatch\\pics"); } if (!Directory.Exists("DevPatch\\pics\\thumbnail")) { Directory.CreateDirectory("DevPatch\\pics\\thumbnail"); } } string str = "cards.cdb"; foreach (var updateCard in updateCards) { if (updateCdb) { if (!File.Exists(str)) { MessageBox.Show("cards.cdb not found."); return; } int cardid = Int32.Parse(updateCard[0]); int newid = Int32.Parse(updateCard[1]); CardManager.RenameKey(cardid, newid); CardInfos card = CardManager.GetCard(newid); card.Id = newid; if (chkremovepre.Checked) { card.Ot = card.Ot & 0x03; } CardManager.UpdateOrAddCard(card); var connection = new SQLiteConnection("Data Source=" + str); connection.Open(); SQLiteCommands.UpdateCardId(updateCard[0], updateCard[1], connection); if (chkremovepre.Checked) { SQLiteCommands.UpdateCardOt(updateCard[1], card.Ot.ToString(), connection); } connection.Close(); } if (updateImage) { string mainDir = Directory.GetCurrentDirectory();; const string picFolderName = "pics"; const string tumbnailFolderName = "pics\\thumbnail"; string picName = updateCard[0] + ".png"; string newPicName = updateCard[1] + ".png"; string imagePath = Path.Combine(mainDir, picFolderName, picName); string newImagePath = Path.Combine(mainDir, picFolderName, newPicName); string thumbnailImagePath = Path.Combine(mainDir, tumbnailFolderName, picName); string newthumbnailImagePath = Path.Combine(mainDir, tumbnailFolderName, newPicName); if (File.Exists(imagePath) && !File.Exists(newImagePath)) { File.Move(imagePath, newImagePath); } if (File.Exists(thumbnailImagePath) && !File.Exists(newthumbnailImagePath)) { File.Move(thumbnailImagePath, newthumbnailImagePath); } if (patchchk.Checked) { if (File.Exists(newImagePath)) { File.Copy(newImagePath, Path.Combine("DevPatch\\pics", newPicName), true); } if (File.Exists(newthumbnailImagePath)) { File.Copy(newthumbnailImagePath, Path.Combine("DevPatch\\pics\\thumbnail", newPicName), true); } } } if (updateScript) { string mainDir = Directory.GetCurrentDirectory();; const string scriptFolderName = "script"; string scriptName = "c" + updateCard[0] + ".lua"; string newScriptName = "c" + updateCard[1] + ".lua"; string scriptPath = Path.Combine(mainDir, scriptFolderName, scriptName); string newScriptPath = Path.Combine(mainDir, scriptFolderName, newScriptName); if (File.Exists(scriptPath)) { File.Move(scriptPath, newScriptPath); //needs testing id replacing string scriptFile = File.ReadAllText(newScriptPath); scriptFile = scriptFile.Replace(updateCard[0], updateCard[1]); File.WriteAllText(newScriptPath, scriptFile); if (patchchk.Checked) { if (File.Exists(newScriptPath)) { File.Copy(newScriptPath, Path.Combine("DevPatch\\script", newScriptName), true); } } } } } if (patchchk.Checked) { File.Copy(str, "DevPatch\\cards.cdb", true); } UpdateCardsList.Items.Clear(); MessageBox.Show("Complete."); ConvertButton.Enabled = true; }