Changeset 447


Ignore:
Timestamp:
Apr 12, 2010, 8:42:44 AM (14 years ago)
Author:
george
Message:
  • Opraveno: Nastavení anonymního uživatele pro aplikace spouštěné z příkazové řádky.
  • Upraveno: Optimalizace generování DBC souborů. Redukce počtu seeků při čtení a zápisu celých řádků. Načítání celých řádků(záznamů) ze souboru do vyrovnávací paměti do struktury MemoryStream. Zobecnění funkcí FileStreamu a MemoryStreamu.
Location:
trunk
Files:
3 added
1 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/download.php

    r442 r447  
    5353
    5454  echo('<h3>Pomocné programy:</h3>'.
    55   '<a href="download/mpqediten32.zip">Ladik\'s MPQ Editor</a><br />'.
     55  '<a href="http://zezula.net/download/mpqediten32.zip">Ladik\'s MPQ Editor</a> <a href="http://zezula.net/">Stránky autora</a><br />'.
    5656  '<a href="download/wowsig.exe">WoWsig.exe addon signature generator by wad (2005)</a><br />'.
    5757  '<a href="download/DBCtoCSV.exe">DBCtoCSV</a> - nástroj pro převod souborů DBC na CSV<br />');
  • trunk/includes/dbc.php

    r443 r447  
    11<?php
    22
    3 include('stream.php');
     3include_once('FileStream.php');
     4include_once('MemoryStream.php');
    45
    56define('NOT_DBC_FILE', 'Není DBC soubor.');
     
    9798  }
    9899 
    99   private function SeekPosi($Row, $Column)
    100   {
    101     $Position = $this->HeaderSize + $Row * $this->RecordSize + $this->Offsets[$Column];
    102     $this->Seek($Position);
     100  private function CellPos($Row, $Column)
     101  {
     102    return($this->HeaderSize + $Row * $this->RecordSize + $this->Offsets[$Column]);
    103103  }
    104104   
    105105  public function GetByte($Row, $Column)
    106106  {
    107     $this->SeekPosi($Row, $Column); 
     107    $this->SetPosition($this->CellPos($Row, $Column)); 
    108108    return($this->ReadByte());
    109109  }   
     
    111111  public function GetUInt($Row, $Column)
    112112  {
    113     $this->SeekPosi($Row, $Column); 
     113    $this->SetPosition($this->CellPos($Row, $Column)); 
    114114    return($this->ReadUint());
    115115  }
     
    117117  public function GetInt($Row, $Column)
    118118  {
    119     $this->SeekPosi($Row, $Column); 
     119    $this->SetPosition($this->CellPos($Row, $Column)); 
    120120    return($this->ReadInt());
    121121  } 
     
    123123  public function GetFloat($Row, $Column)
    124124  {
    125     $this->SeekPosi($Row, $Column); 
     125    $this->SetPosition($this->CellPos($Row, $Column)); 
    126126    return($this->ReadFloat());
    127127  }
     
    129129  public function SetByte($Row, $Column, $Value)
    130130  {
    131     $this->SeekPosi($Row, $Column); 
     131    $this->SetPosition($this->CellPos($Row, $Column)); 
    132132    $this->WriteByte($Value);
    133133  }   
     
    135135  public function SetUint($Row, $Column, $Value)
    136136  {
    137     $this->SeekPosi($Row, $Column); 
     137    $this->SetPosition($this->CellPos($Row, $Column)); 
    138138    $this->WriteUint($Value);
    139139  }
     
    141141  public function SetInt($Row, $Column, $Value)
    142142  {
    143     $this->SeekPosi($Row, $Column); 
     143    $this->SetPosition($this->CellPos($Row, $Column)); 
    144144    $this->WriteInt($Value);
    145145  } 
     
    147147  public function SetFloat($Row, $Column, $Value)
    148148  {
    149     $this->SeekPosi($Row, $Column); 
     149    $this->SetPosition($this->CellPos($Row, $Column)); 
    150150    $this->WriteFloat($Value);
    151151  }
     
    157157    $Position = $this->HeaderSize + $this->RecordCount * $this->RecordSize + $Offset;
    158158    if($Position >= $this->GetSize()) return('');
    159     $this->Seek($Position);
     159    $this->SetPosition($Position);
    160160     
    161161    $String = '';
     
    184184  {
    185185    $this->SetSize($this->HeaderSize + $this->RecordSize * $this->RecordCount); // Preallocate file
    186     $this->Seek(0);
     186    $this->SetPosition(0);
    187187    $this->WriteUint(DBC_SIGNATURE);
    188188    $this->WriteUint($this->RecordCount);
     
    190190    $this->WriteUint($this->RecordSize);
    191191    $this->WriteUint($this->StringOffset);         
    192     $this->Seek($this->HeaderSize + $this->RecordCount * $this->RecordSize);
     192    $this->SetPosition($this->HeaderSize + $this->RecordCount * $this->RecordSize);
    193193    $this->WriteByte(0);
    194194    foreach($this->StringList as $Index => $Item)
     
    200200  public function GetLine($Row)
    201201  {
     202    // Cache record data
     203    $Record = new MemoryStream();
     204    $this->SetPosition($this->CellPos($Row, 0));
     205    $Record->Data = $this->ReadBlock($this->RecordSize);
     206   
    202207    // Preallocate array
    203208    if($this->FieldCount > 0) $Line = array_fill(0, $this->FieldCount, 0);
     
    207212      if(array_key_exists($I, $this->ColumnFormat)) $Format = $this->ColumnFormat[$I];
    208213        else $Format = FORMAT_UINT32;
     214      $Record->SetPosition($this->Offsets[$I]); 
    209215      switch($Format)
    210216      {
    211217        case FORMAT_BYTE:
    212           $Line[$I] = $this->GetByte($Row, $I);
     218          $Line[$I] = $Record->ReadByte();
    213219          break;
    214220        case FORMAT_UINT32:
    215           $Line[$I] = $this->GetUInt($Row, $I);
     221          $Line[$I] = $Record->ReadUInt();
    216222          break;
    217223        case FORMAT_SINT32:
    218           $Line[$I] = $this->GetInt($Row, $I);
     224          $Line[$I] = $Record->ReadInt();
    219225          break;
    220226        case FORMAT_SINGLE:
    221           $Line[$i] = $this->GetFloat($Row, $I);
     227          $Line[$I] = $Record->ReadFloat();
    222228          break;
    223229        case FORMAT_STRING:
    224           $Line[$I] = $this->GetString($Row, $I);
     230          $Offset = $Record->ReadUint();
     231             
     232          $Position = $this->HeaderSize + $this->RecordCount * $this->RecordSize + $Offset;
     233          if($Position >= $this->GetSize()) $String = '';
     234          else
     235          {
     236            $this->SetPosition($Position);     
     237            $String = '';
     238            while(($Char = $this->ReadChar()) != "\0")
     239              $String .= $Char;
     240          }
     241          $Line[$I] = $String;
    225242          break;
    226243        default:
     
    233250  public function SetLine($Row, $Line)
    234251  {
     252    // Cache record data
     253    $Record = new MemoryStream();
     254   
    235255    for($I = 0; $I < $this->FieldCount; $I++)
    236256    {
    237257      if(array_key_exists($I, $this->ColumnFormat)) $Format = $this->ColumnFormat[$I];
    238258        else $Format = FORMAT_UINT32;
     259      $Record->SetPosition($this->Offsets[$I]); 
    239260      switch($Format)
    240261      {
    241262        case FORMAT_BYTE:
    242           $this->SetByte($Row, $I, $Line[$I]);
     263          $Record->WriteByte($Line[$I]);
    243264          break;
    244265        case FORMAT_UINT32:
    245           $this->SetUint($Row, $I, $Line[$I]);
     266          $Record->WriteUint($Line[$I]);
    246267          break;
    247268        case FORMAT_SINT32:
    248           $this->SetInt($Row, $I, $Line[$I]);
     269          $Record->WriteInt($Line[$I]);
    249270          break;
    250271        case FORMAT_SINGLE:
    251           $this->SetFloat($Row, $I, $Line[$i]);
     272          $Record->WriteFloat($Line[$I]);
    252273          break;
    253274        case FORMAT_STRING:
    254           $this->SetString($Row, $I, $Line[$I]);
     275          if(in_array($Line[$I], $this->StringList))
     276          {
     277            $Record->WriteUint($this->StringListOffset[array_search($Line[$I], $this->StringList)]);
     278          } else
     279          {
     280            $Record->WriteUint($this->StringOffset);
     281            $this->StringList[] = $Line[$I];
     282            $this->StringListOffset[] = $this->StringOffset;
     283            $this->StringOffset += strlen($Line[$I]) + 1;
     284          }
    255285          break;
    256286        default:
     
    258288      }
    259289    }
     290   
     291    $this->SetPosition($this->CellPos($Row, 0));
     292    $this->WriteBlock($Record->Data, $this->RecordSize);
    260293    return($Line);
    261   }
    262    
    263   public function GetLineCols($Row, $Columns)
    264   {
    265     // Preallocate array
    266     if(count($Columns) > 0) $Line = array_fill(0, count($Columns), 0);
    267       else $Line = array();
    268     for($I = 0; $I < count($Columns); $I++)
    269     {
    270       if(array_key_exists($I, $this->ColumnFormat)) $Format = $this->ColumnFormat[$I];
    271         else $Format = FORMAT_UINT32;
    272       switch($Format)
    273       {
    274         case FORMAT_BYTE:
    275           $Line[$I] = $this->GetByte($Row, $Columns[$I]);
    276           break;
    277         case FORMAT_UINT32:
    278           $Line[$I] = $this->GetUint($Row, $Columns[$I]);
    279           break;
    280         case FORMAT_SINT32:
    281           $Line[$I] = $this->GetInt($Row, $Columns[$I]);
    282           break;
    283         case FORMAT_SINGLE:
    284           $Line[$i] = $this->GetFloat($Row, $Columns[$I]);
    285           break;
    286         case FORMAT_STRING:
    287           $Line[$I] = $this->GetString($Row, $Columns[$I]);
    288           break;
    289         default:
    290           break;
    291       }
    292     }
    293     return($Line); 
    294   }
     294  } 
    295295   
    296296  public function GetRecordCount()
  • trunk/includes/user.php

    r378 r447  
    1919  {
    2020    if(isset($_SESSION)) $this->Restore();   
     21      else $this->SetAnonymous();
    2122  }
    2223 
Note: See TracChangeset for help on using the changeset viewer.