Beispiel #1
0
        public virtual void Save(SettingsContainer settings)
        {
            if (!Directory.Exists(SETTINGS_DIR))
            {
                Directory.CreateDirectory(SETTINGS_DIR);
            }

            if (File.Exists($"{SETTINGS_DIR}\\{SETTINGS_NAME}.{SETTINGS_EXT}"))
            {
                File.Delete($"{SETTINGS_DIR}\\{SETTINGS_NAME}.{SETTINGS_EXT}");
            }

            using (var io = File.Open($"{SETTINGS_DIR}\\{SETTINGS_NAME}.{SETTINGS_EXT}", FileMode.OpenOrCreate))
            {
                foreach (var opt in settings.GetOptions())
                {
                    byte[] tmp = Encoding.UTF8.GetBytes($"{opt.Key}#{opt.Value}{Environment.NewLine}");
                    io.WriteAsync(tmp, 0, tmp.Length).Wait();
                }
            }
        }