Example #1
0
        static void Main(string[] args)
        {
            List<string> toStrip = new List<string>();
            toStrip.Add("*");

            ushort compressionType = 1;

            int lastOpt = -1;

            PrintBanner();

            // Parse opts
            for (int i = 0; i < args.Length; i++)
            {
                if (args[i][0] != '-')
                {
                    lastOpt = i - 1;
                    break;
                }

                if (args[i].Equals("-?"))
                {
                    Help();
                    return;
                }

                if (args[i].Equals("-r"))
                {
                    bRecurse = true;
                }

                if (args[i].Equals("-i"))
                {
                    usCabinetID = Convert.ToUInt16(args[++i]);
                }

                if (args[i].Equals("-s"))
                {
                    usReservedCabinetSize = Convert.ToUInt16(args[++i]);
                }

                if (args[i].Equals("-c"))
                {
                    bConfirmAll = true;
                }

                if (args[i].Equals("-o"))
                {
                    bOverwriteAll = true;
                }

                if (args[i].Equals("-p"))
                {
                    if (toStrip.Count > 0)
                        toStrip.RemoveAt(0);
                }

                if (args[i].Equals("-P"))
                {
                    toStrip.Add(args[++i]);
                }

                if (args[i].Equals("-m")) // Default: MS-ZIP
                {
                    string s = args[++i].ToLower();
                    if (s.StartsWith("none"))
                        compressionType = 0;
                    if (s.StartsWith("lzx:"))
                    {
                        UInt16 dict = Convert.ToUInt16(s.Substring(4));
                        if (dict < 15 || dict > 21)
                        {
                            Console.WriteLine("Bad dictionary size for LZX: it must be in range 15..21!");
                            return;
                        }
                        compressionType = (ushort)((dict << 8) | 3);
                    }
                    if (s.StartsWith("mszip"))
                    {
                        compressionType = 1;
                    }
                }
            }

            if (lastOpt+1 == args.Length)
            {
                Console.WriteLine("You must specify a command");
                return;
            }

            // Parse args
            for (int i = lastOpt+1; i < args.Length; i++)
            {
                if (args[i].ToLower().Equals("d"))
                {
                    DumpCAB(args[i + 1]);
                }

                if (args[i].ToLower().Equals("l"))
                {
                    ListCAB(args[i + 1]);
                }

                if (args[i].ToLower().Equals("n"))
                {
                    CabWriter cab = new CabWriter(args[i + 1], compressionType);
                    for (int j = i + 2; j < args.Length; j++)
                    {
                        if ((new FileInfo(args[j]).Attributes & FileAttributes.Directory) == FileAttributes.Directory)
                            cab.AddFolder(args[j], bRecurse, toStrip, "*");
                        else
                            cab.AddFile(args[j], toStrip);
                    }
                    cab.Flush();
                }

                // FIXME: in real Cabarc, we must always specify a BASE file name, even if paths are preserved!
                if (args[i].ToLower().Equals("x"))
                {
                    CabReader cab = new CabReader(args[i + 1]);
                    cab.toStrip = toStrip;

                    Console.WriteLine("Extracting file(s) from cabinet '{0}'", args[i + 1]);

                    for (int j = i + 2; j < args.Length - 1; j++)
                    {
                        cab.Extract(args[j]);
                    }
                    if (args[args.Length - 1].EndsWith("\\"))
                        cab.SetTargetFolder(args[args.Length - 1]);
                    else
                        cab.Extract(args[args.Length - 1]);
                    cab.PerformExtraction();
                }
            }

            Console.WriteLine("\nOperation successful");
        }
Example #2
0
        static void Main(string[] args)
        {
            List <string> toStrip = new List <string>();

            toStrip.Add("*");

            ushort compressionType = 1;

            int lastOpt = -1;

            PrintBanner();

            // Parse opts
            for (int i = 0; i < args.Length; i++)
            {
                if (args[i][0] != '-')
                {
                    lastOpt = i - 1;
                    break;
                }

                if (args[i].Equals("-?"))
                {
                    Help();
                    return;
                }

                if (args[i].Equals("-r"))
                {
                    bRecurse = true;
                }

                if (args[i].Equals("-i"))
                {
                    usCabinetID = Convert.ToUInt16(args[++i]);
                }

                if (args[i].Equals("-s"))
                {
                    usReservedCabinetSize = Convert.ToUInt16(args[++i]);
                }

                if (args[i].Equals("-c"))
                {
                    bConfirmAll = true;
                }

                if (args[i].Equals("-o"))
                {
                    bOverwriteAll = true;
                }

                if (args[i].Equals("-p"))
                {
                    if (toStrip.Count > 0)
                    {
                        toStrip.RemoveAt(0);
                    }
                }

                if (args[i].Equals("-P"))
                {
                    toStrip.Add(args[++i]);
                }

                if (args[i].Equals("-m")) // Default: MS-ZIP
                {
                    string s = args[++i].ToLower();
                    if (s.StartsWith("none"))
                    {
                        compressionType = 0;
                    }
                    if (s.StartsWith("lzx:"))
                    {
                        UInt16 dict = Convert.ToUInt16(s.Substring(4));
                        if (dict < 15 || dict > 21)
                        {
                            Console.WriteLine("Bad dictionary size for LZX: it must be in range 15..21!");
                            return;
                        }
                        compressionType = (ushort)((dict << 8) | 3);
                    }
                    if (s.StartsWith("mszip"))
                    {
                        compressionType = 1;
                    }
                }
            }

            if (lastOpt + 1 == args.Length)
            {
                Console.WriteLine("You must specify a command");
                return;
            }

            // Parse args
            for (int i = lastOpt + 1; i < args.Length; i++)
            {
                if (args[i].ToLower().Equals("d"))
                {
                    DumpCAB(args[i + 1]);
                }

                if (args[i].ToLower().Equals("l"))
                {
                    ListCAB(args[i + 1]);
                }

                if (args[i].ToLower().Equals("n"))
                {
                    CabWriter cab = new CabWriter(args[i + 1], compressionType);
                    for (int j = i + 2; j < args.Length; j++)
                    {
                        if ((new FileInfo(args[j]).Attributes & FileAttributes.Directory) == FileAttributes.Directory)
                        {
                            cab.AddFolder(args[j], bRecurse, toStrip, "*");
                        }
                        else
                        {
                            cab.AddFile(args[j], toStrip);
                        }
                    }
                    cab.Flush();
                }

                // FIXME: in real Cabarc, we must always specify a BASE file name, even if paths are preserved!
                if (args[i].ToLower().Equals("x"))
                {
                    CabReader cab = new CabReader(args[i + 1]);
                    cab.toStrip = toStrip;

                    Console.WriteLine("Extracting file(s) from cabinet '{0}'", args[i + 1]);

                    for (int j = i + 2; j < args.Length - 1; j++)
                    {
                        cab.Extract(args[j]);
                    }
                    if (args[args.Length - 1].EndsWith("\\"))
                    {
                        cab.SetTargetFolder(args[args.Length - 1]);
                    }
                    else
                    {
                        cab.Extract(args[args.Length - 1]);
                    }
                    cab.PerformExtraction();
                }
            }

            Console.WriteLine("\nOperation successful");
        }