/// <summary> /// 生成hosts文件缓存 /// </summary> /// <param name="AsmFlags">标志位</param> private static void AssembleHosts(int[] AsmFlags, mainFrame mainForm) { string filename = @"hosts.tmp"; string TargetPath = Environment.CurrentDirectory; //设置缓存文件 string TargetFile = Path.Combine(TargetPath, filename); //缓存文件流 FileStream outfile = new FileStream(TargetFile, FileMode.Append); StreamWriter fileWriter = new StreamWriter(outfile, Encoding.Default); fileWriter.BaseStream.Seek(0, SeekOrigin.End); foreach (int asmCount in regionOrder) { bool hasError = false; if (AsmFlags[asmCount] == 1) { string prefix = "# region "; int regionStart = hostsStream.IndexOf(prefix + sectionName[asmCount]); if (regionStart != -1) { int regionEnd = hostsStream.IndexOf("# endregion", regionStart); int regionCount = regionEnd - regionStart + 1; string[] region = hostsStream.GetRange(regionStart, regionCount).ToArray(); //输出asmCount对应块hosts列表 foreach (string entry in region) { fileWriter.WriteLine(entry); } fileWriter.Flush(); //修改主窗口图标 mainForm.TurnGreen(asmCount); } else { //Error 文件缺少内容 hasError = true; mainForm.TurnRed(asmCount); } } if (hasError) { //Error 文件缺少内容 msg.SetDialog(2, Resources.msg_err_res); msg.ShowDialog(); } } fileWriter.Close(); }