void BtnInitHostClick(object sender, EventArgs e) { if (!Util.canModifyHosts()) { MessageBox.Show("You need Administrator Roll.", "Alert"); return; } PLink.host.initHostFile(); }
public void backupHostFile() { if (!Util.canModifyHosts()) { return; } try { File.Copy(HOST_ROOT + Util.HOST_SOURCE, HOST_ROOT + Util.HOST_TARGET, true); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } }
public void initHostFile() { if (!Util.canModifyHosts()) { return; } File.WriteAllText(HOST_ROOT + Util.HOST_SOURCE, ""); File.WriteAllText(HOST_ROOT + Util.HOST_TARGET, ""); this.changeHostFile(); }
public void changeHostFile() { try { if (!Util.canModifyHosts()) { return; } if (list == null) { return; } StringBuilder sb = new StringBuilder(); foreach (KeyValuePair <string, HostItem> item in list) { if (!item.Value.isSaveHost()) { continue; } string temp_host = getIp(item.Value.After); if (string.IsNullOrEmpty(temp_host)) { sb.Append(Util.DELIMITER_INFO); } sb.Append(temp_host).Append("\t\t\t\t\t").AppendLine(item.Value.Before); } string text = "\r\n### PLink Host Policy ###\r\n" + sb.ToString(); File.WriteAllText(HOST_ROOT + Util.HOST_SOURCE, text); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } }
// call by fiddler public void OnLoad() { msgAdmin.Visible = !Util.canModifyHosts(); bool running = Util.getPrefBool(Util.REG_KEY_RUNNING); // 비정상 종료 , running 변수가 남아있으면 비정상 종료 체크 하시오. if (running) { PLink.host.initHostFile(); plink.initCapture(); } PLink.host.backupHostFile(); bool auto = Util.getPrefBool(Util.REG_KEY_AUTO); bool start = Util.getPrefBool(Util.REG_KEY_START); int current = Util.getPrefInt(Util.REG_KEY_CURRENT_POLICY); int web_select = Util.getPrefInt(Util.REG_KEY_WEB_POLICY_SELECT); string local_path = Util.getPref(Util.REG_KEY_LOCAL_POLICY_PATH); try { PLink.host.Current = current; // regist setting load loadWebData(); autoStart.Checked = auto; if (autoStart.Checked) { changeStatus(current); if (Util.isWeb(current)) { if (web_select > -1) { cbWebPolicy.SelectedIndex = web_select; } if (!string.IsNullOrEmpty(local_path)) { loadLocalData(local_path); } } else if (Util.isFile(current)) { if (!string.IsNullOrEmpty(local_path)) { loadLocalData(local_path, true); } } // set start button checkBox2.Checked = start; } } catch (Exception ex) { log(ex.Message); } Util.setPrefBool(Util.REG_KEY_RUNNING, true); // 북마크 로드 ArrayList bookmark = PLink.host.getBookmarkList(); foreach (KeyValuePair <string, string> mark in bookmark) { bookmarkList.Items.Add(mark); } }