Esempio n. 1
0
 public static Panel GetFindNewPanel(Guid pluginID, object view)
 {
     if (Provider.Handler.Exists(pluginID))
     {
         findNewPluginInst = Provider.Handler.GetFromId(pluginID).CreateInstance();
         findNewPluginInst.FindNewException  += FindNewPluginInst_FindNewException;
         findNewPluginInst.FindNewViewChange += FindNewPluginInst_FindNewViewChange;
         findNewPluginInst.FoundNew          += FindNewPluginInst_FoundNew;
         return(findNewPluginInst.GetFindNewPanel(view));
     }
     else
     {
         return(new Panel());
     }
 }
Esempio n. 2
0
        private static void ExamineAssembly(Assembly assembly)
        {
            // Loop through each type in the assembly
            foreach (Type thisType in assembly.GetTypes())
            {
                // Only look at public types
                if (thisType.IsPublic)
                {
                    // Ignore abstract classes
                    if (!((thisType.Attributes & TypeAttributes.Abstract) == TypeAttributes.Abstract))
                    {
                        if (thisType.IsSubclassOf(typeof(RadioProvider)))
                        {
                            Handler provider = new Handler();
                            provider.assembly  = assembly;
                            provider.fullClass = thisType.FullName;
                            provider.Class     = thisType.Name;

                            try
                            {
                                RadioProvider instance = (RadioProvider)assembly.CreateInstance(thisType.FullName);
                                provider.Id                      = instance.ProviderId;
                                provider.Name                    = instance.ProviderName;
                                provider.Description             = instance.ProviderDescription;
                                provider.Icon                    = instance.ProviderIcon;
                                provider.ShowOptionsHandler      = instance.ShowOptionsHandler;
                                provider.ShowMoreProgInfoHandler = instance.ShowMoreProgInfoHandler;
                                availableProviders.Add(instance.ProviderId, provider);
                            }
                            catch
                            {
                                continue;
                            }
                        }
                    }
                }
            }
        }
        private void DownloadProgThread()
        {
            // Raise a progress event to give the user some feedback
            this.Progress?.Invoke(this.episodeInfo.Epid, 0, Provider.ProgressType.Downloading);

            if (!Provider.Handler.Exists(this.pluginId))
            {
                this.DownloadError(Provider.ErrorType.LocalProblem, "The plugin provider required to download this episode is not currently available.  Please try updating the Radio Downloader providers or cancelling the download.");
                return;
            }

            lock (this.pluginInstanceLock)
            {
                this.pluginInstance           = Provider.Handler.GetFromId(this.pluginId).CreateInstance();
                this.pluginInstance.Progress += this.DownloadPluginInst_Progress;
            }

            string saveLocation;

            try
            {
                saveLocation = FileUtils.GetSaveFolder();
            }
            catch (DirectoryNotFoundException)
            {
                this.DownloadError(Provider.ErrorType.LocalProblem, "Your chosen location for saving downloaded programmes no longer exists.  Select a new one under Options -> Main Options.");
                return;
            }

            const int FreeMb         = 250;
            ulong     availableSpace = OsUtils.PathAvailableSpace(saveLocation);

            if (availableSpace <= FreeMb * 1024 * 1024)
            {
                this.DownloadError(Provider.ErrorType.LocalProblem, "Your chosen location for saving downloaded programmes does not have enough free space.  Make sure that you have at least " + FreeMb.ToString(CultureInfo.CurrentCulture) + " MB free, or select a new location under Options -> Main Options.");
                return;
            }

            Provider.DownloadInfo info = null;

            try
            {
                try
                {
                    info = this.pluginInstance.DownloadProgramme(this.progExtId, this.episodeExtId, this.providerProgInfo, this.providerEpisodeInfo);
                }
                catch (Provider.DownloadException downloadExp)
                {
                    if (downloadExp.ErrorType == Provider.ErrorType.UnknownError)
                    {
                        this.DownloadError(downloadExp);
                    }
                    else
                    {
                        this.DownloadError(downloadExp.ErrorType, downloadExp.Message);
                    }

                    return;
                }
                catch (Exception unknownExp)
                {
                    this.DownloadError(unknownExp);
                    return;
                }

                if (this.cancelled)
                {
                    this.cancelResponse = true;
                    return;
                }

                string finalName;

                try
                {
                    finalName = Model.Download.MoveToSaveFolder(Settings.FileNameFormat, this.progInfo, this.episodeInfo, saveLocation, info.Extension, info.Downloaded.FilePath);
                }
                catch (IOException ioExp)
                {
                    this.DownloadError(Provider.ErrorType.LocalProblem, "Encountered an error saving the downloaded file.  " + ioExp.Message + "  You may need to select a new location for saving downloaded programmes under Options -> Main Options.");
                    return;
                }
                catch (UnauthorizedAccessException unAuthExp)
                {
                    this.DownloadError(Provider.ErrorType.LocalProblem, "Encountered a permissions problem saving the downloaded file.  " + unAuthExp.Message + "  You may need to select a new location for saving downloaded programmes under Options -> Main Options.");
                    return;
                }

                lock (DbUpdateLock)
                {
                    Model.Download.SetComplete(this.episodeInfo.Epid, finalName, info);
                    Model.Programme.SetLatestDownload(this.progInfo.Progid, this.episodeInfo.Date);
                }

                // Remove single episode subscriptions
                if (Model.Subscription.IsSubscribed(this.progInfo.Progid))
                {
                    if (this.progInfo.SingleEpisode)
                    {
                        Model.Subscription.Remove(this.progInfo.Progid);
                    }
                }

                if (!string.IsNullOrEmpty(Settings.RunAfterCommand))
                {
                    try
                    {
                        // Use VB Interaction.Shell as Process.Start doesn't give the option of a non-focused window
                        // The "comspec" environment variable gives the path to cmd.exe
                        Microsoft.VisualBasic.Interaction.Shell("\"" + Environment.GetEnvironmentVariable("comspec") + "\" /c " + Settings.RunAfterCommand.Replace("%file%", finalName), Microsoft.VisualBasic.AppWinStyle.NormalNoFocus);
                    }
                    catch
                    {
                        // Just ignore the error, as it just means that something has gone wrong with the run after command.
                    }
                }
            }
            finally
            {
                info?.Dispose();
            }

            this.DownloadFinished();
        }