Advertisement
Mator

TestRNAM

May 23rd, 2015
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 2.07 KB | None | 0 0
  1. unit UserScript;
  2.  
  3. uses mteFunctions;
  4.  
  5. var
  6.   files, masters: TStringList;
  7.   userFile: IInterface;
  8.  
  9. procedure FixRNAM(g: IInterface);
  10. var
  11.   i: integer;
  12.   r: IInterface;
  13. begin
  14.   for i := 0 to Pred(ElementCount(g)) do begin
  15.     r := ElementByIndex(g, i);
  16.     if not ElementExists(r, 'RNAM') then
  17.       continue;
  18.     AddMessage('    Fixing '+Name(r));
  19.     try
  20.       r := wbCopyElementToFile(r, userFile, false, true);
  21.       SetElementEditValues(r, 'RNAM', '');
  22.     except
  23.       on x : Exception do AddMessage('    Failed to fix record. '+x.Message);
  24.     end;  
  25.   end;
  26. end;
  27.  
  28. function Initialize: Integer;
  29. begin
  30.   { ... }
  31.   files := TStringList.Create;
  32.   masters := TStringList.Create;
  33.   ScriptProcessElements := [etFile];  // process function will only get the files the user selected
  34. end;
  35.  
  36. function Process(e: IInterface): Integer;
  37. begin
  38.   if StrEndsWith(GetFileName(e), '.dat') then exit; // skip hardcoded
  39.   files.AddObject(GetFileName(e), TObject(e));
  40.   AddMastersToList(e, masters);
  41. end;
  42.  
  43. function Finalize: Integer;
  44. var
  45.   i: integer;
  46.   f, g: IInterface;
  47. begin
  48.   if files.Count = 0 then begin
  49.     AddMessage('User selected no files!  Terminating.');
  50.     files.Free;
  51.     masters.Free;
  52.     exit;
  53.   end;
  54.   userFile := FileSelect('Select a file below:');
  55.   if not Assigned(userFile) then begin
  56.     AddMessage('Failed to create patch.');
  57.     files.Free;
  58.     masters.Free;
  59.     exit;
  60.   end;
  61.   AddMastersToFile(userFile, masters, true);
  62.   for i := 0 to Pred(files.Count) do begin
  63.     f := ObjectToElement(files.Objects[i]);
  64.     AddMessage('Processing file: '+files[i]);
  65.     // process ACTI record group
  66.     g := GroupBySignature(f, 'ACTI');
  67.     if Assigned(g) then begin
  68.       AddMessage('  Processing Group: ACTI');
  69.       FixRNAM(g);
  70.     end;
  71.     // process FLOR record group
  72.     g := GroupBySignature(f, 'FLOR');
  73.     if Assigned(g) then begin
  74.       AddMessage('  Processing Group: FLOR');
  75.       FixRNAM(g);
  76.     end;
  77.   end;
  78.  
  79.   // clean masters
  80.   CleanMasters(userFile);
  81.  
  82.   // free memory
  83.   files.Free;
  84.   masters.Free;
  85. end;
  86.  
  87. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement