Advertisement
jpfassis

Atualizador Usando Indy - Delphi

Jun 19th, 2020
1,922
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 6.63 KB | None | 0 0
  1. unit UAtualizador;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  7.   Dialogs, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, ExtCtrls,
  8.   StdCtrls, Buttons, ComCtrls, WiniNet, IdHTTP, IdAntiFreezeBase,
  9.   IdAntiFreeze, Menus, UTransEdit;
  10.  
  11. type
  12.   TForm1 = class(TForm)
  13.     Timer1: TTimer;
  14.     PanelFundo: TPanel;
  15.     Panel_Botoes: TPanel;
  16.     Panel_Status: TPanel;
  17.     Panel_Dados: TPanel;
  18.     Panel_Conexao: TPanel;
  19.     Panel_Titulo: TPanel;
  20.     Label1: TLabel;
  21.     Label2: TLabel;
  22.     Label3: TLabel;
  23.     SpeedButton1: TSpeedButton;
  24.     Label4: TLabel;
  25.     Label5: TLabel;
  26.     Label6: TLabel;
  27.     Label7: TLabel;
  28.     GroupBox1: TGroupBox;
  29.     GroupBox2: TGroupBox;
  30.     Label8: TLabel;
  31.     ProgressBar1: TProgressBar;
  32.     Label_Internet: TLabel;
  33.     IdHTTP1: TIdHTTP;
  34.     IdAntiFreeze1: TIdAntiFreeze;
  35.     SpeedButton2: TSpeedButton;
  36.     Label_status1: TLabel;
  37.     Label_Status2: TLabel;
  38.     SpeedButton3: TSpeedButton;
  39.     PopupMenu1: TPopupMenu;
  40.     CriarArquivoTXTAtualizao1: TMenuItem;
  41.     MyEdit_URL: TMyEditTransTwo;
  42.     MyEditTransTwo2: TMyEditTransTwo;
  43.     MyEditTransTwo3: TMyEditTransTwo;
  44.     procedure SpeedButton1Click(Sender: TObject);
  45.     procedure Panel_TituloMouseDown(Sender: TObject; Button: TMouseButton;
  46.       Shift: TShiftState; X, Y: Integer);
  47.     procedure Label2MouseDown(Sender: TObject; Button: TMouseButton;
  48.       Shift: TShiftState; X, Y: Integer);
  49.     procedure Label1MouseDown(Sender: TObject; Button: TMouseButton;
  50.       Shift: TShiftState; X, Y: Integer);
  51.     procedure Label3MouseDown(Sender: TObject; Button: TMouseButton;
  52.       Shift: TShiftState; X, Y: Integer);
  53.     procedure Timer1Timer(Sender: TObject);
  54.     procedure SpeedButton2Click(Sender: TObject);
  55.     procedure IdHTTP1WorkBegin(ASender: TObject; AWorkMode: TWorkMode;
  56.       AWorkCountMax: Int64);
  57.     procedure IdHTTP1Work(ASender: TObject; AWorkMode: TWorkMode;
  58.       AWorkCount: Int64);
  59.     procedure IdHTTP1WorkEnd(ASender: TObject; AWorkMode: TWorkMode);
  60.     procedure SpeedButton3Click(Sender: TObject);
  61.     procedure CriarArquivoTXTAtualizao1Click(Sender: TObject);
  62.   private
  63.   function StatusInternet: Boolean;
  64.   function ReturnPercentage(ValueMaximum, ValueCurrent: real): string;
  65.   function ReturnKiloBytes(ValueCurrent: real): string;
  66.     { Private declarations }
  67.   public
  68.     { Public declarations }
  69.   end;
  70.  
  71. var
  72.   Form1: TForm1;
  73.  
  74. implementation
  75.  
  76. {$R *.dfm}
  77.  
  78. procedure TForm1.CriarArquivoTXTAtualizao1Click(Sender: TObject);
  79. var
  80. fileTXT : TextFile;
  81. Path : string;
  82. i, n: integer;
  83. begin
  84.  
  85. Path:='C:\Trabalho\Atualizar_SisCom.TXT';
  86.  
  87. if FileExists(Path) then
  88. begin
  89.   DeleteFile(Path); //apagar o arquivo
  90. end;
  91.  
  92.   try
  93.     AssignFile(fileTXT, Path);
  94.   finally
  95.     Rewrite(fileTXT); //abre o arquivo para escrita
  96.     Writeln(fileTXT, 'Arquivo 1;http://maxirecibo.infus.inf.br/bin/setupx32_maxirecibo.exe');
  97.     Writeln(fileTXT, 'Arquivo 2;http://maxirecibo.infus.inf.br/bin/setupx32_maxirecibo.exe');
  98.     Writeln(fileTXT, 'Arquivo 3;http://maxirecibo.infus.inf.br/bin/setupx32_maxirecibo.exe');
  99.     Writeln(fileTXT, 'Arquivo 4;http://maxirecibo.infus.inf.br/bin/setupx32_maxirecibo.exe');
  100.     Writeln(fileTXT, 'Arquivo 5;http://maxirecibo.infus.inf.br/bin/setupx32_maxirecibo.exe');
  101.     Closefile(fileTXT); //fecha o handle de arquivo
  102.   end;
  103.  
  104. end;
  105.  
  106. procedure TForm1.IdHTTP1Work(ASender: TObject; AWorkMode: TWorkMode;
  107.   AWorkCount: Int64);
  108. begin
  109. progressbar1.Position := AWorkCount;
  110. Label_Status1.Caption    := 'Baixando ... ' + ReturnKiloBytes(AWorkCount);
  111. Label_Status2.Caption := 'Download em ... ' + ReturnPercentage(progressbar1.Max, AWorkCount);
  112. end;
  113.  
  114. procedure TForm1.IdHTTP1WorkBegin(ASender: TObject; AWorkMode: TWorkMode;
  115.   AWorkCountMax: Int64);
  116. begin
  117. progressbar1.Max := AWorkCountMax;
  118. end;
  119.  
  120. procedure TForm1.IdHTTP1WorkEnd(ASender: TObject; AWorkMode: TWorkMode);
  121. begin
  122. progressbar1.Position := 0;
  123. Label_Status1.Caption    := 'Download Finalizado ...';
  124. Label_Status2.Caption    := 'Download Finalizado ...';
  125. end;
  126.  
  127. procedure TForm1.Label1MouseDown(Sender: TObject; Button: TMouseButton;
  128.   Shift: TShiftState; X, Y: Integer);
  129. const
  130.   SC_DRAGMOVE = $F012;
  131. begin
  132.   if Button = mbleft then
  133.   begin
  134.     ReleaseCapture;
  135.     Perform(wm_SysCommand, sc_DragMove, 0);
  136.   end;
  137.  
  138. end;
  139.  
  140. procedure TForm1.Label2MouseDown(Sender: TObject; Button: TMouseButton;
  141.   Shift: TShiftState; X, Y: Integer);
  142. const
  143.   SC_DRAGMOVE = $F012;
  144. begin
  145.   if Button = mbleft then
  146.   begin
  147.     ReleaseCapture;
  148.     Perform(wm_SysCommand, sc_DragMove, 0);
  149.   end;
  150.  
  151. end;
  152.  
  153. procedure TForm1.Label3MouseDown(Sender: TObject; Button: TMouseButton;
  154.   Shift: TShiftState; X, Y: Integer);
  155. const
  156.   SC_DRAGMOVE = $F012;
  157. begin
  158.   if Button = mbleft then
  159.   begin
  160.     ReleaseCapture;
  161.     Perform(wm_SysCommand, sc_DragMove, 0);
  162.   end;
  163.  
  164. end;
  165.  
  166. procedure TForm1.Panel_TituloMouseDown(Sender: TObject; Button: TMouseButton;
  167.   Shift: TShiftState; X, Y: Integer);
  168. const
  169.   SC_DRAGMOVE = $F012;
  170. begin
  171.   if Button = mbleft then
  172.   begin
  173.     ReleaseCapture;
  174.     Perform(wm_SysCommand, sc_DragMove, 0);
  175.   end;
  176.  
  177. end;
  178.  
  179. function TForm1.ReturnKiloBytes(ValueCurrent: real): string;
  180. var
  181. FResult : real;
  182. begin
  183. FResult := ((ValueCurrent / 1024) / 1024);
  184. Result    := FormatFloat('0.000 KBs', FResult);
  185. end;
  186.  
  187. function TForm1.ReturnPercentage(ValueMaximum, ValueCurrent: real): string;
  188. var
  189. FResult: Real;
  190. begin
  191. FResult := ((ValueCurrent * 100) / ValueMaximum);
  192. Result    := FormatFloat('0%', FResult);
  193. end;
  194.  
  195. procedure TForm1.SpeedButton1Click(Sender: TObject);
  196. begin
  197. Application.Terminate;
  198. end;
  199.  
  200. procedure TForm1.SpeedButton2Click(Sender: TObject);
  201. begin
  202. IdHTTP1.Disconnect;
  203. Label_status1.Caption:='Download Cancelado';
  204. Label_status2.Caption:='Download Cancelado';
  205. end;
  206.  
  207. procedure TForm1.SpeedButton3Click(Sender: TObject);
  208. var
  209. fileDownload : TFileStream;
  210. begin
  211. fileDownload := TFileStream.Create(ExtractFileExt(MyEdit_URL.Text), fmCreate);
  212.  
  213. try
  214. IdHTTP1.Get(MyEdit_URL.Text, fileDownload);
  215. finally
  216. FreeAndNil(fileDownload);
  217. end;
  218.  
  219. end;
  220.  
  221. function TForm1.StatusInternet: Boolean;
  222. var estado : Dword;
  223. begin
  224. try
  225. if not InternetGetConnectedState(@estado, 0) then
  226. Result := False
  227. else
  228. begin
  229. if (estado and INTERNET_CONNECTION_LAN <> 0) OR
  230. (estado and INTERNET_CONNECTION_MODEM <> 0) or
  231. (Estado and INTERNET_CONNECTION_PROXY <> 0) then
  232. Result := True;
  233. end;
  234. except
  235. Result := False
  236. end;
  237. end;
  238.  
  239. procedure TForm1.Timer1Timer(Sender: TObject);
  240. begin
  241.  
  242. if not StatusInternet then
  243. begin
  244. Label_Internet.Font.Color := clRed;
  245. Label_Internet.Caption := 'OFFLINE';
  246. end
  247. else
  248. begin
  249. Label_Internet.Font.Color := clGreen;
  250. Label_Internet.Caption := 'ONLINE';
  251. end;
  252.  
  253. end;
  254.  
  255. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement