private void LoadItemsWoker_DoWork(object sender, DoWorkEventArgs e) { //1st - Get from DB all data to fill the grid and save it on the list //Fetch this item data from DB ViewerTreeItemDescriptor selectedItem = Viewer.I.SelectedItem; _arrayDBValues = App.DB.GetAllDataOfAnItemFromMemory(selectedItem.PrimaryKeyValue, selectedItem.PrimaryKeyName, selectedItem.TableName); //Fill a list with the data so it can be shown on the DataGrid foreach (object columnValue in _arrayDBValues) { _dataGridItems.Add(new ViewerDataGridItem(DBTableAttributtesFetcher.GetColumnsNames(EDBTable.eItemTypes)[_dataGridItems.Count], columnValue)); } //2nd - Set the checked item mode Dispatcher.BeginInvoke(new Action(() => { switch (_itemMode) { case EItemMode.eEmpty: RadioButtonEmpty.IsChecked = true; break; case EItemMode.eFull: RadioButtonFull.IsChecked = true; break; } })); //3rd - Display the information on canvas CreateUpdateCanvas(); }
public static BitmapSource GetItemDisplayImage(string group_id, string subgroup_id, string table, bool big_gui) { //Ask for item imageList string[] columnsName = DBTableAttributtesFetcher.GetColumnsNames(EDBTable.eItemTypes); string strGroupIDColumn = columnsName[(int)EDBItemTypesTableColumns.eNGroupID]; string strSubgroupIDColumn = columnsName[(int)EDBItemTypesTableColumns.eNSubgroupID]; string strVImageListColumn = columnsName[(int)EDBItemTypesTableColumns.eVImageList]; string strVImageUsage = columnsName[(int)EDBItemTypesTableColumns.eVImageUsage]; List <object> listDBValues = App.DB.GetColumnsValuesFromMemoryTableMultipleAndConditions(new List <string> { strGroupIDColumn, strSubgroupIDColumn }, new List <string> { group_id, subgroup_id }, table, new List <string> { strVImageUsage, strVImageListColumn }); if (listDBValues != null && listDBValues.Count == 2) { //Finally fetch the display image int nImageDisplayIndex = Convert.ToInt32(listDBValues[0].ToString().Split(',')[(int)EImageUsage.eStored]); string strImageName = listDBValues[1].ToString().Split(',')[nImageDisplayIndex]; //translate to the correct DB string strImagesTableSufix = DBTableAttributtesFetcher.GetNameSufix(EDBTable.eImages); GetFinalItemAndTableFromEncapsulatedItemAndTableWithSufix(ref strImageName, ref table, strImagesTableSufix); return(Images.Images.GetImageToDraw(strImageName, table, big_gui, false)); } else { return(null); } }
public static DrawingImage GetGameMapImageWithDrawnImageAtPoint(bool big_gui, EDayTime day_time, bool is_highlighted, BitmapSource image_to_draw, Point?where_to_draw) { // Since this method is only used to fetch the game map we can have this hard-coded object [] arrayDBValues = App.DB.GetAllDataOfAnItemFromMemory("2", DBTableAttributtesFetcher.GetPrimaryKeyName(EDBTable.eMaps), "0_maps"); return(GetMapImageWithDrawnImageAtPoint(big_gui, arrayDBValues, day_time, is_highlighted, image_to_draw, where_to_draw)); }
public STreasureTable(string id, string table, string probability, string occurrence) { string strTreasureTableSufix = DBTableAttributtesFetcher.GetNameSufix(EDBTable.eTreasureTable); ItemTypes.ItemTypes.GetFinalItemAndTableFromEncapsulatedItemAndTableWithSufix(ref id, ref table, strTreasureTableSufix); string strTablePrefix = table.Split('_')[0]; DisplayInfo = string.Format("Table {0}:{1}x{2}x{3}", strTablePrefix, id, probability, occurrence); Elements = new List <List <object> >(); TableName = table; ID = id; }
private void LoadTreeItemsWoker_DoWork(object sender, DoWorkEventArgs e) { _treeItemsList = new List <ViewerTreeItemDescriptor>(); for (int nModIndex = 0; nModIndex < App.I.ModsPrefix.Count; nModIndex++) { for (int nTableIndex = 0; nTableIndex < (int)EDBTable.eTotal; nTableIndex++) { EDBTable eDBTable = (EDBTable)nTableIndex; string strTableNamePrefix = App.I.ModsPrefix[nModIndex]; string strTableNameSufix = DBTableAttributtesFetcher.GetNameSufix(eDBTable); string strTableName = string.Format("{0}_{1}", strTableNamePrefix, strTableNameSufix); List <string> strColumnsList = DBTableAttributtesFetcher.GetTreeViewDecriptiveColumnsNames(eDBTable); //Get items from mem DB List <object[]> listColumnsValuesTable = App.DB.GetAllTableDataOfSpecificColumnsFromMemory(strTableName, strColumnsList); if (listColumnsValuesTable.Count > 0) { //Now check if the collection already have the type int nByTypeTypeIndex = GetTier1NodeIndex(ByTypeTreeData, strTableNameSufix); //Now check if the Tier1 collection already have the mod int nByTypeModIndex = GetTier2NodeIndex(ByTypeTreeData[nByTypeTypeIndex].Tier2, strTableNamePrefix); //Now check if the collection already have the mod int nByModModIndex = GetTier1NodeIndex(ByModTreeData, strTableNamePrefix); //Now check if the Tier1 collection already have the type int nByModTypeIndex = GetTier2NodeIndex(ByModTreeData[nByModModIndex].Tier2, strTableNameSufix); //Now for each item we will create a new ViewerTreeItemDescriptor object and add it to the trees listColumnsValuesTable.ForEach(item => { int nByTypeItemIndex = ByTypeTreeData[nByTypeTypeIndex].Tier2[nByTypeModIndex].Items.Count; int nByModItemIndex = ByModTreeData[nByModModIndex].Tier2[nByModTypeIndex].Items.Count; int[] nTreeIndexByType = new int[3] { nByTypeTypeIndex, nByTypeModIndex, nByTypeItemIndex }; int[] nTreeIndexByMod = new int[3] { nByModModIndex, nByModTypeIndex, nByModItemIndex }; ViewerTreeItemDescriptor newItem = new ViewerTreeItemDescriptor(item, eDBTable, nModIndex, nTreeIndexByType, nTreeIndexByMod, strTableName); _treeItemsList.Add(newItem); ByTypeTreeData[nByTypeTypeIndex].Tier2[nByTypeModIndex].Items.Add(newItem); ByModTreeData[nByModModIndex].Tier2[nByModTypeIndex].Items.Add(newItem); }); } } } }
private void LoadItemsWoker_DoWork(object sender, DoWorkEventArgs e) { //1st - Get from DB all data to fill the grid and save it on the list //Fetch this item data from DB ViewerTreeItemDescriptor selectedItem = Viewer.I.SelectedItem; _arrayDBValues = App.DB.GetAllDataOfAnItemFromMemory(selectedItem.PrimaryKeyValue, selectedItem.PrimaryKeyName, selectedItem.TableName); //Fill a list with the data so it can be shown on the DataGrid foreach (object columnValue in _arrayDBValues) { _dataGridItems.Add(new ViewerDataGridItem(DBTableAttributtesFetcher.GetColumnsNames(EDBTable.eBarterHexes)[_dataGridItems.Count], columnValue)); } //3rd - Display the information on canvas CreateUpdateCanvas(); }
public static void Parse(STreasureTable treasures_table) { string strColumnSearchName = DBTableAttributtesFetcher.GetPrimaryKeyName(EDBTable.eTreasureTable); string strColumnRetriveName = DBTableAttributtesFetcher.GetColumnsNames(EDBTable.eTreasureTable)[(int)EDBTreasureTableColumns.eATreasures]; string strItemTypesTableSufix = DBTableAttributtesFetcher.GetNameSufix(EDBTable.eItemTypes); //Split the and entries first string strATreasures = App.DB.GetColumnValueFromMemoryTable(strColumnSearchName, treasures_table.ID, treasures_table.TableName, strColumnRetriveName); string [] strTableAndEntriesSplitted = strATreasures.Split(','); foreach (string strTableOrEntries in strTableAndEntriesSplitted) { List <object> treasureItems = new List <object>(); //Split the or entries second string[] strTableOrEntriesSplitted = strTableOrEntries.Split('|'); foreach (string strEntry in strTableOrEntriesSplitted) { string[] strEntrySplitted = strEntry.Split('x'); //Translate the entry to the respective table string strEntryID = strEntrySplitted[(int)STreasureTableElement.EDataIndex.eID]; string strEntryTable = treasures_table.TableName; ItemTypes.ItemTypes.GetFinalItemAndTableFromEncapsulatedItemAndTableWithSufix(ref strEntryID, ref strEntryTable, strItemTypesTableSufix); //Now we need to check if it is a table or an item string[] strEntryIDSplitted = strEntryID.Split('.'); //is an item in the format GroupID.SubgroupID if (strEntryIDSplitted.Length == 2) { STreasureTableElement item = new STreasureTableElement(strEntryIDSplitted, strEntrySplitted, strEntryTable); treasureItems.Add(item); } else if (string.IsNullOrEmpty(strEntryIDSplitted[0]) == false) { STreasureTable innerTresureTable = new STreasureTable(strEntryIDSplitted[0], strEntryTable, strEntrySplitted[(int)STreasureTableElement.EDataIndex.eProbability], strEntrySplitted[(int)STreasureTableElement.EDataIndex.eOccurrence]); // Recursive parse tables, hopefully modders didn't create loop references in the treasure tables because I am not protecting them for now Parse(innerTresureTable); treasureItems.Add(innerTresureTable); } } if (treasureItems.Count > 0) { treasures_table.Elements.Add(treasureItems); } } }
//Type 0 (ones with data folder) private void ParseType0(string str_folder, string str_mod_name, string str_mod_folder_name) { string strType0DataFolder = Path.Combine(str_folder, "data"); IEnumerable <string> enumFiles = Directory.EnumerateFiles(strType0DataFolder); foreach (string file in enumFiles) { string strFileName = Path.GetFileName(file); object oDBTable = DBTableAttributtesFetcher.Parse(Path.GetFileNameWithoutExtension(strFileName).ToLower()); if (oDBTable != null && (string.Compare(Path.GetExtension(strFileName), ".xml") == 0)) //only parse supported xml files { EDBTable eDBTable = (EDBTable)oDBTable; App._splashScreen.UpdateMessage("Parsing " + str_mod_folder_name + ": " + strFileName); //only parse the file if it was changed since last time byte[] fileHash = null; if (CheckSavedFileHash(file, out fileHash) == false) { //Let's do one transaction per file to speed things up SQLiteTransaction sqlTransaction = DbFsConnection.BeginTransaction(); //Create the table if it does not exist already string strTableName = str_mod_name + "_" + str_mod_folder_name + "_" + DBTableAttributtesFetcher.GetNameSufix(eDBTable); SQLiteCommand command = new SQLiteCommand(DBTableAttributtesFetcher.GetSqlCreation(eDBTable), DbFsConnection, sqlTransaction); command.CommandText = string.Format(command.CommandText, strTableName); command.ExecuteNonQuery(); //parse the xml file to DB ParseXMLFile(file, str_mod_name + "_" + str_mod_folder_name, sqlTransaction); //now save file hash to table SaveFileHash(file, fileHash, sqlTransaction); //finally commit the transaction sqlTransaction.Commit(); } } } //After parsing all the data files let's check if there are any getimages.php to parse string strImageFile = Path.Combine(str_folder, "getimages.php"); if (File.Exists(strImageFile)) { App._splashScreen.UpdateMessage("Parsing " + str_mod_folder_name + ": getimages.php"); ParseGetImagesFile(strImageFile, str_mod_name + "_" + str_mod_folder_name + "_" + "images", str_folder); } //If everything went well we will add to the mod list App.I.Mods.Add(str_mod_name + "_" + str_mod_folder_name); }
private void ParseType1(string str_folder, string str_mod_name, string str_mod_folder_name) { string strType1NeogameFile = Path.Combine(str_folder, "neogame.xml").ToLower(); App._splashScreen.UpdateMessage("Parsing " + str_mod_folder_name + ": neogame.xml"); //only parse the file if it was changed since last time byte[] fileHash = null; if (CheckSavedFileHash(strType1NeogameFile, out fileHash) == false) { //Let's do one transaction per file to speed things up SQLiteTransaction sqlTransaction = DbFsConnection.BeginTransaction(); //Create all tables for this mod SQLiteCommand command = new SQLiteCommand(DbFsConnection); command.Transaction = sqlTransaction; for (int nIndex = 0; nIndex < (int)EDBTable.eTotal; nIndex++) { EDBTable eDBTable = (EDBTable)nIndex; command.Reset(); string strTableName = str_mod_name + "_" + str_mod_folder_name + "_" + DBTableAttributtesFetcher.GetNameSufix(eDBTable); string strSqlCreation = DBTableAttributtesFetcher.GetSqlCreation(eDBTable); command.CommandText = string.Format(strSqlCreation, strTableName); command.ExecuteNonQuery(); } //parse the xml file to DB ParseXMLFile(strType1NeogameFile, str_mod_name + "_" + str_mod_folder_name, sqlTransaction); //now save file hash to table SaveFileHash(strType1NeogameFile, fileHash, sqlTransaction); //finally commit the transaction sqlTransaction.Commit(); } //After parsing all the data files let's check if there are any getimages.php to parse string strImageFile = Path.Combine(str_folder, "getimages.php"); if (File.Exists(strImageFile)) { App._splashScreen.UpdateMessage("Parsing " + str_mod_folder_name + ": getimages.php"); ParseGetImagesFile(strImageFile, str_mod_name + "_" + str_mod_folder_name + "_" + "images", str_folder); } //If everything went well we will add to the mod list App.I.Mods.Add(str_mod_name + "_" + str_mod_folder_name); }
private void LoadItemsWoker_DoWork(object sender, DoWorkEventArgs e) { //1st - Get from DB all data to fill the grid and save it on the list //Fetch this item data from DB ViewerTreeItemDescriptor selectedItem = Viewer.I.SelectedItem; _arrayDBValues = App.DB.GetAllDataOfAnItemFromMemory(selectedItem.PrimaryKeyValue, selectedItem.PrimaryKeyName, selectedItem.TableName); //Fill a list with the data so it can be shown on the DataGrid foreach (object columnValue in _arrayDBValues) { _dataGridItems.Add(new ViewerDataGridItem(DBTableAttributtesFetcher.GetColumnsNames(EDBTable.eImages)[_dataGridItems.Count], columnValue)); } //2nd - Display the information on canvas string strSmallImagePath = _arrayDBValues[(int)EDBImagesTableColumns.eSmall].ToString(); string strBigImagePath = _arrayDBValues[(int)EDBImagesTableColumns.eBig].ToString(); //Let's add the small image representation if it exists if (string.IsNullOrEmpty(strSmallImagePath) == false && System.IO.File.Exists(strSmallImagePath) == true) { //Create the small image panel in the GUI thread and add it to the grid on the correct place Dispatcher.BeginInvoke(new Action(() => { Panel panelSmallImage = CreateImagePanel("Small image representation:", strSmallImagePath); _gridCanvas.Children.Add(panelSmallImage); int nColumnIndex = _gridCanvas.ColumnDefinitions.Count; _gridCanvas.ColumnDefinitions.Add(new ColumnDefinition()); Grid.SetColumn(panelSmallImage, nColumnIndex); })); } if (string.IsNullOrEmpty(strBigImagePath) == false && System.IO.File.Exists(strBigImagePath) == true) { //Create the big image panel in the GUI thread and add it to the grid on the correct place Dispatcher.BeginInvoke(new Action(() => { Panel panelBigImage = CreateImagePanel("Big image representation:", strBigImagePath); _gridCanvas.Children.Add(panelBigImage); int nColumnIndex = _gridCanvas.ColumnDefinitions.Count; _gridCanvas.ColumnDefinitions.Add(new ColumnDefinition()); Grid.SetColumn(panelBigImage, nColumnIndex); })); } }
public ViewerTreeItemDescriptor(object [] columns_values, EDBTable type, int n_mod_index, int [] tree_index_type, int[] tree_index_mod, string table_name) { _primaryKeyValue = columns_values[0].ToString(); _primaryKeyName = DBTableAttributtesFetcher.GetPrimaryKeyName(type); switch (columns_values.Length) { case 1: _treeText = _primaryKeyValue; _description = string.Empty; break; case 2: // Most of them _description = columns_values[1].ToString(); _treeText = string.Format("{0}_{1}", _primaryKeyValue, _description); break; case 3: // BarterHexes _description = string.Format("({0}, {1})", columns_values[1], columns_values[2]); _treeText = string.Format("{0}_{1}", _primaryKeyValue, _description); break; case 4: // ForbiddenHexes _description = string.Format("({0}, {1})_{2}", columns_values[1], columns_values[2], columns_values[3]); _treeText = string.Format("{0}_{1}", _primaryKeyValue, _description); break; } _type = type; _modIndex = n_mod_index; _treeIndexByType = tree_index_type; _treeIndexByMod = tree_index_mod; _tableName = table_name; }
private void CreateInMemGameDatabase() { App._splashScreen.UpdateMessage("Finalizing in-game database"); #if DEBUG //For debug porpose only var dbFilename = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "NeoScavHelperTool", "mem.sqlite"); _dbMemConnection = new SQLiteConnection(connectionString: "Data Source=" + dbFilename + ";Version=3;Compress=True;UTF8Encoding=True;"); #else _dbMemConnection = new SQLiteConnection(connectionString: "Data Source=:memory:;Version=3;Compress=True;UTF8Encoding=True;"); #endif DbMemConnection.Open(); ////let's fill the TreeViewViewerTypes with the types //DBTableAttributtesFetcher.GetAllNameSufix().ForEach(type => //{ // TreeViewItem treeItem = new TreeViewItem(); // treeItem.Header = type; // MainWindow.ListTypeTreeItems.Add(treeItem); //}); ////let's fill the TreeViewViewerMods with the mods where 0 will only be represented as 0_vanilla //App.I.Mods.Select(mod => mod.Split('_')[0]).Distinct().ToList().ForEach(modPrefix => //{ // TreeViewItem treeItem = new TreeViewItem(); // treeItem.Header = modPrefix; // MainWindow.ListModsTreeItems.Add(treeItem); //}); //Now we will fetch by mod order data to fill the DB overwriting the previous mod data SQLiteCommand fsCommand = new SQLiteCommand(DbFsConnection); foreach (string mod in App.I.Mods) { fsCommand.Reset(); fsCommand.CommandText = _sqlCommandSelectTablesWithNameLike; fsCommand.Parameters.Add(new SQLiteParameter("@name", mod + "%")); //First get existent tables in file system database for this mod List <string> listTables = new List <string>(); using (SQLiteDataReader reader = fsCommand.ExecuteReader()) { while (reader.Read()) { listTables.Add(reader.GetString(0)); } } //now fetch all values from the file system table and insert them on the memory table foreach (string tableName in listTables) { SQLiteTransaction dataTableTransaction = DbMemConnection.BeginTransaction(); //transaction per table SQLiteCommand command = new SQLiteCommand(DbMemConnection); command.Transaction = dataTableTransaction; //First fetch table column names fsCommand.Reset(); fsCommand.CommandText = string.Format(_sqlCommandPragmaTableInfo, tableName); List <string> listColumnNames = new List <string>(); using (SQLiteDataReader reader = fsCommand.ExecuteReader()) { while (reader.Read()) { listColumnNames.Add(reader.GetString(1)); } } //Now fetch their values while insert them into the mem DB fsCommand.Reset(); fsCommand.CommandText = string.Format(_sqlCommandSelectAllTableData, tableName); using (SQLiteDataReader reader = fsCommand.ExecuteReader()) { if (reader.HasRows) //continue only if there are values on this table { string[] splittedTableName = tableName.Split('_'); string strTableNameSufix = splittedTableName[splittedTableName.Length - 1]; string[] splittedModName = mod.Split('_'); string strMemTableName = splittedModName[0] + '_' + strTableNameSufix; //create this mod table if needed command.CommandText = string.Format(DBTableAttributtesFetcher.GetSqlCreation(strTableNameSufix), strMemTableName); command.ExecuteNonQuery(); while (reader.Read()) { object[] arrayColumnValues = new object[listColumnNames.Count]; reader.GetValues(arrayColumnValues); List <object> listColumnValues = arrayColumnValues.ToList(); command.Reset(); command.CommandText = string.Format(_sqlCommandInsertOrReplaceIntoAnyTable, strMemTableName, //parameter {0} table name $"`{string.Join("`,`", listColumnNames)}`" //parameter {1} columns ); command.AddArrayParameters("values", listColumnValues); command.ExecuteNonQuery(); } } } dataTableTransaction.Commit(); } } }
private void ParseGetImagesFile(string file, string table_name, string str_folder) { //only parse the file if it was changed since last time byte[] fileHash = null; if (CheckSavedFileHash(file, out fileHash) == false) { string strFileContent = File.ReadAllText(file); string[] splittedFileContent = strFileContent.Split(new char[] { '&' }, StringSplitOptions.RemoveEmptyEntries); Dictionary <string, string[]> dicImages = new Dictionary <string, string[]>(); //Ignore the first two since they will correspond to "nRows=2326" and "nCols=2" for (int index = 2; index < splittedFileContent.Length; index++) { //Access only to the name of the image string strImageName = splittedFileContent[index].Split('=')[1].TrimEnd(new char[] { '\r', '\n' }); string strImageBaseName = Path.GetFileNameWithoutExtension(strImageName); int iSmallBigIndex = 0; //0 = small, 1 = big if (strImageBaseName.StartsWith("x2")) { iSmallBigIndex = 1; strImageBaseName = strImageBaseName.Substring(3); //remove the x2_ } if (dicImages.ContainsKey(strImageBaseName) == false) { dicImages.Add(strImageBaseName, new string[2] { "", "" }); } dicImages[strImageBaseName][iSmallBigIndex] = strImageName; } //Let's do one transaction per file to speed things up SQLiteTransaction sqlTransaction = DbFsConnection.BeginTransaction(); //Create the table if it does not exist already SQLiteCommand command = new SQLiteCommand(DBTableAttributtesFetcher.GetSqlCreation(EDBTable.eImages), DbFsConnection, sqlTransaction); command.CommandText = string.Format(command.CommandText, table_name); command.ExecuteNonQuery(); string strImageFolderPath = Path.Combine(str_folder, "img"); //since this will be equal for all images we do it outside of for loop to improve performance foreach (KeyValuePair <string, string[]> image in dicImages) { command.Reset(); command.CommandText = string.Format(_sqlCommandInsertOrReplaceIntoAnyTable, table_name, //parameter {0} table name $"`{string.Join("`,`", new List<string> { "name", "small", "big" })}`" //parameter {1} columns ); //Check if any of the strings are empty, and if they are don't prepend the path string strSmallImagePath = string.IsNullOrEmpty(image.Value[0]) ? string.Empty : Path.Combine(strImageFolderPath, image.Value[0]); string strBigImagePath = string.IsNullOrEmpty(image.Value[1]) ? string.Empty : Path.Combine(strImageFolderPath, image.Value[1]); command.AddArrayParameters("values", new List <string> { image.Key, strSmallImagePath, strBigImagePath }); command.ExecuteNonQuery(); } //now save file hash to table SaveFileHash(file, fileHash, sqlTransaction); //finally commit the transaction sqlTransaction.Commit(); } }