예제 #1
0
        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));
        }
예제 #2
0
        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);
            }
        }