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

📄 setupjj.dpr

📁 拼音加加便携版安装程序的源代码 主要解决:注册ime 和 卸载 ime
💻 DPR
字号:
program setupjj;

uses
  windows,
  SysUtils,
  Registry,
  classes,
  imm;

var
  psysdir : pchar;
  sysdir  : string;
  ImeFile ,DllFile , DllFile2, ExeFile : string ;

  tempfile: file of byte ;
  jjhwnd  : HWND ;
  WM_CLOSE: word = $0010 ;

  sV      : TStringList;

  Reg     : TRegistry ;
  tmphandle :Thandle ;
  S         : string[8] ;
  V ,J ,I   : Cardinal;
  tmpHKL : HKL ;

  S1,S3,S4  : string ;
  S2        : string = '拼音加加2.207(便携版)';
  Isinstalled : Boolean = False;
 {$R *.RES}

function ReadString(const Section, Ident, Default , FileName: string): string;
var
  Buffer: array[0..2047] of Char;
begin
  SetString(Result, Buffer, GetPrivateProfileString(PChar(Section),
    PChar(Ident), PChar(Default), Buffer, SizeOf(Buffer), PChar(FileName)));
end;

begin

  tmphandle := openfilemapping(FILE_MAP_READ,true,pchar('PYJJ220_INTAU_DATA'));
  CloseHandle(tmphandle);
  if (tmphandle <> 0) then
    begin
       S1 := '拼音加加正在使用中。请关闭所 '+char(10)+char(13)+
             '有使用过拼音加加的程序再试。 '+char(10)+char(13)+
              char(10)+char(13)+
             '如果系统级程序使用过拼音加加,'+char(10)+char(13)+
             '请先注销或重启计算机后再试。';
       messagebox(0,pchar(S1),pchar(S2),MB_ICONINFORMATION);
       exit;
    end ;
  jjhwnd := FindWindow('PYJJ220INTAUAPP', 'PYJJ220INTAU');
  if (jjhwnd <> 0) then
    begin
     SendMessage(jjhwnd, WM_CLOSE, 0, 0);
     Sleep(1000);
    end ;
  jjhwnd := FindWindow('PYJJ220INTAUAPP', 'PYJJ220INTAU');
  if ( jjhwnd <> 0 ) then
    begin
       S1 := '拼音加加正在使用中。请关闭所 '+char(10)+char(13)+
             '有使用过拼音加加的程序再试。 '+char(10)+char(13)+
              char(10)+char(13)+
             '如果系统级程序使用过拼音加加,'+char(10)+char(13)+
             '请先注销或重启计算机后再试。';
       messagebox(0,pchar(S1),pchar(S2),MB_ICONINFORMATION);
       exit;
     end;

  GetMem(psysdir,32);
  GetSystemDirectory( psysdir,32);
  sysdir:= psysdir;
  freemem(psysdir);

  imefile := sysdir + '\PyjjV.ime';
  dllfile := sysdir + '\PycodeV.dll';
  dllfile2:= sysdir + '\PyjjczV.dll';
  exefile := sysdir + '\PyintaV.exe';

  Reg := TRegistry.Create;
  try
    Reg.RootKey:=HKey_Local_Machine;
    if not Reg.OpenKey('\SOFTWARE\PYJJ',False) then
       Isinstalled := False
    else
      begin
        if Reg.ValueExists('HKL') and
          ( FileExists(imefile) and FileExists(dllfile) and
            FileExists(dllfile2)and FileExists(exefile) )then
          begin
            Isinstalled := True ;
            S4 := Reg.ReadString('Dir');
          end
        else  Isinstalled := False ;
      end;
  finally
    Reg.Free;
  end;

  if ParamStr(1)='/inst' then Isinstalled := False
  else if ParamStr(1)='/uninst' then
    begin
      if Isinstalled then
        begin
          S1 := '拼音加加便携版所有文件都将删除,继续吗?' ;
          if messagebox(0,pchar(S1),pchar(S2),MB_YESNO) = IDNO then exit;
        end
      else
        begin
          S1 := '系统中未安装拼音加加便携版。';
          messagebox(0,pchar(S1),pchar(S2),MB_ICONINFORMATION) ;
          exit;
        end ;
    end ;
    
  if Isinstalled then
  //**************卸载**************
  begin

    S2 := '拼音加加2.207(便携版)卸载';
    try
      assignfile(tempfile , imefile);
      reset(tempfile);
      close(tempfile);

      assignfile(tempfile , exefile);
      reset(tempfile);
      close(tempfile);

      assignfile(tempfile , dllfile);
      reset(tempfile);
      close(tempfile);

      assignfile(tempfile , dllfile2);
      reset(tempfile);
      close(tempfile);
    except
      on EInOutError do
      begin
        S1 := '拼音加加(便携版)核心文件可能被其它程序锁'+char(10)+char(13)+
              '定,或部分文件设置了“只读”属性,不能卸载。';
        messagebox(0,pchar(S1),pchar(S2),MB_ICONERROR);
        exit;
      end;
    end;

    S1:= 'regedit.exe /e myoption.reg hkey_local_machine\software\pyjj\option';
    WinExec(Pchar(s1),0);

    //1st step

    Reg := TRegistry.Create;
    try
      Reg.RootKey:=HKey_Local_Machine;
      if not Reg.OpenKey('\SOFTWARE\PYJJ',False) then
      begin
        S1 := '注册表被系统锁定,不能卸载。。';
        messagebox(0,pchar(S1),pchar(S2),MB_ICONINFORMATION);
        exit ;
      end
      else
      begin
        S := Reg.readstring('HKL');
        Reg.DeleteKey('\SOFTWARE\PYJJ');
      end;
    finally
      Reg.Free;
    end;


    //2nd step
    S := UpperCase(S);
    V := 0 ;
    for I := 1 to 8 do
    begin
      if (S[I]>='0') and (S[I] <='9') then J := Ord(S[I]) - Ord('0')
      else J := Ord(S[I]) - Ord('A') + 10;
      V := (V shl 4) + J;
    end;

    // 注销 Preload 中的拼音加加
    Reg  := TRegistry.Create;
    try
      sV :=TStringList.Create;
      try
        Reg.RootKey:=HKEY_CURRENT_USER;
        if not Reg.OpenKey('\Keyboard Layout\Preload',False) then
          begin
            S1:= '打开注册表失败。请注销或重启计算机后再试。';
            Messagebox(0,pchar(S1),pchar(S2),MB_ICONERROR) ;
            exit;
          end
        else
        begin
          if GetVersion() < $80000000 then
          begin
            Reg.GetValueNames(sV);
            if sV.Count >= 2 then
            for I := 0 to sV.Count-1 do
            begin
              S1 := Reg.ReadString(sV[I]);
              if UpperCase(S1) = S then
                begin
                 Reg.DeleteValue(SV[I]);
                 for J := strtoint(sV[I]) to sV.Count do
                    Reg.RenameValue(inttostr(J),inttostr(J-1));
                 break ;
                end;
            end;
          end
          else
          begin
            Reg.GetKeyNames(sV);
            if sV.Count >= 2 then
            for I := 0 to sV.Count-1 do
            begin
              Reg.OpenKey('\Keyboard Layout\Preload\'+sV[I],False)  ;
              S1 := Reg.ReadString('');
              if UpperCase(S1) = S then
                begin
                  for J := sV.Count  downto strtoint(sV[I]) do
                  begin
                    Reg.OpenKey('\Keyboard Layout\Preload\'+inttostr(J),False);
                    S3 := Reg.ReadString('');
                    reg.WriteString('',S1);
                    S1 := S3;
                  end;
                  Reg.Deletekey('\Keyboard Layout\Preload\'+ inttostr(sV.count));
                  break ;
                end;
            end;
          end;

        end;
      finally
        sV.Free;
      end;
    finally
      Reg.Free;
    end;

    if not UnloadKeyboardLayout(V) then
      begin
        S1 := '删除右下角输入法状态列表中的信息失败。';
        if ParamStr(1)<>'/uninst' then
          begin
            messagebox(0,pchar(S1),pchar(S2),MB_ICONERROR);
            exit;
          end;
      end;

    Reg := TRegistry.Create;
    try
      Reg.RootKey:=HKey_Local_Machine;
      if not Reg.OpenKey('\SYSTEM\CurrentControlSet\Control\Keyboard Layouts\'+S,False) then
        begin
          S1 := '删除注册表输入法目录中的信息失败。';
          messagebox(0,pchar(S1),pchar(S2),MB_ICONERROR);
          exit ;
        end
      else
        begin
          Reg.DeleteKey('\SYSTEM\CurrentControlSet\Control\Keyboard Layouts\'+S);
        end;

      if ParamStr(1)='/uninst' then
        if Reg.OpenKey('\Software\Microsoft\Windows\CurrentVersion\Uninstall\pyjjbxb',False) then
          Reg.DeleteKey('\Software\Microsoft\Windows\CurrentVersion\Uninstall\pyjjbxb');

    finally
      Reg.Free;
    end;

    //3rd step
    try
      if not(deletefile(imefile)  and deletefile(dllfile) and
           deletefile(dllfile2) and deletefile(exefile)  ) then
        begin
          S1 := '拼音加加(便携版)的核心文件可能被其它程序锁定,不能删除.';
          messagebox(0,pchar(S1),pchar(S2),MB_ICONERROR);
          exit;
        end;
    except
      on EInOutError do
        begin
          S1 := '拼音加加(便携版)的核心文件可能被其它程序锁定,不能删除.';
          messagebox(0,pchar(S1),pchar(S2),MB_ICONERROR);
          exit;
        end;
    end;

    if ParamStr(1)='/uninst' then
    begin
      S1 := S4+'\setup.log';
      for i := 1 to 100 do
        begin
          s3 := ReadString('current',inttostr(i),'0',s1);
          if s3 = '0' then break ;
          s3:= S4 +'\' + s3;
          deletefile(s3);
        end;
      deletefile(S1);
      Removedir(S4+'\skin');
      Removedir(S4+'\options');
    end;

    S1 := '拼音加加(便携版)卸载成功。';
    messagebox(0,pchar(S1),pchar(S2),MB_ICONINFORMATION);

    if ParamStr(1)='/uninst' then
    begin
      If GetVersion() < $80000000 then
        begin
          WinExec(pchar('cmd.exe /c del '+'"'+ ParamStr(0)+'"'),SW_HIDE);
          WinExec(pchar('cmd.exe /c rd '+ '"'+ s4 + '"' ),SW_HIDE);
         end
      else
        begin
          WinExec(pchar('command.com /c del '+ '"'+ ParamStr(0)+'"'),SW_HIDE);
          WinExec(pchar('command.com /c rd '+ '"'+ s4 + '"' ),SW_HIDE);
       end;
    end;

  end

  else
  //***********安装*********************************************
  begin

    S2 := '拼音加加2.207(便携版)安装';

    if FileExists(imefile) then
    begin
      S1 := '系统中已安装有拼音加加便携版,替换吗?'+char(13)+char(10)+
            '  ' + char(13)+char(10)+
            '提示:替换后,原来的拼音加加目录仍存在,但原词  '+char(13)+char(10)+
            '库将失效。也可以卸载原来的拼音加加后再试。';
      if messagebox(0,pchar(S1),pchar(S2),MB_YESNO) = IDNO then exit;
    end;


    if not ( FileExists('PyjjV.ime'  ) and
           FileExists('PycodeV.dll') and
           FileExists('PyintaV.bin') and
           FileExists('PyjjczV.dll') and
           FileExists('Pyjjbw.dat' ) and
           FileExists('Pyuc102.bin')
           ) then
      begin
        S1 := '请将安装程序与拼音加加文件放在同一目录下后再试。';
        messagebox(0,pchar(S1),pchar(S2),MB_ICONERROR);
        exit ;
      end;

    try
      if not
        (copyfile( pchar('PyjjV.ime'  ), pchar(imefile) , false) and
         copyfile( pchar('PyintaV.bin'), pchar(exefile) , false) and
         copyfile( pchar('PycodeV.dll'), pchar(dllfile) , false) and
         copyfile( pchar('PyjjczV.dll'), pchar(dllfile2), false) )then
      begin
         S1 := '安装失败:安装拼音加加的核心文件发生错误。核心文'+char(13)+char(10)+
               '件可能被其它程序锁定。请注销或重启计算机后再试。';
         messagebox(0,pchar(S1),pchar(S2),MB_ICONERROR);
        exit;
      end;
    except
      on EInOutError do
        begin
          S1 := '安装失败:安装拼音加加的核心文件发生错误。核心文'+char(13)+char(10)+
                '件可能被其它程序锁定。请注销或重启计算机后再试。';
          messagebox(0,pchar(S1),pchar(S2),MB_ICONERROR);
          exit;
        end;
    end;

    //2nd step

    Reg := TRegistry.Create;
    try
      Reg.RootKey:=HKey_Local_Machine;
      if not Reg.OpenKey('\SOFTWARE\PYJJ',False) then
        begin
          Reg.CreateKey('\SOFTWARE\PYJJ');
          if not Reg.OpenKey('\SOFTWARE\PYJJ',False) then
            begin
              S1 := '安装失败:目录信息写入注册表出错,请注销或重启计算机后再试。';
              messagebox(0,pchar(S1),pchar(S2),MB_ICONERROR);
              exit ;
            end
          else
            begin
              Reg.WriteString('Dir', GetCurrentDir());
              Reg.WriteString('skin_cn', GetCurrentDir()+'\skin\cn.bmp');
              Reg.WriteString('skin_en', GetCurrentDir()+'\skin\en.bmp');
              Reg.WriteString('skin_bg', GetCurrentDir()+'\skin\bg.bmp');
              Reg.WriteString('skin_gbk', GetCurrentDir()+'\skin\gbk.bmp');
            end;
        end
      else
        begin
          Reg.WriteString('Dir', GetCurrentDir());
          Reg.WriteString('skin_cn', GetCurrentDir()+'\skin\cn.bmp');
          Reg.WriteString('skin_en', GetCurrentDir()+'\skin\en.bmp');
          Reg.WriteString('skin_bg', GetCurrentDir()+'\skin\bg.bmp');
          Reg.WriteString('skin_gbk', GetCurrentDir()+'\skin\gbk.bmp');
        end;
    finally
      Reg.Free;
    end;


    //3rd step

    tmpHKL := ImmInstallIME(pchar(imefile), pchar('拼音加加2.207(便携版)')) ;
    { Next codes For uninstall Pyjj}
    if tmpHKL = 0 then
      begin
        S1 := '安装失败:激活输入法出错。请注销或重启计算机后再试。';
        messagebox(0,pchar(S1),pchar(S2),MB_ICONERROR);
        exit ;
      end;

    Reg := TRegistry.Create;
    try
      Reg.RootKey:=HKey_Local_Machine;
      if not Reg.OpenKey('\SOFTWARE\PYJJ',False) then
        begin
          S1 := '安装失败:卸载信息写入注册表出错。请注销或重启计算机后再试。';
          messagebox(0,pchar(S1),pchar(S2),MB_ICONERROR);
          exit ;
        end
      else
        Reg.WriteString('HKL', InttoHex(tmpHKL,8));

      if ParamStr(1)='/inst' then
        if Reg.OpenKey('\Software\Microsoft\Windows\CurrentVersion\Uninstall',False) then
        begin
          Reg.CreateKey('\Software\Microsoft\Windows\CurrentVersion\Uninstall\Pyjjbxb');
          if Reg.OpenKey('\Software\Microsoft\Windows\CurrentVersion\Uninstall\Pyjjbxb',False) then
            begin
              Reg.WriteString('DisplayName', '卸载-拼音加加2.207');
              Reg.WriteString('UninstallString', '"'+GetCurrentDir()+'\setupjj.exe" /uninst');
            end;
        end;
    finally
      Reg.Free;
    end;

    //4th step
    S1 := '  安装成功。恭喜!' + char(13)+char(10)+
          ' hhhhwwww 感谢您的试用。'+ char(13)+char(10)+
          '特别鸣谢:Easycode、Wbfans。';
    messagebox(0,pchar(S1),pchar(S2),MB_ICONINFORMATION);

    if not ( FileExists('myoption.reg')) then exit;
    S1:= 'regedit.exe /s myoption.reg' ;
    WinExec(Pchar(s1),0);

  end;

end.

⌨️ 快捷键说明

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