Changeset 616 for tools/WoWHeadLoader


Ignore:
Timestamp:
Nov 29, 2013, 6:09:49 PM (11 years ago)
Author:
maron
Message:
  • Added: compare with both sex

repair some bugs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/WoWHeadLoader/WoWHeadLoader.lpr

    r612 r616  
    3838    function SqlPre(text: string):string;
    3939    procedure UpdateTranslated;
     40    function GetEndtextData(data:string): string;
    4041
    4142    function GetMaxIDQuest: integer;
     
    118119end;
    119120
    120 procedure TWoWHeadLoader.WriteHelp;       //    D:\ProgramFiles\lazarus\units\indy-10.2.0.3\fpc\
     121procedure TWoWHeadLoader.WriteHelp;
    121122begin
    122123  { add your help code here }
     
    148149     data := IdHTTP1.Get('http://www.wowhead.com/quest='+IntToStr(Id));
    149150    // WriteLn(data);
    150      if (pos('<b style="color: red">This quest was marked obsolete',data) > 0) or (pos('ewr<b style="color: red">This quest is no longer available',data) > 0) then begin
     151     if (pos('<b style="color: red">This quest was marked obsolete',data) > 0) or (pos('<b style="color: red">This quest is no longer available',data) > 0) then begin
    151152       foundtext:=false;
    152153       Exit;
     
    177178     textobject := TextStringReplace(Copy(data,0,Pos('<',data)-1));
    178179
    179      //endtext
    180 
    181 
    182      data := skipto('<table class="iconlist">',data);
    183      //mazání podsupin u objektů questu
    184      if (0 < Pos('<div id="npcgroup-',data)) then begin
    185        data := StringReplace(data,'<div','#@{',[rfIgnoreCase]);
    186        while (Pos('<div',data) < Pos('</div',data)) and (Pos('<div',data) >0) do begin
    187          data := StringReplace(data,'</div','',[rfIgnoreCase]);
    188          data := StringReplace(data,'<div','',[rfIgnoreCase]);
    189        end;
    190        data := Copy(data,0,Pos('#@{',data))+Copy(data,Pos('</div',data),Length(data));
    191        data := StringReplace(data,'</div','',[rfIgnoreCase]);
    192      end;
    193      if (0 < Pos('<div id="npcgroup-',data)) then begin
    194        data := StringReplace(data,'<div','#@{',[rfIgnoreCase]);
    195        while (Pos('<div',data) < Pos('</div',data)) and (Pos('<div',data) >0) do begin
    196          data := StringReplace(data,'</div','',[rfIgnoreCase]);
    197          data := StringReplace(data,'<div','',[rfIgnoreCase]);
    198        end;
    199        data := Copy(data,0,Pos('#@{',data))+Copy(data,Pos('</div',data),Length(data));
    200        data := StringReplace(data,'</div','',[rfIgnoreCase]);
    201      end;
    202      if (0 < Pos('<div id="npcgroup-',data)) then begin
    203        data := StringReplace(data,'<div','#@{',[rfIgnoreCase]);
    204        while (Pos('<div',data) < Pos('</div',data)) and (Pos('<div',data) >0) do begin
    205          data := StringReplace(data,'</div','',[rfIgnoreCase]);
    206          data := StringReplace(data,'<div','',[rfIgnoreCase]);
    207        end;
    208        data := Copy(data,0,Pos('#@{',data))+Copy(data,Pos('</div',data),Length(data));
    209        data := StringReplace(data,'</div','',[rfIgnoreCase]);
    210      end;
    211      //mazání podsupin u objektů questu
    212      if (0 < Pos('<div id="npcgroup-',data)) then begin
    213        data := StringReplace(data,'<div','#@{',[rfIgnoreCase]);
    214        while (Pos('<div',data) < Pos('</div',data)) and (Pos('<div',data) >0) do begin
    215          data := StringReplace(data,'</div','',[rfIgnoreCase]);
    216          data := StringReplace(data,'<div','',[rfIgnoreCase]);
    217        end;
    218        data := Copy(data,0,Pos('#@{',data))+Copy(data,Pos('</div',data),Length(data));
    219        data := StringReplace(data,'</div','',[rfIgnoreCase]);
    220      end;
    221      data := Copy(data,0,Pos('</table',data));
     180     //endtext+objects
     181     data:=GetEndtextData(data);
     182  //   WriteLn(data);
    222183
    223184
     
    232193         textend:='';
    233194       end;
    234        if ((Pos('<',part) = 0) and (Pos('&nbsp;',part) = 0)) then begin
     195       if ((Pos('<',part) = 0) and (Pos('#',part) = 0) and (Pos('&nbsp;',part) = 0)) then begin
    235196         // part := Copy(part,0,Pos('&nbsp;',part)-1);
    236197          textend:=TextStringReplace(DelHtmlTags(part));
    237198       end;
    238        if ((Pos('object=',part) > 0) or (Pos('javascript',part) > 0) or ((itemfound = false) and (Pos('<',part) = 0))) then begin
     199       if ((Pos('object=',part) > 0) or (Pos('javascript',part) > 0) or ((itemfound = false) and  (Pos('#',part) = 0) and (Pos('<',part) = 0))) then begin
    239200         part := Copy(part,0,Pos('&nbsp;',part)-1);
    240201         part := TextStringReplace(DelHtmlTags(part)); //todo
     
    258219  If foundtext then begin
    259220    DBRows := Database.Query('SELECT * FROM  `TextQuest` WHERE  `Entry` ='+IntToStr(Id)+' AND  `Language` =0 ORDER BY  `TextQuest`.`VersionEnd` DESC ');
    260     if (DBRows.Count > 0) then
    261     if (
    262     CompareStrings(DBRows.Data[0].Values['Title'],textname) and
    263     CompareStrings(DBRows.Data[0].Values['Objectives'],textobject) and
    264     CompareStrings(DBRows.Data[0].Values['Details'],textdescription) and
    265     CompareStrings(DBRows.Data[0].Values['OfferRewardText'],textcomplection) and
    266     CompareStrings(DBRows.Data[0].Values['RequestItemsText'],textprogress) and
    267     CompareStrings(DBRows.Data[0].Values['EndText'],textend) and
    268     CompareStrings(DBRows.Data[0].Values['ObjectiveText1'],textobjective1) and
    269     CompareStrings(DBRows.Data[0].Values['ObjectiveText2'],textobjective2) and
    270     CompareStrings(DBRows.Data[0].Values['ObjectiveText3'],textobjective3) and
    271     CompareStrings(DBRows.Data[0].Values['ObjectiveText4'],textobjective4)
    272     ) then
     221    if (DBRows.Count > 0) then begin
     222      if (DBRows.Data[0].Values['VersionEnd'] = IntToStr(ImportedVersion)) then Exit;  //konec pokud už tam text je
     223      if (
     224        CompareStrings(DBRows.Data[0].Values['Title'],textname) and
     225        CompareStrings(DBRows.Data[0].Values['Objectives'],textobject) and
     226        CompareStrings(DBRows.Data[0].Values['Details'],textdescription) and
     227        CompareStrings(DBRows.Data[0].Values['OfferRewardText'],textcomplection) and
     228        CompareStrings(DBRows.Data[0].Values['RequestItemsText'],textprogress) and
     229        CompareStrings(DBRows.Data[0].Values['ObjectiveText2'],textobjective2) and
     230        CompareStrings(DBRows.Data[0].Values['ObjectiveText3'],textobjective3) and
     231        CompareStrings(DBRows.Data[0].Values['ObjectiveText4'],textobjective4) and
     232        (
     233          (
     234            CompareStrings(DBRows.Data[0].Values['EndText'],textend) and
     235            CompareStrings(DBRows.Data[0].Values['ObjectiveText1'],textobjective1)
     236          ) or
     237          (
     238            CompareStrings(DBRows.Data[0].Values['EndText'],textobjective1) and
     239            CompareStrings(DBRows.Data[0].Values['ObjectiveText1'],textend)
     240          )
     241        )
     242      ) then
     243      begin
     244        //text je stejný
     245        Database.Query('UPDATE  `wowpreklad`.`TextQuest` SET  `VersionEnd` = '+IntToStr(ImportedVersion)+' WHERE  `Id` = '+DBRows.Data[0].Values['Id']+' AND `Entry` ='+IntToStr(Id)+';');
     246        Database.Query('UPDATE  `wowpreklad`.`TextQuest` SET  `VersionEnd` = '+IntToStr(ImportedVersion)+' WHERE  `Take` = '+DBRows.Data[0].Values['Id']+' AND `Entry` ='+IntToStr(Id)+';');
     247        UpdateTranslated;
     248        Exit;   //konec: text je stejný upravili se jenom výsledné verze
     249      end;
     250//      if not (
     251//      CompareStrings(DBRows.Data[0].Values['EndText'],textend) and
     252  //    CompareStrings(DBRows.Data[0].Values['ObjectiveText1'],textobjective1) and
     253    //  CompareStrings(DBRows.Data[0].Values['ObjectiveText2'],textobjective2) and
     254//      CompareStrings(DBRows.Data[0].Values['ObjectiveText3'],textobjective3) and
     255//      CompareStrings(DBRows.Data[0].Values['ObjectiveText4'],textobjective4)
     256 //     ) then Readln;
     257    end;
     258
    273259    begin
    274       //text je stejný
    275       Database.Query('UPDATE  `wowpreklad`.`TextQuest` SET  `VersionEnd` = '+IntToStr(ImportedVersion)+' WHERE  `Id` = '+DBRows.Data[0].Values['Id']+' AND `Entry` ='+IntToStr(Id)+';');
    276       DBRows :=   Database.Query('UPDATE  `wowpreklad`.`TextQuest` SET  `VersionEnd` = '+IntToStr(ImportedVersion)+' WHERE  `Take` = '+DBRows.Data[0].Values['Id']+' AND `Entry` ='+IntToStr(Id)+';');
    277       //TODO: update caskadově všechny texty vycházející z této verze
    278       UpdateTranslated;
    279       Exit;
    280     end;
    281 
    282     begin
    283       //v databázi je víc textu než v importu -> vytvoř novou verzi a vytvoř nový překlad
    284260      {
    285261      WriteLn('INSERT INTO  `wowpreklad`.`TextQuest` ('
     
    321297    end;
    322298
     299    {
    323300    if (DBRows.Count = 0) then Exit;
    324     {
    325301    WriteLn('guest='+IntToStr(Id)+' DB "'
    326302    +DBRows.Data[0].Values['Title']+ '" '+chr(10)+
     
    349325    }
    350326
    351 
    352    // ReadLn;
    353   end;
    354 //  else   WriteLn('guest='+IntToStr(Id)+' Nenalezen');
    355 
     327  end;
    356328  except
    357329     on E: EIdHTTPProtocolException do
     
    363335      on E:Exception do
    364336        GetTextQuest(Id);
    365    //  on E: EIdSocketError do then
    366   //       foundtext := false;
    367   //   end;
    368337  end;
    369338end;
     
    374343  i:integer;
    375344begin
    376   GetTextQuest(12996);
    377   GetTextQuest(13105);
    378 
    379   GetTextQuest(13164);
    380 
    381   GetTextQuest(13358);
    382 
    383   GetTextQuest(13375);
     345  GetTextQuest(7081);
     346  GetTextQuest(7122);
     347  GetTextQuest(9192);
     348
     349  GetTextQuest(12509);
     350
     351
     352  GetTextQuest(12580);
    384353
    385354  GetTextQuest(13369);
     
    394363
    395364
    396   for i := 12865 to GetMaxIDQuest do begin
     365  for i := 0 to GetMaxIDQuest do begin
    397366    GetTextQuest(i);
    398367    write('.');
     
    491460
    492461function TWoWHeadLoader.CompareStrings(textdb: string; textimport: string): boolean;
     462var
     463  part,data :string;
    493464begin
    494465  textdb:=DelHtmlTags(LowerCase(textdb));
     466  textdb := StringReplace(textdb,'s'+chr(39)+'s','',[rfReplaceAll, rfIgnoreCase]);
     467  textdb := StringReplace(textdb,'s'+chr(39),'',[rfReplaceAll, rfIgnoreCase]);
     468  textdb := StringReplace(textdb,chr(39)+'s','',[rfReplaceAll, rfIgnoreCase]);
     469  textdb := StringReplace(textdb,chr(39),'',[rfReplaceAll, rfIgnoreCase]);
     470
    495471  textdb := StringReplace(textdb,' ','',[rfReplaceAll, rfIgnoreCase]);
    496472  textdb := StringReplace(textdb,',','',[rfReplaceAll, rfIgnoreCase]);
     
    499475  textdb := StringReplace(textdb,chr(13),'',[rfReplaceAll, rfIgnoreCase]);
    500476  textdb := StringReplace(textdb,'$b','',[rfReplaceAll, rfIgnoreCase]);
    501   textdb := StringReplace(textdb,'$B','',[rfReplaceAll, rfIgnoreCase]);
    502 //  textdb := StringReplace(textdb,'$n','$N',[rfReplaceAll, rfIgnoreCase]);
    503 //  textdb := StringReplace(textdb,'$g','$G',[rfReplaceAll, rfIgnoreCase]);
    504 //  textdb := StringReplace(textdb,'$c','$C',[rfReplaceAll, rfIgnoreCase]);
    505 //  textdb := StringReplace(textdb,'$r','$R',[rfReplaceAll, rfIgnoreCase]);
    506   textdb := StringReplace(textdb,'s'+chr(39)+'s','',[rfReplaceAll, rfIgnoreCase]);
    507   textdb := StringReplace(textdb,'s'+chr(39),'',[rfReplaceAll, rfIgnoreCase]);
    508   textdb := StringReplace(textdb,chr(39)+'s','',[rfReplaceAll, rfIgnoreCase]);
    509   textdb := StringReplace(textdb,chr(39),'',[rfReplaceAll, rfIgnoreCase]);
    510477
    511478  textimport:=DelHtmlTags(LowerCase(textimport));
     
    514481  textimport := StringReplace(textimport,chr(39)+'s','',[rfReplaceAll, rfIgnoreCase]);
    515482  textimport := StringReplace(textimport,chr(39),'',[rfReplaceAll, rfIgnoreCase]);
    516 //  textimport := StringReplace(textimport,'$n','$N',[rfReplaceAll, rfIgnoreCase]);
    517 //  textimport := StringReplace(textimport,'$g','$G',[rfReplaceAll, rfIgnoreCase]);
    518 //  textimport := StringReplace(textimport,'$c','$C',[rfReplaceAll, rfIgnoreCase]);
    519 //  textimport := StringReplace(textimport,'$r','$R',[rfReplaceAll, rfIgnoreCase]);
     483
    520484  textimport := StringReplace(textimport,' ','',[rfReplaceAll, rfIgnoreCase]);
    521485  textimport := StringReplace(textimport,',','',[rfReplaceAll, rfIgnoreCase]);
     
    524488  textimport := StringReplace(textimport,chr(13),'',[rfReplaceAll, rfIgnoreCase]);
    525489  textimport := StringReplace(textimport,'$b','',[rfReplaceAll, rfIgnoreCase]);
    526   textimport := StringReplace(textimport,'$B','',[rfReplaceAll, rfIgnoreCase]);
    527490  if ((textdb = textimport) or ( (textdb <> '') and (textimport = '') )) then Result := true
    528491  else begin
    529     //TODO: smazat celé $g pro porovnání
    530     Result:=false;
    531     WriteLn(textdb);
    532     WriteLn(textimport);
    533   //  ReadLn;
     492    //zkusím rozgenerovat $g nejdřív podle prvního
     493    data:=textdb;
     494    while (Pos('$g',data)> 0) do begin
     495      part := skipto('$g',data);
     496      part := '$g'+Copy(part,0,Pos(';',part));
     497      data := StringReplace(data,part,Copy(part,3,Pos(':',part)-3),[rfReplaceAll, rfIgnoreCase]);
     498    end;
     499    if (data = textimport) then
     500    Result := true else begin
     501      data:=textdb;
     502      while (Pos('$g',data)> 0) do begin
     503        part := skipto('$g',data);
     504        part := '$g'+Copy(part,0,Pos(';',part));
     505        data := StringReplace(data,part,Copy(part,Pos(':',part)+1,Length(part)-1-Pos(':',part)),[rfReplaceAll, rfIgnoreCase]);
     506      end;
     507      if (data = textimport) then
     508      Result := true else begin
     509        Result:=false;
     510        WriteLn('db: '+textdb);
     511        WriteLn('in: '+textimport);
     512      end;
     513    end;
    534514  end;
    535515end;
     
    593573end;
    594574
     575function TWoWHeadLoader.GetEndtextData(data: string): string;
     576var
     577  i:integer;
     578begin
     579  data := skipto('<table class="iconlist">',data);
     580  //mazání podsupin u objektů questu
     581  for i:=0 to 4 do begin
     582    if (0 < Pos('<div id="npcgroup-',data)) then begin
     583      data := StringReplace(data,'<div','#@{',[rfIgnoreCase]);
     584      while (Pos('<div',data) < Pos('</div',data)) and (Pos('<div',data) >0) do begin
     585        data := StringReplace(data,'</div','',[rfIgnoreCase]);
     586        data := StringReplace(data,'<div','',[rfIgnoreCase]);
     587      end;
     588      data := Copy(data,0,Pos('#@{',data))+Copy(data,Pos('</div',data),Length(data));
     589      data := StringReplace(data,'</div','',[rfIgnoreCase]);
     590    end;
     591  end;
     592//  WriteLn(Copy(data,0,Pos('</table',data)));
     593  if (skipto('<table class="iconlist">',data) <> data) then
     594    data := Copy(data,0,Pos('</table',data))+skipto('<table class="iconlist">',data);
     595//  WriteLn(Copy(data,0,Pos('</table',data)));
     596  //writeln(data);
     597  //mazání podsupin u objektů questu
     598  for i:=0 to 4 do begin
     599    if (0 < Pos('<div id="npcgroup-',data)) then begin
     600      data := StringReplace(data,'<div','#@{',[rfIgnoreCase]);
     601      while (Pos('<div',data) < Pos('</div',data)) and (Pos('<div',data) >0) do begin
     602        data := StringReplace(data,'</div','',[rfIgnoreCase]);
     603        data := StringReplace(data,'<div','',[rfIgnoreCase]);
     604      end;
     605      data := Copy(data,0,Pos('#@{',data))+Copy(data,Pos('</div',data),Length(data));
     606      data := StringReplace(data,'</div','',[rfIgnoreCase]);
     607    end;
     608  end;
     609  data := Copy(data,0,Pos('</table',data));
     610  Result:=data;
     611end;
     612
    595613var
    596614  Application: TWoWHeadLoader;
Note: See TracChangeset for help on using the changeset viewer.