Exemple #1
0
        public ProfileManager(string folderPath, Func <Profile <T> > defaultProfileFactory,
                              Action <string> errorLogCallback)
        {
            FolderPath            = folderPath;
            DefaultProfileFactory = defaultProfileFactory;
            ErrorLogCallback      = errorLogCallback;

            // load the profile config, if it exists
            // otherwise, create it
            string conpath = Path.Combine(FolderPath, ConfigFileName);

            if (!File.Exists(conpath))
            {
                Config = new ProfileConfig();
                SaveProfileConfig(conpath);
            }
            else
            {
                LoadProfileConfig(conpath);
            }

            // if the default profile doesn't exist, create it with the factory
            string defpath = Path.Combine(FolderPath, "profile_" + Config.DefaultProfileName + ".json");

            if (!File.Exists(defpath))
            {
                Profile <T> prof = DefaultProfileFactory();
                prof.SaveName = Config.DefaultProfileName;
                SaveProfile(prof, defpath);
            }

            // load all profiles in the folder
            IEnumerable <string> files = Directory.EnumerateFiles(FolderPath, "profile_*.json");

            foreach (string fname in files)
            {
                try
                {
                    Profile <T> prof = LoadProfile(fname);
                    Profiles.Add(prof.SaveName, prof);
                }
                catch
                {
                    ErrorLogCallback("Couldn't load profile '" + fname + "'");
                }
            }

            CurrentProfile = Profiles[Config.DefaultProfileName];
        }
Exemple #2
0
 public void LoadProfileConfig(string path)
 {
     Config = JsonConvert.DeserializeObject <ProfileConfig>(FileUtility.ReadFromFile(path));
 }