Ejemplo n.º 1
0
 public static void Save(ServerTransferTotal config)
 {
     try
     {
         using (StreamWriter sw = new StreamWriter(File.Open(LOG_FILE, FileMode.Create)))
         {
             string jsonString = SimpleJson.SimpleJson.SerializeObject(config.servers);
             if (GlobalConfiguration.config_password.Length > 0)
             {
                 IEncryptor encryptor   = EncryptorFactory.GetEncryptor("aes-256-cfb", GlobalConfiguration.config_password, false);
                 byte[]     cfg_data    = UTF8Encoding.UTF8.GetBytes(jsonString);
                 byte[]     cfg_encrypt = new byte[cfg_data.Length + 128];
                 int        data_len;
                 encryptor.Encrypt(cfg_data, cfg_data.Length, cfg_encrypt, out data_len);
                 jsonString = System.Convert.ToBase64String(cfg_encrypt, 0, data_len);
             }
             sw.Write(jsonString);
             sw.Flush();
         }
     }
     catch (IOException e)
     {
         Console.Error.WriteLine(e);
     }
 }
Ejemplo n.º 2
0
        public static ServerTransferTotal Load()
        {
            try
            {
                var config_str = File.ReadAllText(LOG_FILE);
                var config     = new ServerTransferTotal();
                try
                {
                    if (GlobalConfiguration.config_password.Length > 0)
                    {
                        using var encryptor = EncryptorFactory.GetEncryptor(@"aes-256-cfb", GlobalConfiguration.config_password);
                        config_str          = Encoding.UTF8.GetString(Utils.DecryptLargeBase64StringToBytes(encryptor, config_str));
                    }
                }
                catch
                {
                    // ignored
                }

                config.servers = JsonConvert.DeserializeObject <Dictionary <string, ServerTrans> >(config_str);
                config.Init();
                return(config);
            }
            catch (Exception e)
            {
                if (!(e is FileNotFoundException))
                {
                    Console.WriteLine(e);
                }
                return(new ServerTransferTotal());
            }
        }
Ejemplo n.º 3
0
 public static ServerTransferTotal Load()
 {
     try
     {
         string config_str          = File.ReadAllText(LOG_FILE);
         ServerTransferTotal config = new ServerTransferTotal();
         try
         {
             if (GlobalConfiguration.config_password.Length > 0)
             {
                 byte[]     cfg_encrypt = System.Convert.FromBase64String(config_str);
                 IEncryptor encryptor   = EncryptorFactory.GetEncryptor("aes-256-cfb", GlobalConfiguration.config_password, false);
                 byte[]     cfg_data    = new byte[cfg_encrypt.Length];
                 int        data_len;
                 encryptor.Decrypt(cfg_encrypt, cfg_encrypt.Length, cfg_data, out data_len);
                 config_str = UTF8Encoding.UTF8.GetString(cfg_data, 0, data_len);
             }
         }
         catch
         {
         }
         config.servers = SimpleJson.SimpleJson.DeserializeObject <Dictionary <string, object> >(config_str, new JsonSerializerStrategy());
         config.Init();
         return(config);
     }
     catch (Exception e)
     {
         if (!(e is FileNotFoundException))
         {
             Console.WriteLine(e);
         }
         return(new ServerTransferTotal());
     }
 }
Ejemplo n.º 4
0
        public static ServerTransferTotal Load()
        {
            try
            {
                var config_str = File.ReadAllText(LOG_FILE);
                var config     = new ServerTransferTotal();
                try
                {
                    if (GlobalConfiguration.config_password.Length > 0)
                    {
                        var cfgEncrypt = Convert.FromBase64String(config_str);
                        var encryptor  = EncryptorFactory.GetEncryptor("aes-256-cfb", GlobalConfiguration.config_password);
                        var cfgData    = new byte[cfgEncrypt.Length];
                        encryptor.Decrypt(cfgEncrypt, cfgEncrypt.Length, cfgData, out var data_len);
                        config_str = Encoding.UTF8.GetString(cfgData, 0, data_len);
                    }
                }
                catch
                {
                    // ignored
                }

                config.servers = JsonConvert.DeserializeObject <Dictionary <string, ServerTrans> >(config_str);
                config.Init();
                return(config);
            }
            catch (Exception e)
            {
                if (!(e is FileNotFoundException))
                {
                    Console.WriteLine(e);
                }
                return(new ServerTransferTotal());
            }
        }
 public static void Save(ServerTransferTotal config)
 {
     try
     {
         using var sw = new StreamWriter(File.Open(LOG_FILE, FileMode.Create));
         var jsonString = JsonConvert.SerializeObject(config.servers, Formatting.Indented);
         sw.Write(jsonString);
         sw.Flush();
     }
     catch (IOException e)
     {
         Console.Error.WriteLine(e);
     }
 }
Ejemplo n.º 6
0
 public static void Save(ServerTransferTotal config)
 {
     try
     {
         using (StreamWriter sw = new StreamWriter(File.Open(LOG_FILE, FileMode.Create)))
         {
             string jsonString = SimpleJson.SimpleJson.SerializeObject(config.servers);
             sw.Write(jsonString);
             sw.Flush();
         }
     }
     catch (IOException e)
     {
         Console.Error.WriteLine(e);
     }
 }
Ejemplo n.º 7
0
 public static ServerTransferTotal Load()
 {
     try
     {
         string config_str          = File.ReadAllText(LOG_FILE);
         ServerTransferTotal config = new ServerTransferTotal();
         config.servers = SimpleJson.SimpleJson.DeserializeObject <Dictionary <string, object> >(config_str, new JsonSerializerStrategy());
         config.Init();
         return(config);
     }
     catch (Exception e)
     {
         if (!(e is FileNotFoundException))
         {
             Console.WriteLine(e);
         }
         return(new ServerTransferTotal());
     }
 }
Ejemplo n.º 8
0
 public static void Save(ServerTransferTotal config)
 {
     try
     {
         using var sw = new StreamWriter(File.Open(LOG_FILE, FileMode.Create));
         var jsonString = JsonConvert.SerializeObject(config.servers, Formatting.Indented);
         if (GlobalConfiguration.config_password.Length > 0)
         {
             using var encryptor = EncryptorFactory.GetEncryptor(@"aes-256-cfb", GlobalConfiguration.config_password);
             var cfgData = Encoding.UTF8.GetBytes(jsonString);
             jsonString = Utils.EncryptLargeBytesToBase64String(encryptor, cfgData);
         }
         sw.Write(jsonString);
         sw.Flush();
     }
     catch (IOException e)
     {
         Console.Error.WriteLine(e);
     }
 }
        public static ServerTransferTotal Load()
        {
            try
            {
                var config_str = File.ReadAllText(LOG_FILE);
                var config     = new ServerTransferTotal
                {
                    servers = JsonConvert.DeserializeObject <Dictionary <string, ServerTrans> >(config_str)
                };

                config.Init();
                return(config);
            }
            catch (Exception e)
            {
                if (!(e is FileNotFoundException))
                {
                    Console.WriteLine(e);
                }
                return(new ServerTransferTotal());
            }
        }
Ejemplo n.º 10
0
 public static void Save(ServerTransferTotal config)
 {
     try
     {
         using (var sw = new StreamWriter(File.Open(LOG_FILE, FileMode.Create)))
         {
             var jsonString = JsonConvert.SerializeObject(config.servers, Formatting.Indented);
             if (GlobalConfiguration.config_password.Length > 0)
             {
                 var encryptor  = EncryptorFactory.GetEncryptor("aes-256-cfb", GlobalConfiguration.config_password);
                 var cfgData    = Encoding.UTF8.GetBytes(jsonString);
                 var cfgEncrypt = new byte[cfgData.Length + 128];
                 encryptor.Encrypt(cfgData, cfgData.Length, cfgEncrypt, out var data_len);
                 jsonString = Convert.ToBase64String(cfgEncrypt, 0, data_len);
             }
             sw.Write(jsonString);
             sw.Flush();
         }
     }
     catch (IOException e)
     {
         Console.Error.WriteLine(e);
     }
 }