private void addFolderToolStripMenuItem_Click(Object sender, EventArgs e) { /** ADD A WHOLE FOLDER **/ FolderBrowserDialog diag = new FolderBrowserDialog(); // TODO: Use autogenerated list DialogResult userClickedOk = diag.ShowDialog(); if (userClickedOk == DialogResult.OK) { this.Enabled = false; Cursor.Current = Cursors.WaitCursor; // get the root library path Folder root = Folders.GetFolder(Folders.ROOT_ID); string shortDir = diag.SelectedPath.Substring(diag.SelectedPath.LastIndexOf("\\")); // copy the selected folder into the library, and add everything in it to the database string fullDir = root.Name + "\\" + shortDir; int fId; if (!Directory.Exists(fullDir)) { Directory.CreateDirectory(fullDir); Folder newFolder = new Folder(Folders.ROOT_ID, shortDir); Folders.AddFolder(newFolder, false); fId = Database.GetLastInsertID("folders"); } else { fId = Folders.GetFoldersByName(shortDir)[0].Id; } string[] files = Directory.GetFiles(diag.SelectedPath); foreach (string file in files) { try { string fullPath = root.Name + file.Substring(file.LastIndexOf("\\")); Console.WriteLine(fullPath); File.Copy(file, fullPath); VideoFile fileEntry = new VideoFile( fullPath, MainScreenManager.GetDefaultTags(new FileInfo(fullPath))); Files.AddFile(fileEntry, fId, false); fileEntry = Files.GetFile(Database.GetLastInsertID("files")); Files.AssociateFileLocation(fileEntry, fId); } catch (Exception ex) { MessageBox.Show("Error: Unable to copy file " + file + " to library."); } } // refresh the database _mainManager.LibraryManager.RefreshLibraryFromDatabase(); this.Enabled = true; Cursor.Current = Cursors.Default; } }
// Adds a directory in the library structure as a folder object in the database private Folder MapDirectoryAndContents(DirectoryInfo dir, int parentId) { // Try to add this directory as a folder in the database Folder folder = new Folder(parentId, dir.Name); Response response = Folders.AddFolder(folder, true); // If the folder was added successfully: if (response == Response.Success) { // Get folder with updated info from DB (for id mostly) folder = GetAddedFolder(dir.Name, parentId) ?? folder; // Add all the contained video files to the database folder.Files = MapContainedVideoFiles(dir, folder.Id); // Return the successfully added folder return(folder); } // Otherwise stop digging in this directory return(null); }