Esempio n. 1
0
        private bool TryGetSelectedPath(out string path)
        {
            path = "";
            Folder folder = shell.BrowseForFolder((int)form.Handle, "בחר תיקיית מוזיקה", 0);

            if (folder != null)
            {
                path = RemoveBadStringFromPath((Folder3)folder);
                return(true);
            }
            return(false);
        }
Esempio n. 2
0
        private void syncDirBrowseButton_Click(object sender, EventArgs e)
        {
            Shell  shell  = new Shell();
            Folder folder = shell.BrowseForFolder((int)this.Handle, "", 0, 0);

            if (folder == null)
            {
                return;
            }
            FolderItem fi = (folder as Folder3).Self;

            defaults.PlaylistSync.SyncDirectory = fi.Path;
            syncDirLabel.Text = defaults.PlaylistSync.SyncDirectory;
        }
Esempio n. 3
0
        // ----------------------------------------------------------------------------------------------------------

        public static string FolderBrowserDialogAPI(string title = "Select a folder:")
        {
            const int BIF_NEWDIALOGSTYLE = 0x40;
            const int BIF_VALIDATE       = 0x20;
            const int BIF_EDITBOX        = 0x10;      // Does not exist in FolderBrowserDialog()
            const int OPTIONS            = BIF_NEWDIALOGSTYLE + BIF_VALIDATE + BIF_EDITBOX;
            var       shell  = new Shell();
            var       folder = (Folder2)shell.BrowseForFolder(System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle.ToInt32(), title, OPTIONS);

            if (folder == null)
            {
                return("");
            }
            return(folder.Self.Path);
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            Shell shell = new Shell();

            // open dialog for desktop folder
            // use appropriate constant for folder type - ShellSpecialFolderConstants
            Folder folder = shell.BrowseForFolder(0, "Get some folder from user...", 0, ShellSpecialFolderConstants.ssfDESKTOP);

            if (folder != null)
            {
                foreach (FolderItem fi in folder.Items())
                {
                    Console.WriteLine(fi.Name + fi.Size.ToString());
                }
            }

            Console.ReadLine();
        }
Esempio n. 5
0
        private void ParseAndAddUrl(UrlResolver r, bool syncMode)
        {
            if (!r.HasParsedUrl)
            {
                return;
            }
            if (isListViewDirty)
            {
                CleanQueueListView();
            }
#if !DEBUG
            try
            {
#endif
            // Don't add if the item is already enqueued.
            var isAlreadyInQueue = mediaDownloadQueue.ItemById(r.ParseResult.Id) != null;
            if (isAlreadyInQueue)
            {
                TaskDialogHelper.ShowMessage(owner: Handle, icon: TaskDialogStandardIcon.Error,
                                             caption: "Cannot add to download queue",
                                             message: "This item already exists in the download queue.",
                                             buttons: TaskDialogStandardButtons.Ok);
                return;
            }

            // Ask for the location if required before we begin retrieval
            var prefType    = PreferenceForType(r.ParseResult.Type);
            var saveDir     = prefType.SaveDirectory;
            var folderItems = new List <string>();
            if (prefType.AskForLocation || syncMode)
            {
                Shell  shell  = new Shell();
                Folder folder = shell.BrowseForFolder((int)this.Handle, "Select a destination for this media:", 0, Program.DefaultSettings.Settings.PlaylistSync.SyncDirectory);
                if (folder == null)
                {
                    return;
                }
                FolderItem fi = (folder as Folder3).Self;
                saveDir = fi.Path;
                foreach (FolderItem curr in folder.Items())
                {
                    folderItems.Add(Path.GetFileNameWithoutExtension(curr.Name));
                }


                //using (var folderSelectionDialog = new FolderBrowserDialog { Description = "Select a destination for this media:" })
                //{
                //    if (folderSelectionDialog.ShowDialog(this) == DialogResult.OK)
                //    {
                //        saveDir = folderSelectionDialog.SelectedPath;
                //    }
                //    else
                //    {
                //        return;
                //    }
                //}
            }


            // Build wait dialog
            var retrievalWaitTaskDialog = new TaskDialog
            {
                Cancelable        = false,
                Caption           = "Athame",
                InstructionText   = $"Getting {r.ParseResult.Type.ToString().ToLower()} details...",
                Text              = $"{r.Service.Info.Name}: {r.ParseResult.Id}",
                StandardButtons   = TaskDialogStandardButtons.Cancel,
                OwnerWindowHandle = Handle,
                ProgressBar       = new TaskDialogProgressBar {
                    State = TaskDialogProgressBarState.Marquee
                }
            };



            // Open handler
            retrievalWaitTaskDialog.Opened += async(o, args) =>
            {
                LockUi();
                var  pathFormat  = prefType.GetPlatformSaveFormat();
                var  finalTracks = new List <string>();
                bool isPlaylist  = false;
                try
                {
                    var media = await r.ResolveAsync(syncMode, folderItems, finalTracks);

                    isPlaylist = r.ParseResult.Type == MediaType.Playlist;
                    AddToQueue(r.Service, media, saveDir, pathFormat);
                }
                catch (ResourceNotFoundException)
                {
                    TaskDialogHelper.ShowMessage(caption: "This media does not exist.",
                                                 message: "Ensure the provided URL is valid, and try again", owner: Handle,
                                                 buttons: TaskDialogStandardButtons.Ok, icon: TaskDialogStandardIcon.Information);
                }
                catch (NotImplementedException)
                {
                    TaskDialogHelper.ShowMessage(
                        owner: Handle, icon: TaskDialogStandardIcon.Warning, buttons: TaskDialogStandardButtons.Ok,
                        caption: $"'{r.ParseResult.Type}' is not supported yet.",
                        message: "You may be able to download it in a later release.");
                }
                catch (Exception ex)
                {
                    Log.WriteException(Level.Error, Tag, ex, "While attempting to resolve media");
                    TaskDialogHelper.ShowExceptionDialog(ex,
                                                         "An error occurred while trying to retrieve information for this media.",
                                                         "The provided URL may be invalid or unsupported.", Handle);
                }

                idTextBox.Clear();
                UnlockUi();
                retrievalWaitTaskDialog.Close();
                if (syncMode && isPlaylist)
                {
                    var toDelete = new List <string>();
                    foreach (var curTrack in folderItems)
                    {
                        if (!finalTracks.Contains(curTrack))
                        {
                            toDelete.Add(curTrack);
                        }
                    }
                    if (toDelete.Count > 0)
                    {
                        DialogResult dialogResult = MessageBox.Show("Delete " + toDelete.Count + " tracks, which is not in playlist?", "Confirm delete", MessageBoxButtons.YesNo);
                        if (dialogResult == DialogResult.Yes)
                        {
                            DirectoryInfo di = new DirectoryInfo(saveDir);
                            foreach (FileInfo file in di.GetFiles())
                            {
                                if (toDelete.Contains(Path.GetFileNameWithoutExtension(file.Name)))
                                {
                                    file.Delete();
                                }
                            }
                        }
                    }
                }
                else if (!isPlaylist && syncMode)
                {
                    MessageBox.Show("Can't sync if not playlist");
                }
            };
            // Show dialog
            retrievalWaitTaskDialog.Show();
#if !DEBUG
        }

        catch (Exception ex)
        {
            PresentException(ex);
        }
#endif
        }