コード例 #1
0
            public static void LoadCommonSettings()
            {
                string fullPath   = GlobalSettings.MainDirectory + "\\" + Constants.FILENAME_SETTINGS_COMMON;
                string folderPath = fullPath.Substring(0, fullPath.LastIndexOf('\\'));

                if (!Directory.Exists(folderPath))
                {
                    Directory.CreateDirectory(folderPath);

                    ResetCommonSettings();
                    SaveCommonSettings();
                }
                else if (!File.Exists(fullPath))
                {
                    ResetCommonSettings();
                    SaveCommonSettings();
                }
                else if (File.Exists(fullPath))
                {
                    try
                    {
                        using (FileStream fileStream = new FileStream(fullPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                        {
                            using (StreamReader reader = new StreamReader(fileStream, Encoding.Unicode))
                            {
                                xmlComonSettings = (RootSettingsCommon)xmlSerializer.Deserialize(reader);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(Messages.ERROR_LOAD_SETTINGS_COMMON + ex.Message, Messages.CAPTION_COMMON);
                        ResetCommonSettings();
                        SaveCommonSettings();
                    }
                }
            }
コード例 #2
0
 static CommonSettings()
 {
     xmlComonSettings = new RootSettingsCommon();
     xmlSerializer    = XmlSerializer.FromTypes(new[] { typeof(RootSettingsCommon) })[0];
 }