Example #1
0
 /// <summary>
 /// Reports an error to the user, and provides the option to report if the crash is critical enough
 /// </summary>
 /// <param name="message">Message to show to the user</param>
 /// <param name="inner">The exception that was thrown/raised</param>
 /// <param name="canReport">If the crash should be allowed to be reported to Bugsense</param>
 public static void Throw(String message, Exception inner, bool canReport = true)
 {
     Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US");
     Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
     var handled = inner as HandledException;
     var criticalHandled = handled != null && handled.IsCritical;
     // Use the exception message if it is of type HandledException or a message wasn't passed through
     // If it is a HandledException, only provide the option to report if the exception is critical
     var dialog = new YesNoDialog("ERROR:\n" + (handled != null ? inner.Message : (message ?? inner.Message)),
         (handled == null && canReport) || criticalHandled ? "Report" : "Close",
         (handled == null && canReport) || criticalHandled ? "Close" : null)
     {
         ResponseCallback = result =>
         {
             // Log exception only if 'Report' was chosen, and the exception was critical
             if (result && canReport)
                 BugSenseHandler.Instance.SendExceptionAsync(inner);
             ClearExtras();
         }
     };
     dialog.Show();
 }
Example #2
0
 /// <summary>
 /// Checks if confirmation is needed before exiting, then exits.
 /// (Unless cancelled by the user)
 /// </summary>
 /// <param name="sender">Not used</param>
 /// <param name="eventArgs">Not used</param>
 private void ConfirmExitApplication(object sender, EventArgs eventArgs)
 {
     if (Settings.ConfirmExit)
     {
         var dialog =
             new YesNoDialog(
                 "Are you sure you want to exit? SDownload requires this application to be running in order to download any songs!",
                 "Close", "Cancel", CheckBoxState.NotChecked)
                 {
                     ResponseCallback = result =>
                                            {
                                                if (result)
                                                    Exit();
                                            },
                     CheckBoxSettingCallback = result => Settings.ConfirmExit = !result
                 };
         dialog.Show();
     }
     else
         Exit();
 }
Example #3
0
        /// <summary>
        /// Add the song to iTunes
        /// </summary>
        private void AddToiTunes()
        {
            var newdir = String.Format("{0}\\iTunes\\iTunes Media\\Automatically Add to iTunes\\{1}.{2}", 
                Settings.CustomITunesLocation ?? Environment.GetFolderPath(Environment.SpecialFolder.MyMusic), GetCleanFileName(_title), 
                MainResource.AbsolutePath.Substring(MainResource.AbsolutePath.Length-3));

            if (File.Exists(newdir))
            {
                // Insert random string into dest filename as to not overwrite old file
                var endingIndex = (newdir.Length - 1) - 4;
                var ending = newdir.Substring(endingIndex);
                newdir = newdir.Remove(endingIndex) + GenerateRandomString(3) + ending;
            }

            try
            {
                switch (Settings.TunesTransfer)
                {
                    case Settings.TunesSetting.Move:
                        {
                            BugSenseHandler.Instance.LeaveBreadCrumb("Moving song to iTunes");
                            File.Move(MainResource.AbsolutePath, newdir);

                            // Delete the artist folder if empty
                            if (Settings.AuthorFolder && MainResource.AbsolutePath.StartsWith(Settings.DownloadFolder + _author) 
                                && !Directory.EnumerateFileSystemEntries(Settings.DownloadFolder + _author).Any())
                            {
                                Directory.Delete(Settings.DownloadFolder + _author);
                            }
                            break;
                        }
                    case Settings.TunesSetting.Copy:
                        BugSenseHandler.Instance.LeaveBreadCrumb("Copying song to iTunes");
                        File.Copy(MainResource.AbsolutePath, newdir);
                        break;
                }
            }
            catch (DirectoryNotFoundException)
            {
                // Find iTunes location if it exists
                var dialog = new YesNoDialog(Resources.ErrorCantFindITunes, "Locate", "Disable")
                                 {
                                     ResponseCallback = result =>
                                                            {
                                                                if (result)
                                                                {
                                                                    // User would like to find installation on disk
                                                                    var folderBrowser = new FolderBrowserDialog
                                                                                            {
                                                                                                Description = Resources.FolderBrowserDescriptionFindITunes
                                                                                            };
                                                                    folderBrowser.ShowDialog();
                                                                    // TODO: Better validate if this is a correct iTunes directory
                                                                    if (folderBrowser.SelectedPath.EndsWith("iTunes"))
                                                                    {
                                                                        // Valid iTunes installation
                                                                        Settings.CustomITunesLocation =
                                                                            folderBrowser.SelectedPath;
                                                                    }
                                                                } else
                                                                {
                                                                    // User wants to disable iTunes functionality
                                                                    Settings.TunesTransfer =
                                                                        Settings.TunesSetting.Nothing;
                                                                }
                                                            }
                                 };
                dialog.Show();
            }
        }