private async void uploadButton_Click(object sender, EventArgs e) { #if USE_JSON Chevereto imgUploader; try { var uploader = userMenuStrip.Items.Cast <ToolStripMenuItem>().First(item => item.Checked).Tag as CheveretoUploader; imgUploader = new Chevereto(uploader); } catch (InvalidOperationException) { MessageBox.Show("请在配置文件中设定默认账号或手动选中账号", Utility.GetHelplessEmotion()); return; } #elif USE_LB var lb = new CheveretoUploader("http://img.2222.moe/littlebakas/1/upload/", "0f563a641610160a32a1f87d364269f0"); Chevereto imgUploader = new Chevereto(lb); #else var vcb_s = new CheveretoUploader("http://img.2222.moe/api/1/upload", "0f653a641610160a23a1f87d364926f9"); Chevereto imgUploader = new Chevereto(vcb_s); #endif int count = 0; bool flag = false; foreach (Frame f in FList) { flag = await Task.Run(() => { if (!imgUploader.UploadImage(f.SrcName, Utility.CurrentDir + f.SrcName)) { return(false); } if (!imgUploader.UploadImage(f.RipName, Utility.CurrentDir + f.RipName)) { return(false); } return(imgUploader.UploadImage(f.FrameId + "s.png", Utility.CurrentDir + f.FrameId + "s.png")); }); if (!flag) { break; } count++; InfoBoard.AppendText($"已经上传完第 {count}/{FList.Count} 组截图。\n"); Application.DoEvents(); } if (!flag) { MessageBox.Show("自己登录图床把上传一半的删了,然后手动上传所有图吧。同目录下的截图代码应该还可以用。", "上传跪了" + Utility.GetHelplessEmotion()); } GenerateCode(flag); uploadButton.Enabled = false; }
private async void uploadButton_Click(object sender, EventArgs e) { #if USE_JSON Chevereto imgUploader; try { var uploader = userMenuStrip.Items.Cast <ToolStripMenuItem>().First(item => item.Checked).Tag as CheveretoUploader; imgUploader = new Chevereto(uploader); } catch (InvalidOperationException) { MessageBox.Show("请在配置文件中设定默认账号或手动选中账号", Utility.GetHelplessEmotion()); return; } #elif USE_LB var lb = new CheveretoUploader("http://img.2222.moe/littlebakas/1/upload/", "0f563a641610160a32a1f87d364269f0"); Chevereto imgUploader = new Chevereto(lb); #else var vcb_s = new CheveretoUploader("http://img.2222.moe/api/1/upload", "0f653a641610160a23a1f87d364926f9"); Chevereto imgUploader = new Chevereto(vcb_s); #endif InfoBoard.AppendText($"开始上传,耐心等一会儿......\n"); Application.DoEvents(); int count = 0; bool flag = false; foreach (Frame f in FList) { flag = await Task.Run(() => { if (!imgUploader.UploadImage(f.SrcName, Path.Combine(Utility.CurrentDir, f.SrcName))) { return(false); } if (!imgUploader.UploadImage(f.RipName, Path.Combine(Utility.CurrentDir, f.RipName))) { return(false); } return(imgUploader.UploadImage(f.FrameId + "s.png", Path.Combine(Utility.CurrentDir, f.FrameId + "s.png"))); }); if (!flag) { break; } count++; InfoBoard.AppendText($"已经上传完第 {count}/{FList.Count} 组截图。\n"); Application.DoEvents(); } if (!flag) { MessageBox.Show("自己登录图床把上传一半的删了,然后手动上传所有图吧。同目录下的截图代码应该还可以用。", "上传跪了" + Utility.GetHelplessEmotion()); } try { var urltxt = Path.Combine(Utility.CurrentDir, "url.txt"); using (var file = new StreamWriter(urltxt, false)) { file.WriteLine(GenerateHTML()); file.WriteLine(); file.WriteLine(GenerateBbcode()); file.WriteLine(); file.WriteLine(GenerateMarkdown()); } if (flag) { MessageBox.Show("截图代码已经写在url.txt里", "去丢发布组吧" + Utility.GetHappyEmotion()); } } catch (Exception exception) { MessageBox.Show($"保存文件出现异常: {exception.Message}\n调用栈:{exception.StackTrace}"); } uploadButton.Enabled = false; }
private UploadResult UploadImage(string ssPath) { ImageUploader imageUploader = null; if (!string.IsNullOrEmpty(Program.Settings.PtpImgCode)) { imageUploader = new PtpImageUploader(Crypt.Decrypt(Program.Settings.PtpImgCode)); } else { switch ((ImageDestination)Program.Settings.ImageUploaderType) { case ImageDestination.TinyPic: imageUploader = new TinyPicUploader(ZKeys.TinyPicID, ZKeys.TinyPicKey, Program.UploadersConfig.TinyPicAccountType, Program.UploadersConfig.TinyPicRegistrationCode); break; case ImageDestination.Imgur: if (Program.UploadersConfig.ImgurOAuth2Info == null) { Program.UploadersConfig.ImgurOAuth2Info = new OAuth2Info(APIKeys.ImgurClientID, APIKeys.ImgurClientSecret); } string albumID = null; if (Program.UploadersConfig.ImgurUploadSelectedAlbum && Program.UploadersConfig.ImgurSelectedAlbum != null) { albumID = Program.UploadersConfig.ImgurSelectedAlbum.id; } imageUploader = new Imgur_v3(Program.UploadersConfig.ImgurOAuth2Info) { UploadMethod = Program.UploadersConfig.ImgurAccountType, DirectLink = Program.UploadersConfig.ImgurDirectLink, ThumbnailType = Program.UploadersConfig.ImgurThumbnailType, UploadAlbumID = albumID }; break; case ImageDestination.Flickr: imageUploader = new FlickrUploader(APIKeys.FlickrKey, APIKeys.FlickrSecret, Program.UploadersConfig.FlickrAuthInfo, Program.UploadersConfig.FlickrSettings); break; case ImageDestination.Photobucket: imageUploader = new Photobucket(Program.UploadersConfig.PhotobucketOAuthInfo, Program.UploadersConfig.PhotobucketAccountInfo); break; case ImageDestination.Picasa: imageUploader = new Picasa(Program.UploadersConfig.PicasaOAuth2Info) { AlbumID = Program.UploadersConfig.PicasaAlbumID }; break; case ImageDestination.Twitter: OAuthInfo twitterOAuth = Program.UploadersConfig.TwitterOAuthInfoList.ReturnIfValidIndex(Program.UploadersConfig.TwitterSelectedAccount); imageUploader = new Twitter(twitterOAuth); break; case ImageDestination.Chevereto: imageUploader = new Chevereto(Program.UploadersConfig.CheveretoWebsite, Program.UploadersConfig.CheveretoAPIKey) { DirectURL = Program.UploadersConfig.CheveretoDirectURL }; break; case ImageDestination.HizliResim: imageUploader = new HizliResim() { DirectURL = true }; break; case ImageDestination.CustomImageUploader: if (Program.UploadersConfig.CustomUploadersList.IsValidIndex(Program.UploadersConfig.CustomImageUploaderSelected)) { imageUploader = new CustomImageUploader(Program.UploadersConfig.CustomUploadersList[Program.UploadersConfig.CustomImageUploaderSelected]); } break; case ImageDestination.FileUploader: return(UploadFile(ssPath)); } } if (imageUploader != null) { ReportProgress(ProgressType.UPDATE_STATUSBAR_DEBUG, string.Format("Uploading {0}.", Path.GetFileName(ssPath))); return(imageUploader.Upload(ssPath)); } return(null); }