예제 #1
0
 public static LocalSetting GetSetting()
 {
     if (setting == null)
     {
         string defualtUser = GetDefualtUser();
         if (string.IsNullOrEmpty(defualtUser))
         {
             setting = new LocalSetting();
         }
         else
         {
             setting = GetSetting(defualtUser);
         }
     }
     return(setting);
 }
예제 #2
0
        public static LocalSetting GetSetting(string userName)
        {
            LocalSetting r = new LocalSetting();
            string       settingDirectory = GetSettingPath();

            if (Directory.Exists(settingDirectory))
            {
                string[] files = Directory.GetFiles(settingDirectory);
                foreach (string filepath in files)
                {
                    string userFileName = Path.GetFileNameWithoutExtension(filepath);
                    if (userFileName.ToUpper().Equals(userName.ToUpper()))
                    {
                        string[] temp = File.ReadAllLines(filepath);
                        if (temp.Count() > 0)
                        {
                            foreach (string set in temp)
                            {
                                string   ds = DecodeBase64(set);
                                string[] kp = ds.Split(new Char[] { '=' });
                                if (kp.Count() == 2)
                                {
                                    string key   = kp[0];
                                    string value = kp[1];
                                    switch (key.ToUpper())
                                    {
                                    case "USERNAME": r.userName = value; break;

                                    case "PASSWORD": r.PassWord = value; break;

                                    case "PAPERSAVEPATH": r.PaperSavePath = value; break;

                                    case "UPLOADPATH": r.uploadPath = value; break;

                                    case "SAVEPASSWORD":
                                    {
                                        if (!string.IsNullOrEmpty(value) && "TRUE".Equals(value.ToUpper()))
                                        {
                                            r.SavePassword = true;
                                        }
                                        else
                                        {
                                            r.SavePassword = false;
                                        }
                                    }; break;

                                    case "AUTOLOGIN":
                                    {
                                        if (!string.IsNullOrEmpty(value) && "TRUE".Equals(value.ToUpper()))
                                        {
                                            r.AutoLogin = true;
                                        }
                                        else
                                        {
                                            r.AutoLogin = false;
                                        }
                                    }; break;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if (!r.SavePassword)
            {
                r.PassWord = "";
            }
            return(r);
        }