64 |
64 |
65 {$I-} // iochecks off |
65 {$I-} // iochecks off |
66 filemode:= 0; // readonly |
66 filemode:= 0; // readonly |
67 Assign(f, FileName); |
67 Assign(f, FileName); |
68 reset(f); |
68 reset(f); |
69 // if the locale does not exist, fallback to the default one |
69 TryDo(IOResult = 0, 'Cannot load locale "' + FileName + '"', false); |
70 if (IOResult <> 0) then |
70 if (IOResult <> 0) then |
71 begin |
71 begin |
72 WriteLnToConsole('Warning: Cannot load selected locale "' + FileName + '" fallback to default en.txt'); |
72 while not eof(f) do |
73 Assign(f, 'en.txt'); |
73 begin |
74 reset(f); |
74 readln(f, s); |
75 end; |
75 if Length(s) = 0 then continue; |
76 |
76 if not (s[1] in ['0'..'9']) then continue; |
77 TryDo(IOResult = 0, 'Cannot load locale "' + FileName + ' nor en.txt"', true); |
77 TryDo(Length(s) > 6, 'Load locale: empty string', true); |
78 while not eof(f) do |
78 val(s[1]+s[2], a, c); |
79 begin |
79 TryDo(c = 0, 'Load locale: numbers should be two-digit: ' + s, true); |
80 readln(f, s); |
80 TryDo(s[3] = ':', 'Load locale: ":" expected', true); |
81 if Length(s) = 0 then continue; |
81 val(s[4]+s[5], b, c); |
82 if not (s[1] in ['0'..'9']) then continue; |
82 TryDo(c = 0, 'Load locale: numbers should be two-digit' + s, true); |
83 TryDo(Length(s) > 6, 'Load locale: empty string', true); |
83 TryDo(s[6] = '=', 'Load locale: "=" expected', true); |
84 val(s[1]+s[2], a, c); |
84 Delete(s, 1, 6); |
85 TryDo(c = 0, 'Load locale: numbers should be two-digit: ' + s, true); |
85 case a of |
86 TryDo(s[3] = ':', 'Load locale: ":" expected', true); |
86 0: if (b >=0) and (b <= ord(High(TAmmoStrId))) then trammo[TAmmoStrId(b+1)]:= s; |
87 val(s[4]+s[5], b, c); |
87 1: if (b >=0) and (b <= ord(High(TMsgStrId))) then trmsg[TMsgStrId(b)]:= s; |
88 TryDo(c = 0, 'Load locale: numbers should be two-digit' + s, true); |
88 2: if (b >=0) and (b <= ord(High(TEventId))) then begin |
89 TryDo(s[6] = '=', 'Load locale: "=" expected', true); |
89 TryDo(trevt_n[TEventId(b)] < MAX_EVENT_STRINGS, 'Too many event strings in ' + inttostr(a) + ':' + inttostr(b), false); |
90 Delete(s, 1, 6); |
90 if first[TEventId(b)] then |
91 case a of |
91 begin |
92 0: if (b >=0) and (b <= ord(High(TAmmoStrId))) then trammo[TAmmoStrId(b+1)]:= s; |
92 trevt_n[TEventId(b)]:= 0; |
93 1: if (b >=0) and (b <= ord(High(TMsgStrId))) then trmsg[TMsgStrId(b)]:= s; |
93 first[TEventId(b)]:= false; |
94 2: if (b >=0) and (b <= ord(High(TEventId))) then begin |
94 end; |
95 TryDo(trevt_n[TEventId(b)] < MAX_EVENT_STRINGS, 'Too many event strings in ' + inttostr(a) + ':' + inttostr(b), false); |
95 trevt[TEventId(b)][trevt_n[TEventId(b)]]:= s; |
96 if first[TEventId(b)] then |
96 inc(trevt_n[TEventId(b)]); |
97 begin |
97 end; |
98 trevt_n[TEventId(b)]:= 0; |
98 end; |
99 first[TEventId(b)]:= false; |
99 end; |
100 end; |
100 Close(f) |
101 trevt[TEventId(b)][trevt_n[TEventId(b)]]:= s; |
101 end |
102 inc(trevt_n[TEventId(b)]); |
|
103 end; |
|
104 end; |
|
105 end; |
|
106 Close(f) |
|
107 {$I+} |
102 {$I+} |
108 end; |
103 end; |
109 |
104 |
110 function GetEventString(e: TEventId): string; |
105 function GetEventString(e: TEventId): string; |
111 begin |
106 begin |