Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit UAtualizador;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, ExtCtrls,
- StdCtrls, Buttons, ComCtrls, WiniNet, IdHTTP, IdAntiFreezeBase,
- IdAntiFreeze, Menus, UTransEdit;
- type
- TForm1 = class(TForm)
- Timer1: TTimer;
- PanelFundo: TPanel;
- Panel_Botoes: TPanel;
- Panel_Status: TPanel;
- Panel_Dados: TPanel;
- Panel_Conexao: TPanel;
- Panel_Titulo: TPanel;
- Label1: TLabel;
- Label2: TLabel;
- Label3: TLabel;
- SpeedButton1: TSpeedButton;
- Label4: TLabel;
- Label5: TLabel;
- Label6: TLabel;
- Label7: TLabel;
- GroupBox1: TGroupBox;
- GroupBox2: TGroupBox;
- Label8: TLabel;
- ProgressBar1: TProgressBar;
- Label_Internet: TLabel;
- IdHTTP1: TIdHTTP;
- IdAntiFreeze1: TIdAntiFreeze;
- SpeedButton2: TSpeedButton;
- Label_status1: TLabel;
- Label_Status2: TLabel;
- SpeedButton3: TSpeedButton;
- PopupMenu1: TPopupMenu;
- CriarArquivoTXTAtualizao1: TMenuItem;
- MyEdit_URL: TMyEditTransTwo;
- MyEditTransTwo2: TMyEditTransTwo;
- MyEditTransTwo3: TMyEditTransTwo;
- procedure SpeedButton1Click(Sender: TObject);
- procedure Panel_TituloMouseDown(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- procedure Label2MouseDown(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- procedure Label1MouseDown(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- procedure Label3MouseDown(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- procedure Timer1Timer(Sender: TObject);
- procedure SpeedButton2Click(Sender: TObject);
- procedure IdHTTP1WorkBegin(ASender: TObject; AWorkMode: TWorkMode;
- AWorkCountMax: Int64);
- procedure IdHTTP1Work(ASender: TObject; AWorkMode: TWorkMode;
- AWorkCount: Int64);
- procedure IdHTTP1WorkEnd(ASender: TObject; AWorkMode: TWorkMode);
- procedure SpeedButton3Click(Sender: TObject);
- procedure CriarArquivoTXTAtualizao1Click(Sender: TObject);
- private
- function StatusInternet: Boolean;
- function ReturnPercentage(ValueMaximum, ValueCurrent: real): string;
- function ReturnKiloBytes(ValueCurrent: real): string;
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- Form1: TForm1;
- implementation
- {$R *.dfm}
- procedure TForm1.CriarArquivoTXTAtualizao1Click(Sender: TObject);
- var
- fileTXT : TextFile;
- Path : string;
- i, n: integer;
- begin
- Path:='C:\Trabalho\Atualizar_SisCom.TXT';
- if FileExists(Path) then
- begin
- DeleteFile(Path); //apagar o arquivo
- end;
- try
- AssignFile(fileTXT, Path);
- finally
- Rewrite(fileTXT); //abre o arquivo para escrita
- Writeln(fileTXT, 'Arquivo 1;http://maxirecibo.infus.inf.br/bin/setupx32_maxirecibo.exe');
- Writeln(fileTXT, 'Arquivo 2;http://maxirecibo.infus.inf.br/bin/setupx32_maxirecibo.exe');
- Writeln(fileTXT, 'Arquivo 3;http://maxirecibo.infus.inf.br/bin/setupx32_maxirecibo.exe');
- Writeln(fileTXT, 'Arquivo 4;http://maxirecibo.infus.inf.br/bin/setupx32_maxirecibo.exe');
- Writeln(fileTXT, 'Arquivo 5;http://maxirecibo.infus.inf.br/bin/setupx32_maxirecibo.exe');
- Closefile(fileTXT); //fecha o handle de arquivo
- end;
- end;
- procedure TForm1.IdHTTP1Work(ASender: TObject; AWorkMode: TWorkMode;
- AWorkCount: Int64);
- begin
- progressbar1.Position := AWorkCount;
- Label_Status1.Caption := 'Baixando ... ' + ReturnKiloBytes(AWorkCount);
- Label_Status2.Caption := 'Download em ... ' + ReturnPercentage(progressbar1.Max, AWorkCount);
- end;
- procedure TForm1.IdHTTP1WorkBegin(ASender: TObject; AWorkMode: TWorkMode;
- AWorkCountMax: Int64);
- begin
- progressbar1.Max := AWorkCountMax;
- end;
- procedure TForm1.IdHTTP1WorkEnd(ASender: TObject; AWorkMode: TWorkMode);
- begin
- progressbar1.Position := 0;
- Label_Status1.Caption := 'Download Finalizado ...';
- Label_Status2.Caption := 'Download Finalizado ...';
- end;
- procedure TForm1.Label1MouseDown(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- const
- SC_DRAGMOVE = $F012;
- begin
- if Button = mbleft then
- begin
- ReleaseCapture;
- Perform(wm_SysCommand, sc_DragMove, 0);
- end;
- end;
- procedure TForm1.Label2MouseDown(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- const
- SC_DRAGMOVE = $F012;
- begin
- if Button = mbleft then
- begin
- ReleaseCapture;
- Perform(wm_SysCommand, sc_DragMove, 0);
- end;
- end;
- procedure TForm1.Label3MouseDown(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- const
- SC_DRAGMOVE = $F012;
- begin
- if Button = mbleft then
- begin
- ReleaseCapture;
- Perform(wm_SysCommand, sc_DragMove, 0);
- end;
- end;
- procedure TForm1.Panel_TituloMouseDown(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- const
- SC_DRAGMOVE = $F012;
- begin
- if Button = mbleft then
- begin
- ReleaseCapture;
- Perform(wm_SysCommand, sc_DragMove, 0);
- end;
- end;
- function TForm1.ReturnKiloBytes(ValueCurrent: real): string;
- var
- FResult : real;
- begin
- FResult := ((ValueCurrent / 1024) / 1024);
- Result := FormatFloat('0.000 KBs', FResult);
- end;
- function TForm1.ReturnPercentage(ValueMaximum, ValueCurrent: real): string;
- var
- FResult: Real;
- begin
- FResult := ((ValueCurrent * 100) / ValueMaximum);
- Result := FormatFloat('0%', FResult);
- end;
- procedure TForm1.SpeedButton1Click(Sender: TObject);
- begin
- Application.Terminate;
- end;
- procedure TForm1.SpeedButton2Click(Sender: TObject);
- begin
- IdHTTP1.Disconnect;
- Label_status1.Caption:='Download Cancelado';
- Label_status2.Caption:='Download Cancelado';
- end;
- procedure TForm1.SpeedButton3Click(Sender: TObject);
- var
- fileDownload : TFileStream;
- begin
- fileDownload := TFileStream.Create(ExtractFileExt(MyEdit_URL.Text), fmCreate);
- try
- IdHTTP1.Get(MyEdit_URL.Text, fileDownload);
- finally
- FreeAndNil(fileDownload);
- end;
- end;
- function TForm1.StatusInternet: Boolean;
- var estado : Dword;
- begin
- try
- if not InternetGetConnectedState(@estado, 0) then
- Result := False
- else
- begin
- if (estado and INTERNET_CONNECTION_LAN <> 0) OR
- (estado and INTERNET_CONNECTION_MODEM <> 0) or
- (Estado and INTERNET_CONNECTION_PROXY <> 0) then
- Result := True;
- end;
- except
- Result := False
- end;
- end;
- procedure TForm1.Timer1Timer(Sender: TObject);
- begin
- if not StatusInternet then
- begin
- Label_Internet.Font.Color := clRed;
- Label_Internet.Caption := 'OFFLINE';
- end
- else
- begin
- Label_Internet.Font.Color := clGreen;
- Label_Internet.Caption := 'ONLINE';
- end;
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement