Skip to content

Commit

Permalink
**IMPORTANT** Pass by reference fix!
Browse files Browse the repository at this point in the history
[mteFunctions]
**IMPORTANT NOTE!**
As of 3/2/2015 a few functions were changed to have parameters passed by
reference instead of returning a new variable of the same type.  These
functions were all added recently so it shouldn't affect your scripts
(SetChar is a little older, added January 9, 2015).  The affected
functions are listed below:
- [BatchCopyDirectory]: the batch stringlist is now passed by reference.
Is now a procedure.
- [AddMastersToList]: the lst stringlist is now passed by reference. Is
now a procedure.
- [SetChar]: the input string is now passed by reference. Is now a
procedure.

Other functions (such as ReverseString, RemoveFromEnd, and
SanitizeFileName) weren't changed for clarity regarding string
operations.

[Merge Plugins]
Adjusted to use the BatchCopyDirectory function with pass by reference.

[Re-Balancer]
Adjusted to use the AddMastersToList function with pass by reference.
  • Loading branch information
matortheeternal committed Mar 2, 2015
1 parent 95459f6 commit 071ccf6
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 19 deletions.
2 changes: 1 addition & 1 deletion trunk/Edit Scripts/AT - Re-Balancer v1.0.pas
Expand Up @@ -519,7 +519,7 @@ function Process(e: IInterface): integer;
f := GetFile(e);
if (save = 2) then
if slMasters.IndexOf(GetFileName(f)) = -1 then
slMasters := AddMastersToList(f, slMasters);
AddMastersToList(f, slMasters);

// skip items that inherit from a template
if ElementExists(e, 'TNAM - Template Armor') then
Expand Down
2 changes: 1 addition & 1 deletion trunk/Edit Scripts/Merge plugins v1.8.pas
Expand Up @@ -1215,7 +1215,7 @@ procedure CopyGeneralAssets(filename: string);
batch.Add('>> ..\logs\merge_'+fdt+'.txt robocopy "'+modPath+'" "'+RemoveFromEnd(astPath, '\')+'" /e /xf '+
StringReplace(ignore.Text, #13#10, ' ', [rfReplaceAll])+' /xd facegendata voice translations')
else if batCopy then
batch := BatchCopyDirectory(modPath, astPath, ignore, batch, debug)
BatchCopyDirectory(modPath, astPath, ignore, batch, debug)
else
CopyDirectory(modPath, astPath, ignore, debug);
end;
Expand Down
50 changes: 33 additions & 17 deletions trunk/Edit Scripts/mteFunctions.pas
@@ -1,9 +1,25 @@
{
matortheeternal's Functions
edited 2/28/2015
edited 3/2/2015
A set of useful functions for use in TES5Edit scripts.
**IMPORTANT NOTE!**
As of 3/2/2015 a few functions were changed to have parameters passed by reference
instead of returning a new variable of the same type. These functions were all
added recently so it shouldn't affect your scripts. The affected functions are
listed below:
- [BatchCopyDirectory]: the batch stringlist is now passed by reference. Is now a
procedure.
- [AddMastersToList]: the lst stringlist is now passed by reference. Is now a
procedure.
- [SetChar]: the input string is now passed by reference. Is now a procedure.
Other functions (such as ReverseString, RemoveFromEnd, and SanitizeFileName) weren't
changed for clarity regarding string operations.
This note will be removed 4/2/2015.
**LIST OF INCLUDED FUNCTIONS**
- [GetVersionString]: gets TES5Edit's version as a string.
- [ColorToInt]: gets an integer value representing a color from a TColor record.
Expand Down Expand Up @@ -497,10 +513,12 @@ procedure CopyDirectory(src, dst: string; ignore: TStringList; verbose: boolean)
Example usage:
slIgnore := TStringList.Create;
batch := TStringList.Create;
slIgnore.Add('mteFunctions.pas');
BatchCopyDirectory(ScriptsPath, 'C:\ScriptsBackup', slIgnore);
BatchCopyDirectory(ScriptsPath, 'C:\ScriptsBackup', batch, slIgnore, false);
}
function BatchCopyDirectory(src, dst: string; ignore, batch: TStringList; verbose: boolean): TStringList;
procedure BatchCopyDirectory(src, dst: string; ignore: TStringList;
var batch: TStringList; verbose: boolean);
var
i: integer;
rec: TSearchRec;
Expand Down Expand Up @@ -533,7 +551,6 @@ function BatchCopyDirectory(src, dst: string; ignore, batch: TStringList; verbos

FindClose(rec);
end;
Result := batch;
end;

{
Expand Down Expand Up @@ -593,7 +610,8 @@ function DeleteDirectory(src: string; onlyChildren: boolean): boolean;
p := RecursiveFileSearch('Skyrim.exe', GamePath, ignore, 1, false);
AddMessage(p);
}
function RecursiveFileSearch(aPath, aFileName: string; ignore: TStringList; maxDepth: integer; verbose: boolean): string;
function RecursiveFileSearch(aPath, aFileName: string; ignore: TStringList; \
maxDepth: integer; verbose: boolean): string;
var
skip: boolean;
i: integer;
Expand Down Expand Up @@ -650,7 +668,7 @@ function SanitizeFileName(fn: string): string;
for i := Length(Result) - 1 downto 0 do begin
ch := GetChar(Result, i);
if (Pos(ch, badChars) > 0) or (Ord(ch) < 32) then
Result := SetChar(Result, i, '');
SetChar(Result, i, '');
end;
end;

Expand Down Expand Up @@ -678,10 +696,10 @@ function BoolToStr(b: boolean): string;
Example usage:
s := 'backwards';
S := ReverseString(s);
s := ReverseString(s);
AddMessage(s); // 'sdrawkcab'
}
function ReverseString(s: string): string;
function ReverseString(var s: string): string;
var
i: integer;
begin
Expand Down Expand Up @@ -808,16 +826,16 @@ function CopyFromTo(s: string; p1: integer; p2: integer): string;
Example usage:
s := '1234';
s := SetChar(s, 2, 'A');
SetChar(s, 2, 'A');
AddMessage(s); //'1A34'
}
function SetChar(const s: string; n: integer; c: char): string;
procedure SetChar(var input: string; n: integer; c: char);
var
front, back: string;
begin
front := Copy(s, 1, n - 1);
back := Copy(s, n + 1, Length(s));
Result := front + c + back;
front := Copy(input, 1, n - 1);
back := Copy(input, n + 1, Length(input));
input := front + c + back;
end;

{
Expand Down Expand Up @@ -1611,9 +1629,9 @@ procedure PrintBSAContents(aContainerName);
Example usage:
slMasters := TStringList.Create;
slMasters := AddMastersToList(FileByName('Dragonborn.esm'), slMasters);
AddMastersToList(FileByName('Dragonborn.esm'), slMasters);
}
function AddMastersToList(f: IInterface; lst: TStringList): TStringList;
procedure AddMastersToList(f: IInterface; var lst: TStringList);
var
masters, master: IInterface;
i: integer;
Expand All @@ -1629,8 +1647,6 @@ function AddMastersToList(f: IInterface; lst: TStringList): TStringList;
s := geev(ElementByIndex(masters, i), 'MAST');
if (lst.IndexOf(s) = -1) then lst.Add(s);
end;

Result := lst;
end;

{
Expand Down

0 comments on commit 071ccf6

Please sign in to comment.