Esempio n. 1
0
        /// <summary>
        /// Additional information strings about the metadata
        /// </summary>
        /// <returns>array of strings with the user-readable information</returns>
        public string[] ToInfo()
        {
            string[] infoString = new string[] {
                catalog.GetStringFmt("Start at: {0}", Start),
                catalog.GetStringFmt("Heading to: {0}", End),
            };

            return(infoString);
        }
Esempio n. 2
0
 private void bImportSave_Click_1(object sender, EventArgs e)
 {
     // Show the dialog and get result.
     ofdImportSave.InitialDirectory = UserSettings.SavePackFolder;
     if (ofdImportSave.ShowDialog() == DialogResult.OK)
     {
         ExtractFilesFromZip(ofdImportSave.FileName, UserSettings.UserDataFolder);
         UpdateFileList(catalog.GetStringFmt("Save Pack '{0}' imported successfully.", Path.GetFileNameWithoutExtension(ofdImportSave.FileName)));
     }
 }
Esempio n. 3
0
        private async Task LoadSavePointsAsync()
        {
            lock (savePoints)
            {
                if (ctsLoader != null && !ctsLoader.IsCancellationRequested)
                {
                    ctsLoader.Cancel();
                    ctsLoader.Dispose();
                }
                ctsLoader = new System.Threading.CancellationTokenSource();
            }

            string warnings = string.Empty;

            string build  = VersionInfo.Build.Contains(" ") ? VersionInfo.Build.Substring(VersionInfo.Build.IndexOf(" ") + 1) : null;
            var    prefix = string.Empty;

            if (SelectedAction == MainForm.UserAction.SinglePlayerTimetableGame)
            {
                prefix = Path.GetFileName(route.Path) + " " + Path.GetFileNameWithoutExtension(timeTable.FileName);
            }
            else if (activity.FilePath != null)
            {
                prefix = Path.GetFileNameWithoutExtension(activity.FilePath);
            }
            else if (activity.Name == "- " + catalog.GetString("Explore Route") + " -")
            {
                prefix = Path.GetFileName(route.Path);
            }
            // Explore in activity mode
            else
            {
                prefix = "ea$" + Path.GetFileName(route.Path) + "$";
            }

            savePoints = (await Task.Run(() => SavePoint.GetSavePoints(UserSettings.UserDataFolder,
                                                                       prefix, build, route.Name, settings.YoungestFailedToRestore, warnings, ctsLoader.Token))).OrderBy(s => s.RealTime).Reverse().ToList();

            saveBindingSource.DataSource = savePoints;
            labelInvalidSaves.Text       = catalog.GetString(
                "To prevent crashes and unexpected behaviour, Open Rails invalidates games saved from older versions if they fail to restore.\n") +
                                           catalog.GetStringFmt("{0} of {1} saves for this route are no longer valid.", savePoints.Count(s => (s.Valid == false)), savePoints.Count);
            GridSaves_SelectionChanged(null, null);
            // Show warning after the list has been updated as this is more useful.
            if (!string.IsNullOrEmpty(warnings))
            {
                MessageBox.Show(warnings, Application.ProductName + " " + VersionInfo.VersionOrBuild);
            }
        }
Esempio n. 4
0
        private void SetTexts()
        {
            GettextResourceManager catalog = new GettextResourceManager(PathResolver.Default);

            // If satellite assemblies have another base name use GettextResourceManager("Examples.HelloForms.Messages") constructor
            // If you call from another assembly, use GettextResourceManager(anotherAssembly) constructor
            Localizer.Localize(this, catalog, store);
            // We need pass 'store' argument only to be able revert original text and switch languages on fly
            // Common use case doesn't required it: Localizer.Localize(this, catalog);

            // Manually formatted strings
            label2.Text = catalog.GetStringFmt("This program is running as process number \"{0}\".",
                                               System.Diagnostics.Process.GetCurrentProcess().Id);
            label3.Text = String.Format(
                catalog.GetPluralString("found {0} similar word", "found {0} similar words", 1),
                1);
            label4.Text = String.Format(
                catalog.GetPluralString("found {0} similar word", "found {0} similar words", 2),
                2);
            label5.Text = String.Format(
                catalog.GetPluralString("found {0} similar word", "found {0} similar words", 5),
                5);
            label6.Text = String.Format("{0} ('computers')", catalog.GetParticularString("Computers", "Text encoding"));
            label7.Text = String.Format("{0} ('military')", catalog.GetParticularString("Military", "Text encoding"));
            label8.Text = String.Format("{0} (non contextual)", catalog.GetString("Text encoding"));
        }
Esempio n. 5
0
        static void ShowMessages()
        {
            Console.WriteLine("Current culture {0}", System.Threading.Thread.CurrentThread.CurrentUICulture);
            GettextResourceManager catalog = new GettextResourceManager();

            Console.WriteLine(catalog.GetString("Hello, world!"));
            // GetStringFmt is an Gettext.NET extension
            Console.WriteLine(catalog.GetStringFmt("This program is running as process number \"{0}\".",
                                                   Process.GetCurrentProcess().Id));
            Console.WriteLine(String.Format(
                                  catalog.GetPluralString("found {0} similar word", "found {0} similar words", 1),
                                  1));
            // GetPluralStringFmt is an Gettext.NET extension
            Console.WriteLine(catalog.GetPluralStringFmt("found {0} similar word", "found {0} similar words", 2));
            Console.WriteLine(String.Format(
                                  catalog.GetPluralString("found {0} similar word", "found {0} similar words", 5),
                                  5));

            Console.WriteLine("{0} ('computers')", catalog.GetParticularString("Computers", "Text encoding"));
            Console.WriteLine("{0} ('military')", catalog.GetParticularString("Military", "Text encoding"));
            Console.WriteLine("{0} (non cotextual)", catalog.GetString("Text encoding"));

            Console.WriteLine(catalog.GetString(
                                  "Here is an example of how one might continue a very long string\nfor the common case the string represents multi-line output.\n"));
        }
Esempio n. 6
0
            public string[] ToInfo()
            {
                string[] infoString = new string[] {
                    Catalog.GetStringFmt("Start time: {0}", StartTime),
                };

                return(infoString);
            }
Esempio n. 7
0
 protected Activity(string filePath, Folder folder, Route route)
 {
     if (filePath == null)
     {
         Name = catalog.GetString("- Explore Route -");
     }
     else if (File.Exists(filePath))
     {
         var showInList = true;
         try
         {
             var actFile = new ActivityFile(filePath);
             var srvFile = new ServiceFile(System.IO.Path.Combine(System.IO.Path.Combine(route.Path, "SERVICES"), actFile.Tr_Activity.Tr_Activity_File.Player_Service_Definition.Name + ".srv"));
             // ITR activities are excluded.
             showInList  = actFile.Tr_Activity.Tr_Activity_Header.Mode != ActivityMode.IntroductoryTrainRide;
             Name        = actFile.Tr_Activity.Tr_Activity_Header.Name.Trim();
             Description = actFile.Tr_Activity.Tr_Activity_Header.Description;
             Briefing    = actFile.Tr_Activity.Tr_Activity_Header.Briefing;
             StartTime   = actFile.Tr_Activity.Tr_Activity_Header.StartTime;
             Season      = actFile.Tr_Activity.Tr_Activity_Header.Season;
             Weather     = actFile.Tr_Activity.Tr_Activity_Header.Weather;
             Difficulty  = actFile.Tr_Activity.Tr_Activity_Header.Difficulty;
             Duration    = actFile.Tr_Activity.Tr_Activity_Header.Duration;
             Consist     = new Consist(System.IO.Path.Combine(System.IO.Path.Combine(System.IO.Path.Combine(folder.Path, "TRAINS"), "CONSISTS"), srvFile.Train_Config + ".con"), folder);
             Path        = new Path(System.IO.Path.Combine(System.IO.Path.Combine(route.Path, "PATHS"), srvFile.PathID + ".pat"));
             if (!Path.IsPlayerPath)
             {
                 // Not nice to throw an error now. Error was originally thrown by new Path(...);
                 throw new InvalidDataException("Not a player path");
             }
         }
         catch
         {
             Name = "<" + catalog.GetString("load error:") + " " + System.IO.Path.GetFileNameWithoutExtension(filePath) + ">";
         }
         if (!showInList)
         {
             throw new InvalidDataException(catalog.GetStringFmt("Activity '{0}' is excluded.", filePath));
         }
         if (string.IsNullOrEmpty(Name))
         {
             Name = "<" + catalog.GetString("unnamed:") + " " + System.IO.Path.GetFileNameWithoutExtension(filePath) + ">";
         }
         if (string.IsNullOrEmpty(Description))
         {
             Description = null;
         }
         if (string.IsNullOrEmpty(Briefing))
         {
             Briefing = null;
         }
     }
     else
     {
         Name = "<" + catalog.GetString("missing:") + " " + System.IO.Path.GetFileNameWithoutExtension(filePath) + ">";
     }
     FilePath = filePath;
 }
Esempio n. 8
0
            public string[] ToInfo()
            {
                //string[] infoString = new string[] {
                //    Catalog.GetStringFmt("Start time: {0}", StartTime),
                //};

                //return (infoString);
                if (string.IsNullOrEmpty(Briefing))
                {
                    return new[] { Catalog.GetStringFmt("Start time: {0}", StartTime) }
                }
                ;
                else
                {
                    return new[] { Catalog.GetStringFmt("Start time: {0}", StartTime), "", Briefing }
                };
            }
        }
Esempio n. 9
0
        internal Locomotive(string filePath)
        {
            if (filePath == null)
            {
                Name = catalog.GetString("- Any Locomotive -");
            }
            else if (File.Exists(filePath))
            {
                EngineFile engFile;
                try
                {
                    engFile = new EngineFile(filePath);
                }
                catch
                {
                    Name    = $"<{catalog.GetString("load error:")} {System.IO.Path.GetFileNameWithoutExtension(filePath)}>";
                    engFile = null;
                }
                if (engFile != null)
                {
                    bool showInList = !string.IsNullOrEmpty(engFile.CabViewFile);
                    if (!showInList)
                    {
                        throw new InvalidDataException(catalog.GetStringFmt("Locomotive '{0}' is excluded.", filePath));
                    }

                    string name = (engFile.Name ?? "").Trim();
                    Name = name != "" ? name : $"<{catalog.GetString("unnamed:")} {System.IO.Path.GetFileNameWithoutExtension(filePath)}>";

                    string description = (engFile.Description ?? "").Trim();
                    if (description != "")
                    {
                        Description = description;
                    }
                }
            }
            else
            {
                Name = $"<{catalog.GetString("missing:")} {System.IO.Path.GetFileNameWithoutExtension(filePath)}>";
            }
            FilePath = filePath;
        }
Esempio n. 10
0
 internal Locomotive(string filePath)
 {
     if (filePath == null)
     {
         Name = catalog.GetString("- Any Locomotive -");
     }
     else if (File.Exists(filePath))
     {
         var showInList = true;
         try
         {
             var engFile = new EngineFile(filePath);
             showInList  = !string.IsNullOrEmpty(engFile.CabViewFile);
             Name        = engFile.Name.Trim();
             Description = engFile.Description.Trim();
         }
         catch
         {
             Name = "<" + catalog.GetString("load error:") + " " + System.IO.Path.GetFileNameWithoutExtension(filePath) + ">";
         }
         if (!showInList)
         {
             throw new InvalidDataException(catalog.GetStringFmt("Locomotive '{0}' is excluded.", filePath));
         }
         if (string.IsNullOrEmpty(Name))
         {
             Name = "<" + catalog.GetString("unnamed:") + " " + System.IO.Path.GetFileNameWithoutExtension(filePath) + ">";
         }
         if (string.IsNullOrEmpty(Description))
         {
             Description = null;
         }
     }
     else
     {
         Name = "<" + catalog.GetString("missing:") + " " + System.IO.Path.GetFileNameWithoutExtension(filePath) + ">";
     }
     FilePath = filePath;
 }
Esempio n. 11
0
        public string CheckForErrors(byte[] buttonSettings)
        {
            StringBuilder errors = new StringBuilder();

            var duplicates = buttonSettings.Where(button => button < 255).
                             Select((value, index) => new { Index = index, Button = value }).
                             GroupBy(g => g.Button).
                             Where(g => g.Count() > 1).
                             OrderBy(g => g.Key);

            foreach (var duplicate in duplicates)
            {
                errors.Append(catalog.GetStringFmt("Button {0} is assigned to \r\n\t", duplicate.Key));
                foreach (var buttonMapping in duplicate)
                {
                    errors.Append($"\"{catalog.GetString(((UserCommand)buttonMapping.Index).GetDescription())}\" and ");
                }
                errors.Remove(errors.Length - 5, 5);
                errors.AppendLine();
            }
            return(errors.ToString());
        }
Esempio n. 12
0
 private void numericUpDownFOV_ValueChanged(object sender, EventArgs e)
 {
     labelFOVHelp.Text = catalog.GetStringFmt("{0:F0}° vertical FOV is the same as:\n{1:F0}° horizontal FOV on 4:3\n{2:F0}° horizontal FOV on 16:9", numericViewingFOV.Value, numericViewingFOV.Value * 4 / 3, numericViewingFOV.Value * 16 / 9);
 }
Esempio n. 13
0
        private void SetTexts()
        {
            GettextResourceManager catalog = new GettextResourceManager(PathResolver.Default);
            // If satellite assemblies have another base name use GettextResourceManager("Examples.HelloForms.Messages") constructor
            // If you call from another assembly, use GettextResourceManager(anotherAssembly) constructor
            Localizer.Localize(this, catalog, store);
            // We need pass 'store' argument only to be able revert original text and switch languages on fly
            // Common use case doesn't required it: Localizer.Localize(this, catalog);

            // Manually formatted strings
            label2.Text = catalog.GetStringFmt("This program is running as process number \"{0}\".",
                                               System.Diagnostics.Process.GetCurrentProcess().Id);
            label3.Text = String.Format(
                catalog.GetPluralString("found {0} similar word", "found {0} similar words", 1),
                1);
            label4.Text = String.Format(
                catalog.GetPluralString("found {0} similar word", "found {0} similar words", 2),
                2);
            label5.Text = String.Format(
                catalog.GetPluralString("found {0} similar word", "found {0} similar words", 5),
                5);
            label6.Text = String.Format("{0} ('computers')",  catalog.GetParticularString("Computers", "Text encoding"));
            label7.Text = String.Format("{0} ('military')",  catalog.GetParticularString("Military", "Text encoding"));
            label8.Text = String.Format("{0} (non contextual)",  catalog.GetString("Text encoding"));
        }
Esempio n. 14
0
        public string CheckForErrors()
        {
            // Make sure all modifiable input commands are synchronized first.
            foreach (var command in Commands)
            {
                (command as UserCommandModifiableKeyInput)?.SynchronizeCombine();
            }

            StringBuilder errors = new StringBuilder();

            // Check for commands which both require a particular modifier, and ignore it.
            foreach (var command in EnumExtension.GetValues <UserCommand>())
            {
                if (Commands[(int)command] is UserCommandModifiableKeyInput modInput)
                {
                    if (modInput.Shift && modInput.IgnoreShift)
                    {
                        errors.AppendLine(settingsCatalog.GetStringFmt("{0} requires and is modified by Shift", commonCatalog.GetString(command.GetDescription())));
                    }
                    if (modInput.Control && modInput.IgnoreControl)
                    {
                        errors.AppendLine(settingsCatalog.GetStringFmt("{0} requires and is modified by Control", commonCatalog.GetString(command.GetDescription())));
                    }
                    if (modInput.Alt && modInput.IgnoreAlt)
                    {
                        errors.AppendLine(settingsCatalog.GetStringFmt("{0} requires and is modified by Alt", commonCatalog.GetString(command.GetDescription())));
                    }
                }
            }

            // Check for two commands assigned to the same key
            UserCommand firstCommand = EnumExtension.GetValues <UserCommand>().Min();
            UserCommand lastCommand  = EnumExtension.GetValues <UserCommand>().Max();

            for (UserCommand command1 = firstCommand; command1 <= lastCommand; command1++)
            {
                var input1 = Commands[(int)command1];

                // Modifier inputs don't matter as they don't represent any key.
                if (input1 is UserCommandModifierInput)
                {
                    continue;
                }

                for (var command2 = command1 + 1; command2 <= lastCommand; command2++)
                {
                    var input2 = Commands[(int)command2];

                    // Modifier inputs don't matter as they don't represent any key.
                    if (input2 is UserCommandModifierInput)
                    {
                        continue;
                    }

                    // Ignore problems when both inputs are on defaults. (This protects the user somewhat but leaves developers in the dark.)
                    //if (input1.PersistentDescriptor == InputSettings.DefaultCommands[(int)command1].PersistentDescriptor && input2.PersistentDescriptor == InputSettings.DefaultCommands[(int)command2].PersistentDescriptor)
                    if (input1.UniqueDescriptor == DefaultCommands[(int)command1].UniqueDescriptor &&
                        input2.UniqueDescriptor == DefaultCommands[(int)command2].UniqueDescriptor)
                    {
                        continue;
                    }

                    var unique1      = input1.GetUniqueInputs();
                    var unique2      = input2.GetUniqueInputs();
                    var sharedUnique = unique1.Where(id => unique2.Contains(id));
                    foreach (var uniqueInput in sharedUnique)
                    {
                        errors.AppendLine(settingsCatalog.GetStringFmt("{0} and {1} both match {2}", commonCatalog.GetString(command1.GetDescription()),
                                                                       commonCatalog.GetString(command2.GetDescription()), KeyboardMap.GetPrettyUniqueInput(uniqueInput)));
                    }
                }
            }

            return(errors.ToString());
        }
Esempio n. 15
0
        void LoadSaves()
        {
            if (SaveLoader != null)
            {
                SaveLoader.Cancel();
            }

            var warning = "";

            SaveLoader = new Task <List <Save> >(this, () =>
            {
                var saves     = new List <Save>();
                var directory = UserSettings.UserDataFolder;
                var build     = VersionInfo.Build.Contains(" ") ? VersionInfo.Build.Substring(VersionInfo.Build.IndexOf(" ") + 1) : null;
                var prefix    = String.Empty;

                if (SelectedAction == MainForm.UserAction.SinglePlayerTimetableGame)
                {
                    prefix = Path.GetFileName(Route.Path) + " " + Path.GetFileNameWithoutExtension(Timetable.fileName);
                }
                else if (Activity.FilePath != null)
                {
                    prefix = Path.GetFileNameWithoutExtension(Activity.FilePath);
                }
                else if (Activity.Name == "- " + catalog.GetString("Explore Route") + " -")
                {
                    prefix = Path.GetFileName(Route.Path);
                }
                // Explore in activity mode
                else
                {
                    prefix = "ea$" + Path.GetFileName(Route.Path) + "$";
                }


                if (Directory.Exists(directory))
                {
                    foreach (var saveFile in Directory.GetFiles(directory, prefix + "*.save"))
                    {
                        try
                        {
                            // SavePacks are all in the same folder and activities may have the same name
                            // (e.g. Short Passenger Run shrtpass.act) but belong to a different route,
                            // so pick only the activities for the current route.
                            var save = new Save(saveFile, build, Settings.YoungestFailedToRestore);
                            if (save.RouteName == Route.Name)
                            {
                                if (!save.IsMultiplayer ^ Multiplayer)
                                {
                                    saves.Add(save);
                                }
                            }
                            else    // In case you receive a SavePack where the activity is recognised but the route has been renamed.
                                    // Checks the route is not in your list of routes.
                                    // If so, add it with a warning.
                            {
                                if (!MainForm.Routes.Any(el => el.Name == save.RouteName))
                                {
                                    if (!save.IsMultiplayer ^ Multiplayer)
                                    {
                                        saves.Add(save);
                                    }
                                    // Save a warning to show later.
                                    warning += catalog.GetStringFmt("Warning: Save {0} found from a route with an unexpected name:\n{1}.\n\n", save.RealTime, save.RouteName);
                                }
                            }
                        }
                        catch { }
                    }
                }
                return(saves.OrderBy(s => s.RealTime).Reverse().ToList());
            }, (saves) =>
            {
                Saves = saves;
                saveBindingSource.DataSource = Saves;
                labelInvalidSaves.Text       = catalog.GetString(
                    "To prevent crashes and unexpected behaviour, Open Rails invalidates games saved from older versions if they fail to restore.\n") +
                                               catalog.GetStringFmt("{0} of {1} saves for this route are no longer valid.", Saves.Count(s => (s.Valid == false)), Saves.Count);
                gridSaves_SelectionChanged(null, null);
                // Show warning after the list has been updated as this is more useful.
                if (warning != "")
                {
                    MessageBox.Show(warning, Application.ProductName + " " + VersionInfo.VersionOrBuild);
                }
            });
        }
Esempio n. 16
0
 public string GetStringFmt(string msg, params object[] args)
 {
     return(Cat.GetStringFmt(msg, args));
 }