ClientLauncher.UserPreferences.UpdateSettings C# (CSharp) 메소드

UpdateSettings() 공개 메소드

public UpdateSettings ( SettingsType theType, object theSetting ) : void
theType SettingsType
theSetting object
리턴 void
        public void UpdateSettings(SettingsType theType, object theSetting)
        {
            //collect them from the Application Resources Collection
            theSettings = App.Current.Resources["UserPreferences"] as UserSettings;

            switch (theType)
            {
                case SettingsType.AddCustomServer:
                case SettingsType.RemoveCustomServer:
                    //don't all any duplicates
                    theSettings.CustomServers.RemoveAll(cs => cs.ServerId == ((CustomServer)theSetting).ServerId);

                    if (theType == SettingsType.AddCustomServer)
                    {
                        theSettings.CustomServers.Add(theSetting as CustomServer);
                    }
                    break;
                case SettingsType.AddServerCredentials:
                case SettingsType.RemoveServerCredentials:
                    //get a serverdetail object
                    ServerDetails addMe = theSetting as ServerDetails;

                    //don't allow duplicate username for this server
                    theSettings.Servers.RemoveAll(sd => sd.ServerId == addMe.ServerId && sd.Username.Equals(addMe.Username, StringComparison.InvariantCultureIgnoreCase));

                    if (theType == SettingsType.AddServerCredentials)
                    {
                        theSettings.Servers.Add(addMe);
                    }
                    break;
                default:
                    //update the setting
                    theSettings.GetType().GetProperty(theType.ToString()).SetValue(theSettings, theSetting, null);
                    break;
            }

            App.Current.Resources["UserPreferences"] = theSettings;

            BinaryFormatter bf = new BinaryFormatter();
            LauncherEncryption myEncryption = new LauncherEncryption();
            IsolatedStorageFile inFile = IsolatedStorageFile.GetUserStoreForAssembly();

            //and save that into the file
            using (MemoryStream msOut = new MemoryStream())
            using (IsolatedStorageFileStream outStream = new IsolatedStorageFileStream("settings.cfg", FileMode.OpenOrCreate, System.IO.FileAccess.Write, inFile))
            using (BinaryWriter bwOut = new BinaryWriter(outStream))
            {
                //serialize it
                bf.Serialize(msOut, theSettings);

                //encrypt it and write it out
                bwOut.Write(myEncryption.Encrypt(msOut.ToArray()));
            }
        }

Usage Example

예제 #1
0
        public void MessageBoxOK(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(strSWGANHPath))
            {
                System.Windows.Forms.FolderBrowserDialog dia = new System.Windows.Forms.FolderBrowserDialog();

                if (dia.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    strSWGANHPath = dia.SelectedPath;
                }

                //add a slash if it needs one
                if (!strSWGANHPath.EndsWith("\\"))
                {
                    strSWGANHPath += "\\";
                }

                //save this one
                myUserPreferences.UpdateSettings(UserPreferences.SettingsType.ClientPath, strSWGANHPath);
            }

            if (!string.IsNullOrEmpty(strSWGANHPath))
            {
                PatchClient(cachedServerInfo);
            }
        }
All Usage Examples Of ClientLauncher.UserPreferences::UpdateSettings