You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
218 lines
7.8 KiB
C#
218 lines
7.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Configuration;
|
|
using System.Xml;
|
|
using System.IO;
|
|
using ICSharpCode.Core;
|
|
using System.Windows.Forms;
|
|
|
|
namespace Mesnac.Gui.Common
|
|
{
|
|
public class PublicConfig
|
|
{
|
|
private static PublicConfig _instance = null;
|
|
|
|
private string _componentsPropertyFile = String.Empty; //控件属性文件
|
|
private string _componentsActionFile = String.Empty; //控件动画文件
|
|
private string _componentsEventFile = String.Empty; //控件事件文件
|
|
private XmlDocument _propertyXmlDoc = new XmlDocument(); //属性解析对象
|
|
private XmlDocument _actionXmlDoc = new XmlDocument(); //动画解析对象
|
|
private XmlDocument _eventXmlDoc = new XmlDocument(); //事件解析对象
|
|
|
|
private PublicConfig()
|
|
{
|
|
Load();
|
|
}
|
|
private void Load()
|
|
{
|
|
this._componentsPropertyFile = ConfigurationManager.AppSettings["componentsPropertyFile"];
|
|
this._componentsActionFile = ConfigurationManager.AppSettings["componentsActionFile"];
|
|
this._componentsEventFile = ConfigurationManager.AppSettings["componentsEventFile"];
|
|
|
|
|
|
string componentsPropertyFile = Application.StartupPath + this._componentsPropertyFile; //工具箱控件属性配置文件
|
|
string componentsActionFile = Application.StartupPath + this._componentsActionFile; //工具箱控件动画配置文件
|
|
string componentsEventFile = Application.StartupPath + this._componentsEventFile; //工具箱控件事件配置文件
|
|
|
|
try
|
|
{
|
|
string culture = System.Threading.Thread.CurrentThread.CurrentUICulture.Name;
|
|
|
|
string culturePropertyFile = Path.Combine(Path.GetDirectoryName(componentsPropertyFile), Path.GetFileNameWithoutExtension(componentsPropertyFile));
|
|
culturePropertyFile += "." + culture + Path.GetExtension(componentsPropertyFile);
|
|
|
|
string cultureActionFile = Path.Combine(Path.GetDirectoryName(componentsActionFile), Path.GetFileNameWithoutExtension(componentsActionFile));
|
|
cultureActionFile += "." + culture + Path.GetExtension(componentsActionFile);
|
|
|
|
string cultureEventFile = Path.Combine(Path.GetDirectoryName(componentsEventFile), Path.GetFileNameWithoutExtension(componentsEventFile));
|
|
cultureEventFile += "." + culture + Path.GetExtension(componentsEventFile);
|
|
|
|
if (!File.Exists(culturePropertyFile))
|
|
{
|
|
culturePropertyFile = componentsPropertyFile;
|
|
}
|
|
|
|
if (!File.Exists(cultureActionFile))
|
|
{
|
|
cultureActionFile = componentsActionFile;
|
|
}
|
|
|
|
if (!File.Exists(cultureEventFile))
|
|
{
|
|
cultureEventFile = componentsEventFile;
|
|
}
|
|
|
|
componentsPropertyFile = culturePropertyFile;
|
|
componentsActionFile = cultureActionFile;
|
|
componentsEventFile = cultureEventFile;
|
|
|
|
|
|
if (File.Exists(componentsPropertyFile))
|
|
{
|
|
LoggingService.Info("加载组件属性文件...");
|
|
if (this._propertyXmlDoc == null)
|
|
{
|
|
this._propertyXmlDoc = new XmlDocument();
|
|
}
|
|
this._propertyXmlDoc.Load(componentsPropertyFile);
|
|
}
|
|
if (File.Exists(componentsActionFile))
|
|
{
|
|
LoggingService.Info("加载组件动画文件...");
|
|
if (this._actionXmlDoc == null)
|
|
{
|
|
this._actionXmlDoc = new XmlDocument();
|
|
}
|
|
this._actionXmlDoc.Load(componentsActionFile);
|
|
}
|
|
if (File.Exists(componentsEventFile))
|
|
{
|
|
LoggingService.Info("加载组件动画文件...");
|
|
if (this._eventXmlDoc == null)
|
|
{
|
|
this._eventXmlDoc = new XmlDocument();
|
|
}
|
|
this._eventXmlDoc.Load(componentsEventFile);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LoggingService.Error(ex.Message + "\r\n" + ex.StackTrace);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 公共配置实例对象
|
|
/// </summary>
|
|
public static PublicConfig Instance
|
|
{
|
|
get
|
|
{
|
|
if (_instance == null)
|
|
{
|
|
_instance = new PublicConfig();
|
|
}
|
|
return _instance;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 控件属性列表文件
|
|
/// </summary>
|
|
public string ComponentsPropertyFile
|
|
{
|
|
get { return _componentsPropertyFile; }
|
|
}
|
|
/// <summary>
|
|
/// 控件动画列表文件
|
|
/// </summary>
|
|
public string ComponentsActionFile
|
|
{
|
|
get { return _componentsActionFile; }
|
|
}
|
|
/// <summary>
|
|
/// 控件事件列表文件
|
|
/// </summary>
|
|
public string ComponentsEventFile
|
|
{
|
|
get { return this._componentsEventFile; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// 属性解析对象
|
|
/// </summary>
|
|
public XmlDocument PropertyXmlDoc
|
|
{
|
|
get { return _propertyXmlDoc; }
|
|
set { _propertyXmlDoc = value; }
|
|
}
|
|
/// <summary>
|
|
/// 动画解析对象
|
|
/// </summary>
|
|
public XmlDocument ActionXmlDoc
|
|
{
|
|
get { return _actionXmlDoc; }
|
|
set { _actionXmlDoc = value; }
|
|
}
|
|
/// <summary>
|
|
/// 事件解析对象
|
|
/// </summary>
|
|
public XmlDocument EventXmlDoc
|
|
{
|
|
get { return _eventXmlDoc; }
|
|
set { _eventXmlDoc = value; }
|
|
}
|
|
|
|
#region 自定义全局方法
|
|
|
|
/// <summary>
|
|
/// 刷新配置
|
|
/// </summary>
|
|
public void RefreshConfig()
|
|
{
|
|
this._propertyXmlDoc = null;
|
|
this._actionXmlDoc = null;
|
|
this._eventXmlDoc = null;
|
|
this.Load();
|
|
}
|
|
/// <summary>
|
|
/// 整个文件夹拷贝
|
|
/// </summary>
|
|
/// <param name="yanfilepath">源</param>
|
|
/// <param name="mudifilepath">目标</param>
|
|
public void CopyFilesDirs(string yanfilepath, string mudifilepath)
|
|
{
|
|
try
|
|
{
|
|
string[] arrDirs = Directory.GetDirectories(yanfilepath);
|
|
string[] arrFiles = Directory.GetFiles(yanfilepath);
|
|
if (arrFiles.Length != 0)
|
|
{
|
|
for (int i = 0; i < arrFiles.Length; i++)
|
|
File.Copy(yanfilepath + "//" + Path.GetFileName(arrFiles[i]), mudifilepath + "//"
|
|
+ Path.GetFileName(arrFiles[i]), true);
|
|
}
|
|
if (arrDirs.Length != 0)
|
|
{
|
|
for (int i = 0; i < arrDirs.Length; i++)
|
|
{
|
|
Directory.CreateDirectory(mudifilepath + "//" + Path.GetFileName(arrDirs[i]));
|
|
//递归调用
|
|
CopyFilesDirs(yanfilepath + "//" + Path.GetFileName(arrDirs[i]),
|
|
mudifilepath + "//" + Path.GetFileName(arrDirs[i]));
|
|
}
|
|
}
|
|
else
|
|
return;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//LoggingService.Error("文件拷贝出错!\r\n" + ex.Message + "\r\n" + ex.StackTrace);
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
}
|