Esempio n. 1
0
        /// <summary>
        ///		Loads this games configuration from the games configuration file.
        /// </summary>
        private void LoadGameConfiguration()
        {
            if (_standAlone == false)
            {
                // Reset the working folder in case we are already in a game directory.
                Environment.CurrentDirectory = System.AppDomain.CurrentDomain.BaseDirectory;

                // Work out the path to the game's directory and check it exists.
                _gamePath = _basePath + "\\" + _gameName;
                if (Directory.Exists(_gamePath) == false) DebugLogger.WriteLog("Game directory '" + _gamePath + "' could not be found.", LogAlertLevel.FatalError);
                DebugLogger.WriteLog("Loading game from " + _gamePath + "...");

                // Change the working directory to the games directory.
                _enginePath = Environment.CurrentDirectory;
                Environment.CurrentDirectory = _gamePath;
            }

            // Read in the Xml configuration file for it.
            DebugLogger.WriteLog("Loading game configuration file...");
            _gameConfigFile = new XmlConfigFile(_gameName + ".xml");

            // Load the game's configuration details.
            _configPath = _gameConfigFile["paths:configpath", _configPath];
            _languagePath = _gameConfigFile["paths:languagepath", _languagePath];
            _savePath = _gameConfigFile["paths:savepath", _savePath];
            if (_savePath != "" && Directory.Exists(_savePath) == false) Directory.CreateDirectory(_savePath);

            _buildPath = _gameConfigFile["paths:buildpath", _buildPath];
            _mediaPath = _gameConfigFile["paths:mediapath", _mediaPath];
            _scriptLibraryPath = _gameConfigFile["paths:scriptlibrarypath", _scriptLibraryPath];
            _tilesetPath = _gameConfigFile["paths:tilesetpath", _tilesetPath];
            _fontPath = _gameConfigFile["paths:fontpath", _fontPath];
            _scriptPath = _gameConfigFile["paths:scriptpath", _scriptPath];
            _objectPath = _gameConfigFile["paths:objectpath", _objectPath];
            _graphicPath = _gameConfigFile["paths:graphicpath", _graphicPath];
            _audioPath = _gameConfigFile["paths:audiopath", _audioPath];
            _mapPath = _gameConfigFile["paths:mappath", _mapPath];
            _mapScriptPath = _gameConfigFile["paths:mapscriptpath", _mapScriptPath];
            _effectPath = _gameConfigFile["paths:effectpath", _effectPath];
            _shaderPath = _gameConfigFile["paths:shaderpath", _shaderPath];
            _gamePluginPath = _gameConfigFile["paths:pluginpath", _shaderPath];

            _gameVersion = Convert.ToSingle(_gameConfigFile["version", _gameVersion.ToString()]);
            _gameTitle = _gameConfigFile["title", _gameTitle];
            _startScript = _gameConfigFile["startscript", _startScript];
            _language = _gameConfigFile["language", _language];

            _usePakFiles = _gameConfigFile["resources:usepakfiles", _usePakFiles == true ? "1" : "0"] == "1" ? true : false;
            _pakFilePrefix = _gameConfigFile["resources:pakfileprefix", _pakFilePrefix];
            _maximumPakFileSize = Convert.ToInt32(_gameConfigFile["resources:maximumpakfilesize", _maximumPakFileSize.ToString()]);

            _compileScripts = _gameConfigFile["resources:scripts:compilescripts", _compileScripts == true ? "1" : "0"] == "1" ? true : false;
            _keepScriptSource = _gameConfigFile["resources:scripts:keepscriptsource", _keepScriptSource == true ? "1" : "0"] == "1" ? true : false;
            _treatWarningsAsErrors = _gameConfigFile["resources:scripts:treatwarningsaserrors", _treatWarningsAsErrors == true ? "1" : "0"] == "1" ? true : false;
            _treatMessagesAsErrors = _gameConfigFile["resources:scripts:treatmessagesaserrors", _treatMessagesAsErrors == true ? "1" : "0"] == "1" ? true : false;
            _compileInDebugMode = _gameConfigFile["resources:scripts:compileindebugmode", _compileInDebugMode == true ? "1" : "0"] == "1" ? true : false;
            _scriptDefines = _gameConfigFile["resources:scripts:scriptdefines", _scriptDefines];

            string[] resolutionSplit = _gameConfigFile["graphics:resolution:dimensions", _resolution[0] + "," + _resolution[1]].Split(new char[] { ',' });
            _resolution[0] = Convert.ToInt32(resolutionSplit[0]);
            _resolution[1] = Convert.ToInt32(resolutionSplit[1]);
            _keepAspectRatio = _gameConfigFile["graphics:resolution:keepaspectratio", _keepAspectRatio == true ? "1" : "0"] == "1" ? true : false;
            _targetFps = Convert.ToInt32(_gameConfigFile["graphics:targetfps", _targetFps.ToString()]);

            Networking.NetworkManager.NetworkConfigFile = _gameConfigFile["network:configfile", Networking.NetworkManager.NetworkConfigFile];

            // Go through requirements and filter them.
            string[] requiredPlugins = _gameConfigFile.GetSettings("requirements");
            if (requiredPlugins != null)
            {
                foreach (string requirement in requiredPlugins)
                {
                    string[] pathSplit = requirement.Split(new char[] { ':' });
                    string name = pathSplit[pathSplit.Length - 1];
                    string value = _gameConfigFile[requirement, ""];
                    switch (name.ToLower())
                    {
                        case "plugin":
                            _requiredPlugins.Add(value);
                            break;
                    }
                }
            }

            // Load key bindings.
            string[] keyBindings = _gameConfigFile.GetSettings("input:bindings");
            if (keyBindings != null)
            {
                foreach (string binding in keyBindings)
                {
                    string[] pathSplit = binding.Split(new char[] { ':' });
                    string name = pathSplit[pathSplit.Length - 1];
                    string value = _gameConfigFile[binding, ""];
                    try
                    {
                        InputManager.BindKey(name, (KeyCodes)Enum.Parse(typeof(KeyCodes), value, true));
                        DebugLogger.WriteLog("Bound key " + value + " to action " + name + ".");
                    }
                    catch (Exception)
                    {
                        DebugLogger.WriteLog("Unable to bind key " + value + " to action " + name + ".", LogAlertLevel.Error);
                    }
                }
            }

            // Load entity settings
            string defaultDepthMode = _gameConfigFile["entities:defaultdepthmode", EntityDepthMode.SubtractCollisionBoxBottom.ToString()];
            EntityNode.DefaultDepthMode = (EntityDepthMode)Enum.Parse(typeof(EntityDepthMode), defaultDepthMode, true);
        }
Esempio n. 2
0
        /// <summary> 
        ///		Loads this engines configuration from the engine configuration file.
        /// </summary>
        private void LoadEngineConfiguration()
        {
            // First things first lets read in the engine configuration file.
            _engineConfigFile = new XmlConfigFile(_configFilePath);

            // Get any configuration values relative to initializing the engine.
            _standAlone = _engineConfigFile["standalone", "0"] == "0" ? false : true;
            if (_standAlone == true) _gameName = "standalone";
            DebugLogger.OutputFile = _engineConfigFile["debug:log:logfile", _outputFilePath];
            DebugLogger.LogFatalErrors = _engineConfigFile["debug:log:logfatalerrors", "1"] == "0" ? false : true;
            DebugLogger.LogErrors = _engineConfigFile["debug:log:logerrors", "1"] == "0" ? false : true;
            DebugLogger.LogWarnings = _engineConfigFile["debug:log:logwarnings", "1"] == "0" ? false : true;
            DebugLogger.LogMessages = _engineConfigFile["debug:log:logmessages", "1"] == "0" ? false : true;
            DebugLogger.EmitLogFile = _engineConfigFile["debug:log:emitlog", _logDebugOutput.ToString().ToLower() == "true" ? "1" : "0"] == "0" ? false : true;

            // Read in driver names.
            _graphicsDriverID = _engineConfigFile["graphics:driver", _graphicsDriverID];
            _audioDriverID = _engineConfigFile["audio:driver", _audioDriverID];
            _inputDriverID = _engineConfigFile["input:driver", _inputDriverID];

            // Work out media paths.
            _relativeBasePath = _engineConfigFile["paths:basepath", _basePath];
            _relativePluginPath = _engineConfigFile["paths:pluginpath", _pluginPath];
            _relativeDownloadPath = _engineConfigFile["paths:downloadpath", _downloadPath];
            _relativeLogPath = _engineConfigFile["paths:logpath", _logPath];
            _relativeGlobalScriptLibraryPath = _engineConfigFile["paths:scriptlibrarypath", _globalScriptLibraryPath];
            _basePath = Environment.CurrentDirectory + "\\" + _relativeBasePath;
            _pluginPath = Environment.CurrentDirectory + "\\" + _relativePluginPath;
            _downloadPath = Environment.CurrentDirectory + "\\" + _relativeDownloadPath;
            _logPath = Environment.CurrentDirectory + "\\" + _relativeLogPath;
            _outputFilePath = _logPath + "\\Fusion "+DateTime.Now.Day+"-"+DateTime.Now.Month+"-"+DateTime.Now.Year+" "+DateTime.Now.Hour+"-"+DateTime.Now.Minute+"-"+DateTime.Now.Second+".log";
            _globalScriptLibraryPath = Environment.CurrentDirectory + "\\" + _relativeGlobalScriptLibraryPath;

            // Work out plugin details.
            _loadPlugins = _engineConfigFile["plugins:loadplugins", _loadPlugins == true ? "1" : "0"] == "1" ? true : false;
            _loadOnlyRequiredPlugins = _engineConfigFile["plugins:loadonlyrequiredplugins", _loadOnlyRequiredPlugins == true ? "1" : "0"] == "1" ? true : false;

            // Work out resolution details.
            _showInFullscreen = _engineConfigFile["graphics:fullscreen", _showInFullscreen == true ? "1" : "0"] == "1" ? true : false;
            int.TryParse(_engineConfigFile["graphics:fpslimit", _fpsLimit.ToString()], out _fpsLimit);
            int.TryParse(_engineConfigFile["graphics:frameskip", _frameSkip.ToString()], out _frameSkip);

            string[] realResolutionSplit =_engineConfigFile["graphics:resolution:dimensions", _realResolution[0]+","+_realResolution[1]].Split(new char[] {','});
            int.TryParse(realResolutionSplit[0], out _realResolution[0]);
            int.TryParse(realResolutionSplit[1], out _realResolution[1]);

            // Misc stuff
            _showConsole = _engineConfigFile["debug:showconsole", _showConsole == true ? "1" : "0"] == "1" ? true : false;
            float.TryParse(_engineConfigFile["version", _engineVersion.ToString()], out _engineVersion);
        }
        /// <summary>
        ///     Loads in details on all games that are on the local drive.
        /// </summary>
        private void LoadMyGames()
        {
            _myGames.Clear();
            _myGamesImageList.Images.Clear();
            _myGamesImageList.ColorDepth = ColorDepth.Depth32Bit;
            _myGamesImageList.ImageSize = new Size(48, 48);

            string[] directories = Directory.GetDirectories(Fusion.GlobalInstance.BasePath);
            for (int i = 0; i < directories.Length; i++)
            {
                string gameDir = directories[i];
                string gameName = gameDir.Substring(gameDir.LastIndexOf('\\') + 1);
                if (File.Exists(gameDir + "\\" + gameName + ".xml") == false)
                    continue;

                // Grab data out of the config file.
                XmlConfigFile configFile = new XmlConfigFile(gameDir + "\\" + gameName + ".xml");
                GameDescription description = new GameDescription(gameName, configFile["title", "Unknown"], configFile["description", "Unknown"], configFile["shortDescription", "Unknown"], configFile["rating", "Unknown"], configFile["language", "Unknown"], configFile["requirements", "Unknown"], configFile["players", "Unknown"], configFile["version", "Unknown"], configFile["publisher", "Unknown"]);

                // Load an icon?
                string icon = configFile["icon", ""];
                if (icon != "" && File.Exists(gameDir + "\\" + icon))
                {
                    byte[] data = File.ReadAllBytes(gameDir + "\\" + icon);
                    Stream iconStream = new MemoryStream(data);
                    description.Icon = Image.FromStream(iconStream);
                    //iconStream.Close();

                    _myGamesImageList.Images.Add(description.Icon);
                }

                _myGames.Add(description);
            }

            myGamesStatusLabel.Text = "You currently don't own any games.";

            RefreshMyGames();
        }
Esempio n. 4
0
        /// <summary>
        ///		Initializes the updater and sets up all the sub systems.
        /// </summary>
        /// <returns>True if initialization was sucessfull.</returns>
        private bool Initialize()
        {
            #region Command Line & Configuration Parsing

            // Parse the command lines for configuration options.
            ParseCommandLines(_commandLineArguments, true);

            // First things first lets read in the engine configuration file.
            _engineConfigFile = new XmlConfigFile(_configFilePath);

            // Get any configuration values relative to initializing the engine.
            _relativeBasePath = _engineConfigFile["basepath", _basePath];
            _basePath = _relativeBasePath;

            // Parse the command lines for anything besides configuration options.
            ParseCommandLines(_commandLineArguments, false);

            // Check an update file has been specified.
            if (_updateFile == "")
            {
                MessageBox.Show("Unable to update, no update file was specified.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return false;
            }

            #endregion
            #region Sub System Initialization

            // Create the updater's window.
            _window = new UpdaterWindow();
            _window.Show();

            #endregion
            return true;
        }
        /// <summary>
        ///		Used as an entry point for the project building thread.
        /// </summary>
        private void BuildProjectThread()
        {
            // Work out script compiling options
            _compileFlags = _compileInDebugMode == true ? CompileFlags.Debug : 0;
            if (_treatMessagesAsErrors) _compileFlags |= CompileFlags.TreatMessagesAsErrors;
            if (_treatWarningsAsErrors) _compileFlags |= CompileFlags.TreatWarningsAsErrors;

            // Split up the script defines string.
            string[] defines = _scriptDefines.Split(new char[1] { ',' });
            _scriptDefineList = new Define[defines.Length + 1];
            for (int i = 0; i < defines.Length; i++)
            {
                if (defines[i].IndexOf('=') >= 0)
                {
                    string[] splitList = defines[i].Split(new char[1] { '=' });
                    _scriptDefineList[i] = new Define(splitList[0], splitList[1], TokenID.TypeIdentifier);
                }
                else
                    _scriptDefineList[i] = new Define(defines[i], "", TokenID.TypeIdentifier);
            }
            _scriptDefineList[_scriptDefineList.Length - 1] = new Define(_compileInDebugMode ? "__DEBUG__" : "__RELEASE__", "", TokenID.TypeBoolean);

            // Set the include path list to include the script library path.
            _scriptIncludePathList = new string[] { Environment.CurrentDirectory + "\\" + Editor.GlobalInstance.ScriptLibraryPath, Editor.GlobalInstance.GlobalScriptLibraryPath };

            // Work out a directory that we can build to.
            _buildBasePath = _buildDirectory;
            _buildDirectory = _buildBasePath + "\\" + DateTime.Now.Day + "-" + DateTime.Now.Month + "-" + DateTime.Now.Year + " " + DateTime.Now.Hour + "-" + DateTime.Now.Minute+"-"+DateTime.Now.Second;
            int buildIndex = 2;

            if (Directory.Exists(_buildBasePath) == false)
                Directory.CreateDirectory(_buildBasePath);

            while (Directory.Exists(_buildDirectory) == true)
                _buildDirectory = _buildBasePath + "\\" + DateTime.Now.Day + "-" + DateTime.Now.Month + "-" + DateTime.Now.Year + " " + DateTime.Now.Hour + "-" + DateTime.Now.Minute +"-"+ DateTime.Now.Second + (buildIndex++).ToString().PadLeft(4, '0');

            // Create the build directory.
            Directory.CreateDirectory(_buildDirectory);

            // Open the game configuration file, change the pak file settings and save it into
            // the new build folder.
            XmlConfigFile configFile = new XmlConfigFile(Editor.GlobalInstance.GameName + ".xml");
            configFile.SetSetting("path:resources:usepakfiles", _compilePakFiles == true || _buildStandAlone == true ? "1" : "0");
            if (_buildStandAlone == false)
                configFile.Save(_buildDirectory + "\\" + Editor.GlobalInstance.GameName + ".xml");

            // Copy the configuration directory into the build directory.
            //IOMethods.CopyDirectory(Editor.GlobalInstance.ConfigPath, _buildDirectory + "\\" + Editor.GlobalInstance.ConfigPath);

            // Copy the language directory into the build directory.
            //IOMethods.CopyDirectory(Editor.GlobalInstance.LanguagePath, _buildDirectory + "\\" + Editor.GlobalInstance.LanguagePath);

            // Copy the saves file if we have been told to.
            if (_copySaves == true && Directory.GetFiles(Editor.GlobalInstance.SavePath).Length != 0)
                IOMethods.CopyDirectory(Editor.GlobalInstance.SavePath, _buildDirectory + "\\" + Editor.GlobalInstance.SavePath);

            // Create a plugins folder.
            //IOMethods.CopyDirectory(Editor.GlobalInstance.GamePluginPath, _buildDirectory + "\\" + Editor.GlobalInstance.GamePluginPath);

            // Copy the icon.
            if (_buildStandAlone == false && File.Exists(Editor.GlobalInstance.GamePath + "\\icon.ico"))
                File.Copy(Editor.GlobalInstance.GamePath + "\\icon.ico", _buildDirectory + "\\icon.ico");

            // Compile the pak files or copy the media directory if we are not using pak files.
            if (_buildStandAlone == true)
            {
                _taskProgress = 0;
                _task = "Packing files";
                _logStack.Push(_task);

                // Work out the game ID code.
                long gameIDCode = DateTime.Now.Ticks ^ (long)configFile["title", "engine"].GetHashCode();

                // Create the pak file to save resources to.
                _pakFile = new PakFile();
                _pakFileIndex = 0;
                _pakFileSize = 0;
                _pakFileMaximumSize = 0;

                // Compile the media directory to the pak file.
                CompileDirectoryToPak(Editor.GlobalInstance.MediaPath);
                CompileDirectoryToPak(Editor.GlobalInstance.ConfigPath);
                CompileDirectoryToPak(Editor.GlobalInstance.LanguagePath);

                // Work out game files that we need.
                ArrayList gameFiles = new ArrayList();
                gameFiles.Add(AppDomain.CurrentDomain.BaseDirectory + "fusion.exe");
                gameFiles.Add(AppDomain.CurrentDomain.BaseDirectory + "graphics.dll");
                gameFiles.Add(AppDomain.CurrentDomain.BaseDirectory + "runtime.dll");
                gameFiles.Add(AppDomain.CurrentDomain.BaseDirectory + "input.dll");
                gameFiles.Add(AppDomain.CurrentDomain.BaseDirectory + "audio.dll");
                gameFiles.Add(AppDomain.CurrentDomain.BaseDirectory + "engine.dll");

                // Copy plugins.
                string[] requiredPlugins = Editor.GlobalInstance.GameConfigFile.GetSettings("requirements");
                if (requiredPlugins != null)
                {
                    foreach (string requirement in requiredPlugins)
                    {
                        string[] pathSplit = requirement.Split(new char[] { ':' });
                        string name = pathSplit[pathSplit.Length - 1];
                        string value = Editor.GlobalInstance.GameConfigFile[requirement, ""];
                        switch (name.ToLower())
                        {
                            case "plugin":
                                if (File.Exists(Editor.GlobalInstance.PluginPath + "\\" + value))
                                {
                                    //if (Directory.Exists(_buildDirectory + "\\" + Editor.GlobalInstance.PluginPath) == false)
                                    //    Directory.CreateDirectory(_buildDirectory + "\\" + Editor.GlobalInstance.PluginPath);
                                    //File.Copy(Editor.GlobalInstance.PluginPath + "\\" + value, _buildDirectory + "\\" + Editor.GlobalInstance.PluginPath + value);
                                    gameFiles.Add(AppDomain.CurrentDomain.BaseDirectory + Editor.GlobalInstance.PluginPath + "\\" + value);
                                }
                                break;
                        }
                    }
                }

                // Copy all!
                else
                {
                    if (Directory.Exists(Editor.GlobalInstance.PluginPath))
                    {
                        foreach (string file in Directory.GetFiles(Editor.GlobalInstance.PluginPath))
                        {
                            if (Path.GetExtension(file).ToLower() != ".dll") continue;
                            gameFiles.Add(file);
                        }
                    }

                    // Game plugins as well.
                    // TODO
                }

                _taskProgress = 50;
                _task = "Building executable";

                // Create the sub that we are going to add the files into.
                string stubFile = _buildDirectory + "\\" + string.Join("", configFile["title", "engine"].Split(new char[] { '\\', '/', ':', '*', '?', '"', '<', '>', '|' }, StringSplitOptions.None)) + ".exe";
                File.Copy(AppDomain.CurrentDomain.BaseDirectory + "Stand Alone Stub.exe", stubFile);

                // Open up the stub.
                Stream stubStream = StreamFactory.RequestStream(stubFile, StreamMode.Append);
                BinaryWriter stubWriter = new BinaryWriter(stubStream);

                // Grab the offset.
                long offset = stubStream.Position;
                stubWriter.Write(gameFiles.Count + 3);
                foreach (string gameFilePath in gameFiles)
                {
                    Stream fileStream = null;
                    fileStream = StreamFactory.RequestStream(gameFilePath, StreamMode.Open);
                    if (fileStream == null)
                    {
                        string tmpFile = Path.GetTempFileName();
                        File.Delete(tmpFile);
                        File.Copy(gameFilePath, tmpFile);
                        fileStream = StreamFactory.RequestStream(tmpFile, StreamMode.Open);
                    }
                    byte[] buffer = new byte[fileStream.Length];
                    fileStream.Read(buffer, 0, (int)fileStream.Length);

                    string url = gameFilePath;
                    if (url.ToLower().StartsWith(AppDomain.CurrentDomain.BaseDirectory.ToLower()))
                        url = url.Substring(AppDomain.CurrentDomain.BaseDirectory.Length);

                    stubWriter.Write(url);
                    stubWriter.Write(buffer.Length);
                    stubWriter.Write(buffer, 0, buffer.Length);
                }

                stubStream.Flush();
                GC.Collect();

                // Write the pak file into a memory stream.
                MemoryStream engineMemStream = new MemoryStream();
                BinaryWriter engineMemWriter = new BinaryWriter(engineMemStream);

                XmlConfigFile engineConfigFile = new XmlConfigFile(AppDomain.CurrentDomain.BaseDirectory + "fusion.xml");
                engineConfigFile.SetSetting("standalone", _buildStandAlone == true ? "1" : "0");
                engineConfigFile.Save(engineMemWriter);

                GC.Collect();

                // Write the game config file.
                stubWriter.Write("fusion.xml");
                stubWriter.Write((int)engineMemStream.Length);
                engineMemStream.WriteTo(stubStream);

                // Write the pak file into a memory stream.
                MemoryStream gameMemStream = new MemoryStream();
                BinaryWriter gameMemWriter = new BinaryWriter(gameMemStream);
                configFile.Save(gameMemWriter);
                GC.Collect();

                // Write the game config file.
                stubWriter.Write("standalone.xml");
                stubWriter.Write((int)gameMemStream.Length);
                gameMemStream.WriteTo(stubStream);

                // Write the pak file into a memory stream.
                MemoryStream memStream = new MemoryStream();
                BinaryWriter memWriter = new BinaryWriter(memStream);
                _pakFile.Save(memWriter);
                _pakFile.Resources.Clear();
                GC.Collect();

                // Write in the pak file.
                stubWriter.Write("data.pk");
                stubWriter.Write((int)memStream.Length);
                memStream.WriteTo(stubStream);

                // Write in the offset footer
                stubWriter.Write(gameIDCode);
                stubWriter.Write(offset);

                // Write the data into the stub.
                stubWriter.Close();
                stubStream.Close();
            }
            else
            {
                if (_compilePakFiles == true)
                {
                    _taskProgress = 0;
                    _task = "Compiling pak files";
                    _logStack.Push(_task);

                    // Create the pak file to save resources to.
                    _pakFile = new PakFile();
                    _pakFileIndex = 0;
                    _pakFileSize = 0;

                    // Compile the media directory to the pak file.
                    CompileDirectoryToPak(Editor.GlobalInstance.MediaPath);
                    CompileDirectoryToPak(Editor.GlobalInstance.ConfigPath);
                    CompileDirectoryToPak(Editor.GlobalInstance.LanguagePath);

                    // Save the pak file to the hard drive.
                    if (_pakFile.Resources.Count != 0)
                    {
                        string filePath = _buildDirectory + "\\" + _pakFilePrefix.Replace("#", _pakFileIndex.ToString()) + ".pk";
                        int index = 0;
                        while (File.Exists(filePath) == true)
                            filePath = _buildDirectory + "\\" + _pakFilePrefix.Replace("#", _pakFileIndex.ToString()) + (index++) + ".pk";
                        _pakFile.Save(filePath);
                        _pakFile.Dispose();
                    }
                }
                else
                {
                    _taskProgress = 0;
                    _task = "Copying media";
                    _logStack.Push(_task);
                    CopyDirectoryWithProgress(Editor.GlobalInstance.MediaPath, _buildDirectory + "\\" + Editor.GlobalInstance.MediaPath);
                    CopyDirectoryWithProgress(Editor.GlobalInstance.ConfigPath, _buildDirectory + "\\" + Editor.GlobalInstance.ConfigPath);
                    CopyDirectoryWithProgress(Editor.GlobalInstance.LanguagePath, _buildDirectory + "\\" + Editor.GlobalInstance.LanguagePath);
                }

                // If we are building an FGE distrubutable file then copy the icon file and copile all to pak file.
                if (_buildFGE)
                {
                    _taskProgress = 0;
                    _task = "Compiling FGE files";
                    _logStack.Push(_task);

                    // Create the pak file to save resources to.
                    _pakFile = new PakFile();
                    _pakFileIndex = 0;
                    _pakFileSize = 0;
                    _pakFileMaximumSize = 0;

                    // Pak the build directory.
                    string oldDirectory = Directory.GetCurrentDirectory();

                    Directory.SetCurrentDirectory(_buildDirectory);
                    CompileDirectoryToPak(Directory.GetCurrentDirectory());

                    // Save the pak file.
                    _pakFile.Save(Editor.GlobalInstance.GameName + ".pk");
                    _pakFile.Dispose();

                    Directory.SetCurrentDirectory(oldDirectory);

                    // Delete folder.
                    if (_copySaves == true && Directory.GetFiles(Editor.GlobalInstance.SavePath).Length != 0)
                        Directory.Delete(_buildDirectory + "\\" + Editor.GlobalInstance.SavePath);

                    // Delete all files and folders.
                    File.Delete(_buildDirectory + "\\" + Editor.GlobalInstance.GameName + ".xml");
                    if (Directory.Exists(_buildDirectory + "\\" + Editor.GlobalInstance.MediaPath))
                        Directory.Delete(_buildDirectory + "\\" + Editor.GlobalInstance.MediaPath, true);
                    if (Directory.Exists(_buildDirectory + "\\" + Editor.GlobalInstance.ConfigPath))
                        Directory.Delete(_buildDirectory + "\\" + Editor.GlobalInstance.ConfigPath, true);
                    if (Directory.Exists(_buildDirectory + "\\" + Editor.GlobalInstance.LanguagePath))
                        Directory.Delete(_buildDirectory + "\\" + Editor.GlobalInstance.LanguagePath, true);
                }
            }
        }