Ir ao conteúdo
  • Cadastre-se

Wellington Duarte

Membro Júnior
  • Posts

    4
  • Cadastrado em

  • Última visita

Reputação

0
  1. Então, na verdade sou bem iniciante no Delphi. Eu procurei sobre thread porém eu não entendo. Acredito que se usar esse método funcione. Se alguém conseguir fazer isso pra mim ficarei bem feliz.
  2. Olá, estou desenvolvendo um projeto de auto update com múltiplos downloads. Porém quando está fazendo o download dos arquivos, o programa simplesmente trava e só é possível mexer após todos os downloads. Já coloquei anti freeze, porém o problema continua. Segue o código, caso alguém possa alterar e me mandar ficarei agradecido, acredito que o problema esteja no Timer1. unit CLIENTE; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, sSkinManager, ExtCtrls, sPanel, StdCtrls, Buttons, sBitBtn, sButton, acNoteBook, sSpinEdit, sGauge, ComCtrls, sTreeView, sTrackBar, sPageControl, sTabControl, Mask, sMaskEdit, sSpeedButton, sGroupBox, sComboBox, sListBox, sRadioButton, sCheckBox, sMemo, sEdit, acShellCtrls, sLabel, OleCtrls, SHDocVw, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, IdHTTP, acProgressBar, DFUnRar, IdAntiFreezeBase, IdAntiFreeze; type TForm1 = class(TForm) sSkinManager1: TsSkinManager; sPanel1: TsPanel; sLabelFX1: TsLabelFX; sButton3: TsButton; sPanel2: TsPanel; web: TWebBrowser; Timer1: TTimer; IdHTTP1: TIdHTTP; lista: TMemo; Memo2: TMemo; Memo3: TMemo; sProgressBar1: TsProgressBar; sProgressBar2: TsProgressBar; DFUnRar1: TDFUnRar; Edit1: TEdit; Timer2: TTimer; IdAntiFreeze1: TIdAntiFreeze; sBitBtn1: TsBitBtn; sBitBtn2: TsBitBtn; sBitBtn3: TsBitBtn; procedure FormCreate(Sender: TObject); procedure IdHTTP1Work(Sender: TObject; AWorkMode: TWorkMode; const AWorkCount: Integer); procedure IdHTTP1WorkBegin(Sender: TObject; AWorkMode: TWorkMode; const AWorkCountMax: Integer); procedure IdHTTP1WorkEnd(Sender: TObject; AWorkMode: TWorkMode); procedure Timer1Timer(Sender: TObject); procedure Timer2Timer(Sender: TObject); procedure sButton3Click(Sender: TObject); private IsExtracting: boolean; Abort: boolean; Success: boolean; public ltitle : string; Min: Integer; path : string; pexit: boolean; function UpdateExe():boolean; { Public declarations } end; var Form1: TForm1; sNomeLocalVar:string; implementation {$R *.dfm} procedure TForm1.FormCreate(Sender: TObject); begin sButton3.Enabled := False; web.Navigate('http://www.somubom.net/muspirit/launcher/'); ltitle := 'Launcher'; // Editar /\ sSkinManager1.Active:= true; if FindWindow(Nil, PChar(ltitle)) > 0 then begin MessageDlg('O launcher ja esta em execucao.', mtInformation, [mbOK], 0); Application.Terminate; form1.Close; end else Application.Title:=ltitle; end; procedure TForm1.IdHTTP1Work(Sender: TObject; AWorkMode: TWorkMode; const AWorkCount: Integer); begin sProgressBar1.Position := AWorkCount; end; procedure TForm1.IdHTTP1WorkBegin(Sender: TObject; AWorkMode: TWorkMode; const AWorkCountMax: Integer); begin sProgressBar1.Position := 0; sProgressBar1.Max := AWorkCountMax; sLabelFX1.caption := 'Verificando atualizações...' end; procedure TForm1.IdHTTP1WorkEnd(Sender: TObject; AWorkMode: TWorkMode); begin sProgressBar1.Position := sProgressBar1.Max; sLabelFX1.caption := 'Atualização concluída!'; end; procedure TForm1.Timer1Timer(Sender: TObject); var arquivo,caminho : string; slTemp : TStringList; i : integer; MyFile: TFileStream; begin Timer1.Enabled:= False; caminho:= 'http://127.0.0.1:8090/'; arquivo:= 'versaoatual.txt'; MyFile := TFileStream.Create('versaoatual.txt', fmCreate); try IdHTTP1.Get('http://127.0.0.1:8090/versaoatual.txt', MyFile); finally MyFile.Free; Memo2.Lines.LoadFromFile('versaoatual.txt'); Memo3.Lines.LoadFromFile('versao.txt'); if Memo2.Lines[0] = Memo3.Lines[0] then begin sButton3.enabled := True; sLabelFX1.Caption := 'Atualização concluída!'; sLabelFX1.Top := 35; sProgressBar1.Visible:=False; sProgressBar2.Visible:=False ; end else begin slTemp := TStringList.Create; slTemp.LoadFromFile('update.txt'); for i := 0 to slTemp.Count - 1 do begin sLabelFX1.Caption := 'Baixando: ' + slTemp.Strings[i]; caminho:='http://127.0.0.1:8090/'; arquivo:= slTemp.Strings[i]; MyFile := TFileStream.Create(slTemp.Strings[i], fmCreate); try IdHTTP1.Get('http://127.0.0.1:8090/' + slTemp.Strings[i], MyFile); finally FreeAndNil(MyFile); end; end; timer2.enabled := True; memo2.lines.savetofile('versao.txt'); sLabelFX1.Caption := 'Atualização concluída'; end; end; end; function TForm1.UpdateExe():boolean; begin Success := false; // proteger a executavel if FileExists('Launcher.new') then begin form1.Hide; Repeat //o truque cria-se um laço até o if RenameFile('Launcher.exe','Launcher.old') then //tenta renomear o exe begin //RenameFile('Launcher.new','Launcher.exe'); //renomeia o novo como exe // fim extração if FileExists('Launcher.new') then begin RenameFile('Launcher.new', 'Launcher.exe'); Success:=true; end else begin RenameFile('Launcher.old', 'Launcher.exe'); Success:=true; end; Min:=0; //Se não for possível renomear é porque o aplicativo sleep(2000); if Success = false then //não terminou por completo, espero 2 segundos e Min:=Min+1 else Min := 10; end //tento de novo. Espero até 20 segundos (contador) until Min=10; end; if FileExists('Launcher.old') then windows.DeleteFile(pchar(path+'Launcher.old')); Result := Success; end; procedure TForm1.Timer2Timer(Sender: TObject); begin with Edit1 do if Text <> '' then DFUnRar1.Directory:=Text; DFUnRar1.FileName := Lista.Lines[0]; if not FileExists(DFUnRar1.FileName) then begin Exit; end else begin IsExtracting := True; DFUnRar1.Extract; IsExtracting := False; if not Abort then end; Timer2.Enabled := False; end; procedure TForm1.sButton3Click(Sender: TObject); begin winexec('main.exe connect /u127.0.0.1 /p44405', sw_normal); Application.Terminate; end; end.
  3. Olá pessoa, sou novato em Delphi e estou com um pequeno problema que não consigo resolver. Estou recebendo a mensagem Operator not applicable to this operand type. Estou usando pra fazer uma lista de Downloads, porém ele sempre baixa o que está na primeira variavel lista.Lines[0]. Porém preciso que baixe todos os arquivos que estão em lista.Lines. Valeu ! lista.Lines.LoadFromFile('update.txt'); end; //// INICIIO FOR EACH for vAux in lista.Lines do begin ShowMessage(IntToStr(vAux)); sLabelFX1.Caption := 'Baixando: ' + lista.Lines[0]; caminho:='http://127.0.0.1:8090/'; arquivo:= lista.Lines[0]; MyFile := TFileStream.Create(lista.Lines[0], fmCreate); try IdHTTP1.Get('http://127.0.0.1:8090/' + lista.Lines[0], MyFile); finally MyFile.Free; end; end; /// FIM FOR EACH

Sobre o Clube do Hardware

No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais

Direitos autorais

Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais

×
×
  • Criar novo...

 

GRÁTIS: ebook Redes Wi-Fi – 2ª Edição

EBOOK GRÁTIS!

CLIQUE AQUI E BAIXE AGORA MESMO!