Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit UserScript;
- uses mteFunctions;
- var
- files, masters: TStringList;
- userFile: IInterface;
- procedure FixRNAM(g: IInterface);
- var
- i: integer;
- r: IInterface;
- begin
- for i := 0 to Pred(ElementCount(g)) do begin
- r := ElementByIndex(g, i);
- if not ElementExists(r, 'RNAM') then
- continue;
- AddMessage(' Fixing '+Name(r));
- try
- r := wbCopyElementToFile(r, userFile, false, true);
- SetElementEditValues(r, 'RNAM', '');
- except
- on x : Exception do AddMessage(' Failed to fix record. '+x.Message);
- end;
- end;
- end;
- function Initialize: Integer;
- begin
- { ... }
- files := TStringList.Create;
- masters := TStringList.Create;
- ScriptProcessElements := [etFile]; // process function will only get the files the user selected
- end;
- function Process(e: IInterface): Integer;
- begin
- if StrEndsWith(GetFileName(e), '.dat') then exit; // skip hardcoded
- files.AddObject(GetFileName(e), TObject(e));
- AddMastersToList(e, masters);
- end;
- function Finalize: Integer;
- var
- i: integer;
- f, g: IInterface;
- begin
- if files.Count = 0 then begin
- AddMessage('User selected no files! Terminating.');
- files.Free;
- masters.Free;
- exit;
- end;
- userFile := FileSelect('Select a file below:');
- if not Assigned(userFile) then begin
- AddMessage('Failed to create patch.');
- files.Free;
- masters.Free;
- exit;
- end;
- AddMastersToFile(userFile, masters, true);
- for i := 0 to Pred(files.Count) do begin
- f := ObjectToElement(files.Objects[i]);
- AddMessage('Processing file: '+files[i]);
- // process ACTI record group
- g := GroupBySignature(f, 'ACTI');
- if Assigned(g) then begin
- AddMessage(' Processing Group: ACTI');
- FixRNAM(g);
- end;
- // process FLOR record group
- g := GroupBySignature(f, 'FLOR');
- if Assigned(g) then begin
- AddMessage(' Processing Group: FLOR');
- FixRNAM(g);
- end;
- end;
- // clean masters
- CleanMasters(userFile);
- // free memory
- files.Free;
- masters.Free;
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement