config.vala
changeset 6 0d97b0d61ed2
parent 1 76caf6a3f413
equal deleted inserted replaced
5:9574ebf72d81 6:0d97b0d61ed2
     5     }
     5     }
     6     public Config.from_file(string filename) {
     6     public Config.from_file(string filename) {
     7         base();
     7         base();
     8         hash = new Gee.HashMap<string,string>();
     8         hash = new Gee.HashMap<string,string>();
     9         IOChannel cfg;
     9         IOChannel cfg;
    10         /* try { */
    10         try {
    11             cfg = new IOChannel.file(filename,"r");
    11             cfg = new IOChannel.file(filename,"r");
    12         /*} catch (FileError e) {
    12         } catch (FileError e) {
    13             File.new_for_path(filename);*/
    13             log("config", LogLevelFlags.LEVEL_ERROR, "Failed to load config file '%s'", filename);
       
    14             return;
       
    15         }
    14         string section = "default";
    16         string section = "default";
    15         do {
    17         do {
    16             string str;
    18             string str;
    17             size_t length, termpos;
    19             size_t length, termpos;
    18             IOStatus stat = cfg.read_line(out str,out length,out termpos);
    20             IOStatus stat = cfg.read_line(out str,out length,out termpos);
    19             if (stat == IOStatus.NORMAL) {
    21             if (stat == IOStatus.NORMAL) {
    20                 str = str[0:(long)termpos];
    22                 str = str[0:(long)termpos];
    21                 if ( str.has_prefix("[") && str.has_suffix("]") ) {
    23                 if ( str.has_prefix("[") && str.has_suffix("]") ) {
    22                     section = str[1:-1];
    24                     section = str[1:-1];
    23                     stdout.printf("Section '%s'\n",section);
       
    24                 } else {
    25                 } else {
    25                     string[] parts = str.split("=",2);
    26                     string[] parts = str.split("=",2);
    26                     if (parts.length==2) {
    27                     if (parts.length==2) {
    27                         var nkey = rkey(section,parts[0]);
    28                         var nkey = rkey(section,parts[0]);
    28                         hash[nkey] = parts[1];
    29                         hash[nkey] = parts[1];
    29                         stdout.printf("LOL: key: %s value: %s\n",nkey,parts[1]);
       
    30                     }
    30                     }
    31                 }
    31                 }
    32             } else
    32             } else
    33                 break;
    33                 break;
    34         } while (true);
    34         } while (true);