Advertisement
Guest User

Untitled

a guest
Feb 7th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.29 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11.  
  12. namespace INP_Login
  13. {
  14.     public partial class Form1 : Form
  15.     {
  16.         public Form1()
  17.         {
  18.             InitializeComponent();
  19.         }
  20.         private void button_save_Click(object sender, EventArgs e)
  21.         {
  22.             string username = input_username.Text;
  23.             string password = input_password.Text;
  24.             string auto = input_autologin.Checked ? "1" : "0";
  25.             Properties.Settings.Default.Save();
  26.             try
  27.             {
  28.                 string folder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
  29.                 string specificFolder = Path.Combine(folder, "INPLogin");
  30.                 string saveFile = Path.Combine(specificFolder, "Save.cfg");
  31.                 Console.WriteLine("Config saved!");
  32.                 StreamWriter sw = new StreamWriter(saveFile);
  33.                 sw.WriteLine(username);
  34.                 sw.WriteLine(password);
  35.                 sw.WriteLine(auto);
  36.                 sw.Close();
  37.             }
  38.             catch(Exception e1)
  39.             {
  40.                 Console.WriteLine("Error: " + e1.Message);
  41.             }
  42.         }
  43.  
  44.         private void Form1_Shown(object sender, EventArgs e)
  45.         {
  46.             string folder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
  47.             string specificFolder = Path.Combine(folder, "INPLogin");
  48.             if (!Directory.Exists(specificFolder))
  49.                 Directory.CreateDirectory(specificFolder);
  50.             Console.WriteLine("Window shown! Loading config file");
  51.             //input_username.Text = (string)Properties.Settings.Default["username"];
  52.             string saveFile = Path.Combine(specificFolder, "Save.cfg");
  53.             if (File.Exists(saveFile))
  54.             {
  55.                 StreamReader sr = new StreamReader(saveFile);
  56.                 input_username.Text = sr.ReadLine();
  57.                 input_password.Text = sr.ReadLine();
  58.                 input_autologin.Checked = (sr.ReadLine() == "1") ? true : false;
  59.                 sr.Close();
  60.             }
  61.         }
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement