private DynamicPath PathToDynamicPath(string path) { Folder3 folder = (Folder3)shell.NameSpace(path); List <string> subFolders = new List <string>(); if (folder != null && !folder.Self.IsFileSystem) { if (!path.Contains("usb")) { MessageBox.Show("מיקום לא תקין נבחר", "שגיאה", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.RtlReading); Console.WriteLine("Invalid path selected: " + path); return(new DynamicPath()); } while (folder.Self.Path.Count(c => c == '\\') != 4) { subFolders.Add(folder.Title); folder = (Folder3)folder.ParentFolder; } if (subFolders.Count == 0) { MessageBox.Show("יש לבחור תיקייה בתוך המכשיר", "שגיאה", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.RtlReading); Console.WriteLine("Please select a folder within the device"); return(new DynamicPath()); } } subFolders.Reverse(); return(new DynamicPath() { RootDrivePath = folder.Self.Path, SubFolders = subFolders.ToArray() }); }
public static string RemoveBadStringFromPath(Folder3 folder) { string path = folder.Self.Path; if (!(folder as Folder3).Self.IsFileSystem && path.Contains("SID-")) { int startBadIndex = path.IndexOf("SID-") - 1; int endBadIndex = path.IndexOf("}", startBadIndex + 1) + 1; path = path.Remove(startBadIndex, endBadIndex - startBadIndex); } return(path); }
public string GetPath() { Shell shell = new Shell(); string path = RootDrivePath; Folder3 folder = (Folder3)shell.NameSpace(path); if (string.IsNullOrWhiteSpace(path)) { MessageBox.Show("נתיב ריק", "שגיאה", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.RtlReading); return(""); } if (folder == null) { MessageBox.Show("לא היה ניתן למצוא את הנתיב שצוין", "שגיאה", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.RtlReading); Console.WriteLine("No device found at: " + path); return(""); } if (SubFolders != null && SubFolders.Length != 0) { folder = (Folder3)shell.NameSpace(path); List <FolderItem> items = folder.Items().Cast <FolderItem>().ToList(); if (items.Count == 0) { MessageBox.Show("יש לוודא שהמכשיר מוגדר למצב העברת קבצים", "שגיאה", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.RtlReading); Console.WriteLine("Make sure the device is set to \"transfer file mode\""); return(""); } string subFolder = SubFolders[0]; FolderItem folderItem = items.FirstOrDefault(f => f.Name == subFolder); if (folderItem == null) { folder = (Folder3)items[0].GetFolder; } foreach (string item in SubFolders) { items = folder.Items().Cast <FolderItem>().ToList(); folderItem = items.FirstOrDefault(f => f.Name == item); if (folderItem == null) { MessageBox.Show(string.Format("לא נמצאה תיקייה: {0}", item), "שגיאה", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.RtlReading); Console.WriteLine(@"Folder ""{0}"" was't not found", item); return(""); } folder = (Folder3)folderItem.GetFolder; } } return(SettingsTab.RemoveBadStringFromPath(folder)); }
public void SetMusicTag(string sourcePath) { if (string.IsNullOrWhiteSpace(sourcePath)) { Console.WriteLine("Cannot change tag, path was not found"); return; } Folder folder = shell.NameSpace(sourcePath); if (folder == null) { //TODO: Add dialog Console.WriteLine("Cannot change tag, path was not found"); return; } FolderItem[] musicFiles = folder.Items().Cast <FolderItem>().Where(item => item.Type == "MP3 File").ToArray(); foreach (FolderItem musicFilePath in musicFiles) { Folder3 tempFolder = (Folder3)shell.NameSpace(Path.GetTempPath()); tempFolder.NewFolder("Music ripper"); tempFolder = (Folder3)shell.NameSpace(Path.Combine(Path.GetTempPath(), "Music ripper")); tempFolder.MoveHere(musicFilePath); WaitForAFileTransfer(tempFolder, musicFilePath.Name); FolderItem tempMpFile = tempFolder.Items().Cast <FolderItem>().First(item => item.Name == musicFilePath.Name); using (TagLib.File file = TagLib.File.Create(tempMpFile.Path)) { file.Tag.Album = form.MusicTagName.Text; file.Tag.AlbumArtists = new string[] { form.MusicTagName.Text }; file.Tag.Performers = new string[] { form.MusicTagName.Text }; file.Save(); } folder.MoveHere(tempMpFile.Path); WaitForAFileTransfer(folder, tempMpFile.Name); } }
/// <summary> /// Creates a shell item from the Windows Shell32 library /// </summary> /// <param name="shellFolder">The shell folder</param> public ShellFolder(Folder3 shellFolder) : base(shellFolder == null ? null : shellFolder.Self as ShellFolderItem) { folder = shellFolder; }