コード例 #1
0
ファイル: LZTable.cs プロジェクト: Dmytrych/ProgLab4
        public static void Pack(string path)
        {
            string  originPath  = path.Replace(path.Split('\\')[path.Split('\\').Length - 1], "");
            string  allContains = "";
            LZTable table       = new LZTable();

            if (path.Contains(".txt"))
            {
                allContains += new StreamReader(path).ReadToEnd() + "\n" + separator + "\n";
            }
            else
            {
                foreach (string dirPath in Directory.GetDirectories(path))
                {
                    allContains += PackDir(originPath, dirPath);
                }
                foreach (string filename in Directory.GetFiles(path))
                {
                    allContains += filename.Replace(originPath, "") + "\n" + new StreamReader(filename).ReadToEnd() + "\n" + separator + "\n";
                }
            }
            StreamWriter writer = new StreamWriter(path + "_Packed.txt");

            writer.Write(table.Encode1(allContains));
            writer.Close();
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: Dmytrych/ProgLab4
 static void Main()
 {
     //LZTable.Pack("D:\\Delete");
     //Console.WriteLine(Interpreter.From36B("y1"));
     LZTable.Unpack("D:\\Delete_Packed.txt", "D:\\Game");
     //LZTable table = new LZTable();
     // StreamReader reader = new StreamReader("D:\\Delete\\Text1.txt");
     //StreamWriter writer = new StreamWriter("D:\\Delete_Packed.txt");
     //StreamWriter writer1 = new StreamWriter("D:\\Delete_Packed12.txt");
     //writer.Write(table.Encode1(reader.ReadToEnd()));
     //reader = new StreamReader("D:\\Delete\\Text1.txt");
     //writer1.Write(Interpreter.T2B(reader.ReadToEnd()));
     //writer1.Close();
     //writer.Close();
     //Console.Write(Interpreter.From36B("y1"));
     //Console.ReadLine();
 }
コード例 #3
0
ファイル: LZTable.cs プロジェクト: Dmytrych/ProgLab4
        public static void Unpack(string fromPath, string toPath)
        {
            LZTable      table = new LZTable();
            string       input;
            StreamReader reader     = new StreamReader(fromPath);;
            StreamWriter translator = new StreamWriter(toPath + "\\temp.txt");

            translator.Write(table.Decode(reader.ReadToEnd()));
            translator.Close();
            reader = new StreamReader(toPath + "\\temp.txt");
            string txtPath = toPath + "\\" + reader.ReadLine();

            Directory.CreateDirectory(txtPath.Remove(txtPath.LastIndexOf('\\')));
            StreamWriter writer = new StreamWriter(txtPath);

            while (!reader.EndOfStream)
            {
                input = reader.ReadLine();
                if (input.Contains(separator))
                {
                    writer.Close();
                    if (!reader.EndOfStream)
                    {
                        txtPath = toPath + "\\" + reader.ReadLine();
                        Directory.CreateDirectory(txtPath.Remove(txtPath.LastIndexOf('\\')));
                        writer = new StreamWriter(txtPath);
                    }
                }
                else
                {
                    writer.WriteLine(input);
                }
            }
            reader.Close();
            File.Delete(toPath + "\\temp.txt");
        }