void Wirteini() { try { string file = Path.Combine(Application.StartupPath, "Archselect.ini"); Writeini.Fileini = file; Writeini.Wirteini("username", "user", txtUser.Text.Trim()); } catch { } }
void Readini() { try { string file = Path.Combine(Application.StartupPath, "Archselect.ini"); Writeini.Fileini = file; string user = Writeini.Readini("username", "user"); txtUser.Text = user; } catch {} }
private void toolStripDouGotoP_ButtonClick(object sender, EventArgs e) { string file = Path.Combine(Application.StartupPath, "ScanConfig.ini"); Writeini.Fileini = file; string sj = Writeini.Readini("ImageConten", "GoPage").ToString(); if (sj.Trim().Length > 0) { int p; bool b = int.TryParse(sj, out p); if (!b || p <= 0) { return; } p += Clscheck.CrrentPage; if (p <= Clscheck.MaxPage) { Himg._Gotopage(p); } } }
public void LoadServerMenu() { contextMenuStrip1.Items.Clear(); //添加菜单一 ToolStripMenuItem AboutME; AboutME = AddContextMenu("关于", contextMenuStrip1.Items, null); AboutME.Click += AboutMe_Click; string path = System.Environment.CurrentDirectory; string iniFilePath = path + "\\" + "SquidConfig.ini"; Writeini writeini = new Writeini(); writeini.IniParser(iniFilePath); ToolStripMenuItem StartupSystem; StartupSystem = AddContextMenu("随系统启动", contextMenuStrip1.Items, null); StartupSystem.Click += RebootSystem_Click; ToolStripMenuItem CheckedUpdate; CheckedUpdate = AddContextMenu("检查更新", contextMenuStrip1.Items, null); CheckedUpdate.Click += CheckUpdate_Click; string IsFirstRun = writeini.GetSetting("DefaultStartup", "FirstRun"); // string path = System.Environment.CurrentDirectory; // string IsFirstRun = ReadINI("DefaultStartup", "FirstRun", @path + "\\" + "SquidConfig.ini"); if (IsFirstRun == "1") { // MessageBox.Show("第一次运行"); ToolStripMenuItem ProxyMode; ProxyMode = AddContextMenu("代理模式", contextMenuStrip1.Items, null); ProxyMode1 = AddContextMenu("全局代理", ProxyMode.DropDownItems, new EventHandler(GlobalWriteInIClicked)); ProxyMode2 = AddContextMenu("智能代理", ProxyMode.DropDownItems, new EventHandler(SmartWriteINIClicked)); //添加菜单一 ToolStripMenuItem subItem; subItem = AddContextMenu("服务器", contextMenuStrip1.Items, null); string ServerindexString = writeini.GetSetting("DefaultStartup", "index"); // string ServerindexString = ReadINI("DefaultStartup", "index", path + "\\" + "SquidConfig.ini"); // MessageBox.Show(ServerindexString); int ServerindexInt = int.Parse(ServerindexString); int j = 0; for (int i = 0; i < ServerindexInt; i++) { j = j + 1; string ServerAddress = writeini.GetSetting("User", "Server" + j.ToString()); // string ServerAddress = ReadINI("User", "Server" + j.ToString(), path + "\\" + "SquidConfig.ini"); // MessageBox.Show(ServerAddress); // EditServer.listBox1.Items.Add(ServerAddress); AddContextMenu(ServerAddress, subItem.DropDownItems, new EventHandler(MenuClicked)); } AddContextMenu("编辑服务器", subItem.DropDownItems, new EventHandler(EditServer)); //EditServer form2 = new EditServer(); //// form2.DisableButton += new EventHandler(form2_DisableButton); //form2.DisableButton += new EventHandler(LoadSetting); //form2.ShowDialog(); } else { // MessageBox.Show("第二次运行"); ToolStripMenuItem ProxyMode; ProxyMode = AddContextMenu("代理模式", contextMenuStrip1.Items, null); ProxyMode1 = AddContextMenu("全局代理", ProxyMode.DropDownItems, new EventHandler(GlobalWriteInIClicked)); ProxyMode2 = AddContextMenu("智能代理", ProxyMode.DropDownItems, new EventHandler(SmartWriteINIClicked)); //添加菜单一 ToolStripMenuItem subItem; subItem = AddContextMenu("服务器", contextMenuStrip1.Items, null); string ServerindexString = writeini.GetSetting("DefaultStartup", "index"); // string ServerindexString = ReadINI("DefaultStartup", "index", path + "\\" + "SquidConfig.ini"); // MessageBox.Show(ServerindexString); int ServerindexInt = int.Parse(ServerindexString); int j = 0; for (int i = 0; i < ServerindexInt; i++) { j = j + 1; string ServerAddress = writeini.GetSetting("User", "Server" + j.ToString()); // string ServerAddress = ReadINI("User", "Server" + j.ToString(), path + "\\" + "SquidConfig.ini"); // MessageBox.Show(ServerAddress); // EditServer.listBox1.Items.Add(ServerAddress); AddContextMenu(ServerAddress, subItem.DropDownItems, new EventHandler(MenuClicked)); } AddContextMenu("编辑服务器", subItem.DropDownItems, new EventHandler(EditServer)); } // contextMenuStrip1.Items.Clear(); // contextMenuStrip1.Items.Clear(); // subItem.DropDownItems.Clear(); string GlobalStatus = writeini.GetSetting("ProxyMode", "Global"); string SmartStatus = writeini.GetSetting("ProxyMode", "Smart"); // string GlobalStatus = ReadINI("ProxyMode", "Global", @path + "\\" + "SquidConfig.ini"); // string SmartStatus = ReadINI("ProxyMode", "Smart", @path + "\\" + "SquidConfig.ini"); if (GlobalStatus == "1") { ((ToolStripMenuItem)ProxyMode1).Checked = true; string DefaultServer = writeini.GetSetting("DefaultStartup", "Server"); // string DefaultServer = ReadINI("DefaultStartup", "Server", @path + "\\" + "SquidConfig.ini"); string PacURL = DefaultServer; RegularURL(PacURL); AdslSetSquidProxy(globalURL); string NotifyShowContent = "Squid V2.0.0.17" + Environment.NewLine + "代理模式: 全局" + Environment.NewLine + "服务器:" + globalURL; char[] myChar = NotifyShowContent.ToCharArray(); SetNotifyIconText(notifyIcon1, new string(myChar)); } else if (SmartStatus == "1") { ((ToolStripMenuItem)ProxyMode2).Checked = true; string DefaultServer = writeini.GetSetting("DefaultStartup", "Server"); // string DefaultServer = ReadINI("DefaultStartup", "Server", @path + "\\" + "SquidConfig.ini"); string NotifyShowContent = "Squid V2.0.0.17" + Environment.NewLine + "代理模式: 智能" + Environment.NewLine + "服务器:" + DefaultServer; char[] myChar = NotifyShowContent.ToCharArray(); SetNotifyIconText(notifyIcon1, new string(myChar)); } ToolStripMenuItem subItem1; subItem1 = AddContextMenu("-", contextMenuStrip1.Items, null); subItem1 = AddContextMenu("退出", contextMenuStrip1.Items, null); subItem1.Click += tested; }
void LoadSetting(object sender, EventArgs e) { contextMenuStrip1.Items.Clear(); //添加菜单一 ToolStripMenuItem AboutME; AboutME = AddContextMenu("关于", contextMenuStrip1.Items, null); AboutME.Click += AboutMe_Click; ToolStripMenuItem StartupSystem; StartupSystem = AddContextMenu("随系统启动", contextMenuStrip1.Items, null); StartupSystem.Click += RebootSystem_Click; ToolStripMenuItem CheckedUpdate; CheckedUpdate = AddContextMenu("检查更新", contextMenuStrip1.Items, null); CheckedUpdate.Click += CheckUpdate_Click; //ToolStripMenuItem subItem2; //subItem2 = AddContextMenu("重新加载配置", contextMenuStrip1.Items, new EventHandler(LoadSetting));\ string path = System.Environment.CurrentDirectory; string iniFilePath = path + "\\" + "SquidConfig.ini"; Writeini writeini = new Writeini(); writeini.IniParser(iniFilePath); string IsFirstRun = writeini.GetSetting("DefaultStartup", "FirstRun"); // string IsFirstRun = ReadINI("DefaultStartup", "FirstRun", @path + "\\" + "SquidConfig.ini"); if (IsFirstRun == "1") { } else { ToolStripMenuItem ProxyMode; ToolStripMenuItem subItem; ProxyMode = AddContextMenu("代理模式", contextMenuStrip1.Items, null); ProxyMode1 = AddContextMenu("全局代理", ProxyMode.DropDownItems, new EventHandler(GlobalWriteInIClicked)); ProxyMode2 = AddContextMenu("智能代理", ProxyMode.DropDownItems, new EventHandler(SmartWriteINIClicked)); //添加菜单一 subItem = AddContextMenu("服务器", contextMenuStrip1.Items, null); ToolStripMenuItem subItem1; subItem1 = AddContextMenu("-", contextMenuStrip1.Items, null); subItem1 = AddContextMenu("退出", contextMenuStrip1.Items, null); subItem1.Click += tested; string ServerindexString = writeini.GetSetting("DefaultStartup", "index"); //string ServerindexString = ReadINI("DefaultStartup", "index", path + "\\" + "SquidConfig.ini"); // MessageBox.Show(ServerindexString); int ServerindexInt = int.Parse(ServerindexString); int j = 0; for (int i = 0; i < ServerindexInt; i++) { j = j + 1; string inipath = System.Environment.CurrentDirectory; // Writeini writeini = new Writeini(); string ServerAddress = writeini.GetSetting("User", "Server" + j.ToString()); // MessageBox.Show(ServerAddress); //string ServerAddress = ReadINI("User", "Server" + j.ToString(), path + "\\" + "SquidConfig.ini"); // MessageBox.Show(ServerAddress); // EditServer.listBox1.Items.Add(ServerAddress); AddContextMenu(ServerAddress, subItem.DropDownItems, new EventHandler(MenuClicked)); } AddContextMenu("编辑服务器", subItem.DropDownItems, new EventHandler(EditServer)); } // contextMenuStrip1.Items.Clear(); // contextMenuStrip1.Items.Clear(); // subItem.DropDownItems.Clear(); // SetSquidProxy1((sender as ToolStripMenuItem).Text); string GlobalStatus = writeini.GetSetting("ProxyMode", "Global"); string SmartStatus = writeini.GetSetting("ProxyMode", "Smart"); //string GlobalStatus = ReadINI("ProxyMode", "Global", @path + "\\" + "SquidConfig.ini"); //string SmartStatus = ReadINI("ProxyMode", "Smart", @path + "\\" + "SquidConfig.ini"); if (GlobalStatus == "1") { string DefaultServer = writeini.GetSetting("DefaultStartup", "Server"); // string DefaultServer = ReadINI("DefaultStartup", "Server", @path + "\\" + "SquidConfig.ini"); string PacURL = DefaultServer; RegularURL(PacURL); AdslSetSquidProxy(globalURL); string NotifyShowContent = "Squid V2.0.0.17" + Environment.NewLine + "代理模式: 全局" + Environment.NewLine + "服务器:" + globalURL; char[] myChar = NotifyShowContent.ToCharArray(); SetNotifyIconText(notifyIcon1, new string(myChar)); ((ToolStripMenuItem)ProxyMode1).Checked = true; } else if (SmartStatus == "1") { ((ToolStripMenuItem)ProxyMode2).Checked = true; string DefaultServer = writeini.GetSetting("DefaultStartup", "Server"); string NotifyShowContent = "Squid V2.0.0.17" + Environment.NewLine + "代理模式: 智能" + Environment.NewLine + "服务器:" + DefaultServer; char[] myChar = NotifyShowContent.ToCharArray(); SetNotifyIconText(notifyIcon1, new string(myChar)); // MessageBox.Show("test"); SetSquidProxy1(DefaultServer); //// string DefaultServer = ReadINI("DefaultStartup", "Server", @path + "\\" + "SquidConfig.ini"); //string path1 = System.Environment.CurrentDirectory; //string ServerindexString1 = @path1 + "\\" + "SquidConfig.ini"; //byte[] buffer = new byte[65535]; //int rel = GetPrivateProfileSectionNamesA(buffer, buffer.GetUpperBound(0), ServerindexString1); //int iCnt, iPos; //System.Collections.ArrayList arrayList = new ArrayList(); //string tmp; //if (rel > 0) //{ // iCnt = 0; iPos = 0; // for (iCnt = 0; iCnt < rel; iCnt++) // { // if (buffer[iCnt] == 0x00) // { // tmp = System.Text.ASCIIEncoding.Default.GetString(buffer, iPos, iCnt - iPos).Trim(); // iPos = iCnt + 1; // if (tmp != "") // arrayList.Add(tmp); // // MessageBox.Show(tmp); // } // } //} //bool exists = ((IList)arrayList).Contains("User"); //if (exists) //{ // string NotifyShowContent = "Squid V2.0.0.17" + Environment.NewLine + "代理模式: 智能" + Environment.NewLine + "服务器:" + DefaultServer; // char[] myChar = NotifyShowContent.ToCharArray(); // SetNotifyIconText(notifyIcon1, new string(myChar)); // // MessageBox.Show("test"); // SetSquidProxy1(DefaultServer); //} //// 存在 //else //// 不存在 //{ // // MessageBox.Show("no exists"); // notifyIcon1.Text = "Squid V2.0.0.17" + Environment.NewLine + "代理模式: 智能" + Environment.NewLine + "服务器: 未加入"; //} } }
void GlobalWriteInIClicked(object sender, EventArgs e) { string path = System.Environment.CurrentDirectory; string iniFilePath = path + "\\" + "SquidConfig.ini"; Writeini writeini = new Writeini(); writeini.IniParser(iniFilePath); writeini.AddSetting("ProxyMode", "Global", "1"); writeini.AddSetting("ProxyMode", "Smart", "0"); writeini.SaveiniFile(); //IniWriteValue("ProxyMode", "Global", "1"); //IniWriteValue("ProxyMode", "Smart", "0"); // SetSquidProxy1((sender as ToolStripMenuItem).Text); string GlobalStatus = writeini.GetSetting("ProxyMode", "Global"); string SmartStatus = writeini.GetSetting("ProxyMode", "Smart"); //string GlobalStatus = ReadINI("ProxyMode", "Global", @path + "\\" + "SquidConfig.ini"); //string SmartStatus = ReadINI("ProxyMode", "Smart", @path + "\\" + "SquidConfig.ini"); if (GlobalStatus == "1") { //for (int dlint = 0; dlint< 2; dlint++) //{ try { string Downloadfilename = "GFWlist.pac"; string DefaultServer = writeini.GetSetting("DefaultStartup", "Server"); // string DefaultServer = ReadINI("DefaultStartup", "Server", @path + "\\" + "SquidConfig.ini"); string PacURL = DefaultServer; // RegularURL(PacURL); string url = PacURL; // MessageBox.Show(url); WebClient client = new WebClient(); ServicePointManager.DefaultConnectionLimit = 512; client.CachePolicy = new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.NoCacheNoStore); // client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged); client.DownloadFileCompleted += new AsyncCompletedEventHandler(downloader_DownloadFileCompleted); // Starts the download client.DownloadFileAsync(new Uri(url), @path + "\\" + Downloadfilename); client.Dispose(); } catch (Exception SquidError) { MessageBox.Show(SquidError.Message.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } // System.Threading.Thread.Sleep(5000); //} } else if (SmartStatus == "1") { string DefaultServer = writeini.GetSetting("DefaultStartup", "Server"); // string DefaultServer = ReadINI("DefaultStartup", "Server", @path + "\\" + "SquidConfig.ini"); SetSquidProxy1(DefaultServer); string NotifyShowContent = "Squid V2.0.0.17" + Environment.NewLine + "代理模式: 智能" + Environment.NewLine + "服务器:" + DefaultServer; char[] myChar = NotifyShowContent.ToCharArray(); SetNotifyIconText(notifyIcon1, new string(myChar)); } LoadServerMenu();// LoadServerMenu }
public void ReadSections() { string path = System.Environment.CurrentDirectory; string ServerindexString = @path + "\\" + "SquidConfig.ini"; if (File.Exists(ServerindexString)) { // MessageBox.Show("存在ini"); } else { // MessageBox.Show("不存在ini"); Writeini writeini = new Writeini(); writeini.AddSetting("DefaultStartup", "index", "0"); writeini.AddSetting("DefaultStartup", "FirstRun", "1"); writeini.AddSetting("ProxyMode", "Global", "0"); writeini.AddSetting("ProxyMode", "Smart", "1"); writeini.SaveiniFile(); //EditServer form2 = new EditServer(); //// form2.DisableButton += new EventHandler(form2_DisableButton); //form2.DisableButton += new EventHandler(LoadSetting); //form2.ShowDialog(); } }
void SmartWriteINIClicked(object sender, EventArgs e) { string path = System.Environment.CurrentDirectory; string iniFilePath = path + "\\" + "SquidConfig.ini"; Writeini writeini = new Writeini(); writeini.IniParser(iniFilePath); writeini.AddSetting("ProxyMode", "Global", "0"); writeini.AddSetting("ProxyMode", "Smart", "1"); writeini.SaveiniFile(); //IniWriteValue("ProxyMode", "Global", "0"); //IniWriteValue("ProxyMode", "Smart", "1"); // SetSquidProxy1((sender as ToolStripMenuItem).Text); string GlobalStatus = writeini.GetSetting("ProxyMode", "Global"); string SmartStatus = writeini.GetSetting("ProxyMode", "Smart"); //string GlobalStatus = ReadINI("ProxyMode", "Global", @path + "\\" + "SquidConfig.ini"); //string SmartStatus = ReadINI("ProxyMode", "Smart", @path + "\\" + "SquidConfig.ini"); if (GlobalStatus == "1") { string DefaultServer = writeini.GetSetting("DefaultStartup", "Server"); // string DefaultServer = ReadINI("DefaultStartup", "Server", @path + "\\" + "SquidConfig.ini"); string PacURL = DefaultServer; RegularURL(PacURL); AdslSetSquidProxy(globalURL); // string NotifyShowContent = "Squid V2.0.0.17" + Environment.NewLine + "代理模式: 全局" + Environment.NewLine + "服务器:" + globalURL; char[] myChar = NotifyShowContent.ToCharArray(); SetNotifyIconText(notifyIcon1, new string(myChar)); } else if (SmartStatus == "1") { string DefaultServer = writeini.GetSetting("DefaultStartup", "Server"); // string DefaultServer = ReadINI("DefaultStartup", "Server", @path + "\\" + "SquidConfig.ini"); SetSquidProxy1(DefaultServer); string NotifyShowContent = "Squid V2.0.0.17" + Environment.NewLine + "代理模式: 智能" + Environment.NewLine + "服务器:" + DefaultServer; char[] myChar = NotifyShowContent.ToCharArray(); SetNotifyIconText(notifyIcon1, new string(myChar)); } LoadServerMenu();// LoadServerMenu }
void MenuClicked(object sender, EventArgs e) { string path = System.Environment.CurrentDirectory; string iniFilePath = path + "\\" + "SquidConfig.ini"; Writeini writeini = new Writeini(); writeini.IniParser(iniFilePath); // MessageBox.Show(((sender as ToolStripMenuItem).Text)); // SetSquidProxy1((sender as ToolStripMenuItem).Text); string GlobalStatus = writeini.GetSetting("ProxyMode", "Global"); string SmartStatus = writeini.GetSetting("ProxyMode", "Smart"); //string GlobalStatus = ReadINI("ProxyMode", "Global", @path + "\\" + "SquidConfig.ini"); //string SmartStatus = ReadINI("ProxyMode", "Smart", @path + "\\" + "SquidConfig.ini"); if (GlobalStatus == "1") { try { string Downloadfilename = "GFWlist.pac"; string DefaultServer= writeini.GetSetting("DefaultStartup", "Server"); // string DefaultServer = ReadINI("DefaultStartup", "Server", @path + "\\" + "SquidConfig.ini"); string PacURL = DefaultServer; // RegularURL(PacURL); string url = PacURL; WebClient client = new WebClient(); ServicePointManager.DefaultConnectionLimit = 512; // client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged); client.DownloadFileCompleted += new AsyncCompletedEventHandler(downloader_DownloadFileCompleted); // Starts the download client.DownloadFileAsync(new Uri(url), @path + "/" + Downloadfilename); } catch (Exception SquidError) { MessageBox.Show(SquidError.Message.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } // RegularURL(PacURL); // AdslSetSquidProxy(globalURL); // string path = System.Environment.CurrentDirectory; // string Downloadfilename = "GFWlist.pac"; //System.IO.StreamReader sr = new StreamReader("c:\\1.pac", Encoding.Default); //string tempstr = null; //int count = 0; //while ((tempstr = sr.ReadLine()) != null) //{ // count++; // if (count == 3) // { // string[] StrArray = tempstr.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); // string newsquidproxy = StrArray[4]; // string str = newsquidproxy; // int i = 6; // string StrServerIP = str.Substring(0, str.Length - i); // or str=str.Remove(str.Length-i,i); // // MessageBox.Show(StrServerIP); // AdslSetSquidProxy(StrServerIP); // string NotifyShowContent = "Squid V2.0.0.17" + Environment.NewLine + "代理模式: 全局" + Environment.NewLine + "服务器:" + StrServerIP; // char[] myChar = NotifyShowContent.ToCharArray(); // SetNotifyIconText(notifyIcon1, new string(myChar)); // } //} //sr.Close(); // release Resources } else if (SmartStatus == "1") { // MessageBox.Show(((sender as ToolStripMenuItem).Text)); SetSquidProxy1((sender as ToolStripMenuItem).Text); string NotifyShowContent = "Squid V2.0.0.17" + Environment.NewLine + "代理模式: 智能代理" + Environment.NewLine + "服务器:" + ((sender as ToolStripMenuItem).Text); char[] myChar = NotifyShowContent.ToCharArray(); SetNotifyIconText(notifyIcon1, new string(myChar)); } writeini.AddSetting("DefaultStartup", "Server", ((sender as ToolStripMenuItem).Text)); writeini.SaveiniFile(); // IniWriteValue("DefaultStartup", "Server", ((sender as ToolStripMenuItem).Text)); }