Changeset 3 for trunk/MainWindow.pas
- Timestamp:
- Nov 27, 2008, 12:16:27 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MainWindow.pas
r2 r3 7 7 Dialogs, StdCtrls, ComCtrls, ShellApi, DosCommand, Registry, Menus, 8 8 CoolTrayIcon, ExtCtrls, XPMan, magrascon, magrasedt, magrasent, SHFolder, 9 ShlObj, magrasapi, Winsock ;9 ShlObj, magrasapi, Winsock, UTextFileStream; 10 10 11 11 const … … 14 14 HomePage = 'http://www.zdechov.net/'; 15 15 Email = 'robie@centrum.cz'; 16 Version = '1. 1';17 ReleaseDate = ' 24.8.2006';16 Version = '1.2'; 17 ReleaseDate = '4.9.2006'; 18 18 Creator = 'Chronosoft'; 19 19 RegistryRootKey = HKEY_LOCAL_MACHINE; … … 21 21 ChangeLogFile = 'Novinky.txt'; 22 22 Licence = 'Copyleft'; 23 24 DefaultLogFileName = 'DialLog.txt'; 23 25 24 26 BrowserHomepage = 'http://centrala.zdechov.net/'; … … 62 64 Timer2: TTimer; 63 65 Label2: TLabel; 66 OpenDialog1: TOpenDialog; 67 GroupBox2: TGroupBox; 68 CheckBox10: TCheckBox; 69 Label3: TLabel; 70 Edit1: TEdit; 71 Button4: TButton; 64 72 procedure FormShow(Sender: TObject); 65 73 procedure Button2Click(Sender: TObject); … … 76 84 procedure MagRasCon1StateChanged(Sender: TObject); 77 85 procedure Timer2Timer(Sender: TObject); 86 procedure Button4Click(Sender: TObject); 87 procedure CheckBox10Click(Sender: TObject); 78 88 private 79 89 Connecting: Boolean; … … 93 103 function GetNetSharedFolder: Boolean; 94 104 procedure SetNetSharedFolder(const Value: Boolean); 95 function GetDefaultGateway: string;96 105 public 97 106 DefaultGateway: string; 107 LogFileName: string; 98 108 FirstStart: Boolean; 99 109 LastState: Word; … … 104 114 ConnectionName: string; 105 115 NetworkTestLastUpdate: TDateTime; 116 LogFileEnabled: Boolean; 106 117 property LocalNetworkRouting: Boolean read GetLocalNetworkRouting 107 118 write SetLocalNetworkRouting; … … 122 133 procedure AddConnection; 123 134 procedure DeleteConnection; 135 procedure DialLog(Message: string); 124 136 end; 125 137 … … 181 193 Buffer : Pointer; var ParamError :DWord) : Longint; stdcall; external 'netapi32.dll'; 182 194 195 183 196 function CommonAppDataPath: string; 184 197 const … … 190 203 SHGetFolderPath(0, CSIDL_COMMON_APPDATA, 0, SHGFP_TYPE_CURRENT, @Path[0]); 191 204 Result := Path; 205 end; 206 207 function ApplicationDataFolder: string; 208 begin 209 Result := CommonAppDataPath + '\' + Creator + '\' + ApplicationName; 210 if not DirectoryExists(Result) then 211 ForceDirectories(Result); 192 212 end; 193 213 … … 290 310 ComboBox1.ItemIndex := ComboBox1.Items.IndexOf(ConnectionName); 291 311 312 CheckBox10.Checked := LogFileEnabled; 313 Edit1.Text := LogFileName; 314 Edit1.Enabled := LogFileEnabled; 315 Button4.Enabled := LogFileEnabled; 316 292 317 Label2.Caption := 'Brána: ' + DefaultGateway; 293 318 end; … … 309 334 ZdechovNetConnection := CheckBox8.Checked; 310 335 NetSharedFolder := CheckBox9.Checked; 336 LogFileEnabled := CheckBox10.Checked; 337 LogFileName := Edit1.Text; 311 338 312 339 ConnectionName := ComboBox1.Items.Strings[ComboBox1.ItemIndex]; 313 340 CoolTrayIcon1.HideMainForm; 314 end;315 316 function TMainForm.GetDefaultGateway: string;317 var318 Command: TDosCommand;319 I: Integer;320 Lines2: TStringList;321 begin322 Lines2 := TStringList.Create;323 Result := '';324 Command := TDosCommand.Create(nil);325 with Command do try326 CommandLine := 'route print';327 OutputLines := Lines2;328 Execute2;329 for I := 0 to Lines2.Count - 1 do330 if Pos('choz', Lines2[I]) > 0 then331 Result := Trim(Copy(Lines2[I], 15, 256));332 finally333 Free;334 Lines2.Free;335 end;336 341 end; 337 342 … … 425 430 if ValueExists('PingTimeout') then PingTimeout := ReadInteger('PingTimeout') 426 431 else PingTimeout := 200; 432 if ValueExists('LogFileEnabled') then LogFileEnabled := ReadBool('LogFileEnabled') 433 else LogFileEnabled := False; 434 if ValueExists('LogFileName') then LogFileName := ReadString('LogFileName') 435 else LogFileName := ApplicationDataFolder + '\' + DefaultLogFileName; 427 436 finally 428 437 Free; … … 481 490 MagRasCon1.DisconnectEx(DialHandle, 0, 3000, False); 482 491 483 DialingLog.Memo1.Lines.Add('');484 DialingLog.Memo1.Lines.Add(DateTimeToStr(Now) + ': Vytáèím pøípojení');492 if Assigned(DialingLog) then DialLog(''); 493 if Assigned(DialingLog) then DialLog(DateTimeToStr(Now) + ': Vytáèím pøípojení'); 485 494 with MagRasCon1 do begin 486 495 GetConnections; … … 491 500 PhoneNumber := ''; 492 501 DialHandle := 0; 493 AutoConnectEx(DialHandle); 502 if AutoConnectEx(DialHandle) <> 0 then 503 if Assigned(DialingLog) then DialLog('Dialling Failed - ' + MagRasCon1.StatusStr); 494 504 end; 495 505 end; … … 516 526 WriteString('NetworkTestLastUpdate', DateToStr(NetworkTestLastUpdate)); 517 527 WriteInteger('PingTimeout', PingTimeout); 528 WriteBool('LogFileEnabled', LogFileEnabled); 529 WriteString('LogFileName', LogFileName); 518 530 finally 519 531 Free; … … 541 553 bRequireMSEncryptedPassword := False; 542 554 bSoftwareCompression := True; 555 bCustom := True; 543 556 544 557 // device stuff … … 655 668 // see if new event, else display it 656 669 LastState := MagRasCon1.ConnectState ; 657 DialingLog.Memo1.Lines.Add(Info + MagRasCon1.StatusStr670 if Assigned(DialingLog) then DialLog(Info + MagRasCon1.StatusStr 658 671 + ' (' + IntToStr(LastState) + ')'); 659 672 … … 740 753 end; 741 754 755 procedure TMainForm.DialLog(Message: string); 756 var 757 LogFile: TTextFileStream; 758 begin 759 if Assigned(DialingLog) then DialingLog.Memo1.Lines.Add(Message); 760 761 if LogFileEnabled then 762 try 763 if FileExists(LogFileName) then LogFile := TTextFileStream.Create(LogFileName, fmOpenReadWrite) 764 else LogFile := TTextFileStream.Create(LogFileName, fmCreate); 765 LogFile.Seek(0, soFromEnd); 766 LogFile.WriteLn(Message); 767 finally 768 LogFile.Free; 769 end; 770 end; 771 772 procedure TMainForm.Button4Click(Sender: TObject); 773 begin 774 OpenDialog1.FileName := Edit1.Text; 775 if OpenDialog1.Execute then begin 776 Edit1.Text := OpenDialog1.FileName; 777 end; 778 end; 779 780 procedure TMainForm.CheckBox10Click(Sender: TObject); 781 begin 782 Edit1.Enabled := CheckBox10.Checked; 783 Button4.Enabled := CheckBox10.Checked; 784 end; 785 742 786 end.
Note:
See TracChangeset
for help on using the changeset viewer.