aboutsummaryrefslogtreecommitdiff
path: root/Source/configureunit.pas
blob: 321efc56721ae5e22a6f764cd0a479998d63a46a (plain)
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
unit configureunit;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ExtCtrls, ComCtrls, Buttons, FileCtrl;

type
  Tconfigure = class(TForm)
    PageControl1: TPageControl;
    TSConnections: TTabSheet;
    Panel1: TPanel;
    ButtonOk: TButton;
    ButtonCancel: TButton;
    Label1: TLabel;
    EditPdHost: TEdit;
    Label2: TLabel;
    EditPdReceivePort: TEdit;
    Label3: TLabel;
    EditPdSendPort: TEdit;
    Label4: TLabel;
    Label5: TLabel;
    EditFsPort: TEdit;
    CBEnableFSConns: TCheckBox;
    TSGeneral: TTabSheet;
    CBDockMain: TCheckBox;
    TSFolders: TTabSheet;
    Label6: TLabel;
    EditFSFolder: TEdit;
    Memo1: TMemo;
    DirectoryListBox1: TDirectoryListBox;
    DriveComboBox1: TDriveComboBox;
    procedure ButtonCancelClick(Sender: TObject);
    procedure ButtonOkClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure DriveComboBox1Change(Sender: TObject);
    procedure DirectoryListBox1Change(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    procedure Execute;
  end;

var
  configure: Tconfigure;

implementation

uses
  Registry,
  mainunit;

{$R *.DFM}

procedure Tconfigure.ButtonOkClick(Sender: TObject);
var
  Reg: TRegistry;
begin
  Reg := TRegistry.Create;
  Reg.RootKey := HKEY_CURRENT_USER;

  main.PdHost := EditPdHost.Text;
  main.PdReceivePort := StrToInt(EditPdReceivePort.Text);
  main.PdSendPort := StrToInt(EditPdSendPort.Text);
  main.FSPort := StrToInt(EditFsPort.Text);
  main.EnableFSConns := CBEnableFSConns.Checked;
  main.DockMain := CBDockMain.Checked;
{$IFDEF FSDLL}
  if main.FSFolder <> EditFSFolder.Text then begin
    main.FSFolder := EditFSFolder.Text;
    main.Plugins.Clear;
    main.Plugins.ReLoad;
    main.SearchPath.Add(main.FSFolder);
  end;
{$ENDIF}

  try
    if Reg.OpenKey('\Software\Framestein', True) then begin
      Reg.WriteString('PdHost', main.PdHost);
      Reg.WriteInteger('PDReceivePort', main.PDReceivePort);
      Reg.WriteInteger('PDSendPort', main.PDSendPort);
      Reg.WriteInteger('FSPort', main.FSPort);
      Reg.WriteBool('EnableFSConns', main.EnableFSConns);
      Reg.WriteBool('DockMain', main.DockMain);
{$IFDEF FSDLL}
      Reg.WriteString('FSFolder', main.FSFolder);
{$ENDIF}
    end;
  except
  end;

  Reg.CloseKey;
  Reg.Free;

  main.ss1.Active := False;
  main.ss1.Port := main.PDReceivePort;
  main.ss1.Active := True;

  main.csToPd.Active := False;
  main.csToPd.Host := main.PdHost;
  main.csToPd.Port := main.PdSendPort;
  main.csToPd.Active := True;

  main.ssfs.Active := False;
  main.ssfs.Port := main.FSPort;
  main.ssfs.Active := main.EnableFSConns;

  ModalResult := mrOk;
end;

procedure Tconfigure.ButtonCancelClick(Sender: TObject);
begin
  ModalResult := mrCancel;
end;

procedure Tconfigure.Execute;
begin
{$IFDEF FSDLL}
  TSFolders.TabVisible := True;
  TSFolders.Visible := True;
{$ELSE}
  TSFolders.TabVisible := False;
  TSFolders.Visible := False;
{$ENDIF}

  // load values from main
  EditPdHost.Text := main.PdHost;
  if EditPdHost.Text='' then EditPdHost.Text:='localhost';
  EditPdReceivePort.Text := IntToStr(main.PdReceivePort);
  EditPdSendPort.Text := IntToStr(main.PdSendPort);
  EditFsPort.Text := IntToStr(main.FSPort);
  CBEnableFSConns.Checked := main.EnableFSConns;
  CBDockMain.Checked := main.DockMain;
  EditFSFolder.Text := main.FSFolder;
  // show
  ShowModal;
end;

procedure Tconfigure.FormCreate(Sender: TObject);
begin
  if main.RunConfig then
    Execute;
end;

procedure Tconfigure.DriveComboBox1Change(Sender: TObject);
begin
  DirectoryListBox1.Drive :=
   (Sender as TDriveComboBox).Drive;
end;

procedure Tconfigure.DirectoryListBox1Change(Sender: TObject);
begin
  EditFSFolder.Text :=
   (Sender as TDirectoryListBox).Directory;
end;

end.