Esempio n. 1
0
 /// <summary>
 /// Imgur access token
 /// </summary>
 private void button1_Click(object sender, EventArgs e)
 {
     Enabled = false;
     if (ImgurAPI.EnterPIN(form2, pin.Text))
     {
         Close();
     }
     else
     {
         Enabled = true;
     }
 }
Esempio n. 2
0
        private void DeleteImage_Click(object sender, EventArgs e)
        {
            var res = false;
            var li  = lastitem;

            if (lastlink.Contains("fastpic.ru"))
            {
                res = FastpicAPI.DeleteImage(this, lastlink, removeid);
            }
            else
            {
                res = ImgurAPI.DeleteImage(this, lastlink, removeid);
            }
            if (res)
            {
                li[4] = "3";
            }
        }
Esempio n. 3
0
 private void removefileorlink(ListViewItem item)
 {
     if (item.SubItems[4].Text == "1")
     {
         form1.DeleteFile(item.SubItems[3].Text);
         item.SubItems[4].Text = "3";
         events[item][4]       = "3";
         //selected.ForeColor = eventlist.ForeColor;
     }
     else if (item.SubItems[4].Text == "2" && item.SubItems[5].Text != "")
     {
         if (item.SubItems[3].Text.Contains("fastpic.ru"))
         {
             FastpicAPI.DeleteImage(form1, item.SubItems[3].Text, item.SubItems[5].Text);
         }
         else
         {
             ImgurAPI.DeleteImage(form1, item.SubItems[3].Text, item.SubItems[5].Text);
         }
         item.SubItems[4].Text = "3";
         events[item][4]       = "3";
     }
 }
Esempio n. 4
0
        private void uploadfile(bool bitmap = true)
        {
            byte[] data;
            if (bitmap && !imgedit)
            {
                data = BitmapToArray(lastres);
            }
            else
            {
                if (!File.Exists(lastfile))
                {
                    AddEvent(LocM.GetString("event_upload_err"));
                    MessageBox.Show(LocM.GetString("file_nf"), LocM.GetString("error"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                data = File.ReadAllBytes(lastfile);
            }

            upload.Enabled       = false;
            loadfrom.Enabled     = false;
            lastlabel.Text       = LocM.GetString("loading");
            lastlabel.Enabled    = false;
            TrayUpload.Enabled   = false;
            TrayCopyLink.Enabled = false;
            DeleteImage.Enabled  = false;
            removeid             = "";

            try {
                var link = "";
                if (Properties.Settings.Default.service == 1)
                {
                    link = ImgurAPI.UploadFile(this, data);
                }
                else if (Properties.Settings.Default.service == 2)
                {
                    Int32 unixTimestamp = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
                    var   FileName      = ConvertToBase(unixTimestamp, 36);
                    var   FileExt       = ImgFormatExt[Properties.Settings.Default.format];
                    link = FastpicAPI.UploadFile(this, data, FileName + "." + FileExt);
                }
                else
                {
                    link = WebServerAPI.UploadFile(this, data);
                }
                lastlink             = link;
                lastlabel.Text       = Path.GetFileName(link);
                lastlabel.Enabled    = true;
                TrayCopyLink.Enabled = true;
                AddEvent(LocM.GetString("event_upload"), lastlink, 2, removeid);
                if (Properties.Settings.Default.openlink)
                {
                    try {
                        System.Diagnostics.Process.Start(link);
                    } catch { }
                }
                if (Properties.Settings.Default.copylink)
                {
                    Clipboard.SetText(link);
                }
            } catch (Exception e) {
                lastlabel.Text       = LocM.GetString("error");
                lastlabel.Enabled    = false;
                TrayCopyLink.Enabled = false;
                AddEvent(LocM.GetString("event_upload_err"));
                MessageBox.Show(e.Message, LocM.GetString("error"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            if (lastres != null)
            {
                upload.Enabled     = true;
                TrayUpload.Enabled = true;
            }
            loadfrom.Enabled = true;

            /* Disabled due to .NET framework 3.5 (win xp support)
             * code is fully working
             * HttpContent bytesContent = new ByteArrayContent(data);
             * using (var client = new HttpClient())
             * using (var formData = new MultipartFormDataContent()) {
             *  var url = "";
             *  if (Properties.Settings.Default.service == 0) {
             *      client.DefaultRequestHeaders.Add("User-Agent", Properties.Settings.Default.agent);
             *      url = Properties.Settings.Default.svurl;
             *      formData.Add(new StringContent(Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName), "lang");
             *  } else {
             *      if (Properties.Settings.Default.access_token != "") {
             *          client.DefaultRequestHeaders.Add("Authorization", "Bearer " + Properties.Settings.Default.access_token);
             *      } else {
             *          client.DefaultRequestHeaders.Add("Authorization", "Client-ID " + clientid);
             *      }
             *      url = "https://api.imgur.com/3/image.xml";
             *  }
             *
             *  formData.Add(bytesContent, "image", "image");
             *  try {
             *      var response = client.PostAsync(url, formData).Result;
             *
             *      if (!response.IsSuccessStatusCode) {
             *          MessageBox.Show(response.ReasonPhrase, LocM.GetString("error"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
             *          lastlabel.Text = LocM.GetString("error");
             *          lastlabel.Enabled = false;
             *      } else {
             *          var result = response.Content.ReadAsStringAsync().Result;
             *          //Debug.WriteLine(result);
             *          var link = "";
             *          if (Properties.Settings.Default.service == 0) {
             *              if (result.StartsWith("http")) {
             *                  link = result;
             *              } else {
             *                  if (result == "") result = LocM.GetString("sv_err");
             *                  MessageBox.Show(result, LocM.GetString("error"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
             *                  load.Enabled = true;
             *                  loadfrom.Enabled = true;
             *                  lastlabel.Text = LocM.GetString("error");
             *                  lastlabel.Enabled = false;
             *                  return;
             *              }
             *          } else {
             *              XmlDocument doc = new XmlDocument();
             *              doc.LoadXml(result);
             *              link = doc.DocumentElement.SelectSingleNode("/data/link").InnerText;
             *          }
             *          response.Dispose();
             *          lastlink = link;
             *          lastlabel.Text = Path.GetFileName(link);
             *          lastlabel.Enabled = true;
             *          if (Properties.Settings.Default.openlink) {
             *              System.Diagnostics.Process.Start(link);
             *          }
             *          if (Properties.Settings.Default.copylink) {
             *              Clipboard.SetText(link);
             *          }
             *      //}
             *  } catch (Exception e) {
             *      lastlabel.Text = LocM.GetString("error");
             *      lastlabel.Enabled = false;
             *      MessageBox.Show(e.InnerException.Message, LocM.GetString("error"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
             *  }
             *  load.Enabled = true;
             *  loadfrom.Enabled = true;
             * }*/
        }
Esempio n. 5
0
 private void button2_Click_1(object sender, EventArgs e)
 {
     ImgurAPI.ConnectAccount(this);
 }