tslediter/designer/gettsleditorstart.tsf

241 lines
7.3 KiB
Plaintext

//启动tsl编辑器
//20230421 整理代码
uses tslvcl;
deletefuncacheini(); //清空缓存
ops := ""; //待打开文件
GLobal G_OpenHostory;
G_OpenHostory := true; //默认打开历史文件标记
hasinstance := true; //单独进程
isdebug := false;
for i:= 0 to sysparamcount() do
begin
if ("-DEBUGSERVER" = sysparamstr(i)) then //调试标记
begin
isdebug := true;
end else
if (i<sysparamcount())and ("-f" = sysparamstr(i) ) then //打开文件
begin
ops := sysparamstr(i+1) ;
//break;
end else
if (i<sysparamcount())and ("-h" = sysparamstr(i) ) then //是否打开历史
begin
if "0" = sysparamstr(i+1) then G_OpenHostory := false;
//break;
end else
if (i<sysparamcount())and ("-i" = sysparamstr(i) ) then //启用其他进程
begin
if "1" = sysparamstr(i+1) then
begin
hasinstance := false;
end
end else
if (i<=sysparamcount())and ("-install" = sysparamstr(i) ) then //注册右键打开
begin
InStallToMenu();
//return sleep(5000); //停留8秒
echo "\r\n press enter exit";
return readln();
end else
if (i<=sysparamcount())and ("-uninstall" = sysparamstr(i) ) then //卸载右键打开
begin
UnInStallToMenu();
echo "\r\n press enter exit";
return readln();
end
end
if sysparamcount()=0 then //处理单独一个文件
begin
ops := sysparamstr(0);
if lowercase(SysExecName())=lowercase(ops) then //处理编译成exe 导致参数次序问题
begin
ops := nil;
end
end
if ops and ifstring(ops) then
begin
if not FileList("",ops) then
begin
s := "";
n := 1024;//512;
setlength(s,n);
GetCurrentDirectoryA(n,s);
for i:= 1 to n do
begin
if s[i]="\0" then
begin
if i = 1 then break;
ops := s[1:i-1]+ops;
break;
end
end
end
end
if not(isdebug) and hasinstance then //实现一个编辑器进程
begin
//判断
h := FindWindowA("tslediter_a_a_1",nil);
if h then
begin
basepath := TS_GetUserProfileHome();
handlefile := basepath+"editer\\whandle.tsm";
exportfile(ftstream(),"",handlefile,ops);
PostMessageA(h,0x400,303,1);
return ;
end
end else
begin
global g_dotsavehistory; //是否保存打开的历史记录
g_dotsavehistory := true;
end
app := initializeapplication();
app.createform(class(TRunEditorForm),fm);
fm.OpenAndGotoFileByName(ops);
fm.show();
app.run();
type TRunEditorForm = class(TEditorForm)
function Create(AOwner);override;
begin
inherited;
end
function WMUSER(o,e):WM_USER;override;
begin
if e.wparam = 303 and e.lparam=1 then
begin
basepath := TS_GetUserProfileHome();
handlefile := basepath+"editer\\whandle.tsm";
if (importfile(ftstream(),"",handlefile,n)=1) and ifstring(n) and n then
begin
OpenAndGotoFileByName(n);
end
//
h := self.Handle;
if _wapi.IsZoomed(h) then
begin
_wapi.ShowWindow(h,SW_MAXIMIZE);
end else
_wapi.ShowWindow(h, SW_SHOWNORMAL);//确保显示
//_wapi.ShowWindow(self.Handle, SW_SHOWNORMAL);//确保显示
_Wapi.ForegroundWindow(h);//PostMessageA(self.Handle,WM_USER,303,10);//放到前端
end {else
if e.wparam = 303 and e.lparam=10 then
begin
//Show(SW_SHOWNORMAL);
FCurrentRect := BoundsRect ;
Show(SW_MINIMIZE);
PostMessageA(self.Handle,WM_USER,303,20);
end else
if e.wparam = 303 and e.lparam = 20 then
begin
Show(SW_SHOWNORMAL);
_wapi.bringWindowToTop(self.Handle);
if FCurrentRect then
begin
if ((FCurrentRect[3]-FCurrentRect[1])>200) and ((FCurrentRect[2]-FCurrentRect[0])>200) then
BoundsRect := FCurrentRect;
end
//_wapi.SetForegroundWindow(seLF.Handle);
end}
inherited;
end
function CreateParams(p);override;
begin
inherited;
p.WinClassName := "tslediter_a_a_1";
end
private
FCurrentRect;
end
function InStallToMenu(); //注册
begin
k1 := new TRegKey(class(TRegKey).HKEY_CLASSES_ROOT);
tek := k1.openKeyA("*\\shell\\tslediter");
if not ifobj(tek) then
begin
return echo "Please run with administrator rights!!";
end
tek.SetValueStringA(nil,"TSL本地编辑器");
tek.SetValueStringA("Icon",SysExecName());
tc := tek.openKeyA("command");
if not ifobj(tc) then
begin
echo "Please run with administrator rights!!";
end else
begin
tc.SetValueStringA(nil,SysExecName()+ ' "%1"');
bkcl := k1.openKeyA("Directory\\Background\\shell\\tslediter\\command");
if bkcl then bkcl.SetValueStringA(nil,SysExecName());
bkcl := k1.openKeyA("Directory\\Background\\shell\\tslediter");
bkcl.SetValueStringA(nil,"TSL Editor");
if bkcl then bkcl.SetValueStringA("Icon",SysExecName());
echo "register tslediter ok ~~";
end
end
function UnInStallToMenu(); //卸载
begin
k1 := new TRegKey(class(TRegKey).HKEY_CLASSES_ROOT);
tc := k1.openKeyA("*\\shell");
if not ifobj(tc) then
begin
echo "Please run with administrator rights!!";
return;
end else
begin
if 0=tc.DeleteKeyA("tslediter\\command") then
begin
if 0=tc.DeleteKeyA("tslediter") then
begin
bkcl := k1.openKeyA("Directory\\Background\\shell");
if ifobj(bkcl) then
begin
if 0=bkcl.DeleteKeyA("tslediter\\command") then
begin
if 0=bkcl.DeleteKeyA("tslediter") then
begin
end
end
end
echo "unregister tslediter ok~~";
return ;
end
end
echo "tslediter not installed~~";
return ;
end
end
function deletefuncacheini();
begin
plg := pluginpath();
{$ifdef linux}
sp :="/";
{$else}
sp := "\\";
{$endif}
for i:= length(plg)-1 downto 1 do
begin
if plg[i]=sp then
begin
fn := plg[1:i]+"FunCache.ini";
r := filedelete("",fn);
return r;
end
end
end
{$ifdef linux}
function PostMessageA(hWnd:pointer;Msg:integer;wParam:pointer;lParam:pointer)begin end ;
function FindWindowA(lpClassName:string;lpWindowName:string)begin end ;
function GetCurrentDirectoryA(nBufferLength:integer; var lpBuffer:string)begin end ;
function TS_GetUserProfileHome()begin end ;
{$else}
function PostMessageA(hWnd:pointer;Msg:integer;wParam:pointer;lParam:pointer):integer;stdcall;external "User32.dll" name "PostMessageA";
function FindWindowA(lpClassName:string;lpWindowName:string):pointer;stdcall;external "User32.dll" name "FindWindowA";
function GetCurrentDirectoryA(nBufferLength:integer; var lpBuffer:string):integer;stdcall;external "Kernel32.dll" name "GetCurrentDirectoryA";
function TS_GetUserProfileHome():string;cdecl;external "TSSVRAPI.dll" name "TS_GetUserProfileHome";
{$endif}