⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit1.pas

📁 清理工具PS2键盘驱动程序
💻 PAS
字号:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, RsDefines, StdCtrls, ComCtrls, RsUpgrade;

  
type
  TGetRsCleaner = function(CallBack: ICleanInfo): IRsCleaner; stdcall;
  
  TForm1 = class(TForm, ICleanInfo)
    Btn_Load: TButton;
    ProgressBar1: TProgressBar;
    Label_Loading: TLabel;
    Btn_Detect: TButton;
    ListBox1: TListBox;
    Btn_Clean: TButton;
    Radio_ForceMode: TCheckBox;
    Label_Engine: TLabel;
    ListBox2: TListBox;
    Label_EngineVer: TLabel;
    Button1: TButton;
    procedure FormCreate(Sender: TObject);
    procedure Btn_LoadClick(Sender: TObject);
    procedure Btn_DetectClick(Sender: TObject);
    procedure Btn_CleanClick(Sender: TObject);
    procedure ListBox1Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    FCleaner: IRsCleaner;
    FDLLHandle: THandle;
    FInited: boolean;
    procedure InitRsCleaner;
  protected
    procedure OnFound(const Engine: pCleanInfo; const Found: TFoundItem);
    procedure OnClean(const Engine: pCleanInfo; const Clean: TCleanItem);
    procedure OnMessage(const Engine: pCleanInfo; const MsgType: TMessageType; const Param1, Param2: Cardinal);
    procedure OnEngineLoadOK;
    procedure OnLoading(const EngineName: string; const Total, Loaded: Cardinal);  
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  InitRsCleaner;
  if FCleaner <> nil then begin
    Label_EngineVer.Caption := Format('Engine ver: %s', [FCleaner.EngineVersion]);
  end;
  FInited := False;
end;

procedure TForm1.InitRsCleaner;
var DLLPath: string;
    RsGetFunc:  TGetRsCleaner;
begin
  DLLPath := ExtractFilePath(Application.ExeName) + 'rsclean.dll';
  FDLLHandle := LoadLibrary(PChar(DLLPath));
  if FDLLHandle > 0 then begin
    @RsGetFunc := GetProcAddress(FDllHandle,'GetRsCleanInterface');
    FCleaner := RsGetFunc(Self);
  end;
end;

procedure TForm1.OnClean(const Engine: pCleanInfo;
  const Clean: TCleanItem);
begin
  //Not implement yet.
end;

procedure TForm1.OnEngineLoadOK;
begin
  Progressbar1.Position := 0;
  Label_Loading.Caption := 'Loaded all engines OK!';
  Label_Engine.Caption := Format('Engines count: %d', [FCleaner.EngineCount]);
  FInited := True;
  Btn_Detect.Enabled := true;
  Btn_Clean.Enabled := true;
  Btn_Load.Enabled := False;
end;

procedure TForm1.OnFound(const Engine: pCleanInfo;
  const Found: TFoundItem);
begin
  ListBox1.Items.AddObject(Engine^.Name, TObject(Engine));
end;

procedure TForm1.OnLoading(const EngineName: string; const Total,
  Loaded: Cardinal);
begin
  if Total > 0 then Progressbar1.Position := 100*Loaded div Total;
  Label_Loading.Caption := Format('Loading %s...', [EngineName]);
  Label_Engine.Caption := Format('Engines loaded: %d', [Loaded]);
end;

procedure TForm1.OnMessage(const Engine: pCleanInfo;
  const MsgType: TMessageType; const Param1, Param2: Cardinal);
  function GetListIndexByEngine: integer;
  var i: integer;
  begin
    Result := -1;
    for i:= 0 to ListBox1.Items.Count - 1 do begin
      if ListBox1.Items.Objects[i] = nil then continue; 
      if pCleanInfo(ListBox1.Items.Objects[i]) = Engine then begin
        Result := i;
        break;
      end;
    end;
  end;
var Current: integer;  
begin
  case MsgType of
    mtDetectMessage:
      begin
        Label_Loading.Caption := pString(Param1)^;
      end;
    mtDetectPercent, mtCleanPercent:
      begin
        ProgressBar1.Position := Param1;
      end;
    mtDetectFinished:
      begin
        Label_Loading.Caption := 'Detect OK!';
      end;

   mtRogueFound, mtPartFound:
     begin
       ListBox1.Items.AddObject(Engine.Name, TObject(Engine));
     end;

    mtCleanMessage:
      begin
        Current := GetListIndexByEngine;
        if Current <> -1 then ListBox1.ItemIndex := Current;
        Label_Loading.Caption := pString(Param1)^;
      end;
    mtCleanSuccess:
      begin
        Current := GetListIndexByEngine;
        if Current <> -1 then ListBox1.Items.Delete(Current);
      end;
    mtCleanFaild:
      begin
        Current := GetListIndexByEngine;
        if Current <> -1 then ListBox1.Items[Current] := ListBox1.Items[Current] + '->失败!';
      end;
    mtCleanFinished:
      begin
        Label_Loading.Caption := 'Clean OK!';
      end; 
  end;
  Application.ProcessMessages;
end;

procedure TForm1.Btn_LoadClick(Sender: TObject);
begin
  if FCleaner <> nil then begin
    if not FInited then FCleaner.ReadEngines;
    TButton(Sender).Enabled := False;
  end;
end;

procedure TForm1.Btn_DetectClick(Sender: TObject);
begin
  Listbox1.Items.Clear;
  if FCleaner <> nil then FCleaner.Detect;
end;

procedure TForm1.Btn_CleanClick(Sender: TObject);
var List: TList;
    i: integer;
begin
  if FCleaner = nil then exit; 
  List := TList.Create;
  for i:= 0 to ListBox1.Items.Count - 1 do begin
    List.Add(ListBox1.Items.Objects[i]);
  end;
  FCleaner.Clean(List, Radio_ForceMode.Checked);
  List.Free;
end;

procedure TForm1.ListBox1Click(Sender: TObject);
var Eng: pCleanInfo;
begin
  if Listbox1.ItemIndex < 0 then exit;
  Eng := pCleanInfo(ListBox1.Items.Objects[ListBox1.ItemIndex]);
  ListBox2.Items.Clear;
  FCleaner.GetExistObjectList(Eng, ListBox2.Items);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  TForm_Upgrade.ShowUpgradeDialog(FCleaner.EngineVersion);
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -