Example #1
0
        private List <OutputPattern> Load(ISettingsHandler settings, string lastRanVersion)
        {
            var names = LegacyConfigEntries.Instance;

            List <string> filenames = settings.Get(names.PatternFileNames.Name);

            if (filenames.Count == 1 && string.IsNullOrEmpty(filenames[0]))
            {
                return(new List <OutputPattern>());
            }
            List <string> patterns   = settings.Get(names.Patterns.Name);
            List <int>    saveEvents = settings.Geti(names.SaveEvents.Name);


            var requiredCount = Math.Max(filenames.Count, Math.Max(patterns.Count, saveEvents.Count));

            if (filenames.Count != requiredCount || patterns.Count != requiredCount || saveEvents.Count != requiredCount)
            {
                var userResponse = MessageBox.Show("Your output patterns are broken and could not be loaded successfully" + Environment.NewLine +
                                                   "I can load them with missing data or just reset to default patterns." + Environment.NewLine +
                                                   "Do you want to try to load them?" + Environment.NewLine +
                                                   "Note that after this is done your patterns will be converted to new format with will get rid of this issue."
                                                   , "osu!StreamCompanion - User action required!", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk);
                if (userResponse == DialogResult.No)
                {
                    return(new List <OutputPattern>());
                }

                var toFixCount = requiredCount * 3 - (filenames.Count + patterns.Count + saveEvents.Count);
                while (filenames.Count < requiredCount)
                {
                    filenames.Add(ParserSettings.GenerateFileName(filenames, "Recovered_"));
                }
                while (patterns.Count < requiredCount)
                {
                    patterns.Add("Recovered");
                }
                while (saveEvents.Count < requiredCount)
                {
                    saveEvents.Add((int)OsuStatus.All);
                }

                MessageBox.Show("Finished recovering patterns" + Environment.NewLine +
                                toFixCount + " entrys were missing" + Environment.NewLine +
                                "Go to settings and check your patterns!!!", "osu!StreamCompanion - Done", MessageBoxButtons.OK);
            }

            var loadedPatterns = new List <OutputPattern>();

            for (int i = 0; i < filenames.Count; i++)
            {
                //Converting from ealier versions
                if (saveEvents[i] == 27 || saveEvents[i] == 31)
                {
                    saveEvents[i] = (int)OsuStatus.All;
                }
                if (filenames[i].EndsWith(".txt"))
                {
                    filenames[i] = filenames[i].Substring(0, filenames[i].LastIndexOf(".txt", StringComparison.Ordinal));
                }

                var       c = Color.FromArgb(255, 0, 0);
                OsuStatus saveEvent;
                try
                {
                    saveEvent = (OsuStatus)saveEvents[i];
                }
                catch
                {
                    saveEvent = OsuStatus.All;
                }
                loadedPatterns.Add(new OutputPattern()
                {
                    Name      = filenames[i],
                    Pattern   = patterns[i],
                    SaveEvent = saveEvent,
                    ShowInOsu = false,
                    XPosition = 200,
                    YPosition = 200,
                    Color     = c,
                    FontName  = "Arial",
                    FontSize  = 12
                });
            }

            return(loadedPatterns);
        }
Example #2
0
        private void Load()
        {
            List <string> filenames  = _settings.Get(_names.PatternFileNames.Name);
            List <string> patterns   = _settings.Get(_names.Patterns.Name);
            List <int>    saveEvents = _settings.Geti(_names.saveEvents.Name);

            if (filenames.Count != patterns.Count || filenames.Count != saveEvents.Count)
            {
                string _filenames  = _settings.GetRaw(_names.PatternFileNames.Name);
                string _patterns   = _settings.GetRaw(_names.Patterns.Name);
                string _saveEvents = _settings.GetRaw(_names.saveEvents.Name);
                _logger?.Log("User patterns are broken: {0} {1} {2} \n{3}\n{4}\n{5}", LogLevel.Error,
                             filenames.Count.ToString(), patterns.Count.ToString(), saveEvents.Count.ToString(),
                             _filenames, _patterns, _saveEvents);
                var userResponse = MessageBox.Show("Your output patterns are broken and could not be loaded successfully" + Environment.NewLine +
                                                   "I can load them with missing data or just reset to default patterns." + Environment.NewLine +
                                                   "Do you want to try to load them?"
                                                   , "osu!StreamCompanion - User action required!", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk);
                if (userResponse == DialogResult.No)
                {
                    return;
                }

                var requiredCount = Math.Max(filenames.Count, Math.Max(patterns.Count, saveEvents.Count));
                var toFixCount    = requiredCount * 3 - (filenames.Count + patterns.Count + saveEvents.Count);
                while (filenames.Count < requiredCount)
                {
                    filenames.Add(ParserSettings.GenerateFileName(filenames, "Recovered_"));
                }
                while (patterns.Count < requiredCount)
                {
                    patterns.Add("Recovered");
                }
                while (saveEvents.Count < requiredCount)
                {
                    saveEvents.Add((int)OsuStatus.All);
                }
                MessageBox.Show("Finished recovering patterns" + Environment.NewLine +
                                toFixCount + " entrys were missing" + Environment.NewLine +
                                "Go to settings and check your patterns!!!", "osu!StreamCompanion - Done", MessageBoxButtons.OK);
            }
            lock (_lockingObject)
            {
                _patterns.Clear();
                for (int i = 0; i < filenames.Count; i++)
                {
                    //Converting from ealier versions
                    if (saveEvents[i] == 27)
                    {
                        saveEvents[i] = (int)OsuStatus.All;
                    }
                    if (filenames[i].EndsWith(".txt"))
                    {
                        filenames[i] = filenames[i].Substring(0, filenames[i].LastIndexOf(".txt", StringComparison.Ordinal));
                    }

                    _patterns.Add(new OutputPattern()
                    {
                        Name      = filenames[i],
                        Pattern   = patterns[i],
                        SaveEvent = (OsuStatus)saveEvents[i],
                    });
                }
            }
        }