示例#1
0
        public static bool SaveApplicationConfig(string fileName, SafePassConfiguration config)
        {
            System.Diagnostics.Debug.Assert(config != null);
            if (config == null)
            {
                throw new System.ArgumentNullException("config");
            }

            bool tmpSaveResult = true;

            try
            {
                var tmpWriterSettings = HuiruiSoft.Utils.XmlDocumentHelper.CreateXmlWriterSettings();
                using (var tmpXmlWriter = System.Xml.XmlWriter.Create(fileName, tmpWriterSettings))
                {
                    var tmpXmlSerializer = new XmlSerializerExtend(typeof(SafePassConfiguration));
                    tmpXmlSerializer.Serialize(tmpXmlWriter, config);
                }
            }
            catch (System.Exception)
            {
                System.Diagnostics.Debug.Assert(false); tmpSaveResult = false;
            }

            return(tmpSaveResult);
        }
示例#2
0
        public static bool SaveApplicationConfig(SafePassConfiguration config)
        {
            System.Diagnostics.Debug.Assert(config != null);
            if (config == null)
            {
                throw new System.ArgumentNullException("config");
            }

            bool tmpSaveResult = true;

            try
            {
                var tmpWriterSettings = HuiruiSoft.Utils.XmlDocumentHelper.CreateXmlWriterSettings( );

                var tmpWorkDirectory  = HuiruiSoft.Utils.NativeShellHelper.GetWorkingDirectory();
                var tmpConfigFileName = System.IO.Path.Combine(tmpWorkDirectory, ApplicationDefines.MainConfigFile);
                using (var tmpXmlWriter = System.Xml.XmlWriter.Create(tmpConfigFileName, tmpWriterSettings))
                {
                    var tmpXmlSerializer = new XmlSerializerExtend(typeof(SafePassConfiguration));
                    tmpXmlSerializer.Serialize(tmpXmlWriter, config);
                }
            }
            catch (System.Exception)
            {
                System.Diagnostics.Debug.Assert(false); tmpSaveResult = false;
            }

            return(tmpSaveResult);
        }
        public static LocalizationResources ReadLocalResource(string localLanguageFile)
        {
            if (string.IsNullOrEmpty(localLanguageFile))
            {
                throw new System.ArgumentNullException("localLanguageFile");
            }

            var tmpLocalLanguageFile = localLanguageFile;

            if (!File.Exists(tmpLocalLanguageFile))
            {
                tmpLocalLanguageFile = Path.Combine(System.Windows.Forms.Application.StartupPath, localLanguageFile);
            }

            LocalizationResources localization = null;

            if (File.Exists(tmpLocalLanguageFile))
            {
                using (var tmpFileStream = new FileStream(tmpLocalLanguageFile, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    using (var tmpGZipStream = new GZipStream(tmpFileStream, CompressionMode.Decompress))
                    {
                        var tmpXmlSerializer = new XmlSerializerExtend(typeof(LocalizationResources));
                        localization = (tmpXmlSerializer.Deserialize(tmpGZipStream) as LocalizationResources);
                    }
                }
            }

            return(localization);
        }
        public static bool SaveLocalResource(string localLanguageFile, LocalizationResources localResources)
        {
            System.Diagnostics.Debug.Assert(localResources != null);
            if (localResources == null)
            {
                throw new System.ArgumentNullException("localResources");
            }

            bool tmpSaveResult = true;

            try
            {
                using (var tmpFileStream = new FileStream(localLanguageFile, FileMode.Create, FileAccess.Write, FileShare.None))
                {
                    using (var tmpGZipStream = new GZipStream(tmpFileStream, CompressionMode.Compress))
                    {
                        using (var tmpXmlWriter = HuiruiSoft.Utils.XmlDocumentHelper.CreateXmlWriter(tmpGZipStream))
                        {
                            var tmpXmlSerializer = new XmlSerializerExtend(typeof(LocalizationResources));
                            tmpXmlSerializer.Serialize(tmpXmlWriter, localResources);
                        }
                    }
                }
            }
            catch (System.Exception)
            {
                System.Diagnostics.Debug.Assert(false); tmpSaveResult = false;
            }

            return(tmpSaveResult);
        }
示例#5
0
        private static SafePassConfiguration LoadApplicationConfig(string filePath)
        {
            if (string.IsNullOrEmpty(filePath))
            {
                return(null);
            }

            SafePassConfiguration applicationConfig = null;

            try
            {
                var tmpXmlSerializer = new XmlSerializerExtend(typeof(SafePassConfiguration));
                using (var tmpFileStream = new System.IO.FileStream(filePath, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read))
                {
                    applicationConfig = (SafePassConfiguration)tmpXmlSerializer.Deserialize(tmpFileStream);
                }
            }
            catch (System.Exception exception)
            {
                System.Diagnostics.Debug.WriteLine(exception.StackTrace);
            }

            return(applicationConfig);
        }