	/// <summary>
	/// Application policy settings
	/// </summary>
	public static class AppPolicy
	{
		private static bool[] m_vCurPolicyFlags = new bool[(int)AppPolicyFlag.Count];
		private static bool[] m_vNewPolicyFlags = new bool[(int)AppPolicyFlag.Count];

		private static string PolicyToString(AppPolicyFlag flag)
		{
			string str = KPRes.Feature + @": ";

			switch(flag)
			{
				case AppPolicyFlag.Plugins:
					str += KPRes.Plugins;
					break;
				case AppPolicyFlag.Export:
					str += KPRes.Export;
					break;
				case AppPolicyFlag.Import:
					str += KPRes.Import;
					break;
				case AppPolicyFlag.Print:
					str += KPRes.Print;
					break;
				case AppPolicyFlag.SaveDatabase:
					str += KPRes.SaveDatabase;
					break;
				case AppPolicyFlag.AutoType:
					str += KPRes.AutoType;
					break;
				case AppPolicyFlag.CopyToClipboard:
					str += KPRes.Clipboard;
					break;
				case AppPolicyFlag.DragDrop:
					str += KPRes.DragDrop;
					break;
				case AppPolicyFlag.ChangeMasterKey:
					str += KPRes.ChangeMasterKey;
					break;
				case AppPolicyFlag.EditTriggers:
					str += KPRes.TriggersEdit;
					break;
				case AppPolicyFlag.UnhidePasswords:
					str += KPRes.UnhidePasswords;
					break;
				default:
					Debug.Assert(false);
					str += KPRes.Unknown + ".";
					break;
			}

			str += MessageService.NewLine + KPRes.Description + @": ";

			switch(flag)
			{
				case AppPolicyFlag.Plugins:
					str += KPRes.PolicyPluginsDesc;
					break;
				case AppPolicyFlag.Export:
					str += KPRes.PolicyExportDesc;
					break;
				case AppPolicyFlag.Import:
					str += KPRes.PolicyImportDesc;
					break;
				case AppPolicyFlag.Print:
					str += KPRes.PolicyPrintDesc;
					break;
				case AppPolicyFlag.SaveDatabase:
					str += KPRes.PolicySaveDatabaseDesc;
					break;
				case AppPolicyFlag.AutoType:
					str += KPRes.PolicyAutoTypeDesc;
					break;
				case AppPolicyFlag.CopyToClipboard:
					str += KPRes.PolicyClipboardDesc;
					break;
				case AppPolicyFlag.DragDrop:
					str += KPRes.PolicyDragDropDesc;
					break;
				case AppPolicyFlag.ChangeMasterKey:
					str += KPRes.PolicyChangeMasterKey;
					break;
				case AppPolicyFlag.EditTriggers:
					str += KPRes.PolicyTriggersEditDesc;
					break;
				case AppPolicyFlag.UnhidePasswords:
					str += KPRes.UnhidePasswordsDesc;
					break;
				default:
					Debug.Assert(false);
					str += KPRes.Unknown + ".";
					break;
			}

			return str;
		}

		public static string RequiredPolicyMessage(AppPolicyFlag flag)
		{
			string str = KPRes.PolicyDisallowed + MessageService.NewParagraph;
			str += KPRes.PolicyRequiredFlag + ":" + MessageService.NewLine;
			str += PolicyToString(flag);

			return str;
		}

		public static void CurrentAllowAll(bool bAllow)
		{
			for(int i = 0; i < (int)AppPolicyFlag.Count; ++i)
				m_vCurPolicyFlags[i] = m_vNewPolicyFlags[i] = bAllow;
		}

		public static void CurrentAllow(AppPolicyFlag flag, bool bAllow)
		{
			m_vCurPolicyFlags[(int)flag] = m_vNewPolicyFlags[(int)flag] = bAllow;
		}

		public static void NewAllow(AppPolicyFlag flag, bool bAllow)
		{
			m_vNewPolicyFlags[(int)flag] = bAllow;
		}

		public static bool NewIsAllowed(AppPolicyFlag flag)
		{
			return m_vNewPolicyFlags[(int)flag];
		}

		public static bool IsAllowed(AppPolicyFlag flag)
		{
			return m_vCurPolicyFlags[(int)flag];
		}

		public static bool Try(AppPolicyFlag flag)
		{
			bool bAllowed = m_vCurPolicyFlags[(int)flag];

			if(bAllowed == false)
			{
				string strMsg = RequiredPolicyMessage(flag);
				MessageService.ShowWarning(strMsg);
			}

			return bAllowed;
		}
	}
