// This function is used to Edit an already existing profile public async void EditProfile() { if (SelectedProfileManager.selectedProfile == null) { Debug.Log("You don't have any profile selected"); return; } if (string.IsNullOrEmpty(this.profileName.text)) { Debug.Log("Profile name can't be empty or null"); return; } string profileId = SelectedProfileManager.selectedProfile.profileId; string profileName = this.profileName.text; string fullProfileName = $"{this.profileName.text} {profileId}"; // Checks if the Profile Name is the same if (fullProfileName.Equals(SelectedProfileManager.selectedProfile.fullProfileName, StringComparison.OrdinalIgnoreCase)) { Debug.Log("You didn't change the profile name"); return; } FileManagerExtension.MoveDirectory(Path.Combine(mainDirectoryPath, SelectedProfileManager.selectedProfile.fullProfileName), Path.Combine(mainDirectoryPath, fullProfileName)); // Sets the paths needed for the profile string profilePath = Path.Combine(mainDirectoryPath, fullProfileName); string profileSavePath = Path.Combine(profilePath, "Save"); string profileSaveFilePath = Path.Combine(profileSavePath, "data.dat"); string profileConfigPath = Path.Combine(profilePath, "config.dat"); string profileSettingsPath = Path.Combine(profilePath, "Settings.dat"); if (!Directory.Exists(mainDirectoryPath)) { FileManagerExtension.CreateDirectory(mainDirectoryPath); } if (!Directory.Exists(profileSavePath)) { FileManagerExtension.CreateDirectory(profileSavePath); } if (!File.Exists(profileSaveFilePath)) { FileManagerExtension.CreateFile(profileSaveFilePath); } if (!File.Exists(profileSettingsPath)) { FileManagerExtension.CreateFile(profileSettingsPath); } // Deletes the old Profiles value from profiles.dat SaveManager.profiles.Remove(SaveManager.profiles.FirstOrDefault(p => p.fullProfileName.Equals(SelectedProfileManager.selectedProfile.fullProfileName))); await SaveManager.SaveAllProfilesAsync(profilesPath); if (SelectedProfileManager.selectedProfile == null) { Debug.Log("Failed to create profile reason unknown"); return; } string profileImage = SelectedProfileManager.selectedProfile.profileImage; // Creates and saves the profile. await SaveManager.SaveProfileAsync(profileConfigPath, profileImage, profileName, profileId, fullProfileName); SaveManagerEvents.current.ProfileEdited(SaveManager.CreateProfile(profileId, profileImage, profileName, fullProfileName, false)); SelectedProfileManager.selectedProfile = null; }