public void Remove(AllowedAppElement item)
 {
     if (BaseIndexOf(item) >= 0)
     {
         BaseRemove(item.Shortcut);
     }
 }
 public void Add(AllowedAppElement item)
 {
     base.BaseAdd(item);
 }
Ejemplo n.º 3
0
        /// <summary>
        /// -configa app_path
        /// -configa shortcut app_path
        /// -configa app_path app_args
        /// </summary>
        /// <param name="args">[shortcut] app_path</param>
        private static void ChoiceConfigAdd(string[] args)
        {
            if (IsAdmin())
            {
                AllowedAppElement ae = new AllowedAppElement();

                if (_argCount < 2)
                {
                    ManageErrors(WinService.ErrorCode.ERROR_InvalidArguments);
                    return;
                }
                // -configa [shortcut] app_path [app_args] [-console]
                ae.Console = args.Contains <string>("-console");

                // -configa app_path [app_args] [-console]
                if (File.Exists(args[1]))
                {
                    ae.Shortcut = Path.GetFileNameWithoutExtension(args[1]);
                    ae.Path     = args[1];
                    ae.Args     = (_argCount == 3) ? args[2] : string.Empty;
                }
                // -configa [shortcut] app_path [app_args] [-console]
                else
                {
                    if (_argCount < 3)
                    {
                        ManageErrors(WinService.ErrorCode.ERROR_InvalidArguments);
                        return;
                    }
                    // -configa [shortcut] app_path [app_args] [-console]
                    if (File.Exists(args[2]))
                    {
                        ae.Path     = args[2];
                        ae.Shortcut = args[1];
                        ae.Args     = (_argCount == 4) ? args[3] : string.Empty;
                    }
                    else
                    {
                        ManageErrors(WinService.ErrorCode.ERROR_FileNotFound);
                        return;
                    }
                }

                if (_section.AllowedApps[ae.Shortcut] == null)
                {
                    _section.AllowedApps.Add(ae);
                    _configuration.Save(ConfigurationSaveMode.Modified);
                    ConfigurationManager.RefreshSection("sectionName");
                }
                else
                {
                    ManageErrors(WinService.ErrorCode.ERROR_KeyExist);
                    return;
                }
            }
            else
            {
                ManageErrors(WinService.ErrorCode.ERROR_NotAllowed);
                return;
            }
        }