123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- using ProjectManagementSystem.Common.Function;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Xml.Serialization;
- namespace ProjectManagementSystem.Config
- {
- public class CConfiManager
- {
- public static CustomConfig customConfig = new CustomConfig();
- public static PmsAutoupdateConfig PmsConfig = new PmsAutoupdateConfig();
- private static string m_strPath = "";
- private static string _GlobalDataFilePath = "";
- public static void Init()
- {
- InitConfigPath();
- InitGlobalData();
- InitPmsAutoupdateXml();
- }
- private static void InitConfigPath()
- {
- //获取到文件完整路径
- string s = System.Reflection.Assembly.GetExecutingAssembly().Location;
- //获取到文件所在目录
- FileInfo finfo = new FileInfo(s);
- string BaseDirectory = finfo.DirectoryName;
- m_strPath = Path.Combine(BaseDirectory, "PMS", "Config");
- _GlobalDataFilePath = Path.Combine(m_strPath, "CConfigSetting.xml");
- }
- private static void ExsitConfigPath()
- {
- DirectoryInfo dir = new DirectoryInfo(m_strPath);
- if (!dir.Exists)
- {
- dir.Create();
- }
- }
- public static void InitGlobalData()
- {
- //反序列化
- try
- {
- ExsitConfigPath();
- XmlSerializer serializer = new XmlSerializer(customConfig.GetType());
- if (!File.Exists(_GlobalDataFilePath))
- {
- SaveGlobalData();
- }
- else
- {
- using (TextReader tr = new StreamReader(_GlobalDataFilePath))
- {
- customConfig = (CustomConfig)serializer.Deserialize(tr);
- }
- }
- }
- catch (Exception e)
- {
- string strlog = e.Message;
- }
- }
- public static void SaveGlobalData()
- {
- try
- {
- ExsitConfigPath();
- XmlSerializer serializer = new XmlSerializer(customConfig.GetType());
- using (TextWriter tw = new StreamWriter(_GlobalDataFilePath))
- {
- serializer.Serialize(tw, customConfig);
- }
- }
- catch
- { }
- }
- public static void InitPmsAutoupdateXml()
- {
- try
- {
- string s = System.Reflection.Assembly.GetExecutingAssembly().Location;
- FileInfo finfo = new FileInfo(s);
- string currPath = finfo.DirectoryName;
- //string configDir = Path.Combine(currPath, "PMS", "Config");
- string configFile = Path.Combine(currPath, "pms.xml");
- PmsConfig.Version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
- PmsConfig.Url = AppSetting.GetAutoUpdateUrl().Replace("xml", "zip");
- string xml = XmlTools.XmlSerialize(PmsConfig);
- //XmlSerializer serializer = new XmlSerializer(PmsConfig.GetType());
- using (TextWriter tw = new StreamWriter(configFile))
- {
- tw.Write(xml);
- //serializer.Serialize(tw, PmsConfig);
- }
- string dataFile = Path.Combine(currPath, "pms.zip");
- if (File.Exists(dataFile))
- {
- File.Delete(dataFile);
- }
- List<string> fileList = new List<string>();
- DirectoryInfo theFolder = new DirectoryInfo(currPath);
- FileInfo[] fileInfos = theFolder.GetFiles();
- //遍历文件
- foreach (FileInfo fileInfo in fileInfos)
- {
- if (fileInfo.Extension == ".config"
- || fileInfo.Name.Contains("vshost"))
- {
- continue;
- }
- if (fileInfo.Name.StartsWith("ProjectManagementSystem")
- || fileInfo.Name.StartsWith("DbCommon"))
- {
- fileList.Add(fileInfo.FullName);
- }
- }
- ZipUtility zipUtility = new ZipUtility();
- zipUtility.ZipFileFromFiles(currPath, fileList, dataFile, 9);
- }
- catch (Exception)
- {
- }
- }
- }
- }
|