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; }