private void AddFileToFolder(PackageFolder folder, string file) { if (folder == null) { string guessFolderName = FileHelper.GuessFolderNameFromFile(file); bool confirmed = UIServices.Confirm( String.Format(CultureInfo.CurrentCulture, Resources.ConfirmToMoveFileIntoFolder, file, guessFolderName)); if (confirmed) { if (RootFolder.ContainsFolder(guessFolderName)) { folder = (PackageFolder)RootFolder[guessFolderName]; } else { folder = RootFolder.AddFolder(guessFolderName); } } else { folder = RootFolder; } } folder.AddFile(file); }
public void AddDraggedAndDroppedFiles(PackageFolder folder, string[] fileNames) { if (folder == null) { bool?rememberedAnswer = null; for (var i = 0; i < fileNames.Length; i++) { var file = fileNames[i]; if (File.Exists(file)) { bool movingFile; PackageFolder targetFolder; var guessFolderName = FileHelper.GuessFolderNameFromFile(file); if (rememberedAnswer == null) { // ask user if he wants to move file var answer = UIServices.ConfirmMoveFile( Path.GetFileName(file), guessFolderName, fileNames.Length - i - 1); if (answer.Item1 == null) { // user presses Cancel break; } movingFile = (bool)answer.Item1; if (answer.Item2) { rememberedAnswer = answer.Item1; } } else { movingFile = (bool)rememberedAnswer; } if (movingFile) { if (RootFolder.ContainsFolder(guessFolderName)) { targetFolder = (PackageFolder)RootFolder[guessFolderName]; } else { targetFolder = RootFolder.AddFolder(guessFolderName); } } else { targetFolder = RootFolder; } targetFolder.AddFile(file); } else if (Directory.Exists(file)) { RootFolder.AddPhysicalFolder(file); } } } else { foreach (var file in fileNames) { if (File.Exists(file)) { folder.AddFile(file); } else if (Directory.Exists(file)) { folder.AddPhysicalFolder(file); } } } }