示例#1
0
    private async void strip_update(object sender, EventArgs e)
    {
        statusprogress.Visible = true;
        string penis = await currentcomic.source.fetchURL(stripretriever, ctk, date.Value);         //String.Format(currentcomic.urlFormat, date.Value)

        Uri  f**k;
        bool good = Uri.TryCreate(penis, UriKind.Absolute, out f**k);

        if (!good)
        {
            Uri.TryCreate(Path.GetFullPath(penis), UriKind.Absolute, out f**k);
        }
        //why in the world does absoluteuri return a string and not an uri

        /*
         * had to break my balls for this one.
         * none of the uri class methods don't even f*****g support
         * relative paths.
         */
        Image img;

        if (f**k.IsFile)
        {
            string path = f**k.LocalPath;
            try{
                FileStream fs = await Task.Run(() => File.OpenRead(path));                //File.OpenRead(path); its asynchronous now lol

                img = Image.FromStream(fs, false, false);
            }
            catch (FileNotFoundException suck)
            {
                img = BitmapUtils.drawMessage("not found");
            }
            catch (IOException suck)
            {
                img = BitmapUtils.drawMessage("i/o exception.\nyour file must be locked.", 36);
            }
        }
        else
        {
            HttpResponseMessage response = new HttpResponseMessage();
            try
            {
                //Stream stream = stripretriever.OpenRead(String.Format(currentcomic.urlFormat, date.Value));
                //ctk.Cancel();
                response = await currentcomic.source.fetch(penis, stripretriever, ctk);

                // response = await stripretriever.GetAsync(f**k, ctk.Token);
                response.EnsureSuccessStatusCode();
                Stream stream = await response.Content.ReadAsStreamAsync();

                img = Image.FromStream(stream, false, false);
            }
            catch (HttpRequestException suck)
            {
                //MessageBox.Show(suck.ToString());
                img = BitmapUtils.drawMessage(((int)(response.StatusCode)).ToString());
            }
            catch (ArgumentException suck)
            {
                img = BitmapUtils.drawMessage("an error occured while\nprocessing the image", 36);
            }
        }
        Bitmap bm = BitmapUtils.shittyCopy(img);         // wish i could be using "using" here

        foreach (Gimmick gimmick in gimmicks.gimmicks)
        {
            if (gimmick.enabled)
            {
                img = gimmick.doIt(bm, img, currentcomic);
                bm  = BitmapUtils.shittyCopy(img);
                // just found out Bitmap extends Image. what a waste
                // THis is prone to exceptions and im not doing anything abouti t
            }
        }
        bm.Dispose();
        strip.Image            = img;
        statusprogress.Visible = false;
        statusdate.Text        = date.Value.ToString("d");
    }