Changeset 3 for trunk/MainWindow.pas


Ignore:
Timestamp:
Nov 27, 2008, 12:16:27 PM (15 years ago)
Author:
george
Message:
  • Upraveno: Verze 1.2.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/MainWindow.pas

    r2 r3  
    77  Dialogs, StdCtrls, ComCtrls, ShellApi, DosCommand, Registry, Menus,
    88  CoolTrayIcon, ExtCtrls, XPMan, magrascon, magrasedt, magrasent, SHFolder,
    9   ShlObj, magrasapi, Winsock;
     9  ShlObj, magrasapi, Winsock, UTextFileStream;
    1010
    1111const
     
    1414  HomePage = 'http://www.zdechov.net/';
    1515  Email = 'robie@centrum.cz';
    16   Version = '1.1';
    17   ReleaseDate = '24.8.2006';
     16  Version = '1.2';
     17  ReleaseDate = '4.9.2006';
    1818  Creator = 'Chronosoft';
    1919  RegistryRootKey = HKEY_LOCAL_MACHINE;
     
    2121  ChangeLogFile = 'Novinky.txt';
    2222  Licence = 'Copyleft';
     23
     24  DefaultLogFileName = 'DialLog.txt';
    2325
    2426  BrowserHomepage = 'http://centrala.zdechov.net/';
     
    6264    Timer2: TTimer;
    6365    Label2: TLabel;
     66    OpenDialog1: TOpenDialog;
     67    GroupBox2: TGroupBox;
     68    CheckBox10: TCheckBox;
     69    Label3: TLabel;
     70    Edit1: TEdit;
     71    Button4: TButton;
    6472    procedure FormShow(Sender: TObject);
    6573    procedure Button2Click(Sender: TObject);
     
    7684    procedure MagRasCon1StateChanged(Sender: TObject);
    7785    procedure Timer2Timer(Sender: TObject);
     86    procedure Button4Click(Sender: TObject);
     87    procedure CheckBox10Click(Sender: TObject);
    7888  private
    7989    Connecting: Boolean;
     
    93103    function GetNetSharedFolder: Boolean;
    94104    procedure SetNetSharedFolder(const Value: Boolean);
    95     function GetDefaultGateway: string;
    96105  public
    97106    DefaultGateway: string;
     107    LogFileName: string;
    98108    FirstStart: Boolean;
    99109    LastState: Word;
     
    104114    ConnectionName: string;
    105115    NetworkTestLastUpdate: TDateTime;
     116    LogFileEnabled: Boolean;
    106117    property LocalNetworkRouting: Boolean read GetLocalNetworkRouting
    107118      write SetLocalNetworkRouting;
     
    122133    procedure AddConnection;
    123134    procedure DeleteConnection;
     135    procedure DialLog(Message: string);
    124136  end;
    125137
     
    181193  Buffer : Pointer; var ParamError :DWord) : Longint; stdcall; external 'netapi32.dll';
    182194
     195
    183196function CommonAppDataPath: string;
    184197const
     
    190203  SHGetFolderPath(0, CSIDL_COMMON_APPDATA, 0, SHGFP_TYPE_CURRENT, @Path[0]);
    191204  Result := Path;
     205end;
     206
     207function ApplicationDataFolder: string;
     208begin
     209  Result := CommonAppDataPath + '\' + Creator + '\' + ApplicationName;
     210  if not DirectoryExists(Result) then
     211    ForceDirectories(Result);
    192212end;
    193213
     
    290310  ComboBox1.ItemIndex := ComboBox1.Items.IndexOf(ConnectionName);
    291311
     312  CheckBox10.Checked := LogFileEnabled;
     313  Edit1.Text := LogFileName;
     314  Edit1.Enabled := LogFileEnabled;
     315  Button4.Enabled := LogFileEnabled;
     316
    292317  Label2.Caption := 'Brána: ' + DefaultGateway;
    293318end;
     
    309334  ZdechovNetConnection := CheckBox8.Checked;
    310335  NetSharedFolder := CheckBox9.Checked;
     336  LogFileEnabled := CheckBox10.Checked;
     337  LogFileName := Edit1.Text;
    311338
    312339  ConnectionName := ComboBox1.Items.Strings[ComboBox1.ItemIndex];
    313340  CoolTrayIcon1.HideMainForm;
    314 end;
    315 
    316 function TMainForm.GetDefaultGateway: string;
    317 var
    318   Command: TDosCommand;
    319   I: Integer;
    320   Lines2: TStringList;
    321 begin
    322   Lines2 := TStringList.Create;
    323   Result := '';
    324   Command := TDosCommand.Create(nil);
    325   with Command do try
    326     CommandLine := 'route print';
    327     OutputLines := Lines2;
    328     Execute2;
    329     for I := 0 to Lines2.Count - 1 do
    330       if Pos('choz', Lines2[I]) > 0 then
    331         Result := Trim(Copy(Lines2[I], 15, 256));
    332   finally
    333     Free;
    334     Lines2.Free;
    335   end;
    336341end;
    337342
     
    425430      if ValueExists('PingTimeout') then PingTimeout := ReadInteger('PingTimeout')
    426431        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;
    427436    finally
    428437      Free;
     
    481490      MagRasCon1.DisconnectEx(DialHandle, 0, 3000, False);
    482491
    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í');
    485494        with MagRasCon1 do begin
    486495      GetConnections;
     
    491500              PhoneNumber :=    '';
    492501            DialHandle := 0;
    493         AutoConnectEx(DialHandle);
     502        if AutoConnectEx(DialHandle) <> 0 then
     503          if Assigned(DialingLog) then DialLog('Dialling Failed - ' + MagRasCon1.StatusStr);
    494504      end;
    495505    end;
     
    516526      WriteString('NetworkTestLastUpdate', DateToStr(NetworkTestLastUpdate));
    517527      WriteInteger('PingTimeout', PingTimeout);
     528      WriteBool('LogFileEnabled', LogFileEnabled);
     529      WriteString('LogFileName', LogFileName);
    518530    finally
    519531      Free;
     
    541553    bRequireMSEncryptedPassword := False;
    542554    bSoftwareCompression := True;
     555    bCustom := True;
    543556
    544557    // device stuff
     
    655668  // see if new event, else display it
    656669  LastState := MagRasCon1.ConnectState ;
    657   DialingLog.Memo1.Lines.Add (Info + MagRasCon1.StatusStr
     670  if Assigned(DialingLog) then DialLog(Info + MagRasCon1.StatusStr
    658671    +   ' (' + IntToStr(LastState) + ')');
    659672
     
    740753end;
    741754
     755procedure TMainForm.DialLog(Message: string);
     756var
     757  LogFile: TTextFileStream;
     758begin
     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;
     770end;
     771
     772procedure TMainForm.Button4Click(Sender: TObject);
     773begin
     774  OpenDialog1.FileName := Edit1.Text;
     775  if OpenDialog1.Execute then begin
     776    Edit1.Text := OpenDialog1.FileName;
     777  end;
     778end;
     779
     780procedure TMainForm.CheckBox10Click(Sender: TObject);
     781begin
     782  Edit1.Enabled := CheckBox10.Checked;
     783  Button4.Enabled := CheckBox10.Checked;
     784end;
     785
    742786end.
Note: See TracChangeset for help on using the changeset viewer.