using System; using System.ComponentModel; using System.IO; namespace VEPROMS.CSLA.Library { [Serializable] [TypeConverter(typeof(ExpandableObjectConverter))] public class RODbConfig : ConfigDynamicTypeDescriptor, INotifyPropertyChanged { #region DynamicTypeDescriptor internal override bool IsReadOnly => _RODb == null; #endregion #region XML private readonly XMLProperties _Xp; #endregion #region Constructors private readonly RODb _RODb; public RODbConfig(RODb roDb) { _RODb = roDb; string xml = roDb.Config; if (xml == string.Empty) xml = ""; _Xp = new XMLProperties(xml); } private readonly RODbInfo _RODbInfo; public RODbConfig(RODbInfo roDbInfo) { _RODbInfo = roDbInfo; string xml = roDbInfo.Config; if (xml == string.Empty) xml = ""; _Xp = new XMLProperties(xml); } public RODbConfig(string xml) { if (xml == string.Empty) xml = ""; _Xp = new XMLProperties(xml); } public RODbConfig() { string xml = ""; _Xp = new XMLProperties(xml); } internal string GetValue(string group, string item) => _Xp[group, item]; #endregion #region Local Properties [Category("General")] [DisplayName("ROName")] [Description("ROName")] public string ROName { get { return (_RODb != null ? _RODb.ROName : _RODbInfo.ROName); } set { if (_RODb != null) _RODb.ROName = value; } } [Category("General")] [DisplayName("FolderPath")] [Description("FolderPath")] public string FolderPath { get { return (_RODb != null ? _RODb.FolderPath : _RODbInfo?.FolderPath); } set { if (_RODb != null) _RODb.FolderPath = value; } } public RODb MyRODb => _RODb; #endregion #region ToString public override string ToString() { string s = _Xp.ToString(); return s == "" || s == "" ? string.Empty : s; } #endregion #region RODefaults [Category("Referenced Objects")] [DisplayName("Graphic File Extension")] [RefreshProperties(RefreshProperties.All)] [Description("Default File Extension")] public string Graphics_defaultext { get { // For this data: // look in roapp.ini in the FolderPath directory; // look in top folder's config // set to Volian default, i.e. "TIF". string s = GetRoAppIniValue("Extention"); if (s == null || s == string.Empty) s = TopFolderConfigValue(); if (s == null || s == string.Empty) return s = "TIF"; return s; } } private string GetRoAppIniValue(string p_2) { if (FolderPath == null) return null; string inipath = FolderPath + @"\roapp.ini"; if (!File.Exists(inipath)) return null; using (StreamReader myReader = new StreamReader(inipath)) { string sLine; int indx = -1; while ((sLine = myReader.ReadLine()) != null) { if (sLine.Length > 0 && sLine.Substring(0, 1) != ";") { if ((indx = sLine.ToLower().IndexOf(p_2.ToLower())) >= 0) { indx = sLine.IndexOf("=", indx + 9); return sLine.Substring(indx + 1, sLine.Length - indx - 1).Trim(); } } } myReader.Close(); } return null; } private string TopFolderConfigValue() { FolderInfo fi = FolderInfo.GetTop(); return fi.FolderConfig.Graphics_defaultext; } public string GetDefaultGraphicExtension() { if (_RODb != null) return Graphics_defaultext; if (_RODbInfo != null) return Graphics_defaultext; else return "TIF"; // this is the Volian Default } public string GetDefaultGraphicExtensionLocation() { string s = GetRoAppIniValue("Extention"); if (s != null && s != string.Empty) return "Default Extension found in roapp.ini"; s = TopFolderConfigValue(); if (s != null && s != string.Empty) return "Default Extension defined in veproms properties"; return "Used program default"; } #endregion } }