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; } }
private void addFilesToolStripMenuItem_Click(object sender, EventArgs e) { /** ADD A FILE **/ OpenFileDialog diag = new OpenFileDialog(); // TODO: Use autogenerated list diag.Filter = "Video Files|*.mp4;*.avi;*.mov;*.flv;*.mkv"; diag.Title = "Add Files to Library"; diag.Multiselect = true; 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); // copy the selected files into the library, and add them to the database foreach (string file in diag.FileNames) { 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, 1, false); fileEntry = Files.GetFile(Database.GetLastInsertID("files")); Files.AssociateFileLocation(fileEntry, 1); } catch (Exception ex) { Console.WriteLine(ex.ToString()); MessageBox.Show("Error: Unable to copy file " + file + " to library."); } } // refresh the database _mainManager.LibraryManager.RefreshLibraryFromDatabase(); this.Enabled = true; Cursor.Current = Cursors.Default; } }