Exemplo n.º 1
0
        public static void ParseFileWindows(string filename, Form1 form1)
        {
            CultureInfo  info   = CultureInfo.InvariantCulture;
            StreamReader reader = new StreamReader(filename);

            files.Clear();
            string[] directory = null;

            string line = "";

            while ((line = reader.ReadLine()) != null)
            {
                if (line.Contains(DIRECTORY_OF))
                {
                    directory = line.Substring(line.IndexOf(DIRECTORY_OF) + DIRECTORY_OF.Length).Trim().Split(new char[] { '\\' }).ToArray();
                    Console.WriteLine(line);
                    Array.ForEach(directory, Console.WriteLine);
                }
                else
                {
                    Match dateMatch = Regex.Match(line, REGEX_DATE_PATTERN);
                    if (dateMatch.Success && !line.Contains("<DIR>"))
                    {
                        Match    filenameMatch = Regex.Match(line.Trim(), REGEX_FILENAME_PATTERN, RegexOptions.RightToLeft);
                        FILEITEM newFileItem   = new FILEITEM()
                        {
                            folder = directory, filename = filenameMatch.Value
                        };
                        files.Add(newFileItem);
                    }
                }
            }
        }
Exemplo n.º 2
0
        public static void ParseFileLinux(string filename, Form1 form1)
        {
            const string DIRECTORY_OF           = "/";
            const string REGEX_DATE_PATTERN     = @"[d][l,r,w,x,t,-]{9}\s";
            const string REGEX_IS_FILE          = @"[-][l,r,w,x,t,-]{9}\s";
            const string REGEX_FILENAME_PATTERN = @"[^\s]+";

            CultureInfo  info   = CultureInfo.InvariantCulture;
            StreamReader reader = new StreamReader(filename);

            files.Clear();
            string[] directory = null;

            string line = "";

            while ((line = reader.ReadLine()) != null)
            {
                //Console.WriteLine(line);
                if (line.StartsWith(DIRECTORY_OF))
                {
                    if (line.EndsWith(":"))
                    {
                        line = line.Substring(0, line.Length - 1);
                    }
                    directory = line.Substring(line.IndexOf(DIRECTORY_OF) + DIRECTORY_OF.Length).Trim().Split(new char[] { '/' }).ToArray();
                    Console.WriteLine(line);
                    //Console.WriteLine(line.Substring(line.IndexOf(DIRECTORY_OF) + DIRECTORY_OF.Length).Trim().Split('/'));
                    Array.ForEach(directory, Console.WriteLine);
                }
                else
                {
                    Match dateMatch = Regex.Match(line, REGEX_IS_FILE);
                    if (dateMatch.Success)
                    {
                        //Console.WriteLine(line);
                        Match filenameMatch = Regex.Match(line.Trim(), REGEX_FILENAME_PATTERN, RegexOptions.RightToLeft);
                        //string fileNameStripped = filenameMatch.Value.Substring(6);
                        FILEITEM newFileItem = new FILEITEM()
                        {
                            folder = directory, filename = filenameMatch.Value
                        };
                        files.Add(newFileItem);
                    }
                }
            }
        }
Exemplo n.º 3
0
        private void OpenButton_Click(object sender, EventArgs e)
        {
            int            result          = -1;
            string         fileName        = null;
            OpenFileDialog openFileDialog1 = new OpenFileDialog();


            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                result   = checkType(openFileDialog1.FileName);
                fileName = openFileDialog1.FileName;
            }

            if (result == 1)
            {
                FILEITEM.ParseFileWindows(fileName, this);
            }
            if (result == 2)
            {
                StreamReader reading = File.OpenText(fileName);
                string       str     = reading.ReadLine();
                string       text    = File.ReadAllText(fileName);
                text     = text.Replace("./", str + "/");
                fileName = fileName + "_tmp";
                File.WriteAllText(fileName, text);
                FILEITEM.ParseFileLinux(fileName, this);
            }
            this.treeView.Nodes.Clear();
            this.treeView.Invalidate();


            FILEITEM.MakeTree(FILEITEM.files, null, treeView, 0);

            treeView.ExpandAll();
            isExpanded = true;
        }