-
Notifications
You must be signed in to change notification settings - Fork 11
/
mmrelay.iss
201 lines (172 loc) · 7.36 KB
/
mmrelay.iss
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
[Setup]
// Add the custom wizard page to the installation
//WizardImageFile=wizard.bmp
//WizardSmallImageFile=smallwiz.bmp
AppName=Matrix <> Meshtastic Relay
AppVersion={#AppVersion}
DefaultDirName={userpf}\MM Relay
DefaultGroupName=MM Relay
UninstallFilesDir={app}
OutputDir=.
OutputBaseFilename=MMRelay_setup_{#AppVersion}
PrivilegesRequiredOverridesAllowed=dialog commandline
[Files]
Source: "dist\mmrelay.exe"; DestDir: "{app}"; Flags: recursesubdirs createallsubdirs; AfterInstall: AfterInstall(ExpandConstant('{app}'));
[Icons]
Name: "{group}\MM Relay"; Filename: "{app}\mmrelay.bat"
Name: "{group}\MM Relay Config"; Filename: "{app}\config.yaml"; IconFilename: "{sys}\notepad.exe"; WorkingDir: "{app}"; Parameters: "config.yaml";
[Run]
Filename: "{app}\mmrelay.bat"; Description: "Launch MM Relay"; Flags: nowait postinstall
[Code]
var
TokenInfoLabel: TLabel;
TokenInfoLink: TNewStaticText;
MatrixPage: TInputQueryWizardPage;
OverwriteConfig: TInputOptionWizardPage;
MatrixMeshtasticPage: TInputQueryWizardPage;
MeshtasticPage: TInputQueryWizardPage;
OptionsPage: TInputOptionWizardPage;
Connection: string;
procedure TokenInfoLinkClick(Sender: TObject);
var
ErrorCode: Integer;
begin
if not ShellExec('', 'open', TNewStaticText(Sender).Caption, '', SW_SHOWNORMAL, ewNoWait, ErrorCode) then
begin
// handle failure if necessary
end;
end;
procedure InitializeWizard;
begin
OverwriteConfig := CreateInputOptionPage(wpWelcome,
'Configure the relay', 'Create new configuration',
'', False, False);
MatrixPage := CreateInputQueryPage(OverwriteConfig.ID,
'Matrix Setup', 'Configure Matrix Settings',
'Enter the settings for your Matrix server.');
MeshtasticPage := CreateInputQueryPage(MatrixPage.ID,
'Meshtastic Setup', 'Configure Meshtastic Settings',
'Enter the settings for connecting with your Meshtastic radio.');
MatrixMeshtasticPage := CreateInputQueryPage(MeshtasticPage.ID,
'Matrix <> Meshtastic Setup', 'Configure Matrix <> Meshtastic Settings',
'Connect a Matrix room with a Meshtastic radio channel.');
OptionsPage := CreateInputOptionPage(MatrixMeshtasticPage.ID,
'Additional Options', 'Provide additional options',
'Set logging and broadcast options, you can keep the defaults.', False, False);
// Increase page height
WizardForm.ClientHeight := WizardForm.ClientHeight + 50;
OverwriteConfig.Add('Generate configuration (overwrite any current config files)');
OverwriteConfig.Values[0] := False;
MatrixPage.Add('Homeserver (example: https://matrix.org):', False);
MatrixPage.Add('Bot user ID (example: @mybotuser:matrix.org):', False);
MatrixPage.Add('Access token (example: syt_bWvzaGjvdD1_PwsXoZgGItImVxBIZbBK_1XZVW8):', False);
TokenInfoLabel := TLabel.Create(WizardForm);
TokenInfoLabel.Caption := 'For instructions on where to find your access token, visit:';
TokenInfoLabel.Parent := MatrixPage.Surface;
TokenInfoLabel.Left := 0;
TokenInfoLabel.Top := MatrixPage.Edits[2].Top + MatrixPage.Edits[2].Height + 8;
TokenInfoLink := TNewStaticText.Create(WizardForm);
TokenInfoLink.Caption := 'https://t2bot.io/docs/access_tokens/';
TokenInfoLink.Cursor := crHand;
TokenInfoLink.Font.Color := clBlue;
TokenInfoLink.Font.Style := [fsUnderline];
TokenInfoLink.OnClick := @TokenInfoLinkClick;
TokenInfoLink.Parent := MatrixPage.Surface;
TokenInfoLink.Left := TokenInfoLabel.Left;
TokenInfoLink.Top := TokenInfoLabel.Top + TokenInfoLabel.Height;
MatrixPage.Edits[0].Hint := 'https://example.matrix.org';
MatrixPage.Edits[1].Hint := '@botuser:example.matrix.org';
MatrixPage.Edits[2].Hint := 'reaalllllyloooooongsecretttttcodeeeeeeforrrrbot';
MeshtasticPage.Add('Connection type (network, serial, or ble):', False);
MeshtasticPage.Add('Serial port (if serial):', False);
MeshtasticPage.Add('Hostname/IP (if network):', False);
MeshtasticPage.Add('BLE address/name (if ble):', False);
MeshtasticPage.Add('Meshnet name:', False);
MeshtasticPage.Edits[0].Hint := 'network, serial, or ble';
MeshtasticPage.Edits[1].Hint := 'serial port (if serial)';
MeshtasticPage.Edits[2].Hint := 'hostname/IP (if network)';
MeshtasticPage.Edits[3].Hint := 'BLE address or name (if ble)';
MeshtasticPage.Edits[4].Hint := 'Name for radio Meshnet';
MatrixMeshtasticPage.Add('Matrix room ID/alias (example: #someroom:example.matrix.org):', False);
MatrixMeshtasticPage.Add('Meshtastic channel # (0 is primary, 1-7 secondary):', False);
MatrixMeshtasticPage.Edits[0].Hint := '!someroomid:example.matrix.org';
MatrixMeshtasticPage.Edits[1].Hint := '0-7 (default 0)';
OptionsPage.Add('Detailed logging');
OptionsPage.Add('Radio broadcasts enabled');
OptionsPage.Values[0] := True;
OptionsPage.Values[1] := True;
end;
function BoolToStr(Value: Boolean): String;
begin
if Value then
result := 'true'
else
result := 'false';
end;
{ Skips config setup pages if needed}
function ShouldSkipPage(PageID: Integer): Boolean;
begin
if PageID = OverwriteConfig.ID then
Result := False
else
Result := Not OverwriteConfig.Values[0];
end;
procedure AfterInstall(sAppDir: string);
var
config: string;
connection_type: string;
serial_port: string;
host: string;
ble_address: string;
log_level: string;
batch_file: string;
begin
If Not OverwriteConfig.Values[0] then
Exit;
if (FileExists(sAppDir + '/config.yaml')) then
begin
RenameFile(sAppDir + '/config.yaml', sAppDir + '/config-old.yaml');
end;
connection_type := MeshtasticPage.Values[0];
serial_port := MeshtasticPage.Values[1];
host := MeshtasticPage.Values[2];
ble_address := MeshtasticPage.Values[3];
if OptionsPage.Values[0] then
begin
log_level := 'debug';
end
else
begin
log_level := 'info';
end;
config := 'matrix:' + #13#10 +
' homeserver: "' + MatrixPage.Values[0] + '"' + #13#10 +
' bot_user_id: "' + MatrixPage.Values[1] + '"' + #13#10 +
' access_token: "' + MatrixPage.Values[2] + '"' + #13#10 +
'matrix_rooms:' + #13#10 +
' - id: "' + MatrixMeshtasticPage.Values[0] + '"' + #13#10 +
' meshtastic_channel: ' + MatrixMeshtasticPage.Values[1] + #13#10 +
'meshtastic:' + #13#10 +
' connection_type: "' + connection_type + '"' + #13#10;
if connection_type = 'serial' then
config := config + ' serial_port: "' + serial_port + '"' + #13#10
else if connection_type = 'network' then
config := config + ' host: "' + host + '"' + #13#10
else if connection_type = 'ble' then
config := config + ' ble_address: "' + ble_address + '"' + #13#10;
config := config + ' meshnet_name: "' + MeshtasticPage.Values[4] + '"' + #13#10 +
' broadcast_enabled: ' + BoolToStr(OptionsPage.Values[1]) + #13#10 +
'logging:' + #13#10 +
' level: "' + log_level + '"' + #13#10 +
'plugins:' + #13#10;
if Not SaveStringToFile(sAppDir + '/config.yaml', config, false) then
begin
MsgBox('Could not create config file "config.yaml". Close any applications that may have it open and re-run setup', mbInformation, MB_OK);
end;
batch_file := '"' + sAppDir + '\mmrelay.exe" config.yaml ' + #13#10 +
'pause';
if Not SaveStringToFile(sAppDir + '/mmrelay.bat', batch_file, false) then
begin
MsgBox('Could not create batch file "relay.bat". Close any applications that may have it open and re-run setup', mbInformation, MB_OK);
end;
end;