FindFailureAssetsWnd.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. const FairyGUI = CS.FairyGUI;
  4. const FairyEditor = CS.FairyEditor;
  5. const FileUtils_1 = require("./FileUtils");
  6. const UIWindow_1 = require("./UIWindow");
  7. const App = FairyEditor.App;
  8. class FindFailureAssetsWnd extends UIWindow_1.default {
  9. constructor() {
  10. super(new UIWindow_1.WindData("Extend", "FindFailureAssets"));
  11. }
  12. static show() {
  13. let url = FileUtils_1.default.joinUrl("Extend", "FindFailureAssets");
  14. if (UIWindow_1.default.FindUrl(url) == undefined) {
  15. UIWindow_1.default.add(new this);
  16. }
  17. super.show(url);
  18. }
  19. state;
  20. check;
  21. progress;
  22. resList;
  23. assets = new Map();
  24. onInit() {
  25. super.onInit();
  26. this.state = this.contentPane.GetController("state");
  27. this.check = this.contentPane.GetChild("check").asButton;
  28. this.progress = this.contentPane.GetChild("progress").asProgress;
  29. this.resList = this.contentPane.GetChild("resList").asList;
  30. this.resList.itemRenderer = this.onItemRenderer.bind(this);
  31. this.resList.onClickItem.Add(this.onListClickItem.bind(this));
  32. this.check.onClick.Add(this.onCheckClick.bind(this));
  33. let cancel = this.contentPane.GetChild("close").asButton;
  34. cancel.onClick.Add(this.onCancelClick.bind(this));
  35. this.resList.SetVirtual();
  36. }
  37. onShown() {
  38. super.onShown();
  39. }
  40. onHide() {
  41. super.onHide();
  42. this.resList.data = null;
  43. this.resList.numItems = 0;
  44. }
  45. async onCheckClick() {
  46. if (this.state.selectedIndex == 0) {
  47. this.state.selectedIndex = 1;
  48. this.assets.clear();
  49. let pkgs = App.project.allPackages;
  50. this.progress.value = 0;
  51. this.progress.max = FileUtils_1.default.getAllPackageItemsCount();
  52. for (let index = 0; index < pkgs.Count; index++) {
  53. let pkg = pkgs.get_Item(index);
  54. if (this.state.selectedIndex == 0)
  55. break;
  56. for (let j = 0; j < pkg.items.Count; j++) {
  57. if (this.state.selectedIndex == 0)
  58. break;
  59. let item = pkg.items.get_Item(j);
  60. this.progress.value += 1;
  61. if (item.type != CS.FairyEditor.FObjectType.COMPONENT) {
  62. continue;
  63. }
  64. //@ts-ignore
  65. this.getFailureAssets(item, this.assets, 0);
  66. if (this.progress.value % 30 == 0) {
  67. await FileUtils_1.default.sleep(0);
  68. }
  69. }
  70. }
  71. App.consoleView.Log("查找完毕");
  72. this.state.selectedIndex = 0;
  73. let asset = Array.from(this.assets).map(item => item[1]);
  74. this.resList.data = asset;
  75. this.resList.numItems = asset.length;
  76. this.contentPane.GetChild("projectCount").asTextField.templateVars = FileUtils_1.default.getTemplateVars(['value'], [asset.length.toString()]);
  77. }
  78. else {
  79. this.state.selectedIndex = 0;
  80. }
  81. }
  82. onItemRenderer(index, obj) {
  83. let data = this.resList.data[index];
  84. obj.data = data;
  85. let packageItem = App.project.GetItemByURL(data.url);
  86. obj.GetChild("title").text = packageItem.name;
  87. obj.__onDispose = () => {
  88. obj.GetChild("title").text = '';
  89. obj.data = null;
  90. };
  91. }
  92. onListClickItem(item) {
  93. let data = item.data.data;
  94. let packageItem = App.project.GetItemByURL(data.url);
  95. App.consoleView.Log(FileUtils_1.default.getUBBUrl(packageItem.GetURL(), `包含无效URL的组件:${packageItem.name}`));
  96. for (let index = 0; index < data.failure.length; index++) {
  97. App.consoleView.Log('无效URL:' + data.failure[index]);
  98. }
  99. }
  100. onCancelClick() {
  101. let self = this;
  102. this.Hide();
  103. FairyGUI.Timers.inst.Add(0.05, 1, () => {
  104. UIWindow_1.default.remove(self);
  105. });
  106. }
  107. /**查找失效资源 */
  108. getFailureAssets(item, map, quertIndex) {
  109. let xml = CS.FairyEditor.XMLExtension.Load(item.file);
  110. if (!xml) {
  111. App.consoleView.LogError(`PackageItem找不到配置文件. Name:${item.name} Index:${quertIndex} File:${item.file}`);
  112. return quertIndex;
  113. }
  114. let rootElements = xml.Elements();
  115. for (let index = 0; index < rootElements.Count; index++) {
  116. let child = rootElements.get_Item(index);
  117. if (child.name != 'displayList')
  118. continue;
  119. let childElements = child.Elements();
  120. for (let index = 0; index < childElements.Count; index++) {
  121. const element = childElements.get_Item(index);
  122. if (element.name == 'loader' || element.name == 'loader3D') {
  123. if (element.GetAttribute('clearOnPublish'))
  124. continue;
  125. let url = element.GetAttribute('url');
  126. if (!url)
  127. continue;
  128. //没清理依赖
  129. let packageItem = App.project.GetItemByURL(url);
  130. if (!packageItem) {
  131. if (!map.has(item.GetURL())) {
  132. map.set(item.GetURL(), {
  133. url: item.GetURL(),
  134. failure: []
  135. });
  136. }
  137. map.get(item.GetURL()).failure.push(`name:${element.GetAttribute("name")} file:${element.GetAttribute("fileName")} url:${url}`);
  138. }
  139. else if (!map.has(packageItem.GetURL())) {
  140. if (packageItem.type == FairyEditor.FPackageItemType.COMPONENT) {
  141. quertIndex = this.getFailureAssets(packageItem, map, quertIndex);
  142. }
  143. quertIndex += 1;
  144. }
  145. }
  146. else {
  147. let src = element.GetAttribute("src");
  148. if (!src) {
  149. //系统资源 不需要依赖
  150. continue;
  151. }
  152. let pkg = element.GetAttribute("pkg");
  153. if (!pkg) {
  154. //自己依赖包的资源 所以不需要pkg
  155. pkg = item.owner.id;
  156. }
  157. let url = `ui://${pkg}${src}`;
  158. if (src == null)
  159. App.consoleView.Log(element.name);
  160. let packageItem = App.project.GetItemByURL(url);
  161. if (!packageItem) {
  162. if (!map.has(item.GetURL())) {
  163. map.set(item.GetURL(), {
  164. url: item.GetURL(),
  165. failure: []
  166. });
  167. }
  168. map.get(item.GetURL()).failure.push(`name:${element.GetAttribute("name")} file:${element.GetAttribute("fileName")} url:${url}`);
  169. }
  170. else if (!map.has(packageItem.GetURL())) {
  171. if (packageItem.type == FairyEditor.FPackageItemType.COMPONENT) {
  172. quertIndex = this.getFailureAssets(packageItem, map, quertIndex);
  173. }
  174. quertIndex += 1;
  175. }
  176. }
  177. }
  178. }
  179. return quertIndex;
  180. }
  181. }
  182. exports.default = FindFailureAssetsWnd;