Exemplo n.º 1
0
        public bool Config(string cookie, Server server, bool skipVerification = false)
        {
            if (!skipVerification)
            {
                bool isVaild = false;
                switch (server)
                {
                case Server.Inso:
                    isVaild = Inso.IsCookieValid(cookie);
                    if (isVaild)
                    {
                        Inso.SetCookie(cookie);
                    }
                    break;

                case Server.Blooadcat:
                    isVaild = Bloodcat.IsCookieValid(cookie);
                    if (isVaild)
                    {
                        Bloodcat.SetCookie(cookie);
                    }
                    break;
                }
                IsServerVaild[server] = isVaild;
                return(isVaild);
            }
            else
            {
                switch (server)
                {
                case Server.Inso:
                    Inso.SetCookie(cookie);
                    break;

                case Server.Blooadcat:
                    Bloodcat.SetCookie(cookie);
                    break;
                }
                IsServerVaild[server] = true;
                return(true);
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            Console.Title = "osi_Console";
            Console.WriteLine("START");

            Configuration config      = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            var           appsettings = config.AppSettings.Settings;

            string InsoCookie;
            string BloodcatCookie;

            if (appsettings["FirstRun"].Value == "true")
            {
                string httpHash, httpsHash;

                RegisterAsDefaultBrowserFunction.Register(out httpHash, out httpsHash);
                if (httpHash != null)
                {
                    appsettings["HttpHash"].Value = httpHash;
                }
                if (httpsHash != null)
                {
                    appsettings["HttpsHash"].Value = httpsHash;
                }

                while (!(InputCookieFunction.InputInsoCookie(out InsoCookie) | InputCookieFunction.InputBloodcatCookie(out BloodcatCookie)))
                {
                    Console.WriteLine("请至少满足一个服务器的需求。");
                }
                if (InsoCookie != null)
                {
                    appsettings["InsoCookie"].Value = InsoCookie;
                }
                if (BloodcatCookie != null)
                {
                    appsettings["BloodcatCookie"].Value = BloodcatCookie;
                }
                appsettings["FirstRun"].Value = "false";
            }
            else
            {
                RegisterAsDefaultBrowserFunction.RegisterAsDefaultBrowser(appsettings["HttpHash"].Value, appsettings["HttpsHash"].Value);

                InsoCookie     = appsettings["InsoCookie"].Value;
                BloodcatCookie = appsettings["BloodcatCookie"].Value;
                if (InsoCookie != null)
                {
                    if (!Inso.IsCookieValid(InsoCookie))
                    {
                        Console.WriteLine("Inso Cookie已失效 请重新输入。");
                        InputCookieFunction.InputInsoCookie(out InsoCookie);
                        appsettings["InsoCookie"].Value = InsoCookie;
                    }
                    else
                    {
                        Console.WriteLine("do_not_remove_this_0w0" + " = " + InsoCookie);
                        Console.WriteLine("Inso Cookie有效。");
                    }
                }
                if (BloodcatCookie != null)
                {
                    if (!Bloodcat.IsCookieValid(BloodcatCookie))
                    {
                        Console.WriteLine("Bloodcat Cookie已失效 请重新输入。");
                        InputCookieFunction.InputBloodcatCookie(out BloodcatCookie);
                        appsettings["BloodcatCookie"].Value = BloodcatCookie;
                    }
                    else
                    {
                        Console.WriteLine("obm_human" + " = " + BloodcatCookie);
                        Console.WriteLine("Bloodcat Cookie有效。");
                    }
                }
            }
            config.Save();
            Console.CancelKeyPress += delegate(object sender, ConsoleCancelEventArgs e)
            {
            };

            DownloadManager downloadMgr = new DownloadManager();

            if (InsoCookie != null)
            {
                downloadMgr.Config(InsoCookie, Server.Inso, true);
            }
            if (BloodcatCookie != null)
            {
                downloadMgr.Config(BloodcatCookie, Server.Blooadcat, true);
            }
            downloadMgr.MaxDownloaderCount = 2;
            downloadMgr.FileWriter         = DownloadHepler.FileHelper.FileWrite;

            Console.WriteLine("Start Monitor", System.Drawing.Color.White);
            NamedPipeServerStream server = new NamedPipeServerStream("osi", PipeDirection.In);

            while (true)
            {
                server.WaitForConnection();

                StreamReader sr   = new StreamReader(server);
                string       link = sr.ReadToEnd();
                Console.WriteLine("Get Link" + " " + link);

                try
                {
                    BeatmapsetPackage package = new BeatmapsetPackage(new Beatmapset(link));
                    package.GetInfoCompleted += delegate(object sender, BeatmapsetPackage.BeatmapsetInfo e)
                    {
                        Console.WriteLine(e.beatmapsetId + " " + e.artist + "-" + e.title);
                    };
                    package.DownloadProgressChanged += delegate(object sender, BeatmapsetPackage.DownloadProgressChangedArgs e)
                    {
                        Console.WriteLine(e.Status);
                    };
                    package.WriteFileCompleted += delegate(object sender, BeatmapsetPackage.WriteFileCompletedArg e)
                    {
                        System.Diagnostics.Process.Start(e.Path);
                    };
                    downloadMgr.Add(package);
                }
                catch (Beatmapset.NotValidUri e)
                {
                }

                server.Disconnect();
            }
        }