Esempio n. 1
0
        public void CheckNewItemsDisabledByDefault()
        {
            bool shouldSave = false;

            if (string.IsNullOrEmpty(LastMaxId))
            {
                if (DisabledItems.Count == 0)
                {
                    foreach (string id in DisabledByDefault.Split(','))
                    {
                        DisabledItems.Add(id);
                    }
                }

                shouldSave = true;
            }
            else if (string.Compare(LastMaxId, MaxId, StringComparison.Ordinal) < 0)
            {
                foreach (string id in DisabledByDefault
                         .Split(',')
                         .Where(f => string.Compare(LastMaxId, f, StringComparison.Ordinal) < 0))
                {
                    DisabledItems.Add(id);
                }

                shouldSave = true;
            }

            if (shouldSave)
            {
                LastMaxId = MaxId;
                SaveSettingsToStorage();
            }
        }
Esempio n. 2
0
        public void CheckNewItemsDisabledByDefault(IEnumerable <string> itemsDisabledByDefault)
        {
            bool shouldSave = false;

            if (string.IsNullOrEmpty(LastMaxId))
            {
                if (DisabledItems.Count == 0)
                {
                    foreach (string id in itemsDisabledByDefault)
                    {
                        DisabledItems.Add(id);
                    }
                }

                shouldSave = true;
            }
            else if (string.CompareOrdinal(LastMaxId, MaxId) < 0)
            {
                foreach (string id in itemsDisabledByDefault)
                {
                    if (string.CompareOrdinal(LastMaxId, id) < 0)
                    {
                        DisabledItems.Add(id);
                    }
                }

                shouldSave = true;
            }

            if (shouldSave)
            {
                LastMaxId = MaxId;
                SaveSettingsToStorage();
            }
        }
Esempio n. 3
0
 public void ClearCustomizations(IContentManager modList)
 {
     lock (DisabledItems)
         DisabledItems.Clear();
     lock (AdditionalMods)
         AdditionalMods.Clear();
     UpdateState();
 }
Esempio n. 4
0
        public void UpdateCustomRepoServerInfo(IContentManager modList, SixRepoServer repoServer, string url,
                                               SixRepo repo)
        {
            if (modList == null)
            {
                throw new ArgumentNullException(nameof(modList));
            }
            if (repoServer == null)
            {
                throw new ArgumentNullException(nameof(repoServer));
            }
            if (url == null)
            {
                throw new ArgumentNullException(nameof(url));
            }
            if (repo == null)
            {
                throw new ArgumentNullException(nameof(repo));
            }

            UpdateSharedRepoInfo(url, repo);

            var rMods        = repoServer.RequiredMods;
            var optionalMods =
                repoServer.AllowedMods.Where(x => !SixRepoServer.SYS.Contains(x))
                .DistinctBy(x => x.ToLower())
                .ToList();
            var requiredMods =
                rMods.Where(x => !SixRepoServer.SYS.Contains(x)).DistinctBy(x => x.ToLower()).ToArray();

            Name           = GetNameFromServerOrRepo(repoServer, repo);
            Mods           = requiredMods.ToList();
            SkipServerMods = rMods.None(SixRepoServer.SYS.Contains);
            RequiredMods   =
                requiredMods.Where(x => !optionalMods.Contains(x, StringComparer.CurrentCultureIgnoreCase)).ToList();
            OptionalMods = optionalMods;
            DisabledItems.AddWhenMissing(optionalMods.Where(x =>
                                                            !requiredMods.Contains(x, StringComparer.CurrentCultureIgnoreCase) &&
                                                            !AdditionalMods.Contains(x, StringComparer.CurrentCultureIgnoreCase)),
                                         StringComparison.CurrentCultureIgnoreCase);

            AdditionalMods.AddWhenMissing(optionalMods, StringComparison.CurrentCultureIgnoreCase);

            Image      = String.IsNullOrWhiteSpace(repoServer.Image) ? repo.Config.Image : repoServer.Image;
            ImageLarge =
                String.IsNullOrWhiteSpace(repoServer.ImageLarge)
                    ? repo.Config.ImageLarge
                    : repoServer.ImageLarge;

            CustomRepoUuid = repoServer.Uuid;
            CustomRepoApps = repoServer.Apps.Where(x => repo.Config.Apps.ContainsKey(x))
                             .Select(x => repo.Config.Apps[x]).ToArray();
            IsOpen         = repoServer.IsOpen;
            ForceModUpdate = repoServer.ForceModUpdate;

            HandleModsetMods(modList);
            UpdateState();
        }
Esempio n. 5
0
 protected void SetIsEnabled(string id, bool isEnabled)
 {
     if (isEnabled)
     {
         DisabledItems.Remove(id);
     }
     else
     {
         DisabledItems.Add(id);
     }
 }
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!StopProcessing)
     {
         ReloadData();
     }
     else
     {
         // Get disabled item indexes and disable them
         string[] indexes = DisabledItems.TrimEnd('|').Split('|');
         DisabledItems = string.Empty;
         int cnt = drpCategories.Items.Count;
         foreach (int i in indexes.Select(index => ValidationHelper.GetInteger(index, -1)).Where(i => (i >= 0) && (i < cnt)))
         {
             DisableItem(drpCategories.Items[i]);
         }
     }
 }
Esempio n. 7
0
        protected virtual bool RemoveMod(IMod mod)
        {
            var key = mod.GetSerializationString();

            lock (Items) {
                lock (AdditionalMods) {
                    if (!AdditionalMods.Contains(key, StringComparer.InvariantCultureIgnoreCase))
                    {
                        return(false);
                    }
                    AdditionalMods.Remove(key);
                }
                if (Mods.Contains(key, StringComparer.InvariantCultureIgnoreCase))
                {
                    return(false);
                }
                Items.RemoveAll(Items.Where(x => x.ComparePK(mod)).ToArray());
                DisabledItems.RemoveAllLocked(x => x.Equals(mod.Name, StringComparison.InvariantCultureIgnoreCase));
                UpdateState();
                return(true);
            }
        }
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!StopProcessing && !URLHelper.IsPostback())
     {
         ReloadData();
     }
     else
     {
         // Get disabled item indexes and disable them
         string[] indexs = DisabledItems.TrimEnd('|').Split('|');
         DisabledItems = string.Empty;
         int cnt = drpCategories.Items.Count;
         foreach (string index in indexs)
         {
             int i = ValidationHelper.GetInteger(index, -1);
             if (i >= 0 && i < cnt)
             {
                 DisableItem(drpCategories.Items[i]);
             }
         }
     }
 }
    /// <summary>
    /// Fills dropdown with data.
    /// </summary>
    /// <param name="parentID">Identifier of node which children you want to add</param>
    /// <param name="level">Level of indentation</param>
    private void FillDropDown(int parentID, int level)
    {
        if (GroupedCategories != null)
        {
            List <DataRowView> gCategory = GroupedCategories.GetGroup(parentID);
            if (gCategory != null)
            {
                var categoryTypeInfo = CategoryInfo.TypeInfo;

                foreach (DataRowView drCategory in gCategory)
                {
                    if (!ExcludedItems.Contains(ValidationHelper.GetInteger(drCategory[categoryTypeInfo.IDColumn], 0)))
                    {
                        string name       = ResHelper.LocalizeString(drCategory[CategoryInfo.Generalized.DisplayNameColumn].ToString());
                        int    categoryId = ValidationHelper.GetInteger(drCategory[categoryTypeInfo.IDColumn], 0);

                        List <DataRowView> objectGroup        = ((!ShowEmptyCategories || ShowObjects) && GroupedObjects != null) ? GroupedObjects.GetGroup(drCategory[categoryTypeInfo.IDColumn]) : null;
                        List <DataRowView> childCategoryGroup = !ShowEmptyCategories?GroupedCategories.GetGroup(categoryId) : null;

                        // Check for empty categories except the root
                        if ((level == 0) || ShowEmptyCategories || ((objectGroup != null) && (objectGroup.Count > 0)) || ((childCategoryGroup != null) && (childCategoryGroup.Count > 0)))
                        {
                            bool enabled = true;

                            // Resolve Enabled condition
                            if (!String.IsNullOrEmpty(EnabledCondition))
                            {
                                MacroResolver.SetAnonymousSourceData(drCategory);
                                enabled = ValidationHelper.GetBoolean(MacroResolver.ResolveMacros(EnabledCondition), true);
                            }

                            string indentation = String.Empty;

                            if ((level > 0) || ShowRoot)
                            {
                                // Create indentation for specified level
                                indentation = String.Concat(Enumerable.Repeat(SubItemPrefix, ShowRoot ? level : level - 1));

                                string value = ((level == 0) && (RootValue > 0) ? RootValue : categoryId).ToString();

                                // Prevent category list item to be selected by ID when selecting object
                                if (ShowObjects)
                                {
                                    value = "cat_" + value;
                                }

                                // Insert category
                                ListItem listItem = new ListItem(indentation + ResHelper.LocalizeString(name), value);
                                if (ShowObjects || DisabledItems.Contains(categoryId) || !enabled)
                                {
                                    listItem.Attributes.Add("style", DisabledItemStyle);
                                    listItem.Attributes.Add("disabled", "disabled");
                                }
                                else
                                {
                                    if (!firstItem && String.IsNullOrEmpty(mSelectedValue))
                                    {
                                        SetItem(parentID, value);
                                    }
                                }
                                drpCategory.Items.Add(listItem);
                            }

                            // Go deeper
                            FillDropDown(categoryId, level + 1);

                            // Insert all child objects if needed
                            if (ShowObjects && !DataHelper.DataSourceIsEmpty(objectGroup))
                            {
                                if (objectGroup != null)
                                {
                                    indentation += SubItemPrefix;
                                    foreach (DataRowView childObject in objectGroup)
                                    {
                                        string text     = indentation + ResHelper.LocalizeString(childObject[ObjectInfo.Generalized.DisplayNameColumn].ToString());
                                        string objValue = childObject[ObjectInfo.TypeInfo.IDColumn].ToString();
                                        drpCategory.Items.Add(new ListItem(text, objValue));

                                        if (!firstItem && String.IsNullOrEmpty(mSelectedValue))
                                        {
                                            SetItem(parentID, objValue);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
Esempio n. 10
0
 IEnumerable <string> KeepModsWhichAreRequiredOrOptionalOrEnabled(IEnumerable <string> mods) => mods.Where(x => GetRequiredAndOptionalMods().ContainsIgnoreCase(x) ||
                                                                                                           !DisabledItems.ContainsIgnoreCase(x));
Esempio n. 11
0
 protected bool IsEnabled(string id)
 {
     return(!DisabledItems.Contains(id));
 }
Esempio n. 12
0
 public void DisableMod(string name)
 {
     DisabledItems.AddLocked(name);
     UpdateState();
 }
Esempio n. 13
0
 public void EnableMod(string name)
 {
     DisabledItems.RemoveAllLocked(x => x.Equals(name, StringComparison.CurrentCultureIgnoreCase));
     UpdateState();
 }