private bool CreateNewGame(string newGameDirectory, string newGameName, GameTemplate createFromTemplate)
{
bool createdSuccessfully = false;
try
{
string templateFileName = Path.Combine(_agsEditor.EditorDirectory, createFromTemplate.FileName);
_agsEditor.Tasks.CreateNewGameFromTemplate(templateFileName, newGameDirectory);
string newGameFileName = Path.Combine(newGameDirectory, AGSEditor.GAME_FILE_NAME);
if (!File.Exists(newGameFileName))
{
newGameFileName = Path.Combine(newGameDirectory, AGSEditor.OLD_GAME_FILE_NAME);
}
if (_agsEditor.Tasks.LoadGameFromDisk(newGameFileName, false))
{
_agsEditor.CurrentGame.Settings.GameName = newGameName;
_agsEditor.CurrentGame.Settings.SaveGameFolderName = newGameName;
_agsEditor.CurrentGame.Settings.GenerateNewGameID();
Factory.GUIController.GameNameUpdated();
_agsEditor.CurrentGame.WorkspaceState.LastBuildConfiguration = _agsEditor.CurrentGame.Settings.DebugMode ? BuildConfiguration.Debug : BuildConfiguration.Release;
if (_agsEditor.SaveGameFiles())
{
// Force a rebuild to remove the key in the room
// files that links them to the old game ID
// Force no message to be displayed if the build fails
// (which it will for the Empty Game template)
MessageBoxOnCompile oldMessageBoxSetting = _agsEditor.Preferences.MessageBoxOnCompileErrors;
_agsEditor.Preferences.MessageBoxOnCompileErrors = MessageBoxOnCompile.Never;
_agsEditor.CompileGame(true, false);
_agsEditor.Preferences.MessageBoxOnCompileErrors = oldMessageBoxSetting;
}
if (File.Exists(TEMPLATE_INTRO_FILE))
{
StreamReader sr = new StreamReader(TEMPLATE_INTRO_FILE);
string introText = sr.ReadToEnd();
sr.Close();
Factory.GUIController.ShowMessage(introText, MessageBoxIcon.Information);
}
createdSuccessfully = true;
}
}
catch (Exception ex)
{
Factory.GUIController.ShowMessage("There was an error creating your game. The error was: " + ex.Message + Environment.NewLine + Environment.NewLine + "Error details: " + ex.ToString(), MessageBoxIcon.Stop);
}
if (!createdSuccessfully)
{
Directory.SetCurrentDirectory(_agsEditor.EditorDirectory);
if (Directory.Exists(newGameDirectory))
{
Directory.Delete(newGameDirectory, true);
}
}
return createdSuccessfully;
}