Ejemplo n.º 1
0
        /// <summary>
        ///		获取模式文件字符串
        /// </summary>
        /// <returns>模式文件字符串</returns>
        public string ToFileString()
        {
            string FileString;

            // 进程模式
            if (Type == 0)
            {
                FileString = $"# {Remark}\r\n";
            }

            // TUN/TAP 规则内 IP CIDR,无 Bypass China 设置
            else if (Type == 1)
            {
                FileString = $"# {Remark}, {Type}, 0\r\n";
            }

            // TUN/TAP 全局,绕过规则内 IP CIDR
            // HTTP 代理(自动设置到系统代理)
            // Socks5 代理(不自动设置到系统代理)
            // Socks5 + HTTP 代理(不自动设置到系统代理)
            else
            {
                FileString = $"# {Remark}, {Type}, {(BypassChina ? 1 : 0)}\r\n";
            }

            foreach (var item in Rule)
            {
                FileString = $"{FileString}{item}\r\n";
            }

            // 去除最后两个多余回车符和换行符
            FileString = FileString.Substring(0, FileString.Length - 2);

            return(FileString);
        }
Ejemplo n.º 2
0
 private void MainMenuSave_Click(object sender, EventArgs e)
 {
     if (saveFileDialog1.ShowDialog() == DialogResult.OK)
     {
         string path = saveFileDialog1.FileName;
         FileString.SaveFile(label2.Text, path);
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Things changed in 3.2.0
        /// </summary>
        private void FindVersionInfo2()
        {
            long startOffset = FileString.IndexOf("RELEASE_BUILD");

            if (startOffset > 0)
            {
                BaseStream.Position = startOffset;

                do
                {
                    BaseStream.Position--;
                } while (PeekChar() == 0);

                while (PeekChar() != 0)
                {
                    BaseStream.Position--;
                }

                BaseStream.Position++;
                var version = this.ReadCString();
                BaseStream.Position -= 2;

                while (PeekChar() != 0)
                {
                    BaseStream.Position--;
                }

                do
                {
                    BaseStream.Position--;
                } while (PeekChar() == 0);

                while (PeekChar() != 0)
                {
                    BaseStream.Position--;
                }

                BaseStream.Position++;
                var build = this.ReadCString();

                m_version = new ClientVersion(version + "." + build);

                /*
                 * Aug 17 2009.10314....3.2.0..RELEASE_BUILD
                 * */
                //BaseStream.Position = startOffset - 16;

                //var build = this.ReadCString();
                //BaseStream.Position += 3;
                //m_version = new ClientVersion(this.ReadCString() + "." + build);
            }
            else
            {
                throw new InvalidDataException("Could not locate version information");
            }
        }
Ejemplo n.º 4
0
        private void MainMenuOpen_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                string path = openFileDialog1.FileName;
                File_Text.Text = File.ReadAllText(path);

                FileString instance   = new FileString(path);
                string     output_str = string.Join("; ", instance.ReadStringFromFile());

                label2.Text = output_str;
            }
        }
Ejemplo n.º 5
0
        private void FindVersionInfo()
        {
            long startOffset = FileString.IndexOf("=> Version %s (%s) %s");

            if (startOffset > 0)
            {
                BaseStream.Position = startOffset;
                this.ReadCString();

                while (PeekChar() == 0)
                {
                    BaseStream.Position++;
                }
                var version = this.ReadCString();

                while (PeekChar() == 0)
                {
                    BaseStream.Position++;
                }
                var build = this.ReadCString();

                try
                {
                    m_version = new ClientVersion(version + "." + build);
                }
                catch
                {
                    // something went wrong:
                    FindVersionInfo2();
                }

                /*
                 * 6898....2.1.3...RELEASE_BUILD
                 * */
                //BaseStream.Position = startOffset - 16;

                //var build = this.ReadCString();
                //BaseStream.Position += 3;
                //m_version = new ClientVersion(this.ReadCString() + "." + build);
            }
            else
            {
                //throw new InvalidDataException("Could not locate version information");
                FindVersionInfo2();
            }
        }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            int    N = 0, i = 0, j = 0;
            string PathIn  = "Inlet.txt";
            string PathOut = "Outlet.txt";

            int[]  Vector = new int[50];
            string FileString;

            string[] FileMatrix;
            int      result = 0;

            using (var file = new StreamReader(PathIn))
            {
                while (!file.EndOfStream)
                {
                    FileString = file.ReadLine();
                    FileMatrix = FileString.Split(' ');
                    for (j = 0; j < FileMatrix.Length; j++)
                    {
                        Vector[j] = int.Parse(FileMatrix[j]);
                    }
                    i++;
                }
            }

            N = j;

            for (i = 1; i < N - 1; i++)
            {
                if (Vector[i - 1] > Vector[i] && Vector[i] < Vector[i + 1])
                {
                    result += Vector[i];
                }
            }
            using (var file = new StreamWriter(Path.GetFullPath(PathOut), false))
                file.Write($"Result: {result}");
            Console.WriteLine("Запись в файл произведена!");
            Console.ReadKey();
        }
Ejemplo n.º 7
0
        static void Main(string[] args)
        {
            int    N = 0, M = 0, i = 0, j = 0;
            string PathIn  = "Inlet.txt";
            string PathOut = "Outlet.txt";

            string[,] array = new string[50, 50];
            string temp;
            string FileString;

            string[] FileMatrix;
            int[]    lengthofStr = new int[50];

            using (var file = new StreamReader(PathIn))
            {
                while (!file.EndOfStream)
                {
                    FileString     = file.ReadLine();
                    FileMatrix     = FileString.Split(' ');
                    lengthofStr[i] = FileMatrix.Length;
                    for (j = 0; j < FileMatrix.Length; j++)
                    {
                        array[i, j] = FileMatrix[j];
                    }
                    i++;
                }
            }

            N = i;
            M = j;

            for (i = 0; i < N; i++)
            {
                if (lengthofStr[i] % 2 != 0)
                {
                    lengthofStr[i]--;


                    for (j = 0; j < lengthofStr[i]; j += 2)
                    {
                        temp            = array[i, j];
                        array[i, j]     = array[i, j + 1];
                        array[i, j + 1] = temp;
                    }

                    lengthofStr[i]++;
                    continue;
                }
                for (j = 0; j < lengthofStr[i]; j += 2)
                {
                    temp            = array[i, j];
                    array[i, j]     = array[i, j + 1];
                    array[i, j + 1] = temp;
                }
            }

            using (var file = new StreamWriter(Path.GetFullPath(PathOut), false))
            {
                for (i = 0; i < N; i++)
                {
                    for (j = 0; j < lengthofStr[i]; j++)
                    {
                        file.Write(array[i, j] + " ");
                    }
                    file.WriteLine();
                }
            }
            Console.WriteLine("Запись в файл произведена!");
            Console.ReadKey();
        }