MCPcopy Create free account
hub / github.com/Shazbot/WH3-Mod-Manager / buildDBReferenceTree

Function buildDBReferenceTree

src/DBClone.ts:90–819  ·  view source on GitHub ↗
(
  packPath: string,
  currentDBTableSelection: DBTableSelection,
  deepCloneTarget: { row: number; col: number },
  existingRefs: DBCell[],
  selectedNodesByName: IViewerTreeNodeWithData[],
  existingTree?: IViewerTreeNodeWithData
)

Source from the content-addressed store, hash-verified

88};
89
90export const buildDBReferenceTree = async (
91 packPath: string,
92 currentDBTableSelection: DBTableSelection,
93 deepCloneTarget: { row: number; col: number },
94 existingRefs: DBCell[],
95 selectedNodesByName: IViewerTreeNodeWithData[],
96 existingTree?: IViewerTreeNodeWithData
97): Promise<IViewerTreeNodeWithData | undefined> => {
98 console.log("ENTER buildDBReferenceTree");
99 console.log("args:", packPath, currentDBTableSelection, deepCloneTarget, selectedNodesByName);
100 const DBNameToDBVersions = gameToDBNameToDBVersions[appData.currentGame];
101 const DBFieldsReferencedBy = gameToDBFieldsReferencedBy[appData.currentGame];
102 const tableToreferencedColumns = gameToReferences[appData.currentGame];
103 const packedFilePath = getDBPackedFilePath(currentDBTableSelection);
104
105 const gameFolderPaths = appData.gamesToGameFolderPaths[appData.currentGame];
106 if (!gameFolderPaths || !gameFolderPaths.dataFolder) return;
107
108 const nodePath = await import("path");
109 const dataPackPath = nodePath.join(
110 gameFolderPaths.dataFolder,
111 gameToPackWithDBTablesName[appData.currentGame]
112 );
113
114 const isCurrentPackDataPack = nodePath.relative(packPath, dataPackPath) == "";
115
116 const isStartingSearchIndirect = selectedNodesByName.length > 0;
117
118 console.log("isStartingSearchIndirect:", isStartingSearchIndirect);
119 console.log("isCurrentPackDataPack:", isCurrentPackDataPack);
120
121 const packsWithReadLocsByPackPath = [] as string[];
122
123 let existingPack = appData.packsData.find((pack) => pack.path == packPath);
124 if (!existingPack) {
125 await readModsByPath([packPath], { skipParsingTables: true }, true);
126
127 existingPack = appData.packsData.find((pack) => pack.path == packPath);
128 if (!existingPack) {
129 console.log("buildDBReferenceTree: no existingPack");
130 return;
131 }
132 }
133
134 if (!isCurrentPackDataPack) {
135 let tablesToReadInDataPack = existingPack.packedFiles
136 .filter((pf) => pf.schemaFields && pf.name.startsWith("db\\"))
137 .map((pf) => `db\\${getDBNameFromString(pf.name)}`);
138
139 tablesToReadInDataPack = Array.from(new Set(tablesToReadInDataPack));
140 console.log("tables to read from data pack:", tablesToReadInDataPack);
141
142 if (!wasPackAlreadyReadAll(dataPackPath, tablesToReadInDataPack)) {
143 await readModsByPath([dataPackPath], { tablesToRead: tablesToReadInDataPack }, true);
144 const existingDataPack = appData.packsData.find((pack) => pack.path == dataPackPath);
145 if (existingDataPack) {
146 getPacksTableData([existingDataPack], tablesToReadInDataPack);
147 }

Callers 1

registerIpcMainListenersFunction · 0.90

Calls 14

enqueueMethod · 0.95
isEmptyMethod · 0.95
dequeueMethod · 0.95
getDBPackedFilePathFunction · 0.90
readModsByPathFunction · 0.90
getDBNameFromStringFunction · 0.90
getPacksTableDataFunction · 0.90
chunkSchemaIntoRowsFunction · 0.90
getReferencesForGameFunction · 0.90
wasPackAlreadyReadAllFunction · 0.85
getSelectedPackFileFunction · 0.85
getRefFunction · 0.85

Tested by

no test coverage detected