public static UserProfile SaveUserProfile(UserProfile userProfile, string serverPath) { if (userProfile == null) { throw new ArgumentNullException(nameof(userProfile)); } if (serverPath == null) { throw new ArgumentNullException(nameof(serverPath)); } if (!String.IsNullOrWhiteSpace(userProfile.FilePath) && File.Exists(userProfile.FilePath)) { File.Delete(userProfile.FilePath); } string userProfileRoot = OSVRDirectories.GetUserProfileDirectory(serverPath, true); userProfile.FilePath = Path.Combine(userProfileRoot, GetUserProfileFileName(userProfile.Name)); using (var fs = File.CreateText(userProfile.FilePath)) { var serializer = new JsonSerializer(); serializer.Serialize(fs, userProfile); } return(userProfile); }
public static IEnumerable <UserProfile> GetAvailableUserProfiles(string serverPath) { string userProfileDirectory = OSVRDirectories.GetUserProfileDirectory(serverPath, true); var profiles = from file in Directory.EnumerateFiles(userProfileDirectory) where String.CompareOrdinal(Path.GetExtension(file), ".json") == 0 select ReadProfileFromFile(file); return(profiles); }
public static void DeleteUserProfile(string name, string serverPath) { if (name == null) { throw new ArgumentNullException(nameof(name)); } if (serverPath == null) { throw new ArgumentNullException(nameof(serverPath)); } string userProfileRoot = OSVRDirectories.GetUserProfileDirectory(serverPath); var profilePath = Path.Combine(userProfileRoot, GetUserProfileFileName(name)); // We're idempotent. Deleting a non-existant file is OK, just do nothing. if (File.Exists(profilePath)) { File.Delete(profilePath); } }