public void run_check_update() { //檢查目前版本,如果版本檔不存在,關程式,下載新版,執行 double local_version = 0; double remote_version = 0; bool isNeedUpdate = false; string downloadPath = ""; //Console.WriteLine("step 1"); if (!F1.my.is_file(F1.PWD + "\\version.txt")) { isNeedUpdate = true; //Console.WriteLine("step 2"); } else { //檢查現在版本,跟網站上版本 local_version = Convert.ToDouble(F1.my.b2s(F1.my.file_get_contents(F1.PWD + "\\version.txt"))); remote_version = local_version; try { var jd = my.json_decode(F1.my.b2s(my.file_get_contents(F1.my.getSystemKey("checkVersionURL")))); remote_version = Convert.ToDouble(jd[0]["version"].ToString()); downloadPath = jd[0]["downloadPath"].ToString(); //Console.WriteLine("step 3"); } catch { //無網路 } } if (local_version < remote_version || isNeedUpdate) { //Console.WriteLine("step 4"); //版本不一樣,如果服務正在跑,就停止,下載,重新啟動程式 F1.my.killProcess("system_status"); if (downloadPath != "") { //Console.WriteLine("step 5"); F1.my.file_put_contents(F1.PWD + "\\system_status.exe", F1.my.file_get_contents(downloadPath)); F1.logError("下載更新版本...:" + remote_version.ToString()); } F1.my.system(F1.PWD + "\\system_status.exe"); } if (!F1.my.isProcessRunning("system_status")) { //Console.WriteLine("step 6"); F1.my.system(F1.PWD + "\\system_status.exe"); } }
public void getSettingINI() { /* # setting.ini # [ # { # "name":"", # "ip":"", # "port":"", # "kind":"", # "login_id":"", # "pwd":"", # "isConnect":"F", # "pdo": obj , # "connString": string # } # ] */ List <Dictionary <string, string> > data = new List <Dictionary <string, string> >(); string setting_path = my.pwd() + "\\setting.ini"; if (!my.is_file(setting_path)) { my.file_put_contents(setting_path, ""); } string endata = my.b2s(my.file_get_contents(setting_path)); //string dedata = my.dePWD_string(endata, the_code); JArray ja = new JArray(); if (endata != "") { ja = my.json_decode(endata); } for (int i = 0, max_i = ja.Count; i < max_i; i++) { Dictionary <string, object> doo = new Dictionary <string, object>(); foreach (JObject obj in ja[i]) { Dictionary <string, object> dictObj = obj.ToObject <Dictionary <string, object> >(); dictObj["isConnect"] = "F"; connections.Add(dictObj); } } }
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; }