Skip to content

A modern terminal with a built-in multiplexer: close it and your sessions keep running. Run shells and tons of AI agents across your machines, then pick them up from desktop, browser, TUI and more. Written in Rust with no UI framework: interface drawn straight on the GPU. No Electron, GPUI or webview.

14.3 KB
Raw Blame
; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
; vim:ts=2:sw=2:et:

#define MyAppName "ThinkTerm"
;#define MyAppVersion "1.5"
#define MyAppPublisher "RoversX"
#define MyAppURL "https://github.com/RoversX/thinkterm"
#define MyAppExeName "thinkterm-gui.exe"
#ifndef MyAppSourceDir
  #error MyAppSourceDir must name the directory containing the built executables
#endif
; x64 or arm64: the architecture of the executables in MyAppSourceDir
#ifndef MyAppArch
  #define MyAppArch "x64"
#endif

[Setup]
AppId={{56CBA99B-8F65-4EC0-8CE4-F13BFCB70274}
#if MyAppArch == "arm64"
ArchitecturesAllowed=arm64
ArchitecturesInstallIn64BitMode=arm64
#else
ArchitecturesAllowed=x64 arm64
ArchitecturesInstallIn64BitMode=x64 arm64
#endif
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={autopf}\{#MyAppName}
DisableProgramGroupPage=yes
;LicenseFile=..\LICENSE.md
; Remove the following line to run in administrative install mode (install for all users.)
;PrivilegesRequired=lowest
;PrivilegesRequiredOverridesAllowed=dialog
OutputDir=..
OutputBaseFilename=ThinkTerm-Setup
SetupIconFile=..\assets\windows\terminal.ico
UninstallDisplayIcon={app}\{#MyAppExeName}
Compression=lzma
SolidCompression=yes
WizardStyle=modern
; Build 1809 is required for pty support
MinVersion=10.0.17763
ChangesEnvironment=true

[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"

[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked

[Files]
Source: "{#MyAppSourceDir}\thinkterm.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "{#MyAppSourceDir}\wezterm.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "{#MyAppSourceDir}\thinkterm-gui.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "{#MyAppSourceDir}\thinkterm-mux-server.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "{#MyAppSourceDir}\thinkterm-plugin-server.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "{#MyAppSourceDir}\thinkterm-connect-auth.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "{#MyAppSourceDir}\mesa\opengl32.dll"; DestDir: "{app}\mesa"; Flags: ignoreversion
; ANGLE has no arm64 build here
#if MyAppArch != "arm64"
Source: "{#MyAppSourceDir}\libEGL.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "{#MyAppSourceDir}\libGLESv2.dll"; DestDir: "{app}"; Flags: ignoreversion
#endif
Source: "{#MyAppSourceDir}\conpty.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "{#MyAppSourceDir}\OpenConsole.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "..\thinkterm-web\www\*"; DestDir: "{app}\web"; Flags: ignoreversion recursesubdirs skipifsourcedoesntexist
Source: "{#MyAppSourceDir}\strip-ansi-escapes.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "..\LICENSE.md"; DestDir: "{app}"; Flags: ignoreversion
Source: "..\LICENSE-MIT"; DestDir: "{app}"; Flags: ignoreversion
Source: "..\NOTICE"; DestDir: "{app}"; Flags: ignoreversion
; NOTE: Don't use "Flags: ignoreversion" on any shared system files

#if MyAppArch == "arm64"
[InstallDelete]
; Left behind by an x64 install in the same place; an arm64 process cannot load them
Type: files; Name: "{app}\libEGL.dll"
Type: files; Name: "{app}\libGLESv2.dll"

#endif
[UninstallDelete]
; Files of an older build that were still running when an update replaced them
Type: filesandordirs; Name: "{app}\.old"

[Icons]
Name: "{autoprograms}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; AppUserModelID: "com.roversx.thinkterm"
Name: "{autodesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon; AppUserModelID: "com.roversx.thinkterm"

[Run]
Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent

[Registry]
Root: HKA; Subkey: "Software\Classes\Drive\shell\Open ThinkTerm here"; Flags: uninsdeletekey
Root: HKA; Subkey: "Software\Classes\Drive\shell\Open ThinkTerm here"; ValueName: "icon"; ValueType: string; ValueData: "{app}\{#MyAppExeName}"; Flags: uninsdeletekey;
Root: HKA; Subkey: "Software\Classes\Drive\shell\Open ThinkTerm here\command"; ValueType: string; ValueData: """{app}\{#MyAppExeName}"" start --no-auto-connect --cwd ""%V\"""; Flags: uninsdeletekey;
Root: HKA; Subkey: "Software\Classes\Directory\Background\shell\Open ThinkTerm here"; Flags: uninsdeletekey
Root: HKA; Subkey: "Software\Classes\Directory\Background\shell\Open ThinkTerm here"; ValueName: "icon"; ValueType: string; ValueData: "{app}\{#MyAppExeName}"; Flags: uninsdeletekey;
Root: HKA; Subkey: "Software\Classes\Directory\Background\shell\Open ThinkTerm here\command"; ValueType: string; ValueData: """{app}\{#MyAppExeName}"" start --no-auto-connect --cwd ""%V"; Flags: uninsdeletekey;
Root: HKA; Subkey: "Software\Classes\Directory\shell\Open ThinkTerm here"; Flags: uninsdeletekey
Root: HKA; Subkey: "Software\Classes\Directory\shell\Open ThinkTerm here"; ValueName: "icon"; ValueType: string; ValueData: "{app}\{#MyAppExeName}"; Flags: uninsdeletekey;
Root: HKA; Subkey: "Software\Classes\Directory\shell\Open ThinkTerm here\command"; ValueType: string; ValueData: """{app}\{#MyAppExeName}"" start --no-auto-connect --cwd ""%V\\"""; Flags: uninsdeletekey;

[Code]
{ https://stackoverflow.com/a/46609047/149111 }
const EnvironmentKey = 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment';

// The x64 package also installs on arm64, where it runs under emulation;
// these check that the machine can emulate x64. The arm64 package runs
// natively and needs none of it.
#if MyAppArch != "arm64"
const IMAGE_FILE_MACHINE_AMD64 = $8664;

function GetMachineTypeAttributes(
    Machine: Word; var MachineTypeAttributes: Integer): HRESULT;
  external '[email protected] stdcall delayload';

function IsSupportedArch(): Boolean;
var
  Version: TWindowsVersion;
  MachineTypeAttributes: Integer;
  Arch: TSetupProcessorArchitecture;
begin
  GetWindowsVersionEx(Version);
  // Use capability detection if available. GetMachineTypeAttributes is
  // available starting Build 22000
  if Version.Build >= 22000 then
  begin
    OleCheck(
      GetMachineTypeAttributes(IMAGE_FILE_MACHINE_AMD64, MachineTypeAttributes)
    );
    Result := MachineTypeAttributes <> 0;
  end
  else
  begin
    // If capability detection is not available, then we rely on build number.
    // x64 emulation on arm64 is available starting build 21277 so both x64 and
    // arm64 will work
    if Version.Build >= 21277 then
    begin
      Result := True;
    end
    else
    begin
      // If we're here, it means we're on a build between 17763 and 21277
      // because Inno will check MinVersion 10.0.17763 and arch will be x64 or
      // arm64. Only x64 is supported in this build range
      Arch := ProcessorArchitecture;
      Result := Arch = paX64;
    end
  end;
end;

<event('InitializeSetup')>
function InitializeSetupCheckArchitecture(): Boolean;
begin
  Result := IsSupportedArch();
end;
#endif

procedure EnvAddPath(instlPath: string);
var
  Paths: string;
begin
  { Retrieve current path (use empty string if entry not exists) }
  if not RegQueryStringValue(HKEY_LOCAL_MACHINE, EnvironmentKey, 'Path', Paths) then
    Paths := '';

  if Paths = '' then
    Paths := instlPath + ';'
  else
  begin
    { Skip if string already found in path }
    if Pos(';' + Uppercase(instlPath) + ';',  ';' + Uppercase(Paths) + ';') > 0 then exit;
    if Pos(';' + Uppercase(instlPath) + '\;', ';' + Uppercase(Paths) + ';') > 0 then exit;

    { Append App Install Path to the end of the path variable }
    if Paths[length(Paths)] <> ';' then
      Paths := Paths + ';';

    Paths := Paths + instlPath + ';';
  end;

  { Overwrite (or create if missing) path environment variable }
  if RegWriteStringValue(HKEY_LOCAL_MACHINE, EnvironmentKey, 'Path', Paths)
  then Log(Format('The [%s] added to PATH: [%s]', [instlPath, Paths]))
  else Log(Format('Error while adding the [%s] to PATH: [%s]', [instlPath, Paths]));
end;

procedure EnvRemovePath(instlPath: string);
var
  Paths: string;
  P, Offset, DelimLen: Integer;
begin
  { Skip if registry entry not exists }
  if not RegQueryStringValue(HKEY_LOCAL_MACHINE, EnvironmentKey, 'Path', Paths) then
    exit;

  { Skip if string not found in path }
  DelimLen := 1;     { Length(';') }
  P := Pos(';' + Uppercase(instlPath) + ';', ';' + Uppercase(Paths) + ';');
  if P = 0 then
  begin
    { perhaps instlPath lives in Paths, but terminated by '\;' }
    DelimLen := 2; { Length('\;') }
    P := Pos(';' + Uppercase(instlPath) + '\;', ';' + Uppercase(Paths) + ';');
    if P = 0 then exit;
  end;

  { Decide where to start string subset in Delete() operation. }
  if P = 1 then
    Offset := 0
  else
    Offset := 1;
  { Update path variable }
  Delete(Paths, P - Offset, Length(instlPath) + DelimLen);

  { Overwrite path environment variable }
  if RegWriteStringValue(HKEY_LOCAL_MACHINE, EnvironmentKey, 'Path', Paths)
  then Log(Format('The [%s] removed from PATH: [%s]', [instlPath, Paths]))
  else Log(Format('Error while removing the [%s] from PATH: [%s]', [instlPath, Paths]));
end;

// An update replaces files a running ThinkTerm still has open: the session
// server, which holds every terminal, and a console host per pane. Windows
// will not overwrite or delete a running program, but it will move one, so
// before anything is installed each program and library of the old build
// moves to .old\<stamp>\ in the app folder -- under the same name, as
// ThinkTerm finds its server by its program's name -- and the new files go
// in their place. Nothing is closed: a running ThinkTerm keeps the old build
// until it restarts, and its session server hands its terminals to the new
// one then. A moved file is deleted once nothing runs it: at the end of this
// install, at the next one, or when Windows next starts.
var
  AsideStamp: String;
  MovedFrom: TArrayOfString;
  MovedTo: TArrayOfString;
  Installed: Boolean;

function AsideRoot(): String;
begin
  Result := ExpandConstant('{app}\.old');
end;

procedure DeleteTree(const Dir: String);
var
  FindRec: TFindRec;
begin
  if FindFirst(Dir + '\*', FindRec) then
  begin
    try
      repeat
        if (FindRec.Name <> '.') and (FindRec.Name <> '..') then
        begin
          if FindRec.Attributes and FILE_ATTRIBUTE_DIRECTORY <> 0 then
          begin
            DeleteTree(Dir + '\' + FindRec.Name);
            RemoveDir(Dir + '\' + FindRec.Name);
          end
          else
            DeleteFile(Dir + '\' + FindRec.Name);
        end;
      until not FindNext(FindRec);
    finally
      FindClose(FindRec);
    end;
  end;
end;

function IsProgramFile(const Name: String): Boolean;
var
  Ext: String;
begin
  Ext := Lowercase(ExtractFileExt(Name));
  Result := ((Ext = '.exe') or (Ext = '.dll')) and (Pos('unins', Lowercase(Name)) <> 1);
end;

// Moves the programs and libraries of the app folder's Rel aside; returns
// the first that could not be moved, or ''.
function MoveAside(const Rel: String): String;
var
  FindRec: TFindRec;
  Dir, Dest: String;
  Names: TArrayOfString;
  I, Tries: Integer;
  Moved: Boolean;
begin
  Result := '';
  Dir := ExpandConstant('{app}');
  Dest := AsideRoot() + '\' + AsideStamp;
  if Rel <> '' then
  begin
    Dir := Dir + '\' + Rel;
    Dest := Dest + '\' + Rel;
  end;
  // Listed first: the folder is not changed while it is read.
  if FindFirst(Dir + '\*', FindRec) then
  begin
    try
      repeat
        if (FindRec.Attributes and FILE_ATTRIBUTE_DIRECTORY = 0) and IsProgramFile(FindRec.Name) then
        begin
          SetArrayLength(Names, GetArrayLength(Names) + 1);
          Names[GetArrayLength(Names) - 1] := FindRec.Name;
        end;
      until not FindNext(FindRec);
    finally
      FindClose(FindRec);
    end;
  end;
  if GetArrayLength(Names) = 0 then
    Exit;
  ForceDirectories(Dest);
  for I := 0 to GetArrayLength(Names) - 1 do
  begin
    Moved := False;
    // A scanner may hold the file for a moment.
    for Tries := 1 to 20 do
    begin
      Moved := RenameFile(Dir + '\' + Names[I], Dest + '\' + Names[I]);
      if Moved then
        Break;
      Sleep(100);
    end;
    if not Moved then
    begin
      Result := Dir + '\' + Names[I];
      Exit;
    end;
    SetArrayLength(MovedFrom, GetArrayLength(MovedFrom) + 1);
    SetArrayLength(MovedTo, GetArrayLength(MovedTo) + 1);
    MovedFrom[GetArrayLength(MovedFrom) - 1] := Dir + '\' + Names[I];
    MovedTo[GetArrayLength(MovedTo) - 1] := Dest + '\' + Names[I];
    Log(Format('Moved aside: %s', [Dir + '\' + Names[I]]));
  end;
end;

// Runs before Setup checks for files in use, so that check finds none.
function PrepareToInstall(var NeedsRestart: Boolean): String;
var
  Failed: String;
begin
  Result := '';
  DeleteTree(AsideRoot());
  AsideStamp := GetDateTimeString('yyyymmddhhnnss', #0, #0);
  Failed := MoveAside('');
  if Failed = '' then
    Failed := MoveAside('mesa');
  if Failed <> '' then
    Result := Format('%s is in use and could not be replaced. Close ThinkTerm and run Setup again.', [Failed]);
end;

// The folders this install moved files into, once they are empty.
procedure RemoveEmptyAsideDirs();
begin
  RemoveDir(AsideRoot() + '\' + AsideStamp + '\mesa');
  RemoveDir(AsideRoot() + '\' + AsideStamp);
  RemoveDir(AsideRoot());
end;

// The moved files of this install that nothing runs any more go now; the
// rest when Windows next starts.
procedure DeleteMovedFiles();
var
  I: Integer;
begin
  for I := 0 to GetArrayLength(MovedTo) - 1 do
    if not DeleteFile(MovedTo[I]) then
      RestartReplace(MovedTo[I], '');
  RemoveEmptyAsideDirs();
end;

// A cancelled or failed install puts back what it moved, wherever nothing
// new took its place, so the old build keeps working.
procedure DeinitializeSetup();
var
  I: Integer;
begin
  if Installed or (GetArrayLength(MovedFrom) = 0) then
    Exit;
  for I := GetArrayLength(MovedFrom) - 1 downto 0 do
    if not FileExists(MovedFrom[I]) then
      RenameFile(MovedTo[I], MovedFrom[I]);
  RemoveEmptyAsideDirs();
end;

procedure CurStepChanged(CurStep: TSetupStep);
begin
  if CurStep = ssPostInstall then
  begin
    EnvAddPath(ExpandConstant('{app}'));
    Installed := True;
    DeleteMovedFiles();
  end;
end;

procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
begin
  if CurUninstallStep = usPostUninstall then
    EnvRemovePath(ExpandConstant('{app}'));
end;