Skip to content

Commit

Permalink
Ensure file loads always done in readOnly mode
Browse files Browse the repository at this point in the history
  • Loading branch information
neurolabusc committed Mar 7, 2018
1 parent 0705f78 commit bfaa260
Show file tree
Hide file tree
Showing 16 changed files with 163 additions and 77 deletions.
3 changes: 3 additions & 0 deletions cifti.inc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ begin
result := false;
if not fileexists(fnm) then exit;
if fsize(fnm) < 540 then exit;
FileMode := fmOpenRead;
AssignFile(f, fnm);
FileMode := fmOpenRead; //Set file access to read only
Reset(f, 1);
Expand Down Expand Up @@ -150,6 +151,7 @@ begin
if not fileexists(fnm) then exit;
fsz := FSize(fnm);
if (fsz < (sizeof(hdr)+132)) then exit;
FileMode := fmOpenRead;
AssignFile(f, fnm);
FileMode := fmOpenRead; //Set file access to read only
Reset(f, 1);
Expand All @@ -172,6 +174,7 @@ begin
end;
//next: read XML
setlength(xmlStr, xmlLen);
FileMode := fmOpenRead;
AssignFile(f, fnm);
FileMode := fmOpenRead; //Set file access to read only
Reset(f, 1);
Expand Down
4 changes: 4 additions & 0 deletions commandsu.pas
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,7 @@ procedure EDGECREATE(filename: string; const mtx: array of single);
fnm := filename;
fnm := changeFileExt(fnm, '.edge');
fnm := DefaultToHomeDir(fnm);
FileMode := fmOpenWrite;
AssignFile(f, fnm);
ReWrite(f);
WriteLn(f, '# created with Surf Ice EDGECREATE command');
Expand All @@ -623,6 +624,7 @@ procedure EDGECREATE(filename: string; const mtx: array of single);
end;
end;
CloseFile(f);
FileMode := fmOpenRead;
if not GLForm1.OpenEdge(fnm) then
ScriptForm.Memo2.Lines.Add('EDGECREATE Unable to load edge file named "'+fnm+'" (use nodecreate or nodeload first) ')
else
Expand Down Expand Up @@ -680,12 +682,14 @@ procedure NODECREATE(filename: string; const x,y,z,clr,radius: array of single);
fnm := filename;
fnm := changeFileExt(fnm, '.node');
fnm := DefaultToHomeDir(fnm);
FileMode := fmOpenWrite;
AssignFile(f, fnm);
ReWrite(f);
WriteLn(f, '# created with Surf Ice NODECREATE command');
for i := 0 to (n-1) do
WriteLn(f, format('%g %g %g %g %g', [x[i], y[i], z[i], c[i], r[i]]));
CloseFile(f);
FileMode := fmOpenRead;
if not GLForm1.OpenNode(fnm) then
ScriptForm.Memo2.Lines.Add('NODECREATE Unable to load node named "'+fnm+'"')
else
Expand Down
1 change: 1 addition & 0 deletions curv.pas
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ procedure SaveCurv(fnm: string; k: TFloats; num_f: integer);
num_vS := num_v;
num_fS := num_f;
ValsPerVertex := 1;
FileMode := fmOpenRead;
AssignFile(f, fnm);
FileMode := fmOpenWrite;
Rewrite(f,1);
Expand Down
2 changes: 2 additions & 0 deletions entrail.lpr
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ function endtrack (var p: TTrackingPrefs): boolean;
if i < 1 then goto 666;
if length(p.outName) > 0 then begin
showmsg(format(' Creating output %s', [p.outName]));
FileMode := fmOpenWrite;
AssignFile(txtFile, p.outName);
ReWrite(txtFile);
WriteLn(txtFile, kVers);
Expand All @@ -200,6 +201,7 @@ function endtrack (var p: TTrackingPrefs): boolean;
end;
if length(p.outName) > 0 then
CloseFile(txtFile);
FileMode := fmOpenRead;
showmsg(format('Fiber tracking completed (%dms)', [ MilliSecondsBetween(Now, startTime)]));
result := true;
666:
Expand Down
7 changes: 5 additions & 2 deletions glext2.pas
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ interface

var
glProgramParameteriEXT: procedure(_program: GLuint; pname: GLenum; value: GLint); extdecl;

procedure SetglProgramParameteriEXT;
implementation

{$IFDEF Windows}
Expand All @@ -30,6 +30,9 @@ function wglGetProcAddress(proc: PChar): Pointer;
end;
{$ENDIF}

initialization
procedure SetglProgramParameteriEXT;
begin
glProgramParameteriEXT := wglGetProcAddress('glProgramParameteriEXT');
end;

end.
4 changes: 4 additions & 0 deletions glmtext.pas
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,12 @@ procedure SaveMetricsBinary(fnm: string; fnt: TMetrics);
f : File of TMetrics;
begin
{$IFDEF ENDIAN_BIG}to do: byte-swap to little-endian {$ENDIF}
FileMode := fmOpenWrite;
AssignFile(f, changefileext(fnm,'.fnb'));
ReWrite(f, 1);
Write(f, fnt);
CloseFile(f);
FileMode := fmOpenRead;
end;

function LoadMetricsBinary(fnm: string; out fnt: TMetrics): boolean;
Expand All @@ -126,6 +128,7 @@ function LoadMetricsBinary(fnm: string; out fnt: TMetrics): boolean;
result := false;
fnm := changefileext(fnm,'.fnb');
if not fileexists(fnm) then exit;
FileMode := fmOpenRead;
AssignFile(f, fnm);
Reset(f, 1);
Read(f, fnt);
Expand Down Expand Up @@ -194,6 +197,7 @@ function GetFntVal(key: string): single;
showmessage('Unable to find '+fnm);
exit;
end;
FileMode := fmOpenRead;
AssignFile(f, fnm);
Reset(f);
ReadLn(f, str);
Expand Down
3 changes: 2 additions & 1 deletion mainunit.pas
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,7 @@ function isVtkMesh (filename: string): boolean; //vtk files can be tracks (" LIN
begin
result := false;
if not fileexistsF(filename) then exit;
FileMode := fmOpenRead;
AssignFile(f, FileName);
Reset(f,1);
FileMode := fmOpenRead;
Expand All @@ -756,7 +757,6 @@ function isVtkMesh (filename: string): boolean; //vtk files can be tracks (" LIN
CloseFile(f);
if (pos('POLYGONS ', Str) > 0) then result := true; //faces
if (pos('TRIANGLE_STRIPS ', Str) > 0) then result := true; //faces

end;

function isGiiMesh (filename: string): boolean;
Expand Down Expand Up @@ -3693,6 +3693,7 @@ procedure TGLForm1.FormCreate(Sender: TObject);
c: char;
forceReset: boolean = false;
begin
FileMode := fmOpenRead; //in case files set with read-only permissions
//check if user includes parameters
gPrefs.initScript := ''; //e.g. 'c:\dir\script.gls'
i := 1;
Expand Down
Loading

0 comments on commit bfaa260

Please sign in to comment.