diff --git a/README.md b/README.md index c5f1085..6f82e46 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,13 @@ unzip_pc3 ========= -Compress and decompress pc3 files for AutoCAD +Compress and decompress pc3 files for AutoCAD + +Original Version: Boxa Shu 2014-Okt-16 + +v1.01 Arie van Brakel 2020-Jan-16 +-Fixed Special chars in strings #1 + If special chars like are replaced by ? +-Added error messages and userfeedback +-Added filter on files +-Added support for extracting .PMP and .CTB files \ No newline at end of file diff --git a/unzip_pc3/Ionic.Zip.dll b/unzip_pc3/Ionic.Zip.dll new file mode 100644 index 0000000..95fa928 Binary files /dev/null and b/unzip_pc3/Ionic.Zip.dll differ diff --git a/unzip_pc3/Program.cs b/unzip_pc3/Program.cs index 8587dc4..544dbf0 100644 --- a/unzip_pc3/Program.cs +++ b/unzip_pc3/Program.cs @@ -4,8 +4,6 @@ using System.Text; using System.Threading.Tasks; using System.IO; - - using Ionic.Zlib; namespace unzip_pc3 @@ -20,85 +18,129 @@ class Program static void Main(string[] args) { //' на основе вот этого топака : http://www.theswamp.org/index.php?topic=41529.0 - if(args.Length == 2){ + if (args.Length == 2) + { if (File.Exists(args[1])) { - // тут распаковываем архивчик - if (args[0] == "e") + // тут распаковываем архивчик, Extract + if ((args[0] == "e") || (args[0] == "-e")) { string fileName = args[1]; - using (FileStream fs = File.Open(fileName, FileMode.Open, FileAccess.Read)) + string ext = Path.GetExtension(fileName).ToUpper(); + if ((0 == String.Compare(ext, ".PC3"))||(0 == String.Compare(ext, ".PMP"))||(0 == String.Compare(ext, ".CTB"))) { - fs.Seek(60L, SeekOrigin.Begin); - - using (ZlibStream zs = new ZlibStream(fs, CompressionMode.Decompress)) + using (FileStream fs = File.Open(fileName, FileMode.Open, FileAccess.Read)) { - using (StreamReader sr = new StreamReader(zs)) + fs.Seek(60L, SeekOrigin.Begin); + using (ZlibStream zs = new ZlibStream(fs, CompressionMode.Decompress)) { - //тут текстово содержание файла - string s = sr.ReadToEnd(); + // Console.WriteLine("\nStart:"); + int chr; + chr = 0; + string str = ""; - using (FileStream fs_out = File.Open(fileName + ".txt", FileMode.Create, FileAccess.ReadWrite)) + while (chr > -1) { - fs_out.Write(Encoding.Default.GetBytes(s), 0, Encoding.Default.GetBytes(s).Length); + chr = zs.ReadByte(); + if (chr > -1) + { + str = str + Convert.ToChar(chr); + } } + //Console.Write(str); + //Console.WriteLine("\nend:"); + /* using (StreamReader sr = new StreamReader(zs)) + { + //тут текстово содержание файла + string s = sr.ReadToEnd(); + //Console.WriteLine(s); + */ + using (FileStream fs_out = File.Open(fileName + ".txt", FileMode.Create, FileAccess.ReadWrite)) + { + fs_out.Write(Encoding.Default.GetBytes(str), 0, Encoding.Default.GetBytes(str).Length); + } + //} + Console.WriteLine("\n File saved to {0}.txt ", fileName); } } } + else + { + Console.Write("File {0} is not a .pc3 file", args[1]); + } } - - // Тут запаковываем все обратно - if (args[0] == "c") + else if ((args[0] == "c") || (args[0] == "-c"))// Тут запаковываем все обратно, COMPRESS { string fileName = args[1]; - using (FileStream fs = File.Open(fileName, FileMode.Open, FileAccess.Read)) + string ext = Path.GetExtension(fileName); + if (0 == String.Compare(ext.ToUpper(), ".TXT")) { - using (StreamReader sr = new StreamReader(fs)) + using (FileStream fs = File.Open(fileName, FileMode.Open, FileAccess.Read)) { - // заголовок файла, без него автокад не работает - String pref_s = "PIAFILEVERSION_2.0,PC3VER1,compress\r\npmzlibcodec"; - /* - is a good starting point, but contains several errors/lack of information - The header size is 60 No 59 - bytes 49->52 = ZlibCodec.Adler32 - bytes 53->56 = decompresse stream size - bytes 57->60 = compressed stream size - Эти данные(байты) должны вычеслятся - */ - String s = sr.ReadToEnd(); - //Byte[] ZlibCodec_Adler32 = { 157, 94, 173, 006 }; - long decompresse_stream_size = fs.Length; - //тут считаем размер запакованных данных - byte[] compressed_stream_size; - using (var ms = new MemoryStream()) + using (StreamReader sr = new StreamReader(fs, Encoding.Default)) /*Mod by Arie add encoding*/ { - using (ZlibStream deflateStream = new ZlibStream(ms, CompressionMode.Compress, - CompressionLevel.BestCompression, false)) + // заголовок файла, без него автокад не работает + String pref_s = "PIAFILEVERSION_2.0,PC3VER1,compress\r\npmzlibcodec"; + /* + is a good starting point, but contains several errors/lack of information + The header size is 60 No 59 + bytes 49->52 = ZlibCodec.Adler32 + bytes 53->56 = decompresse stream size + bytes 57->60 = compressed stream size + Эти данные(байты) должны вычеслятся + */ + String s = sr.ReadToEnd(); + //Console.Write(s); + //Byte[] ZlibCodec_Adler32 = { 157, 94, 173, 006 }; + long decompresse_stream_size = fs.Length; + //тут считаем размер запакованных данных + byte[] compressed_stream_size; + using (var ms = new MemoryStream()) { - deflateStream.Write(Encoding.Default.GetBytes(s), 0, Encoding.Default.GetBytes(s).Length); + using (ZlibStream deflateStream = new ZlibStream(ms, CompressionMode.Compress, CompressionLevel.BestCompression, false)) + { + deflateStream.Write(Encoding.Default.GetBytes(s), 0, Encoding.Default.GetBytes(s).Length); + } + compressed_stream_size = ms.ToArray(); } - compressed_stream_size = ms.ToArray(); - } - // Тут все пишем в файл - using (FileStream fs_out = File.Open(fileName + ".pc3", FileMode.Create, FileAccess.ReadWrite)) - { - using (ZlibStream zs = new ZlibStream(fs_out, CompressionMode.Compress, - CompressionLevel.BestCompression, false)) + // Тут все пишем в файл + using (FileStream fs_out = File.Open(fileName + ".pc3", FileMode.Create, FileAccess.ReadWrite)) { - fs_out.Write(Encoding.Default.GetBytes(pref_s), 0, Encoding.Default.GetBytes(pref_s).Length); - //fs_out.Write(ZlibCodec_Adler32, 0, 4); - fs_out.Write(BitConverter.GetBytes(new ZlibCodec(CompressionMode.Compress).Adler32), 0, 4); - fs_out.Write(BitConverter.GetBytes(decompresse_stream_size), 0, 4); - fs_out.Write(BitConverter.GetBytes(compressed_stream_size.Length), 0, 4); - zs.Write(Encoding.Default.GetBytes(s), 0, Encoding.Default.GetBytes(s).Length); + using (ZlibStream zs = new ZlibStream(fs_out, CompressionMode.Compress, + CompressionLevel.BestCompression, false)) + { + fs_out.Write(Encoding.Default.GetBytes(pref_s), 0, Encoding.Default.GetBytes(pref_s).Length); + //fs_out.Write(ZlibCodec_Adler32, 0, 4); + fs_out.Write(BitConverter.GetBytes(new ZlibCodec(CompressionMode.Compress).Adler32), 0, 4); + fs_out.Write(BitConverter.GetBytes(decompresse_stream_size), 0, 4); + fs_out.Write(BitConverter.GetBytes(compressed_stream_size.Length), 0, 4); + zs.Write(Encoding.Default.GetBytes(s), 0, Encoding.Default.GetBytes(s).Length); + } } + Console.WriteLine("\n File saved to {0}.pc3 ", fileName); } } } + else + { + Console.Write("File {0} is not a .txt file", args[1]); + } } + else + { + Console.Write("incorrect input\nFormat unzip_pc3 (AutoCAD zip/unzip .pc3 files) \n to extract: unzip_pc3 e xxx.pc3\n to Compress: unzip_pc3 c xxx.txt"); + } + } + else + { + Console.Write("File {0} does not exist", args[1]); } - } + } + else + { + Console.Write("incorrect input\nFormat unzip_pc3 (AutoCAD zip/unzip .pc3 files) \n to extract: unzip_pc3 e xxx.pc3\n to Compress: unzip_pc3 c xxx.txt"); + } } } } diff --git a/unzip_pc3/bin/Debug/unzip_pc3.exe b/unzip_pc3/bin/Debug/unzip_pc3.exe index 729068b..968cdb1 100644 Binary files a/unzip_pc3/bin/Debug/unzip_pc3.exe and b/unzip_pc3/bin/Debug/unzip_pc3.exe differ diff --git a/unzip_pc3/packages.config b/unzip_pc3/packages.config new file mode 100644 index 0000000..c0a93c9 --- /dev/null +++ b/unzip_pc3/packages.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/unzip_pc3/unzip_pc3.csproj b/unzip_pc3/unzip_pc3.csproj index b62d993..16c2937 100644 --- a/unzip_pc3/unzip_pc3.csproj +++ b/unzip_pc3/unzip_pc3.csproj @@ -11,6 +11,21 @@ unzip_pc3 v4.5 512 + false + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + true AnyCPU @@ -32,8 +47,8 @@ 4 - - ..\..\..\..\..\3\Ionic.Zip.dll + + ..\packages\Ionic.Zip.1.9.1.8\lib\Ionic.Zip.dll @@ -48,13 +63,23 @@ - + + Designer + + + + + False + .NET Framework 3.5 SP1 + false + +