Ejemplo n.º 1
0
#pragma warning restore CS0649

        public SettingsForm(ISettings settings)
        {
            // Load versions before loading UI xaml.
            var versions = TimetableVersionExt.GetAllVersionInfos()
                           .Where(c => c.Compatibility == TtVersionCompatType.ReadWrite)
                           .Where(c => c.JtgVersionCompatibility.Any())
                           .SelectMany(c =>
                                       c.JtgVersionCompatibility.Select(j => new VersionItem(c.Version, j.version.Replace("*", "x"))))
                           .ToArray();

            L.CompatibleVersions = string.Join(", ", versions.Select(vi => vi.Name));

            Eto.Serialization.Xaml.XamlReader.Load(this);

            this.settings = settings;

            versionComboBox.DataStore       = versions;
            versionComboBox.ItemTextBinding = Binding.Delegate <VersionItem, string>(vi => vi.Name);

            javaPathTextBox.Text    = settings.Get("jTGStarter.javapath", "");
            jtgPathTextBox.Text     = settings.Get("jTGStarter.jtgpath", JtgShared.DEFAULT_FILENAME);
            messageCheckBox.Checked = !settings.Get("jTGStarter.show-message", true);

            var targetVersion = settings.GetEnum("jTGStarter.target-version", JtgShared.DEFAULT_TT_VERSION);
            var vidx          = Array.FindIndex(versions, v => v.Version == targetVersion);

            versionComboBox.SelectedIndex = vidx == -1 ? 0 : vidx;
        }
Ejemplo n.º 2
0
        public static bool JtgCompatCheck(string jTgPath, out TimetableVersion?fileVersion)
        {
            var versions = TimetableVersionExt.GetAllVersionInfos()
                           .Where(c => c.Compatibility == TtVersionCompatType.ReadWrite)
                           .Where(c => c.JtgVersionCompatibility.Any())
                           .SelectMany(c =>
                                       c.JtgVersionCompatibility.Select(j => (version: c.Version, pattern: j.version)))
                           .ToArray();

            var fn = Path.GetFileNameWithoutExtension(jTgPath);

            fileVersion = null;

            var match = Regex.Match(fn, @"jTrainGraph_(\d)(\d{2})");

            if (match.Success && match.Groups.Count == 3)
            {
                var major = int.Parse(match.Groups[1].Value);
                var minor = int.Parse(match.Groups[2].Value);

                foreach (var(version, pattern) in versions)
                {
                    var regex = new Regex(@$ "^{pattern.Replace(".", " \ \.").Replace(" * ", " \ \ d * ")}$");
                    if (regex.IsMatch($"{major}.{minor}"))
                    {
                        fileVersion = version;
                        return(true);
                    }
                }

                return(false); // New major version, probably incompatible.
            }
            return(true);      // No information available, so it is "compatibile".
        }
Ejemplo n.º 3
0
 private TimetableVersion[] GetAvailableVersions(TimetableType type)
 {
     return(TimetableVersionExt.GetAllVersionInfos()
            .Where(c => c.Compatibility == TtVersionCompatType.ReadWrite && c.Type == type)
            .Select(c => c.Version)
            .ToArray());
 }