/// <summary>
 /// Loads settings from file
 /// </summary>
 /// <returns></returns>
 public bool Load()
 {
     try
     {
         var settingsobj =
             JsonObjectFileSaveLoad.ReadFromJsonFile <ApplicationSettings>(
                 Path.Combine(Environment.CurrentDirectory, @"AppSettings.json"));
         StartWithWindows  = settingsobj.StartWithWindows;
         DatabaseDirectory = settingsobj.DatabaseDirectory;
         DatabaseName      = settingsobj.DatabaseName;
         AutoBackup        = settingsobj.AutoBackup;
         AutoSaveLocation  = settingsobj.AutoSaveLocation;
         OverrideBackups   = settingsobj.OverrideBackups;
         BackupFrequency   = settingsobj.BackupFrequency;
         return(true);
     }
     catch (FileNotFoundException)
     {
         MessageBox.Show("Ingen indstillinger fil fundet, indlæser standard indstillinger",
                         "Ingen indstillinger fundet", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
         LoadDefaults();
         Save();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
        /// <summary>
        /// Test button
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonLoadDepData_Click(object sender, System.EventArgs e)
        {
            if (mappedAchievements.Count < 1)
            {
                LogInfo("[-] Please load the achievements first!");
                return;
            }
            var fileDialog = new OpenFileDialog();

            fileDialog.CheckFileExists = true;
            fileDialog.Multiselect     = false;
            fileDialog.CheckPathExists = true;
            var res = fileDialog.ShowDialog();

            if (res == DialogResult.OK)
            {
                mappedAchievements = JsonObjectFileSaveLoad.ReadFromJsonFile <List <Achievement> >(fileDialog.FileName);
                foreach (var achievement in mappedAchievements)
                {
                    var listItem = new ListViewItem(achievement.Name);
                    listItem.SubItems.Add(new ListViewItem.ListViewSubItem(listItem, achievement.Description));
                    listViewAchievement.Items.Add(listItem);
                }
            }
            LogInfo("[+] Loaded old dependency data");
        }
        private void buttonLoadData_Click(object sender, System.EventArgs e)
        {
            var fileDialog = new OpenFileDialog();

            fileDialog.CheckFileExists = true;
            fileDialog.Multiselect     = false;
            fileDialog.CheckPathExists = true;
            var res = fileDialog.ShowDialog();

            if (res == DialogResult.OK)
            {
                mappedAchievements = JsonObjectFileSaveLoad.ReadFromJsonFile <List <Achievement> >(fileDialog.FileName);
                foreach (var achievement in mappedAchievements)
                {
                    var listItem = new ListViewItem(achievement.Name);
                    listItem.SubItems.Add(new ListViewItem.ListViewSubItem(listItem, achievement.Description));
                    listViewAchievement.Items.Add(listItem);
                    DependencyOptions.Add((ListViewItem)listItem.Clone());
                }
                foreach (var skill in Enum.GetValues(typeof(Skill)))
                {
                    var listItem = new ListViewItem(skill.ToString());
                    listItem.SubItems.Add(new ListViewItem.ListViewSubItem(listItem, "Level required to complete achievement"));
                    DependencyOptions.Add(listItem);
                }
                LogInfo("[+] Loaded achievement data");
            }
        }
Ejemplo n.º 4
0
        public static void LoadSettings()
        {
            var settings = Settings.Instance;

            Console.Clear();
            FileInfo[] SettingsFiles = new FileInfo[] { };
            int        counter       = 1;

            SettingsFiles = Program.SettingsDirectory.GetFiles("*.json");
            if (SettingsFiles.Length > 0)
            {
                foreach (var file in SettingsFiles)
                {
                    Console.WriteLine(counter + ". " + file.Name);
                    counter++;
                }

                Console.WriteLine(counter + ". Return to main menu");
                Console.WriteLine("Which settings do you wish to load?");
                if (Int32.TryParse(Console.ReadLine(), out var value))
                {
                    if (value < counter)
                    {
                        settings = JsonObjectFileSaveLoad.ReadFromJsonFile <Settings>(SettingsFiles[value - 1].Name);
                        Settings.Instance.ActiveAutoSwitchHotkeys = settings.ActiveAutoSwitchHotkeys;
                        Settings.Instance.ActivePrayerHotkeys     = settings.ActivePrayerHotkeys;
                        Settings.Instance.AttackFkey            = settings.AttackFkey;
                        Settings.Instance.InventorySlots        = settings.InventorySlots;
                        Settings.Instance.PrayerFkey            = settings.PrayerFkey;
                        Settings.Instance.SpecialAttackBarPoint = settings.SpecialAttackBarPoint;
                        Settings.Instance.SpecialAttackHotkeys  = settings.SpecialAttackHotkeys;
                        Settings.Instance.Speed          = settings.Speed;
                        Settings.Instance.ReturnToOldPos = settings.ReturnToOldPos;
                        Settings.Instance.Prayers        = settings.Prayers;
                        Settings.Instance.Stretched      = settings.Stretched;
                        Settings.Instance.InventFKey     = settings.InventFKey;
                        Settings.Instance.WaitForSpecBar = settings.WaitForSpecBar;
                        Console.WriteLine("Loaded profile stored in: " + SettingsFiles[value - 1].Name);
                        Console.WriteLine("Press any key to return to main menu");
                        Console.ReadKey();
                    }
                    else if (value == counter)
                    {
                        return;
                    }
                    else
                    {
                        Console.WriteLine("Invalid value");
                        Console.WriteLine("Press any key to return to main menu");
                        Console.ReadKey();
                    }
                }
                else
                {
                    Console.WriteLine("Invalid value");
                    Console.WriteLine("Press any key to return to main menu");
                    Console.ReadKey();
                }
            }
            else
            {
                Console.WriteLine("None");
                Console.WriteLine("Press any key to return to main menu");
                Console.ReadKey();
            }
        }