Ejemplo n.º 1
0
        /**
         * Runs the program
         */
        private void Run(String[] args)
        {
            // Verify argument count
            if (!CheckArguments(args))
            {
                return;
            }
            // Retrieve argument values and listfile, and check for existence
            String operationName = args[0];
            String mpqName       = args[1];
            String listfileName  = "listfile.txt";

            if (!File.Exists(mpqName))
            {
                Console.WriteLine("MPQ file does not exist: " + mpqName);
                return;
            }
            if (!File.Exists(listfileName))
            {
                Console.WriteLine("Listfile does not exist: " + listfileName);
                return;
            }
            // Determine what operation the user wanted
            Boolean extract;

            if (operationName.Equals("ext") ||
                operationName.Equals("exp") ||
                operationName.Equals("export") ||
                operationName.Equals("extract"))
            {
                extract = true;
            }
            else if (operationName.Equals("imp") || operationName.Equals("import"))
            {
                extract = false;
            }
            else
            {
                Console.WriteLine("Invalid operation: " + operationName);
                return;
            }
            // For every entered file, we either perform import/export
            using (MpqArchive archive = new MpqArchive(mpqName, FileAccess.ReadWrite))
            {
                // Add listfile.txt as external listfile
                int retval = archive.AddListFile(listfileName);
                Console.WriteLine("Added listfile: " + retval + " (0 is ok)");
                for (int i = 2; i < args.Length; i++)
                {
                    if (extract)
                    {
                        Extract(args[i], archive);
                    }
                    else
                    {
                        Import(args[i], archive);
                    }
                }
                Console.WriteLine("All desired operations completed. Flushing & closing.");
                // Close out resources
                archive.Compact(listfileName);
                archive.Flush();
                archive.Dispose();
            }
        }