Changeset 617


Ignore:
Timestamp:
Dec 2, 2013, 8:06:58 PM (10 years ago)
Author:
maron
Message:
Location:
tools/WoWHeadLoader
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • tools/WoWHeadLoader/WoWHeadLoader.lpi

    r612 r617  
    3333      </local>
    3434    </RunParams>
    35     <Units Count="1">
     35    <Units Count="2">
    3636      <Unit0>
    3737        <Filename Value="WoWHeadLoader.lpr"/>
     
    3939        <UnitName Value="WoWHeadLoader"/>
    4040      </Unit0>
     41      <Unit1>
     42        <Filename Value="uglobal.pas"/>
     43        <IsPartOfProject Value="True"/>
     44        <UnitName Value="Uglobal"/>
     45      </Unit1>
    4146    </Units>
    4247  </ProjectOptions>
  • tools/WoWHeadLoader/WoWHeadLoader.lpr

    r616 r617  
    1313  ;
    1414//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{
     16DELETE FROM `wowpreklad`.`TextQuest` WHERE `VersionStart` = 17359;
     17DELETE FROM `wowpreklad`.`TextAchievement` WHERE `VersionStart` = 17359;
     18DELETE FROM `wowpreklad`.`TextGameObject` WHERE `VersionStart` = 17359;
     19DELETE FROM `wowpreklad`.`TextItem` WHERE `VersionStart` = 17359;
     20DELETE FROM `wowpreklad`.`TextCreature` WHERE `VersionStart` = 17359;
     21DELETE FROM `wowpreklad`.`TextArea` WHERE `VersionStart` = 17359;
     22
     23UPDATE  `wowpreklad`.`TextItem` SET  `VersionEnd` = 12340 WHERE  `VersionEnd` = 17359;
     24UPDATE  `wowpreklad`.`TextGameObject` SET  `VersionEnd` = 12340 WHERE  `VersionEnd` = 17359;
     25UPDATE  `wowpreklad`.`TextQuest` SET  `VersionEnd` = 12340 WHERE  `VersionEnd` = 17359;
     26UPDATE  `wowpreklad`.`TextAchievement` SET  `VersionEnd` = 12340 WHERE  `VersionEnd` = 17359;
     27UPDATE  `wowpreklad`.`TextCreature` SET  `VersionEnd` = 12340 WHERE  `VersionEnd` = 17359;
     28UPDATE  `wowpreklad`.`TextArea` SET  `VersionEnd` = 12340 WHERE  `VersionEnd` = 17359;
     29}
    1930type
    2031
     
    3243    procedure Main;
    3344    function skipto(part: string; text: string): string;
    34     function GetPartText(textname: string; text: string): string;
    3545    function TextStringReplace(text:string):string;
    3646    function CompareStrings(textdb: string; textimport: string): boolean;
    3747    function DelHtmlTags(text:string):string;
    3848    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
    4053    function GetEndtextData(data:string): string;
    41 
    42     function GetMaxIDQuest: integer;
    4354    procedure GetTextQuest(Id: Integer);
    4455    procedure UpdateQuest;
    4556
    46     function GetLastVersion: integer;
     57    function GetMaxID(TextType: string): integer;
     58    procedure GetText(Id: Integer;TextType : integer);
    4759end;
    4860var
    4961  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','','','');
    5065
    5166{ TWoWHeadLoader }
     
    126141
    127142procedure TWoWHeadLoader.Main;
    128 
    129 begin
    130   UpdateQuest;
     143var
     144  i,t: integer;
     145begin
     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;
    131158  //čekej před uzavřením
    132159  ReadLn;
     
    245272        Database.Query('UPDATE  `wowpreklad`.`TextQuest` SET  `VersionEnd` = '+IntToStr(ImportedVersion)+' WHERE  `Id` = '+DBRows.Data[0].Values['Id']+' AND `Entry` ='+IntToStr(Id)+';');
    246273        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');
    248275        Exit;   //konec: text je stejný upravili se jenom výsledné verze
    249276      end;
     
    363390
    364391
    365   for i := 0 to GetMaxIDQuest do begin
     392  for i := 0 to GetMaxID('quest') do begin
    366393    GetTextQuest(i);
    367394    write('.');
    368395  end;
     396end;
     397
     398procedure TWoWHeadLoader.GetText(Id: Integer; TextType: Integer);
     399var
     400  part,data, sql,
     401   textname,textdescription: string;
     402  foundtext: boolean = true;
     403  DBRows : TDbRows;
     404  i: integer;
     405begin
     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;
     500end;
     501
     502function TWoWHeadLoader.GetMaxID(TextType: string): integer;
     503var
     504  data:string;
     505  maxid:integer=10000; //34000 pro questy
     506begin
     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);
    369514end;
    370515
     
    387532end;
    388533
    389 function TWoWHeadLoader.GetMaxIDQuest: integer;
    390 var
    391   data:string;
    392   maxid:integer=34000;
    393 begin
    394 //  http://www.wowhead.com/quests?filter=cr=30;crs=1;crv=34000
    395   repeat
    396 
    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 
    403534function TWoWHeadLoader.GetPartText(textname: string; text: string): string;
    404535begin
     
    426557  text := StringReplace(text,'<br />','$B',[rfReplaceAll, rfIgnoreCase]);
    427558  text := StringReplace(text,'<br>','$B',[rfReplaceAll, rfIgnoreCase]);
    428   text := StringReplace(text,'&nbsp;','',[rfReplaceAll, rfIgnoreCase]);
     559  text := StringReplace(text,'&nbsp;',' ',[rfReplaceAll, rfIgnoreCase]);
     560  text := StringReplace(text,'&amp;','&',[rfReplaceAll, rfIgnoreCase]);
     561  text := StringReplace(text,'&#039;',chr(39),[rfReplaceAll, rfIgnoreCase]);
    429562  text := StringReplace(text,'&lt;name&gt;','$N',[rfReplaceAll, rfIgnoreCase]);
    430563  text := StringReplace(text,'&lt;class&gt;','$C',[rfReplaceAll, rfIgnoreCase]);
     
    534667end;
    535668
    536 procedure TWoWHeadLoader.UpdateTranslated;
     669procedure TWoWHeadLoader.UpdateTranslated(table: string);
    537670var
    538671  i:integer;
     
    564697    DBRows := Database.Query('SELECT  `gs_tran`.`ID` ,  `gs_tran`.`VersionEnd` AS  `VersionEnd_tran` ,'
    565698    +'`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`'
    567700    +'WHERE  `gs_tran`.`VersionEnd` <>  `gs_orig`.`VersionEnd` ');
    568701    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']);
    570703    end;
    571704  until (DBRows.Count = 0);
Note: See TracChangeset for help on using the changeset viewer.