Thread: Arc Gui (beta)
View Single Post
  #11  
Old 03-01-2018, 06:08
JRD!'s Avatar
JRD! JRD! is offline
Registered User
 
Join Date: Sep 2015
Location: Matrix
Posts: 274
Thanks: 225
Thanked 600 Times in 168 Posts
JRD! is on a distinguished road
Finally I will leave the original format, I just change the way to recovered the output path in order to be compatible with ArcGUI.

for those interested here are the changes:
Code:
function IsRelativePath(const sPath: string): Boolean;
begin
  Result:=True;
  if Length(sPath) >= 2 then
    Result:=sPath[2] <> ':';
end;

function ClsMain(operation: Integer; Callback: CLS_CALLBACK; Instance: Pointer): Integer; cdecl;
const
  BuffSize = 64 * 1024;
var
  CLS: TCLSStream;
  SS: TSplitStream;
  Bytes: TBytes;
  X: Integer;
  X8: Byte;
  X64: Int64;
  s: String;
  FirstVolume, OtherVolume: Int64;
  i: integer;
begin

  Result := CLS_ERROR_GENERAL;

  case (operation) of
    CLS_COMPRESS:
      begin
 
        for i := 1 to ParamCount do
        begin
          if (ExtractFileExt(ParamStr(i)) = '.001') then
          begin
            Archive := ParamStr(i);
            Break;
          end;
        end;

        if IsRelativePath(Archive) then
          Archive := ExtractFilePath(GetModuleName) + Archive;

        Archive := ChangeFileExt(Archive, '');

        SetLength(Bytes, 256);
        FillChar(Bytes[0], Length(Bytes), #0);

        X := Callback(Instance, CLS_GET_PARAMSTR, @Bytes[0], Length(Bytes));
        s := StringOf(Bytes);
        s := ReplaceStr(s, #0, '');

        FirstVolume := ConvertToBytes(LeftStr(s, Pos(':', s) - 1));
        OtherVolume := ConvertToBytes(ReplaceStr(s, LeftStr(s, Pos(':', s)), ''));

        CLS := TCLSStream.Create(Callback, Instance);
        CLS.WriteBuffer(FirstVolume, sizeof(FirstVolume));

        Bytes := BytesOf(ExtractFileName(Archive));

        X := Length(Bytes);

        CLS.WriteBuffer(X, sizeof(X));
        CLS.WriteBuffer(Bytes, Length(Bytes));

        X64 := StreamToStream(CLS, CLS, BuffSize, FirstVolume);

        if X64 = FirstVolume then
        begin
          X := CLS.Read(Bytes, Length(Bytes));
          if X > 0 then
          begin
            X8 := 1;
            CLS.WriteBuffer(X8, sizeof(X8));
            SS := TSplitStream.Create(Archive, False, OtherVolume, OtherVolume);
            SS.WriteBuffer(Bytes, X);
            StreamToStream(CLS, SS, BuffSize);
            SS.Free;
          end else
          begin
            X8 := 0;
            CLS.WriteBuffer(X8, sizeof(X8));
          end;
        end;
        CLS.Free;
        SetLength(Bytes, 0);
        Result := CLS_OK;
      end;
    CLS_DECOMPRESS:
      begin
        try
          if SrcPath = '' then
            SrcPath := GetCurrentDir;
          CLS := TCLSStream.Create(Callback, Instance);
          CLS.ReadBuffer(FirstVolume, sizeof(FirstVolume));
          CLS.ReadBuffer(X, sizeof(X));
          SetLength(Bytes, X);
          CLS.ReadBuffer(Bytes, Length(Bytes));
          Archive := IncludeTrailingBackSlash(SrcPath) + StringOf(Bytes);
          X64 := StreamToStream(CLS, CLS, BuffSize, FirstVolume);
          if FirstVolume = X64 then
          begin
            CLS.ReadBuffer(X8, sizeof(X8));
            if X8 = 1 then
            begin
              SS := TSplitStream.Create(Archive, True, OtherVolume, OtherVolume, MyDiskRequest);
              StreamToStream(SS, CLS, BuffSize);
              SS.Free;
            end;
          end;
          CLS.Free;
          SetLength(Bytes, 0);
          Result := CLS_OK;
        except
          Result := CLS_ERROR_GENERAL;
        end;
      end;
  else
    Result := CLS_ERROR_NOT_IMPLEMENTED;
  end;
end;
I also re-implemented the external compressors in the popup menu:

__________________
Practice makes perfect.
Reply With Quote
The Following 7 Users Say Thank You to JRD! For This Useful Post:
78372 (03-01-2018), ffmla (05-01-2018), mausschieber (03-01-2018), pakrat2k2 (03-01-2018), romi1996 (30-01-2020), Simorq (03-01-2018), Titeuf (03-01-2018)