實現了這個功能就可以脫離大宇遊戲領航員3.0來進行客戶端更新(客戶端更新功能直接置入到登陸器)
5 ]; I- x, J7 {$ Hbbs.mocwww.com魔力私服,最新魔力私服,魔力宝贝私服,魔力宝贝私服技术,魔力宝贝私服,私服架设技术,妖城,FLASH,电影,黑客,网络,网吧,破解,入侵,注册表) [9 _) w, {: Y) S
代碼寫的粗糙還請大家不要見怪
魔力私服,最新魔力宝贝私服技术交流' z! Y. r; O" a) u
程序通過下載Script_CRC.ini 然後讀取客戶端當前Script.ini的CRC值和最新版本比較 如果不一樣就更新Script.ini
bbs.mocwww.com8 n# z& ]' K+ Y& T
然後讀取Script.ini來獲取更新文件的信息並下載 根據對應的模式進行更新文件
复制内容到剪贴板
代码:
unit UpdateCG;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, IdHashCRC, IniFiles, IdBaseComponent, IdComponent,
IdTCPConnection, IdTCPClient, IdHTTP, Vcl.StdCtrls, StrUtils;
type
TForm16 = class(TForm)
IdHTTP1: TIdHTTP;
Memo1: TMemo;
procedure FormCreate(Sender: TObject);
private
function GetFile_CRC(const iFileName: String): String;
{ Private declarations }
public
{ Public declarations }
end;
var
Form16: TForm16;
implementation
{$R *.dfm}
type
inifmt = record
path: String;
url: String;
filename: String;
size: String;
crc: String;
method: String;
end;
function TForm16.GetFile_CRC(const iFileName: String): String;
var
crc: TIdHashCRC32;
fileStream: TMemoryStream;
begin
crc:= TIdHashCRC32.Create;
fileStream:= TMemoryStream.Create;
try
fileStream.LoadFromFile(iFileName);
Result:= crc.HashStreamAsHex(fileStream);
finally
fileStream.Free;
crc.Free;
end;
end;
procedure TForm16.FormCreate(Sender: TObject);
VAR
Buffer: TFileStream;
HttpClient: TIdHttp;
crcini: TIniFile;
Path: string;
Temp: inifmt;
List: TStrings;
mycrc: String;
i: Integer;
UpdateFileName: String;
begin
Memo1.Clear;
Path := ExtractFilePath(Application.ExeName);
Path:= Path + '\script_CRC.ini';
if not FileExists(Path) then // 目錄不正確直接退出流程
Exit;
{ 總是下載 script_CRC.ini}
Buffer := TFileStream.Create('Script_CRC.ini', fmOpenWrite or fmShareDenyNone);
try
HttpClient := TIdHttp.Create(nil);
try
HttpClient.Get('http://patch.joypark.com.tw:3210/cg_test/script_CRC.ini', Buffer); // wait until it is done
finally
HttpClient.Free;
end;
finally
Buffer.Free;
end;
{ 讀取 script_CRC.ini 中的[CRC]節 和本地文件Script.ini的crc值作比較}
crcini := TIniFile.Create(Path);
Temp.url:= crcini.ReadString('CRC', 'url', '');
Temp.filename:= crcini.ReadString('CRC', 'filename', '');
Temp.crc:= crcini.ReadString('CRC', 'crc', '');
List := TStringList.Create;
List.LoadFromFile(Path);
crcini.ReadSections(List);
mycrc:= GetFile_CRC(ExtractFilePath(Application.ExeName) + '\script.ini');
if (Temp.crc = mycrc) then
Exit
else begin
Buffer := TFileStream.Create(Temp.filename, fmOpenWrite or fmShareDenyNone);
// Buffer := TFileStream.Create('Script.ini', fmOpenWrite or fmShareDenyNone);
try
HttpClient := TIdHttp.Create(nil);
try
HttpClient.Get(Temp.url, Buffer); // wait until it is done
// HttpClient.Get('http://patch.joypark.com.tw:3210/cg_test/script.ini', Buffer); // wait until it is done
finally
HttpClient.Free;
end;
finally
Buffer.Free;
crcini.Free;
crcini := TIniFile.Create(ExtractFilePath(Application.ExeName) + '\' + Temp.filename);
List.Clear;
List.LoadFromFile(ExtractFilePath(Application.ExeName) + '\' + Temp.filename);
crcini.ReadSections(List);
// ShowMessage(List.Count.ToString);
for i := 1 to List.Count do
begin
Temp.path:= crcini.ReadString(List[i-1], 'path', '');
Temp.filename:= crcini.ReadString(List[i-1], 'filename', '');
Temp.url:= crcini.ReadString(List[i-1], 'url', '');
Temp.size:= crcini.ReadString(List[i-1], 'size', '');
Temp.crc:= crcini.ReadString(List[i-1], 'crc', '');
Temp.method:= crcini.ReadString(List[i-1], 'method', '');
// if Temp.method = '' then
// begin
// Buffer := TFileStream.Create(ExtractFilePath(Application.ExeName) + '\' + Temp.path + Temp.filename, fmOpenWrite or fmShareDenyNone);
// try
// HttpClient := TIdHttp.Create(nil);
// HttpClient.Get(Temp.url, Buffer); // wait until it is done
// finally
// HttpClient.Free;
// Buffer.Free;
// end;
// end;
if (Temp.method = '') or (Temp.method = 'replace') then
begin
if not (FileExists(ExtractFilePath(Application.ExeName) + Temp.path + Temp.filename)) then
continue; // 如果文件不存在跳過該文件
Buffer := TFileStream.Create(
ExtractFilePath(Application.ExeName) + '\' + Temp.path + Temp.filename,
fmOpenWrite or fmShareDenyNone);
try
HttpClient := TIdHttp.Create(nil);
HttpClient.Get(Temp.url, Buffer); // wait until it is done
finally
HttpClient.Free;
Buffer.Free;
end;
end
else if Temp.method = 'append' then
begin
if not (FileExists(ExtractFilePath(Application.ExeName) + Temp.path + Temp.filename)) then
continue; // 如果文件不存在跳過該文件
Buffer := TFileStream.Create(
ExtractFilePath(Application.ExeName) + Temp.path + Temp.filename, +
fmOpenWrite or fmShareDenyNone);
Buffer.Seek(0, soFromEnd); // append模式
try
HttpClient := TIdHttp.Create(nil);
HttpClient.Get(Temp.url, Buffer);
finally
HttpClient.Free;
Buffer.Free;
UpdateFileName:= RightStr(Temp.url, Length(Temp.filename));
RenameFile(ExtractFilePath(Application.ExeName) + Temp.path + Temp.filename,
PCHAR(ExtractFilePath(Application.ExeName) + Temp.path + UpdateFileName));
end;
end;
Memo1.Lines.Add('更新文件: ' + ExtractFilePath(Application.ExeName) + Temp.path + UpdateFileName);
end;
crcini.Free;
end;
end;
List.Free;
end;
end.
妖城在线论坛3 `- n, u2 T; ]* G
魔力私服,最新魔力宝贝私服技术交流) Z. a0 \6 C/ X* u
魔力私服,最新魔力宝贝私服技术交流+ U1 E/ h; r N) u* c
bbs.mocwww.com7 y. e! N4 C4 B) y
妖城在线论坛" |/ `& `: \3 q8 ^
bbs.mocwww.com! \ h. j4 O! C* S" m+ A ?