1. Hey! Guest! The 36th GMC Jam will take place between February 27th, 12:00 UTC - March 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice

GML Can I read from an ini_file without knowing the keys?

Discussion in 'Programming' started by zpinn, Feb 8, 2018.

  1. zpinn

    zpinn Guest

    So I've made this whole system for encrypting values as well as the keys, just to make it harder for anyone to know what they are changing if they would open the text files. But only now as I implemented it did I realise that ini_read needs a key to read a value, and if that key is encrypted it could be anything.

    Is there any way to read keys and values from an ini file without knowing the keys and without having to guess them by going through the whole alphabet 30 times?
     
  2. Sidorakh

    Sidorakh Member

    Joined:
    Oct 17, 2016
    Posts:
    7
    Unfortunately not, there is no function that lists all the sections and keys in an INI file. One thing you can do is, open the file using the file functions, and list the sections based off of that. Here's some code that should point you in the right direction
    Code:
    var _file = file_text_open_read(filename);
    if (_file == -1) {
        error
    }
    while (!file_text_eof(file)) {
        var _str = file_text_read_string(file);
        if (string_pos("]",_str)) {
            it's a section!
        }
        else {
            it's a key!
        }
        file_text_readln(file);
    }
    
    It's incomplete because I don't have the time to finish it up properly, but it should give you the right idea. To get the section name, strip the '[' and ']' out, for a key, strip everything from the '=' onwards.
     

Share This Page