Results 1 to 10 of 43

Thread: Luna Game Pascal

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #21
    Hi, yea sure. Here is the handler for the test project i'm working this evening. I just figured out how to prevent the new browser window popup Problem. You have to cancel it and then do a new navigation to the URL. The problem now is how to keep the link content within the frame. When you click on a link, the URL will be something like this: lgp://index.html/and.html, this will display and.html within the frame contents of index.html. Gosh, I can't rem now how I made this work. I don't have the old project code version where I got all these little PITA things sorted out. I rem now running up against each one and sorting them out one by one. Once I can get the frame thing sorted out, then I can start trying to read from zip.


    Code:
    procedure TForm2.MyProtocolHandler(aURL: string; var aMIMEType: string;
      const aPostMIMEType: string; const aPostData: array of byte;
      aMemoryStream: TCustomMemoryStream); // TProtocolCallback
    var
      fn: string;
    
    
      procedure WriteOutString(const aStr: string);
      var
        utf8Out: UTF8String;
      begin
        utf8Out := UTF8Encode(aStr);
        aMemoryStream.WriteBuffer(Pointer(utf8Out)^,
          Length(utf8Out) * SizeOf(AnsiChar));
      end;
    
    
      procedure WriteOutFile(const aFilename: string);
      var
        ms: TMemoryStream;
      begin
        ms := TMemoryStream.Create;
        try
          ms.LoadFromFile(aFilename);
          ms.SaveToStream(aMemoryStream);
        finally
          ms.Free;
        end;
      end;
    
    
      procedure WriteOutTextFile(const aFilename: string);
      var
        ms: TStringList;
      begin
        ms := TStringList.Create;
        try
          ms.LoadFromFile(aFilename);
          WriteOutString(ms.Text);
        finally
          ms.Free;
        end;
      end;
    
    
      function FindMimeType(const url: WideString): string;
      var
        mimetype: PWideChar;
      begin
        mimetype := nil;
        FindMimeFromData(nil, PWideChar(URL), nil, 0, nil, 0, mimetype, 0);
        Result := mimetype;
      end;
    
    
    begin
      // remove any slashes from the front
      while (aURL <> '') and (aURL[1] = '/') do
        Delete(aURL, 1, 1);
      // remove any slashes from the back
      while (aURL <> '') and (aURL[Length(aURL)] = '/') do
        Delete(aURL, Length(aURL), 1);
    
    
      if aURL.Contains('index.html?') then
        aURL := aURL.Replace('index.html?', '')
      else
        aURL := aURL.Replace('index.html/', '');
      if aURL.IsEmpty then
        aURL := 'index.html';
    
    
      // get mime type
      aMIMEType := FindMimeType(aURL);
    
    
      fn :=  TPath.Combine(TPath.GetDirectoryName(ParamStr(0)), 'HTML\' + aURL);
      WriteOutFile(fn);
    end;
    
    
    procedure TForm2.WebBrowser1NewWindow3(ASender: TObject; var ppDisp: IDispatch;
      var Cancel: WordBool; dwFlags: Cardinal; const bstrUrlContext,
      bstrUrl: WideString);
    begin
      Cancel := True;
      WebBrowser1.Navigate(bstrUrl);
    end;
    Last edited by drezgames; 22-06-2017 at 12:50 AM.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •