index 3f13946bcb1dea1532c6805ad57af2ae4854449a..1419f264faf6876b54adfe1d0b3f4dfa076bf713 100644 (file)
--- a/src/shared/wadreader.pas
+++ b/src/shared/wadreader.pas
-(* Copyright (C) DooM 2D:Forever Developers
+(* Copyright (C) Doom 2D: Forever Developers
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
+ * the Free Software Foundation, version 3 of the License ONLY.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
interface
uses
interface
uses
- mempool, sfs, xstreams, Classes;
+ Classes,
+ {$IFDEF USE_MEMPOOL}mempool,{$ENDIF}
+ sfs, xstreams, utils;
type
type
- SArray = array of ShortString;
-
- TWADFile = class(TPoolObject)
+ TWADFile = class{$IFDEF USE_MEMPOOL}(TPoolObject){$ENDIF}
private
fFileName: AnsiString; // empty: not opened
fIter: TSFSFileList;
private
fFileName: AnsiString; // empty: not opened
fIter: TSFSFileList;
function GetResource (name: AnsiString; var pData: Pointer; var Len: Integer; logError: Boolean=true): Boolean;
function GetMapResource (name: AnsiString; var pData: Pointer; var Len: Integer; logError: Boolean=true): Boolean;
function GetResource (name: AnsiString; var pData: Pointer; var Len: Integer; logError: Boolean=true): Boolean;
function GetMapResource (name: AnsiString; var pData: Pointer; var Len: Integer; logError: Boolean=true): Boolean;
- function GetMapResources (): SArray;
+ function GetMapResources (): SSArray;
// returns `nil` if file wasn't found
function openFileStream (name: AnsiString): TStream;
// returns `nil` if file wasn't found
function openFileStream (name: AnsiString): TStream;
property isOpen: Boolean read getIsOpen;
end;
property isOpen: Boolean read getIsOpen;
end;
-
+// g_ExtractWadName C:\svr\shit.wad:\MAPS\MAP01 -> C:/svr/shit.wad
function g_ExtractWadName (resourceStr: AnsiString): AnsiString;
function g_ExtractWadName (resourceStr: AnsiString): AnsiString;
+
+// g_ExtractWadNameNoPath C:\svr\shit.wad:\MAPS\MAP01 -> shit.wad
function g_ExtractWadNameNoPath (resourceStr: AnsiString): AnsiString;
function g_ExtractWadNameNoPath (resourceStr: AnsiString): AnsiString;
+
+// g_ExtractFilePath C:\svr\shit.wad:\MAPS\MAP01 -> :/MAPS
function g_ExtractFilePath (resourceStr: AnsiString): AnsiString;
function g_ExtractFilePath (resourceStr: AnsiString): AnsiString;
+
+// g_ExtractFileName C:\svr\shit.wad:\MAPS\MAP01 -> MAP01
function g_ExtractFileName (resourceStr: AnsiString): AnsiString; // without path
function g_ExtractFileName (resourceStr: AnsiString): AnsiString; // without path
-function g_ExtractFilePathName (resourceStr: AnsiString): AnsiString;
-// return fixed AnsiString or empty AnsiString
-function findDiskWad (fname: AnsiString): AnsiString;
+// g_ExtractFilePathName C:\svr\shit.wad:\MAPS\MAP01 -> MAPS/MAP01
+function g_ExtractFilePathName (resourceStr: AnsiString): AnsiString;
var
var
implementation
uses
implementation
uses
- SysUtils, e_log, utils, MAPDEF, xdynrec;
-
-
-function findDiskWad (fname: AnsiString): AnsiString;
-begin
- result := '';
- if not findFileCI(fname) then
- begin
- //e_WriteLog(Format('findDiskWad: error looking for [%s]', [fname]), MSG_NOTIFY);
- if StrEquCI1251(ExtractFileExt(fname), '.wad') then
- begin
- fname := ChangeFileExt(fname, '.pk3');
- //e_WriteLog(Format(' looking for [%s]', [fname]), MSG_NOTIFY);
- if not findFileCI(fname) then
- begin
- fname := ChangeFileExt(fname, '.zip');
- //e_WriteLog(Format(' looking for [%s]', [fname]), MSG_NOTIFY);
- if not findFileCI(fname) then exit;
- end;
- end
- else
- begin
- exit;
- end;
- end;
- //e_WriteLog(Format('findDiskWad: FOUND [%s]', [fname]), MSG_NOTIFY);
- result := fname;
-end;
+ SysUtils, e_log, MAPDEF, xdynrec;
function normSlashes (s: AnsiString): AnsiString;
function normSlashes (s: AnsiString): AnsiString;
if fs = nil then
begin
if wantMap then continue;
if fs = nil then
begin
if wantMap then continue;
- if logError then e_WriteLog(Format('DFWAD: can''t open file [%s] in [%s]', [name, fFileName]), MSG_WARNING);
+ if logError then e_WriteLog(Format('DFWAD: can''t open file [%s] in [%s]', [name, fFileName]), TMsgType.Warning);
break;
end;
// if we want only maps, check if this is map
break;
end;
// if we want only maps, check if this is map
result := true;
{$IFDEF SFS_DFWAD_DEBUG}
if wadoptDebug then
result := true;
{$IFDEF SFS_DFWAD_DEBUG}
if wadoptDebug then
- e_WriteLog(Format('DFWAD: file [%s] FOUND in [%s]; size is %d bytes', [name, fFileName, Len]), MSG_NOTIFY);
+ e_WriteLog(Format('DFWAD: file [%s] FOUND in [%s]; size is %d bytes', [name, fFileName, Len]), TMsgType.Notify);
{$ENDIF}
exit;
end;
end;
{$ENDIF}
exit;
end;
end;
- if logError then e_WriteLog(Format('DFWAD: file [%s] not found in [%s]', [name, fFileName]), MSG_WARNING);
+ if logError then e_WriteLog(Format('DFWAD: file [%s] not found in [%s]', [name, fFileName]), TMsgType.Warning);
end;
function TWADFile.GetResource (name: AnsiString; var pData: Pointer; var Len: Integer; logError: Boolean=true): Boolean;
end;
function TWADFile.GetResource (name: AnsiString; var pData: Pointer; var Len: Integer; logError: Boolean=true): Boolean;
result := GetResourceEx(name, true, pData, Len, logError);
end;
result := GetResourceEx(name, true, pData, Len, logError);
end;
-function TWADFile.GetMapResources (): SArray;
+function TWADFile.GetMapResources (): SSArray;
var
f, c: Integer;
fi: TSFSFileInfo;
var
f, c: Integer;
fi: TSFSFileInfo;
rfn := findDiskWad(FileName);
if length(rfn) = 0 then
begin
rfn := findDiskWad(FileName);
if length(rfn) = 0 then
begin
- e_WriteLog(Format('TWADFile.ReadFile: error looking for [%s]', [FileName]), MSG_NOTIFY);
+ e_WriteLog(Format('TWADFile.ReadFile: error looking for [%s]', [FileName]), TMsgType.Notify);
exit;
end;
{$IFDEF SFS_DFWAD_DEBUG}
exit;
end;
{$IFDEF SFS_DFWAD_DEBUG}
- if wadoptDebug then e_WriteLog(Format('TWADFile.ReadFile: FOUND [%s]', [rfn]), MSG_NOTIFY);
+ if wadoptDebug then e_WriteLog(Format('TWADFile.ReadFile: FOUND [%s]', [rfn]), TMsgType.Notify);
{$ENDIF}
// cache this wad
try
{$ENDIF}
// cache this wad
try
if fIter = nil then Exit;
fFileName := rfn;
{$IFDEF SFS_DFWAD_DEBUG}
if fIter = nil then Exit;
fFileName := rfn;
{$IFDEF SFS_DFWAD_DEBUG}
- if wadoptDebug then e_WriteLog(Format('TWADFile.ReadFile: [%s] opened', [fFileName]), MSG_NOTIFY);
+ if wadoptDebug then e_WriteLog(Format('TWADFile.ReadFile: [%s] opened', [fFileName]), TMsgType.Notify);
{$ENDIF}
Result := True;
end;
{$ENDIF}
Result := True;
end;
FreeWAD();
if (Data = nil) or (Len = 0) then
begin
FreeWAD();
if (Data = nil) or (Len = 0) then
begin
- e_WriteLog('TWADFile.ReadMemory: EMPTY SUBWAD!', MSG_WARNING);
+ e_WriteLog('TWADFile.ReadMemory: EMPTY SUBWAD!', TMsgType.Warning);
Exit;
end;
fn := Format(' -- memwad %d -- ', [uniqueCounter]);
Inc(uniqueCounter);
{$IFDEF SFS_DFWAD_DEBUG}
Exit;
end;
fn := Format(' -- memwad %d -- ', [uniqueCounter]);
Inc(uniqueCounter);
{$IFDEF SFS_DFWAD_DEBUG}
- if wadoptDebug then e_WriteLog(Format('TWADFile.ReadMemory: [%s]', [fn]), MSG_NOTIFY);
+ if wadoptDebug then e_WriteLog(Format('TWADFile.ReadMemory: [%s]', [fn]), TMsgType.Notify);
{$ENDIF}
try
{$ENDIF}
try
fFileName := fn;
{$IFDEF SFS_DFWAD_DEBUG}
fFileName := fn;
{$IFDEF SFS_DFWAD_DEBUG}
- if wadoptDebug then e_WriteLog(Format('TWADFile.ReadMemory: [%s] opened', [fFileName]), MSG_NOTIFY);
+ if wadoptDebug then e_WriteLog(Format('TWADFile.ReadMemory: [%s] opened', [fFileName]), TMsgType.Notify);
{$ENDIF}
{
{$ENDIF}
{