Exemple #1
0
 public void SaveSettings()
 {
     new XDocument(
         new XElement(Tag_Root,
                      new XElement(Tag_NamedPipeAddress, NamedPipeAddress),
                      new XElement(Tag_AutoConnect, AutoConnect.ToString()),
                      new XElement(Tag_TimePaddingForLoop, TimePaddingForLoop.ToString()),
                      new XElement(Tag_LoopSelection, LoopSelection.ToString()),
                      new XElement(Tag_LoopNumber, LoopNumber.ToString()),
                      new XElement(Tag_PlayMode, PlayMode.ToString()),
                      new XElement(Tag_Volume,
                                   new XElement(Tag_VolumeValue, VolumeValue.ToString()),
                                   new XElement(Tag_VolumeMute, VolumeMute.ToString())),
                      new XElement(Tag_Documents, DocumentByDocumentGuid.Select(x =>
                                                                                new XElement(Tag_Document, new XAttribute(Att_Document_Id, x.Key), new XElement(Tag_Document_Name, x.Value.Name), new XElement(Tag_Media, x.Value.Media)))),
                      new XElement(Tag_MinimalSeverityToShowInLog, MinimalSeverityToShowInLog.ToString()),
                      new XElement(Tag_Window,
                                   new XElement(Tag_Top, WindowTop.ToString()),
                                   new XElement(Tag_Left, WindowLeft.ToString()),
                                   new XElement(Tag_Width, WindowWidth.ToString()),
                                   new XElement(Tag_Height, WindowHeight.ToString()),
                                   new XElement(Tag_Maximized, WindowMaximized.ToString()),
                                   new XElement(Tag_AlwaysOnTop, AlwaysOnTop.ToString())),
                      new XElement(Tag_VlcLibPath, VlcLibPath),
                      new XElement(Tag_DoNotAskAgain, FontMissingWindowDoNotAskAgain.ToString()))
         ).Save(SettingsPath);
 }
Exemple #2
0
		public void RewriteConfig() {
			SetConfigField("CertificateStore", CertificateStore.ToString());
			SetConfigField("CertificateItem", CertificateItem.ToString());
			SetConfigField("WindowHeight", WindowHeight.ToString());
			SetConfigField("WindowWidth", WindowWidth.ToString());
			SetConfigField("WindowLeft", WindowLeft.ToString());
			SetConfigField("WindowTop", WindowTop.ToString());
			saveChangesToConfig();
		}
Exemple #3
0
 public void SaveSettings()
 {
     new XDocument(
         new XElement(Tag_Root,
                      new XElement(Tag_NamedPipeAddress, NamedPipeAddress),
                      new XElement(Tag_AutoConnect, AutoConnect.ToString()),
                      new XElement(Tag_MinimalSeverityToShowInLog, MinimalSeverityToShowInLog.ToString()),
                      new XElement(Tag_Window,
                                   new XElement(Tag_Top, WindowTop.ToString()),
                                   new XElement(Tag_Left, WindowLeft.ToString()),
                                   new XElement(Tag_Width, WindowWidth.ToString()),
                                   new XElement(Tag_Height, WindowHeight.ToString()),
                                   new XElement(Tag_Maximized, WindowMaximized.ToString()),
                                   new XElement(Tag_AlwaysOnTop, AlwaysOnTop.ToString())))
         ).Save(SettingsPath);
 }
Exemple #4
0
        public override void Update()
        {
            SettingNode root = new SettingNode(Xml_SettingRootName);

            root.SetAttribute(Xml_ActiveUserNodeName, ActiveUser);
            root.SetAttribute(Xml_ExportFolder, exportworkFolder);
            root.SetAttribute(Xml_SimpleMode, SimpleMode.ToString());

            SettingNode window = new SettingNode(Xml_WindowSettingRoot);

            window.SetAttribute(Xml_WindowLocX, WindowLeft.ToString());
            window.SetAttribute(Xml_WindowLocY, WindowTop.ToString());
            window.SetAttribute(Xml_WindowWidth, WindowWidth.ToString());
            window.SetAttribute(Xml_WindowHeight, WindowHeight.ToString());
            window.SetAttribute(Xml_APPName, AppName);

            root.AppendChild(window);

            SaveSettingXML(SettingFile, root);
        }
Exemple #5
0
		private bool checkConfig(XDocument cfg) {
			string binConfigPath = cfg.Root?.Element("CfgBinPath")?.Value;
			string certFilePath = cfg.Root?.Element("CertificateFilePath")?.Value;

			StoreLocation storeLocation;
			StoreLocation.TryParse(cfg.Root?.Element("CertificateStore")?.Value, true, out storeLocation);
			if(storeLocation != 0) {
				CertificateStore = storeLocation;
			} else {
				CertificateStore = StoreLocation.CurrentUser;
				SetConfigField("CertificateStore", CertificateStore.ToString());
			}

			#region [set window position and size]

			string lastHeightStr = cfg.Root?.Element("WindowHeight")?.Value;
			string lastWidthStr = cfg.Root?.Element("WindowWidth")?.Value;
			string lastLeftStr = cfg.Root?.Element("WindowLeft")?.Value;
			string lastTopStr = cfg.Root?.Element("WindowTop")?.Value;

			if(!string.IsNullOrEmpty(lastHeightStr)) {
				WindowHeight = Int32.Parse(lastHeightStr);
			} else {
				WindowHeight = 780;
				SetConfigField("WindowHeight", WindowHeight.ToString());
			}

			if(!string.IsNullOrEmpty(lastWidthStr)) {
				WindowWidth = Int32.Parse(lastWidthStr);
			} else {
				WindowWidth = 590;
				SetConfigField("WindowWidth", WindowWidth.ToString());
			}

			if(!string.IsNullOrEmpty(lastLeftStr)) {
				WindowLeft = Int32.Parse(lastLeftStr);
			} else {
				WindowLeft = 100;
				SetConfigField("WindowLeft", WindowLeft.ToString());
			}

			if(!string.IsNullOrEmpty(lastTopStr)) {
				WindowTop = Int32.Parse(lastTopStr);
			} else {
				WindowTop = 20;
				SetConfigField("WindowTop", WindowTop.ToString());
			}
			#endregion

			string lastCertificateStr = cfg.Root?.Element("CertificateItem")?.Value;
			if(!string.IsNullOrEmpty(lastCertificateStr)) {
				CertificateItem = Int32.Parse(lastCertificateStr);
			} else {
				CertificateItem = 0;
				SetConfigField("CertificateItem", CertificateItem.ToString());
			}

			string interopCertificateThumb = cfg.Root?.Element("InteropCertificateThumbprint")?.Value;
			if (string.IsNullOrEmpty(interopCertificateThumb)) {
//				Thread.Sleep(1000);
				SetErrorMessage("Не указан сертификат подписи для взаимодействия");
					bool certSelected = SelectInteropCertificate();
					if (!certSelected) {

						MessageBox.Show(
							"Не указан сертификат подписи для взаимодействия.\nУкажите сертификат подписи, используя соответствующий пункт меню «Настройка» программы.",
							"Ошибка загрузки начальной конфигурации.", MessageBoxButton.OK,
							MessageBoxImage.Error);

						return false;
					} else {
						StoreLocation.TryParse(cfg.Root?.Element("InteropCertificateStore")?.Value,
												true,
												out _interopCertificateStoreLocation);
					}
			} else {
				_interopCertificateThumbprint = interopCertificateThumb;
				StoreLocation.TryParse(cfg.Root?.Element("InteropCertificateStore")?.Value, true, out _interopCertificateStoreLocation);
			}

			saveChangesToConfig();

			//signed (and siphered) binary config
			if(string.IsNullOrEmpty(binConfigPath)) {
				SetErrorMessage("Личный конфигурационный файл не найден");
				bool privateConfigSelected = LoadPrivateConfig();
				if (!privateConfigSelected) {

					MessageBox.Show("Личный конфигурационный файл не найден.\nСкачайте новый личный конфигурационный файл с корпоративного портала.",
									"Ошибка загрузки начальной конфигурации.", MessageBoxButton.OK, MessageBoxImage.Error);

					return false;
				}
			} else {
				//means htere is a config
				//check it's signature, but first load our certificate
				if(string.IsNullOrEmpty(certFilePath)) {
					MessageBox.Show("Файл сертификата сервера не найден.\nСкачайте файл сертификата сервера с корпоративного портала.",
								"Ошибка загрузки начальной конфигурации.", MessageBoxButton.OK, MessageBoxImage.Error);
					SetErrorMessage("Файл сертификата сервера не найден");
					bool serverCertifcateSelected = LoadServerCertificate();
					if (!serverCertifcateSelected) {
						return false;
					}
				} else {
					//means certificate && config present
					//check cert expiration date
					X509Certificate2 cert = new X509Certificate2();
					try {
						cert.Import(certFilePath);
						if (cert.NotAfter > DateTime.Now) {
							//cert ok
							//check config signature
							string configContents = Util.DecryptConfig(binConfigPath,ProgramFolder);
							if (string.IsNullOrEmpty(configContents)) {
								MessageBox.Show("Личный конфигурационный файл поврежден.\nСкачайте новый личный конфигурационный файл с корпоративного портала.",
									"Ошибка загрузки начальной конфигурации.", MessageBoxButton.OK, MessageBoxImage.Error);
								SetErrorMessage("Личный конфигурационный файл поврежден");
								return false;
							}
							XmlDocument xdocConfig = new XmlDocument();     // this stuff is for

							try {
								xdocConfig.LoadXml(configContents); // check signature further
							} catch (Exception e) {
								MessageBox.Show(
									$"Личный конфигурационный файл поврежден.\nСкачайте новый личный конфигурационный файл с корпоративного портала.\n\n{e.Message}",
									"Ошибка загрузки начальной конфигурации.", MessageBoxButton.OK, MessageBoxImage.Error);
								SetErrorMessage("Личный конфигурационный файл поврежден");
								return false;
							}

							XDocument privateConfig = XDocument.Parse(configContents);
							try {
								#if !DEBUG
								if (SignatureProcessor.VerifySignature(SignatureProcessor.SignatureType.Smev3SidebysideDetached, xdocConfig, cert)) {
								#endif
								#if DEBUG
								if(SignatureProcessor.VerifySignature(SignatureProcessor.SignatureType.Smev3SidebysideDetached, xdocConfig)) {
								#endif
									//config signature OK - loading contents
									if (privateConfig.Root?.Attribute("version").Value == ProgramVersion) {
										//means config version corresponds to a program version

										_ourCertificate = cert;
										_serverUri = new Uri(privateConfig.Root?.Element("Server").Element("GetFileUri")?.Value ?? "");
										_serverSignatureCertificateThumbprint = privateConfig.Root?.Element("Server").Element("CertificateThumbprint")?.Value ?? "";
										_serverHttpsCertificateThumbprint =
											privateConfig.Root?.Element("Server").Element("SSLCertificateThumbprint")?.Value ?? "";
										ClearError("Конфигурационный файл успешно загружен");
									} else {
										//means version in config is not right one
										MessageBox.Show(
											$"Текущая версия программы <{ProgramVersion}> устарела.\nСкачайте новую версию с корпоративного портала.",
											"Программа устарела.", MessageBoxButton.OK, MessageBoxImage.Error);
										SetErrorMessage($"Установленная версия программы <{ProgramVersion}> устарела");
										return false;
									}
								} else {
									//signature incorrect
									Debug.WriteLine("Invalid Signature");
									MessageBox.Show(
										"Личный конфигурационный файл поврежден.\nСкачайте новый личный конфигурационный файл с корпоративного портала.",
										"Ошибка загрузки начальной конфигурации.", MessageBoxButton.OK, MessageBoxImage.Error);
									SetErrorMessage("Личный конфигурационный файл поврежден");
									return false;
								}
							} catch (Exception e) {
								MessageBox.Show(
										$"Личный конфигурационный файл поврежден.\nСкачайте новый личный конфигурационный файл с корпоративного портала.\n\n{e.Message}",
										"Ошибка загрузки начальной конфигурации.", MessageBoxButton.OK, MessageBoxImage.Error);
								SetErrorMessage("Личный конфигурационный файл поврежден");
								return false;
							}

						} else {
							//cert expired
							MessageBox.Show("Файл сертификата сервера просрочен.\nСкачайте новый файл сертификата сервера с корпоративного портала.",
								"Ошибка загрузки начальной конфигурации.", MessageBoxButton.OK, MessageBoxImage.Error);
							SetErrorMessage("Файл сертификата сервера просрочен");
							return false;
						}
					} catch (Exception e) {
						//certificate corrupted
						MessageBox.Show($"Ошибка загрузки сертификата сервера. Файл поврежден.\nСкачайте новый файл сертификата сервера с корпоративного портала.\n\n{e.Message}",
								"Ошибка загрузки начальной конфигурации.", MessageBoxButton.OK, MessageBoxImage.Error);
						SetErrorMessage("Ошибка загрузки сертификата сервера");
						return false;
					}
				}
			}
			return true;
		}