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
5 [
Attribute(defvalue:
"",
desc:
"File extensions separated by a comma (e.g.: \"edds,imageset\")\nNo value means all extensions")]
6 protected string m_sExtensions;
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;
11 protected static const ref array<string> ALLOWED_EXTENSIONS = {
"conf",
"et" };
17 if (!Workbench.ScriptDialog(
"Find Linked Resources",
"Scan all selected files and print out resources of given extension(s) linked to from attributes.",
this))
20 m_sExtensions.ToLower();
21 array<string> extensions = {};
22 m_sExtensions.Split(
",", extensions,
true);
24 for (
int i = extensions.Count() - 1; i >= 0; --i)
26 string extension = extensions[i];
27 extension.TrimInPlace();
29 extensions[i] = extension;
36 bool noExtensionsDefined = extensions.IsEmpty();
38 array<ResourceName> selection = {};
39 ResourceManager resourceManager = Workbench.GetModule(ResourceManager);
40 resourceManager.GetResourceBrowserSelection(selection.Insert,
true);
42 int count = selection.Count();
45 Print(
"No resources selected in Resource Browser",
LogLevel.NORMAL);
49 array<ref Resource> resourceObjects = {};
51 array<BaseContainer> containers = {};
52 float prevProgress, currProgress;
53 WBProgressDialog progress =
new WBProgressDialog(
"Loading " + count +
" resources...", resourceManager);
59 if (!ALLOWED_EXTENSIONS.Contains(extension))
63 if (!resource.IsValid())
69 resourceObjects.Insert(resource);
70 containers.Insert(resource.GetResource().ToBaseContainer());
72 currProgress = i / count;
73 if (currProgress - prevProgress >= 0.01)
75 progress.SetProgress(currProgress);
76 prevProgress = currProgress;
80 array<string> resourcePaths = {};
86 count = containers.Count();
93 array<ResourceName> resourceNames;
94 progress =
new WBProgressDialog(
"Processing " + count +
" main containers...", resourceManager);
95 while (!containers.IsEmpty())
97 container = containers[0];
98 containers.RemoveOrdered(0);
107 for (
int i = container.GetNumChildren() - 1; i >= 0; --i)
109 containers.Insert(container.GetChild(i));
112 for (
int i, varCount = container.GetNumVars(); i < varCount; ++i)
114 string varName = container.GetVarName(i);
115 if (m_bOnlyShowDirectlySetVariables && !container.IsVariableSetDirectly(varName))
118 switch (container.GetDataVarType(i))
125 Print(
"Cannot read " + varName +
" (resourceName)",
LogLevel.WARNING);
135 if (!noExtensionsDefined)
139 varExtension.ToLower();
141 if (!extensions.Contains(varExtension))
152 if (!resourcePaths.Contains(
path))
153 resourcePaths.Insert(
path);
158 if (!container.Get(varName, resourceNames))
160 Print(
"Cannot read " + varName +
" (resourceName array)",
LogLevel.WARNING);
166 if (!noExtensionsDefined)
170 varExtension.ToLower();
172 if (!extensions.Contains(varExtension))
190 object = container.GetObject(varName);
193 Print(
"Cannot read " + varName +
" (object)",
LogLevel.WARNING);
197 containers.Insert(
object);
201 list = container.GetObjectArray(varName);
204 Print(
"Cannot read " + varName +
" (object array)",
LogLevel.WARNING);
208 for (
int l = 0, listCount = list.Count(); l < listCount; l++)
210 containers.Insert(list.Get(l));
217 currProgress = (count - containers.Count()) / count;
218 if (currProgress - prevProgress >= 0.01)
220 progress.SetProgress(currProgress);
221 prevProgress = currProgress;
225 int resourcesCount = resourcePaths.Count();
226 if (resourcesCount < 1)
232 if (noExtensionsDefined)
233 PrintFormat(
"Linked resources of all types (%1):", resourcesCount, level:
LogLevel.NORMAL);
237 resourcePaths.Sort();
238 foreach (
string resourcePath : resourcePaths)
253 protected bool Cancel()
ResourceName resourceName
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
SCR_RespawnComponentClass OK
Result code for request/assign response.
class WorkbenchDialog_AbortRetryIgnore ButtonAttribute("OK", true)
Object holding reference to resource. In destructor release the resource.
static string Join(string separator, notnull array< string > pieces, bool joinEmptyEntries=true)
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
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