Guest User

Untitled

a guest
Feb 15th, 2025
12
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.88 KB | None | 0 0
  1. {
  2. Scans all the files you run this on, and generates data about all the Addon Nodes it found.
  3. You will be shown a dialog, where you can select whenever you want to output the data into xEdit's messages,
  4. or save it in a file, and whenever you want it as CSV or in a Wiki table format.
  5. }
  6. unit ListAllAddonNodes;
  7. var
  8. outData: TStringList;
  9. targetFile: string;
  10.  
  11. doOutputMessages: boolean;
  12. doUseWikiFormat: boolean;
  13.  
  14.  
  15. function saveFileAs(title: string; filter: string): string;
  16. var
  17. objFile: TSaveDialog;
  18. begin
  19. objFile := TSaveDialog.Create(nil);
  20. Result := '';
  21.  
  22. objFile.Title := title;
  23. objFile.Options := objFile.Options + [ofOverwritePrompt];
  24.  
  25.  
  26. objFile.Filter := filter;
  27. objFile.FilterIndex := 1;
  28.  
  29. //Result := objFile;
  30.  
  31. try
  32. if objFile.Execute then begin
  33. Result := objFile.FileName;
  34. end;
  35. finally
  36. objFile.free;
  37. end;
  38. end;
  39.  
  40.  
  41. function showInitialGui(): boolean;
  42. var
  43. frm: TForm;
  44. outputModeRg, formatRg: TRadioGroup;
  45. resultCode: cardinal;
  46.  
  47. okBtn, cancelBtn: TButton;
  48. begin
  49. frm := TForm.Create(nil);
  50. frm.BorderStyle := bsDialog;
  51. frm.Height := 300;
  52. frm.Width := 300;
  53. frm.Position := poScreenCenter;
  54. frm.Caption := 'Output Addon Nodes';
  55.  
  56. outputModeRg := TRadioGroup.Create(frm);
  57. outputModeRg.Parent := frm;
  58. outputModeRg.Left := 20;
  59. outputModeRg.Top := 10;
  60. outputModeRg.Width := 240;
  61. outputModeRg.Height := 70;
  62. outputModeRg.Caption := 'Output Mode';
  63. outputModeRg.Items.Add('Save As File');
  64. outputModeRg.Items.Add('Output To Messages');
  65. outputModeRg.ItemIndex := 0;
  66.  
  67. formatRg := TRadioGroup.Create(frm);
  68. formatRg.Parent := frm;
  69. formatRg.Left := 20;
  70. formatRg.Top := 100;
  71. formatRg.Width := 240;
  72. formatRg.Height := 70;
  73. formatRg.Caption := 'Output Format';
  74. formatRg.Items.Add('Regular CSV');
  75. formatRg.Items.Add('Wiki Table Format');
  76. formatRg.ItemIndex := 0;
  77.  
  78. okBtn := TButton.Create(frm);
  79. okBtn.Width := 60;
  80. okBtn.Parent := frm;
  81. okBtn.Left := 20;
  82. okBtn.Top := 200;
  83. okBtn.Caption := 'OK';
  84. okBtn.ModalResult := mrOk;
  85.  
  86. cancelBtn := TButton.Create(frm);
  87. cancelBtn.Width := 60;
  88. cancelBtn.Parent := frm;
  89. cancelBtn.Left := 80;
  90. cancelBtn.Top := 200;
  91. cancelBtn.Caption := 'Cancel';
  92.  
  93. cancelBtn.ModalResult := mrCancel;
  94.  
  95.  
  96. resultCode := frm.showModal();
  97.  
  98. Result := false;
  99. if(resultCode = mrOk) then begin
  100. Result := true;
  101.  
  102. doOutputMessages := (outputModeRg.ItemIndex = 1);
  103. doUseWikiFormat := (formatRg.ItemIndex = 1);
  104.  
  105. if(not doOutputMessages) then begin
  106. if(doUseWikiFormat) then begin
  107. targetFile := saveFileAs('Save output as', 'Text files|*.txt|All files|*.*');
  108. end else begin
  109. targetFile := saveFileAs('Save output as', 'CSV files|*.csv|All files|*.*');
  110. end;
  111. end;
  112.  
  113. end;
  114.  
  115. frm.free();
  116.  
  117. end;
  118.  
  119.  
  120.  
  121.  
  122. // Called before processing
  123. // You can remove it if script doesn't require initialization code
  124. function Initialize: integer;
  125. var
  126. ext: string;
  127. begin
  128. if(not showInitialGui()) then exit;
  129.  
  130. outData := TStringList.create;
  131.  
  132. if(not doUseWikiFormat) then begin
  133. outData.add('Editor ID,Node Index,Filename');
  134. end;
  135.  
  136.  
  137. if(not doOutputMessages) then begin
  138.  
  139. if(targetFile = '') then begin
  140. AddMessage('Cancelled');
  141. Result := 1;
  142. exit;
  143. end;
  144.  
  145. ext := LowerCase(ExtractFileExt(targetFile));
  146. if(ext = '') then begin
  147. if(doUseWikiFormat) then begin
  148. targetFile := targetFile + '.txt';
  149. end else begin
  150. targetFile := targetFile + '.csv';
  151. end;
  152. end;
  153.  
  154. AddMessage('Target file: '+targetFile);
  155. end;
  156. Result := 0;
  157. end;
  158.  
  159. // called for every record selected in xEdit
  160. function Process(e: IInterface): integer;
  161. var
  162. curIndex, numSoFar: integer;
  163. begin
  164. Result := 0;
  165.  
  166. if(Signature(e) <> 'ADDN') or (not IsMaster(e)) then begin
  167. exit;
  168. end;
  169.  
  170. curIndex := GetElementNativeValues(e, 'DATA');
  171.  
  172. if(doUseWikiFormat) then begin
  173. outData.add('|-');
  174. outData.add('| '+EditorID(e)+' || '+IntToStr(curIndex)+' || '+GetFileName(GetFile(e))+' || Mod Link Here');
  175. end else begin
  176. outData.add(EditorID(e)+','+IntToStr(curIndex)+','+GetFileName(GetFile(e)));
  177. end;
  178. numSoFar := (outData.count - 1);
  179. if((numSoFar mod 50) = 0) then begin
  180. AddMessage('Found '+IntToStr(numSoFar)+' AddOn Nodes so far');
  181. end;
  182. end;
  183.  
  184. procedure outputData();
  185. var
  186. i: integer;
  187. begin
  188. AddMessage('=== DATA OUTPUT BEGIN ===');
  189. for i:=0 to outData.count-1 do begin
  190. AddMessage(outData[i]);
  191. end;
  192. AddMessage('=== DATA OUTPUT END ===');
  193. end;
  194.  
  195. // Called after processing
  196. // You can remove it if script doesn't require finalization code
  197. function Finalize: integer;
  198. begin
  199. if(doOutputMessages) then begin
  200. outputData();
  201. end else begin
  202. AddMessage('Saving file '+targetFile);
  203. outData.saveToFile(targetFile);
  204. end;
  205. Result := 0;
  206. outData.free();
  207. end;
  208.  
  209. end.
Add Comment
Please, Sign In to add comment