示例#1
0
        /// <summary>
        /// Re-writes the modification json file
        /// </summary>
        /// <param name="installed">a list of installed mods</param>
        /// <param name="jsonFilePath">the path to the emergeny mod settings file</param>
        /// <returns>true or false</returns>
        public static bool writeJsonModFile(SortableObservableCollection <InstalledMod> installed, string jsonFilePath)
        {
            // Reformate List into  Dictonary
            //
            Dictionary <string, Dictionary <string, string> > mods = new Dictionary <string, Dictionary <string, string> >();

            foreach (var mod in installed)
            {
                Dictionary <string, string> optionStorage = new Dictionary <string, string>();
                string[] options = new string[2];

                //Getting mod Options and preparing them for saving
                //
                options[0] = mod.Enabled.ToString().ToLower();
                options[1] = mod.OrderingIndex;

                optionStorage.Add("Enabled", options[0]);
                optionStorage.Add("OrderingIndex", options[1]);

                //Adding the mods to our Dictonary
                //
                mods.Add(mod.ModificationName, optionStorage);
            }

            // Creating JSON Data
            //
            string jsonModData = JsonConvert.SerializeObject(mods, Formatting.Indented);

            // Save to file
            //
            File.WriteAllText(@jsonFilePath, jsonModData);

            return(true);
        }
示例#2
0
        public void setInstalledModifications(string jsonFilePath)
        {
            this.InstalledModifications = new SortableObservableCollection <InstalledMod>();

            Dictionary <string, Dictionary <string, string> > mods = new Dictionary <string, Dictionary <string, string> >();

            mods = JsonConvert.DeserializeObject <Dictionary <string, Dictionary <string, string> > >(File.ReadAllText(jsonFilePath));

            foreach (var mod in mods)
            {
                // grab the mod name
                //
                string modName = mod.Key;

                //grab all options in foreach and then add them to a new InstalledMods object
                //
                string[] modOption = new string[2];

                //counter for stringarray
                int i = 0;
                foreach (var option in mod.Value)
                {
                    modOption[i] = option.Value;
                    i++;
                }

                bool active;

                if (modOption[0].Equals("true"))
                {
                    active = true;
                }
                else
                {
                    active = false;
                }


                InstalledMod currentMod = new InstalledMod(modName, active, modOption[1]);
                this.InstalledModifications.Add(currentMod);
            }
            NotifyPropertyChanged();
        }
示例#3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="modIndex"></param>
        /// <param name="installed"></param>
        /// <returns></returns>
        public static bool decreaseOrderingIndex(int modIndex, SortableObservableCollection <InstalledMod> installed)
        {
            //only change somethint if not the last object was selected
            //
            if (modIndex - 1 == -1)
            {
                return(false);
            }

            // store the name of the modifications which currently has the new ordering index (mod Index = Ordering Index
            // because of calculation minus on and the list, the indexes and also the Collection counts from zero
            //
            string helperModName = installed.Where(e => e.OrderingIndex.Equals((modIndex - 1).ToString())).FirstOrDefault().ModificationName;

            installed[modIndex].OrderingIndex = (modIndex - 1).ToString();
            installed.Where(e => e.ModificationName.Equals(helperModName)).FirstOrDefault().OrderingIndex = modIndex.ToString();
            installed.Sort(x => x.OrderingIndex, ListSortDirection.Ascending);
            return(true);
        }
示例#4
0
        /// <summary>
        /// Activates inactiv mods or deactivates activ mods
        /// </summary>
        /// <param name="modIndex">The index displayed in the listbox</param>
        /// <param name="installed">A list of all installed Emergency 5 Mods</param>
        /// <returns></returns>
        public static bool modifyModActivityState(int modIndex, SortableObservableCollection <InstalledMod> installed)
        {
            if (installed[modIndex].Enabled == false)
            {
                installed[modIndex].Enabled = true;
            }
            else if (installed[modIndex].Enabled == true)
            {
                installed[modIndex].Enabled = false;
            }
            else
            {
                // should only been reached if some  unexpected things are set as status
                //
                return(false);
            }

            // return true if all is nice :-)
            //

            return(true);
        }