hxClientApp.pas
上传用户:youjie821
上传日期:2013-01-27
资源大小:459k
文件大小:4k
- unit hxClientApp;
- interface
- uses
- hxUpdate, ComCtrls, IniFiles, SysUtils;
- type
- TConnectType = (ctDirect, ctProxy);
- ThxClientSettings = class(TObject)
- private
- FUseProxy: Boolean;
- FServerPort: Integer;
- FProxyPort: Integer;
- FServerIP: string;
- FProxyUser: string;
- FIniFileName: string;
- FProxyIP: string;
- FProxyPass: string;
- FServerUser: string;
- FServerPass: string;
- FConnectType: TConnectType;
- procedure SaveSettings;
- procedure LoadSettings;
- public
- constructor Create(IniFileName: string);
- destructor Destroy; override;
- property ConnectType: TConnectType read FConnectType write FConnectType;
- property ServerIP: string read FServerIP write FServerIP;
- property ServerPort: Integer read FServerPort write FServerPort;
- property ServerUser: string read FServerUser write FServerUser;
- property ServerPass: string read FServerPass write FServerPass;
- property UseProxy: Boolean read FUseProxy write FUseProxy;
- property ProxyIP: string read FProxyIP write FProxyIP;
- property ProxyPort: Integer read FProxyPort write FProxyPort;
- property ProxyUser: string read FProxyUser write FProxyUser;
- property ProxyPass: string read FProxyPass write FProxyPass;
- end;
- ThxClientApp = class(TObject)
- private
- FUpdateClient: ThxUpdateClient;
- FSettings: ThxClientSettings;
- public
- constructor Create(ProjectName: string);
- destructor Destroy; override;
- property UpdateClient: ThxUpdateClient read FUpdateClient;
- property Settings: ThxClientSettings read FSettings;
- end;
- function GetClientApp: ThxClientApp;
-
- var
- G_ClientApp: ThxClientApp = nil;
- implementation
- function GetClientApp: ThxClientApp;
- begin
- if not Assigned(G_ClientApp) then
- raise Exception.Create('无法获取ClientApp,类尚未创建!');
- Result:= G_ClientApp;
- end;
- { ThxClientApp }
- constructor ThxClientApp.Create(ProjectName: string);
- begin
- FSettings:= ThxClientSettings.Create(ExtractFilePath(ParamStr(0)) + 'Client.ini');
- with FSettings do
- begin
- FUpdateClient:= ThxUpdateClient.Create(ProjectName);
- with FUpdateClient.ProxyInfo do
- begin
- Enabled:= UseProxy;
- IP:= ProxyIP;
- Port:= ProxyPort;
- Username:= ProxyUser;
- Password:= ProxyPass;
- end;
- end;
- end;
- destructor ThxClientApp.Destroy;
- begin
- FUpdateClient.Destroy;
- FSettings.Free;
- inherited Destroy;
- end;
- { ThxClientSettings }
- constructor ThxClientSettings.Create(IniFileName: string);
- begin
- FIniFileName:= IniFileName;
- LoadSettings;
- end;
- destructor ThxClientSettings.Destroy;
- begin
- SaveSettings;
- inherited Destroy;
- end;
- procedure ThxClientSettings.LoadSettings;
- var
- Ini: TIniFile;
- begin
- Ini:= TIniFile.Create(FIniFileName);
- try
- FConnectType:= TConnectType(Ini.ReadInteger('Server', 'ConnectType', 0));
- FServerIP:= Ini.ReadString('Server', 'Address', '');
- FServerPort:= Ini.ReadInteger('Server', 'Port', 9901);
- FServerUser:= Ini.ReadString('Server', 'Username', '');
- FServerPass:= Ini.ReadString('Server', 'Password', '');
- FUseProxy:= Ini.ReadBool('Server', 'UseProxy', False);
- FProxyIP:= Ini.ReadString('Server', 'ProxyIP', '');
- FProxyPort:= Ini.ReadInteger('Server', 'ProxyPort', 1080);
- FProxyUser:= Ini.ReadString('Server', 'ProxyUser', '');
- FProxyPass:= Ini.ReadString('Server', 'ProxyPass', '');
- finally
- Ini.Free;
- end;
- end;
- procedure ThxClientSettings.SaveSettings;
- var
- Ini: TIniFile;
- begin
- Ini:= TIniFile.Create(FIniFileName);
- try
- Ini.WriteInteger('Server', 'ConnectType', Integer(FConnectType));
- Ini.WriteString('Server', 'Address', FServerIP);
- Ini.WriteInteger('Server', 'Port', FServerPort);
- Ini.WriteString('Server', 'Username', FServerUser);
- Ini.WriteString('Server', 'Password', FServerPass);
- Ini.WriteBool('Server', 'UseProxy', FUseProxy);
- Ini.WriteString('Server', 'ProxyIP', FProxyIP);
- Ini.WriteInteger('Server', 'ProxyPort', FProxyPort);
- Ini.WriteString('Server', 'ProxyUser', FProxyUser);
- Ini.WriteString('Server', 'ProxyPass', FProxyPass);
- finally
- Ini.Free;
- end;
- end;
- end.