mirror of
				https://gitlab.com/freepascal.org/lazarus/lazarus.git
				synced 2025-11-04 13:49:34 +01:00 
			
		
		
		
	printe4lazarus: raise exception, if tmp file cannot be created
git-svn-id: trunk@50173 -
This commit is contained in:
		
							parent
							
								
									7cdf5a2bb6
								
							
						
					
					
						commit
						a46caecea3
					
				@ -1509,6 +1509,13 @@ begin
 | 
				
			|||||||
  cairo_ps_surface_dsc_begin_setup(sf);
 | 
					  cairo_ps_surface_dsc_begin_setup(sf);
 | 
				
			||||||
  cairo_ps_surface_dsc_comment(sf, PChar(s));
 | 
					  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
 | 
					  //rotate and move
 | 
				
			||||||
  case Orientation of
 | 
					  case Orientation of
 | 
				
			||||||
    poLandscape: begin
 | 
					    poLandscape: begin
 | 
				
			||||||
 | 
				
			|||||||
@ -473,6 +473,8 @@ var
 | 
				
			|||||||
  aPrinterName : string;
 | 
					  aPrinterName : string;
 | 
				
			||||||
begin
 | 
					begin
 | 
				
			||||||
  Result:=-1;
 | 
					  Result:=-1;
 | 
				
			||||||
 | 
					  if aFileName='' then
 | 
				
			||||||
 | 
					    raise Exception.Create('TCUPSPrinter.PrintFile missing Filename');
 | 
				
			||||||
  if not CUPSLibInstalled then Exit;
 | 
					  if not CUPSLibInstalled then Exit;
 | 
				
			||||||
  aFileName:=ExpandFileNameUTF8(aFileName);
 | 
					  aFileName:=ExpandFileNameUTF8(aFileName);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -846,6 +848,7 @@ end;
 | 
				
			|||||||
procedure TCUPSPrinter.DoBeginDoc;
 | 
					procedure TCUPSPrinter.DoBeginDoc;
 | 
				
			||||||
var
 | 
					var
 | 
				
			||||||
  NewPath: String;
 | 
					  NewPath: String;
 | 
				
			||||||
 | 
					  fs: TFileStream;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  function TryTemporaryPath(const Path: string): Boolean;
 | 
					  function TryTemporaryPath(const Path: string): Boolean;
 | 
				
			||||||
  var
 | 
					  var
 | 
				
			||||||
@ -879,6 +882,15 @@ begin
 | 
				
			|||||||
    FOutputFileName := FOutputFileName + '.ps';
 | 
					    FOutputFileName := FOutputFileName + '.ps';
 | 
				
			||||||
    TFilePrinterCanvas(Canvas).OutputFileName := FOutputFileName;
 | 
					    TFilePrinterCanvas(Canvas).OutputFileName := FOutputFileName;
 | 
				
			||||||
  end;
 | 
					  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;
 | 
					end;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//If not aborted, send PostScript file to printer.
 | 
					//If not aborted, send PostScript file to printer.
 | 
				
			||||||
@ -902,9 +914,11 @@ begin
 | 
				
			|||||||
    end;
 | 
					    end;
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
  end else
 | 
					  end else
 | 
				
			||||||
    TFilePrinterCanvas(Canvas).OutPutFileName:='';
 | 
					    TFilePrinterCanvas(Canvas).OutputFileName:='';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if not aAborted and FileExistsUTF8(FOutputFileName) then begin
 | 
					  if not aAborted then begin
 | 
				
			||||||
 | 
					    if not FileExistsUTF8(FOutputFileName) then
 | 
				
			||||||
 | 
					      raise Exception.Create('Unable to write to "'+FOutputFileName+'"');
 | 
				
			||||||
    {$IFDEF LogPrintoutFile}
 | 
					    {$IFDEF LogPrintoutFile}
 | 
				
			||||||
    CopyFile(FOutputFileName, 'printjob'+ExtractFileExt(FOutputFileName));
 | 
					    CopyFile(FOutputFileName, 'printjob'+ExtractFileExt(FOutputFileName));
 | 
				
			||||||
    {$ENDIF}
 | 
					    {$ENDIF}
 | 
				
			||||||
@ -916,7 +930,6 @@ begin
 | 
				
			|||||||
    {$ENDIF}
 | 
					    {$ENDIF}
 | 
				
			||||||
    DeleteFileUTF8(FOutputFilename);
 | 
					    DeleteFileUTF8(FOutputFilename);
 | 
				
			||||||
  end;
 | 
					  end;
 | 
				
			||||||
 | 
					 | 
				
			||||||
end;
 | 
					end;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
procedure TCUPSPrinter.DoResetPrintersList;
 | 
					procedure TCUPSPrinter.DoResetPrintersList;
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user