예제 #1
0
        public VSButton LoadUri(Uri Uri, IHost Host)
        {
            Status = CurrentLanguage.LoadingComic;

            CurrentHost = CreateInstance(Host);

            CurrentInfo     = CurrentHost.LoadUri(Uri);
            TitleLabel.Text = CurrentInfo.Title;
            CoverBox.Image  = CurrentHost.GetDecoder().Decode(CurrentInfo.Cover);

            if (CurrentInfo.Url == null)
            {
                CurrentInfo.Url = Uri;
            }

            CoverBox.Cursor = Cursors.Default;

            string Dir = DataTools.GetRawName(CurrentInfo.Title.Trim(), FileNameMode: true);

            ChapterTools.MatchLibraryPath(ref Dir, Settings.LibraryPath, CurrentInfo.Url, ReplaceMode.UpdateURL, CurrentLanguage);
            RefreshCoverLink(Dir);

            var OnlinePath = Path.Combine(Settings.LibraryPath, Dir, "Online.url");

            if (Directory.Exists(Dir) && !File.Exists(OnlinePath))
            {
                var OnlineData = string.Format(Properties.Resources.UrlFile, CurrentInfo.Url.AbsoluteUri);
                File.WriteAllText(OnlinePath, OnlineData);
            }

            ButtonsContainer.Controls.Clear();

            VSButton DownAll = null;

            var Chapters = new Dictionary <int, string>();

            foreach (var Chapter in CurrentHost.EnumChapters())
            {
                if (Chapters.ContainsValue(Chapter.Value))
                {
                    continue;
                }

                VSButton Button = new VSButton()
                {
                    Size        = new Size(110, 30),
                    Text        = string.Format(CurrentLanguage.ChapterName, Chapter.Value),
                    Indentifier = CurrentHost
                };

                Button.Click += (sender, args) =>
                {
                    try
                    {
                        IHost HostIsnt = (IHost)((VSButton)sender).Indentifier;
                        DownloadChapter(Chapters, Chapter.Key, HostIsnt, CurrentInfo);
                    }
                    catch (Exception ex)
                    {
                        if (Program.Debug)
                        {
                            throw;
                        }
                    }
                    StatusBar.SecondLabelText = string.Empty;
                    Status = CurrentLanguage.IDLE;
                };

                DownAll = Button;

                ButtonsContainer.Controls.Add(Button);
                Chapters.Add(Chapter.Key, Chapter.Value);
            }

            if (Chapters.Count > 1)
            {
                VSButton Button = new VSButton()
                {
                    Size        = new Size(110, 30),
                    Text        = CurrentLanguage.DownloadAll,
                    Indentifier = CurrentHost
                };

                Button.Click += (sender, args) =>
                {
                    foreach (var Chapter in Chapters.Reverse())
                    {
                        try
                        {
                            IHost HostIsnt = (IHost)((VSButton)sender).Indentifier;
                            DownloadChapter(Chapters, Chapter.Key, HostIsnt, CurrentInfo);
                        }
                        catch (Exception ex)
                        {
                            if (Program.Debug)
                            {
                                throw;
                            }
                        }

                        StatusBar.SecondLabelText = string.Empty;
                        Status = CurrentLanguage.IDLE;
                    }
                };
                DownAll = Button;
                ButtonsContainer.Controls.Add(Button);
            }

            var PActions = CurrentHost.GetPluginInfo().Actions;

            if (PActions != null)
            {
                var Actions = (from x in PActions where x.Availability.HasFlag(ActionTo.ChapterList) select x);

                if (Actions.Any())
                {
                    foreach (var Action in Actions)
                    {
                        VSButton Bnt = new VSButton()
                        {
                            Size        = new Size(110, 30),
                            Text        = Action.Name,
                            Indentifier = CurrentHost
                        };
                        Bnt.Click += (sender, args) => Action.Action();
                        ButtonsContainer.Controls.Add(Bnt);
                    }
                    ;
                }
            }

            Status = CurrentLanguage.IDLE;

            return(DownAll);
        }