~chronoscz/wowpreklad/trunk

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<?php

define('FILE_NOT_FOUND', 'Soubor "%s" nenalezen.');

class FileStream
{
  private $Handle;
  private $FileName;

  function __construct()
  {
    $this->Handle = false;
  }

  function __destruct()
  {
    if ($this->Handle)
      fclose($this->Handle);
  }

  public function OpenFile($FileName)
  {
    $this->FileName = $FileName;
    $this->CloseFile();
    $this->Handle = fopen($FileName, 'rb');
    if (!$this->Handle) die(str_replace('%s', $FileName, FILE_NOT_FOUND));
  }

  public function CreateFile($FileName)
  {
    $this->FileName = $FileName;
    $this->CloseFile();
    $this->Handle = fopen($FileName, 'wb+');
    if (!$this->Handle) die(str_replace('%s', $FileName, FILE_NOT_FOUND));
  }

  public function CloseFile()
  {
    if ($this->Handle)
      fclose($this->Handle);
  }

  public function ReadBlock($Count)
  {
    return fread($this->Handle, $Count);
  }

  public function ReadByte()
  {
    return fread($this->Handle, 1);
  }

  public function ReadUint()
  {
    $val = unpack('V*', fread($this->Handle, 4));
    return $val[1];
  }

  public function ReadInt()
  {
    $val = unpack('I*', fread($this->Handle, 4));
    return $val[1];
  }

  public function ReadFloat()
  {
    $val = unpack('f*', fread($this->Handle, 4));
    return $val[1];
  }

  public function ReadChar()
  {
    return fread($this->Handle, 1);
  }

  public function ReadLine()
  {
    return fgets($this->Handle);
  }

  public function ReadTextLine()
  {
    return fgets($this->Handle);
  }

  public function WriteBlock($Value, $Count)
  {
    fwrite($this->Handle, $Value, $Count);
  }

  public function WriteByte($Value)
  {
    fwrite($this->Handle, pack('C*', $Value), 1);
  }

  public function WriteUint($Value)
  {
    fwrite($this->Handle, pack('V*', $Value), 4);
  }

  public function WriteInt($Value)
  {
    fwrite($this->Handle, pack('I*', $Value), 4);
  }

  public function WriteFloat($Value)
  {
    fwrite($this->Handle, pack('f*', $Value), 4);
  }

  public function WriteChar($Value)
  {
    fwrite($this->Handle, $Value, 1);
  }

  public function WriteString($Value)
  {
    fwrite($this->Handle, $Value);
  }

  public function WriteLine($Value)
  {
    fputs($this->Handle, $Value);
  }

  public function SetPosition($Position)
  {
    fseek($this->Handle, $Position, SEEK_SET);
  }

  public function GetPosition()
  {
    return ftell($this->Handle);
  }

  public function GetSize()
  {
    return filesize($this->FileName);
  }

  public function SetSize($Size)
  {
    return ftruncate($this->Handle, $Size);
  }

  public function EOF()
  {
    return feof($this->Handle);
  }
}