private string Upload(string sPath) { try { System.IO.FileStream fs = new System.IO.FileStream( sPath, System.IO.FileMode.Open, System.IO.FileAccess.Read); byte[] bImg = new byte[fs.Length]; fs.Read(bImg, 0, bImg.Length); fs.Close(); fs.Dispose(); string fname = MakeFName(); string sPostTo = "http://www.imagehost.org/"; string sRefer = "http://www.imagehost.org/"; WebReq WReq = new WebReq(); string sMPBound = "----------" + WReq.RandomChars(22); string sPD1 = "--" + sMPBound + "\r\n" + "Content-Disposition: form-data; name=\"a\"" + "\r\n" + "\r\n" + "upload" + "\r\n" + "--" + sMPBound + "\r\n" + "Content-Disposition: form-data; name=\"file[]\"; " + "filename=\"" + fname + ".png\r\n" + "Content-Type: image/png" + "\r\n" + "\r\n"; string sPD2 = "\r\n" + "--" + sMPBound + "\r\n" + "Content-Disposition: form-data; name=\"file[]\"; filename=\"\"" + "\r\n" + "\r\n" + "\r\n" + "--" + sMPBound + "\r\n" + "Content-Disposition: form-data; name=\"file[]\"; filename=\"\"" + "\r\n" + "\r\n" + "\r\n" + "--" + sMPBound + "\r\n" + "Content-Disposition: form-data; name=\"file[]\"; filename=\"\"" + "\r\n" + "\r\n" + "\r\n" + "--" + sMPBound + "\r\n" + "Content-Disposition: form-data; name=\"file[]\"; filename=\"\"" + "\r\n" + "\r\n" + "\r\n" + "--" + sMPBound + "\r\n" + "Content-Disposition: form-data; name=\"file[]\"; filename=\"\"" + "\r\n" + "\r\n" + "\r\n" + "--" + sMPBound + "\r\n" + "Content-Disposition: form-data; name=\"file[]\"; filename=\"\"" + "\r\n" + "\r\n" + "\r\n" + "--" + sMPBound + "\r\n" + "Content-Disposition: form-data; name=\"file[]\"; filename=\"\"" + "\r\n" + "\r\n" + "\r\n" + "--" + sMPBound + "--" + "\r\n"; byte[] bPD1 = new byte[sPD1.Length]; byte[] bPD2 = new byte[sPD2.Length]; for (int a = 0; a < sPD1.Length; a++) { bPD1[a] = (byte)sPD1[a]; } for (int a = 0; a < sPD2.Length; a++) { bPD2[a] = (byte)sPD2[a]; } byte[] bPD = new byte[bPD1.Length + bImg.Length + bPD2.Length]; bPD1.CopyTo(bPD, 0); bImg.CopyTo(bPD, 0 + bPD1.Length); bPD2.CopyTo(bPD, 0 + bPD1.Length + bImg.Length); System.Net.WebHeaderCollection whc = new System.Net.WebHeaderCollection(); //whc.Add("Expect: 100-continue"); whc.Add("Referer: " + sRefer); WReq.Request(sPostTo, whc, bPD, sMPBound, 3, "", true); while (!WReq.isReady) { Application.DoEvents(); System.Threading.Thread.Sleep(1); } if (WReq.sResponse.Contains(fname)) { if (WReq.sResponse.Contains("nowrap\">Hotlink</td>")) { return(Split(Split(Split(WReq.sResponse, "nowrap\">Hotlink</td>")[1], " size=\"50\" value=\"")[1], "\" />")[0]); } else { return(Split(Split(Split(WReq.sResponse, "nowrap\">Text Link</td>")[1], " size=\"50\" value=\"")[1], "\" />")[0]); } } else { return(""); } } catch { return(""); } }
private void frmMain_Load(object sender, EventArgs e) { sAppVer = Application.ProductVersion; sAppVer = sAppVer.Substring(0, sAppVer.LastIndexOf('.')); txtPath.Text = Application.StartupPath; if (System.IO.File.Exists("grab.wav")) { spShot.Load(); } if (System.IO.File.Exists("done.wav")) { spDone.Load(); } if (System.IO.File.Exists("config.ini")) { string sConf = System.IO.File.ReadAllText("config.ini"); string sPath = txtPath.Text; string sFormat = "png"; string sCrop = txtCrop.Text; string sResize = txtResize.Text; string sUpload = ""; if (sConf.Contains("</path>")) { sPath = Split(Split(sConf, "<path>")[1], "</path>")[0]; } if (sConf.Contains("</format>")) { sFormat = Split(Split(sConf, "<format>")[1], "</format>")[0]; } if (sConf.Contains("</crop>")) { sCrop = Split(Split(sConf, "<crop>")[1], "</crop>")[0]; } if (sConf.Contains("<crop-explicit />")) { chkCrop.Checked = true; } else { chkCrop.Checked = false; } if (sConf.Contains("</resize>")) { sResize = Split(Split(sConf, "<resize>")[1], "</resize>")[0]; } if (sConf.Contains("<keep-aspect />")) { chkResize.Checked = true; } else { chkResize.Checked = false; } if (sConf.Contains("</upload>")) { sUpload = Split(Split(sConf, "<upload>")[1], "</upload>")[0]; } if (sConf.Contains("<upload-clip />")) { chkUploadClip.Checked = true; } else { chkUploadClip.Checked = false; } if (sConf.Contains("<upload-notify />")) { chkUploadNotify.Checked = true; } else { chkUploadNotify.Checked = false; } txtPath.Text = sPath; txtCrop.Text = sCrop; txtResize.Text = sResize; if (sFormat == "bmp") { rBMP.Checked = true; } if (sFormat == "jpg") { rJPG.Checked = true; } if (sFormat == "png") { rPNG.Checked = true; } if (sFormat == "gif") { rGIF.Checked = true; } if (sFormat == "tif") { rTIF.Checked = true; } if (sUpload == "Disabled") { rUP_NA.Checked = true; } if (sUpload == "Tinypic") { rUP_Tinypic.Checked = true; } if (sUpload == "Imagehost") { rUP_Imagehost.Checked = true; } } this.Opacity = 0; this.Show(); for (int a = 1; a <= 10; a++) { Application.DoEvents(); this.Opacity = (double)a / 10; System.Threading.Thread.Sleep(20); } nico.Icon = this.Icon; nico.Text = "Preenshot"; nico.Visible = true; try { bool bUpdateCheckOK = true; WebReq WR = new WebReq(); WR.Request(PrgDomain + "Preenshot_version.php?cv=" + sAppVer); long lUpdateStart = Tick(); while (!WR.isReady && bUpdateCheckOK) { Application.DoEvents(); System.Threading.Thread.Sleep(10); if (Tick() > lUpdateStart + 5000) { bUpdateCheckOK = false; } } string wrh = WR.sResponse; if (wrh.Contains("<WebReq_Error>")) { throw new Exception("wat"); } if (!bUpdateCheckOK) { throw new Exception("wat"); } if (!wrh.Contains("<VERSION>" + sAppVer + "</VERSION>")) { string sNewVer = Split(Split(wrh, "<VERSION>")[1], "</VERSION>")[0]; bool GetUpdate = (DialogResult.Yes == MessageBox.Show( "A new version (" + sNewVer + ") is available. Update?", "Preenshot Updater", MessageBoxButtons.YesNo)); if (GetUpdate) { string UpdateLink = new System.Net.WebClient().DownloadString( ToxDomain + "inf/Preenshot_link.html").Split('%')[1]; System.Diagnostics.Process.Start(UpdateLink + "&cv=" + sAppVer); Application.Exit(); } } } catch { MessageBox.Show("Couldn't check for updates.", "Preenshot Updater"); } log("Finished."); }