Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- Scans all the files you run this on, and generates data about all the Addon Nodes it found.
- You will be shown a dialog, where you can select whenever you want to output the data into xEdit's messages,
- or save it in a file, and whenever you want it as CSV or in a Wiki table format.
- }
- unit ListAllAddonNodes;
- var
- outData: TStringList;
- targetFile: string;
- doOutputMessages: boolean;
- doUseWikiFormat: boolean;
- function saveFileAs(title: string; filter: string): string;
- var
- objFile: TSaveDialog;
- begin
- objFile := TSaveDialog.Create(nil);
- Result := '';
- objFile.Title := title;
- objFile.Options := objFile.Options + [ofOverwritePrompt];
- objFile.Filter := filter;
- objFile.FilterIndex := 1;
- //Result := objFile;
- try
- if objFile.Execute then begin
- Result := objFile.FileName;
- end;
- finally
- objFile.free;
- end;
- end;
- function showInitialGui(): boolean;
- var
- frm: TForm;
- outputModeRg, formatRg: TRadioGroup;
- resultCode: cardinal;
- okBtn, cancelBtn: TButton;
- begin
- frm := TForm.Create(nil);
- frm.BorderStyle := bsDialog;
- frm.Height := 300;
- frm.Width := 300;
- frm.Position := poScreenCenter;
- frm.Caption := 'Output Addon Nodes';
- outputModeRg := TRadioGroup.Create(frm);
- outputModeRg.Parent := frm;
- outputModeRg.Left := 20;
- outputModeRg.Top := 10;
- outputModeRg.Width := 240;
- outputModeRg.Height := 70;
- outputModeRg.Caption := 'Output Mode';
- outputModeRg.Items.Add('Save As File');
- outputModeRg.Items.Add('Output To Messages');
- outputModeRg.ItemIndex := 0;
- formatRg := TRadioGroup.Create(frm);
- formatRg.Parent := frm;
- formatRg.Left := 20;
- formatRg.Top := 100;
- formatRg.Width := 240;
- formatRg.Height := 70;
- formatRg.Caption := 'Output Format';
- formatRg.Items.Add('Regular CSV');
- formatRg.Items.Add('Wiki Table Format');
- formatRg.ItemIndex := 0;
- okBtn := TButton.Create(frm);
- okBtn.Width := 60;
- okBtn.Parent := frm;
- okBtn.Left := 20;
- okBtn.Top := 200;
- okBtn.Caption := 'OK';
- okBtn.ModalResult := mrOk;
- cancelBtn := TButton.Create(frm);
- cancelBtn.Width := 60;
- cancelBtn.Parent := frm;
- cancelBtn.Left := 80;
- cancelBtn.Top := 200;
- cancelBtn.Caption := 'Cancel';
- cancelBtn.ModalResult := mrCancel;
- resultCode := frm.showModal();
- Result := false;
- if(resultCode = mrOk) then begin
- Result := true;
- doOutputMessages := (outputModeRg.ItemIndex = 1);
- doUseWikiFormat := (formatRg.ItemIndex = 1);
- if(not doOutputMessages) then begin
- if(doUseWikiFormat) then begin
- targetFile := saveFileAs('Save output as', 'Text files|*.txt|All files|*.*');
- end else begin
- targetFile := saveFileAs('Save output as', 'CSV files|*.csv|All files|*.*');
- end;
- end;
- end;
- frm.free();
- end;
- // Called before processing
- // You can remove it if script doesn't require initialization code
- function Initialize: integer;
- var
- ext: string;
- begin
- if(not showInitialGui()) then exit;
- outData := TStringList.create;
- if(not doUseWikiFormat) then begin
- outData.add('Editor ID,Node Index,Filename');
- end;
- if(not doOutputMessages) then begin
- if(targetFile = '') then begin
- AddMessage('Cancelled');
- Result := 1;
- exit;
- end;
- ext := LowerCase(ExtractFileExt(targetFile));
- if(ext = '') then begin
- if(doUseWikiFormat) then begin
- targetFile := targetFile + '.txt';
- end else begin
- targetFile := targetFile + '.csv';
- end;
- end;
- AddMessage('Target file: '+targetFile);
- end;
- Result := 0;
- end;
- // called for every record selected in xEdit
- function Process(e: IInterface): integer;
- var
- curIndex, numSoFar: integer;
- begin
- Result := 0;
- if(Signature(e) <> 'ADDN') or (not IsMaster(e)) then begin
- exit;
- end;
- curIndex := GetElementNativeValues(e, 'DATA');
- if(doUseWikiFormat) then begin
- outData.add('|-');
- outData.add('| '+EditorID(e)+' || '+IntToStr(curIndex)+' || '+GetFileName(GetFile(e))+' || Mod Link Here');
- end else begin
- outData.add(EditorID(e)+','+IntToStr(curIndex)+','+GetFileName(GetFile(e)));
- end;
- numSoFar := (outData.count - 1);
- if((numSoFar mod 50) = 0) then begin
- AddMessage('Found '+IntToStr(numSoFar)+' AddOn Nodes so far');
- end;
- end;
- procedure outputData();
- var
- i: integer;
- begin
- AddMessage('=== DATA OUTPUT BEGIN ===');
- for i:=0 to outData.count-1 do begin
- AddMessage(outData[i]);
- end;
- AddMessage('=== DATA OUTPUT END ===');
- end;
- // Called after processing
- // You can remove it if script doesn't require finalization code
- function Finalize: integer;
- begin
- if(doOutputMessages) then begin
- outputData();
- end else begin
- AddMessage('Saving file '+targetFile);
- outData.saveToFile(targetFile);
- end;
- Result := 0;
- outData.free();
- end;
- end.
Add Comment
Please, Sign In to add comment