Add config file
This commit is contained in:
		
							
								
								
									
										37
									
								
								Elwig/Helpers/Config.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								Elwig/Helpers/Config.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,37 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using IniParser;
 | 
			
		||||
using IniParser.Model;
 | 
			
		||||
 | 
			
		||||
namespace Elwig.Helpers {
 | 
			
		||||
    public class Config {
 | 
			
		||||
 | 
			
		||||
        private readonly string FileName;
 | 
			
		||||
        public string DatabasePath;
 | 
			
		||||
 | 
			
		||||
        public Config(string filename) {
 | 
			
		||||
            FileName = filename;
 | 
			
		||||
            Read();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void Read() {
 | 
			
		||||
            var parser = new FileIniDataParser();
 | 
			
		||||
            IniData? ini = null;
 | 
			
		||||
            try {
 | 
			
		||||
                ini = parser.ReadFile(FileName, Encoding.UTF8);
 | 
			
		||||
            } catch {}
 | 
			
		||||
 | 
			
		||||
            if (ini == null || !ini.TryGetKey("database.path", out string db)) {
 | 
			
		||||
                DatabasePath = App.DataPath + "database.sqlite3";
 | 
			
		||||
            } else if (db.Length > 1 && db[1] == ':') {
 | 
			
		||||
                DatabasePath = db;
 | 
			
		||||
            } else {
 | 
			
		||||
                DatabasePath = App.DataPath + db;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void Write() {
 | 
			
		||||
            throw new NotImplementedException();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user