Пример #1
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);
        }
Пример #2
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);
        }
        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);
        }