Skip to content
View in the app

A better way to browse. Learn more.

LCPDFR.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Problems with ini file

Featured Replies

So I am making a plugin but when I try to load my INI file it just says that the object isn't set.

internal static class Settings
{
  public static Keys OpenMenuKey = Keys.U;
  public static Keys ModOpenMenuKey = Keys.None;
  static KeysConverter kc = new KeysConverter();

  public static void Load()
  {
    Common.Log("Loading config.");
    Common.Log(GetIniString("Keybindings", "MenuKey"));
    Common.Log(GetIniString("Keybindings", "MenuKeyModifier"));
    OpenMenuKey = (Keys)kc.ConvertFromString(GetIniString("Keybindings", "MenuKey", "U"));
    ModOpenMenuKey = (Keys)kc.ConvertFromString(GetIniString("Keybindings", "MenuKeyModifier", "None"));
  }

  private static InitializationFile initialiseFile()
  {
    InitializationFile ini = new InitializationFile(@"Plugins\LSPDFR\LevelSystem.ini");
    ini.Create();
    return ini;
  }

  private static string GetIniString(string section, string key, string defaultVal = "")
  {
    if (initialiseFile().Exists() && ValidateIni(section, key))
    {
      return initialiseFile().ReadString(section, key, defaultVal);
    }
    else
    {
      Common.Log("Ini file doesn't exist.");
      Game.DisplayNotification("mprpsymbol", "rp", "~b~LSPDFR Level System", "~r~Ini file error", $"Ini File doesnt exist!");
      return defaultVal;
    }
  }

  private static bool ValidateIni(string section, string key)
  {
    return initialiseFile().DoesSectionExist(section) && initialiseFile().DoesKeyExist(section, key);
  }
}

Also my Common Logs are empty where I request the value. Am I doing something wrong?

Also the "initialiseFile().Exists()" returns true but the "ValidateIni()" returns false

 

The INI I'm using:

[Keybindings]

MenuKey = U
MenuKeyModifier = None

 

Edited by AlwayzPatty

AlwayzPatty (Patrick)

Founder Overpunch Studios

 

The sun is always shining :)

  • Management Team

It looks to me like you are creating the same ini file over and over again. You should initialize it once and then always use that instance. I'd suggest making a (static) variable such as "InitializationFile myIni" and in "initialiseFile" check if it is null. If so, you initialize it once. If it is not null, you return it instead.

Please do not PM me unless really necessary (knowing you helps). If you think you need my attention in a topic, tag me.

  • Author

The new code:

internal static class Settings
    {
        private static InitializationFile iniFile;

        #region User Settings
            public static Keys OpenMenuKey = Keys.U;
            public static Keys ModOpenMenuKey = Keys.None;
        #endregion

        #region System Settings
            public static float PercentageIncrementExpNeeded = .35f;
        #endregion

        static KeysConverter kc = new KeysConverter();

        public static void Load()
        {
            Common.Log("Loading config.");
            Common.Log(GetIniString("Keybindings", "MenuKey"));
            Common.Log(GetIniString("Keybindings", "MenuKeyModifier"));
            OpenMenuKey = (Keys)kc.ConvertFromString(GetIniString("Keybindings", "MenuKey", "U"));
            ModOpenMenuKey = (Keys)kc.ConvertFromString(GetIniString("Keybindings", "MenuKeyModifier", "None"));
        }

        private static InitializationFile initialiseFile()
        {
            if (iniFile != null && iniFile.Exists())
                return iniFile;

            iniFile = new InitializationFile(@"Plugins\LSPDFR\LevelSystem.ini");
            iniFile.Create();
            if (iniFile.Exists())
                return iniFile;
            else
                throw new Exception("Ini doesn't exist.");
        }

        private static string GetIniString(string section, string key, string defaultVal = "")
        {
            try
            {
                Common.Log($"[Requesting INI String] Section: {section}, Key: {key}, FileLocation: {initialiseFile().FileName}, IniValidation: {ValidateIni(section, key).ToString()}");
                if (ValidateIni(section, key))
                {
                    return initialiseFile().ReadString(section, key, defaultVal);
                }
                else
                {
                    Common.Log("Ini file doesn't exist.");
                    Game.DisplayNotification("mprpsymbol", "rp", "~b~LSPDFR Level System", "~r~Ini file error", $"Ini File doesnt exist!");
                    return defaultVal;
                }
            }
            catch(Exception e)
            {
                Common.Log($"[ERROR] {e.Message}");
                return defaultVal;
            }
        }

        private static bool ValidateIni(string section, string key)
        {
            return initialiseFile().DoesSectionExist(section) && initialiseFile().DoesKeyExist(section, key);
        }
    }

This results to this being said in the logs:

image.thumb.png.ce3ba3cc2d04a8bd4cf8ca93eb99450f.png

 

So your solution doesn't work.

I will try some stuff today myself and you will hear from me if I found the solution.

 

AlwayzPatty (Patrick)

Founder Overpunch Studios

 

The sun is always shining :)

  • Author

Fixed the issue it was apperantly an encoding issue that was already mentioned as a bug to RPH.
 

Thanks to PNWParksFan

Quote

just discovered a very interesting bug in InitializationFile

if the file format is UTF-8 with BOM, and your first INI section starts on line 0, then it won't parse it as a section correctly

and it seems that UTF-8 with BOM is the default encoding when you create a new empty data file using VS

if I change it to regular UTF-8 encoding, or add a blank line at the beginning of the file, the problem goes away

 

Edited by AlwayzPatty
added solution

AlwayzPatty (Patrick)

Founder Overpunch Studios

 

The sun is always shining :)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.