/// <summary> /// 讀取系統的 config 進階設定檔 /// </summary> public void fun_config() { // try { //先讀取文字檔 StreamReader sr = new StreamReader(path_config, Encoding.UTF8); String s_xml = sr.ReadToEnd(); sr.Close(); sr.Dispose(); //因為網址裡面可能有【&】,所以要先取代成【&】 s_xml = s_xml.Replace("&", "&"); s_xml = s_xml.Replace("<", "*+<+*"); s_xml = s_xml.Replace(">", "*+>+*"); s_xml = s_xml.Replace("&", "&"); s_xml = s_xml.Replace("*+<+*", "<"); s_xml = s_xml.Replace("*+>+*", ">"); XmlDocument XmlDoc = new XmlDocument(); XmlDoc.LoadXml(s_xml);//從字串解析xml XmlNodeList NodeLists = XmlDoc.SelectNodes("settings/item"); foreach (XmlNode item in NodeLists) { if (item.Attributes["name"].Value.Equals("預設瀏覽器")) // { foreach (XmlNode item2 in item.ChildNodes) { ar_預設瀏覽器.Add(item2.InnerText.Trim().Replace("\"", "")); } } else if (item.Attributes["name"].Value.Equals("使用其他程式開啟")) { foreach (XmlNode item2 in item.ChildNodes) { if (item2.Name != "path") { continue; } var cls = new data_開啟程式(); cls.type = item2.Attributes["type"].Value.Trim(); cls.path = item2.InnerText.Trim().Replace("\"", "").Replace("/", "\\"); if (item2.Attributes["name"] != null) { cls.name = item2.Attributes["name"].Value.Trim(); } cls.lnk_name = cls.path; ar_外部開啟.Add(cls); } } } // } catch { } }
/// <summary> /// /// </summary> /// <returns></returns> private List <data_開啟程式> fun_處理名單() { List <data_開啟程式> ar = new List <data_開啟程式>();//處理後的名單 if (Directory.Exists(fun_作業系統的槽() + @":\ProgramData\Microsoft\Windows\Start Menu\Programs")) { fun_遍歷開始選單資料夾(fun_作業系統的槽() + @":\ProgramData\Microsoft\Windows\Start Menu\Programs");//windows的開始 } else { } //路徑沒有重複才新增 Action <data_開啟程式> ac_add2 = (data_開啟程式 data) => { if (data.path.ToLower().Contains("uninstall")) { return; } //判斷是否可以新增 bool bool_可以新增 = true; for (int i = 0; i < ar.Count; i++) { if (data != null) { if (data.path.ToUpper() == ar[i].path.ToUpper()) { bool_可以新增 = false; break; } } } if (bool_可以新增 && data != null) { ar.Add(data); } }; //跟開始選單裡面的程式 join foreach (data_開啟程式 item in M.c_set.ar_外部開啟) { data_開啟程式 cc = null; if (item.type == "start_menu") //開始選單 { try { foreach (var item2 in ar_file) { String path_name = item2;//使用檔名判斷,而不是使用完整路徑 if (path_name.Contains("\\")) { path_name = path_name.Substring(path_name.LastIndexOf('\\')); } if (path_name.ToUpper().Contains(item.path.ToUpper())) { if (item2.Length > 5 && item2.Substring(item2.Length - 3).ToUpper() == "LNK") //超連結才新增 { cc = new data_開啟程式(); cc.type = "absolute"; try { cc.path = ResolveShortcut(item2); } catch { } cc.lnk_name = item2; cc.name = item.name; ac_add2(cc); } } } } catch { } } else if (item.type == "absolute") //絕對路徑 { cc = item; ac_add2(cc); } } //處理名稱。如果沒有設定name,就使用檔案名稱 foreach (data_開啟程式 item in ar) { try { String s_name = item.lnk_name; if (item.name == "") { int int_start = s_name.LastIndexOf("\\");//最後一個\ if (int_start > -1) { s_name = s_name.Substring(int_start + 1); } int int_end = s_name.LastIndexOf(".");//去掉附檔名 if (int_end > -1) { s_name = s_name.Substring(0, int_end); } item.name = s_name; } } catch { } } //移除檔案不存在的路徑 List <data_開啟程式> ar2 = new List <data_開啟程式>(); foreach (var item in ar) { try { if (File.Exists(item.path)) { string Dialog = item.path; System.Drawing.Icon[] GetIcon = IconHandler.IconHandler.IconsFromFile(Dialog, IconSize.Large); if (GetIcon.Length > 0) { item.img = GetIcon[0].ToBitmap(); } ar2.Add(item); } } catch { } } return(ar2); }