/// <summary> /// プロファイルリストに追加 /// </summary> /// <param name="pf"></param> /// <param name="index">上書きではない場合、リストのどの位置に追加するか(-1指定で末尾に追加)</param> private void AddToUserProfileList(UserProfileInfo newUserProfileInfo, int index) { if (UserProfileList.Any(pl => pl.RelativePath == newUserProfileInfo.RelativePath)) { // 上書き UserProfileInfo oldProfileInfo = UserProfileList.FirstOrDefault(pl => pl.RelativePath == newUserProfileInfo.RelativePath); if (oldProfileInfo != null) { index = UserProfileList.IndexOf(oldProfileInfo); UserProfileList.RemoveAt(index); UserProfileList.Insert(index, newUserProfileInfo); newUserProfileInfo.SaveProfileToXmlFile(); } } else { // 追加 if (index > -1) { UserProfileList.Insert(index, newUserProfileInfo); } else { UserProfileList.Add(newUserProfileInfo); } newUserProfileInfo.SaveProfileToXmlFile(); } }
public UserProfileInfo CopyUserProfileInfo(UserProfileInfo upi) { string xmlDir = Directory.GetParent(System.Reflection.Assembly.GetExecutingAssembly().Location).FullName + "\\Profile"; // コピー先の相対パスを決める string srcRelativePathWithoutExt = System.IO.Path.GetFileNameWithoutExtension(upi.RelativePath); string newRelativePath = srcRelativePathWithoutExt + "_コピー.xml"; int cnt = 2; while (File.Exists(xmlDir + "\\" + newRelativePath)) { newRelativePath = srcRelativePathWithoutExt + "_コピー(" + cnt + ").xml"; cnt++; if (cnt >= int.MaxValue) { return(null); } } // Profileのコピー Profile newProfile = upi.Profile.Clone(); string newProfileName = System.IO.Path.GetFileName(newRelativePath); newProfileName = System.IO.Path.GetFileNameWithoutExtension(newProfileName); newProfile.Name = newProfileName; // UserProfileInfoのコピー UserProfileInfo newUpi = new UserProfileInfo(newRelativePath); newUpi.Profile = newProfile; // Profileのコピーをxmlに保存 newUpi.SaveProfileToXmlFile(); return(newUpi); }