Example #1
0
        public void Start(string host, string url, string novelName, string maxPage, string updateMode)
        {
            try
            {
                IsRunning = true;
                StartTime = DateTime.Now;

                LogFile = DateTime.Now.ToString("yyyyMMdd_HHmmssfff") + ".txt";

                novelName = FileDownloadUtil.GetInvalidPath(novelName);

                SaveTo = string.Format("{0}/Downloads", AppDomain.CurrentDomain.BaseDirectory);

                if (string.IsNullOrEmpty(novelName))
                {
                    mLogSaveToFileUrl = "Downloads/" + LogFile;
                }
                else
                {
                    mLogSaveToFileUrl = "Downloads/" + novelName + "/" + LogFile;
                }

                mSaveToDirectory = SaveTo + System.IO.Path.DirectorySeparatorChar + novelName;

                SetLog(mSaveToDirectory);

                Url  = url;
                Host = host;

                ProgressArgs arg = new ProgressArgs();
                arg.Progress = ProgressEnum.Progressing;
                FireOnProgressChangedEvent(arg);

                if (string.IsNullOrEmpty(novelName))
                {
                    Logger.Instance.Error("Novel Name can't be empty");

                    EndTime      = DateTime.Now;
                    arg.Progress = ProgressEnum.FinishFailed;
                    FireOnProgressChangedEvent(arg);

                    return;
                }


                NovelName = novelName;

                if (!int.TryParse(maxPage, out MaxPages))
                {
                    MaxPages = 1000;
                    Logger.Instance.Error("Use Default Max Pages 1000");
                }

                UpdateMode = !updateMode.Equals("YES", StringComparison.OrdinalIgnoreCase);

                if (Host.TrimStart().TrimEnd().Equals("BIQUGE", StringComparison.OrdinalIgnoreCase) ||
                    Host.TrimStart().TrimEnd().Equals("BIQUGE.COM", StringComparison.OrdinalIgnoreCase))
                {
                    download = new BiqugeDownloadImagesText(Url, SaveTo, NovelName, UpdateMode, MaxPages);
                }
                else if (Host.TrimStart().TrimEnd().Equals("BIQUGE.CO", StringComparison.OrdinalIgnoreCase))
                {
                    download = new BiqugeCODownloadImagesText(Url, SaveTo, NovelName, UpdateMode, MaxPages);
                }
                else if (Host.TrimStart().TrimEnd().Equals("DAYANWENXUE", StringComparison.OrdinalIgnoreCase) ||
                         Host.TrimStart().TrimEnd().Equals("DAYANWENXUE.COM", StringComparison.OrdinalIgnoreCase))
                {
                    download = new DayanwenxueDownloadImagesText(Url, SaveTo, NovelName, UpdateMode, MaxPages);
                }
                else if (Host.TrimStart().TrimEnd().Equals("XIAOSHUOM", StringComparison.OrdinalIgnoreCase) ||
                         Host.TrimStart().TrimEnd().Equals("XIAOSHUOM.COM", StringComparison.OrdinalIgnoreCase))
                {
                    download = new XiaoshuomDownloadImagesText(Url, SaveTo, NovelName, UpdateMode, MaxPages);
                }
                else if (Host.TrimStart().TrimEnd().Equals("SHUKEJU", StringComparison.OrdinalIgnoreCase) ||
                         Host.TrimStart().TrimEnd().Equals("SHUKEJU.COM", StringComparison.OrdinalIgnoreCase))
                {
                    download = new ShukejuDownloadImagesText(Url, SaveTo, NovelName, UpdateMode, MaxPages);
                }
                else if (Host.TrimStart().TrimEnd().Equals("WENXUELOU", StringComparison.OrdinalIgnoreCase) ||
                         Host.TrimStart().TrimEnd().Equals("WENXUELOU.COM", StringComparison.OrdinalIgnoreCase))
                {
                    download = new WenxuelouDownloadImagesText(Url, SaveTo, NovelName, UpdateMode, MaxPages);
                }
                else if (Host.TrimStart().TrimEnd().Equals("BIQUGE", StringComparison.OrdinalIgnoreCase) ||
                         Host.TrimStart().TrimEnd().Equals("BIQUGE.CC", StringComparison.OrdinalIgnoreCase))
                {
                    download = new BiqugeCCDownloadImagesText(Url, SaveTo, NovelName, UpdateMode, MaxPages);
                }
                else
                {
                    Logger.Instance.Error("Can't find plug-in for this host");

                    EndTime      = DateTime.Now;
                    arg.Progress = ProgressEnum.FinishFailed;
                    FireOnProgressChangedEvent(arg);

                    return;
                }

                if (download != null)
                {
                    download.CopyFiles();

                    download.OnProgressChanged += new ProgressChangeDelegate(download_OnProgressChanged);

                    thread = new Thread(new ThreadStart(download.ProcessAllOneByOne));
                    thread.Start();
                }
            }
            catch (Exception ex)
            {
                Logger.Instance.Error(ex.ToString());
                ProgressArgs arg = new ProgressArgs();
                arg.Progress = ProgressEnum.FinishFailed;
                FireOnProgressChangedEvent(arg);
            }
            finally
            {
                IsRunning = false;
            }
        }
        public void Start(string host, string url, string novelName, string maxPage, string updateMode, string saveTo)
        {
            try
            {
                IsRunning = true;
                StartTime = DateTime.Now;

                Url  = url;
                Host = host;

                ProgressArgs arg = new ProgressArgs();
                arg.Progress = ProgressEnum.Progressing;
                FireOnProgressChangedEvent(arg);

                if (string.IsNullOrEmpty(novelName))
                {
                    Logger.Instance.Error("Novel Name can't be empty");

                    EndTime      = DateTime.Now;
                    arg.Progress = ProgressEnum.FinishFailed;
                    FireOnProgressChangedEvent(arg);

                    return;
                }

                SaveTo    = saveTo;
                NovelName = novelName;

                if (string.IsNullOrEmpty(SaveTo))
                {
                    SaveTo = string.Format("{0}\\DOWNLOAD", AppDomain.CurrentDomain.BaseDirectory);
                }

                if (!int.TryParse(maxPage, out MaxPages))
                {
                    MaxPages = 1000;
                    Logger.Instance.Error("Use Default Max Pages 1000");
                }

                UpdateMode = !updateMode.Equals("YES", StringComparison.OrdinalIgnoreCase);


                if (Host.TrimStart().TrimEnd().Equals("BIQUGE", StringComparison.OrdinalIgnoreCase) ||
                    Host.TrimStart().TrimEnd().Equals("BIQUGE.COM", StringComparison.OrdinalIgnoreCase))
                {
                    download = new BiqugeDownloadImagesText(Url, SaveTo, NovelName, UpdateMode, MaxPages);
                }
                else if (Host.TrimStart().TrimEnd().Equals("BIQUGE.CO", StringComparison.OrdinalIgnoreCase))
                {
                    download = new BiqugeCODownloadImagesText(Url, SaveTo, NovelName, UpdateMode, MaxPages);
                }
                else if (Host.TrimStart().TrimEnd().Equals("DAYANWENXUE", StringComparison.OrdinalIgnoreCase) ||
                         Host.TrimStart().TrimEnd().Equals("DAYANWENXUE.COM", StringComparison.OrdinalIgnoreCase))
                {
                    download = new DayanwenxueDownloadImagesText(Url, SaveTo, NovelName, UpdateMode, MaxPages);
                }
                else if (Host.TrimStart().TrimEnd().Equals("XIAOSHUOM", StringComparison.OrdinalIgnoreCase) ||
                         Host.TrimStart().TrimEnd().Equals("XIAOSHUOM.COM", StringComparison.OrdinalIgnoreCase))
                {
                    download = new XiaoshuomDownloadImagesText(Url, SaveTo, NovelName, UpdateMode, MaxPages);
                }
                else if (Host.TrimStart().TrimEnd().Equals("SHUKEJU", StringComparison.OrdinalIgnoreCase) ||
                         Host.TrimStart().TrimEnd().Equals("SHUKEJU.COM", StringComparison.OrdinalIgnoreCase))
                {
                    download = new ShukejuDownloadImagesText(Url, SaveTo, NovelName, UpdateMode, MaxPages);
                }
                else if (Host.TrimStart().TrimEnd().Equals("WENXUELOU", StringComparison.OrdinalIgnoreCase) ||
                         Host.TrimStart().TrimEnd().Equals("WENXUELOU.COM", StringComparison.OrdinalIgnoreCase))
                {
                    download = new WenxuelouDownloadImagesText(Url, SaveTo, NovelName, UpdateMode, MaxPages);
                }
                else if (Host.TrimStart().TrimEnd().Equals("BIQUGE", StringComparison.OrdinalIgnoreCase) ||
                         Host.TrimStart().TrimEnd().Equals("BIQUGE.CC", StringComparison.OrdinalIgnoreCase))
                {
                    download = new BiqugeCCDownloadImagesText(Url, SaveTo, NovelName, UpdateMode, MaxPages);
                }
                else if (Host.TrimStart().TrimEnd().Equals("1KANSHU", StringComparison.OrdinalIgnoreCase) ||
                         Host.TrimStart().TrimEnd().Equals("1KANSHU.COM", StringComparison.OrdinalIgnoreCase))
                {
                    download = new YaokanShuDownloadImagesText(Url, SaveTo, NovelName, UpdateMode, MaxPages);
                }
                else if (Host.TrimStart().TrimEnd().Equals("AOYECC", StringComparison.OrdinalIgnoreCase) ||
                         Host.TrimStart().TrimEnd().Equals("AOYE.CC", StringComparison.OrdinalIgnoreCase))
                {
                    download = new AoyeCCDownloadImagesText(Url, SaveTo, NovelName, UpdateMode, MaxPages);
                }
                else
                {
                    Logger.Instance.Error("Can't find plug-in for this host");

                    EndTime      = DateTime.Now;
                    arg.Progress = ProgressEnum.FinishFailed;
                    FireOnProgressChangedEvent(arg);

                    return;
                }


                if (download != null)
                {
                    download.CopyFiles();
                    download.SaveToConfig();

                    string arguments = BuildArguments(host, url, novelName, maxPage, updateMode, saveTo);

                    download.SaveLastWorkingArguments(arguments);

                    download.OnProgressChanged += new ProgressChangeDelegate(download_OnProgressChanged);

                    thread = new Thread(new ThreadStart(download.ProcessAllOneByOne));
                    thread.Start();
                }
            }
            catch (Exception ex)
            {
                Logger.Instance.Error(ex.ToString());
                ProgressArgs arg = new ProgressArgs();
                arg.Progress = ProgressEnum.FinishFailed;
                FireOnProgressChangedEvent(arg);
            }
        }