Elvas Tower: Generate the INI file from the Registry - Elvas Tower

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Generate the INI file from the Registry Proposal for a tool to create an INI file matching the Registry Rate Topic: -----

#1 User is offline   C44-9W 

  • Apprentice
  • Group: Posts: Active Member
  • Posts: 25
  • Joined: 18-March 23
  • Gender:Male
  • Simulator:Openrails
  • Country:

Posted 29 November 2024 - 04:37 PM

I recently learned that user settings can also be stored in an OpenRails.ini file. This allows different instances of OpenRails to use different settings. By default, the settings are in the Windows Registry, and the same settings are used by all OpenRails installation instances.

There currently is no method to create an INI file with the same values as are in the registry. The method to use an INI file is to manually create the INI file. OpenRails then sees the INI file and attempts to read settings from there. If a setting is not there (or invalid), OpenRails uses the default value.

First Question: Do many people use the INI file? Is it worth the effort to build a tool that allows the current settings to be copied from the registry to the INI file?

Now to the techical implications. The settings are handled by the ORTS.Settings.UserSettings class. The challenges are:
  • The source/destination of the settings, registry or INI file, is defined in static variables, and determined in a static constructor. Although there can be two instances of settings, both will use the same source/destination.
  • The member variables that hold the source/destination are readonly. It is not possible to change the source/destination after the settings are loaded.
  • The settings store is created in the SettingsBase class, having its own access protection.

    public class UserSettings : SettingsBase
    {
        public static readonly string RegistryKey;        // ie @"SOFTWARE\OpenRails\ORTS"
        public static readonly string SettingsFilePath;   // ie @"C:\Program Files\Open Rails\OpenRails.ini"
        public static readonly string UserDataFolder; 	// ie @"C:\Users\Wayne\AppData\Roaming\Open Rails"
        public static readonly string DeletedSaveFolder;  // ie @"C:\Users\Wayne\AppData\Roaming\Open Rails\Deleted Saves"
        public static readonly string SavePackFolder; 	// ie @"C:\Users\Wayne\AppData\Roaming\Open Rails\Save Packs"

        static UserSettings()
        {
            // Only one of these is allowed; if the INI file exists, we use that, otherwise we use the registry.
            RegistryKey = "SOFTWARE\\OpenRails\\ORTS";
            SettingsFilePath = Path.Combine(ApplicationInfo.ProcessDirectory, "OpenRails.ini");
            if (File.Exists(SettingsFilePath))
                RegistryKey = null;
            else
                SettingsFilePath = null;

            UserDataFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), ApplicationInfo.ProductName);
            // TODO: If using INI file, move these to application directory as well.
            if (!Directory.Exists(UserDataFolder)) Directory.CreateDirectory(UserDataFolder);
            DeletedSaveFolder = Path.Combine(UserDataFolder, "Deleted Saves");
            SavePackFolder = Path.Combine(UserDataFolder, "Save Packs");
        }



Options are:
  • Allow the UserSetting to switch the SettingsStore, or have two SettingsStore. Neither is easy while preserving access controls and avoiding external impact.
  • Make RegistryKey and SettingsFilePath part of the object, and create two UserSettings instances. This requires a copy constructor.

I tried a simple tool that uses nativ methods to read all registry entries, and the UserSettings class to write to the INI file. But this did not handle all types of settings.

Finally, would it make sense to have a stand-alone tool (which possibly allows export in both directions), or to make it part of the SettingsStore (when it sees an empty INI file, do an export).

Thanks for any feedback you have.

#2 User is offline   Weter 

  • Member, Board of Directors
  • PipPipPipPipPipPipPipPipPipPip
  • Group: ET Admin
  • Posts: 7,827
  • Joined: 01-June 20
  • Gender:Not Telling
  • Simulator:ORTS
  • Country:

Posted 29 November 2024 - 04:46 PM

Hello.
If I misunderstood, please excuse me, but it was told some times here and there: Just creating empty *.ini-file in given ORTS program directory will lead to population of the file with all needed parameters, during next game session launching. Since next time, settings from created *.ini-file will be used for this instance of ORTS only, overriding ones from windows registry.

#3 User is offline   engmod 

  • Open Rails Developer
  • PipPipPipPipPipPipPip
  • Group: ET Admin
  • Posts: 1,961
  • Joined: 26-February 08
  • Gender:Male
  • Location:Eltham, Victoria, Australia
  • Simulator:ORNYMG
  • Country:

Posted 29 November 2024 - 04:47 PM

>There currently is no method to create an INI file with the same values as are in the registry.

Yes there is, create an empty openrails.ini file in the directory, load OR, unload OR, ini file saved.

#4 User is offline   C44-9W 

  • Apprentice
  • Group: Posts: Active Member
  • Posts: 25
  • Joined: 18-March 23
  • Gender:Male
  • Simulator:Openrails
  • Country:

Posted 29 November 2024 - 06:47 PM

Weter and engmod: The INI file created has default values for all settings, not the values from the registry. For example, it will not have routes that were in your Content folder.

#5 User is offline   Weter 

  • Member, Board of Directors
  • PipPipPipPipPipPipPipPipPipPip
  • Group: ET Admin
  • Posts: 7,827
  • Joined: 01-June 20
  • Gender:Not Telling
  • Simulator:ORTS
  • Country:

Posted 29 November 2024 - 06:50 PM

Quote

The INI file created has default values for all settings

Are You sure? I didn't know, sorry.

#6 User is offline   cjakeman 

  • Vice President
  • PipPipPipPipPipPipPipPip
  • Group: ET Admin
  • Posts: 2,963
  • Joined: 03-May 11
  • Gender:Male
  • Location:Peterborough, UK
  • Simulator:Open Rails
  • Country:

Posted 30 November 2024 - 05:57 AM

View PostC44-9W, on 29 November 2024 - 06:47 PM, said:

Weter and engmod: The INI file created has default values for all settings, not the values from the registry. For example, it will not have routes that were in your Content folder.

I don't think any of this is included in the Manual, which is a shame.

I hope it's OK to discuss it at today's session of the Open Rails Management Team (ORMT). Perhaps there is a worthwhile project here.

#7 User is offline   Siebren 

  • Fireman
  • Group: Posts: Active Member
  • Posts: 119
  • Joined: 16-November 22
  • Gender:Not Telling
  • Location:Ede, the Netherlands
  • Simulator:open rails
  • Country:

Posted 30 November 2024 - 06:43 AM

I use the .ini file in all my OR installations. That way it's automatically backupped. Some time ago I had to reinstall windows and restore the OR installations from backup. Registry of course a clean one without OR data. Had to rebuild it.

One .ini file, in the rest of the environments a simlink to this file (yes, Windows does support that also). So I do not need such a tool, but others might find it handy.

#8 User is offline   engmod 

  • Open Rails Developer
  • PipPipPipPipPipPipPip
  • Group: ET Admin
  • Posts: 1,961
  • Joined: 26-February 08
  • Gender:Male
  • Location:Eltham, Victoria, Australia
  • Simulator:ORNYMG
  • Country:

Posted 30 November 2024 - 10:48 AM

I have 4 installations here and have used ini files when I set them up.
They have different settings depending what I am testing for.

#9 User is offline   R H Steele 

  • Executive Vice President
  • PipPipPipPipPipPipPipPipPip
  • Group: ET Admin
  • Posts: 3,540
  • Joined: 14-March 13
  • Gender:Male
  • Location:known universe
  • Simulator:Open Rails
  • Country:

Posted 01 December 2024 - 08:25 AM

View Postcjakeman, on 30 November 2024 - 05:57 AM, said:

I don't think any of this is included in the Manual, which is a shame.


This should be in the manual, I learned about the ini file from reading the forum and from Derek (engmod ) --- I also use different ini files for different versions.

#10 User is offline   cjakeman 

  • Vice President
  • PipPipPipPipPipPipPipPip
  • Group: ET Admin
  • Posts: 2,963
  • Joined: 03-May 11
  • Gender:Male
  • Location:Peterborough, UK
  • Simulator:Open Rails
  • Country:

Posted 01 December 2024 - 08:52 AM

View PostR H Steele, on 01 December 2024 - 08:25 AM, said:

This should be in the manual.

Agree. I will add it.

The intention for the INI file was to allow a different set of settings to be used temporarily without disturbing the settings in the registry. As engmod has written, this allows Stable, Testing, Unstable and ORNYMG to have different settings.

It is interesting to read that Siebren is using INI for the inverse behaviour, using simlinks to share a common INI file among all the versions and so not relying on the registry.

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users