198 lines
7.2 KiB
C#
198 lines
7.2 KiB
C#
// ========================================================================
|
|
// Copyright 2006 - Volian Enterprises, Inc. All rights reserved.
|
|
// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
|
|
// ------------------------------------------------------------------------
|
|
// $Workfile: $ $Revision: $
|
|
// $Author: $ $Date: $
|
|
//
|
|
// $History: $
|
|
// ========================================================================
|
|
using System;
|
|
using System.Drawing;
|
|
using System.Collections;
|
|
using System.ComponentModel;
|
|
using System.Windows.Forms;
|
|
using System.Data;
|
|
using System.Data.OleDb;
|
|
using System.Collections.Specialized;
|
|
using System.Collections.Generic;
|
|
using System.Xml;
|
|
using System.IO;
|
|
using System.Text;
|
|
using Volian.CSLA.Library;
|
|
|
|
namespace Config
|
|
{
|
|
public class ConfigFile
|
|
{
|
|
#region Log4Net
|
|
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
|
#endregion
|
|
#region MigrateStrings
|
|
// the following lists are used for storing the element and attribute names
|
|
// for migrating of ini & cfg files. The names stored in these lists are
|
|
// those that should be migrated. If not in this list, the data (either element
|
|
// or attribute name) is prefaced with a 'z'. At some point in the future, those
|
|
// names with a 'z' will be removed.
|
|
public List<string> listIni_EleName = new List<string>();
|
|
public List<string> listIni_AttrName = new List<string>();
|
|
private void SetIniEleName()
|
|
{
|
|
// veproms.ini
|
|
listIni_EleName.Add("graphics");
|
|
listIni_EleName.Add("color");
|
|
listIni_EleName.Add("print");
|
|
listIni_EleName.Add("startup");
|
|
listIni_EleName.Add("data integrity");
|
|
listIni_EleName.Add("wordprocessor");
|
|
listIni_EleName.Add("procedurelisttabstops");
|
|
|
|
// proc.ini
|
|
listIni_EleName.Add("rodefaults");
|
|
listIni_EleName.Add("display");
|
|
listIni_EleName.Add("backgrounddefaults");
|
|
|
|
// <user>.cfg
|
|
listIni_EleName.Add("spelldictionary");
|
|
// listIni_EleName.Add("wordprocessor"); - already in here.
|
|
}
|
|
|
|
private void SetIniAttrName()
|
|
{
|
|
//veproms.ini
|
|
listIni_AttrName.Add("defaultext");
|
|
listIni_AttrName.Add("ro");
|
|
listIni_AttrName.Add("editbackground");
|
|
listIni_AttrName.Add("black");
|
|
listIni_AttrName.Add("blue");
|
|
listIni_AttrName.Add("green");
|
|
listIni_AttrName.Add("cyan");
|
|
listIni_AttrName.Add("red");
|
|
listIni_AttrName.Add("magenta");
|
|
listIni_AttrName.Add("brown");
|
|
listIni_AttrName.Add("lightgray");
|
|
listIni_AttrName.Add("darkgray");
|
|
listIni_AttrName.Add("ligthblue");
|
|
listIni_AttrName.Add("lightgreen");
|
|
listIni_AttrName.Add("lightcyan");
|
|
listIni_AttrName.Add("lightred");
|
|
listIni_AttrName.Add("lightmagenta");
|
|
listIni_AttrName.Add("yellow");
|
|
listIni_AttrName.Add("white");
|
|
listIni_AttrName.Add("underlinewidth");
|
|
listIni_AttrName.Add("verticalOffset");
|
|
listIni_AttrName.Add("strokewidth");
|
|
listIni_AttrName.Add("strokewidthbold");
|
|
listIni_AttrName.Add("messageboxtitle");
|
|
listIni_AttrName.Add("messagefile");
|
|
listIni_AttrName.Add("enableindexcheck");
|
|
listIni_AttrName.Add("wordwrap");
|
|
listIni_AttrName.Add("procedurenumbertab");
|
|
listIni_AttrName.Add("proceduretitletab");
|
|
|
|
// proc.ini
|
|
listIni_AttrName.Add("setpoint");
|
|
listIni_AttrName.Add("graphics");
|
|
listIni_AttrName.Add("ropath");
|
|
listIni_AttrName.Add("display");
|
|
listIni_AttrName.Add("sectiontitle");
|
|
listIni_AttrName.Add("sectionnumber");
|
|
|
|
// <user>.cfg
|
|
listIni_AttrName.Add("custom");
|
|
listIni_AttrName.Add("page");
|
|
listIni_AttrName.Add("toolbar");
|
|
listIni_AttrName.Add("paragraph");
|
|
listIni_AttrName.Add("ruler");
|
|
listIni_AttrName.Add("userphone1");
|
|
listIni_AttrName.Add("userphone2");
|
|
listIni_AttrName.Add("userloc1");
|
|
listIni_AttrName.Add("userloc2");
|
|
}
|
|
#endregion
|
|
#region LoadDataCode
|
|
public ConfigFile()
|
|
{
|
|
}
|
|
public void LoadUsrCfg(User user)
|
|
{
|
|
string cmdline = System.Environment.CommandLine;
|
|
string cfgpath = cmdline.Substring(1, cmdline.LastIndexOf("\\") - 1) + "\\config";
|
|
if (!Directory.Exists(cfgpath))
|
|
{
|
|
log.Info("No user cfgs found in config directory - did not migrate any user cfgs");
|
|
return;
|
|
}
|
|
DirectoryInfo di = new DirectoryInfo(cfgpath);
|
|
FileInfo[] fis = di.GetFiles("*.cfg");
|
|
|
|
foreach (FileInfo fi in fis)
|
|
{
|
|
string cfgname = fi.Name.Substring(0, fi.Name.IndexOf("."));
|
|
if (cfgname.ToUpper() == user.UserID.ToUpper())
|
|
{
|
|
// Get Users table fields by reading the cfg file into a buffer & looking
|
|
// for the UserNetworkId and UserName fields.
|
|
StreamReader myReader = new StreamReader(fi.FullName);
|
|
string sLine;
|
|
string UserLogin = null;
|
|
string UserName = null;
|
|
int indx = -1;
|
|
while ((sLine = myReader.ReadLine()) != null && (UserLogin == null || UserName == null))
|
|
{
|
|
if (sLine.Length > 0 && sLine.Substring(0, 1) != ";")
|
|
{
|
|
if ((indx = sLine.ToLower().IndexOf("usernetworkid")) >= 0)
|
|
{
|
|
indx = sLine.IndexOf("=", indx + 13);
|
|
UserLogin = sLine.Substring(indx + 1, sLine.Length - indx - 1).Trim();
|
|
}
|
|
else if ((indx = sLine.ToLower().IndexOf("username")) >= 0)
|
|
{
|
|
indx = sLine.IndexOf("=", indx + 8);
|
|
UserName = sLine.Substring(indx + 1, sLine.Length - indx - 1).Trim();
|
|
}
|
|
}
|
|
}
|
|
myReader.Close();
|
|
|
|
// get the xml to set the config field
|
|
XmlDocument d = IniToXml(fi.FullName);
|
|
user.Config = d == null ? null : d.InnerXml;
|
|
user.UserLogin = UserLogin;
|
|
user.UserName = UserName;
|
|
user.CFGName = cfgname;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
public XmlDocument LoadSystemIni()
|
|
{
|
|
string cmdline = System.Environment.CommandLine;
|
|
string inipath = cmdline.Substring(1, cmdline.LastIndexOf("\\") - 1) + "\\veproms.ini";
|
|
if (!File.Exists(inipath))
|
|
{
|
|
log.InfoFormat("Did not migrate {0} - file not found", inipath);
|
|
return null;
|
|
}
|
|
XmlDocument d = IniToXml(inipath);
|
|
return d;
|
|
}
|
|
|
|
public XmlDocument IniToXml(string path)
|
|
{
|
|
FileInfo fi = new FileInfo(path);
|
|
if (fi.Exists)
|
|
{
|
|
PrivateProfile ppCfg;
|
|
if (listIni_AttrName == null || listIni_AttrName.Count == 0) SetIniAttrName();
|
|
if (listIni_EleName == null || listIni_EleName.Count == 0) SetIniEleName();
|
|
ppCfg = new PrivateProfile(path, listIni_EleName, listIni_AttrName);
|
|
return ppCfg.XML();
|
|
}
|
|
return null;
|
|
}
|
|
#endregion
|
|
}
|
|
} |