Changeset 617
- Timestamp:
- Dec 2, 2013, 8:06:58 PM (11 years ago)
- Location:
- tools/WoWHeadLoader
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
tools/WoWHeadLoader/WoWHeadLoader.lpi
r612 r617 33 33 </local> 34 34 </RunParams> 35 <Units Count=" 1">35 <Units Count="2"> 36 36 <Unit0> 37 37 <Filename Value="WoWHeadLoader.lpr"/> … … 39 39 <UnitName Value="WoWHeadLoader"/> 40 40 </Unit0> 41 <Unit1> 42 <Filename Value="uglobal.pas"/> 43 <IsPartOfProject Value="True"/> 44 <UnitName Value="Uglobal"/> 45 </Unit1> 41 46 </Units> 42 47 </ProjectOptions> -
tools/WoWHeadLoader/WoWHeadLoader.lpr
r616 r617 13 13 ; 14 14 //poznámka mazání pro testování 15 //DELETE FROM `wowpreklad`.`TextQuest` WHERE `textquest`.`VersionStart` = 17359; 16 //UPDATE `wowpreklad`.`TextQuest` SET `VersionEnd` = 12340 WHERE `textquest`.`VersionEnd` = 17359; 17 18 15 { 16 DELETE FROM `wowpreklad`.`TextQuest` WHERE `VersionStart` = 17359; 17 DELETE FROM `wowpreklad`.`TextAchievement` WHERE `VersionStart` = 17359; 18 DELETE FROM `wowpreklad`.`TextGameObject` WHERE `VersionStart` = 17359; 19 DELETE FROM `wowpreklad`.`TextItem` WHERE `VersionStart` = 17359; 20 DELETE FROM `wowpreklad`.`TextCreature` WHERE `VersionStart` = 17359; 21 DELETE FROM `wowpreklad`.`TextArea` WHERE `VersionStart` = 17359; 22 23 UPDATE `wowpreklad`.`TextItem` SET `VersionEnd` = 12340 WHERE `VersionEnd` = 17359; 24 UPDATE `wowpreklad`.`TextGameObject` SET `VersionEnd` = 12340 WHERE `VersionEnd` = 17359; 25 UPDATE `wowpreklad`.`TextQuest` SET `VersionEnd` = 12340 WHERE `VersionEnd` = 17359; 26 UPDATE `wowpreklad`.`TextAchievement` SET `VersionEnd` = 12340 WHERE `VersionEnd` = 17359; 27 UPDATE `wowpreklad`.`TextCreature` SET `VersionEnd` = 12340 WHERE `VersionEnd` = 17359; 28 UPDATE `wowpreklad`.`TextArea` SET `VersionEnd` = 12340 WHERE `VersionEnd` = 17359; 29 } 19 30 type 20 31 … … 32 43 procedure Main; 33 44 function skipto(part: string; text: string): string; 34 function GetPartText(textname: string; text: string): string;35 45 function TextStringReplace(text:string):string; 36 46 function CompareStrings(textdb: string; textimport: string): boolean; 37 47 function DelHtmlTags(text:string):string; 38 48 function SqlPre(text: string):string; 39 procedure UpdateTranslated; 49 procedure UpdateTranslated(table:string); 50 function GetLastVersion: integer; 51 function GetPartText(textname: string; text: string): string; 52 40 53 function GetEndtextData(data:string): string; 41 42 function GetMaxIDQuest: integer;43 54 procedure GetTextQuest(Id: Integer); 44 55 procedure UpdateQuest; 45 56 46 function GetLastVersion: integer; 57 function GetMaxID(TextType: string): integer; 58 procedure GetText(Id: Integer;TextType : integer); 47 59 end; 48 60 var 49 61 ImportedVersion: integer; 62 Group: array [1..6] of string = ('achievement','item','npc','object','zone','quest'); 63 GroupDB: array [1..6] of string = ('TextAchievement','TextItem','TextCreature','TextGameObject','TextArea','TextQuest'); 64 Column2DB: array [1..6] of string = ('Description','Description','SubName','','',''); 50 65 51 66 { TWoWHeadLoader } … … 126 141 127 142 procedure TWoWHeadLoader.Main; 128 129 begin 130 UpdateQuest; 143 var 144 i,t: integer; 145 begin 146 // UpdateQuest; 147 GetText(1111,1); 148 GetText(98148,2); 149 GetText(29,3); 150 GetText(55,4); 151 GetText(15,5); 152 GetText(4,6); 153 for t :=1 to Length(Group) do 154 for i := 0 to 1000 do begin //GetMaxID('quest') 155 GetText(i,t); 156 // write('.'); 157 end; 131 158 //čekej před uzavřením 132 159 ReadLn; … … 245 272 Database.Query('UPDATE `wowpreklad`.`TextQuest` SET `VersionEnd` = '+IntToStr(ImportedVersion)+' WHERE `Id` = '+DBRows.Data[0].Values['Id']+' AND `Entry` ='+IntToStr(Id)+';'); 246 273 Database.Query('UPDATE `wowpreklad`.`TextQuest` SET `VersionEnd` = '+IntToStr(ImportedVersion)+' WHERE `Take` = '+DBRows.Data[0].Values['Id']+' AND `Entry` ='+IntToStr(Id)+';'); 247 UpdateTranslated ;274 UpdateTranslated('textquest'); 248 275 Exit; //konec: text je stejný upravili se jenom výsledné verze 249 276 end; … … 363 390 364 391 365 for i := 0 to GetMaxID Questdo begin392 for i := 0 to GetMaxID('quest') do begin 366 393 GetTextQuest(i); 367 394 write('.'); 368 395 end; 396 end; 397 398 procedure TWoWHeadLoader.GetText(Id: Integer; TextType: Integer); 399 var 400 part,data, sql, 401 textname,textdescription: string; 402 foundtext: boolean = true; 403 DBRows : TDbRows; 404 i: integer; 405 begin 406 WriteLn(); 407 WriteLn(Group[TextType]+'='+IntToStr(Id)); 408 if (TextType = 6) then begin 409 GetTextQuest(Id); 410 Exit; 411 end; 412 413 try 414 415 //načtení 416 data := IdHTTP1.Get('http://www.wowhead.com/'+Group[TextType]+'='+IntToStr(Id)); 417 418 if (pos('<b style="color: red">',data) > 0) then begin 419 WriteLn('color:red'); 420 // ReadLn; 421 foundtext:=false; 422 Exit; 423 end; 424 if ((pos('is no longer available within the game.</b>',data) > 0)) then begin 425 foundtext:=false; 426 Exit; 427 end; 428 429 //skok na text 430 data := skipto('<div class="text">',data); 431 432 //name 433 data := skipto('<h1',data); 434 data := skipto('>',data); 435 textname := TextStringReplace(Copy(data,0,Pos('</h1>',data)-1)); 436 //description 437 data := skipto('</h1>',data); 438 for i:= 0 to 4 do begin 439 data := StringReplace(data,'<br>','$B',[rfIgnoreCase]); 440 data := StringReplace(data,'<br />','$B',[rfIgnoreCase]); 441 end; 442 if ('' <> Column2DB[TextType]) then 443 if ('item' = Group[TextType]) then begin 444 data := skipto('Use:',data); 445 data := skipto('<',data); 446 // textdescription := TextStringReplace(Copy(data,0,Pos('<',data)-1)); 447 end else begin 448 data := skipto('<script type="text/javascript">',data); 449 data := skipto('</script>',data); 450 textdescription := TextStringReplace(Copy(data,0,Pos('<',data)-1)); 451 end; 452 if ('npc' = Group[TextType]) then begin 453 textdescription := skipto('<',textname); 454 textdescription := TextStringReplace(Copy(textdescription,0,Pos('>',textdescription)-1)); 455 if (Pos('<',textname) >0) then 456 textname := TextStringReplace(Copy(textname,0,Pos('<',textname)-1)); 457 end; 458 textname:=DelHtmlTags(textname); 459 460 If foundtext then begin 461 DBRows := Database.Query('SELECT * FROM `'+GroupDB[TextType]+'` WHERE `Entry` ='+IntToStr(Id)+' AND `Language` =0 ORDER BY `VersionEnd` DESC '); 462 if (DBRows.Count > 0) then begin 463 WriteLn('"'+DBRows.Data[0].Values['Name']+'"-"'+DBRows.Data[0].Values[Column2DB[TextType]]+'"'); 464 WriteLn('"'+textname+'"-"'+textdescription+'"'); 465 if (DBRows.Data[0].Values['VersionEnd'] = IntToStr(ImportedVersion)) then Exit; //konec pokud už tam text je 466 if ( 467 CompareStrings(DBRows.Data[0].Values['Name'],textname) and 468 CompareStrings(DBRows.Data[0].Values[Column2DB[TextType]],textdescription) 469 ) then 470 begin 471 //text je stejný 472 Database.Query('UPDATE `wowpreklad`.`'+GroupDB[TextType]+'` SET `VersionEnd` = '+IntToStr(ImportedVersion)+' WHERE `Id` = '+DBRows.Data[0].Values['Id']+' AND `Entry` ='+IntToStr(Id)+';'); 473 Database.Query('UPDATE `wowpreklad`.`'+GroupDB[TextType]+'` SET `VersionEnd` = '+IntToStr(ImportedVersion)+' WHERE `Take` = '+DBRows.Data[0].Values['Id']+' AND `Entry` ='+IntToStr(Id)+';'); 474 WriteLn('update'); 475 UpdateTranslated(GroupDB[TextType]); 476 Exit; //konec: text je stejný upravili se jenom výsledné verze 477 end; 478 end; 479 sql := 'INSERT INTO `wowpreklad`.`'+GroupDB[TextType]+'` (`ID` ,`Entry` ,`Name`,'; 480 if (Column2DB[TextType] <> '') then sql += '`'+Column2DB[TextType]+'` ,'; 481 sql +='`Language` , `User` , `Complete` ,`CompleteParts` ,`Take` ,`VersionStart` ,`VersionEnd` ,`ModifyTime`)' 482 +'VALUES (NULL,'+IntToStr(Id)+',' 483 +SqlPre(textname)+', '; 484 if (Column2DB[TextType] <> '') then sql += SqlPre(textdescription)+', '; 485 sql +='0, NULL, 1,0,NULL,'+IntToStr(ImportedVersion)+','+IntToStr(ImportedVersion)+',NOW())'; 486 WriteLn('insert'); 487 Database.Query(sql); 488 end; 489 except 490 on E: EIdHTTPProtocolException do 491 begin 492 if E.ErrorCode = 404 then begin 493 foundtext := false; 494 WriteLn('notfound'); 495 end; 496 end; 497 on E:Exception do 498 // GetText(Id,TextType); 499 end; 500 end; 501 502 function TWoWHeadLoader.GetMaxID(TextType: string): integer; 503 var 504 data:string; 505 maxid:integer=10000; //34000 pro questy 506 begin 507 // http://www.wowhead.com/quests?filter=cr=30;crs=1;crv=34000 508 repeat 509 510 data := IdHTTP1.Get('http://www.wowhead.com/'+TextType+'?filter=cr=30;crs=1;crv='+IntToStr(maxid)); 511 result := maxid; 512 maxid := maxid+400; 513 until (Pos('Your criteria did not match',data) > 0); 369 514 end; 370 515 … … 387 532 end; 388 533 389 function TWoWHeadLoader.GetMaxIDQuest: integer;390 var391 data:string;392 maxid:integer=34000;393 begin394 // http://www.wowhead.com/quests?filter=cr=30;crs=1;crv=34000395 repeat396 397 data := IdHTTP1.Get('http://www.wowhead.com/quests?filter=cr=30;crs=1;crv='+IntToStr(maxid));398 result := maxid;399 maxid := maxid+200;400 until (Pos('Your criteria did not match',data) > 0);401 end;402 403 534 function TWoWHeadLoader.GetPartText(textname: string; text: string): string; 404 535 begin … … 426 557 text := StringReplace(text,'<br />','$B',[rfReplaceAll, rfIgnoreCase]); 427 558 text := StringReplace(text,'<br>','$B',[rfReplaceAll, rfIgnoreCase]); 428 text := StringReplace(text,' ','',[rfReplaceAll, rfIgnoreCase]); 559 text := StringReplace(text,' ',' ',[rfReplaceAll, rfIgnoreCase]); 560 text := StringReplace(text,'&','&',[rfReplaceAll, rfIgnoreCase]); 561 text := StringReplace(text,''',chr(39),[rfReplaceAll, rfIgnoreCase]); 429 562 text := StringReplace(text,'<name>','$N',[rfReplaceAll, rfIgnoreCase]); 430 563 text := StringReplace(text,'<class>','$C',[rfReplaceAll, rfIgnoreCase]); … … 534 667 end; 535 668 536 procedure TWoWHeadLoader.UpdateTranslated ;669 procedure TWoWHeadLoader.UpdateTranslated(table: string); 537 670 var 538 671 i:integer; … … 564 697 DBRows := Database.Query('SELECT `gs_tran`.`ID` , `gs_tran`.`VersionEnd` AS `VersionEnd_tran` ,' 565 698 +'`gs_orig`.`VersionEnd` AS `VersionEnd_orig`' 566 +' FROM ` textquest` AS `gs_tran` JOIN `textquest` AS `gs_orig` ON `gs_orig`.`ID` = `gs_tran`.`Take`'699 +' FROM `'+table+'` AS `gs_tran` JOIN `'+table+'` AS `gs_orig` ON `gs_orig`.`ID` = `gs_tran`.`Take`' 567 700 +'WHERE `gs_tran`.`VersionEnd` <> `gs_orig`.`VersionEnd` '); 568 701 for i:=0 to DBRows.Count-1 do begin 569 Database.Query('UPDATE ` textquest` SET `VersionEnd` = '+DBRows.Data[i].Values['VersionEnd_orig']+' WHERE `ID` = '+DBRows.Data[i].Values['ID']);702 Database.Query('UPDATE `'+table+'` SET `VersionEnd` = '+DBRows.Data[i].Values['VersionEnd_orig']+' WHERE `ID` = '+DBRows.Data[i].Values['ID']); 570 703 end; 571 704 until (DBRows.Count = 0);
Note:
See TracChangeset
for help on using the changeset viewer.