Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_UpdateAllEditablePrefabsPlugin.c
Go to the documentation of this file.
1#ifdef WORKBENCH
2[WorkbenchPluginAttribute(name: "Update All Editable Prefabs", category: SCR_PluginCategory.EDITOR, wbModules: { "WorldEditor", "ResourceManager" }, awesomeFontCode: 0xF1B3)]
3class SCR_UpdateAllEditablePrefabsPlugin : WorkbenchPlugin
4{
5 [Attribute(defvalue: "{90B4D95CF3610F3D}Configs/Workbench/EditablePrefabs/EditablePrefabsConfig.conf", desc: "", params: "conf")]
6 protected ResourceName m_sConfig;
7
8 [Attribute(desc: "Enable to only check for renamed or delete files, don't update their content.")]
9 protected bool m_bOnlyFileChanges;
10
11 protected static const string META_EXTENSION = ".meta";
12
13 //------------------------------------------------------------------------------------------------
14 protected void DeleteEmptyDirectoriesCallback(string path, FileAttribute attributes)
15 {
16 if ((attributes & FileAttribute.DIRECTORY) && FileIO.DeleteFile(path)) //--- DeleteFile fails when the folder is not empty
17 Print(string.Format("Folder DELETED: '%1' (was empty)", path), LogLevel.WARNING);
18 }
19
20 //------------------------------------------------------------------------------------------------
21 protected void DeleteEmptyDirectories(string path)
22 {
23 FileIO.FindFiles(DeleteEmptyDirectoriesCallback, path, string.Empty);
24 }
25
26 //------------------------------------------------------------------------------------------------
27 override void Run()
28 {
29 if (!Workbench.ScriptDialog("Configure 'Update All Editable Prefabs' plugin", "Batch operation applied on all auto-generated editable prefabs\n(check the config to see which folders will be affected).\n\nWARNING: This operation can take several minutes to perform!", this))
30 return;
31
32 EditablePrefabsConfig config = EditablePrefabsConfig.GetConfig(m_sConfig);
33 if (!config || !config.IsValid())
34 return;
35
36 ResourceManager resourceManager = Workbench.GetModule(ResourceManager);
37 if (!resourceManager)
38 return;
39
40 Workbench.OpenModule(WorldEditor);
41 WorldEditor worldEditor = Workbench.GetModule(WorldEditor);
42 if (!worldEditor)
43 return;
44
45 WorldEditorAPI api = worldEditor.GetApi();
46 if (!api)
47 return;
48
49 //--- Ask first
50 //SCR_ConfirmationDialogWorkbench dialog = new SCR_ConfirmationDialogWorkbench();
51 //if (!Workbench.ScriptDialog("", "Do you want to update all editable prefabs?", dialog))
52 // return;
53
54 string targetPath = config.GetTargetPathAuto();
55
56 WBProgressDialog progress = new WBProgressDialog("Processing Prefabs...", resourceManager);
57 Print(string.Format("Updating editable entity prefabs STARTED at '%1'", targetPath), LogLevel.DEBUG);
58
59 if (!config.CreateWorld())
60 return;
61
62 //--- Get all files
63 array<ResourceName> resources = {};
64
65 SearchResourcesFilter filter = new SearchResourcesFilter();
66 filter.fileExtensions = { "et" };
67 ResourceDatabase.SearchResources(filter, resources.Insert);
68 int resourcesCount = resources.Count();
69
70 string prefabPath;
71 array<string> toRebuild = {};
72
73 api.BeginEntityAction();
74 float prevProgress, currProgress;
75 foreach (int i, ResourceName prefab : resources)
76 {
77 prefabPath = prefab.GetPath();
78 if (!prefabPath.StartsWith(targetPath))
79 continue;
80
81 prefabPath = config.VerifyEditablePrefab(api, prefab, m_bOnlyFileChanges);
82 if (!prefabPath.IsEmpty())
83 toRebuild.Insert(prefabPath);
84
85 currProgress = i / resourcesCount;
86 if (currProgress - prevProgress >= 0.01) // min 1%
87 {
88 progress.SetProgress(currProgress); // expensive
89 prevProgress = currProgress;
90 }
91 }
92
93 api.EndEntityAction();
94 resources.Clear();
95
96 resourceManager.RebuildResourceFiles(toRebuild, "PC");
97
98 DeleteEmptyDirectories(targetPath);
99
100 worldEditor.Save(); //--- Save to world so it's not marked as edited
101
102 Print(string.Format("Updating editable entity prefabs FINISHED at '%1'", targetPath), LogLevel.DEBUG);
103 }
104
105 //------------------------------------------------------------------------------------------------
106 [ButtonAttribute("Run")]
107 protected bool ButtonRun()
108 {
109 return true;
110 }
111
112 //------------------------------------------------------------------------------------------------
113 [ButtonAttribute("Close")]
114 protected bool ButtonClose()
115 {
116 return false;
117 }
118}
119
120class SCR_ConfirmationDialogWorkbench
121{
122 //------------------------------------------------------------------------------------------------
123 [ButtonAttribute("OK")]
124 protected bool ButtonOK()
125 {
126 return true;
127 }
128
129 //------------------------------------------------------------------------------------------------
130 [ButtonAttribute("Cancel")]
131 protected bool ButtonCancel()
132 {
133 return false;
134 }
135}
136#endif // WORKBENCH
string path
GenerateFlowMaps WorkbenchPlugin WorkbenchPluginAttribute("Regenerate river flow-maps", "Generate and save/overwrite river flow-maps", "", "", {"WorldEditor"}, "", 0xf773)
Definition FlowmapTool.c:59
override void Run()
bool ButtonCancel()
bool ButtonOK()
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
class WorkbenchDialog_AbortRetryIgnore ButtonAttribute("OK", 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.
Definition LogLevel.c:14
SCR_FieldOfViewSettings Attribute
FileAttribute
File attributes. See FileDescription.