public static void WriteGBKString(string ResourceString, string NewFilePath) { try { StreamWriter SA = new StreamWriter(NewFilePath, false, System.Text.Encoding.GetEncoding("gbk")); SA.Write(ResourceString); SA.Dispose(); } catch (Exception EX) { My.Show(EX); } }
//删除文件 private void CheckDeleteFile() { if (webBrowser1.Url != null && webBrowser1.ReadyState == WebBrowserReadyState.Complete && webBrowser1.Url.ToString().Contains("https://portal.qiniu.com/bucket/moonlord/files/0/delete?bucket=")) { if (webBrowser1.DocumentText.Contains("\"failed_keys\":[]")) { My.Show("所有选中的文件都成功删除。"); } else { My.Show("选中的部分文件删除失败。"); } My.MainForm.FormMainButton_Click(My.MainForm.FormMainButton[My.MainForm.ChosenButtomIndex], new EventArgs()); } }
//设置IE浏览器的默认解析方法 public static void ResetWebbrowser() { //Show(MyProjectName); try//32位设置 { RegistryKey RK = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION", true); RK.SetValue(MyProjectName + ".exe", 10000);//默认IE10,然后按照网页上!DOCTYPE指令来显示网页 //RK.SetValue("YourApplication.exe", 10001);//强制IE10 //IE9:9000或9999 //My.Show(RK.GetValue(MyProjectName+ ".exe").ToString()); RK.Close(); } catch (Exception EX) { My.Show(EX); } try//64位设置 { RegistryKey RK = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION", true); RK.SetValue(MyProjectName + ".exe", 10000);//默认IE10,然后按照网页上!DOCTYPE指令来显示网页 //RK.SetValue("YourApplication.exe", 10001);//强制IE10 //IE9:9000或9999 //My.Show(RK.GetValue(MyProjectName+ ".exe").ToString()); RK.Close(); } catch (Exception EX) { My.Show(EX); } try//显示JSON而不是提示下载 { RegistryKey RK = Registry.ClassesRoot.OpenSubKey(@"MIME\Database\Content Type", true); RK.CreateSubKey("application/json"); RK = RK.OpenSubKey("application/json", true); RK.SetValue("CLSID", "{25336920-03F9-11cf-8FD0-00AA00686F13}"); RK.SetValue("Encoding", "dword:00080000"); RK.Close(); } catch (Exception EX) { My.Show(EX); } try//显示JSON而不是提示下载 { RegistryKey RK = Registry.ClassesRoot.OpenSubKey(@"MIME\Database\Content Type", true); RK.CreateSubKey("text/json"); RK = RK.OpenSubKey("text/json", true); RK.SetValue("CLSID", "{25336920-03F9-11cf-8FD0-00AA00686F13}"); RK.SetValue("Encoding", "dword:00080000"); RK.Close(); } catch (Exception EX) { My.Show(EX); } }
//检查登录和获取文件 private Boolean CheckGetFile() { if (webBrowser1.Url != null && webBrowser1.ReadyState == WebBrowserReadyState.Complete && webBrowser1.Url.ToString().Contains("https://portal.qiniu.com/bucket/") && webBrowser1.Url.ToString().Contains("?marker=")) { My.MainForm.dataGridView1.Columns.Clear(); My.MainForm.dataGridView1.Rows.Clear(); DataGridViewTextBoxColumn Column1 = new DataGridViewTextBoxColumn(); DataGridViewTextBoxColumn Column2 = new DataGridViewTextBoxColumn(); DataGridViewTextBoxColumn Column3 = new DataGridViewTextBoxColumn(); DataGridViewTextBoxColumn Column4 = new DataGridViewTextBoxColumn(); DataGridViewTextBoxColumn Column5 = new DataGridViewTextBoxColumn(); DataGridViewTextBoxColumn Column6 = new DataGridViewTextBoxColumn(); Column1.HeaderText = "文件名 Key"; Column2.HeaderText = "类型 MimeType"; Column3.HeaderText = "大小 Fsize"; Column4.HeaderText = "上传时间 PutTime"; Column5.HeaderText = "散列值 Hash"; Column6.HeaderText = "下载链接 Url"; Column1.Width = (My.MainForm.dataGridView1.Width - 58) * 1 / 6; Column2.Width = (My.MainForm.dataGridView1.Width - 58) * 1 / 6; Column3.Width = (My.MainForm.dataGridView1.Width - 58) * 1 / 6; Column4.Width = (My.MainForm.dataGridView1.Width - 58) * 1 / 6; Column5.Width = (My.MainForm.dataGridView1.Width - 58) * 1 / 6; Column6.Width = (My.MainForm.dataGridView1.Width - 58) * 1 / 6; My.MainForm.dataGridView1.Columns.Add(Column1); My.MainForm.dataGridView1.Columns.Add(Column2); My.MainForm.dataGridView1.Columns.Add(Column3); My.MainForm.dataGridView1.Columns.Add(Column4); My.MainForm.dataGridView1.Columns.Add(Column5); My.MainForm.dataGridView1.Columns.Add(Column6); String[] Data = new String[0]; //无数据:{"bucketType":"public","hasSensitiveWord":false,"items":[]} if (webBrowser1.DocumentText == "\"获取空间文件列表失败\"") { My.MainForm.label2.Text = "七牛云反馈:获取空间文件列表失败。推测可能为网络或服务器故障,请稍后再试。"; My.MainForm.Refresh(); My.Show("七牛云反馈:获取空间文件列表失败。推测可能为网络或服务器故障,请稍后再试。"); } else if (webBrowser1.DocumentText.Contains("\"items\":[]")) { My.MainForm.label2.Text = "文件列表获取完成,满足条件的文件的数量为0。"; My.MainForm.Refresh(); } else if (My.ExtractCode(webBrowser1.DocumentText, "\"items\":[{", "}]") == "") { My.MainForm.label2.Text = "文件列表获取失败,请稍后再试。"; My.MainForm.Refresh(); } else { //My.Show(webBrowser1.DocumentText.Contains("\"items\":[{")); //My.Show(webBrowser1.DocumentText.Contains("}],\"marker\"")); Data = System.Text.RegularExpressions.Regex.Split(My.ExtractCode(webBrowser1.DocumentText, "\"items\":[{", "}]"), "},{"); //My.Show(Data); for (int i = 0; i < Data.Length; i++) { try { My.MainForm.dataGridView1.Rows.Add( My.SeekCode(Data[i], "\"key\":\"", "\""), My.SeekCode(Data[i], "\"mimeType\":\"", "\""), Convert.ToDecimal(Convert.ToDouble(My.SeekCode(Data[i], "\"fsize\":", ","))), My.ConvertIntDateTime((double)Convert.ToDouble(My.SeekCode(Data[i], "\"putTime\":", ",")) / 10000000), My.SeekCode(Data[i], "\"hash\":\"", "\""), My.SeekCode(Data[i], "\"signed_download_url\":\"", "\"") ); } catch (Exception EX) { My.Show(EX.ToString()); //My.Show(webBrowser1.DocumentText); //My.Show(Data[i]); } } My.MainForm.dataGridView1.ClearSelection(); String Temp = My.MainForm.dataGridView1.Rows[My.MainForm.dataGridView1.RowCount - 2].Cells[0].Value.ToString(); Temp = "{\"c\":0,\"k\":\"" + Temp + "\"}"; My.MainForm.Marker = My.ChangeIntoSafeBase64(Temp); My.MainForm.label2.Text = "文件列表获取完成,满足条件的文件的数量为" + Data.Length + "。"; My.MainForm.Refresh(); } return(true); } return(false); }