2007-12-01 01:32:56 +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;
|
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Globalization;
|
|
|
|
using System.Text;
|
|
|
|
using CodeImp.DoomBuilder.IO;
|
|
|
|
using CodeImp.DoomBuilder.Data;
|
|
|
|
using System.IO;
|
|
|
|
using System.Diagnostics;
|
|
|
|
using System.Windows.Forms;
|
2008-05-08 13:04:18 +00:00
|
|
|
using CodeImp.DoomBuilder.Map;
|
2008-05-18 15:43:49 +00:00
|
|
|
using System.Reflection;
|
|
|
|
using CodeImp.DoomBuilder.Plugins;
|
2008-05-26 20:06:15 +00:00
|
|
|
using CodeImp.DoomBuilder.Editing;
|
2007-12-01 01:32:56 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
namespace CodeImp.DoomBuilder.Config
|
|
|
|
{
|
|
|
|
public class ProgramConfiguration
|
|
|
|
{
|
|
|
|
#region ================== Constants
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Variables
|
|
|
|
|
|
|
|
// Original configuration
|
|
|
|
private Configuration cfg;
|
|
|
|
|
|
|
|
// Cached variables
|
2007-12-08 15:18:14 +00:00
|
|
|
private int undolevels;
|
2007-12-01 01:32:56 +00:00
|
|
|
private bool blackbrowsers;
|
2008-01-05 18:11:29 +00:00
|
|
|
private int visualfov;
|
|
|
|
private float visualmousesensx;
|
|
|
|
private float visualmousesensy;
|
2008-01-18 19:52:19 +00:00
|
|
|
private float visualviewrange;
|
2008-02-24 21:52:18 +00:00
|
|
|
private int imagebrightness;
|
|
|
|
private bool qualitydisplay;
|
2008-05-10 16:09:45 +00:00
|
|
|
private bool squarethings;
|
2008-09-26 05:53:34 +00:00
|
|
|
private bool testmonsters;
|
2008-05-26 20:06:15 +00:00
|
|
|
|
2008-05-08 13:04:18 +00:00
|
|
|
// These are not stored in the configuration, only used at runtime
|
|
|
|
private string defaulttexture;
|
|
|
|
private int defaultbrightness = 192;
|
|
|
|
private int defaultfloorheight = 0;
|
|
|
|
private int defaultceilheight = 128;
|
|
|
|
private string defaultfloortexture;
|
|
|
|
private string defaultceiltexture;
|
2008-06-10 11:32:06 +00:00
|
|
|
private int defaultthingtype = 1;
|
|
|
|
private float defaultthingangle = 0.0f;
|
2008-05-08 13:04:18 +00:00
|
|
|
|
2007-12-01 01:32:56 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Properties
|
|
|
|
|
2008-01-02 21:49:43 +00:00
|
|
|
internal Configuration Config { get { return cfg; } }
|
|
|
|
public int UndoLevels { get { return undolevels; } internal set { undolevels = value; } }
|
|
|
|
public bool BlackBrowsers { get { return blackbrowsers; } internal set { blackbrowsers = value; } }
|
2008-01-05 18:11:29 +00:00
|
|
|
public int VisualFOV { get { return visualfov; } internal set { visualfov = value; } }
|
2008-02-24 21:52:18 +00:00
|
|
|
public int ImageBrightness { get { return imagebrightness; } internal set { imagebrightness = value; } }
|
2008-01-05 18:11:29 +00:00
|
|
|
public float VisualMouseSensX { get { return visualmousesensx; } internal set { visualmousesensx = value; } }
|
|
|
|
public float VisualMouseSensY { get { return visualmousesensy; } internal set { visualmousesensy = value; } }
|
2008-01-18 19:52:19 +00:00
|
|
|
public float VisualViewRange { get { return visualviewrange; } internal set { visualviewrange = value; } }
|
2008-02-24 21:52:18 +00:00
|
|
|
public bool QualityDisplay { get { return qualitydisplay; } internal set { qualitydisplay = value; } }
|
2008-05-10 16:09:45 +00:00
|
|
|
public bool SquareThings { get { return squarethings; } internal set { squarethings = value; } }
|
2008-09-26 05:53:34 +00:00
|
|
|
public bool TestMonsters { get { return testmonsters; } internal set { testmonsters = value; } }
|
2007-12-01 01:32:56 +00:00
|
|
|
|
2008-05-08 13:04:18 +00:00
|
|
|
public string DefaultTexture { get { return defaulttexture; } set { defaulttexture = value; } }
|
|
|
|
public string DefaultFloorTexture { get { return defaultfloortexture; } set { defaultfloortexture = value; } }
|
|
|
|
public string DefaultCeilingTexture { get { return defaultceiltexture; } set { defaultceiltexture = value; } }
|
|
|
|
public int DefaultBrightness { get { return defaultbrightness; } set { defaultbrightness = value; } }
|
|
|
|
public int DefaultFloorHeight { get { return defaultfloorheight; } set { defaultfloorheight = value; } }
|
|
|
|
public int DefaultCeilingHeight { get { return defaultceilheight; } set { defaultceilheight = value; } }
|
2008-06-10 11:32:06 +00:00
|
|
|
public int DefaultThingType { get { return defaultthingtype; } set { defaultthingtype = value; } }
|
|
|
|
public float DefaultThingAngle { get { return defaultthingangle; } set { defaultthingangle = value; } }
|
2008-05-08 13:04:18 +00:00
|
|
|
|
2007-12-01 01:32:56 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Constructor / Disposer
|
|
|
|
|
|
|
|
// Constructor
|
2008-01-02 21:49:43 +00:00
|
|
|
internal ProgramConfiguration()
|
2007-12-01 01:32:56 +00:00
|
|
|
{
|
|
|
|
// We have no destructor
|
|
|
|
GC.SuppressFinalize(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Loading / Saving
|
|
|
|
|
|
|
|
// This loads the program configuration
|
2008-01-02 21:49:43 +00:00
|
|
|
internal bool Load(string cfgfilepathname, string defaultfilepathname)
|
2007-12-01 01:32:56 +00:00
|
|
|
{
|
|
|
|
// First parse it
|
|
|
|
if(Read(cfgfilepathname, defaultfilepathname))
|
|
|
|
{
|
|
|
|
// Read the cache variables
|
|
|
|
blackbrowsers = cfg.ReadSetting("blackbrowsers", false);
|
2007-12-08 15:18:14 +00:00
|
|
|
undolevels = cfg.ReadSetting("undolevels", 20);
|
2008-01-05 18:11:29 +00:00
|
|
|
visualfov = cfg.ReadSetting("visualfov", 80);
|
2008-01-18 19:52:19 +00:00
|
|
|
visualmousesensx = cfg.ReadSetting("visualmousesensx", 40f);
|
|
|
|
visualmousesensy = cfg.ReadSetting("visualmousesensy", 40f);
|
|
|
|
visualviewrange = cfg.ReadSetting("visualviewrange", 1000f);
|
2008-02-24 21:52:18 +00:00
|
|
|
imagebrightness = cfg.ReadSetting("imagebrightness", 3);
|
|
|
|
qualitydisplay = cfg.ReadSetting("qualitydisplay", true);
|
2008-05-10 16:14:22 +00:00
|
|
|
squarethings = cfg.ReadSetting("squarethings", false);
|
2008-09-26 05:53:34 +00:00
|
|
|
testmonsters = cfg.ReadSetting("testmonsters", true);
|
2008-01-05 18:11:29 +00:00
|
|
|
|
2007-12-01 01:32:56 +00:00
|
|
|
// Success
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Failed
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// This saves the program configuration
|
2008-01-02 21:49:43 +00:00
|
|
|
internal void Save(string filepathname)
|
2007-12-01 01:32:56 +00:00
|
|
|
{
|
|
|
|
// Write the cache variables
|
|
|
|
cfg.WriteSetting("blackbrowsers", blackbrowsers);
|
2007-12-08 15:18:14 +00:00
|
|
|
cfg.WriteSetting("undolevels", undolevels);
|
2008-01-05 18:11:29 +00:00
|
|
|
cfg.WriteSetting("visualfov", visualfov);
|
|
|
|
cfg.WriteSetting("visualmousesensx", visualmousesensx);
|
|
|
|
cfg.WriteSetting("visualmousesensy", visualmousesensy);
|
2008-01-18 19:52:19 +00:00
|
|
|
cfg.WriteSetting("visualviewrange", visualviewrange);
|
2008-02-24 21:52:18 +00:00
|
|
|
cfg.WriteSetting("imagebrightness", imagebrightness);
|
|
|
|
cfg.WriteSetting("qualitydisplay", qualitydisplay);
|
2008-05-10 16:09:45 +00:00
|
|
|
cfg.WriteSetting("squarethings", squarethings);
|
2008-09-26 05:53:34 +00:00
|
|
|
cfg.WriteSetting("testmonsters", testmonsters);
|
2007-12-01 01:32:56 +00:00
|
|
|
|
|
|
|
// Save settings configuration
|
|
|
|
General.WriteLogLine("Saving program configuration...");
|
|
|
|
cfg.SaveConfiguration(filepathname);
|
|
|
|
}
|
|
|
|
|
|
|
|
// This reads the configuration
|
|
|
|
private bool Read(string cfgfilepathname, string defaultfilepathname)
|
|
|
|
{
|
|
|
|
DialogResult result;
|
|
|
|
|
|
|
|
// Check if no config for this user exists yet
|
|
|
|
if(!File.Exists(cfgfilepathname))
|
|
|
|
{
|
|
|
|
// Copy new configuration
|
|
|
|
General.WriteLogLine("Local user program configuration is missing!");
|
|
|
|
File.Copy(defaultfilepathname, cfgfilepathname);
|
|
|
|
General.WriteLogLine("New program configuration copied for local user");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load it
|
|
|
|
cfg = new Configuration(cfgfilepathname, true);
|
|
|
|
if(cfg.ErrorResult != 0)
|
|
|
|
{
|
|
|
|
// Error in configuration
|
|
|
|
// Ask user for a new copy
|
|
|
|
result = General.ShowErrorMessage("Error in program configuration near line " + cfg.ErrorLine + ": " + cfg.ErrorDescription, MessageBoxButtons.YesNoCancel);
|
|
|
|
if(result == DialogResult.Yes)
|
|
|
|
{
|
|
|
|
// Remove old configuration and make a new copy
|
|
|
|
General.WriteLogLine("User requested a new copy of the program configuration");
|
|
|
|
File.Delete(cfgfilepathname);
|
|
|
|
File.Copy(defaultfilepathname, cfgfilepathname);
|
|
|
|
General.WriteLogLine("New program configuration copied for local user");
|
|
|
|
|
|
|
|
// Load it
|
|
|
|
cfg = new Configuration(cfgfilepathname, true);
|
|
|
|
if(cfg.ErrorResult != 0)
|
|
|
|
{
|
|
|
|
// Error in configuration
|
|
|
|
General.WriteLogLine("Error in program configuration near line " + cfg.ErrorLine + ": " + cfg.ErrorDescription);
|
|
|
|
General.ShowErrorMessage("Default program configuration is corrupted. Please re-install Doom Builder.", MessageBoxButtons.OK);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(result == DialogResult.Cancel)
|
|
|
|
{
|
|
|
|
// User requested to cancel startup
|
|
|
|
General.WriteLogLine("User cancelled startup");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Success
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Methods
|
|
|
|
|
2008-05-18 15:43:49 +00:00
|
|
|
// This makes the path prefix for the given assembly
|
|
|
|
private string GetPluginPathPrefix(Assembly asm)
|
|
|
|
{
|
|
|
|
Plugin p = General.Plugins.FindPluginByAssembly(asm);
|
|
|
|
return "plugins." + p.Name.ToLowerInvariant() + ".";
|
|
|
|
}
|
|
|
|
|
|
|
|
// ReadPluginSetting
|
|
|
|
public string ReadPluginSetting(string setting, string defaultsetting) { return cfg.ReadSetting(GetPluginPathPrefix(Assembly.GetCallingAssembly()) + setting, defaultsetting); }
|
|
|
|
public int ReadPluginSetting(string setting, int defaultsetting) { return cfg.ReadSetting(GetPluginPathPrefix(Assembly.GetCallingAssembly()) + setting, defaultsetting); }
|
|
|
|
public float ReadPluginSetting(string setting, float defaultsetting) { return cfg.ReadSetting(GetPluginPathPrefix(Assembly.GetCallingAssembly()) + setting, defaultsetting); }
|
|
|
|
public short ReadPluginSetting(string setting, short defaultsetting) { return cfg.ReadSetting(GetPluginPathPrefix(Assembly.GetCallingAssembly()) + setting, defaultsetting); }
|
|
|
|
public long ReadPluginSetting(string setting, long defaultsetting) { return cfg.ReadSetting(GetPluginPathPrefix(Assembly.GetCallingAssembly()) + setting, defaultsetting); }
|
|
|
|
public bool ReadPluginSetting(string setting, bool defaultsetting) { return cfg.ReadSetting(GetPluginPathPrefix(Assembly.GetCallingAssembly()) + setting, defaultsetting); }
|
|
|
|
public byte ReadPluginSetting(string setting, byte defaultsetting) { return cfg.ReadSetting(GetPluginPathPrefix(Assembly.GetCallingAssembly()) + setting, defaultsetting); }
|
|
|
|
public IDictionary ReadPluginSetting(string setting, IDictionary defaultsetting) { return cfg.ReadSetting(GetPluginPathPrefix(Assembly.GetCallingAssembly()) + setting, defaultsetting); }
|
|
|
|
|
|
|
|
// WritePluginSetting
|
|
|
|
public bool WritePluginSetting(string setting, object settingvalue) { return cfg.WriteSetting(GetPluginPathPrefix(Assembly.GetCallingAssembly()) + setting, settingvalue); }
|
|
|
|
|
2007-12-01 01:32:56 +00:00
|
|
|
// ReadSetting
|
2008-05-18 15:43:49 +00:00
|
|
|
internal string ReadSetting(string setting, string defaultsetting) { return cfg.ReadSetting(setting, defaultsetting); }
|
|
|
|
internal int ReadSetting(string setting, int defaultsetting) { return cfg.ReadSetting(setting, defaultsetting); }
|
|
|
|
internal float ReadSetting(string setting, float defaultsetting) { return cfg.ReadSetting(setting, defaultsetting); }
|
|
|
|
internal short ReadSetting(string setting, short defaultsetting) { return cfg.ReadSetting(setting, defaultsetting); }
|
|
|
|
internal long ReadSetting(string setting, long defaultsetting) { return cfg.ReadSetting(setting, defaultsetting); }
|
|
|
|
internal bool ReadSetting(string setting, bool defaultsetting) { return cfg.ReadSetting(setting, defaultsetting); }
|
|
|
|
internal byte ReadSetting(string setting, byte defaultsetting) { return cfg.ReadSetting(setting, defaultsetting); }
|
|
|
|
internal IDictionary ReadSetting(string setting, IDictionary defaultsetting) { return cfg.ReadSetting(setting, defaultsetting); }
|
2007-12-01 01:32:56 +00:00
|
|
|
|
|
|
|
// WriteSetting
|
2008-01-02 21:49:43 +00:00
|
|
|
internal bool WriteSetting(string setting, object settingvalue) { return cfg.WriteSetting(setting, settingvalue); }
|
|
|
|
internal bool WriteSetting(string setting, object settingvalue, string pathseperator) { return cfg.WriteSetting(setting, settingvalue, pathseperator); }
|
2008-06-10 11:32:06 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Default Settings
|
|
|
|
|
|
|
|
// This applies default settings to a thing
|
|
|
|
public void ApplyDefaultThingSettings(Thing t)
|
|
|
|
{
|
|
|
|
t.Type = defaultthingtype;
|
|
|
|
t.Rotate(defaultthingangle);
|
|
|
|
foreach(string f in General.Map.Config.DefaultThingFlags) t.Flags[f] = true;
|
|
|
|
}
|
2007-12-01 01:32:56 +00:00
|
|
|
|
2008-05-08 13:04:18 +00:00
|
|
|
// This attempts to find the default drawing settings
|
|
|
|
public void FindDefaultDrawSettings()
|
|
|
|
{
|
|
|
|
bool foundone;
|
|
|
|
|
|
|
|
// Only possible when a map is loaded
|
|
|
|
if(General.Map == null) return;
|
|
|
|
|
|
|
|
// Default texture missing?
|
|
|
|
if((defaulttexture == null) || defaulttexture.StartsWith("-"))
|
|
|
|
{
|
|
|
|
// Find default texture from map
|
|
|
|
foundone = false;
|
|
|
|
foreach(Sidedef sd in General.Map.Map.Sidedefs)
|
|
|
|
{
|
|
|
|
if(!sd.MiddleTexture.StartsWith("-"))
|
|
|
|
{
|
|
|
|
foundone = true;
|
|
|
|
defaulttexture = sd.MiddleTexture;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Not found yet?
|
|
|
|
if(!foundone)
|
|
|
|
{
|
|
|
|
// Pick the first STARTAN from the list.
|
|
|
|
// I love the STARTAN texture as default for some reason.
|
|
|
|
foreach(string s in General.Map.Data.TextureNames)
|
|
|
|
{
|
|
|
|
if(s.StartsWith("STARTAN"))
|
|
|
|
{
|
|
|
|
foundone = true;
|
|
|
|
defaulttexture = s;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise just pick the first
|
|
|
|
if(!foundone)
|
|
|
|
{
|
|
|
|
if(General.Map.Data.TextureNames.Count > 1)
|
|
|
|
defaulttexture = General.Map.Data.TextureNames[1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Default floor missing?
|
|
|
|
if((defaultfloortexture == null) || (defaultfloortexture.Length == 0))
|
|
|
|
{
|
|
|
|
// Find default texture from map
|
|
|
|
foundone = false;
|
|
|
|
if(General.Map.Map.Sectors.Count > 0)
|
|
|
|
{
|
|
|
|
foundone = true;
|
|
|
|
defaultfloortexture = General.GetByIndex<Sector>(General.Map.Map.Sectors, 0).FloorTexture;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pick the first FLOOR from the list.
|
|
|
|
foreach(string s in General.Map.Data.FlatNames)
|
|
|
|
{
|
|
|
|
if(s.StartsWith("FLOOR"))
|
|
|
|
{
|
|
|
|
foundone = true;
|
|
|
|
defaultfloortexture = s;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise just pick the first
|
|
|
|
if(!foundone)
|
|
|
|
{
|
|
|
|
if(General.Map.Data.FlatNames.Count > 0)
|
|
|
|
defaultfloortexture = General.Map.Data.FlatNames[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Default ceiling missing?
|
|
|
|
if((defaultceiltexture == null) || (defaultceiltexture.Length == 0))
|
|
|
|
{
|
|
|
|
// Find default texture from map
|
|
|
|
foundone = false;
|
|
|
|
if(General.Map.Map.Sectors.Count > 0)
|
|
|
|
{
|
|
|
|
foundone = true;
|
|
|
|
defaultceiltexture = General.GetByIndex<Sector>(General.Map.Map.Sectors, 0).CeilTexture;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pick the first FLOOR from the list.
|
|
|
|
foreach(string s in General.Map.Data.FlatNames)
|
|
|
|
{
|
|
|
|
if(s.StartsWith("FLOOR"))
|
|
|
|
{
|
|
|
|
foundone = true;
|
|
|
|
defaultceiltexture = s;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise just pick the first
|
|
|
|
if(!foundone)
|
|
|
|
{
|
|
|
|
if(General.Map.Data.FlatNames.Count > 1)
|
|
|
|
defaultceiltexture = General.Map.Data.FlatNames[1];
|
|
|
|
}
|
|
|
|
}
|
2008-06-01 20:25:46 +00:00
|
|
|
|
|
|
|
// Texture names may not be null
|
|
|
|
if((defaulttexture == null) || (defaulttexture == "")) defaulttexture = "-";
|
|
|
|
if((defaultfloortexture == null) || (defaultfloortexture == "")) defaultfloortexture = "-";
|
|
|
|
if((defaultceiltexture == null) || (defaultceiltexture == "")) defaultceiltexture = "-";
|
2008-05-08 13:04:18 +00:00
|
|
|
}
|
|
|
|
|
2007-12-01 01:32:56 +00:00
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|