2009-04-19 18:07:22 +00:00
#region = = = = = = = = = = = = = = = = = = Copyright ( c ) 2007 Pascal vd Heiden
/ *
* Copyright ( c ) 2007 Pascal vd Heiden , www . codeimp . com
* This program is released under GNU General Public License
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* /
#endregion
#region = = = = = = = = = = = = = = = = = = Namespaces
using System ;
Added, Sector Edit window, UDMF: added UI for sector damage-realted properties.
Added, DECORATE parser: damage types are now parsed.
Added: the editor now reports duplicate textures/flats/patches/sprites/colormaps/voxels in the loaded wads.
Added, all text parsers: added #region/#endregion support.
Added TERRAIN parser.
Added, Script Editor: added special handling for DECORATE special comments.
Added, Sector Edit window, UDMF: Soundsequence value was setup incorrectly when showing the window for multiple sectors with mixed Soundsequence value.
Fixed, Map Options window: "Strictly load patches between P_START and P_END" was not applied when applying the changes.
Fixed, MAPINFO parser: MapInfo should be treated as defined when a map MAPINFO block corresponding to current map is encountered even if it doesn't define any properties recognized by the editor.
Fixed, all text parsers: in some cases error line was calculated incorrectly when reporting an error detected by a text parser.
Cosmetic: changed ' to " in the rest of Error and Warning messages.
Internal: added text resource tracking.
Updated ZDoom_DECORATE.cfg.
Updated documentation ("Game Configuration - Basic Settings" page).
2016-02-22 12:33:19 +00:00
using System.Collections.Generic ;
2009-04-19 18:07:22 +00:00
using System.IO ;
2016-04-29 13:42:52 +00:00
using CodeImp.DoomBuilder.Compilers ;
2016-05-12 13:56:25 +00:00
using CodeImp.DoomBuilder.Config ;
2009-04-19 18:07:22 +00:00
using CodeImp.DoomBuilder.IO ;
#endregion
namespace CodeImp.DoomBuilder.Data
{
internal sealed class DirectoryReader : PK3StructuredReader
{
#region = = = = = = = = = = = = = = = = = = Variables
2016-01-13 09:34:32 +00:00
private readonly DirectoryFilesList files ;
2009-04-19 18:07:22 +00:00
#endregion
#region = = = = = = = = = = = = = = = = = = Constructor / Disposer
// Constructor
2016-04-29 13:42:52 +00:00
public DirectoryReader ( DataLocation dl , bool asreadonly ) : base ( dl , asreadonly )
2009-04-19 18:07:22 +00:00
{
Added, Sector Edit window, UDMF: added UI for sector damage-realted properties.
Added, DECORATE parser: damage types are now parsed.
Added: the editor now reports duplicate textures/flats/patches/sprites/colormaps/voxels in the loaded wads.
Added, all text parsers: added #region/#endregion support.
Added TERRAIN parser.
Added, Script Editor: added special handling for DECORATE special comments.
Added, Sector Edit window, UDMF: Soundsequence value was setup incorrectly when showing the window for multiple sectors with mixed Soundsequence value.
Fixed, Map Options window: "Strictly load patches between P_START and P_END" was not applied when applying the changes.
Fixed, MAPINFO parser: MapInfo should be treated as defined when a map MAPINFO block corresponding to current map is encountered even if it doesn't define any properties recognized by the editor.
Fixed, all text parsers: in some cases error line was calculated incorrectly when reporting an error detected by a text parser.
Cosmetic: changed ' to " in the rest of Error and Warning messages.
Internal: added text resource tracking.
Updated ZDoom_DECORATE.cfg.
Updated documentation ("Game Configuration - Basic Settings" page).
2016-02-22 12:33:19 +00:00
General . WriteLogLine ( "Opening directory resource \"" + location . location + "\"" ) ;
2009-04-19 18:07:22 +00:00
// Initialize
files = new DirectoryFilesList ( dl . location , true ) ;
Initialize ( ) ;
// We have no destructor
GC . SuppressFinalize ( this ) ;
}
Added, Sector Edit window, UDMF: added UI for sector damage-realted properties.
Added, DECORATE parser: damage types are now parsed.
Added: the editor now reports duplicate textures/flats/patches/sprites/colormaps/voxels in the loaded wads.
Added, all text parsers: added #region/#endregion support.
Added TERRAIN parser.
Added, Script Editor: added special handling for DECORATE special comments.
Added, Sector Edit window, UDMF: Soundsequence value was setup incorrectly when showing the window for multiple sectors with mixed Soundsequence value.
Fixed, Map Options window: "Strictly load patches between P_START and P_END" was not applied when applying the changes.
Fixed, MAPINFO parser: MapInfo should be treated as defined when a map MAPINFO block corresponding to current map is encountered even if it doesn't define any properties recognized by the editor.
Fixed, all text parsers: in some cases error line was calculated incorrectly when reporting an error detected by a text parser.
Cosmetic: changed ' to " in the rest of Error and Warning messages.
Internal: added text resource tracking.
Updated ZDoom_DECORATE.cfg.
Updated documentation ("Game Configuration - Basic Settings" page).
2016-02-22 12:33:19 +00:00
//mxd. Don't move directory wads anywhere
protected override void Initialize ( )
{
// Load all WAD files in the root as WAD resources
2016-11-24 11:55:11 +00:00
string [ ] wadfiles = GetWadFiles ( ) ;
Added, Sector Edit window, UDMF: added UI for sector damage-realted properties.
Added, DECORATE parser: damage types are now parsed.
Added: the editor now reports duplicate textures/flats/patches/sprites/colormaps/voxels in the loaded wads.
Added, all text parsers: added #region/#endregion support.
Added TERRAIN parser.
Added, Script Editor: added special handling for DECORATE special comments.
Added, Sector Edit window, UDMF: Soundsequence value was setup incorrectly when showing the window for multiple sectors with mixed Soundsequence value.
Fixed, Map Options window: "Strictly load patches between P_START and P_END" was not applied when applying the changes.
Fixed, MAPINFO parser: MapInfo should be treated as defined when a map MAPINFO block corresponding to current map is encountered even if it doesn't define any properties recognized by the editor.
Fixed, all text parsers: in some cases error line was calculated incorrectly when reporting an error detected by a text parser.
Cosmetic: changed ' to " in the rest of Error and Warning messages.
Internal: added text resource tracking.
Updated ZDoom_DECORATE.cfg.
Updated documentation ("Game Configuration - Basic Settings" page).
2016-02-22 12:33:19 +00:00
wads = new List < WADReader > ( wadfiles . Length ) ;
foreach ( string wadfile in wadfiles )
{
2016-11-24 11:55:11 +00:00
// Don't add the map file. Otherwise DataManager will try to load it twice (and fial).
2016-06-03 20:22:07 +00:00
string wadfilepath = Path . Combine ( location . location , wadfile ) ;
if ( General . Map . FilePathName ! = wadfilepath )
{
DataLocation wdl = new DataLocation ( DataLocation . RESOURCE_WAD , wadfilepath , false , false , true ) ;
2016-11-24 11:55:11 +00:00
wads . Add ( new WADReader ( wdl , isreadonly ) { ParentResource = this } ) ;
2016-06-03 20:22:07 +00:00
}
Added, Sector Edit window, UDMF: added UI for sector damage-realted properties.
Added, DECORATE parser: damage types are now parsed.
Added: the editor now reports duplicate textures/flats/patches/sprites/colormaps/voxels in the loaded wads.
Added, all text parsers: added #region/#endregion support.
Added TERRAIN parser.
Added, Script Editor: added special handling for DECORATE special comments.
Added, Sector Edit window, UDMF: Soundsequence value was setup incorrectly when showing the window for multiple sectors with mixed Soundsequence value.
Fixed, Map Options window: "Strictly load patches between P_START and P_END" was not applied when applying the changes.
Fixed, MAPINFO parser: MapInfo should be treated as defined when a map MAPINFO block corresponding to current map is encountered even if it doesn't define any properties recognized by the editor.
Fixed, all text parsers: in some cases error line was calculated incorrectly when reporting an error detected by a text parser.
Cosmetic: changed ' to " in the rest of Error and Warning messages.
Internal: added text resource tracking.
Updated ZDoom_DECORATE.cfg.
Updated documentation ("Game Configuration - Basic Settings" page).
2016-02-22 12:33:19 +00:00
}
}
2009-04-19 18:07:22 +00:00
// Disposer
public override void Dispose ( )
{
// Not already disposed?
if ( ! isdisposed )
{
Added, Sector Edit window, UDMF: added UI for sector damage-realted properties.
Added, DECORATE parser: damage types are now parsed.
Added: the editor now reports duplicate textures/flats/patches/sprites/colormaps/voxels in the loaded wads.
Added, all text parsers: added #region/#endregion support.
Added TERRAIN parser.
Added, Script Editor: added special handling for DECORATE special comments.
Added, Sector Edit window, UDMF: Soundsequence value was setup incorrectly when showing the window for multiple sectors with mixed Soundsequence value.
Fixed, Map Options window: "Strictly load patches between P_START and P_END" was not applied when applying the changes.
Fixed, MAPINFO parser: MapInfo should be treated as defined when a map MAPINFO block corresponding to current map is encountered even if it doesn't define any properties recognized by the editor.
Fixed, all text parsers: in some cases error line was calculated incorrectly when reporting an error detected by a text parser.
Cosmetic: changed ' to " in the rest of Error and Warning messages.
Internal: added text resource tracking.
Updated ZDoom_DECORATE.cfg.
Updated documentation ("Game Configuration - Basic Settings" page).
2016-02-22 12:33:19 +00:00
General . WriteLogLine ( "Closing directory resource \"" + location . location + "\"" ) ;
2009-04-19 18:07:22 +00:00
// Done
base . Dispose ( ) ;
}
}
#endregion
#region = = = = = = = = = = = = = = = = = = Textures
// This finds and returns a patch stream
2016-03-14 21:53:53 +00:00
public override Stream GetPatchData ( string pname , bool longname , ref string patchlocation )
2009-04-19 18:07:22 +00:00
{
// Error when suspended
if ( issuspended ) throw new Exception ( "Data reader is suspended" ) ;
// Find in any of the wad files
// Note the backward order, because the last wad's images have priority
2014-11-25 11:52:01 +00:00
if ( ! longname ) //mxd. Patches with long names can't be in wads
2009-04-19 18:07:22 +00:00
{
2015-12-28 15:01:53 +00:00
for ( int i = wads . Count - 1 ; i > - 1 ; i - - )
2014-11-25 11:52:01 +00:00
{
2016-03-14 21:53:53 +00:00
Stream data = wads [ i ] . GetPatchData ( pname , false , ref patchlocation ) ;
2015-12-28 15:01:53 +00:00
if ( data ! = null ) return data ;
2014-11-25 11:52:01 +00:00
}
2009-04-19 18:07:22 +00:00
}
2014-11-25 11:52:01 +00:00
2009-04-19 18:07:22 +00:00
try
{
2014-11-25 11:52:01 +00:00
if ( longname )
{
//mxd. Long names are absolute
pname = pname . Replace ( Path . AltDirectorySeparatorChar , Path . DirectorySeparatorChar ) ;
2016-03-14 21:53:53 +00:00
if ( FileExists ( pname ) )
{
patchlocation = location . GetDisplayName ( ) ;
return LoadFile ( pname ) ;
}
return null ;
2014-11-25 11:52:01 +00:00
}
2016-03-14 21:53:53 +00:00
if ( General . Map . Config . MixTexturesFlats )
Textures Browser form: empty texture sets are no longer shown when mixed textures & flats is disabled in the current game configuration.
Textures Browser form: PK3/Directory TEXTURES images are now shown in a separate folder in the resources tree.
Fixed, Textures Browser form: fixed a logic error when trying to select initial flat when mix textures & flats was disabled in the current game configuration (this resulted in the blank textures list after opening the form).
Fixed, Textures Browser form: resources tree showed textures count even when browsing flats.
Fixed, Textures Browser form: PK3/Directory textures took precedence even when browsing flats (this means when there were a flat and a texture with the same name, a texture was displayed when browsing flats).
Fixed, Classic modes: actor's scale set in DECORATE was ignored when rendering models.
Fixed, MODELDEF parser: in some cases, several model definitions were skipped when trying to skip the current one.
Fixed, resource management: flat and sprite TEXTURES definitions were loaded only from TEXTURES files named "TEXTURES".
Fixed/added, PK3/folder resource management: patch locations for sprites defined in TEXTURES are now checked the same way as in ZDoom (previously only the "sprites" folder was checked).
Fixed/added, PK3/folder resource management: patch locations for textures defined in TEXTURES are now checked the same way as in ZDoom (previously only the "textures" folder was checked).
Fixed, PK3/folder resource management: flats defined in TEXTURES were not added to the global Flats image list.
Fixed, PK3/folder resource management: in some cases, the image search algorithm could find flats, textures, patches or sprites in incorrect folders (for example, it could find a flat in "flats_backup" folder).
2014-10-07 00:23:02 +00:00
{
2014-10-07 08:56:21 +00:00
//mxd. Find in directories ZDoom expects them to be
string dir = Path . GetDirectoryName ( pname ) ;
string name = Path . GetFileName ( pname ) ;
2015-12-28 15:01:53 +00:00
foreach ( string loc in PatchLocations )
2014-10-07 08:56:21 +00:00
{
string path = Path . Combine ( loc , dir ) ;
string filename = FindFirstFile ( path , name , true ) ;
2016-03-14 21:53:53 +00:00
if ( ! string . IsNullOrEmpty ( filename ) & & FileExists ( filename ) )
{
patchlocation = location . GetDisplayName ( ) ; //mxd
2014-10-07 08:56:21 +00:00
return LoadFile ( filename ) ;
2016-03-14 21:53:53 +00:00
}
2014-10-07 08:56:21 +00:00
}
}
else
{
// Find in patches directory
string path = Path . Combine ( PATCHES_DIR , Path . GetDirectoryName ( pname ) ) ;
2013-07-29 08:50:50 +00:00
string filename = FindFirstFile ( path , Path . GetFileName ( pname ) , true ) ;
if ( ! string . IsNullOrEmpty ( filename ) & & FileExists ( filename ) )
2016-03-14 21:53:53 +00:00
{
patchlocation = location . GetDisplayName ( ) ; //mxd
2013-07-29 08:50:50 +00:00
return LoadFile ( filename ) ;
2016-03-14 21:53:53 +00:00
}
2009-04-19 18:07:22 +00:00
}
}
catch ( Exception e )
{
Added, Sector Edit window, UDMF: added UI for sector damage-realted properties.
Added, DECORATE parser: damage types are now parsed.
Added: the editor now reports duplicate textures/flats/patches/sprites/colormaps/voxels in the loaded wads.
Added, all text parsers: added #region/#endregion support.
Added TERRAIN parser.
Added, Script Editor: added special handling for DECORATE special comments.
Added, Sector Edit window, UDMF: Soundsequence value was setup incorrectly when showing the window for multiple sectors with mixed Soundsequence value.
Fixed, Map Options window: "Strictly load patches between P_START and P_END" was not applied when applying the changes.
Fixed, MAPINFO parser: MapInfo should be treated as defined when a map MAPINFO block corresponding to current map is encountered even if it doesn't define any properties recognized by the editor.
Fixed, all text parsers: in some cases error line was calculated incorrectly when reporting an error detected by a text parser.
Cosmetic: changed ' to " in the rest of Error and Warning messages.
Internal: added text resource tracking.
Updated ZDoom_DECORATE.cfg.
Updated documentation ("Game Configuration - Basic Settings" page).
2016-02-22 12:33:19 +00:00
General . ErrorLogger . Add ( ErrorType . Error , e . GetType ( ) . Name + " while loading patch \"" + pname + "\" from directory: " + e . Message ) ;
2009-04-19 18:07:22 +00:00
}
// Nothing found
return null ;
}
// This finds and returns a textue stream
2016-03-14 21:53:53 +00:00
public override Stream GetTextureData ( string pname , bool longname , ref string texturelocation )
2009-04-19 18:07:22 +00:00
{
// Error when suspended
if ( issuspended ) throw new Exception ( "Data reader is suspended" ) ;
// Find in any of the wad files
// Note the backward order, because the last wad's images have priority
2015-12-28 15:01:53 +00:00
if ( ! longname ) //mxd. Textures with long names can't be in wads
2009-04-19 18:07:22 +00:00
{
2015-12-28 15:01:53 +00:00
for ( int i = wads . Count - 1 ; i > = 0 ; i - - )
2014-11-25 11:52:01 +00:00
{
2016-03-14 21:53:53 +00:00
Stream data = wads [ i ] . GetTextureData ( pname , false , ref texturelocation ) ;
2015-12-28 15:01:53 +00:00
if ( data ! = null ) return data ;
2014-11-25 11:52:01 +00:00
}
2009-04-19 18:07:22 +00:00
}
try
{
2014-11-25 11:52:01 +00:00
//mxd. Long names are absolute
2015-12-28 15:01:53 +00:00
if ( longname )
2014-11-25 11:52:01 +00:00
{
pname = pname . Replace ( Path . AltDirectorySeparatorChar , Path . DirectorySeparatorChar ) ;
2016-03-14 21:53:53 +00:00
if ( FileExists ( pname ) )
{
texturelocation = location . GetDisplayName ( ) ;
return LoadFile ( pname ) ;
}
return null ;
2014-11-25 11:52:01 +00:00
}
2014-12-03 09:06:05 +00:00
else
{
// Find in textures directory
string path = Path . Combine ( TEXTURES_DIR , Path . GetDirectoryName ( pname ) ) ;
string filename = FindFirstFile ( path , Path . GetFileName ( pname ) , true ) ;
2016-03-14 21:53:53 +00:00
if ( ! string . IsNullOrEmpty ( filename ) & & FileExists ( filename ) )
{
texturelocation = location . GetDisplayName ( ) ; //mxd
2014-12-03 09:06:05 +00:00
return LoadFile ( filename ) ;
2016-03-14 21:53:53 +00:00
}
2014-12-03 09:06:05 +00:00
}
2009-04-19 18:07:22 +00:00
}
catch ( Exception e )
{
Added, Sector Edit window, UDMF: added UI for sector damage-realted properties.
Added, DECORATE parser: damage types are now parsed.
Added: the editor now reports duplicate textures/flats/patches/sprites/colormaps/voxels in the loaded wads.
Added, all text parsers: added #region/#endregion support.
Added TERRAIN parser.
Added, Script Editor: added special handling for DECORATE special comments.
Added, Sector Edit window, UDMF: Soundsequence value was setup incorrectly when showing the window for multiple sectors with mixed Soundsequence value.
Fixed, Map Options window: "Strictly load patches between P_START and P_END" was not applied when applying the changes.
Fixed, MAPINFO parser: MapInfo should be treated as defined when a map MAPINFO block corresponding to current map is encountered even if it doesn't define any properties recognized by the editor.
Fixed, all text parsers: in some cases error line was calculated incorrectly when reporting an error detected by a text parser.
Cosmetic: changed ' to " in the rest of Error and Warning messages.
Internal: added text resource tracking.
Updated ZDoom_DECORATE.cfg.
Updated documentation ("Game Configuration - Basic Settings" page).
2016-02-22 12:33:19 +00:00
General . ErrorLogger . Add ( ErrorType . Error , e . GetType ( ) . Name + " while loading texture \"" + pname + "\" from directory: " + e . Message ) ;
2009-04-19 18:07:22 +00:00
}
// Nothing found
return null ;
}
2016-03-04 08:10:56 +00:00
//mxd. This finds and returns a HiRes textue stream
2016-03-14 21:53:53 +00:00
public override Stream GetHiResTextureData ( string name , ref string hireslocation )
2016-03-04 08:10:56 +00:00
{
// Error when suspended
if ( issuspended ) throw new Exception ( "Data reader is suspended" ) ;
// Find in any of the wad files
// Note the backward order, because the last wad's images have priority
for ( int i = wads . Count - 1 ; i > = 0 ; i - - )
{
2016-03-14 21:53:53 +00:00
Stream data = wads [ i ] . GetHiResTextureData ( name , ref hireslocation ) ;
2016-03-04 08:10:56 +00:00
if ( data ! = null ) return data ;
}
try
{
// Find in hires directory
2016-03-22 22:24:33 +00:00
string filename = FindFirstFile ( HIRES_DIR , name , true ) ;
2016-03-04 08:10:56 +00:00
if ( ! string . IsNullOrEmpty ( filename ) & & FileExists ( filename ) )
2016-03-14 21:53:53 +00:00
{
hireslocation = location . GetDisplayName ( ) ;
2016-03-04 08:10:56 +00:00
return LoadFile ( filename ) ;
2016-03-14 21:53:53 +00:00
}
2016-03-04 08:10:56 +00:00
}
catch ( Exception e )
{
General . ErrorLogger . Add ( ErrorType . Error , e . GetType ( ) . Name + " while loading HiRes texture \"" + name + "\" from directory: " + e . Message ) ;
}
// Nothing found
return null ;
}
2009-05-12 09:50:08 +00:00
// This finds and returns a colormap stream
public override Stream GetColormapData ( string pname )
{
// Error when suspended
if ( issuspended ) throw new Exception ( "Data reader is suspended" ) ;
// Find in any of the wad files
// Note the backward order, because the last wad's images have priority
for ( int i = wads . Count - 1 ; i > = 0 ; i - - )
{
Stream data = wads [ i ] . GetColormapData ( pname ) ;
if ( data ! = null ) return data ;
}
try
{
// Find in patches directory
string path = Path . Combine ( COLORMAPS_DIR , Path . GetDirectoryName ( pname ) ) ;
string filename = FindFirstFile ( path , Path . GetFileName ( pname ) , true ) ;
if ( ( filename ! = null ) & & FileExists ( filename ) )
{
return LoadFile ( filename ) ;
}
}
catch ( Exception e )
{
Added, Sector Edit window, UDMF: added UI for sector damage-realted properties.
Added, DECORATE parser: damage types are now parsed.
Added: the editor now reports duplicate textures/flats/patches/sprites/colormaps/voxels in the loaded wads.
Added, all text parsers: added #region/#endregion support.
Added TERRAIN parser.
Added, Script Editor: added special handling for DECORATE special comments.
Added, Sector Edit window, UDMF: Soundsequence value was setup incorrectly when showing the window for multiple sectors with mixed Soundsequence value.
Fixed, Map Options window: "Strictly load patches between P_START and P_END" was not applied when applying the changes.
Fixed, MAPINFO parser: MapInfo should be treated as defined when a map MAPINFO block corresponding to current map is encountered even if it doesn't define any properties recognized by the editor.
Fixed, all text parsers: in some cases error line was calculated incorrectly when reporting an error detected by a text parser.
Cosmetic: changed ' to " in the rest of Error and Warning messages.
Internal: added text resource tracking.
Updated ZDoom_DECORATE.cfg.
Updated documentation ("Game Configuration - Basic Settings" page).
2016-02-22 12:33:19 +00:00
General . ErrorLogger . Add ( ErrorType . Error , e . GetType ( ) . Name + " while loading colormap \"" + pname + "\" from directory: " + e . Message ) ;
2009-05-12 09:50:08 +00:00
}
// Nothing found
return null ;
}
2009-04-19 18:07:22 +00:00
#endregion
#region = = = = = = = = = = = = = = = = = = Sprites
// This finds and returns a sprite stream
2016-03-14 21:53:53 +00:00
public override Stream GetSpriteData ( string pname , ref string spritelocation )
2009-04-19 18:07:22 +00:00
{
// Error when suspended
if ( issuspended ) throw new Exception ( "Data reader is suspended" ) ;
// Find in any of the wad files
for ( int i = wads . Count - 1 ; i > = 0 ; i - - )
{
2016-03-14 21:53:53 +00:00
Stream sprite = wads [ i ] . GetSpriteData ( pname , ref spritelocation ) ;
2009-04-19 18:07:22 +00:00
if ( sprite ! = null ) return sprite ;
}
try
{
// Find in sprites directory
string path = Path . Combine ( SPRITES_DIR , Path . GetDirectoryName ( pname ) ) ;
string filename = FindFirstFile ( path , Path . GetFileName ( pname ) , true ) ;
if ( ( filename ! = null ) & & FileExists ( filename ) )
{
2016-03-14 21:53:53 +00:00
spritelocation = location . GetDisplayName ( ) ; //mxd
2009-04-19 18:07:22 +00:00
return LoadFile ( filename ) ;
}
}
catch ( Exception e )
{
Added, Sector Edit window, UDMF: added UI for sector damage-realted properties.
Added, DECORATE parser: damage types are now parsed.
Added: the editor now reports duplicate textures/flats/patches/sprites/colormaps/voxels in the loaded wads.
Added, all text parsers: added #region/#endregion support.
Added TERRAIN parser.
Added, Script Editor: added special handling for DECORATE special comments.
Added, Sector Edit window, UDMF: Soundsequence value was setup incorrectly when showing the window for multiple sectors with mixed Soundsequence value.
Fixed, Map Options window: "Strictly load patches between P_START and P_END" was not applied when applying the changes.
Fixed, MAPINFO parser: MapInfo should be treated as defined when a map MAPINFO block corresponding to current map is encountered even if it doesn't define any properties recognized by the editor.
Fixed, all text parsers: in some cases error line was calculated incorrectly when reporting an error detected by a text parser.
Cosmetic: changed ' to " in the rest of Error and Warning messages.
Internal: added text resource tracking.
Updated ZDoom_DECORATE.cfg.
Updated documentation ("Game Configuration - Basic Settings" page).
2016-02-22 12:33:19 +00:00
General . ErrorLogger . Add ( ErrorType . Error , e . GetType ( ) . Name + " while loading sprite \"" + pname + "\" from directory: " + e . Message ) ;
2009-04-19 18:07:22 +00:00
}
// Nothing found
return null ;
}
// This checks if the given sprite exists
public override bool GetSpriteExists ( string pname )
{
// Error when suspended
if ( issuspended ) throw new Exception ( "Data reader is suspended" ) ;
// Find in any of the wad files
for ( int i = wads . Count - 1 ; i > = 0 ; i - - )
{
if ( wads [ i ] . GetSpriteExists ( pname ) ) return true ;
}
// Find in sprites directory
try
{
string path = Path . Combine ( SPRITES_DIR , Path . GetDirectoryName ( pname ) ) ;
string filename = FindFirstFile ( path , Path . GetFileName ( pname ) , true ) ;
if ( ( filename ! = null ) & & FileExists ( filename ) )
{
return true ;
}
}
catch ( Exception e )
{
Added, Sector Edit window, UDMF: added UI for sector damage-realted properties.
Added, DECORATE parser: damage types are now parsed.
Added: the editor now reports duplicate textures/flats/patches/sprites/colormaps/voxels in the loaded wads.
Added, all text parsers: added #region/#endregion support.
Added TERRAIN parser.
Added, Script Editor: added special handling for DECORATE special comments.
Added, Sector Edit window, UDMF: Soundsequence value was setup incorrectly when showing the window for multiple sectors with mixed Soundsequence value.
Fixed, Map Options window: "Strictly load patches between P_START and P_END" was not applied when applying the changes.
Fixed, MAPINFO parser: MapInfo should be treated as defined when a map MAPINFO block corresponding to current map is encountered even if it doesn't define any properties recognized by the editor.
Fixed, all text parsers: in some cases error line was calculated incorrectly when reporting an error detected by a text parser.
Cosmetic: changed ' to " in the rest of Error and Warning messages.
Internal: added text resource tracking.
Updated ZDoom_DECORATE.cfg.
Updated documentation ("Game Configuration - Basic Settings" page).
2016-02-22 12:33:19 +00:00
General . ErrorLogger . Add ( ErrorType . Error , e . GetType ( ) . Name + " while checking sprite \"" + pname + "\" existance in directory: " + e . Message ) ;
2009-04-19 18:07:22 +00:00
}
// Nothing found
return false ;
}
#endregion
2014-01-03 10:33:45 +00:00
#region = = = = = = = = = = = = = = = = = = Voxels ( mxd )
//mxd. This finds and returns a voxel stream
2016-07-11 22:13:43 +00:00
public override Stream GetVoxelData ( string name , ref string voxellocation )
2014-12-03 09:06:05 +00:00
{
2014-01-03 10:33:45 +00:00
// Error when suspended
if ( issuspended ) throw new Exception ( "Data reader is suspended" ) ;
2014-01-08 09:46:57 +00:00
// Find in any of the wad files
2014-12-03 09:06:05 +00:00
for ( int i = wads . Count - 1 ; i > = 0 ; i - - )
{
2016-07-11 22:13:43 +00:00
Stream voxel = wads [ i ] . GetVoxelData ( name , ref voxellocation ) ;
2014-01-08 09:46:57 +00:00
if ( voxel ! = null ) return voxel ;
}
2014-12-03 09:06:05 +00:00
try
{
2014-01-03 10:33:45 +00:00
// Find in voxels directory
string path = Path . Combine ( VOXELS_DIR , Path . GetDirectoryName ( name ) ) ;
string filename = FindFirstFile ( path , Path . GetFileName ( name ) , true ) ;
2014-12-03 09:06:05 +00:00
if ( ( filename ! = null ) & & FileExists ( filename ) )
{
2016-07-11 22:13:43 +00:00
voxellocation = location . GetDisplayName ( ) ;
2014-01-03 10:33:45 +00:00
return LoadFile ( filename ) ;
}
2014-12-03 09:06:05 +00:00
}
catch ( Exception e )
{
Added, Sector Edit window, UDMF: added UI for sector damage-realted properties.
Added, DECORATE parser: damage types are now parsed.
Added: the editor now reports duplicate textures/flats/patches/sprites/colormaps/voxels in the loaded wads.
Added, all text parsers: added #region/#endregion support.
Added TERRAIN parser.
Added, Script Editor: added special handling for DECORATE special comments.
Added, Sector Edit window, UDMF: Soundsequence value was setup incorrectly when showing the window for multiple sectors with mixed Soundsequence value.
Fixed, Map Options window: "Strictly load patches between P_START and P_END" was not applied when applying the changes.
Fixed, MAPINFO parser: MapInfo should be treated as defined when a map MAPINFO block corresponding to current map is encountered even if it doesn't define any properties recognized by the editor.
Fixed, all text parsers: in some cases error line was calculated incorrectly when reporting an error detected by a text parser.
Cosmetic: changed ' to " in the rest of Error and Warning messages.
Internal: added text resource tracking.
Updated ZDoom_DECORATE.cfg.
Updated documentation ("Game Configuration - Basic Settings" page).
2016-02-22 12:33:19 +00:00
General . ErrorLogger . Add ( ErrorType . Error , e . GetType ( ) . Name + " while loading voxel \"" + name + "\" from directory: " + e . Message ) ;
2014-01-03 10:33:45 +00:00
}
// Nothing found
return null ;
}
#endregion
2009-04-19 18:07:22 +00:00
#region = = = = = = = = = = = = = = = = = = Methods
// Return a short name for this data location
public override string GetTitle ( )
{
return Path . GetFileName ( location . location ) ;
}
// This creates an image
2014-11-25 11:52:01 +00:00
protected override ImageData CreateImage ( string filename , int imagetype )
2009-04-19 18:07:22 +00:00
{
2009-05-12 09:50:08 +00:00
switch ( imagetype )
{
case ImageDataFormat . DOOMFLAT :
2014-11-25 11:52:01 +00:00
return new FileImage ( filename , Path . Combine ( location . location , filename ) , true ) ;
2009-05-12 09:50:08 +00:00
case ImageDataFormat . DOOMPICTURE :
2014-11-25 11:52:01 +00:00
return new FileImage ( filename , Path . Combine ( location . location , filename ) , false ) ;
2009-05-12 09:50:08 +00:00
case ImageDataFormat . DOOMCOLORMAP :
2014-11-25 11:52:01 +00:00
return new ColormapImage ( Path . GetFileNameWithoutExtension ( filename ) ) ;
2009-05-12 09:50:08 +00:00
default :
throw new ArgumentException ( "Invalid image format specified!" ) ;
}
2009-04-19 18:07:22 +00:00
}
// This returns true if the specified file exists
2016-04-29 13:42:52 +00:00
internal override bool FileExists ( string filename , int unused ) { return files . FileExists ( filename ) ; } //mxd
2012-07-23 21:28:23 +00:00
internal override bool FileExists ( string filename )
2009-04-19 18:07:22 +00:00
{
return files . FileExists ( filename ) ;
}
// This returns all files in a given directory
protected override string [ ] GetAllFiles ( string path , bool subfolders )
{
return files . GetAllFiles ( path , subfolders ) . ToArray ( ) ;
}
2016-04-23 23:15:43 +00:00
//mxd. This returns wad files in the root directory
protected override string [ ] GetWadFiles ( )
{
return files . GetWadFiles ( ) . ToArray ( ) ;
}
2010-08-13 15:19:51 +00:00
// This returns all files in a given directory that have the given file title
protected override string [ ] GetAllFilesWithTitle ( string path , string title , bool subfolders )
{
return files . GetAllFilesWithTitle ( path , title , subfolders ) . ToArray ( ) ;
}
2012-08-05 19:18:05 +00:00
2013-09-11 09:47:53 +00:00
//mxd. This returns all files in a given directory which title starts with given title
Added, Sector Edit window, UDMF: added UI for sector damage-realted properties.
Added, DECORATE parser: damage types are now parsed.
Added: the editor now reports duplicate textures/flats/patches/sprites/colormaps/voxels in the loaded wads.
Added, all text parsers: added #region/#endregion support.
Added TERRAIN parser.
Added, Script Editor: added special handling for DECORATE special comments.
Added, Sector Edit window, UDMF: Soundsequence value was setup incorrectly when showing the window for multiple sectors with mixed Soundsequence value.
Fixed, Map Options window: "Strictly load patches between P_START and P_END" was not applied when applying the changes.
Fixed, MAPINFO parser: MapInfo should be treated as defined when a map MAPINFO block corresponding to current map is encountered even if it doesn't define any properties recognized by the editor.
Fixed, all text parsers: in some cases error line was calculated incorrectly when reporting an error detected by a text parser.
Cosmetic: changed ' to " in the rest of Error and Warning messages.
Internal: added text resource tracking.
Updated ZDoom_DECORATE.cfg.
Updated documentation ("Game Configuration - Basic Settings" page).
2016-02-22 12:33:19 +00:00
protected override string [ ] GetAllFilesWhichTitleStartsWith ( string path , string title , bool subfolders )
2014-11-25 11:52:01 +00:00
{
Added, Sector Edit window, UDMF: added UI for sector damage-realted properties.
Added, DECORATE parser: damage types are now parsed.
Added: the editor now reports duplicate textures/flats/patches/sprites/colormaps/voxels in the loaded wads.
Added, all text parsers: added #region/#endregion support.
Added TERRAIN parser.
Added, Script Editor: added special handling for DECORATE special comments.
Added, Sector Edit window, UDMF: Soundsequence value was setup incorrectly when showing the window for multiple sectors with mixed Soundsequence value.
Fixed, Map Options window: "Strictly load patches between P_START and P_END" was not applied when applying the changes.
Fixed, MAPINFO parser: MapInfo should be treated as defined when a map MAPINFO block corresponding to current map is encountered even if it doesn't define any properties recognized by the editor.
Fixed, all text parsers: in some cases error line was calculated incorrectly when reporting an error detected by a text parser.
Cosmetic: changed ' to " in the rest of Error and Warning messages.
Internal: added text resource tracking.
Updated ZDoom_DECORATE.cfg.
Updated documentation ("Game Configuration - Basic Settings" page).
2016-02-22 12:33:19 +00:00
return files . GetAllFilesWhichTitleStartsWith ( path , title , subfolders ) . ToArray ( ) ;
2013-09-11 09:47:53 +00:00
}
2010-08-13 15:19:51 +00:00
2009-04-19 18:07:22 +00:00
// This returns all files in a given directory that match the given extension
2016-11-24 21:09:24 +00:00
internal override string [ ] GetFilesWithExt ( string path , string extension , bool subfolders )
2009-04-19 18:07:22 +00:00
{
return files . GetAllFiles ( path , extension , subfolders ) . ToArray ( ) ;
}
// This finds the first file that has the specific name, regardless of file extension
2016-01-13 09:34:32 +00:00
internal override string FindFirstFile ( string beginswith , bool subfolders )
2009-04-19 18:07:22 +00:00
{
return files . GetFirstFile ( beginswith , subfolders ) ;
}
// This finds the first file that has the specific name, regardless of file extension
protected override string FindFirstFile ( string path , string beginswith , bool subfolders )
{
return files . GetFirstFile ( path , beginswith , subfolders ) ;
}
// This finds the first file that has the specific name
protected override string FindFirstFileWithExt ( string path , string beginswith , bool subfolders )
{
string title = Path . GetFileNameWithoutExtension ( beginswith ) ;
string ext = Path . GetExtension ( beginswith ) ;
2015-08-28 19:22:28 +00:00
ext = ( ! string . IsNullOrEmpty ( ext ) & & ext . Length > 1 ? ext . Substring ( 1 ) : string . Empty ) ;
2009-04-19 18:07:22 +00:00
return files . GetFirstFile ( path , title , subfolders , ext ) ;
}
// This loads an entire file in memory and returns the stream
// NOTE: Callers are responsible for disposing the stream!
2013-09-11 09:47:53 +00:00
internal override MemoryStream LoadFile ( string filename )
2009-04-19 18:07:22 +00:00
{
2013-03-18 13:52:27 +00:00
MemoryStream s = null ;
2020-07-29 07:57:42 +00:00
string casecorrectfilename = GetCorrectCaseForFile ( filename ) ;
2020-07-29 20:05:12 +00:00
2020-09-13 08:45:30 +00:00
if ( casecorrectfilename = = null )
{
General . ErrorLogger . Add ( ErrorType . Error , "Unable to load file " + filename + ": file doesn't exist" ) ;
return null ;
}
2020-07-29 07:57:42 +00:00
try
2014-11-25 11:52:01 +00:00
{
2015-08-28 19:22:28 +00:00
lock ( this )
{
2020-07-29 07:57:42 +00:00
s = new MemoryStream ( File . ReadAllBytes ( Path . Combine ( location . location , casecorrectfilename ) ) ) ;
2015-08-28 19:22:28 +00:00
}
2014-11-25 11:52:01 +00:00
}
catch ( Exception e )
{
Added, Sector Edit window, UDMF: added UI for sector damage-realted properties.
Added, DECORATE parser: damage types are now parsed.
Added: the editor now reports duplicate textures/flats/patches/sprites/colormaps/voxels in the loaded wads.
Added, all text parsers: added #region/#endregion support.
Added TERRAIN parser.
Added, Script Editor: added special handling for DECORATE special comments.
Added, Sector Edit window, UDMF: Soundsequence value was setup incorrectly when showing the window for multiple sectors with mixed Soundsequence value.
Fixed, Map Options window: "Strictly load patches between P_START and P_END" was not applied when applying the changes.
Fixed, MAPINFO parser: MapInfo should be treated as defined when a map MAPINFO block corresponding to current map is encountered even if it doesn't define any properties recognized by the editor.
Fixed, all text parsers: in some cases error line was calculated incorrectly when reporting an error detected by a text parser.
Cosmetic: changed ' to " in the rest of Error and Warning messages.
Internal: added text resource tracking.
Updated ZDoom_DECORATE.cfg.
Updated documentation ("Game Configuration - Basic Settings" page).
2016-02-22 12:33:19 +00:00
General . ErrorLogger . Add ( ErrorType . Error , "Unable to load file: " + e . Message ) ;
2013-03-18 13:52:27 +00:00
}
return s ;
2009-04-19 18:07:22 +00:00
}
2016-04-29 13:42:52 +00:00
//mxd
internal override bool SaveFile ( MemoryStream stream , string filename , int unused ) { return SaveFile ( stream , filename ) ; }
internal override bool SaveFile ( MemoryStream stream , string filename )
{
if ( isreadonly ) return false ;
try
{
lock ( this )
{
File . WriteAllBytes ( Path . Combine ( location . location , filename ) , stream . ToArray ( ) ) ;
}
}
catch ( Exception e )
{
General . ErrorLogger . Add ( ErrorType . Error , "Unable to save file: " + e . Message ) ;
return false ;
}
return true ;
}
2009-04-19 18:07:22 +00:00
// This creates a temp file for the speciied file and return the absolute path to the temp file
// NOTE: Callers are responsible for removing the temp file when done!
protected override string CreateTempFile ( string filename )
{
// Just copy the file
string tempfile = General . MakeTempFilename ( General . Map . TempPath , "wad" ) ;
File . Copy ( Path . Combine ( location . location , filename ) , tempfile ) ;
return tempfile ;
}
2020-07-29 20:05:12 +00:00
/// <summary>
/// Returns the correctly cased file from a path/file. This is required for case sensitive file systems.
/// </summary>
/// <param name="filepathname">File name get the the correctly cased name from</param>
/// <returns></returns>
2020-07-29 07:57:42 +00:00
protected override string GetCorrectCaseForFile ( string filepathname )
{
2020-09-13 08:45:30 +00:00
try
{
return files . GetFileInfo ( filepathname ) . filepathname ;
}
2021-09-06 21:43:30 +00:00
catch ( KeyNotFoundException )
2020-09-13 08:45:30 +00:00
{
return null ;
}
2020-07-29 07:57:42 +00:00
}
2009-04-19 18:07:22 +00:00
#endregion
2016-04-29 13:42:52 +00:00
#region = = = = = = = = = = = = = = = = = = Compiling ( mxd )
// This compiles a script lump and returns any errors that may have occurred
// Returns true when our code worked properly (even when the compiler returned errors)
2016-05-12 13:56:25 +00:00
internal override bool CompileLump ( string filepathname , int unused , ScriptConfiguration scriptconfig , List < CompilerError > errors ) { return CompileLump ( filepathname , scriptconfig , errors ) ; }
internal override bool CompileLump ( string filepathname , ScriptConfiguration scriptconfig , List < CompilerError > errors )
2016-04-29 13:42:52 +00:00
{
2016-05-12 13:56:25 +00:00
return CompileScriptLump ( filepathname , scriptconfig , errors ) ;
}
internal static bool CompileScriptLump ( string filepathname , ScriptConfiguration scriptconfig , List < CompilerError > errors )
{
// No compiling required
if ( scriptconfig . Compiler = = null ) return true ;
// Initialize compiler
Compiler compiler ;
try
{
compiler = scriptconfig . Compiler . Create ( ) ;
}
catch ( Exception e )
{
// Fail
errors . Add ( new CompilerError ( "Unable to initialize compiler. " + e . GetType ( ) . Name + ": " + e . Message ) ) ;
return false ;
}
// Copy the source file into the temporary directory
string inputfile = Path . Combine ( compiler . Location , Path . GetFileName ( filepathname ) ) ;
File . Copy ( filepathname , inputfile ) ;
// Make random output filename
string outputfile = General . MakeTempFilename ( compiler . Location , "tmp" ) ;
// Run compiler
compiler . Parameters = scriptconfig . Parameters ;
compiler . InputFile = inputfile ;
compiler . OutputFile = Path . GetFileName ( outputfile ) ;
compiler . SourceFile = filepathname ;
compiler . WorkingDirectory = Path . GetDirectoryName ( inputfile ) ;
if ( compiler . Run ( ) )
{
// Fetch errors
foreach ( CompilerError e in compiler . Errors )
{
CompilerError newerr = e ;
// If the error's filename equals our temporary file, replace it with the original source filename
if ( String . Compare ( e . filename , inputfile , true ) = = 0 ) newerr . filename = filepathname ;
errors . Add ( newerr ) ;
}
// No errors and output file exists?
if ( compiler . Errors . Length = = 0 )
{
// Output file exists?
if ( ! File . Exists ( outputfile ) )
{
// Fail
compiler . Dispose ( ) ;
errors . Add ( new CompilerError ( "Output file \"" + outputfile + "\" doesn't exist." ) ) ;
return false ;
}
//mxd. Move and rename the result file
string targetfilename ;
if ( compiler is AccCompiler )
{
AccCompiler acccompiler = ( AccCompiler ) compiler ;
targetfilename = Path . Combine ( Path . GetDirectoryName ( filepathname ) , acccompiler . Parser . LibraryName + ".o" ) ;
}
else
{
//mxd. No can't do...
if ( String . IsNullOrEmpty ( scriptconfig . ResultLump ) )
{
// Fail
compiler . Dispose ( ) ;
errors . Add ( new CompilerError ( "Unable to create target file: unable to determine target filename. Make sure \"ResultLump\" property is set in the \"" + scriptconfig + "\" script configuration." ) ) ;
return false ;
}
targetfilename = Path . Combine ( Path . GetDirectoryName ( filepathname ) , scriptconfig . ResultLump ) ;
}
// Rename and copy to source file directory
try
{
File . Copy ( outputfile , targetfilename , true ) ;
}
catch ( Exception e )
{
// Fail
compiler . Dispose ( ) ;
errors . Add ( new CompilerError ( "Unable to create library file \"" + targetfilename + "\". " + e . GetType ( ) . Name + ": " + e . Message ) ) ;
return false ;
}
}
// Done
compiler . Dispose ( ) ;
return true ;
}
// Fail
compiler . Dispose ( ) ;
return false ;
2016-04-29 13:42:52 +00:00
}
#endregion
2009-04-19 18:07:22 +00:00
}
}