Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
AddonBuildInfoTool.c
Go to the documentation of this file.
2 name: "Generate addon.ci-info files",
3 description: "Generates addon metadata for external tools to know how to build data all at once or in parts, and saves it into JSON file.",
4 wbModules: {"ResourceManager"},
5 awesomeFontCode: 0xF6E3
6)]
7class AddonBuildInfoTool : WorkbenchPlugin
8{
9 private ref array<string> m_EntFiles;
10
11 /*
12 Build-NavMesh-High: .nmn + .ntile
13 Build-NavMesh-Low: .nmn + .ntile
14 Build-ShoreMap: .smd
15 Build-SoundMap: .smap
16
17 Build-FlowMap:
18 * generates .Rivers/{GUID}_flow.edds
19 * command line:
20 * -wbmodule=ResourceManager
21 * -plugin=GenerateFlowMaps
22 * -world=${srcDir}/${entFilePath}
23 * -saveDir=${dstDir}/${entDirPath}
24
25 */
26
27 static bool FindAddonByAbsolutePath(
28 string queryAbsolutePath,
29 out string outAddonGuid,
30 out string outAddonId,
31 out string outAddonExactRoot
32 )
33 {
34 if (!FilePath.IsAbsolutePath(queryAbsolutePath))
35 return false;
36
37 queryAbsolutePath = FilePath.ToInternalFormat(queryAbsolutePath);
38 if (!queryAbsolutePath.EndsWith("/"))
39 queryAbsolutePath += "/";
40
41 array<string> addonGuids = {};
42 GameProject.GetLoadedAddons(addonGuids);
43
44 foreach(string addonGuid : addonGuids)
45 {
46 string addonId = GameProject.GetAddonID(addonGuid);
47 string addonExactRoot = string.Format("$%1:", addonId);
48 string addonAbsolutePath;
49 if (!Workbench.GetAbsolutePath(addonExactRoot, addonAbsolutePath))
50 continue;
51
52 if (!addonAbsolutePath.EndsWith("/"))
53 addonAbsolutePath += "/";
54
55 if (addonAbsolutePath.Compare(queryAbsolutePath, caseSensitive: false) == 0)
56 {
57 outAddonGuid = addonGuid;
58 outAddonId = addonId;
59 outAddonExactRoot = addonExactRoot;
60 return true;
61 }
62 }
63
64 return false;
65 }
66
67 private void OnEntFileFound(ResourceName resName, string file)
68 {
69 m_EntFiles.Insert(resName.GetPath());
70 }
71
72 private bool TryExtractGUID(ResourceName resName, out string guid)
73 {
74 int guidBeg = resName.IndexOf("{");
75 int guidEnd = resName.IndexOf("}");
76 if (guidBeg != -1 && guidEnd != -1)
77 {
78 guidBeg += 1;
79 guid = resName.Substring(guidBeg, guidEnd - guidBeg);
80 return true;
81 }
82 else
83 {
84 return false;
85 }
86 }
87
88 void GenerateCiInfo(ResourceManager rm, FileHandle outputFile, string addonExactRoot, string addonID)
89 {
90 Print(addonExactRoot);
91 Print(addonID);
92 m_EntFiles = {};
94 filter.fileExtensions = {"ent"};
95 filter.rootPath = addonExactRoot;
96 ResourceDatabase.SearchResources(filter, OnEntFileFound);
97
99
100 foreach (string entFile : m_EntFiles)
101 {
102 Print(entFile);
103 string entExactPath = addonExactRoot + entFile;
104 MetaFile mf = rm.GetMetaFile(entExactPath);
105 BaseContainerList configs = mf.GetObjectArray("Configurations");
106 for (int i = 0, count = configs.Count(); i < count; i++)
107 {
108 BaseContainer config = configs[i];
109 string resourceID;
110 if (!TryExtractGUID(mf.GetResourceID(), resourceID))
111 {
112 PrintFormat("Couldn't extract GUID from resource name '%1'", mf.GetResourceID());
113 continue;
114 }
115
116 string configName = config.GetName();
117 array<string> buildTags;
118 config.Get("BuildTags", buildTags);
119 if (!buildTags.IsEmpty())
120 {
121 WorldBuildMeta wbm = new WorldBuildMeta();
122 wbm.id = resourceID;
123 wbm.path = entFile;
124 wbm.tags = buildTags;
125 array<ref WorldBuildMeta> resultList;
126 if (!result.Find(configName, resultList))
127 {
128 resultList = {};
129 result.Set(configName, resultList);
130 }
131 resultList.Insert(wbm);
132 }
133 }
134 }
135
136 string json = "{";
137 bool separateConfigs = false;
138 foreach (string k, array<ref WorldBuildMeta> v : result)
139 {
140 if (separateConfigs)
141 json += ",";
142
143 json += string.Format("\"%1\":{", k);
144 bool separateWbm = false;
145 foreach (WorldBuildMeta wbm : v)
146 {
147 if (separateWbm)
148 json += ",";
149
150 json += string.Format(
151 "\"%1\": {\"name\":\"%2\",\"path\":\"%3\",\"tags\":[",
152 wbm.id,
153 FilePath.StripExtension(FilePath.StripPath(wbm.path)),
154 wbm.path
155 );
156 bool separateTags = false;
157 foreach (string tag : wbm.tags)
158 {
159 if (separateTags)
160 json += ",";
161 json += string.Format("\"%1\"", tag);
162 separateTags = true;
163 }
164 json += "]}";
165 separateWbm = true;
166 }
167 json += "}";
168 separateConfigs = true;
169 }
170 json += "}";
171
172 outputFile.WriteLine(json);
173 }
174
175#ifdef AddonBuildInfoTool_IN_UI
176 override void Run()
177 {
178 ResourceManager rm = Workbench.GetModule(ResourceManager);
179 array<string> addonGUIDs = {};
180 GameProject.GetLoadedAddons(addonGUIDs);
181
182 foreach(string addonGUID : addonGUIDs)
183 {
184 string addonID = GameProject.GetAddonID(addonGUID);
185 string addonExactRoot = string.Format("$%1:", addonID);
186 FileHandle outputFile = FileIO.OpenFile(addonExactRoot + "addon.ci-info", FileMode.WRITE);
187 if (!outputFile.IsOpen())
188 continue;
189
190 GenerateCiInfo(rm, outputFile, addonExactRoot, addonID);
191 outputFile.Close();
192 }
193 }
194#endif
195
196 override void RunCommandline()
197 {
198 ResourceManager rm = Workbench.GetModule(ResourceManager);
199 string addonPathCli;
200 if (!rm.GetCmdLine("-addonPath", addonPathCli))
201 {
202 Print("Missing argument 'addonPath', which is required AddonBuildInfoTool plugin.", level: LogLevel.ERROR);
203 Workbench.Exit(1);
204 return;
205 }
206 if (!FilePath.IsAbsolutePath(addonPathCli))
207 {
208 PrintFormat("Argument 'addonPath' must be an absolute path, but its value is '%1'", addonPathCli, level: LogLevel.ERROR);
209 Workbench.Exit(2);
210 return;
211 }
212
213 string addonGuid, addonId, addonExactRoot;
214 bool found = AddonBuildInfoTool.FindAddonByAbsolutePath(
215 addonPathCli, addonGuid, addonId, addonExactRoot
216 );
217 if (!found)
218 {
219 PrintFormat("Could not find addon matching path '%1'.", addonPathCli);
220 Workbench.Exit(3);
221 }
222
223 string ciInfoDstCli;
224 if (!rm.GetCmdLine("-ciInfoDst", ciInfoDstCli))
225 {
226 Print("Missing argument 'ciInfoDst' for AddonBuildInfoTool plugin.", level: LogLevel.ERROR);
227 Workbench.Exit(4);
228 return;
229 }
230 ciInfoDstCli = FilePath.ToInternalFormat(ciInfoDstCli);
231
232 FileHandle outputFile = FileIO.OpenFile(ciInfoDstCli, FileMode.WRITE);
233 if (!outputFile.IsOpen())
234 {
235 PrintFormat("Couldn't open file '%1' for writing.", ciInfoDstCli, level: LogLevel.ERROR);
236 Workbench.Exit(5);
237 return;
238 }
239
240 GenerateCiInfo(rm, outputFile, addonExactRoot, addonId);
241 outputFile.Close();
242 Workbench.Exit(0);
243 }
244}
245
246class WorldBuildMeta
247{
248 string id;
249 string path;
250 ref array<string> tags;
251}
string path
ref array< string > tags
AddonBuildInfoTool id
override void RunCommandline()
Definition FlowmapTool.c:60
GenerateFlowMaps WorkbenchPlugin WorkbenchPluginAttribute("Regenerate river flow-maps", "Generate and save/overwrite river flow-maps", "", "", {"WorldEditor"}, "", 0xf773)
Definition FlowmapTool.c:59
override void Run()
Object used for holding filtering params for ResourceDatabase.SearchResources() method.
Definition System.c:9
Definition Types.c:486
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14
proto void PrintFormat(string fmt, void param1=NULL, void param2=NULL, void param3=NULL, void param4=NULL, void param5=NULL, void param6=NULL, void param7=NULL, void param8=NULL, void param9=NULL, LogLevel level=LogLevel.NORMAL)
FileMode
Mode for opening file. See FileSystem::Open.
Definition FileMode.c:14