printe4lazarus: raise exception, if tmp file cannot be created

git-svn-id: trunk@50173 -
This commit is contained in:
mattias 2015-10-26 10:12:31 +00:00
parent 7cdf5a2bb6
commit a46caecea3
2 changed files with 28 additions and 8 deletions

View File

@ -1509,6 +1509,13 @@ begin
cairo_ps_surface_dsc_begin_setup(sf);
cairo_ps_surface_dsc_comment(sf, PChar(s));
if (fStream=nil) and not FileExists(FOutputFileName) then
begin
DebugLn('Error: unable to write cairo ps to "'+FOutputFileName+'"');
DestroyCairoHandle;
exit(0);
end;
//rotate and move
case Orientation of
poLandscape: begin

View File

@ -473,18 +473,20 @@ var
aPrinterName : string;
begin
Result:=-1;
if aFileName='' then
raise Exception.Create('TCUPSPrinter.PrintFile missing Filename');
if not CUPSLibInstalled then Exit;
aFileName:=ExpandFileNameUTF8(aFileName);
if (Printers.Count>0) then
begin
if not Assigned(fcupsOptions) then
SetOptionsOfPrinter;
SetOptionsOfPrinter;
if Assigned(fcupsPrinter) then
aPrinterName:=fcupsPrinter^.Name
aPrinterName:=fcupsPrinter^.Name
else
aPrinterName:='';
aPrinterName:='';
{$IFDEF DebugCUPS}
DebugOptions;
@ -846,6 +848,7 @@ end;
procedure TCUPSPrinter.DoBeginDoc;
var
NewPath: String;
fs: TFileStream;
function TryTemporaryPath(const Path: string): Boolean;
var
@ -872,13 +875,22 @@ begin
FOutputFileName := AppendPathDelim(NewPath)+
'OutPrinter_'+FormatDateTime('yyyymmmddd-hhnnss',Now);
if RawMode then
FOutputFileName := FOutputFileName + '.raw'
else begin
FOutputFileName := FOutputFileName + '.ps';
TFilePrinterCanvas(Canvas).OutputFileName := FOutputFileName;
end;
// test writing, on error this raises exception showing the user the filename
fs:=TFileStream.Create(FOutputFilename,fmCreate);
try
fs.Write(FOutputFilename[1],1);
finally
fs.free;
end;
DeleteFileUTF8(FOutputFilename);
end;
//If not aborted, send PostScript file to printer.
@ -902,9 +914,11 @@ begin
end;
end else
TFilePrinterCanvas(Canvas).OutPutFileName:='';
if not aAborted and FileExistsUTF8(FOutputFileName) then begin
TFilePrinterCanvas(Canvas).OutputFileName:='';
if not aAborted then begin
if not FileExistsUTF8(FOutputFileName) then
raise Exception.Create('Unable to write to "'+FOutputFileName+'"');
{$IFDEF LogPrintoutFile}
CopyFile(FOutputFileName, 'printjob'+ExtractFileExt(FOutputFileName));
{$ENDIF}
@ -916,7 +930,6 @@ begin
{$ENDIF}
DeleteFileUTF8(FOutputFilename);
end;
end;
procedure TCUPSPrinter.DoResetPrintersList;