-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnosonet_main.pas
211 lines (174 loc) · 5.12 KB
/
nosonet_main.pas
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
202
203
204
205
206
207
208
209
210
unit nosonet_main;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, DefaultTranslator,
ComCtrls, StdCtrls, Menus, Grids, LCLTranslator, ExtCtrls, NosoNet_Language,
NosoNet_Functions, LCLType, nosonet_file ;
type
{ TForm1 }
NodeData = Packed Record
ip: string[15];
Port : int64;
end;
TForm1 = class(TForm)
ConsoleEdit: TEdit;
MainMenu1: TMainMenu;
Console: TMemo;
MenuItem1: TMenuItem;
PageControl1: TPageControl;
StringGrid1: TStringGrid;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
TimerLatido: TTimer;
procedure ConsoleEditKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure FormActivate(Sender: TObject);
procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
procedure StringGrid1Resize(Sender: TObject);
procedure TimerLatidoTimer(Sender: TObject);
private
public
end;
function StartApp():boolean;
function CloseApp():Boolean;
function Latido(): Boolean;
Procedure processLine(linetext:string);
Procedure ChangeLang(linetext:string);
CONST
DefaultNodes : String = 'DefNodes '+
'45.146.252.103:8080 '+
'194.156.88.117:8080 '+
'192.210.226.118:8080 '+
'107.172.5.8:8080 '+
'185.239.239.184:8080 '+
'109.230.238.240:8080';
AppVersion : string = '1.0';
var
Form1: TForm1;
// User options
FileOptions : TextFile;
OPT_Lang : string = 'en';
NodeList : Array of NodeData; // Stores the info of the mainnet nodes
G_ConsoleLines : TStringList; // Text to be show on console
G_ProcessLines : TStringList; // Lines to be preocessed ordered
G_LastConsoleCommand: String = ''; //
G_FirstRun : Boolean = True;
G_LangsList : String = '';
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.FormActivate(Sender: TObject);
begin
//Form1.OnActivate:= nil;
if G_FirstRun then
begin
G_FirstRun := false;
//TimerLatido.Enabled:=false;
// Code to be run at launch
Console.Lines.Add(Restring1);
if not StartApp then CloseApp;
end;
end;
/////////////////////// START APP RELATIVES /////////////////////////////////
function StartApp():boolean;
Begin
Result := false;
G_ConsoleLines := TStringlist.Create;
G_ProcessLines := TStringlist.Create;
InitLangs;
LoadDefNodes;
Result := true;
Form1.TimerLatido.Enabled:=True;
End;
/////////////////////// EXECUTION RELATIVES /////////////////////////////////
procedure TForm1.TimerLatidoTimer(Sender: TObject);
begin
TimerLatido.Enabled:=false;
Latido;
TimerLatido.Enabled:=True;
end;
function Latido(): Boolean;
Begin
if G_ProcessLines.Count>0 then
begin
processLine(G_ProcessLines[0]);
G_ProcessLines.Delete(0);
end;
if G_ConsoleLines.Count>0 then
begin
Form1.Console.Lines.Add(G_ConsoleLines[0]);
G_ConsoleLines.Delete(0);
end;
Result := true;
End;
procedure TForm1.ConsoleEditKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
var
LineText : String;
begin
LineText := ConsoleEdit.Text;
if Key=VK_RETURN then
begin
G_LastConsoleCommand := LineText;
ConsoleEdit.Text := '';
if LineText <> '' then G_ProcessLines.Add(LineText);
end;
end;
Procedure processLine(linetext:string);
var
command : string = '';
Begin
command := Parameter(LineText,0);
G_consolelines.Add(format('> %S',[linetext]));
if uppercase(command) = 'EXIT' then Form1.Close
else if uppercase(command) = 'VER' then G_consolelines.Add(Format(Restring2,[AppVersion]))
else if uppercase(command) = 'LANG' then ChangeLang(linetext)
else G_consolelines.Add(Format(Restring3,[command]));
End;
/////////////////////// PARSING CONSOLE /////////////////////////////////
Procedure ChangeLang(linetext:string);
var
language : string = '';
Begin
language := LowerCase(Parameter(linetext,1));
if language = '' then
begin
G_ConsoleLines.Add(format(Restring8,[G_LangsList]));
end
else
begin
if not fileexists('languages'+DirectorySeparator+'nosonet.'+language+'.po') then G_consolelines.Add(Format(Restring4,[language]))
else
begin
SetDefaultLang(language);
G_consolelines.Add(Format(Restring5,[LangCodeToName(Language)]));
OPT_Lang := language;
SaveOptions(true);
end;
end;
End;
/////////////////////// CLOSE APP RELATIVES /////////////////////////////////
function CloseApp():Boolean;
Begin
Result := true;
G_Consolelines.Free;
G_ProcessLines.Free;
//form1.Close;
End;
procedure TForm1.FormClose(Sender: TObject; var CloseAction: TCloseAction);
begin
CloseApp;
CloseAction:= caFree;
end;
// Adjust the size of the Sgrid for nodes
procedure TForm1.StringGrid1Resize(Sender: TObject);
begin
Stringgrid1.ColWidths[0] := Stringgrid1.Width div 5;
Stringgrid1.ColWidths[1] := Stringgrid1.Width div 10;
Stringgrid1.ColWidths[2] := Stringgrid1.Width div 10;
Stringgrid1.ColWidths[3] := Stringgrid1.Width div 10;
Stringgrid1.ColWidths[4] := Stringgrid1.Width div 10;
Stringgrid1.ColWidths[5] := Stringgrid1.Width div 10;
Stringgrid1.ColWidths[6] := Stringgrid1.Width div 10;
Stringgrid1.ColWidths[7] := Stringgrid1.Width div 10;
end;
END.