Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_FindResourcesPlugin.c
Go to the documentation of this file.
1#ifdef WORKBENCH
2[WorkbenchPluginAttribute(name: "Find Linked Resources", description: "Find resources referenced by the resources selected in Resource Browser", wbModules: { "ResourceManager" }, awesomeFontCode: 0xF0C1)]
3class SCR_FindResourcesPlugin : ResourceManagerPlugin
4{
5 [Attribute(defvalue: "", desc: "File extensions separated by a comma (e.g.: \"edds,imageset\")\nNo value means all extensions")]
6 protected string m_sExtensions;
7
8 [Attribute(defvalue: "0", desc: "Show only values set directly in the resource (and not in its parents or default value)")]
9 protected bool m_bOnlyShowDirectlySetVariables;
10
11 protected static const ref array<string> ALLOWED_EXTENSIONS = { "conf", "et" };
12// protected static const ref array<string> FORBIDDEN_DOTTED_EXTENSIONS = { ".c", ".edds", ".fbx", ".png", ".txt", ".wav", ".xob" };
13
14 //------------------------------------------------------------------------------------------------
15 override void Run()
16 {
17 if (!Workbench.ScriptDialog("Find Linked Resources", "Scan all selected files and print out resources of given extension(s) linked to from attributes.", this))
18 return;
19
20 m_sExtensions.ToLower();
21 array<string> extensions = {};
22 m_sExtensions.Split(",", extensions, true);
23
24 for (int i = extensions.Count() - 1; i >= 0; --i)
25 {
26 string extension = extensions[i];
27 extension.TrimInPlace();
28 if (extension)
29 extensions[i] = extension;
30 else
31 extensions.Remove(i);
32 }
33
34 m_sExtensions = SCR_StringHelper.Join(",", extensions, false);
35
36 bool noExtensionsDefined = extensions.IsEmpty();
37
38 array<ResourceName> selection = {};
39 ResourceManager resourceManager = Workbench.GetModule(ResourceManager);
40 resourceManager.GetResourceBrowserSelection(selection.Insert, true);
41
42 int count = selection.Count();
43 if (count < 1)
44 {
45 Print("No resources selected in Resource Browser", LogLevel.NORMAL);
46 return;
47 }
48
49 array<ref Resource> resourceObjects = {}; // reference MUST be kept
50 Resource resource;
51 array<BaseContainer> containers = {};
52 float prevProgress, currProgress;
53 WBProgressDialog progress = new WBProgressDialog("Loading " + count + " resources...", resourceManager);
54 foreach (int i, ResourceName resourceName : selection)
55 {
56 string extension;
57 FilePath.StripExtension(resourceName.GetPath(), extension);
58 extension.ToLower();
59 if (!ALLOWED_EXTENSIONS.Contains(extension))
60 continue;
61
62 resource = Resource.Load(resourceName);
63 if (!resource.IsValid())
64 {
65 Print("Cannot load resource " + resourceName.GetPath(), LogLevel.WARNING);
66 continue;
67 }
68
69 resourceObjects.Insert(resource);
70 containers.Insert(resource.GetResource().ToBaseContainer());
71
72 currProgress = i / count;
73 if (currProgress - prevProgress >= 0.01) // min 1%
74 {
75 progress.SetProgress(currProgress); // expensive
76 prevProgress = currProgress;
77 }
78 }
79
80 array<string> resourcePaths = {};
81 BaseContainer container, object;
83
84 prevProgress = 0;
85 currProgress = 0;
86 count = containers.Count();
87 if (count < 1)
88 {
89 Print("No containers found.", LogLevel.NORMAL);
90 return;
91 }
92
93 array<ResourceName> resourceNames;
94 progress = new WBProgressDialog("Processing " + count + " main containers...", resourceManager);
95 while (!containers.IsEmpty())
96 {
97 container = containers[0];
98 containers.RemoveOrdered(0);
99
100 if (!container)
101 {
102 Print("null container?!", LogLevel.WARNING);
103 continue;
104 }
105
106 // add children already
107 for (int i = container.GetNumChildren() - 1; i >= 0; --i)
108 {
109 containers.Insert(container.GetChild(i));
110 }
111
112 for (int i, varCount = container.GetNumVars(); i < varCount; ++i)
113 {
114 string varName = container.GetVarName(i);
115 if (m_bOnlyShowDirectlySetVariables && !container.IsVariableSetDirectly(varName))
116 continue;
117
118 switch (container.GetDataVarType(i))
119 {
120 case DataVarType.RESOURCE_NAME:
121// case DataVarType.STRING:
123 if (!container.Get(varName, resourceName))
124 {
125 Print("Cannot read " + varName + " (resourceName)", LogLevel.WARNING);
126 break;
127 }
128
129 if (!resourceName) // .IsEmpty()
130 {
131 // Print(varName + " is empty", LogLevel.NORMAL);
132 break;
133 }
134
135 if (!noExtensionsDefined)
136 {
137 string varExtension;
138 FilePath.StripExtension(resourceName, varExtension);
139 varExtension.ToLower();
140
141 if (!extensions.Contains(varExtension))
142 break;
143 }
144
145 string path = resourceName.GetPath();
146 if (!path) // .IsEmpty()
147 {
148 PrintFormat("%1 has no path (%2)", varName, resourceName, level: LogLevel.WARNING);
149 break;
150 }
151
152 if (!resourcePaths.Contains(path))
153 resourcePaths.Insert(path);
154
155 break;
156
157 case DataVarType.RESOURCE_NAME_ARRAY:
158 if (!container.Get(varName, resourceNames))
159 {
160 Print("Cannot read " + varName + " (resourceName array)", LogLevel.WARNING);
161 break;
162 }
163
164 foreach (ResourceName resourceName : resourceNames)
165 {
166 if (!noExtensionsDefined)
167 {
168 string varExtension;
169 FilePath.StripExtension(resourceName, varExtension);
170 varExtension.ToLower();
171
172 if (!extensions.Contains(varExtension))
173 continue;
174 }
175
176 string path = resourceName.GetPath();
177 if (!path) // .IsEmpty()
178 {
179 PrintFormat("%1 has no path (%2)", varName, resourceName, level: LogLevel.WARNING);
180 break;
181 }
182
183 if (!resourcePaths.Contains(resourceName))
184 resourcePaths.Insert(resourceName);
185 }
186
187 break;
188
189 case DataVarType.OBJECT:
190 object = container.GetObject(varName);
191 if (!object)
192 {
193 Print("Cannot read " + varName + " (object)", LogLevel.WARNING);
194 break;
195 }
196
197 containers.Insert(object);
198 break;
199
200 case DataVarType.OBJECT_ARRAY:
201 list = container.GetObjectArray(varName);
202 if (!list)
203 {
204 Print("Cannot read " + varName + " (object array)", LogLevel.WARNING);
205 break;
206 }
207
208 for (int l = 0, listCount = list.Count(); l < listCount; l++)
209 {
210 containers.Insert(list.Get(l));
211 }
212
213 break;
214 }
215 }
216
217 currProgress = (count - containers.Count()) / count;
218 if (currProgress - prevProgress >= 0.01) // min 1%
219 {
220 progress.SetProgress(currProgress); // expensive
221 prevProgress = currProgress;
222 }
223 }
224
225 int resourcesCount = resourcePaths.Count();
226 if (resourcesCount < 1)
227 {
228 Print("No resources found.", LogLevel.NORMAL);
229 return;
230 }
231
232 if (noExtensionsDefined)
233 PrintFormat("Linked resources of all types (%1):", resourcesCount, level: LogLevel.NORMAL);
234 else
235 PrintFormat("Linked resources of type(s) %1 (%2):", SCR_StringHelper.Join(", ", extensions, false), resourcesCount, level: LogLevel.NORMAL);
236
237 resourcePaths.Sort();
238 foreach (string resourcePath : resourcePaths)
239 {
240 PrintFormat("@\"%1\"", resourcePath, level: LogLevel.NORMAL);
241 }
242 }
243
244 //------------------------------------------------------------------------------------------------
245 [ButtonAttribute("Run")]
246 protected bool OK()
247 {
248 return true;
249 }
250
251 //------------------------------------------------------------------------------------------------
252 [ButtonAttribute("Cancel")]
253 protected bool Cancel()
254 {
255 return false;
256 }
257}
258#endif // WORKBENCH
string path
GenerateFlowMaps WorkbenchPlugin WorkbenchPluginAttribute("Regenerate river flow-maps", "Generate and save/overwrite river flow-maps", "", "", {"WorldEditor"}, "", 0xf773)
Definition FlowmapTool.c:59
ResourceName resourceName
Definition SCR_AIGroup.c:66
override void Run()
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
SCR_RespawnComponentClass OK
Result code for request/assign response.
Definition EMoveError.c:14
class WorkbenchDialog_AbortRetryIgnore ButtonAttribute("OK", true)
Object holding reference to resource. In destructor release the resource.
Definition Resource.c:25
static string Join(string separator, notnull array< string > pieces, bool joinEmptyEntries=true)
DataVarType
Definition DataVarType.c:18
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)
SCR_FieldOfViewSettings Attribute