se7enek

u1

Jul 24th, 2014
364
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 6.84 KB | None | 0 0
  1. unit Unit1;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  7.   Dialogs, StdCtrls, IdBaseComponent, IdComponent, IdTCPConnection,
  8.   IdTCPClient, IdHTTP, INIFiles, ExtActns, ComCtrls, ExtCtrls, ShellAPI,
  9.   IdAntiFreezeBase, IdAntiFreeze, ScktComp, OverbyteIcsMD5, jpeg, sLabel,
  10.   Menus;
  11.  
  12. type
  13.   TForm1 = class(TForm)
  14.     IdHTTP1: TIdHTTP;
  15.     ProgressBar1: TProgressBar;
  16.     Image1: TImage;
  17.     Memo1: TMemo;
  18.     Button1: TButton;
  19.     Button2: TButton;
  20.     Button3: TButton;
  21.     Button4: TButton;
  22.     IdAntiFreeze1: TIdAntiFreeze;
  23.     Socket: TClientSocket;
  24.     Timer1: TTimer;
  25.     Button5: TButton;
  26.     sLabel1: TsLabel;
  27.     procedure FormCreate(Sender: TObject);
  28.     procedure Button4Click(Sender: TObject);
  29.     procedure Button2Click(Sender: TObject);
  30.     procedure Button3Click(Sender: TObject);
  31.     procedure Timer1Timer(Sender: TObject);
  32.     procedure Button5Click(Sender: TObject);
  33.     procedure Button1Click(Sender: TObject);
  34.   private
  35.     { Private declarations }
  36.   public
  37.     procedure URL_OnDownloadProgress(Sender: TDownLoadURL; Progress, ProgressMax: Cardinal; StatusCode: TURLDownloadStatus; StatusText: String; var Cancel: Boolean);
  38.     function DoDownload(const strWhichURL,strLocalFile:string): boolean;
  39.     function DoReadINI(const strFile,strWhichSection,strString:string): string;
  40.     procedure DoWriteINI(const strFileWRI,strWhichSectionWRI, strNameWRI, strStringWRI:string);
  41.     procedure CompareStrings(const string1, string2, filename: string);
  42.     procedure CheckMD5();
  43.   end;
  44.  
  45. var
  46.   Form1: TForm1;
  47.  
  48. implementation
  49.  
  50. uses Unit2;
  51.  
  52. {$R *.dfm}
  53.  
  54. procedure TForm1.URL_OnDownloadProgress;
  55.  
  56. begin
  57.  
  58.   ProgressBar1.Max:= ProgressMax;
  59.  
  60.   ProgressBar1.Position:= Progress;
  61.  
  62. end;
  63. function TForm1.DoReadINI(const strFile,strWhichSection,strString:string): string;
  64.  var
  65.     ReadINI : TINIFile;
  66. begin
  67. try
  68.     ReadINI := TINIFile.Create(strFile);
  69.     result := ReadINI.ReadString(strWhichSection, strString, 'Default');
  70.     finally
  71.     ReadINI.Free;
  72. end;
  73. end;
  74.  
  75. procedure TForm1.DoWriteINI(const strFileWRI,strWhichSectionWRI,strNameWRI,strStringWRI:string);
  76.  var
  77.     WriteINI : TINIFile;
  78. begin
  79. try
  80.     WriteINI := TINIFile.Create(strFileWRI);
  81.     WriteINI.WriteString(strWhichSectionWRI, strNameWRI, strStringWRI);
  82.     finally
  83.     WriteINI.Free;
  84. end;
  85. end;
  86.  
  87. function TForm1.DoDownload(const strWhichURL,strLocalFile:string): boolean;
  88.  
  89. begin
  90.     Result:=True;
  91.   with TDownloadURL.Create(nil) do
  92.  
  93.   try
  94.  
  95.     URL := strWhichURL;
  96.  
  97.     FileName := strLocalFile;
  98.  
  99.     OnDownloadProgress := URL_OnDownloadProgress;
  100.      try
  101.      Application.ProcessMessages;
  102.     ExecuteTarget(nil);
  103.     except
  104.     ShowMessage('Can not Download ' + strWhichURL);
  105.     Result:=False
  106.     end;
  107.  
  108.  
  109.     finally
  110.  
  111.     Free;
  112.     ProgressBar1.Position := 0;
  113.  
  114.   end;
  115.  
  116. end;
  117.  
  118. procedure TForm1.CompareStrings(const string1, string2, filename: string);
  119.   var result : Integer;
  120.   FiledownloadInet, FileDownloadName : string;
  121.  
  122. begin
  123.   result := AnsiCompareStr(string1, string2);
  124.  
  125.   if result < 0 then
  126.   begin
  127.  
  128.   //Different
  129.   Button1.Enabled := false;
  130.   //showmessage('Start Download');
  131.   FileDownloadName :=  filename;
  132.   Delete(FileDownloadName, 1,1);
  133.   FiledownloadInet := DoReadINI('./updater.ini','Settings','UpdateHost')  + FileDownloadName;
  134.  
  135.   Application.ProcessMessages;
  136.  
  137.   DoDownload(FiledownloadInet,filename);
  138.   //showmessage('DIFF String1:' + string1 + ' String2: ' + string2 + ' Filename: ' + filename);
  139.   Button1.Enabled := true;
  140.  
  141.   end;
  142.   if result = 0 then
  143.   begin
  144.   //Same
  145.   { do nothing }
  146.   //showmessage('==SAME ServMD5 ' + string1 + ' LocalMD5 ' + string2 + ' FileName ' + filename);
  147.  
  148.   end;
  149.   if result > 0 then
  150.   begin
  151.   Button1.Enabled := false;
  152.   //showmessage('Start Download');
  153.   FileDownloadName :=  filename;
  154.   Delete(FileDownloadName, 1,1);
  155.   FiledownloadInet := DoReadINI('./updater.ini','Settings','UpdateHost')  + FileDownloadName;
  156.  
  157.   Application.ProcessMessages;
  158.  
  159.   DoDownload(FiledownloadInet,filename);
  160.    //showmessage('String1:' + string1 + ' String2: ' + string2 + ' Filename: ' + filename);
  161.   Button1.Enabled := true;
  162.   //Error
  163.   //showmessage('==ERROR ServMD5 ' + string1 + ' LocalMD5 ' + string2 + ' FileName ' + filename);
  164.   //ShowMessage('Error In Version');
  165.   end;
  166. end;
  167.  
  168. procedure TForm1.CheckMD5();
  169. var
  170.   SomeTxtFile : TextFile;
  171.   buffer, md5filename, md5var, SrvMD5 : string;
  172.   Line : TStringList;
  173. begin
  174.   AssignFile(SomeTxtFile, './file.list') ;
  175.   Reset(SomeTxtFile) ;
  176.   while not EOF(SomeTxtFile) do
  177.   begin
  178.    ReadLn(SomeTxtFile, buffer) ;
  179.    Line := TStringList.Create;
  180.    Line.CommaText := buffer;
  181.    SrvMD5 := AnsiUpperCase(Line[1]);
  182.    md5filename := Line[0];
  183.    md5var := FileMD5(md5filename);
  184.  
  185.    Application.ProcessMessages;
  186.  
  187.   CompareStrings(md5var, SrvMD5, Line[0]);
  188.   //showmessage('ServMD5 ' + SrvMD5 + ' LocalMD5 ' + md5var + ' FileName ' + Line[0]);
  189.     Screen.Cursor := crDefault;
  190.   end;
  191.   CloseFile(SomeTxtFile) ;
  192. end;
  193.  
  194. procedure TForm1.FormCreate(Sender: TObject);
  195. var
  196. UpdaterTitle: string;
  197. begin
  198. //Center Form
  199. Left:=(Screen.Width-Width)  div 2;
  200. Top:=(Screen.Height-Height) div 2;
  201. //Change Title
  202. UpdaterTitle := DoReadINI('./updater.ini','Settings','UpdaterTitle');
  203. sLabel1.caption := UpdaterTitle;
  204.  
  205. end;
  206.  
  207.  
  208. procedure TForm1.Button4Click(Sender: TObject);
  209. begin
  210. Close;
  211. end;
  212.  
  213. procedure TForm1.Button2Click(Sender: TObject);
  214. begin
  215.  ShellExecute(Form1.Handle, 'open', 'engine.exe', '/setup', nil, SW_SHOWNORMAL);
  216. end;
  217.  
  218. procedure TForm1.Button3Click(Sender: TObject);
  219. var
  220.     SiteButtonURL: string;
  221. begin
  222. SiteButtonURL := DoReadINI('./updater.ini','Settings','WebsiteButtonURL');
  223. ShellExecute(Form1.Handle, 'open', PChar(SiteButtonURL), nil, nil, SW_SHOWNORMAL);
  224.  
  225. end;
  226.  
  227. procedure TForm1.Timer1Timer(Sender: TObject);
  228. var
  229. NoticeLocalFile, NoticeInetFile, UpdateFileLocal, UpdateFileInet: string;
  230. begin
  231. Timer1.enabled:=false;
  232.  
  233. //Notice File
  234.  
  235. NoticeLocalFile := DoReadINI('./updater.ini','Settings','NoticeFile');
  236. NoticeInetFile := DoReadINI('./updater.ini','Settings','UpdateHost') + '/' + DoReadINI('./updater.ini','Settings','NoticeFile');
  237. DoDownload(NoticeInetFile,NoticeLocalFile);
  238. if FileExists(NoticeLocalFile) then
  239.    Memo1.Lines.LoadFromFile(NoticeLocalFile)
  240. else
  241.   ShowMessage('Can not Display Notice File');
  242.  
  243.   //Download Update List
  244. UpdateFileLocal := DoReadINI('./updater.ini','Settings','UpdateFile');
  245. UpdateFileInet := DoReadINI('./updater.ini','Settings','UpdateHost') + '/' + DoReadINI('./updater.ini','Settings','UpdateFile');
  246.  
  247. DoDownload(UpdateFileInet,UpdateFileLocal);
  248.   CheckMD5();
  249. end;
  250.  
  251. procedure TForm1.Button5Click(Sender: TObject);
  252. begin
  253. form1.visible := false;
  254. form2.visible := true;
  255. end;
  256.  
  257. procedure TForm1.Button1Click(Sender: TObject);
  258. begin
  259. ShellExecute(Form1.Handle, 'open', 'engine.exe', '/load /config debug', nil, SW_SHOWNORMAL);
  260. close;
  261. end;
  262.  
  263. end.
Advertisement
Add Comment
Please, Sign In to add comment