mirror of
				https://gitlab.com/freepascal.org/lazarus/lazarus.git
				synced 2025-10-31 04:41:42 +01:00 
			
		
		
		
	Revert r45857 #c2a0094609, "ChmHelp: close lhelp that laz started when laz is closed..." because Reinier requested it.
git-svn-id: trunk@45864 -
This commit is contained in:
		
							parent
							
								
									6ff6f62e77
								
							
						
					
					
						commit
						cace204583
					
				| @ -5,7 +5,7 @@ unit chmcontentprovider; | ||||
| {$Note Compiling lhelp with search support} | ||||
| {$DEFINE CHM_SEARCH} | ||||
| 
 | ||||
| {$IF FPC_FULLVERSION>=20400} | ||||
| {$if (fpc_version=2) and (fpc_release>4)} | ||||
| {$Note Compiling lhelp *with* binary index and toc support} | ||||
| {$DEFINE CHM_BINARY_INDEX_TOC} | ||||
| {$endif} | ||||
|  | ||||
| @ -47,6 +47,12 @@ | ||||
|               </Win32> | ||||
|             </Options> | ||||
|           </Linking> | ||||
|           <Other> | ||||
|             <CompilerMessages> | ||||
|               <UseMsgFile Value="True"/> | ||||
|             </CompilerMessages> | ||||
|             <CompilerPath Value="$(CompPath)"/> | ||||
|           </Other> | ||||
|         </CompilerOptions> | ||||
|       </Item2> | ||||
|     </BuildModes> | ||||
| @ -78,6 +84,7 @@ | ||||
|       <Unit0> | ||||
|         <Filename Value="lhelp.lpr"/> | ||||
|         <IsPartOfProject Value="True"/> | ||||
|         <UnitName Value="lhelp"/> | ||||
|       </Unit0> | ||||
|       <Unit1> | ||||
|         <Filename Value="chmdataprovider.pas"/> | ||||
| @ -87,12 +94,14 @@ | ||||
|       <Unit2> | ||||
|         <Filename Value="chmspecialparser.pas"/> | ||||
|         <IsPartOfProject Value="True"/> | ||||
|         <UnitName Value="ChmSpecialParser"/> | ||||
|       </Unit2> | ||||
|       <Unit3> | ||||
|         <Filename Value="chmpopup.pas"/> | ||||
|         <IsPartOfProject Value="True"/> | ||||
|         <ComponentName Value="HelpPopupForm"/> | ||||
|         <ResourceBaseClass Value="Form"/> | ||||
|         <UnitName Value="ChmPopup"/> | ||||
|       </Unit3> | ||||
|       <Unit4> | ||||
|         <Filename Value="lhelpcore.pas"/> | ||||
| @ -105,10 +114,12 @@ | ||||
|       <Unit5> | ||||
|         <Filename Value="lnethttpdataprovider.pas"/> | ||||
|         <IsPartOfProject Value="True"/> | ||||
|         <UnitName Value="LNetHTTPDataProvider"/> | ||||
|       </Unit5> | ||||
|       <Unit6> | ||||
|         <Filename Value="basecontentprovider.pas"/> | ||||
|         <IsPartOfProject Value="True"/> | ||||
|         <UnitName Value="BaseContentProvider"/> | ||||
|       </Unit6> | ||||
|       <Unit7> | ||||
|         <Filename Value="chmcontentprovider.pas"/> | ||||
| @ -118,6 +129,7 @@ | ||||
|       <Unit8> | ||||
|         <Filename Value="httpcontentprovider.pas"/> | ||||
|         <IsPartOfProject Value="True"/> | ||||
|         <UnitName Value="HTTPContentProvider"/> | ||||
|       </Unit8> | ||||
|     </Units> | ||||
|   </ProjectOptions> | ||||
| @ -147,5 +159,11 @@ | ||||
|         </Win32> | ||||
|       </Options> | ||||
|     </Linking> | ||||
|     <Other> | ||||
|       <CompilerMessages> | ||||
|         <UseMsgFile Value="True"/> | ||||
|       </CompilerMessages> | ||||
|       <CompilerPath Value="$(CompPath)"/> | ||||
|     </Other> | ||||
|   </CompilerOptions> | ||||
| </CONFIG> | ||||
|  | ||||
| @ -1,4 +1,4 @@ | ||||
| { Copyright (C) <2005-2014> <Andrew Haines>, Lazarus contributors lhelp.lpr | ||||
| { Copyright (C) <2005> <Andrew Haines> lhelp.lpr | ||||
| 
 | ||||
|   Lhelp CHM help viewer application | ||||
| 
 | ||||
|  | ||||
| @ -5,7 +5,7 @@ object HelpForm: THelpForm | ||||
|   Width = 758 | ||||
|   ActiveControl = Panel1 | ||||
|   Caption = 'LHelp' | ||||
|   ClientHeight = 516 | ||||
|   ClientHeight = 510 | ||||
|   ClientWidth = 758 | ||||
|   Icon.Data = { | ||||
|     7E04000000000100010010100000010020006804000016000000280000001000 | ||||
| @ -238,7 +238,7 @@ object HelpForm: THelpForm | ||||
|   end | ||||
|   object PageControl: TPageControl | ||||
|     Left = 0 | ||||
|     Height = 484 | ||||
|     Height = 478 | ||||
|     Top = 32 | ||||
|     Width = 758 | ||||
|     Align = alClient | ||||
|  | ||||
| @ -1,4 +1,4 @@ | ||||
| { Copyright (C) 2005-2014  Andrew Haines, Lazarus contributors | ||||
| { Copyright (C) 2005-2013  Andrew Haines, Lazarus contributors | ||||
| 
 | ||||
|   Main form for lhelp. Includes processing/data communication. | ||||
| 
 | ||||
| @ -27,7 +27,7 @@ unit lhelpcore; | ||||
| 
 | ||||
| {$IFDEF UNIX} | ||||
|   {$if FPC_FULLVERSION <= 20700} | ||||
|     {$DEFINE STALE_PIPE_WORKAROUND} | ||||
|        {$DEFINE STALE_PIPE_WORKAROUND} | ||||
|   {$ENDIF} | ||||
| {$ENDIF} | ||||
| 
 | ||||
| @ -150,7 +150,7 @@ var | ||||
| 
 | ||||
| const | ||||
|   INVALID_FILE_TYPE = 1; | ||||
|   VERSION_STAMP = '2013-07-31'; //used in displaying version in about form etc | ||||
|   VERSION_STAMP = '2013-07-31'; //used in displaying about form etc | ||||
| 
 | ||||
| implementation | ||||
| 
 | ||||
| @ -244,22 +244,20 @@ procedure THelpForm.FileMenuOpenURLItemClick(Sender: TObject); | ||||
| var | ||||
|   fRes: String; | ||||
|   URLSAllowed: String; | ||||
|   Protocol: TStrings; | ||||
|   Protocall: TStrings; | ||||
|   i: Integer; | ||||
| begin | ||||
|   Protocol := GetContentProviderList; | ||||
|   try | ||||
|     URLSAllowed:=''; | ||||
|     for i := 0 to Protocol.Count-1 do | ||||
|     begin | ||||
|       if i < 1 then | ||||
|         URLSAllowed := URLSAllowed + Protocol[i] | ||||
|       else | ||||
|         URLSAllowed := URLSAllowed + ', ' +Protocol[i] | ||||
|     end; | ||||
|   finally | ||||
|     Protocol.Free; | ||||
|   Protocall := GetContentProviderList; | ||||
| 
 | ||||
|   URLSAllowed:=''; | ||||
|   for i := 0 to Protocall.Count-1 do | ||||
|   begin | ||||
|     if i < 1 then | ||||
|       URLSAllowed := URLSAllowed + Protocall[i] | ||||
|     else | ||||
|       URLSAllowed := URLSAllowed + ', ' +Protocall[i] | ||||
|   end; | ||||
|   Protocall.Free; | ||||
| 
 | ||||
|   URLSAllowed := Trim(URLSALLowed); | ||||
| 
 | ||||
| @ -333,7 +331,7 @@ end; | ||||
| 
 | ||||
| procedure THelpForm.ViewMenuContentsClick(Sender: TObject); | ||||
| begin | ||||
|   // TabsControl property in TChmContentProvider | ||||
|   //TabsControl property in TChmContentProvider | ||||
|   if Assigned(ActivePage) then | ||||
|     with TChmContentProvider(ActivePage.ContentProvider) do | ||||
|     begin | ||||
| @ -354,7 +352,7 @@ begin | ||||
|   PrefFile := GetAppConfigDirUTF8(False); | ||||
|   ForceDirectoriesUTF8(PrefFile); | ||||
|   // --ipcname passes a server ID that consists of a | ||||
|   // server-dependent constant together with a process ID. | ||||
|   // a server-dependent constant together with a process ID. | ||||
|   // Strip out the process ID to get fixed config file names for one server | ||||
|   ServerPart := Copy(AIPCName, 1, length(AIPCName)-5); //strip out PID | ||||
|   PrefFile:=Format('%slhelp-%s.conf',[IncludeTrailingPathDelimiter(PrefFile), ServerPart]); | ||||
| @ -477,7 +475,6 @@ begin | ||||
|     Stream.Position := 0; | ||||
|     FillByte(FileReq{%H-},SizeOf(FileReq),0); | ||||
|     Stream.Read(FileReq, SizeOf(FileReq)); | ||||
|     Res := Ord(srError); //fail by default | ||||
|     case FileReq.RequestType of | ||||
|       rtFile    : begin | ||||
|                     Url := 'file://'+FileReq.FileName; | ||||
| @ -523,7 +520,7 @@ begin | ||||
|                       end; | ||||
|                       mrVersion: | ||||
|                       begin | ||||
|                         // Protocol version encoded in the filename | ||||
|                         //Protocol version encoded in the filename | ||||
|                         // Verify what we support | ||||
|                         if strtointdef(FileReq.FileName,0)=strtointdef(PROTOCOL_VERSION,0) then | ||||
|                           Res := ord(srSuccess) | ||||
| @ -539,14 +536,8 @@ begin | ||||
|       AddRecentFile(Url); | ||||
|     SendResponse(Res); | ||||
|     if MustClose then | ||||
|     begin | ||||
|       // Wait some time for the response message to go out before shutting down | ||||
|       Application.ProcessMessages; | ||||
|       Sleep(10); | ||||
|       Application.Terminate; | ||||
|     end; | ||||
| 
 | ||||
|     // We received mrShow: | ||||
|     if (MustClose=false) and (fHide=false) then | ||||
|     begin | ||||
|       Self.SendToBack; | ||||
| @ -684,20 +675,20 @@ var | ||||
|  fPage: TContentTab = nil; | ||||
|  I: Integer; | ||||
| begin | ||||
|  Result := Ord(srInvalidURL); | ||||
|  Result := Ord(srUnknown); | ||||
|  fURLPrefix := GetURLPrefix; | ||||
|  fContentProvider := GetContentProvider(fURLPrefix); | ||||
|   | ||||
|  if fContentProvider = nil then begin | ||||
|    ShowError('Cannot handle this type of content. "' + fURLPrefix + '" for url:'+LineEnding+AURL); | ||||
|    Result := Ord(srInvalidURL); | ||||
|    Result := Ord(srInvalidFile); | ||||
|    Exit; | ||||
|  end; | ||||
|  fRealContentProvider := fContentProvider.GetProperContentProvider(AURL); | ||||
|   | ||||
|  if fRealContentProvider = nil then begin | ||||
|    ShowError('Cannot handle this type of subcontent. "' + fURLPrefix + '" for url:'+LineEnding+AURL); | ||||
|    Result := Ord(srInvalidURL); | ||||
|    Result := Ord(srInvalidFile); | ||||
|    Exit; | ||||
|  end; | ||||
| 
 | ||||
| @ -726,6 +717,7 @@ begin | ||||
|    fPage.ContentProvider.LoadPreferences(fConfig); | ||||
|  end; | ||||
| 
 | ||||
|   | ||||
|  if fPage.ContentProvider.LoadURL(AURL, AContext) then | ||||
|  begin | ||||
|    PageControl.ActivePage := fPage; | ||||
| @ -733,7 +725,7 @@ begin | ||||
|    Result := Ord(srSuccess); | ||||
|  end | ||||
|  else | ||||
|    Result := Ord(srInvalidURL); | ||||
|    Result := Ord(srInvalidFile); | ||||
| 
 | ||||
|  if not fHide then | ||||
|    ShowOnTop; | ||||
|  | ||||
| @ -12,7 +12,7 @@ Currently, the only help viewer that supports this protocol is the lhelp CHM hel | ||||
| 
 | ||||
| {$IFDEF UNIX} | ||||
|   {$if FPC_FULLVERSION <= 20700} | ||||
|     {$DEFINE STALE_PIPE_WORKAROUND} | ||||
|        {$DEFINE STALE_PIPE_WORKAROUND} | ||||
|   {$ENDIF} | ||||
| {$ENDIF} | ||||
| 
 | ||||
| @ -25,12 +25,7 @@ uses | ||||
|   Classes, SysUtils, FileUtil, LazLogger, SimpleIPC, process, UTF8Process; | ||||
| 
 | ||||
| const | ||||
|   PROTOCOL_VERSION='2'; //IDE<>LHelp communication protocol version. Please update when breaking compatibility | ||||
|   // Version 1: original version | ||||
|   // Version 2: | ||||
|   // - support for Proposed extensions in bug 24743: | ||||
|   // - openurl: if applicable return error instead of unknown | ||||
|   // - openurl: if applicable return invalid url instead of invalid file for openurl | ||||
|   PROTOCOL_VERSION='1'; //IDE<>LHelp communication protocol version. Please update when breaking compatibility | ||||
| type | ||||
|   TRequestType = (rtFile, rtUrl, rtContext, rtMisc {window handling etc}); | ||||
|   TMiscRequests = (mrShow, mrVersion, mrClose); | ||||
| @ -118,9 +113,12 @@ end; | ||||
| 
 | ||||
| function TLHelpConnection.SendMessage(Stream: TStream): TLHelpResponse; | ||||
| begin | ||||
|   Result := srNoAnswer; | ||||
|   fServerOut.SendMessage(mtUnknown, Stream); | ||||
|   Result := WaitForMsgResponse; | ||||
|   //try | ||||
|     fServerOut.SendMessage(mtUnknown, Stream); | ||||
|     Result := WaitForMsgResponse; | ||||
|   //except | ||||
|   //  on EIPCError do Result := srNoAnswer; | ||||
|   //end; | ||||
| end; | ||||
| 
 | ||||
| constructor TLHelpConnection.Create; | ||||
| @ -227,9 +225,6 @@ begin | ||||
|   if fServerOut.ServerRunning then begin | ||||
|     fServerOut.Active := True; | ||||
|     Result := True; | ||||
|   end | ||||
|   else begin | ||||
|     debugln('Could not get lhelp running with command '+Cmd); | ||||
|   end; | ||||
| end; | ||||
| 
 | ||||
| @ -243,17 +238,8 @@ begin | ||||
|     UrlRequest.FileRequest.FileName := HelpFileName+#0; | ||||
|     UrlRequest.FileRequest.RequestType := rtURL; | ||||
|     UrlRequest.Url := Url+#0; | ||||
|     Result:=srNoAnswer; | ||||
|     try | ||||
|       Stream.Write(UrlRequest,SizeOf(UrlRequest)); | ||||
|       Result := SendMessage(Stream); | ||||
|     except | ||||
|       // Catch stream read errors etc | ||||
|       on E: Exception do | ||||
|       begin | ||||
|         debugln('Help connection: error '+E.Message+' running UrlRequest command'); | ||||
|       end; | ||||
|     end; | ||||
|     Stream.Write(UrlRequest,SizeOf(UrlRequest)); | ||||
|     Result := SendMessage(Stream); | ||||
|   finally | ||||
|     Stream.Free; | ||||
|   end; | ||||
| @ -266,22 +252,12 @@ var | ||||
|   Stream: TMemoryStream; | ||||
| begin | ||||
|   Stream := TMemoryStream.Create; | ||||
|   Result := srNoAnswer; | ||||
|   try | ||||
|     ContextRequest.FileRequest.FileName := HelpFileName+#0; | ||||
|     ContextRequest.FileRequest.RequestType := rtContext; | ||||
|     ContextRequest.HelpContext := Context; | ||||
|     Result := srNoAnswer; | ||||
|     try | ||||
|       Stream.Write(ContextRequest, SizeOf(ContextRequest)); | ||||
|       Result := SendMessage(Stream); | ||||
|     except | ||||
|       // Catch stream read errors etc | ||||
|       on E: Exception do | ||||
|       begin | ||||
|         debugln('Help connection: error '+E.Message+' running ContextRequest command'); | ||||
|       end; | ||||
|     end; | ||||
|     Stream.Write(ContextRequest, SizeOf(ContextRequest)); | ||||
|     Result := SendMessage(Stream); | ||||
|   finally | ||||
|     Stream.Free; | ||||
|   end; | ||||
| @ -296,17 +272,8 @@ begin | ||||
|   try | ||||
|     FileRequest.RequestType := rtFile; | ||||
|     FileRequest.FileName := HelpFileName+#0; | ||||
|     Result := srNoAnswer; | ||||
|     try | ||||
|       Stream.Write(FileRequest, SizeOf(FileRequest)); | ||||
|       Result := SendMessage(Stream); | ||||
|     except | ||||
|       // Catch stream read errors etc | ||||
|       on E: Exception do | ||||
|       begin | ||||
|         debugln('Help connection: error '+E.Message+' running FileRequest command'); | ||||
|       end; | ||||
|     end; | ||||
|     Stream.Write(FileRequest, SizeOf(FileRequest)); | ||||
|     Result := SendMessage(Stream); | ||||
|   finally | ||||
|     Stream.Free; | ||||
|   end; | ||||
| @ -320,27 +287,17 @@ begin | ||||
|   Stream := TMemoryStream.Create; | ||||
|   try | ||||
|     MiscRequest.FileRequest.RequestType := rtMisc; | ||||
|     MiscRequest.FileRequest.FileName := ''+#0; | ||||
|     MiscRequest.FileRequest.FileName := ''+#0; //i | ||||
|     //CommandID is ord(TMiscRequests) | ||||
|     MiscRequest.RequestID:=CommandID; | ||||
|     case CommandID of | ||||
|       mrClose: ; //no arguments required | ||||
|       mrShow: ;  //no arguments required | ||||
|       mrClose: ; //do nothing | ||||
|       mrShow: ;  //do nothing | ||||
|       mrVersion: | ||||
|         MiscRequest.FileRequest.FileName := PROTOCOL_VERSION+#0; | ||||
|     end; | ||||
|     try | ||||
|       Stream.Write(MiscRequest, SizeOf(MiscRequest)); | ||||
|       Result := SendMessage(Stream); | ||||
|     except | ||||
|       // Catch stream read errors etc | ||||
|       on E: Exception do | ||||
|       begin | ||||
|         // When closing, the viewer may not respond in time, which is expected. | ||||
|         if CommandID<>mrClose then | ||||
|           debugln('Help connection: error '+E.Message+' running MiscRequest command'); | ||||
|       end; | ||||
|     end; | ||||
|     Stream.Write(MiscRequest, SizeOf(MiscRequest)); | ||||
|     Result := SendMessage(Stream); | ||||
|   finally | ||||
|     Stream.Free; | ||||
|   end; | ||||
|  | ||||
| @ -1,4 +1,4 @@ | ||||
| { Copyright (C) <2005-2014> <Andrew Haines>, Lazarus contributors | ||||
| { Copyright (C) <2005-2013> <Andrew Haines>, Lazarus contributors | ||||
| 
 | ||||
|   lazchmhelp.pas | ||||
| 
 | ||||
| @ -437,16 +437,6 @@ end; | ||||
| 
 | ||||
| destructor TChmHelpViewer.Destroy; | ||||
| begin | ||||
|   // Try to close lhelp if we had opened it before; ignore response | ||||
|   try | ||||
|     fHelpConnection.RunMiscCommand(LHelpControl.mrClose); | ||||
|   except | ||||
|     // ignore errors; let user close it himself | ||||
|     on E: Exception do begin | ||||
|       debugln('TChmHelpViewer.Destroy: exception '+E.Message+' when trying to send mrClose on viewer'); | ||||
|     end; | ||||
|   end; | ||||
| 
 | ||||
|   fHelpConnection.Free; | ||||
|   inherited Destroy; | ||||
| end; | ||||
| @ -491,7 +481,9 @@ begin | ||||
|     fHelpConnection.StartHelpServer(HelpLabel, HelpExeFileName, true); | ||||
|     Response:=fHelpConnection.RunMiscCommand(mrVersion); | ||||
|     if Response<>srSuccess then | ||||
|       debugln('Help viewer does not support our protocol version ('+PROTOCOL_VERSION +'). Response was: ord: '+inttostr(ord(Response))) | ||||
|     begin | ||||
|       debugln('Help viewer does not support our protocol version.'); | ||||
|     end | ||||
|     else | ||||
|     begin | ||||
|       // Open all chm files after it has started, while still hidden | ||||
| @ -499,7 +491,9 @@ begin | ||||
|       // Instruct viewer to show its GUI | ||||
|       Response:=fHelpConnection.RunMiscCommand(mrShow); | ||||
|       if Response<>srSuccess then | ||||
|         debugln('Help viewer gave error response to mrShow command. Response was: ord: '+inttostr(ord(Response))); | ||||
|       begin | ||||
|         debugln('Help viewer failed to respond to mrShow command.'); | ||||
|       end; | ||||
|     end; | ||||
|   end; | ||||
| end; | ||||
| @ -540,7 +534,7 @@ begin | ||||
|   begin | ||||
|     Result := shrDatabaseNotFound; | ||||
|     ErrMsg := FileName +' not found. Please put the chm help files in '+ LineEnding | ||||
|                        +SearchPath + LineEnding | ||||
|                        +SearchPath+  LineEnding | ||||
|                        +' or set the path to lcl.chm rtl.chm fcl.chm with "HelpFilesPath" in ' | ||||
|                        +' Environment Options -> Help -> Help Options ->'+LineEnding | ||||
|                        +' under HelpViewers - CHMHelpViewer'; | ||||
| @ -562,7 +556,7 @@ begin | ||||
|     if Trim(fHelpExeParams) = '' then | ||||
|     begin | ||||
|       Result := shrViewerError; | ||||
|       ErrMsg := 'If you do not use "lhelp" as viewer you have to set up ' | ||||
|       ErrMsg := 'If you do not use "lhelp" as viewer you have to setup ' | ||||
|               + 'HelpExeParams correctly in' + sLineBreak | ||||
|               + 'Tools -> Options -> Help -> Help Options -> ' | ||||
|               + 'under HelpViewers - CHM Help Viewer' + sLineBreak | ||||
| @ -606,19 +600,7 @@ begin | ||||
|   case Res of | ||||
|     srSuccess: Result := shrSuccess; | ||||
|     srNoAnswer: Result := shrSuccess; | ||||
|     srInvalidContext: begin | ||||
|       Result := shrNone; | ||||
|       ErrMsg := 'Invalid context showing '+URL; | ||||
|     end; | ||||
|     srInvalidFile: begin | ||||
|       Result := shrNone; | ||||
|       ErrMsg := 'Invalid file showing '+URL; | ||||
|     end; | ||||
|     srInvalidURL: begin | ||||
|       Result := shrNone; | ||||
|       ErrMsg := 'Invalid URL showing '+URL; | ||||
|     end; | ||||
|   else //srUnknown, srError | ||||
|   else | ||||
|     Result := shrNone; | ||||
|     ErrMsg := 'Unknown error showing '+URL; | ||||
|   end; | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 juha
						juha