Advertisement
Guest User

Untitled

a guest
Jun 13th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.24 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Runtime.Serialization.Formatters.Binary;
  6. using System.IO;
  7. using System.Windows.Forms;
  8. using System.Net;
  9. using System.Data;
  10. using System.ComponentModel;
  11.  
  12.  
  13. namespace FTPHound
  14. {
  15.     class SettingsManagement
  16.     {
  17.         BinaryFormatter formatter = new BinaryFormatter();
  18.         FileStream stream;
  19.  
  20.         public void LoadSettings(Settings setting)
  21.         {
  22.             stream = new FileStream("settings.dat", FileMode.OpenOrCreate);
  23.             if (stream.Length > 0)
  24.             {
  25.                 setting = (Settings)formatter.Deserialize(stream);
  26.                 //MessageBox.Show(settings.teststr.GetType().ToString() + ", " + settings.teststr.Length + ", " + settings.teststr);
  27.             }
  28.         }
  29.  
  30.         public void SaveSettings(Settings settings)
  31.         {
  32.             formatter.Serialize(stream, settings);
  33.         }
  34.  
  35.         public void InitDraw(Settings settings) //For when the program first loads up.
  36.         {
  37.             if (settings.serverlist.Count > 0)
  38.             {
  39.                 for (int i = 0; i <= settings.serverlist.Count; i++)
  40.                 {
  41.                     settings.serverlist.Add(settings.serverlist[i]);
  42.                 }
  43.             }
  44.         }
  45.     }
  46.  
  47.     [Serializable]
  48.     class Settings
  49.     {
  50.         public BindingList<ServerSetting>serverlist = new BindingList<ServerSetting>();
  51.  
  52.     }
  53.  
  54.     [Serializable]
  55.     public struct ServerSetting
  56.     {
  57.         public string CustomName;
  58.         public IPAddress hostaddress;
  59.         public string localdirectory;
  60.         public string remotedirectory;
  61.         public string login;
  62.         public string password;
  63.  
  64.         public ServerSetting(string customname, IPAddress hostaddr, string localdir, string remotedir, string user, string pass)
  65.         {
  66.             CustomName = customname;
  67.             hostaddress = hostaddr;
  68.             localdirectory = localdir;
  69.             remotedirectory = remotedir;
  70.             login = user;
  71.             password = pass;
  72.         }
  73.  
  74.         new public string ToString()
  75.         {
  76.             return "CustomName: " + CustomName + "; HostAddress: " + hostaddress + "; LocalDirectory: " + localdirectory + "; RemoteDirectory: " + remotedirectory + "; Username: " + login + "; Password: " + password;
  77.         }
  78.  
  79.     }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement