private void AddNewProfile(int gameID, bool isUsed) { AddProfileForm addProfileForm = new AddProfileForm(); addProfileForm.ShowDialog(); SqlDataReader sqlDataReader = DatabaseManager.ExecuteDataReader(String.Format( @"SELECT GameSaveLocation FROM Games WHERE GameID={0}", gameID)); string gameSaveLocation = ""; while (sqlDataReader.Read()) { gameSaveLocation = sqlDataReader.GetValue(0).ToString().TrimEnd(' '); } string profileSaveLocation = gameSaveLocation + "_" + addProfileForm.GetProfileName; sqlDataReader.Close(); string command = String.Format( "INSERT INTO Profiles (ProfileName, GameID, ProfileSaveLocation, IsUsed) VALUES (\'{0}\', {1}, \'{2}\', {3})", addProfileForm.GetProfileName, gameID, profileSaveLocation, (isUsed ? 1 : 0)); DatabaseManager.AddToDatabase(command); FSManager.DirectoryCopy(gameSaveLocation, profileSaveLocation, true); RefreshProfiles(); }
private void ProfileListView_SelectedIndexChanged(object sender, EventArgs e) { int selectedProfileID = profileListView.SelectedIndex; if (selectedProfileID != -1) { Game game = gameListView.SelectedItem as Game; SqlDataReader sqlDataReader = DatabaseManager.ExecuteDataReader(String.Format( @"SELECT ProfileName,ProfileID FROM Profiles WHERE IsUsed=1")); string lastProfileName = ""; int profileID = 0; while (sqlDataReader.Read()) { lastProfileName = sqlDataReader.GetString(0).TrimEnd(' '); profileID = sqlDataReader.GetInt32(1); } sqlDataReader.Close(); FSManager.DirectoryRename(game.game_save_location, game.game_save_location + "_" + lastProfileName); DatabaseManager.UpdateDatabase(String.Format( "UPDATE Profiles SET ProfileSaveLocation=\'{0}\' WHERE ProfileID={1}", game.game_save_location + "_" + lastProfileName, profileID)); DatabaseManager.UpdateDatabase(String.Format( @"UPDATE Profiles SET IsUsed=0 WHERE ProfileID={0}", profileID)); RefreshProfiles(); Profile profile = profileListView.Items[selectedProfileID] as Profile; FSManager.DirectoryRename(profile.profile_save_location, game.game_save_location); DatabaseManager.UpdateDatabase(String.Format( "UPDATE Profiles SET ProfileSaveLocation=\'{0}\' WHERE ProfileID={1}", game.game_save_location, game.game_id)); DatabaseManager.UpdateDatabase(String.Format( @"UPDATE Profiles SET IsUsed=1 WHERE ProfileID={0}", profile.profile_id)); } }