salvadordf / CEF4Delphi

CEF4Delphi is an open source project to embed Chromium-based browsers in applications made with Delphi or Lazarus/FPC for Windows, Linux and MacOS.
https://www.briskbard.com/forum/
Other
1.22k stars 373 forks source link

Generate link for download libs? #166

Closed ange007 closed 5 years ago

ange007 commented 5 years ago

Is it possible to somehow generate a link to download libraries? To be able to update libraries directly from the program without having to download them yourself, and then distribute them with the program?

salvadordf commented 5 years ago

CEF3 evolves very rapidly and the wrappers need to adapt to the new features. Each CEF4Delphi version uses a very specific CEF3 binaries package because the new features may cause crashes if you try to use them before CEF4Delphi has been modified to support them.

That's why CEF4Delphi checks the binaries while initializing CEF3.

If you want to create a separate download for the binaries then your app will need to use a separate EXE for the subprocesses and the CEF3 initialization will have to be done after the user has downloaded and decompressed the binaries.

The CEF3 binaries available for download should match the CEF3 version supported by the CEF4Delphi version used in your application.

I would personally use my own website to host those binaries with a custom name instead of using the Spotify service.

Please, use our forum for more questions : https://www.briskbard.com/forum/

ange007 commented 5 years ago

I would personally use my own website to host those binaries with a custom name instead of using the Spotify service.

I would like to avoid this, so that it would not be necessary to transfer the library updates from Spotify to self server. And just read the version of CEF in the application and download the right one (which is important for supporting old versions as well).

salvadordf commented 5 years ago

The CEF3 binaries package name is generated automatically by Spotify with the CEF version, branch, build, commit id and target platform.

If I remember correctly, the details for the name generation is somewhere in the CEF3 wiki page.

For example : "cef_binary_3.3626.1894.g90eb8cc_windows32.tar.bz2" This name was generated like this : "cefbinary" + cef version + "." + cef branch + "." + build + ".g" + commit id + "_" + target platform + ".tar.bz2"

CEF4Delphi has some constants in uCEFApplication.pas with this information :

... but the commit id is not used by CEF4Delphi and it's not available.

ange007 commented 5 years ago

The link is taken from here - right? http://opensource.spotify.com/cefbuilds/index.html

In this case, one request and regular expressions will do its job. Thanks.

salvadordf commented 5 years ago

Yes but I don't work for Spotify and I don't know if they allow that.

To be honest, I haven't read their terms and conditions of use...

Please, read this : https://www.spotify.com/us/legal/end-user-agreement/

ange007 commented 4 years ago

Maybe someone will need

class function TChromiumUtils.GetLibURL: string;
var
  target, linkPattern, mainLink, pageResponse, fileName: string;
begin
  Result := '';
  mainLink := 'http://opensource.spotify.com/cefbuilds/';

  {System}
  target :=
  {$IFDEF WIN32} 'windows32'
  {$ELSEIF Defined(WIN64)} 'windows64'
  {$ELSEIF Defined(MACOS32)} 'macosx64'
  {$ELSEIF Defined(MACOS64)} 'macosx64'
  {$ELSEIF Defined(LINUX32)} 'linux32'
  {$ELSEIF Defined(LINUX64)} 'linux64'
  {$ENDIF};

  {Regexp pattern}
  linkPattern := Format('(cef_binary_%d.%d.%d\+g.*?\+chromium.*?_%s_client\.tar\.bz2)', [
    CEF_SUPPORTED_VERSION_MAJOR,
    CEF_SUPPORTED_VERSION_MINOR,
    CEF_SUPPORTED_VERSION_RELEASE,
    target
  ]);

  {Get builds page}
  with TNetHTTPClient.Create(nil) do
  begin
    try pageResponse := Get(mainLink + 'index.html').ContentAsString; except end;
    Free;
  end;

  {Check response}
  if pageResponse = '' then Exit;

  {Find URL}
  fileName := TRegEx.Match(pageResponse, linkPattern).Value;
  if fileName = '' then Exit;  

  {Encode result link}
  Result := mainLink + TNetEncoding.URL.Encode(fileName);
end;
ange007 commented 3 years ago

Updated:

class function TChromiumUtils.GetLibURL: string;
var
  target, versionPannern, mainLink, pageResponse, fileName: string;
  JSON, JSONTarget, JSONObject: TJSONObject;
  JSONVersions, JSONFiles: TJSONArray;
begin
  Result := '';
  mainLink := 'https://cef-builds.spotifycdn.com/';

  {System}
  target :=
  {$IFDEF WIN32} 'windows32'
  {$ELSEIF Defined(WIN64)} 'windows64'
  {$ELSEIF Defined(MACOS32)} 'macosx64'
  {$ELSEIF Defined(MACOS64)} 'macosx64'
  {$ELSEIF Defined(LINUX32)} 'linux32'
  {$ELSEIF Defined(LINUX64)} 'linux64'
  {$ENDIF};

  {Version pattern}
  versionPannern := Format('%d.%d.%d', [
    CEF_SUPPORTED_VERSION_MAJOR,
    CEF_SUPPORTED_VERSION_MINOR,
    CEF_SUPPORTED_VERSION_RELEASE
  ]);

  {Get builds page}
  with TNetHTTPClient.Create(nil) do
  begin
    try pageResponse := Get(mainLink + 'index.json').ContentAsString; except end;
    Free;
  end;

  {Check response}
  if pageResponse = '' then Exit;

  {Parse response}
  JSON := TJSONObject.ParseJSONValue(pageResponse, False, True) as TJSONObject;
  try
    JSONTarget := JSON.FindValue(target) as TJSONObject;
    if not (Assigned(JSONTarget)) then Exit;

    with JSONTarget do
    begin
      JSONVersions := FindValue('versions') as TJSONArray;
      if not (Assigned(JSONVersions))
        or (JSONVersions.Count <= 0) then Exit;

      with JSONVersions.GetEnumerator do
      begin
        while MoveNext do
        begin
          if not (Current is TJSONObject)
            or (Pos(versionPannern, (Current as TJSONObject).Values[ 'cef_version' ].Value) <> 1) then Continue;

          JSONFiles := (Current as TJSONObject).FindValue('files') as TJSONArray;
          if not (Assigned(JSONFiles))
            or (JSONFiles.Count <= 0) then Exit;

          with JSONFiles.GetEnumerator do
          begin
            while MoveNext do
            begin
              if not (Current is TJSONObject)
                or ((Current as TJSONObject).Values[ 'type' ].Value <> 'client') then Continue;

              fileName := (Current as TJSONObject).Values['name'].Value;
            end;
          end;
        end;
      end;
    end;
  finally
    JSON.Free;
  end;

  {Find URL}
  if fileName = '' then Exit;

  {Encode result link}
  Result := mainLink + TNetEncoding.URL.Encode(fileName);
end;