Example #1
0
        public static void LoadXmlConfig()
        {
            if (!File.Exists(Properties.Settings.Default.configFileName))
            {
                CreateFile();
                return;
            }

            CFormat.Print("Chargement du fichier de configuration.", "XmlManager", DateTime.Now, ConsoleColor.Yellow);
            FileStream reader = new FileStream(Properties.Settings.Default.configFileName, FileMode.OpenOrCreate, FileAccess.Read, FileShare.Read);

            try
            {
                Config._INSTANCE = (Config)_Serializer.ReadObject(reader);

                reader.Close();
            }
            catch (Exception ex)
            {
                reader.Close();

                CFormat.Print("Erreur lors de la lecture du fichier de configuration. Détails : " + ex.Message, "XmlManager", DateTime.Now, ConsoleColor.Yellow);
                CreateFile(); // force file creation
            }
        }
Example #2
0
        public static void SaveXmlConfig()
        {
            CFormat.Print("Sauvegarde du fichier de configuration.", "XmlManager", DateTime.Now, ConsoleColor.Yellow);

            StreamWriter sr     = new StreamWriter(Properties.Settings.Default.configFileName, false);
            XmlWriter    writer = XmlWriter.Create(sr, _settings);

            _Serializer.WriteObject(writer, Config._INSTANCE);

            writer.Flush();
            sr.Flush();
            writer.Close();
            sr.Close();
        }
Example #3
0
 private static void CreateFile()
 {
     try
     {
         CFormat.Print("Création d'un nouveau fichier de configuration.", "XmlManager", DateTime.Now, ConsoleColor.Yellow);
         Config._INSTANCE.ResetDefault();
         SaveXmlConfig();
         return;
     }
     catch (Exception ex)
     {
         CFormat.Print("Impossible de créer un fichier de configuration. Détails : " + ex.Message, "XmlManager", DateTime.Now, ConsoleColor.Yellow);
         CFormat.Write("Appuyez sur une touche pour quitter l'application...");
         Console.ReadKey(true);
         Environment.Exit(0);
     }
 }
Example #4
0
        /// <summary>
        /// /!\ WARNING /!\ NEVER USE UNLESS FILE CREATION
        /// </summary>
        public void ResetDefault()
        {
            CFormat.Print("Mise en place des paramètres par défaut.", "Config", DateTime.Now, ConsoleColor.Yellow);


            BotToken = (string)CInput.ReadFromConsole("BotToken=", ConsoleInputType.String, false, ConsoleColor.White);

            XanaId = (ulong)CInput.ReadFromConsole("XanaId=", ConsoleInputType.Ulong, false, ConsoleColor.White, 18);


            GuildConfigs = new Dictionary <ulong, GuildConfig>();

            TresorProbabilities = new Dictionary <int, int>()
            {
                { 1, 18 }, { 2, 16 }, { 3, 15 }, { 4, 13 }, { 5, 11 }, { 6, 9 }, { 7, 7 }, { 8, 5 }, { 9, 4 }, { 10, 2 }
            };

            XanaOAuth2URL = "";


            CFormat.Print("Paramètres appliqués.", "Config", DateTime.Now, ConsoleColor.Yellow);
        }
Example #5
0
 private static void _Serializer_UnknownAttribute(object sender, XmlAttributeEventArgs e)
 {
     CFormat.Print("Erreur lors de la lecture du fichier de configuration : attribut inconnu (nom : " + e.Attr.Name + ".",
                   "XmlManager", DateTime.Now, ConsoleColor.Red);
 }
Example #6
0
 private static void _Serializer_UnreferencedObject(object sender, UnreferencedObjectEventArgs e)
 {
     CFormat.Print("Erreur lors de la lecture du fichier de configuration : objet non référencé (détails : " + e.UnreferencedObject.ToString() + ".",
                   "XmlManager", DateTime.Now, ConsoleColor.Red);
 }