/// <summary>
        ///		Copys a directory tree from one location to another, unlike the one in IOMethods this
        ///		one will also increment a progress bar as it copys the directory tree.
        /// </summary>
        /// <param name="from">The source directory tree.</param>
        /// <param name="to">The destination path of the directory tree.</param>
        private void CopyDirectoryWithProgress(string from, string to)
        {
            // Append a directory seperator to the end of the path.
            if (to[to.Length - 1] != Path.DirectorySeparatorChar)
            {
                to += Path.DirectorySeparatorChar;
            }

            // If the destination directory does not exist then create it.
            if (Directory.Exists(to) == false)
            {
                Directory.CreateDirectory(to);
            }

            // Retrieve all the files in the directory to be copied.
            string[] files = Directory.GetFileSystemEntries(from);

            // Update the progress bar.
            DebugLogger.WriteLog("Copying directory \"" + from + "\"...");
            _subTaskProgress = 0;
            _subTask         = "Copying directory: " + from;
            _logStack.Push(_subTask);

            // Go through each sub directory and file and copy it.
            int index = 1;

            foreach (string file in files)
            {
                if (Directory.Exists(file) == true)
                {
                    CopyDirectoryWithProgress(file, to + Path.GetFileName(file));
                }
                else
                {
                    _logStack.Push("Copying file \"" + file + "\"...");

                    // Check if its a script file which would mean we have to compile it.
                    if (file.ToLower().EndsWith(".fs") == true || file.ToLower().EndsWith(".fso") == true)
                    {
                        // See if we should compile it or not.
                        if (_compileScripts == true)
                        {
                            // Create a compile and compile the script.
                            ScriptCompiler compiler = new ScriptCompiler();
                            _logStack.Push("Compiling script \"" + file + "\"...");

                            // If there are any errors when compiling the script yell
                            // at the user.
                            string errorMessage     = "";
                            bool   showErrorMessage = false;
                            if (compiler.Compile(file, _compileFlags, _scriptDefineList, _scriptIncludePathList) > 0)
                            {
                                errorMessage = compiler.ErrorList.Count + " errors occured while compiling the script \"" + file + "\" \n\n";
                                foreach (CompileError error in compiler.ErrorList)
                                {
                                    if (error.AlertLevel == ErrorAlertLevel.Error ||
                                        error.AlertLevel == ErrorAlertLevel.FatalError ||
                                        (error.AlertLevel == ErrorAlertLevel.Warning && _treatWarningsAsErrors == true) ||
                                        (error.AlertLevel == ErrorAlertLevel.Message && _treatMessagesAsErrors == true)
                                        )
                                    {
                                        showErrorMessage = true;
                                    }
                                    errorMessage += error.ToString() + "\n";
                                }
                            }
                            if (showErrorMessage == true)
                            {
                                DebugLogger.WriteLog(errorMessage, LogAlertLevel.Error);
                                _logStack.Push(errorMessage);
                            }

                            // Dump the compiled byte code to the build directory.
                            if (showErrorMessage == false)
                            {
                                compiler.DumpExecutableFile(to + Path.GetFileName(file));
                            }
                        }

                        // Copy the source code if we have been told to keep it.
                        if (_keepScriptSource == true)
                        {
                            File.Copy(file, to + Path.GetFileName(file), true);
                        }
                    }

                    // Check if its a script script file.
                    else if (file.ToLower().EndsWith(".fsl") == true)
                    {
                        if (_keepScriptSource == true)
                        {
                            File.Copy(file, to + Path.GetFileName(file), true);
                        }
                    }

                    // Its a normal file so we can just ignore it.
                    else
                    {
                        File.Copy(file, to + Path.GetFileName(file), true);
                    }
                }

                _subTaskProgress = (int)(((float)index / (float)files.Length) * 100.0f);
                _subTask         = "Copying directory: " + from;
            }
        }
        /// <summary>
        ///		Compiles the given directory to the current pak file.
        /// </summary>
        /// <param name="from">Directory to compile.</param>
        private void CompileDirectoryToPak(string from)
        {
            // Retrieve all the files in the directory to be copied.
            string[] files = Directory.GetFileSystemEntries(from);

            if (from != Directory.GetCurrentDirectory() && from.ToLower().StartsWith(Directory.GetCurrentDirectory().ToLower()))
            {
                from = from.Substring(Directory.GetCurrentDirectory().Length + 1);
            }

            // Update the progress bar.
            _subTaskProgress = 0;
            _subTask         = "Paking directory: " + from;
            _logStack.Push(_subTask);
            DebugLogger.WriteLog("Paking directory \"" + from + "\"...");

            // Go through each sub directory and file and copy it.
            int index = 1;

            foreach (string subFile in files)
            {
                string file = subFile;

                if (file.ToLower().StartsWith(Directory.GetCurrentDirectory().ToLower()))
                {
                    file = file.Substring(Directory.GetCurrentDirectory().Length + 1);
                }

                if (Directory.Exists(file) == true)
                {
                    CompileDirectoryToPak(file);
                }
                else
                {
                    DebugLogger.WriteLog("Paking file \"" + file + "\"...");
                    _logStack.Push("Paking file \"" + file + "\"...");

                    // Check if its a script file which would mean we have to compile it.
                    if (file.ToLower().EndsWith(".fso") == true || file.ToLower().EndsWith(".fs") == true)
                    {
                        // See if we should compile it or not.
                        if (_compileScripts == true)
                        {
                            // Create a compile and compile the script.
                            ScriptCompiler compiler = new ScriptCompiler();
                            DebugLogger.WriteLog("Compiling script \"" + file + "\"...");
                            _logStack.Push("Compiling script \"" + file + "\"...");

                            // If there are any errors when compiling the script yell
                            // at the user.
                            string errorMessage     = "";
                            bool   showErrorMessage = false;
                            if (compiler.Compile(file, _compileFlags, _scriptDefineList, _scriptIncludePathList) > 0)
                            {
                                errorMessage = compiler.ErrorList.Count + " errors occured while compiling the script \"" + file + "\" \n\n";
                                foreach (CompileError error in compiler.ErrorList)
                                {
                                    if (error.AlertLevel == ErrorAlertLevel.Error ||
                                        error.AlertLevel == ErrorAlertLevel.FatalError ||
                                        (error.AlertLevel == ErrorAlertLevel.Warning && _treatWarningsAsErrors == true) ||
                                        (error.AlertLevel == ErrorAlertLevel.Message && _treatMessagesAsErrors == true)
                                        )
                                    {
                                        showErrorMessage = true;
                                    }
                                    errorMessage += error.ToString() + "\n";
                                }
                            }
                            if (showErrorMessage == true)
                            {
                                DebugLogger.WriteLog(errorMessage, LogAlertLevel.Error);
                                _logStack.Push(errorMessage);
                            }

                            // Dump the compiled byte code to a temporary folder and set its path
                            // as this files path.
                            if (showErrorMessage == false)
                            {
                                string tempFile = Path.GetTempFileName();
                                compiler.DumpExecutableFile(tempFile);
                                PakFile(tempFile, file);
                            }

                            // Copy the source code if we have been told to keep it.
                            if (_keepScriptSource == true)
                            {
                                PakFile(file, file + ".source");
                            }
                        }
                        else
                        {
                            PakFile(file, file);
                        }
                    }

                    // Check if its a library script file.
                    else if (file.ToLower().EndsWith(".fsl") == true)
                    {
                        if (_keepScriptSource == true)
                        {
                            PakFile(file, file);
                        }
                    }

                    // Its a normal file so pak it normally.
                    else
                    {
                        PakFile(file, file);
                    }
                }

                _subTaskProgress = (int)((100.0f / (float)files.Length) * index);
                _subTask         = "Compiling directory: " + from;
            }
        }