示例#1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtUsername.Text))
            {
                MessageBox.Show("The Username cannot be blank");
            }
            else
            {
                AWBProfile profile = new AWBProfile {
                    Username = txtUsername.Text
                };

                if (chkSavePassword.Checked && !string.IsNullOrEmpty(txtPassword.Text))
                {
                    profile.Password = txtPassword.Text;
                }

                profile.DefaultSettings = txtPath.Text;

                int idUpload = AWBProfiles.GetIDOfUploadAccount();

                if (chkUseForUpload.Checked && (idUpload != -1) && (idUpload != Editid))
                {
                    AWBProfiles.SetOtherAccountsAsNotForUpload();
                }

                profile.UseForUpload = chkUseForUpload.Checked;
                profile.Notes        = txtNotes.Text;

                profile.ID = Editid;
                AWBProfiles.AddEditProfile(profile);

                DialogResult = DialogResult.Yes;
            }
        }
        private void AWBProfiles_Load(object sender, EventArgs e)
        {
            if (!DesignMode)
            {
                LoadProfiles();
            }

            string lua = AWBProfiles.LastUsedAccount;

            if (!string.IsNullOrEmpty(lua))
            {
                int id;
                int.TryParse(lua, out id);

                AWBProfile p = AWBProfiles.GetProfile(id);

                if (p == null)
                {
                    txtUsername.Text = lua;
                    return;
                }

                txtUsername.Text = (id > 0) ? p.Username : lua;
            }
        }
示例#3
0
        /// <summary>
        /// Loads details from an AWBProfile object for editing
        /// </summary>
        public AWBProfileAdd(AWBProfile profile)
        {
            InitializeComponent();
            JustLoading = true;

            Editid = profile.ID;

            txtUsername.Text        = profile.Username;
            txtPassword.Text        = profile.Password;
            txtPath.Text            = profile.DefaultSettings;
            chkUseForUpload.Checked = profile.UseForUpload;
            txtNotes.Text           = profile.Notes;

            if (!string.IsNullOrEmpty(txtPath.Text))
            {
                chkDefaultSettings.Checked = true;
            }

            if (!string.IsNullOrEmpty(txtPassword.Text))
            {
                chkSavePassword.Checked = true;
            }

            Text        = "Edit Profile";
            JustLoading = false;
        }
示例#4
0
        private void btnQuickLogin_Click(object sender, EventArgs e)
        {
            string user     = txtUsername.Text;
            string password = txtPassword.Text;

            if (chkSaveProfile.Checked)
            {
                if (AWBProfiles.GetProfile(txtUsername.Text) != null)
                {
                    MessageBox.Show("Username \"" + txtUsername.Text + "\" already exists.", "Username exists");
                    return;
                }

                var profile = new AWBProfile {
                    Username = user
                };
                if (chkSavePassword.Checked)
                {
                    profile.Password = password;
                }
                AWBProfiles.AddEditProfile(profile);
            }

            AWBProfiles.LastUsedAccount = user;
            PerformLogin(user, password);
        }
示例#5
0
        /// <summary>
        /// Gets a Specified Profile from the Registry
        /// </summary>
        /// <param name="id">Profile ID to get</param>
        /// <returns>Specified Profile</returns>
        public static AWBProfile GetProfile(int id)
        {
            AWBProfile prof       = new AWBProfile();
            Computer   myComputer = new Computer();

            prof.id = id;
            try { prof.Username = Decrypt(myComputer.Registry.GetValue("HKEY_CURRENT_USER\\" + RegKey + "\\" + id, "User", "").ToString()); }
            catch
            {
                if (MessageBox.Show("Profile corrupt. Would you like to delete this profile?", "Delete corrupt profile?", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    DeleteProfile(id);
                }

                throw new Exception("");
            }

            // one try...catch without a resume has the effect that all remaining code in the try block is skipped
            // WHY are we just ignoring these errors anyway? There should be a wrapper around Registry.GetValue perhaps?
            try { prof.Password = Decrypt(myComputer.Registry.GetValue("HKEY_CURRENT_USER\\" + RegKey + "\\" + id, "Pass", "").ToString()); }
            catch { prof.Password = ""; }
            finally
            {
                prof.defaultsettings = myComputer.Registry.GetValue("HKEY_CURRENT_USER\\" + RegKey + "\\" + id, "Settings", "").ToString();
                try { prof.useforupload = bool.Parse(myComputer.Registry.GetValue("HKEY_CURRENT_USER\\" + RegKey + "\\" + id, "UseForUpload", "").ToString()); }
                catch { prof.useforupload = false; }
                prof.notes = myComputer.Registry.GetValue("HKEY_CURRENT_USER\\" + RegKey + "\\" + id, "Notes", "").ToString();
            }
            return(prof);
        }
        /// <summary>
        /// Gets a Specified Profile from the Registry
        /// </summary>
        /// <param name="id">Profile ID to get</param>
        /// <returns>Specified Profile</returns>
        public static AWBProfile GetProfile(int id)
        {
            AWBProfile prof = new AWBProfile();

            prof.id = id;
            try { prof.Username = RegistryGetAndDecryptValue(id + "\\User", ""); }
            catch
            {
                if (MessageBox.Show("Profile corrupt. Would you like to delete this profile?", "Delete corrupt profile?", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    DeleteProfile(id);
                }
            }

            if (string.IsNullOrEmpty(prof.Username))
            {
                return(null);
            }

            // one try...catch without a resume has the effect that all remaining code in the try block is skipped
            // WHY are we just ignoring these errors anyway? There should be a wrapper around Registry.GetValue perhaps?
            try { prof.Password = RegistryGetAndDecryptValue(id + "\\Pass", ""); }
            catch { prof.Password = ""; }
            finally
            {
                prof.defaultsettings = RegistryGetValue(id + "\\Settings", "");
                try { prof.useforupload = bool.Parse(RegistryGetValue(id + "\\UseForUpload", "")); }
                catch { prof.useforupload = false; }
                prof.notes = RegistryGetValue(id + "\\Notes", "");
            }
            return(prof);
        }
示例#7
0
        /// <summary>
        /// Gets a Specified Profile from the Registry
        /// </summary>
        /// <param name="id">Profile ID to get</param>
        /// <returns>Specified Profile</returns>
        public static AWBProfile GetProfile(int id)
        {
            AWBProfile prof = new AWBProfile {ID = id};

            try { prof.Username = RegistryGetAndDecryptValue(id + "\\User", ""); }
            catch
            {
                if (MessageBox.Show("Profile corrupt. Would you like to delete this profile?", "Delete corrupt profile?", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    DeleteProfile(id);
            }

            if (string.IsNullOrEmpty(prof.Username)) return null;

            // one try...catch without a resume has the effect that all remaining code in the try block is skipped
            // WHY are we just ignoring these errors anyway? There should be a wrapper around Registry.GetValue perhaps?
            try { prof.Password = RegistryGetAndDecryptValue(id + "\\Pass", ""); }
            catch { prof.Password = ""; }
            finally
            {
                prof.DefaultSettings = RegistryGetValue(id + "\\Settings", "");
                try { prof.UseForUpload = bool.Parse(RegistryGetValue(id + "\\UseForUpload", "")); }
                catch { prof.UseForUpload = false; }
                prof.Notes = RegistryGetValue(id + "\\Notes", "");
            }
            return prof;
        }
示例#8
0
        /// <summary>
        /// Publically accessible login, to allow calling of login via AWB startup parameters
        /// </summary>
        /// <param name="profileID">Profile ID to login to</param>
        public void login(int profileID)
        {
            if (profileID == -1)
            {
                return;
            }

            try
            {
                AWBProfile startupProfile = AWBProfiles.GetProfile(profileID);

                if (!string.IsNullOrEmpty(startupProfile.Password))
                {//Get 'Saved' Password
                    browserLogin(startupProfile.Username, startupProfile.Password);
                }
                else
                {//Get Password from User
                    UserPassword password = new UserPassword();
                    password.SetText = "Enter password for " + startupProfile.Username;

                    if (password.ShowDialog() == DialogResult.OK)
                    {
                        browserLogin(startupProfile.Username, password.GetPassword);
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorHandler.Handle(ex);
            }
        }
示例#9
0
 /// <summary>
 /// Does the registry writing for add & edit profiles
 /// </summary>
 /// <param name="profile">Profile Object of User</param>
 /// <param name="Key">Registry Key for Adding/Editing</param>
 private static void AddEditProfile(AWBProfile profile, Microsoft.Win32.RegistryKey Key)
 {
     Key.SetValue("User", Encrypt(profile.Username));
     Key.SetValue("Pass", Encrypt(profile.Password));
     Key.SetValue("Settings", profile.defaultsettings);
     Key.SetValue("UseForUpload", profile.useforupload);
     Key.SetValue("Notes", profile.notes);
 }
示例#10
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtUsername.Text))
            {
                MessageBox.Show("The Username cannot be blank");
            }
            else
            {
                // warn user if profile for entered user ID already exists
                if (Editid == -1 && AWBProfiles.GetProfile(txtUsername.Text) != null)
                {
                    if (MessageBox.Show("Username \"" + txtUsername.Text + "\" is already used in another profile. Are you sure you want to use this username again?",
                                        "Username already used in another profile", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                    {
                        return;
                    }
                }

                AWBProfile profile = new AWBProfile {
                    Username = txtUsername.Text
                };

                if (chkSavePassword.Checked && !string.IsNullOrEmpty(txtPassword.Text))
                {
                    profile.Password = txtPassword.Text;
                }
                else
                {
                    profile.Password = "";
                }

                profile.DefaultSettings = txtPath.Text;

                int idUpload = AWBProfiles.GetIDOfUploadAccount();

                if (chkUseForUpload.Checked && (idUpload != -1) && (idUpload != Editid))
                {
                    AWBProfiles.SetOtherAccountsAsNotForUpload();
                }

                profile.UseForUpload = chkUseForUpload.Checked;
                profile.Notes        = txtNotes.Text;

                profile.ID = Editid;
                AWBProfiles.AddEditProfile(profile);

                DialogResult = DialogResult.Yes;
            }
        }
示例#11
0
        /// <summary>
        /// Publically accessible login, to allow calling of login via AWB startup parameters
        /// </summary>
        /// <param name="profileIdOrName">Profile ID to login to</param>
        public void Login(string profileIdOrName)
        {
            if (profileIdOrName.Length == 0)
            {
                return;
            }

            try
            {
                int        profileID;
                AWBProfile startupProfile = int.TryParse(profileIdOrName, out profileID)
                    ? AWBProfiles.GetProfile(profileID)
                    : AWBProfiles.GetProfile(profileIdOrName);

                if (startupProfile == null)
                {
                    MessageBox.Show(Parent, "Can't find user '" + profileIdOrName + "'.", "Command line error",
                                    MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }

                if (!string.IsNullOrEmpty(startupProfile.Password))
                {
                    //Get 'Saved' Password
                    PerformLogin(startupProfile.Username, startupProfile.Password);
                }
                else
                {
                    //Get Password from User
                    UserPassword password = new UserPassword
                    {
                        Username = startupProfile.Username
                    };

                    if (password.ShowDialog(this) == DialogResult.OK)
                    {
                        PerformLogin(startupProfile.Username, password.GetPassword);
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorHandler.HandleException(ex);
            }
        }
示例#12
0
        /// <summary>
        /// Writes a new or modified Profile to the registry
        /// </summary>
        /// <param name="profile">Profile Object of User</param>
        internal static void AddEditProfile(AWBProfile profile)
        {
            if (profile.ID == -1)
            {
                profile.ID = GetFirstFreeID();
            }

            RegistryKey key = RegistryGetWritableKey(profile.ID);

            try
            {
                key.SetValue("User", EncryptionUtils.Encrypt(profile.Username));
                key.SetValue("Pass", EncryptionUtils.Encrypt(profile.Password));
                key.SetValue("Settings", profile.DefaultSettings);
                key.SetValue("Notes", profile.Notes);
            }
            catch { }
        }
示例#13
0
        /// <summary>
        /// Loads details from an AWBProfile object for editing
        /// </summary>
        public AWBProfileAdd(AWBProfile profile)
        {
            InitializeComponent();

            Editid = profile.ID;

            txtUsername.Text = profile.Username;
            txtPassword.Text = profile.Password;
            txtPath.Text = profile.DefaultSettings;
            txtNotes.Text = profile.Notes;

            if (!string.IsNullOrEmpty(txtPath.Text))
                chkDefaultSettings.Checked = true;

            if (!string.IsNullOrEmpty(txtPassword.Text))
                chkSavePassword.Checked = true;

            Text = "Edit Profile";
        }
示例#14
0
        /// <summary>
        /// Loads details from an AWBProfile object for editing
        /// </summary>
        public AWBProfileAdd(AWBProfile profile)
        {
            InitializeComponent();
            justLoading = true;

            editid = profile.id;

            txtUsername.Text = profile.Username;
            txtPassword.Text = profile.Password;
            txtPath.Text = profile.defaultsettings;
            chkUseForUpload.Checked = profile.useforupload;
            txtNotes.Text = profile.notes;

            if (!string.IsNullOrEmpty(txtPath.Text))
                chkDefaultSettings.Checked = true;

            this.Text = "Edit Profile";
            justLoading = false;
        }
        /// <summary>
        /// Writes a new or modified Profile to the registry
        /// </summary>
        /// <param name="profile">Profile Object of User</param>
        internal static void AddEditProfile(AWBProfile profile)
        {
            if (profile.id == -1)
            {
                profile.id = GetFirstFreeID();
            }

            RegistryKey Key = RegistryGetWritableKey(profile.id);

            try
            {
                Key.SetValue("User", EncryptionUtils.Encrypt(profile.Username));
                Key.SetValue("Pass", EncryptionUtils.Encrypt(profile.Password));
                Key.SetValue("Settings", profile.defaultsettings);
                Key.SetValue("UseForUpload", profile.useforupload);
                Key.SetValue("Notes", profile.notes);
            }
            catch { }
        }
示例#16
0
        private void btnQuickLogin_Click(object sender, EventArgs e)
        {
            string user     = txtUsername.Text;
            string password = txtPassword.Text;

            if (chkSaveProfile.Checked)
            {
                var profile = new AWBProfile {
                    Username = user
                };
                if (chkSavePassword.Checked)
                {
                    profile.Password = password;
                }
                AWBProfiles.AddEditProfile(profile);
            }

            AWBProfiles.LastUsedAccount = user;
            PerformLogin(user, password);
        }
        /// <summary>
        /// Loads details from an AWBProfile object for editing
        /// </summary>
        public AWBProfileAdd(AWBProfile profile)
        {
            InitializeComponent();
            justLoading = true;

            editid = profile.id;

            txtUsername.Text        = profile.Username;
            txtPassword.Text        = profile.Password;
            txtPath.Text            = profile.defaultsettings;
            chkUseForUpload.Checked = profile.useforupload;
            txtNotes.Text           = profile.notes;

            if (!string.IsNullOrEmpty(txtPath.Text))
            {
                chkDefaultSettings.Checked = true;
            }

            this.Text   = "Edit Profile";
            justLoading = false;
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtUsername.Text))
            {
                MessageBox.Show("The Username cannot be blank");
            }
            else
            {
                AWBProfile profile = new AWBProfile();

                profile.Username        = txtUsername.Text;
                profile.Password        = txtPassword.Text;
                profile.defaultsettings = txtPath.Text;

                int idUpload = AWBProfiles.GetIDOfUploadAccount();

                if (chkUseForUpload.Checked && idUpload != -1 && idUpload != editid)
                {
                    AWBProfiles.SetOtherAccountsAsNotForUpload();
                }

                profile.useforupload = chkUseForUpload.Checked;
                profile.notes        = txtNotes.Text;

                if (editid == -1)
                {
                    AWBProfiles.AddProfile(profile);
                }
                else
                {
                    profile.id = editid;
                    AWBProfiles.EditProfile(profile);
                }

                this.DialogResult = DialogResult.Yes;
            }
        }
        public static void MigrateProfiles()
        {
            const string RegKey = "Software\\Wikipedia\\AutoWikiBrowser\\Profiles";

            try
            {
                foreach (string id in new Microsoft.VisualBasic.Devices.Computer().Registry.CurrentUser.OpenSubKey(RegKey).GetSubKeyNames())
                {
                    AWBProfile prof = new AWBProfile();

                    Microsoft.VisualBasic.Devices.Computer myComputer = new Microsoft.VisualBasic.Devices.Computer();

                    prof.id = int.Parse(id);
                    try
                    {
                        prof.Username = EncryptionUtils.Decrypt(myComputer.Registry.GetValue("HKEY_CURRENT_USER\\" + RegKey + "\\" + id, "User", "").ToString());

                        try { prof.Password = EncryptionUtils.Decrypt(myComputer.Registry.GetValue("HKEY_CURRENT_USER\\" + RegKey + "\\" + id, "Pass", "").ToString()); }
                        catch { prof.Password = ""; }

                        prof.defaultsettings = myComputer.Registry.GetValue("HKEY_CURRENT_USER\\" + RegKey + "\\" + id, "Settings", "").ToString();

                        try { prof.useforupload = bool.Parse(myComputer.Registry.GetValue("HKEY_CURRENT_USER\\" + RegKey + "\\" + id, "UseForUpload", "").ToString()); }
                        catch { prof.useforupload = false; }

                        prof.notes = myComputer.Registry.GetValue("HKEY_CURRENT_USER\\" + RegKey + "\\" + id, "Notes", "").ToString();
                    }
                    catch
                    { }

                    AddEditProfile(prof);
                }
            }
            catch
            { }
        }
示例#20
0
 /// <summary>
 /// Edits the profile
 /// </summary>
 /// <param name="profile">Profile Object of User</param>
 public static void EditProfile(AWBProfile profile)
 {
     try { AddEditProfile(profile, new Computer().Registry.CurrentUser.OpenSubKey(RegKey + "\\" + profile.id, true)); }
     catch { }
 }
示例#21
0
 /// <summary>
 /// Edits the profile
 /// </summary>
 /// <param name="profile">Profile Object of User</param>
 public static void EditProfile(AWBProfile profile)
 {
     try { AddEditProfile(profile, new Computer().Registry.CurrentUser.OpenSubKey(RegKey + "\\" + profile.id, true)); }
     catch { }
 }
示例#22
0
 /// <summary>
 /// Adds a new Profile to the Registry
 /// </summary>
 /// <param name="profile">Profile Object of User</param>
 public static void AddProfile(AWBProfile profile)
 {
     try { AddEditProfile(profile, new Computer().Registry.CurrentUser.CreateSubKey(RegKey + "\\" + GetFirstFreeID())); }
     catch { }
 }
示例#23
0
 /// <summary>
 /// Does the registry writing for add & edit profiles
 /// </summary>
 /// <param name="profile">Profile Object of User</param>
 /// <param name="Key">Registry Key for Adding/Editing</param>
 private static void AddEditProfile(AWBProfile profile, Microsoft.Win32.RegistryKey Key)
 {
     Key.SetValue("User", Encrypt(profile.Username));
     Key.SetValue("Pass", Encrypt(profile.Password));
     Key.SetValue("Settings", profile.defaultsettings);
     Key.SetValue("UseForUpload", profile.useforupload);
     Key.SetValue("Notes", profile.notes);
 }
示例#24
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtUsername.Text))
                MessageBox.Show("The Username cannot be blank");
            else
            {
                // warn user if profile for entered user ID already exists
                if (Editid == -1 && AWBProfiles.GetProfile(txtUsername.Text) != null)
                {
                    if (MessageBox.Show("Username \"" +txtUsername.Text + "\" is already used in another profile. Are you sure you want to use this username again?",
                                        "Username already used in another profile", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                    return;
                }

                AWBProfile profile = new AWBProfile {Username = txtUsername.Text};

                if (chkSavePassword.Checked && !string.IsNullOrEmpty(txtPassword.Text))
                    profile.Password = txtPassword.Text;
                else
                     profile.Password ="";

                profile.DefaultSettings = txtPath.Text;
                profile.Notes = txtNotes.Text;

                profile.ID = Editid;
                AWBProfiles.AddEditProfile(profile);

                DialogResult = DialogResult.Yes;
            }
        }
示例#25
0
 /// <summary>
 /// Adds a new Profile to the Registry
 /// </summary>
 /// <param name="profile">Profile Object of User</param>
 public static void AddProfile(AWBProfile profile)
 {
     try { AddEditProfile(profile, new Computer().Registry.CurrentUser.CreateSubKey(RegKey + "\\" + GetFirstFreeID())); }
     catch { }
 }
示例#26
0
        public static void MigrateProfiles()
        {
            const string RegKey = "Software\\Wikipedia\\AutoWikiBrowser\\Profiles";
            try
            {
                foreach (string id in new Microsoft.VisualBasic.Devices.Computer().Registry.CurrentUser.OpenSubKey(RegKey).GetSubKeyNames())
                {
                    AWBProfile prof = new AWBProfile();

                    Microsoft.VisualBasic.Devices.Computer myComputer = new Microsoft.VisualBasic.Devices.Computer();

                    prof.id = int.Parse(id);
                    try
                    {
                        prof.Username = EncryptionUtils.Decrypt(myComputer.Registry.GetValue("HKEY_CURRENT_USER\\" + RegKey + "\\" + id, "User", "").ToString());

                        try { prof.Password = EncryptionUtils.Decrypt(myComputer.Registry.GetValue("HKEY_CURRENT_USER\\" + RegKey + "\\" + id, "Pass", "").ToString()); }
                        catch { prof.Password = ""; }

                        prof.defaultsettings = myComputer.Registry.GetValue("HKEY_CURRENT_USER\\" + RegKey + "\\" + id, "Settings", "").ToString();

                        try { prof.useforupload = bool.Parse(myComputer.Registry.GetValue("HKEY_CURRENT_USER\\" + RegKey + "\\" + id, "UseForUpload", "").ToString()); }
                        catch { prof.useforupload = false; }

                        prof.notes = myComputer.Registry.GetValue("HKEY_CURRENT_USER\\" + RegKey + "\\" + id, "Notes", "").ToString();
                    }
                    catch
                    { }

                    AddEditProfile(prof);
                }
            }
            catch
            { }
        }
        private void btnQuickLogin_Click(object sender, EventArgs e)
        {
            string user = txtUsername.Text;
            string password = txtPassword.Text;

            if (chkSaveProfile.Checked)
            {
                var profile = new AWBProfile { Username = user };
                if (chkSavePassword.Checked) profile.Password = password;
                AWBProfiles.AddEditProfile(profile);
            }

            AWBProfiles.LastUsedAccount = user;
            PerformLogin(user, password);
        }
示例#28
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtUsername.Text))
                MessageBox.Show("The Username cannot be blank");
            else
            {
                if (Editid == -1 && AWBProfiles.GetProfile(txtUsername.Text) != null)
                {
                    MessageBox.Show("Username \"" +txtUsername.Text + "\" already exists.", "Username exists");
                    return;
                }

                AWBProfile profile = new AWBProfile {Username = txtUsername.Text};

                if (chkSavePassword.Checked && !string.IsNullOrEmpty(txtPassword.Text))
                    profile.Password = txtPassword.Text;

                profile.DefaultSettings = txtPath.Text;

                int idUpload = AWBProfiles.GetIDOfUploadAccount();

                if (chkUseForUpload.Checked && (idUpload != -1) && (idUpload != Editid))
                    AWBProfiles.SetOtherAccountsAsNotForUpload();

                profile.UseForUpload = chkUseForUpload.Checked;
                profile.Notes = txtNotes.Text;

                profile.ID = Editid;
                AWBProfiles.AddEditProfile(profile);

                DialogResult = DialogResult.Yes;
            }
        }
示例#29
0
        /// <summary>
        /// Gets a Specified Profile from the Registry
        /// </summary>
        /// <param name="id">Profile ID to get</param>
        /// <returns>Specified Profile</returns>
        public static AWBProfile GetProfile(int id)
        {
            AWBProfile prof = new AWBProfile();
            Computer myComputer = new Computer();

            prof.id = id;
            try { prof.Username = Decrypt(myComputer.Registry.GetValue("HKEY_CURRENT_USER\\" + RegKey + "\\" + id, "User", "").ToString()); }
            catch
            {
                if (MessageBox.Show("Profile corrupt. Would you like to delete this profile?", "Delete corrupt profile?", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    DeleteProfile(id);

                throw new Exception("");
            }

            // one try...catch without a resume has the effect that all remaining code in the try block is skipped
            // WHY are we just ignoring these errors anyway? There should be a wrapper around Registry.GetValue perhaps?
            try { prof.Password = Decrypt(myComputer.Registry.GetValue("HKEY_CURRENT_USER\\" + RegKey + "\\" + id, "Pass", "").ToString()); }
            catch { prof.Password = ""; }
            finally
            {
                prof.defaultsettings = myComputer.Registry.GetValue("HKEY_CURRENT_USER\\" + RegKey + "\\" + id, "Settings", "").ToString();
                try { prof.useforupload = bool.Parse(myComputer.Registry.GetValue("HKEY_CURRENT_USER\\" + RegKey + "\\" + id, "UseForUpload", "").ToString()); }
                catch { prof.useforupload = false; }
                prof.notes = myComputer.Registry.GetValue("HKEY_CURRENT_USER\\" + RegKey + "\\" + id, "Notes", "").ToString();
            }
            return prof;
        }
示例#30
0
        /// <summary>
        /// Writes a new or modified Profile to the registry
        /// </summary>
        /// <param name="profile">Profile Object of User</param>
        internal static void AddEditProfile(AWBProfile profile)
        {
            if (profile.id == -1)
                profile.id = GetFirstFreeID();

            RegistryKey Key = RegistryGetWritableKey(profile.id);

            try
            {
                Key.SetValue("User", EncryptionUtils.Encrypt(profile.Username));
                Key.SetValue("Pass", EncryptionUtils.Encrypt(profile.Password));
                Key.SetValue("Settings", profile.defaultsettings);
                Key.SetValue("UseForUpload", profile.useforupload);
                Key.SetValue("Notes", profile.notes);
            }
            catch { }
        }
示例#31
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtUsername.Text))
                MessageBox.Show("The Username cannot be blank");
            else
            {
                AWBProfile profile = new AWBProfile();

                profile.Username = txtUsername.Text;

                if (chkSavePassword.Checked && !string.IsNullOrEmpty(txtPassword.Text))
                    profile.Password = txtPassword.Text;

                profile.defaultsettings = txtPath.Text;

                int idUpload = AWBProfiles.GetIDOfUploadAccount();

                if (chkUseForUpload.Checked && (idUpload != -1) && (idUpload != editid))
                    AWBProfiles.SetOtherAccountsAsNotForUpload();

                profile.useforupload = chkUseForUpload.Checked;
                profile.notes = txtNotes.Text;

                profile.id = editid;
                AWBProfiles.AddEditProfile(profile);

                DialogResult = DialogResult.Yes;
            }
        }
示例#32
0
        /// <summary>
        /// Writes a new or modified Profile to the registry
        /// </summary>
        /// <param name="profile">Profile Object of User</param>
        internal static void AddEditProfile(AWBProfile profile)
        {
            if (profile.ID == -1)
                profile.ID = GetFirstFreeID();

            RegistryKey key = RegistryGetWritableKey(profile.ID);

            try
            {
                key.SetValue("User", EncryptionUtils.Encrypt(profile.Username));
                key.SetValue("Pass", EncryptionUtils.Encrypt(profile.Password));
                key.SetValue("Settings", profile.DefaultSettings);
                key.SetValue("Notes", profile.Notes);
            }
            catch { }
        }
        private void btnQuickLogin_Click(object sender, EventArgs e)
        {
            string user = txtUsername.Text;
            string password = txtPassword.Text;

            if (chkSaveProfile.Checked)
            {
                if (AWBProfiles.GetProfile(txtUsername.Text) != null)
                {
                    MessageBox.Show("Username \"" + txtUsername.Text + "\" already exists.", "Username exists");
                    return;
                }

                var profile = new AWBProfile { Username = user };
                if (chkSavePassword.Checked) profile.Password = password;
                AWBProfiles.AddEditProfile(profile);
            }

            AWBProfiles.LastUsedAccount = user;
            PerformLogin(user, password);
        }