static void Main(string[] args) { //列出所有檔案 myziplib.myziplib myzip = new myziplib.myziplib(); string zipFilePath = pwd() + "\\test.zip"; var p = myzip.getZipFileLists(zipFilePath); var output = my.json_format_utf8(my.json_encode(p)); Console.WriteLine(output); //取得資料 byte[] obyte = myzip.getZipFileData(zipFilePath, "test/folder1/images.jpg"); string output_file = pwd() + "\\output.jpg"; my.file_put_contents(output_file, obyte); Array.Clear(obyte, 0, obyte.Length); obyte = null; }
private void button1_Click(object sender, EventArgs e) { button1.Enabled = false; button1.Text = "載入中..."; string URL = downloadURL.Text; if (!Regex.IsMatch(URL, @"^https://www.comico.com.tw/\d*/")) { MessageBox.Show("網址不對..."); button1.Enabled = true; button1.Text = "載入"; return; } string orin_URL = URL; //從已知的 tabs 找 tooltips,如果一樣,就跳過,直接跳到那頁 for (int i = 0, max_i = tabControl1.TabPages.Count; i < max_i; i++) { string tipname = tabControl1.TabPages[i].ToolTipText; if (tipname == orin_URL) { tabControl1.SelectedIndex = i; button1.Enabled = true; button1.Text = "載入"; return; } } string orin_data = my.b2s(my.file_get_contents(orin_URL)); //my.file_put_contents(PWD + "\\log.txt", orin_data); string orin_NAME = my.get_between(orin_data, "<meta property=\"og:title\" content=\"", "|"); orin_NAME = orin_NAME.Replace("。", ""); URL = URL.Replace("https://", ""); var m = my.explode("/", URL); string id = m[1]; string jsonURL = "https://www.comico.com.tw/api/getArticleList.nhn"; string data = my.b2s(my.file_get_contents_post(jsonURL, "titleNo=" + id)); //my.file_put_contents(PWD + "\\log.txt", data); var jd = my.json_decode(data); List <ConcurrentDictionary <string, string> > ldt = new List <ConcurrentDictionary <string, string> >(); for (int i = 0; i < jd[0]["result"]["list"].Count(); i++) { var d = new ConcurrentDictionary <string, string>(); d["URL"] = jd[0]["result"]["list"][i]["articleDetailUrl"].ToString(); d["NAME"] = jd[0]["result"]["list"][i]["subtitle"].ToString(); d["URL_IMG"] = jd[0]["result"]["list"][i]["imgUrl"].ToString(); ldt.Add(d); } Console.WriteLine(my.json_encode(ldt)); // Gets the controls collection for tabControl1. // Adds the tabPage1 to this collection. var tab = new TabPage("item_" + orin_NAME); tab.ToolTipText = orin_URL; DataGridView dgv = new DataGridView(); //dgv.AutoGenerateColumns = false; //這啥 dgv.AllowUserToAddRows = false; //不能允許使用者自行調整 dgv.RowHeadersVisible = false; //左邊空欄移除 dgv.Dock = DockStyle.None; //自動展開到最大 dgv.AllowDrop = false; dgv.ReadOnly = true; dgv.Name = "PAGE_" + tabControl1.TabPages.Count.ToString(); SOURCES[dgv.Name] = new ConcurrentDictionary <string, object>(); SOURCES[dgv.Name]["NAME"] = orin_NAME; SOURCES[dgv.Name]["URL"] = orin_URL; dgv.Width = 650; dgv.Height = 500; //dgv.Columns.Add("ID", "序號"); //dgv.Columns.Add("NAME", "話"); //dgv.Columns.Add("URL", "URL"); dgv.Location = new Point(0, 50); DataTable dtt = new DataTable(); dtt.Columns.Add("ID"); dtt.Columns.Add("NAME"); dtt.Columns.Add("URL"); dtt.Columns.Add("STATUS"); for (int i = 0, max_i = ldt.Count; i < max_i; i++) { dtt.Rows.Add(); int LAST_ID = dtt.Rows.Count - 1; dtt.Rows[LAST_ID]["ID"] = (i + 1).ToString(); dtt.Rows[LAST_ID]["NAME"] = ldt[i]["NAME"]; dtt.Rows[LAST_ID]["URL"] = ldt[i]["URL"]; dtt.Rows[LAST_ID]["STATUS"] = "待命"; } dgv.DataSource = dtt; SOURCES[dgv.Name]["回"] = dtt; //加一個標題 var labelTitle = new System.Windows.Forms.Label(); labelTitle.Text = orin_NAME + " (共 " + ldt.Count.ToString() + " 回)"; labelTitle.Width = 650; labelTitle.Font = new Font("微軟正黑體", 16); labelTitle.Location = new Point(0, 0); //加一個下載的鈕 var btnRun = new System.Windows.Forms.Button(); btnRun.Name = "goBtn - " + dgv.Name; btnRun.Text = "開始下載"; btnRun.Location = new Point(this.Width - btnRun.Width - 50, 0); btnRun.Click += (object s, EventArgs ee) => { //按鈕的程式 //MessageBox.Show(dgv.Name); Button btn = s as Button; string key = my.explode(" - ", btn.Name)[1]; switch (btn.Text) { case "開始下載": { btn.Text = "下載中...(點了取消)"; SOURCES[key]["RUN_THREAD"] = new Thread(() => run(key, btn)); ((Thread)SOURCES[key]["RUN_THREAD"]).Start(); } break; default: { btn.Text = "開始下載"; if (SOURCES[key].Keys.Contains("RUN_THREAD") && SOURCES[key]["RUN_THREAD"] != null) { ((Thread)(SOURCES[key]["RUN_THREAD"])).Abort(); } } break; } }; tab.Controls.Add(labelTitle); tab.Controls.Add(btnRun); tab.Controls.Add(dgv); tab.Text = dgv.Name; tabControl1.TabPages.Add(tab); for (int i = 0; i < dgv.Columns.Count - 1; i++) { dgv.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells; } dgv.Columns[dgv.Columns.Count - 1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; for (int i = 0; i < dgv.Columns.Count; i++) { int colw = dgv.Columns[i].Width; dgv.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.None; dgv.Columns[i].Width = colw; } button1.Enabled = true; button1.Text = "載入"; tabControl1.SelectedIndex = tabControl1.TabPages.Count - 1; }
private void run_upload() { if (textSystemName.Text == "") { return; } //手動同步 //收集所有 gridview 的內容 //組合成 json 加密後,上傳到伺服器 Dictionary <string, object> output = new Dictionary <string, object>(); setStatusBar("同步開始...", 0); logError("同步開始..."); output["NAME"] = textSystemName.Text; setStatusBar("同步開始...取得系統資訊", 20); cSystem.init(this); cHdd.init(this); cEvents.init(this); cFirewall.init(this); cRunningProgram.init(this); cSystemService.init(this); cSchedule.init(this); cIis.init(this); cInstalledSoftware.init(this); Thread.Sleep(3000); while ( cSystem.is_running == true || cHdd.is_running == true || cEvents.is_running == true || cRunningProgram.is_running == true || cSystemService.is_running == true || cFirewall.is_running == true || cSchedule.is_running == true || cIis.is_running == true || cInstalledSoftware.is_running == true ) { Thread.Sleep(1000); setStatusBar("等待資料完成...", 0); } //setStatusBar("同步開始...取得硬碟資訊", 40); try { //output["SYSTEM_INFO"] = my.gridViewToDataTable(system_grid); output["SYSTEM_INFO"] = cSystem.dt; } catch { } try { //output["SYSTEM_SERVICE_INFO"] = my.gridViewToDataTable(system_service_grid); output["SYSTEM_SERVICE_INFO"] = cSystemService.dt; } catch { } try { //output["HDD_INFO"] = my.gridViewToDataTable(hdd_grid); output["HDD_INFO"] = cHdd.dt; } catch { } try { //output["FIREWALL_INFO"] = my.gridViewToDataTable(firewall_grid); output["FIREWALL_INFO"] = cFirewall.dt; } catch { } try { //output["EVENTS_INFO"] = my.gridViewToDataTable(events_grid); output["EVENTS_INFO"] = cEvents.dt; } catch { } try { //output["TASK_INFO"] = my.gridViewToDataTable(running_program_grid); output["TASK_INFO"] = cRunningProgram.dt; } catch { } try { //output["SCHEDULE_INFO"] = my.gridViewToDataTable(schedule_grid); output["SCHEDULE_INFO"] = cSchedule.dt; } catch { } try { //output["IIS_INFO"] = my.gridViewToDataTable(iis_grid); output["IIS_INFO"] = cIis.dt; } catch { } try { //output["IIS_INFO"] = my.gridViewToDataTable(iis_grid); output["INSTALLED_SOFTWARE_INFO"] = cInstalledSoftware.dt; } catch { } //logError(my.json_encode_formated(output)); string URL = my.getSystemKey("REPORT_URL") + "?mode=updateStatus"; ConcurrentDictionary <string, string> o = new ConcurrentDictionary <string, string>(); o["data"] = my.base64_encode(my.Zip(my.json_encode(output))); output = null; try { string data = my.b2s(my.file_get_contents_post(URL, o)); if (data != "") { logError(data); } } catch (Exception ex) { logError(ex.Message + "\r\n" + ex.StackTrace); } o = null; }