/** \brief Retrieves the path and filename of the settings file to use *** \return A string with the settings filename, or an empty string if the settings file could not be found **/ static const std::string _SetupSettingsFilename() { std::string settings_file = GetUserConfigPath() + "settings.lua"; if(!DoesFileExist(settings_file)) { #ifdef __APPLE__ settings_file = "../Resources/data/config/settings.lua"; #else settings_file = "data/config/settings.lua"; #endif if(!DoesFileExist(settings_file)) PRINT_WARNING << "settings.lua file not found." << std::endl; } return settings_file; }
BOOL SaveFakeRegistry(void) { FILE *f_ptr; FakeRegistry *registry_ptr = reg_head_ptr; /* Set file path, if fail cannot continue. */ if ( GetUserConfigPath(reg_file, FR_FILENAME_LEN) == NULL) return FALSE; /* Append filename of registry to path. */ strcat(reg_file, REG_FILENAME); /* Save the fake registry to disc. */ if ( (f_ptr=fopen(reg_file, "w")) != NULL){ fprintf(f_ptr, "# Beebem configuration file.\n"); fprintf(f_ptr, "#\n"); fprintf(f_ptr, "# This is a fake windows registry." " Edit this at your own risk!\n"); fprintf(f_ptr, "# (TIP: Deleted rows will be recreated next" " time you save config.)\n"); while( registry_ptr != NULL){ fprintf(f_ptr, "%s=%s\n", registry_ptr->key_ptr , registry_ptr->value_ptr); registry_ptr = registry_ptr->next_ptr; } fclose(f_ptr); }else{ fprintf(stderr, "Could not save configuration [%s]!\n" , reg_file); } return TRUE; }
/* Initialize the fake registry. */ void InitializeFakeRegistry(void) { /* There must be a better way of doing this: */ char row[10*1024], key[10*1024], value[10*1024]; FILE *f_ptr; int i; /* Initialize fake registry linked list. */ reg_head_ptr = reg_tail_ptr = NULL; /* Load a previously saved fake registry (if this fails we assume one * does not yet exist and leave creating one up to the save function). */ if ( GetUserConfigPath(reg_file, FR_FILENAME_LEN) == NULL) return; /* Append filename of registry to path. */ strcat(reg_file, REG_FILENAME); /* Test file, quit if does not exist (first time beebem ran so * no entries). */ if ( (f_ptr=fopen(reg_file, "r")) == NULL) return; /* Load existing registry */ while (fgets( row, 256, f_ptr ) != NULL){ i = strlen(row) -1; while(i>=0){ if (row[i]<32) row[i] = '\0'; i--; } if (strlen(row)<=0) continue; if (row[0] == '#') continue; for(i=0; i< (int) strlen(row); i++) if (row[i] == '#'){ row[i]='\0'; break; } i = strlen(row) -1; while(i>=0){ if (row[i] == '=') break; i--; } if (i<=0) continue; memcpy(key, row, i); key[i]='\0'; value[0] = '\0'; if(strlen(row)-i-1>0){ memcpy(value, row+i+1, strlen(row)-i-1); value[strlen(row)-i-1] = '\0'; } i = strlen(value) -1; while(value[i]<=32 && i>=0){ value[i] = '\0'; i--; } if (SetFakeRegistryItem(key, value) != TRUE) pERROR(dL"Failed to add '%s' to the registry!\n", dR , key); } fclose(f_ptr); }