Esempio n. 1
0
        public CompileMessages NumberSpeechLines(Game game, bool includeNarrator, bool combineIdenticalLines, bool removeNumbering, int? characterID)
        {
            _speechableFunctionCalls = GetFunctionCallsToProcessForSpeech(includeNarrator);

            _errors = new CompileMessages();
            _game = game;
            _includeNarrator = includeNarrator;
            _combineIdenticalLines = combineIdenticalLines;
            _removeNumbering = removeNumbering;
            _characterID = characterID;

            if (Factory.AGSEditor.AttemptToGetWriteAccess(SPEECH_REFERENCE_FILE_NAME))
            {
                using (_referenceFile = new StreamWriter(SPEECH_REFERENCE_FILE_NAME, false))
                {
                    _referenceFile.WriteLine("// AGS auto-numbered speech lines output. This file was automatically generated.");
                    PerformNumbering(game);
                }
            }
            else
            {
                _errors.Add(new CompileError("unable to create file " + SPEECH_REFERENCE_FILE_NAME));
            }

            return _errors;
        }
 public VoiceActorScriptProcessor(Game game, CompileMessages errors,
     Dictionary<string, FunctionCallType> speechableFunctionCalls)
     : base(game, errors, false, false, speechableFunctionCalls)
 {
     _linesByCharacter = new Dictionary<int, Dictionary<string, string>>();
     _linesInOrder = new List<GameTextLine>();
 }
Esempio n. 3
0
 public GameSpeechProcessor(Game game, CompileMessages errors, bool makesChanges, bool processHotspotAndObjectDescriptions)
 {
     _game = game;
     _errors = errors;
     _makesChanges = makesChanges;
     _processHotspotAndObjectDescriptions = processHotspotAndObjectDescriptions;
 }
Esempio n. 4
0
        public string ConvertGameDialogScripts(Game game, CompileMessages errors, bool rebuildAll)
        {
            int stringBuilderCapacity = 1000 * game.RootDialogFolder.GetAllItemsCount() + _DefaultDialogScriptsScript.Length;
            StringBuilder sb = new StringBuilder(_DefaultDialogScriptsScript, stringBuilderCapacity);

            foreach (Dialog dialog in game.RootDialogFolder.AllItemsFlat)
            {
                sb.AppendLine(AGS.CScript.Compiler.Constants.NEW_SCRIPT_MARKER + "Dialog " + dialog.ID + "\"");

                if ((dialog.CachedConvertedScript == null) ||
                    (dialog.ScriptChangedSinceLastConverted) ||
                    (rebuildAll))
                {
                    int errorCountBefore = errors.Count;
                    this.ConvertDialogScriptToRealScript(dialog, game, errors);

                    if (errors.Count > errorCountBefore)
                    {
                        dialog.ScriptChangedSinceLastConverted = true;
                    }
                    else
                    {
                        dialog.ScriptChangedSinceLastConverted = false;
                    }
                }

                sb.Append(dialog.CachedConvertedScript);
            }

            return sb.ToString();
        }
Esempio n. 5
0
        public void ConvertDialogScriptToRealScript(Dialog dialog, Game game, CompileMessages errors)
        {
            string thisLine;
            _currentlyInsideCodeArea = false;
            _hadFirstEntryPoint = false;
            _game = game;
            _currentDialog = dialog;
            _existingEntryPoints.Clear();
            _currentLineNumber = 0;

            StringReader sr = new StringReader(dialog.Script);
            StringWriter sw = new StringWriter();
            sw.Write(string.Format("function _run_dialog{0}(int entryPoint) {1} ", dialog.ID, "{"));
            while ((thisLine = sr.ReadLine()) != null)
            {
                _currentLineNumber++;
                try
                {
                    ConvertDialogScriptLine(thisLine, sw, errors);
                }
                catch (CompileMessage ex)
                {
                    errors.Add(ex);
                }
            }
            if (_currentlyInsideCodeArea)
            {
                sw.WriteLine("}");
            }
            sw.WriteLine("return RUN_DIALOG_RETURN; }"); // end the function
            dialog.CachedConvertedScript = sw.ToString();
            sw.Close();
            sr.Close();
        }
Esempio n. 6
0
        public static bool CreateInteractionScripts(Room room, CompileMessages errors)
        {
            Script theScript = room.Script;
            bool convertedSome = CreateScriptsForInteraction("room", theScript, room.Interactions, errors);

            foreach (RoomHotspot hotspot in room.Hotspots)
            {
                if (hotspot.Name.Length < 1)
                {
                    hotspot.Name = "hHotspot" + hotspot.ID;
                }
                convertedSome |= CreateScriptsForInteraction(hotspot.Name, theScript, hotspot.Interactions, errors);
            }
            foreach (RoomObject obj in room.Objects)
            {
                if (obj.Name.Length < 1)
                {
                    obj.Name = "oObject" + obj.ID;
                }
                convertedSome |= CreateScriptsForInteraction(obj.Name, theScript, obj.Interactions, errors);
            }
            foreach (RoomRegion region in room.Regions)
            {
                string useName = "region" + region.ID;
                convertedSome |= CreateScriptsForInteraction(useName, theScript, region.Interactions, errors);
            }
            return convertedSome;
        }
Esempio n. 7
0
        private SpeechLipSyncLine CompilePAMFile(string fileName, CompileMessages errors)
        {
            SpeechLipSyncLine syncDataForThisFile = new SpeechLipSyncLine();
            syncDataForThisFile.FileName = Path.GetFileNameWithoutExtension(fileName);

            string thisLine;
            bool inMainSection = false;
            int lineNumber = 0;

            StreamReader sr = new StreamReader(fileName);
            while ((thisLine = sr.ReadLine()) != null)
            {
                lineNumber++;
                if (thisLine.ToLower().StartsWith("[speech]"))
                {
                    inMainSection = true;
                    continue;
                }
                if (inMainSection)
                {
                    if (thisLine.TrimStart().StartsWith("["))
                    {
                        // moved onto another section
                        break;
                    }
                    if (thisLine.IndexOf(':') > 0)
                    {
                        string[] parts = thisLine.Split(':');
                        // Convert from Pamela XPOS into milliseconds
                        int milliSeconds = ((Convert.ToInt32(parts[0]) / 15) * 1000) / 24;
                        string phenomeCode = parts[1].Trim().ToUpper();
                        int frameID = FindFrameNumberForPhenome(phenomeCode);
                        if (frameID < 0)
                        {
                            string friendlyFileName = Path.GetFileName(fileName);
                            errors.Add(new CompileError("No frame found to match phenome code '" + phenomeCode + "'", friendlyFileName, lineNumber));
                        }
                        else
                        {
                            syncDataForThisFile.Phenomes.Add(new SpeechLipSyncPhenome(milliSeconds, (short)frameID));
                        }
                    }
                }
            }
            sr.Close();
            syncDataForThisFile.Phenomes.Sort();

            // The PAM file contains start times: Convert to end times
            for (int i = 0; i < syncDataForThisFile.Phenomes.Count - 1; i++)
            {
                syncDataForThisFile.Phenomes[i].EndTimeOffset = syncDataForThisFile.Phenomes[i + 1].EndTimeOffset;
            }

            if (syncDataForThisFile.Phenomes.Count > 1)
            {
                syncDataForThisFile.Phenomes[syncDataForThisFile.Phenomes.Count - 1].EndTimeOffset = syncDataForThisFile.Phenomes[syncDataForThisFile.Phenomes.Count - 2].EndTimeOffset + 1000;
            }

            return syncDataForThisFile;
        }
Esempio n. 8
0
        public static void ProcessAllGameText(IGameTextProcessor processor, Game game, CompileMessages errors)
        {
            foreach (Dialog dialog in game.RootDialogFolder.AllItemsFlat)
            {
                foreach (DialogOption option in dialog.Options)
                {
                    option.Text = processor.ProcessText(option.Text, GameTextType.DialogOption, game.PlayerCharacter.ID);
                }

                dialog.Script = processor.ProcessText(dialog.Script, GameTextType.DialogScript);
            }

            foreach (ScriptAndHeader script in game.RootScriptFolder.AllItemsFlat)
            {                                
                string newScript = processor.ProcessText(script.Script.Text, GameTextType.Script);
                if (newScript != script.Script.Text)
                {
                    // Only cause it to flag Modified if we changed it
                    script.Script.Text = newScript;
                }                
            }

            foreach (GUI gui in game.RootGUIFolder.AllItemsFlat)
            {
                foreach (GUIControl control in gui.Controls)
                {
                    GUILabel label = control as GUILabel;
                    if (label != null)
                    {
                        label.Text = processor.ProcessText(label.Text, GameTextType.ItemDescription);
                    }
                    else
                    {
                        GUIButton button = control as GUIButton;
                        if (button != null)
                        {
                            button.Text = processor.ProcessText(button.Text, GameTextType.ItemDescription);
                        }
                    }
                }
            }

            foreach (Character character in game.RootCharacterFolder.AllItemsFlat)
            {
                character.RealName = processor.ProcessText(character.RealName, GameTextType.ItemDescription);
            }

            foreach (InventoryItem item in game.RootInventoryItemFolder.AllItemsFlat)
            {
                item.Description = processor.ProcessText(item.Description, GameTextType.ItemDescription);
            }

			for (int i = 0; i < game.GlobalMessages.Length; i++)
			{
				game.GlobalMessages[i] = processor.ProcessText(game.GlobalMessages[i], GameTextType.Message);
			}

            Factory.AGSEditor.RunProcessAllGameTextsEvent(processor, errors);
        }
Esempio n. 9
0
        public static void ProcessAllGameText(IGameTextProcessor processor, Game game, CompileMessages errors)
        {
            foreach (Dialog dialog in game.Dialogs)
            {
                foreach (DialogOption option in dialog.Options)
                {
                    option.Text = processor.ProcessText(option.Text, GameTextType.DialogOption, game.PlayerCharacter.ID);
                }

                dialog.Script = processor.ProcessText(dialog.Script, GameTextType.DialogScript);
            }

            foreach (Script script in game.Scripts)
            {
                if (!script.IsHeader)
                {
                    string newScript = processor.ProcessText(script.Text, GameTextType.Script);
                    if (newScript != script.Text)
                    {
                        // Only cause it to flag Modified if we changed it
                        script.Text = newScript;
                    }
                }
            }

            foreach (GUI gui in game.GUIs)
            {
                foreach (GUIControl control in gui.Controls)
                {
                    if (control is GUILabel)
                    {
                        ((GUILabel)control).Text = processor.ProcessText(((GUILabel)control).Text, GameTextType.ItemDescription);
                    }
                    else if (control is GUIButton)
                    {
                        ((GUIButton)control).Text = processor.ProcessText(((GUIButton)control).Text, GameTextType.ItemDescription);
                    }
                }
            }

            foreach (Character character in game.Characters)
            {
                character.RealName = processor.ProcessText(character.RealName, GameTextType.ItemDescription);
            }

            foreach (InventoryItem item in game.InventoryItems)
            {
                item.Description = processor.ProcessText(item.Description, GameTextType.ItemDescription);
            }

            for (int i = 0; i < game.GlobalMessages.Length; i++)
            {
                game.GlobalMessages[i] = processor.ProcessText(game.GlobalMessages[i], GameTextType.Message);
            }

            Factory.AGSEditor.RunProcessAllGameTextsEvent(processor, errors);
        }
Esempio n. 10
0
        public static CompileMessages ReplaceAllGameText(Game game, Translation withTranslation)
        {
            CompileMessages errors = new CompileMessages();

            TextImportProcessor processor = new TextImportProcessor(game, errors, withTranslation.TranslatedLines);

            TextProcessingHelper.ProcessAllGameText(processor, game, errors);

            return errors;
        }
Esempio n. 11
0
        public CompileMessages CreateTranslationList(Game game)
        {
            CompileMessages errors = new CompileMessages();

            TranslationSourceProcessor processor = new TranslationSourceProcessor(game, errors);

            TextProcessingHelper.ProcessAllGameText(processor, game, errors);

            _linesForTranslation = processor.LinesForTranslation;

            return errors;
        }
Esempio n. 12
0
		public CompileMessages CreateVoiceActingScript(Game game)
		{
			CompileMessages errors = new CompileMessages();

			VoiceActorScriptProcessor processor = new VoiceActorScriptProcessor(game, errors, GetFunctionCallsToProcessForSpeech(true));

			TextProcessingHelper.ProcessAllGameText(processor, game, errors);

			_linesByCharacter = processor.LinesByCharacter;
			_linesInOrder = processor.LinesInOrder;

			return errors;
		}
Esempio n. 13
0
 public override bool Build(CompileMessages errors, bool forceRebuild)
 {
     if (!base.Build(errors, forceRebuild)) return false;
     try
     {
         string baseGameFileName = Factory.AGSEditor.BaseGameFileName;
         string exeFileName = baseGameFileName + ".exe";
         IBuildTarget targetWin = BuildTargetsInfo.FindBuildTargetByName("Windows");
         if (targetWin == null)
         {
             errors.Add(new CompileError("Debug build depends on Windows build target being available! Your AGS installation may be corrupted!"));
             return false;
         }
         string compiledEXE = targetWin.GetCompiledPath(exeFileName);
         string sourceEXE = Path.Combine(Factory.AGSEditor.EditorDirectory, AGSEditor.ENGINE_EXE_FILE_NAME);
         Utilities.DeleteFileIfExists(compiledEXE);
         File.Copy(sourceEXE, exeFileName, true);
         BusyDialog.Show("Please wait while we prepare to run the game...", new BusyDialog.ProcessingHandler(CreateDebugFiles), errors);
         if (errors.HasErrors)
         {
             return false;
         }
         Utilities.DeleteFileIfExists(GetDebugPath(exeFileName));
         File.Move(exeFileName, GetDebugPath(exeFileName));
         // copy configuration from Compiled folder to use with Debugging
         string cfgFilePath = targetWin.GetCompiledPath(AGSEditor.CONFIG_FILE_NAME);
         if (File.Exists(cfgFilePath))
         {
             File.Copy(cfgFilePath, GetDebugPath(AGSEditor.CONFIG_FILE_NAME), true);
         }
         else
         {
             cfgFilePath = Path.Combine(AGSEditor.OUTPUT_DIRECTORY, Path.Combine(AGSEditor.DATA_OUTPUT_DIRECTORY, AGSEditor.CONFIG_FILE_NAME));
             if (File.Exists(cfgFilePath))
             {
                 File.Copy(cfgFilePath, GetDebugPath(AGSEditor.CONFIG_FILE_NAME), true);
             }
         }
         foreach (Plugin plugin in Factory.AGSEditor.CurrentGame.Plugins)
         {
             File.Copy(Path.Combine(Factory.AGSEditor.EditorDirectory, plugin.FileName), GetDebugPath(plugin.FileName), true);
         }
     }
     catch (Exception ex)
     {
         errors.Add(new CompileError("Unexpected error: " + ex.Message));
         return false;
     }
     return true;
 }
Esempio n. 14
0
 public override bool Build(CompileMessages errors, bool forceRebuild)
 {
     if (!base.Build(errors, forceRebuild)) return false;
     string compiledDataDir = Path.Combine(AGSEditor.OUTPUT_DIRECTORY, AGSEditor.DATA_OUTPUT_DIRECTORY);
     string baseGameFileName = Factory.AGSEditor.BaseGameFileName;
     string newExeName = GetCompiledPath(baseGameFileName + ".exe");
     string sourceEXE = Path.Combine(Factory.AGSEditor.EditorDirectory, AGSEditor.ENGINE_EXE_FILE_NAME);
     File.Copy(sourceEXE, newExeName, true);
     UpdateWindowsEXE(newExeName, errors);
     CreateCompiledSetupProgram();
     Environment.CurrentDirectory = Factory.AGSEditor.CurrentGame.DirectoryPath;
     foreach (string fileName in Utilities.GetDirectoryFileList(compiledDataDir, "*"))
     {
         if (fileName.EndsWith(".ags"))
         {
             using (FileStream ostream = File.Open(GetCompiledPath(baseGameFileName + ".exe"), FileMode.Append,
                 FileAccess.Write))
             {
                 int startPosition = (int)ostream.Position;
                 using (FileStream istream = File.Open(fileName, FileMode.Open, FileAccess.Read))
                 {
                     const int bufferSize = 4096;
                     byte[] buffer = new byte[bufferSize];
                     for (int count = istream.Read(buffer, 0, bufferSize); count > 0;
                         count = istream.Read(buffer, 0, bufferSize))
                     {
                         ostream.Write(buffer, 0, count);
                     }
                 }
                 // write the offset into the EXE where the first data file resides
                 ostream.Write(BitConverter.GetBytes(startPosition), 0, 4);
                 // write the CLIB end signature so the engine knows this is a valid EXE
                 ostream.Write(Encoding.UTF8.GetBytes(NativeConstants.CLIB_END_SIGNATURE.ToCharArray()), 0,
                     NativeConstants.CLIB_END_SIGNATURE.Length);
             }
         }
         else if (!fileName.EndsWith(AGSEditor.CONFIG_FILE_NAME))
         {
             Utilities.CreateHardLink(GetCompiledPath(Path.GetFileName(fileName)), fileName, true);
         }
     }
     // Update config file with current game parameters
     Factory.AGSEditor.WriteConfigFile(GetCompiledPath());
     // Copy Windows plugins
     CopyPlugins(errors);
     return true;
 }
Esempio n. 15
0
        public SpeechLineProcessor(Game game, bool includeNarrator, bool combineIdenticalLines, 
            bool removeNumbering, int? characterID,
            Dictionary<string, FunctionCallType> speechableFunctionCalls, 
            CompileMessages errors, StreamWriter referenceFile)
            : base(game, errors, true, false, speechableFunctionCalls)
        {
            _speechLineCount = new Dictionary<int, int>();
            _combineIdenticalLines = combineIdenticalLines;
            _includeNarrator = includeNarrator;
            _referenceFile = referenceFile;
            _removeNumbering = removeNumbering;
            _characterID = characterID;

            if (combineIdenticalLines)
            {
                _existingLines = new Dictionary<int, Dictionary<string, string>>();
            }
        }
Esempio n. 16
0
 public static void CreateInteractionScripts(Game game, CompileMessages errors)
 {
     Script theScript = game.Scripts.GetScriptByFilename(Script.GLOBAL_SCRIPT_FILE_NAME);
     foreach (InventoryItem item in game.InventoryItems)
     {
         if (item.Name.Length < 1)
         {
             item.Name = "iInventory" + item.ID;
         }
         CreateScriptsForInteraction(item.Name, theScript, item.Interactions, errors);
     }
     foreach (Character character in game.Characters)
     {
         if (character.ScriptName.Length < 1)
         {
             character.ScriptName = "cCharacter" + character.ID;
         }
         CreateScriptsForInteraction(character.ScriptName, theScript, character.Interactions, errors);
     }
 }
Esempio n. 17
0
 public override bool Build(CompileMessages errors, bool forceRebuild)
 {
     if (!base.Build(errors, forceRebuild)) return false;
     Factory.AGSEditor.SetMODMusicFlag();
     DeleteAnyExistingSplitResourceFiles();
     if (!DataFileWriter.SaveThisGameToFile(AGSEditor.COMPILED_DTA_FILE_NAME, Factory.AGSEditor.CurrentGame, errors))
     {
         return false;
     }
     string errorMsg = DataFileWriter.MakeDataFile(ConstructFileListForDataFile(), Factory.AGSEditor.CurrentGame.Settings.SplitResources * 1000000,
         Factory.AGSEditor.BaseGameFileName, true);
     if (errorMsg != null)
     {
         errors.Add(new CompileError(errorMsg));
     }
     File.Delete(AGSEditor.COMPILED_DTA_FILE_NAME);
     CreateAudioVOXFile(forceRebuild);
     // Update config file with current game parameters
     Factory.AGSEditor.WriteConfigFile(GetCompiledPath());
     return true;
 }
Esempio n. 18
0
        public CompileMessages CompileGame(bool forceRebuild, bool createMiniExeForDebug)
        {
            Factory.GUIController.ClearOutputPanel();
            CompileMessages errors = new CompileMessages();

            Utilities.EnsureStandardSubFoldersExist();

            if (PreCompileGame != null)
            {
                PreCompileGameEventArgs evArgs = new PreCompileGameEventArgs(forceRebuild);
                evArgs.Errors = errors;

                PreCompileGame(evArgs);

                if (!evArgs.AllowCompilation)
                {
                    Factory.GUIController.ShowOutputPanel(errors);
                    ReportErrorsIfAppropriate(errors);
                    return errors;
                }
            }

            RunPreCompilationChecks(errors);

            if (!errors.HasErrors)
            {
                CompileMessage result = (CompileMessage)BusyDialog.Show("Please wait while your scripts are compiled...", new BusyDialog.ProcessingHandler(CompileScripts), new CompileScriptsParameters(errors, forceRebuild));
                if (result != null)
                {
                    errors.Add(result);
                }
                else if (!errors.HasErrors)
                {
                    string sourceEXE = Path.Combine(this.EditorDirectory, ENGINE_EXE_FILE_NAME);
                    if (!File.Exists(sourceEXE))
                    {
                        errors.Add(new CompileError("Cannot find the file '" + sourceEXE + "'. This file is required in order to compile your game."));
                    }
                    else if (createMiniExeForDebug)
                    {
                        CreateMiniEXEForDebugging(sourceEXE, errors);
                    }
                    else
                    {
                        CreateCompiledFiles(sourceEXE, errors, forceRebuild);
                    }
                }
            }

            Factory.GUIController.ShowOutputPanel(errors);

            ReportErrorsIfAppropriate(errors);

            return errors;
        }
Esempio n. 19
0
 internal CompileScriptsParameters(CompileMessages errors, bool rebuildAll)
 {
     this.Errors = errors;
     this.RebuildAll = rebuildAll;
 }
Esempio n. 20
0
        public override bool Build(CompileMessages errors, bool forceRebuild)
        {
            if (!base.Build(errors, forceRebuild))
            {
                return(false);
            }
            if (!CheckPluginsHaveSharedLibraries())
            {
                errors.Add(new CompileError("Could not build for Linux due to missing plugins."));
                return(false);
            }
            foreach (string fileName in Directory.GetFiles(Path.Combine(AGSEditor.OUTPUT_DIRECTORY, AGSEditor.DATA_OUTPUT_DIRECTORY)))
            {
                if ((!fileName.EndsWith(".dll", StringComparison.OrdinalIgnoreCase)) &&
                    (!Path.GetFileName(fileName).Equals("winsetup.exe", StringComparison.OrdinalIgnoreCase)) &&
                    (!Path.GetFileName(fileName).Equals(AGSEditor.CONFIG_FILE_NAME, StringComparison.OrdinalIgnoreCase)))
                {
                    Utilities.CreateHardLink(GetCompiledPath(LINUX_DATA_DIR, Path.GetFileName(fileName)), fileName, true);
                }
            }
            // Update config file with current game parameters
            Factory.AGSEditor.WriteConfigFile(GetCompiledPath(LINUX_DATA_DIR));

            foreach (KeyValuePair <string, string> pair in GetRequiredLibraryPaths())
            {
                string fileName = pair.Value;
                if (!fileName.EndsWith(pair.Key))
                {
                    fileName = Path.Combine(fileName, pair.Key);
                }
                string folderName = null;
                if ((!fileName.EndsWith("ags32")) && (!fileName.EndsWith("ags64")))
                {
                    // the engine files belong in the LINUX_DATA_DIR, but the other libs
                    // should have lib32 or lib64 subdirectories as part of their name
                    folderName = Path.GetFileName(Path.GetDirectoryName(fileName).TrimEnd(Path.DirectorySeparatorChar));
                }
                Utilities.CreateHardLink(GetCompiledPath(LINUX_DATA_DIR, folderName, Path.GetFileName(fileName)),
                                         fileName, true);
            }
            string linuxDataLib32Dir   = GetCompiledPath(LINUX_DATA_DIR, LINUX_LIB32_DIR);
            string linuxDataLib64Dir   = GetCompiledPath(LINUX_DATA_DIR, LINUX_LIB64_DIR);
            string editorLinuxDir      = Path.Combine(Factory.AGSEditor.EditorDirectory, LINUX_DIR);
            string editorLinuxLib32Dir = Path.Combine(editorLinuxDir, LINUX_LIB32_DIR);
            string editorLinuxLib64Dir = Path.Combine(editorLinuxDir, LINUX_LIB64_DIR);

            foreach (string soName in _plugins)
            {
                Utilities.CreateHardLink(Path.Combine(linuxDataLib32Dir, soName),
                                         Path.Combine(editorLinuxLib32Dir, soName), true);
                Utilities.CreateHardLink(Path.Combine(linuxDataLib64Dir, soName),
                                         Path.Combine(editorLinuxLib64Dir, soName), true);
            }
            string scriptFileName = GetCompiledPath(Factory.AGSEditor.BaseGameFileName.Replace(" ", "")); // strip whitespace from script name
            string scriptText     =
                @"#!/bin/sh
SCRIPTPATH=""$(dirname ""$(readlink -f $0)"")""

if test ""x$@"" = ""x-h"" -o ""x$@"" = ""x--help""
  then
    echo ""Usage:"" ""$(basename ""$(readlink -f $0)"")"" ""[<ags options>]""
    echo """"
fi

if test $(uname -m) = x86_64
  then" + GetSymLinkScriptForEachPlugin(true) +
                @"
  else" + GetSymLinkScriptForEachPlugin(false) +
                @"
fi
";

            scriptText = scriptText.Replace("\r\n", "\n"); // make sure script has UNIX line endings
            FileStream stream = File.Create(scriptFileName);

            byte[] bytes = Encoding.UTF8.GetBytes(scriptText);
            stream.Write(bytes, 0, bytes.Length);
            stream.Close();
            return(true);
        }
Esempio n. 21
0
        private void _agsEditor_ExtraCompilationStep(CompileMessages errors)
        {
            string[] pamFileList = ConstructFileListForSyncData();

            if (DoesTargetFileNeedRebuild(LIP_SYNC_DATA_OUTPUT, pamFileList, _pamFileStatus))
            {
                CompilePAMFiles(errors);

                UpdateVOXFileStatusWithCurrentFileTimes(pamFileList, _pamFileStatus);
            }
        }
Esempio n. 22
0
 private static SpriteFolder ImportSpriteFolders(BinaryReader reader, Dictionary<int,Sprite> spriteList, CompileMessages importErrors)
 {
     const string DUMMY_FOLDER_NAME = "$$TEMPNAME";
     Dictionary<int, SpriteFolder> spriteFolders = new Dictionary<int, SpriteFolder>();
     int spriteFolderCount = reader.ReadInt32();
     // First, create an object for all of them (since folder 2
     // might have folder 15 as its parent, all objects need
     // to be there from the start).
     for (int i = 0; i < spriteFolderCount; i++)
     {
         spriteFolders.Add(i, new SpriteFolder(DUMMY_FOLDER_NAME));
     }
     for (int i = 0; i < spriteFolderCount; i++)
     {
         int numItems = reader.ReadInt32();
         for (int j = 0; j < 240; j++)
         {
             int spriteNum = reader.ReadInt16();
             if ((j < numItems) && (spriteNum >= 0))
             {
                 if (spriteList.ContainsKey(spriteNum))
                 {
                     spriteFolders[i].Sprites.Add(spriteList[spriteNum]);
                     spriteList.Remove(spriteNum);
                 }
                 else
                 {
                     importErrors.Add(new CompileWarning("Sprite " + spriteNum + " not found whilst importing the sprite folder list"));
                 }
             }
         }
         int parentFolder = reader.ReadInt16();
         if (parentFolder >= 0)
         {
             if (!spriteFolders.ContainsKey(parentFolder))
             {
                 throw new AGS.Types.InvalidDataException("Invalid sprite folder structure found: folder " + i + " has parent " + parentFolder);
             }
             spriteFolders[parentFolder].SubFolders.Add(spriteFolders[i]);
         }
         string folderName = ReadNullTerminatedString(reader, 30);
         if (folderName.Contains("\0"))
         {
             folderName = folderName.TrimEnd('\0');
         }
         spriteFolders[i].Name = folderName;
     }
     return spriteFolders[0];
 }
Esempio n. 23
0
        public static void ProcessAllGameText(IGameTextProcessor processor, Game game, CompileMessages errors)
        {
            foreach (Dialog dialog in game.RootDialogFolder.AllItemsFlat)
            {
                foreach (DialogOption option in dialog.Options)
                {
                    option.Text = processor.ProcessText(option.Text, GameTextType.DialogOption, game.PlayerCharacter.ID);
                }

                dialog.Script = processor.ProcessText(dialog.Script, GameTextType.DialogScript);
            }

            foreach (ScriptAndHeader script in game.RootScriptFolder.AllItemsFlat)
            {
                string newScript = processor.ProcessText(script.Script.Text, GameTextType.Script);
                if (newScript != script.Script.Text)
                {
                    // Only cause it to flag Modified if we changed it
                    script.Script.Text = newScript;
                }
            }

            foreach (GUI gui in game.RootGUIFolder.AllItemsFlat)
            {
                foreach (GUIControl control in gui.Controls)
                {
                    GUILabel label = control as GUILabel;
                    if (label != null)
                    {
                        label.Text = processor.ProcessText(label.Text, GameTextType.ItemDescription);
                    }
                    else
                    {
                        GUIButton button = control as GUIButton;
                        if (button != null)
                        {
                            button.Text = processor.ProcessText(button.Text, GameTextType.ItemDescription);
                        }
                    }
                }
            }

            CustomProperty tmp;

            foreach (Character character in game.RootCharacterFolder.AllItemsFlat)
            {
                character.RealName = processor.ProcessText(character.RealName, GameTextType.ItemDescription);

                if (character.Properties.PropertyValues.TryGetValue("DescName", out tmp))
                {
                    processor.ProcessText(tmp.Value, GameTextType.ItemDescription);
                }
                if (character.Properties.PropertyValues.TryGetValue("Verb", out tmp))
                {
                    processor.ProcessText(tmp.Value, GameTextType.ItemDescription);
                }
                if (character.Properties.PropertyValues.TryGetValue("StringLookAt", out tmp))
                {
                    processor.ProcessText(tmp.Value, GameTextType.ItemDescription);
                }
                if (character.Properties.PropertyValues.TryGetValue("StringTalkTo", out tmp))
                {
                    processor.ProcessText(tmp.Value, GameTextType.ItemDescription);
                }
                if (character.Properties.PropertyValues.TryGetValue("StringExamine", out tmp))
                {
                    processor.ProcessText(tmp.Value, GameTextType.ItemDescription);
                }
                if (character.Properties.PropertyValues.TryGetValue("StringThink", out tmp))
                {
                    processor.ProcessText(tmp.Value, GameTextType.ItemDescription);
                }
                if (character.Properties.PropertyValues.TryGetValue("StringUTORP", out tmp))
                {
                    processor.ProcessText(tmp.Value, GameTextType.ItemDescription);
                }
                if (character.Properties.PropertyValues.TryGetValue("VerbInv", out tmp))
                {
                    processor.ProcessText(tmp.Value, GameTextType.ItemDescription);
                }
                if (character.Properties.PropertyValues.TryGetValue("PrepositionInv", out tmp))
                {
                    processor.ProcessText(tmp.Value, GameTextType.ItemDescription);
                }
            }

            foreach (InventoryItem item in game.RootInventoryItemFolder.AllItemsFlat)
            {
                item.Description = processor.ProcessText(item.Description, GameTextType.ItemDescription);

                if (item.Properties.PropertyValues.TryGetValue("DescName", out tmp))
                {
                    processor.ProcessText(tmp.Value, GameTextType.ItemDescription);
                }
                if (item.Properties.PropertyValues.TryGetValue("Verb", out tmp))
                {
                    processor.ProcessText(tmp.Value, GameTextType.ItemDescription);
                }
                if (item.Properties.PropertyValues.TryGetValue("StringLookAt", out tmp))
                {
                    processor.ProcessText(tmp.Value, GameTextType.ItemDescription);
                }
                if (item.Properties.PropertyValues.TryGetValue("StringTalkTo", out tmp))
                {
                    processor.ProcessText(tmp.Value, GameTextType.ItemDescription);
                }
                if (item.Properties.PropertyValues.TryGetValue("StringExamine", out tmp))
                {
                    processor.ProcessText(tmp.Value, GameTextType.ItemDescription);
                }
                if (item.Properties.PropertyValues.TryGetValue("StringThink", out tmp))
                {
                    processor.ProcessText(tmp.Value, GameTextType.ItemDescription);
                }
                if (item.Properties.PropertyValues.TryGetValue("StringUTORP", out tmp))
                {
                    processor.ProcessText(tmp.Value, GameTextType.ItemDescription);
                }
                if (item.Properties.PropertyValues.TryGetValue("VerbInv", out tmp))
                {
                    processor.ProcessText(tmp.Value, GameTextType.ItemDescription);
                }
                if (item.Properties.PropertyValues.TryGetValue("PrepositionInv", out tmp))
                {
                    processor.ProcessText(tmp.Value, GameTextType.ItemDescription);
                }
            }

            for (int i = 0; i < game.GlobalMessages.Length; i++)
            {
                game.GlobalMessages[i] = processor.ProcessText(game.GlobalMessages[i], GameTextType.Message);
            }

            Factory.AGSEditor.RunProcessAllGameTextsEvent(processor, errors);
        }
Esempio n. 24
0
 private Script CompileDialogs(CompileMessages errors, bool rebuildAll)
 {
     DialogScriptConverter dialogConverter = new DialogScriptConverter();
     string dialogScriptsText = dialogConverter.ConvertGameDialogScripts(_game, errors, rebuildAll);
     Script dialogScripts = new Script(Script.DIALOG_SCRIPTS_FILE_NAME, dialogScriptsText, false);
     Script globalScript = _game.Scripts.GetScriptByFilename(Script.GLOBAL_SCRIPT_FILE_NAME);
     if (!System.Text.RegularExpressions.Regex.IsMatch(globalScript.Text, @"function\s+dialog_request\s*\("))
     {
         // A dialog_request must exist in the global script, otherwise
         // the dialogs script fails to load at run-time
         globalScript.Text += Environment.NewLine + "function dialog_request(int param) {" + Environment.NewLine + "}";
     }
     return dialogScripts;
 }
Esempio n. 25
0
        public static void ProcessAllGameText(IGameTextProcessor processor, Game game, CompileMessages errors)
        {
            foreach (Dialog dialog in game.Dialogs)
            {
                foreach (DialogOption option in dialog.Options)
                {
                    option.Text = processor.ProcessText(option.Text, GameTextType.DialogOption, game.PlayerCharacter.ID);
                }

                dialog.Script = processor.ProcessText(dialog.Script, GameTextType.DialogScript);
            }

            foreach (Script script in game.Scripts)
            {
                if (!script.IsHeader)
                {
                    string newScript = processor.ProcessText(script.Text, GameTextType.Script);
                    if (newScript != script.Text)
                    {
                        // Only cause it to flag Modified if we changed it
                        script.Text = newScript;
                    }
                }
            }

            foreach (GUI gui in game.GUIs)
            {
                foreach (GUIControl control in gui.Controls)
                {
                    if (control is GUILabel)
                    {
                        ((GUILabel)control).Text = processor.ProcessText(((GUILabel)control).Text, GameTextType.ItemDescription);
                    }
                    else if (control is GUIButton)
                    {
                        ((GUIButton)control).Text = processor.ProcessText(((GUIButton)control).Text, GameTextType.ItemDescription);
                    }
                }
            }

            foreach (Character character in game.Characters)
            {
                character.RealName = processor.ProcessText(character.RealName, GameTextType.ItemDescription);
            }

            foreach (InventoryItem item in game.InventoryItems)
            {
                item.Description = processor.ProcessText(item.Description, GameTextType.ItemDescription);
            }

            for (int i = 0; i < game.GlobalMessages.Length; i++)
            {
                game.GlobalMessages[i] = processor.ProcessText(game.GlobalMessages[i], GameTextType.Message);
            }

            Factory.AGSEditor.RunProcessAllGameTextsEvent(processor, errors);
        }
Esempio n. 26
0
        private void UpdateAllTranslationsWithNewDefaultText(Dictionary <string, string> textChanges, CompileMessages errors)
        {
            foreach (Translation otherTranslation in _agsEditor.CurrentGame.Translations)
            {
                otherTranslation.LoadData();
                Dictionary <string, string> newTranslation = new Dictionary <string, string>();

                foreach (string sourceLine in otherTranslation.TranslatedLines.Keys)
                {
                    string otherTranslationOfThisLine = otherTranslation.TranslatedLines[sourceLine];
                    string newKeyName = null;
                    if ((textChanges.ContainsKey(sourceLine)) && (textChanges[sourceLine].Length > 0))
                    {
                        newKeyName = textChanges[sourceLine];

                        if (newTranslation.ContainsKey(newKeyName))
                        {
                            if (!string.IsNullOrEmpty(otherTranslationOfThisLine))
                            {
                                errors.Add(new CompileWarning("Text '" + newKeyName + "' already has a translation; '" + sourceLine + "' translation will be lost"));
                            }
                            newKeyName = null;
                        }
                    }
                    else if (!newTranslation.ContainsKey(sourceLine))
                    {
                        newKeyName = sourceLine;
                    }

                    if (newKeyName != null)
                    {
                        if (newKeyName == otherTranslationOfThisLine)
                        {
                            newTranslation.Add(newKeyName, string.Empty);
                        }
                        else
                        {
                            newTranslation.Add(newKeyName, otherTranslationOfThisLine);
                        }
                    }
                }

                otherTranslation.TranslatedLines = newTranslation;
                otherTranslation.Modified        = true;
                otherTranslation.SaveData();
            }
        }
Esempio n. 27
0
        private void CompileTranslation(Translation translation, CompileMessages errors)
        {
            translation.LoadData();

            string   tempFile     = Path.GetTempFileName();
            Encoding textEncoding = translation.Encoding;

            using (BinaryWriter bw = new BinaryWriter(new FileStream(tempFile, FileMode.Create, FileAccess.Write)))
            {
                bw.Write(Encoding.ASCII.GetBytes(COMPILED_TRANSLATION_FILE_SIGNATURE));
                bw.Write(TRANSLATION_BLOCK_GAME_ID);
                byte[] gameName = EncryptStringToBytes(_agsEditor.CurrentGame.Settings.GameName, _agsEditor.CurrentGame.TextEncoding);
                bw.Write(gameName.Length + 4 + 4);
                bw.Write(_agsEditor.CurrentGame.Settings.UniqueID);
                bw.Write(gameName.Length);
                bw.Write(gameName);
                bw.Write(TRANSLATION_BLOCK_TRANSLATION_DATA);
                long offsetOfBlockSize = bw.BaseStream.Position;
                bw.Write((int)0); // placeholder for block size, will be filled later
                foreach (string line in translation.TranslatedLines.Keys)
                {
                    if (translation.TranslatedLines[line].Length > 0)
                    {
                        WriteString(bw, Regex.Unescape(line), textEncoding);
                        WriteString(bw, Regex.Unescape(translation.TranslatedLines[line]), textEncoding);
                    }
                }
                WriteString(bw, string.Empty, textEncoding);
                WriteString(bw, string.Empty, textEncoding);
                long mainBlockSize = (bw.BaseStream.Position - offsetOfBlockSize) - 4;
                bw.Write(TRANSLATION_BLOCK_OPTIONS);
                bw.Write((int)12);
                bw.Write(translation.NormalFont ?? -1);
                bw.Write(translation.SpeechFont ?? -1);
                bw.Write((translation.RightToLeftText == true) ? 2 : ((translation.RightToLeftText == false) ? 1 : -1));

                bw.Write((int)0); // required for compatibility
                DataFileWriter.WriteString(TRANSLATION_BLOCK_STROPTIONS, 16, bw);
                var data_len_pos = bw.BaseStream.Position;
                bw.Write((long)0); // data length placeholder
                bw.Write((int)1);  // size of key/value table
                DataFileWriter.FilePutString("encoding", bw);
                DataFileWriter.FilePutString(translation.EncodingHint, bw);
                var end_pos  = bw.BaseStream.Position;
                var data_len = end_pos - data_len_pos - 8;
                bw.Seek((int)data_len_pos, SeekOrigin.Begin);
                bw.Write(data_len);
                bw.Seek((int)end_pos, SeekOrigin.Begin);

                bw.Write(TRANSLATION_BLOCK_END_OF_FILE);
                bw.Write((int)0);
                bw.Seek((int)offsetOfBlockSize, SeekOrigin.Begin);
                bw.Write((int)mainBlockSize);
                bw.Close();
            }

            string destFile = Path.Combine(AGSEditor.OUTPUT_DIRECTORY,
                                           Path.Combine(AGSEditor.DATA_OUTPUT_DIRECTORY, translation.CompiledFileName));

            Utilities.TryDeleteFile(destFile);
            File.Move(tempFile, destFile);
        }
Esempio n. 28
0
        public override bool Build(CompileMessages errors, bool forceRebuild)
        {
            if (!base.Build(errors, forceRebuild))
            {
                return(false);
            }
            if (!CheckPluginsHaveSharedLibraries())
            {
                errors.Add(new CompileError("Could not build for Linux due to missing plugins."));
                return(false);
            }
            foreach (string fileName in Directory.GetFiles(Path.Combine(AGSEditor.OUTPUT_DIRECTORY, AGSEditor.DATA_OUTPUT_DIRECTORY)))
            {
                if ((File.GetAttributes(fileName) & (FileAttributes.Hidden | FileAttributes.System | FileAttributes.Temporary)) != 0)
                {
                    continue;
                }
                if ((!fileName.EndsWith(".dll", StringComparison.OrdinalIgnoreCase)) &&
                    (!Path.GetFileName(fileName).Equals("winsetup.exe", StringComparison.OrdinalIgnoreCase)) &&
                    (!Path.GetFileName(fileName).Equals(AGSEditor.CONFIG_FILE_NAME, StringComparison.OrdinalIgnoreCase)))
                {
                    Utilities.HardlinkOrCopy(GetCompiledPath(LINUX_DATA_DIR, Path.GetFileName(fileName)), fileName, true);
                }
            }
            // Update config file with current game parameters
            Factory.AGSEditor.WriteConfigFile(GetCompiledPath(LINUX_DATA_DIR));

            foreach (KeyValuePair <string, string> pair in GetRequiredLibraryPaths())
            {
                string fileName = pair.Value;
                if (!fileName.EndsWith(pair.Key))
                {
                    fileName = Path.Combine(fileName, pair.Key);
                }
                string folderName = null;
                if ((!fileName.EndsWith("ags32")) && (!fileName.EndsWith("ags64")))
                {
                    // the engine files belong in the LINUX_DATA_DIR, but the other libs
                    // should have lib32 or lib64 subdirectories as part of their name
                    folderName = Path.GetFileName(Path.GetDirectoryName(fileName).TrimEnd(Path.DirectorySeparatorChar));
                }
                Utilities.HardlinkOrCopy(GetCompiledPath(LINUX_DATA_DIR, folderName, Path.GetFileName(fileName)),
                                         fileName, true);
            }
            string linuxDataLib32Dir   = GetCompiledPath(LINUX_DATA_DIR, LINUX_LIB32_DIR);
            string linuxDataLib64Dir   = GetCompiledPath(LINUX_DATA_DIR, LINUX_LIB64_DIR);
            string editorLinuxDir      = Path.Combine(Factory.AGSEditor.EditorDirectory, LINUX_DIR);
            string editorLinuxLib32Dir = Path.Combine(editorLinuxDir, LINUX_LIB32_DIR);
            string editorLinuxLib64Dir = Path.Combine(editorLinuxDir, LINUX_LIB64_DIR);

            foreach (string soName in _plugins)
            {
                Utilities.HardlinkOrCopy(Path.Combine(linuxDataLib32Dir, soName),
                                         Path.Combine(editorLinuxLib32Dir, soName), true);
                Utilities.HardlinkOrCopy(Path.Combine(linuxDataLib64Dir, soName),
                                         Path.Combine(editorLinuxLib64Dir, soName), true);
            }
            string scriptFileName = GetCompiledPath(Factory.AGSEditor.BaseGameFileName.Replace(" ", "")); // strip whitespace from script name
            string scriptText     =
                @"#!/bin/sh
scriptpath=$(readlink -f ""$0"")
scriptdir=$(dirname ""$scriptpath"")

for arg; do
    if [ ""$arg"" = ""--help"" ]; then
        echo ""Usage: $(basename ""$scriptpath"") [<ags options>]\n""
        break
    fi
done

## Old versions of Mesa can hang when using DRI3
## https://bugs.freedesktop.org/show_bug.cgi?id=106404
export LIBGL_DRI3_DISABLE=true

if [ ""$(uname -m)"" = ""x86_64"" ]; then" + GetSymLinkScriptForEachPlugin(true) +
                @"
else" + GetSymLinkScriptForEachPlugin(false) +
                @"
fi
";

            scriptText = scriptText.Replace("\r\n", "\n"); // make sure script has UNIX line endings
            FileStream stream = File.Create(scriptFileName);

            byte[] bytes = Encoding.UTF8.GetBytes(scriptText);
            stream.Write(bytes, 0, bytes.Length);
            stream.Close();
            return(true);
        }
Esempio n. 29
0
        /// <summary>
        /// Preprocesses and then compiles the script using the supplied headers.
        /// </summary>
        public void CompileScript(Script script, List<Script> headers, CompileMessages errors, bool isRoomScript)
        {
            IPreprocessor preprocessor = CompilerFactory.CreatePreprocessor(AGS.Types.Version.AGS_EDITOR_VERSION);
            DefineMacrosAccordingToGameSettings(preprocessor);

            List<string> preProcessedCode = new List<string>();
            foreach (Script header in headers)
            {
                preProcessedCode.Add(preprocessor.Preprocess(header.Text, header.FileName));
            }

            preProcessedCode.Add(preprocessor.Preprocess(script.Text, script.FileName));

            #if DEBUG
            // TODO: REMOVE BEFORE DISTRIBUTION
            /*			if (true)
            {
                string wholeScript = string.Join("\n", preProcessedCode.ToArray());
                IScriptCompiler compiler = CompilerFactory.CreateScriptCompiler();
                CompileResults output = compiler.CompileScript(wholeScript);
                preprocessor.Results.AddRange(output);
            }*/
            #endif

            if (preprocessor.Results.Count > 0)
            {
                foreach (AGS.CScript.Compiler.Error error in preprocessor.Results)
                {
                    CompileError newError = new CompileError(error.Message, error.ScriptName, error.LineNumber);
                    if (errors == null)
                    {
                        throw newError;
                    }
                    errors.Add(newError);
                }
            }
            else
            {
                Factory.NativeProxy.CompileScript(script, preProcessedCode.ToArray(), _game, isRoomScript);
            }
        }
Esempio n. 30
0
        public override bool Build(CompileMessages errors, bool forceRebuild)
        {
            if (!base.Build(errors, forceRebuild))
            {
                return(false);
            }
            try
            {
                string             baseGameFileName = Factory.AGSEditor.BaseGameFileName;
                string             exeFileName      = baseGameFileName + ".exe";
                BuildTargetWindows targetWin        = BuildTargetsInfo.FindBuildTargetByName("Windows") as BuildTargetWindows;
                if (targetWin == null)
                {
                    errors.Add(new CompileError("Debug build depends on Windows build target being available! Your AGS installation may be corrupted!"));
                    return(false);
                }
                string compiledEXE = targetWin.GetCompiledPath(exeFileName);
                string compiledDat = targetWin.GetCompiledPath(baseGameFileName + ".ags");
                string sourceEXE   = Path.Combine(Factory.AGSEditor.EditorDirectory, AGSEditor.ENGINE_EXE_FILE_NAME);
                Utilities.DeleteFileIfExists(compiledEXE);
                Utilities.DeleteFileIfExists(compiledDat);
                File.Copy(sourceEXE, exeFileName, true);
                BusyDialog.Show("Please wait while we prepare to run the game...", new BusyDialog.ProcessingHandler(CreateDebugFiles), errors);
                if (errors.HasErrors)
                {
                    return(false);
                }
                Utilities.DeleteFileIfExists(GetDebugPath(exeFileName));
                File.Move(exeFileName, GetDebugPath(exeFileName));
                // copy configuration from Compiled folder to use with Debugging
                string cfgFilePath = targetWin.GetCompiledPath(AGSEditor.CONFIG_FILE_NAME);
                if (File.Exists(cfgFilePath))
                {
                    File.Copy(cfgFilePath, GetDebugPath(AGSEditor.CONFIG_FILE_NAME), true);
                }
                else
                {
                    cfgFilePath = Path.Combine(AGSEditor.OUTPUT_DIRECTORY, Path.Combine(AGSEditor.DATA_OUTPUT_DIRECTORY, AGSEditor.CONFIG_FILE_NAME));
                    if (File.Exists(cfgFilePath))
                    {
                        File.Copy(cfgFilePath, GetDebugPath(AGSEditor.CONFIG_FILE_NAME), true);
                    }
                }
                // Copy DLLs
                File.Copy(Path.Combine(Factory.AGSEditor.EditorDirectory, "SDL2.dll"), GetDebugPath("SDL2.dll"), true);
                // Copy plugins
                foreach (Plugin plugin in Factory.AGSEditor.CurrentGame.Plugins)
                {
                    File.Copy(Path.Combine(Factory.AGSEditor.EditorDirectory, plugin.FileName), GetDebugPath(plugin.FileName), true);
                }

                // Copy files from Compiled/Data to Compiled/Windows, because this is currently where game will be looking them up
                targetWin.CopyAuxiliaryGameFiles(Path.Combine(AGSEditor.OUTPUT_DIRECTORY, AGSEditor.DATA_OUTPUT_DIRECTORY), false);
                // Update config file with current game parameters
                Factory.AGSEditor.WriteConfigFile(GetCompiledPath());
            }
            catch (Exception ex)
            {
                errors.Add(new CompileError("Unexpected error: " + ex.Message));
                return(false);
            }
            return(true);
        }
Esempio n. 31
0
 public void RunProcessAllGameTextsEvent(IGameTextProcessor processor, CompileMessages errors)
 {
     if (ProcessAllGameTexts != null)
     {
         ProcessAllGameTexts(processor, errors);
     }
 }
 public TranslationSourceProcessor(Game game, CompileMessages errors)
     : base(game, errors, false, true)
 {
     _linesProcessed = new Dictionary <string, string>();
 }
Esempio n. 33
0
        public static CompileMessages ImportOldEditorDatFile(string fileName, Game game, Dictionary<int, Sprite> spriteList)
        {
            CompileMessages importErrors = new CompileMessages();
            string editorDatFilename = Path.Combine(Path.GetDirectoryName(fileName), "editor.dat");
            BinaryReader reader = new BinaryReader(new FileStream(editorDatFilename, FileMode.Open));
            string fileSig = Encoding.ASCII.GetString(reader.ReadBytes(14));
            if (fileSig != "AGSEditorInfo\0")
            {
                throw new AGS.Types.InvalidDataException("This is not a valid AGS game file.");
            }
            int version = reader.ReadInt32();
            if (version != EDITOR_DAT_LATEST_FILE_VERSION)
            {
                throw new AGS.Types.InvalidDataException("This game is from an unsupported version of AGS. This editor can only import games saved with AGS 2.72.");
            }
            game.Scripts.Clear();

            Script globalScript, scriptHeader;
            ReadGlobalScriptAndScriptHeader(reader, game, out globalScript, out scriptHeader);

            game.RootSpriteFolder = ImportSpriteFolders(reader, spriteList, importErrors);

            ImportRoomList(game, reader, fileName, importErrors);

            if (reader.ReadInt32() != 1)
            {
                throw new AGS.Types.InvalidDataException("Error in game files: invalid header for script modules");
            }

            int moduleCount = reader.ReadInt32();
            for (int i = 0; i < moduleCount; i++)
            {
                string author = ReadNullTerminatedString(reader);
                string description = ReadNullTerminatedString(reader);
                string name = ReadNullTerminatedString(reader);
                string moduleVersion = ReadNullTerminatedString(reader);

                int scriptLength = reader.ReadInt32();
                string moduleScript = Encoding.Default.GetString(reader.ReadBytes(scriptLength));
                reader.ReadByte();  // discard the null terminating byte

                scriptLength = reader.ReadInt32();
                string moduleHeader = Encoding.Default.GetString(reader.ReadBytes(scriptLength));
                reader.ReadByte();  // discard the null terminating byte

                int uniqueKey = reader.ReadInt32();

                game.Scripts.Add(new Script("Module" + i + ".ash", moduleHeader, name, description, author, moduleVersion, uniqueKey, true));
                game.Scripts.Add(new Script("Module" + i + ".asc", moduleScript, name, description, author, moduleVersion, uniqueKey, false));

                int permissions = reader.ReadInt32();
                int weAreOwner = reader.ReadInt32();
            }

            game.Scripts.Add(scriptHeader);
            game.Scripts.Add(globalScript);

            // Ensure that all .asc/.ash files are saved
            foreach (Script script in game.Scripts)
            {
                script.Modified = true;
            }

            int voxFilesListLength = reader.ReadInt32();
            reader.ReadBytes(voxFilesListLength); // skip over vox file list

            // The final portion of the file contains state data
            // for COM plugins, but since we no longer support these,
            // we can ignore it and finish here.

            reader.Close();
            return importErrors;
        }
Esempio n. 34
0
 public TextImportProcessor(Game game, CompileMessages errors, Dictionary <string, string> translationToUse)
     : base(game, errors, true, true)
 {
     _translationToUse = translationToUse;
 }
Esempio n. 35
0
        private static bool CreateScriptsForInteraction(string itemName, Script script, Interactions interactions, CompileMessages errors)
        {
            bool convertedSome = false;

            for (int i = 0; i < interactions.ImportedScripts.Length; i++)
            {
                if ((interactions.ImportedScripts[i] != null) &&
                    (interactions.ImportedScripts[i].Length > 0))
                {
                    if (interactions.ImportedScripts[i].IndexOf(SINGLE_RUN_SCRIPT_TAG) >= 0)
                    {
                        // just a single Run Script -- don't wrap it in an outer
                        // function since there's no need to
                        interactions.ScriptFunctionNames[i] = interactions.ImportedScripts[i].Replace(SINGLE_RUN_SCRIPT_TAG, string.Empty).Replace("();", string.Empty).Trim();
                        convertedSome = true;
                    }
                    else
                    {
                        string funcName = itemName + "_" + interactions.FunctionSuffixes[i];
                        string funcScriptLine = "function " + funcName + "()";
                        interactions.ScriptFunctionNames[i] = funcName;
                        if (script.Text.IndexOf(funcScriptLine) >= 0)
                        {
                            errors.Add(new CompileWarning("Function " + funcName + " already exists in script and could not be created"));
                        }
                        else
                        {
                            script.Text += Environment.NewLine + funcScriptLine + Environment.NewLine;
                            script.Text += "{" + Environment.NewLine + interactions.ImportedScripts[i] + "}" + Environment.NewLine;
                            convertedSome = true;
                        }
                    }
                    interactions.ImportedScripts[i] = null;
                }
            }

            return convertedSome;
        }
Esempio n. 36
0
        public override bool Build(CompileMessages errors, bool forceRebuild)
        {
            if (!base.Build(errors, forceRebuild))
            {
                return(false);
            }
            string my_game_files_text = "var gamefiles = [";

            foreach (string fileName in Directory.GetFiles(Path.Combine(AGSEditor.OUTPUT_DIRECTORY, AGSEditor.DATA_OUTPUT_DIRECTORY)))
            {
                if ((File.GetAttributes(fileName) & (FileAttributes.Hidden | FileAttributes.System | FileAttributes.Temporary)) != 0)
                {
                    continue;
                }
                if ((!fileName.EndsWith(".dll", StringComparison.OrdinalIgnoreCase)) &&
                    (!Path.GetFileName(fileName).Equals("winsetup.exe", StringComparison.OrdinalIgnoreCase)) &&
                    (!Path.GetFileName(fileName).Equals(AGSEditor.CONFIG_FILE_NAME, StringComparison.OrdinalIgnoreCase)))
                {
                    Utilities.HardlinkOrCopy(GetCompiledPath(WEB_DIR, Path.GetFileName(fileName)), fileName, true);

                    my_game_files_text += "'" + Path.GetFileName(fileName) + "', ";
                }
            }
            my_game_files_text += "'" + AGSEditor.CONFIG_FILE_NAME + "'";

            my_game_files_text += "];";

            // Update config file with current game parameters
            Factory.AGSEditor.WriteConfigFile(GetCompiledPath(WEB_DIR));

            string compiled_web_path   = GetCompiledPath(WEB_DIR);
            string editor_web_prebuilt = Path.Combine(Factory.AGSEditor.EditorDirectory, WEB_DIR);

            foreach (KeyValuePair <string, string> pair in GetRequiredLibraryPaths())
            {
                string fileName  = pair.Key;
                string originDir = pair.Value;

                string destFile   = GetCompiledPath(WEB_DIR, fileName);
                string originFile = Path.Combine(originDir, fileName);

                if (fileName.EndsWith(".wasm"))
                {
                    Utilities.HardlinkOrCopy(destFile, originFile, true);
                }
                else
                {
                    string destFileName   = Utilities.ResolveSourcePath(destFile);
                    string sourceFileName = Utilities.ResolveSourcePath(originFile);
                    File.Copy(sourceFileName, destFileName, true);
                }
            }

            FileStream stream = File.Create(GetCompiledPath(WEB_DIR, MY_GAME_FILES_JS));

            byte[] bytes = Encoding.UTF8.GetBytes(my_game_files_text);
            stream.Write(bytes, 0, bytes.Length);
            stream.Close();

            return(true);
        }
Esempio n. 37
0
        private static void ImportRoomList(Game game, BinaryReader reader, string fullPathToGameFiles, CompileMessages importErrors)
        {
            Dictionary<int, UnloadedRoom> rooms = new Dictionary<int, UnloadedRoom>();
            foreach (string roomFileFullPath in Utilities.GetDirectoryFileList(Path.GetDirectoryName(fullPathToGameFiles), "room*.crm"))
            {
                int roomNumber = GetRoomNumberFromFileName(Path.GetFileName(roomFileFullPath));

                if (roomNumber >= 0)
                {
                    try
                    {
                        string roomScript = Factory.NativeProxy.LoadRoomScript(roomFileFullPath);
                        if (roomScript != null)
                        {
                            StreamWriter sw = new StreamWriter(roomFileFullPath.Substring(0, roomFileFullPath.Length - 4) + ".asc", false, Encoding.Default);
                            sw.Write(roomScript);
                            sw.Close();
                        }
                    }
                    catch (AGSEditorException ex)
                    {
                        importErrors.Add(new CompileError("There was an error saving the script for room " + roomNumber + ": " + ex.Message));
                    }

                    UnloadedRoom newUnloadedRoom = new UnloadedRoom(roomNumber);
                    rooms.Add(roomNumber, newUnloadedRoom);
                    game.Rooms.Add(newUnloadedRoom);
                }
                else
                {
                    importErrors.Add(new CompileWarning("The room file '" + roomFileFullPath + "' does not have a recognised name and will not be part of the game."));
                }
            }

            ((List<IRoom>)game.Rooms).Sort();

            int roomCount = reader.ReadInt32();
            for (int i = 0; i < roomCount; i++)
            {
                string roomDescription = ReadNullTerminatedString(reader);
                if (rooms.ContainsKey(i))
                {
                    rooms[i].Description = roomDescription;
                }
            }
        }
Esempio n. 38
0
 public SpeechOnlyProcessor(Game game, CompileMessages errors, bool makesChanges, bool processHotspotAndObjectDescriptions,
                            Dictionary <string, FunctionCallType> speechableFunctionCalls)
     : base(game, errors, makesChanges, processHotspotAndObjectDescriptions)
 {
     _speechableFunctionCalls = speechableFunctionCalls;
 }
Esempio n. 39
0
        public override bool Build(CompileMessages errors, bool forceRebuild)
        {
            if (!base.Build(errors, forceRebuild)) return false;
            if (!CheckPluginsHaveSharedLibraries())
            {
                errors.Add(new CompileError("Could not build for Linux due to missing plugins."));
                return false;
            }
            foreach (string fileName in Directory.GetFiles(Path.Combine(AGSEditor.OUTPUT_DIRECTORY, AGSEditor.DATA_OUTPUT_DIRECTORY)))
            {
                if ((!fileName.EndsWith(".dll", StringComparison.OrdinalIgnoreCase)) &&
                    (!Path.GetFileName(fileName).Equals("winsetup.exe", StringComparison.OrdinalIgnoreCase)) &&
                    (!Path.GetFileName(fileName).Equals(AGSEditor.CONFIG_FILE_NAME, StringComparison.OrdinalIgnoreCase)))
                {
                    Utilities.CreateHardLink(GetCompiledPath(LINUX_DATA_DIR, Path.GetFileName(fileName)), fileName, true);
                }
            }
            // Update config file with current game parameters
            Factory.AGSEditor.WriteConfigFile(GetCompiledPath(LINUX_DATA_DIR));

            foreach (KeyValuePair<string, string> pair in GetRequiredLibraryPaths())
            {
                string fileName = pair.Value;
                if (!fileName.EndsWith(pair.Key)) fileName = Path.Combine(fileName, pair.Key);
                string folderName = null;
                if ((!fileName.EndsWith("ags32")) && (!fileName.EndsWith("ags64")))
                {
                    // the engine files belong in the LINUX_DATA_DIR, but the other libs
                    // should have lib32 or lib64 subdirectories as part of their name
                    folderName = Path.GetFileName(Path.GetDirectoryName(fileName).TrimEnd(Path.DirectorySeparatorChar));
                }
                Utilities.CreateHardLink(GetCompiledPath(LINUX_DATA_DIR, folderName, Path.GetFileName(fileName)),
                    fileName, true);
            }
            string linuxDataLib32Dir = GetCompiledPath(LINUX_DATA_DIR, LINUX_LIB32_DIR);
            string linuxDataLib64Dir = GetCompiledPath(LINUX_DATA_DIR, LINUX_LIB64_DIR);
            string editorLinuxDir = Path.Combine(Factory.AGSEditor.EditorDirectory, LINUX_DIR);
            string editorLinuxLib32Dir = Path.Combine(editorLinuxDir, LINUX_LIB32_DIR);
            string editorLinuxLib64Dir = Path.Combine(editorLinuxDir, LINUX_LIB64_DIR);
            foreach (string soName in _plugins)
            {
                Utilities.CreateHardLink(Path.Combine(linuxDataLib32Dir, soName),
                    Path.Combine(editorLinuxLib32Dir, soName), true);
                Utilities.CreateHardLink(Path.Combine(linuxDataLib64Dir, soName),
                    Path.Combine(editorLinuxLib64Dir, soName), true);
            }
            string scriptFileName = GetCompiledPath(Factory.AGSEditor.BaseGameFileName.Replace(" ", "")); // strip whitespace from script name
            string scriptText =
            @"#!/bin/sh
            SCRIPTPATH=""$(dirname ""$(readlink -f $0)"")""

            if test ""x$@"" = ""x-h"" -o ""x$@"" = ""x--help""
              then
            echo ""Usage:"" ""$(basename ""$(readlink -f $0)"")"" ""[<ags options>]""
            echo """"
            fi

            if test $(uname -m) = x86_64
              then" + GetSymLinkScriptForEachPlugin(true) +
            @"
              else" + GetSymLinkScriptForEachPlugin(false) +
            @"
            fi
            ";
            scriptText = scriptText.Replace("\r\n", "\n"); // make sure script has UNIX line endings
            FileStream stream = File.Create(scriptFileName);
            byte[] bytes = Encoding.UTF8.GetBytes(scriptText);
            stream.Write(bytes, 0, bytes.Length);
            stream.Close();
            return true;
        }
Esempio n. 40
0
        private SpeechLipSyncLine CompilePAMFile(string fileName, CompileMessages errors)
        {
            SpeechLipSyncLine syncDataForThisFile = new SpeechLipSyncLine();

            syncDataForThisFile.FileName = Path.GetFileNameWithoutExtension(fileName);

            string thisLine;
            bool   inMainSection = false;
            int    lineNumber    = 0;

            StreamReader sr = new StreamReader(fileName);

            while ((thisLine = sr.ReadLine()) != null)
            {
                lineNumber++;
                if (thisLine.ToLower().StartsWith("[speech]"))
                {
                    inMainSection = true;
                    continue;
                }
                if (inMainSection)
                {
                    if (thisLine.TrimStart().StartsWith("["))
                    {
                        // moved onto another section
                        break;
                    }
                    if (thisLine.IndexOf(':') > 0)
                    {
                        string[] parts = thisLine.Split(':');
                        // Convert from Pamela XPOS into milliseconds
                        int    milliSeconds = ((Convert.ToInt32(parts[0]) / 15) * 1000) / 24;
                        string phenomeCode  = parts[1].Trim().ToUpper();
                        int    frameID      = FindFrameNumberForPhenome(phenomeCode);
                        if (frameID < 0)
                        {
                            string friendlyFileName = Path.GetFileName(fileName);
                            errors.Add(new CompileError("No frame found to match phenome code '" + phenomeCode + "'", friendlyFileName, lineNumber));
                        }
                        else
                        {
                            syncDataForThisFile.Phenomes.Add(new SpeechLipSyncPhenome(milliSeconds, (short)frameID));
                        }
                    }
                }
            }
            sr.Close();
            syncDataForThisFile.Phenomes.Sort();

            // The PAM file contains start times: Convert to end times
            for (int i = 0; i < syncDataForThisFile.Phenomes.Count - 1; i++)
            {
                syncDataForThisFile.Phenomes[i].EndTimeOffset = syncDataForThisFile.Phenomes[i + 1].EndTimeOffset;
            }

            if (syncDataForThisFile.Phenomes.Count > 1)
            {
                syncDataForThisFile.Phenomes[syncDataForThisFile.Phenomes.Count - 1].EndTimeOffset = syncDataForThisFile.Phenomes[syncDataForThisFile.Phenomes.Count - 2].EndTimeOffset + 1000;
            }

            return(syncDataForThisFile);
        }
Esempio n. 41
0
        private void CompilePAMFiles(CompileMessages errors)
        {
            List<SpeechLipSyncLine> lipSyncDataLines = new List<SpeechLipSyncLine>();

            foreach (string fileName in Utilities.GetDirectoryFileList(Directory.GetCurrentDirectory(), PAM_FILE_FILTER))
            {
                lipSyncDataLines.Add(CompilePAMFile(fileName, errors));
            }

            if (File.Exists(LIP_SYNC_DATA_OUTPUT))
            {
                File.Delete(LIP_SYNC_DATA_OUTPUT);
            }

            if ((!errors.HasErrors) && (lipSyncDataLines.Count > 0))
            {
                BinaryWriter bw = new BinaryWriter(new FileStream(LIP_SYNC_DATA_OUTPUT, FileMode.Create, FileAccess.Write));
                bw.Write((int)4);
                bw.Write(lipSyncDataLines.Count);

                foreach (SpeechLipSyncLine line in lipSyncDataLines)
                {
                    bw.Write((short)line.Phenomes.Count);

                    byte[] fileNameBytes = Encoding.Default.GetBytes(line.FileName);
                    byte[] paddedFileNameBytes = new byte[14];
                    Array.Copy(fileNameBytes, paddedFileNameBytes, fileNameBytes.Length);
                    paddedFileNameBytes[fileNameBytes.Length] = 0;
                    bw.Write(paddedFileNameBytes);

                    for (int i = 0; i < line.Phenomes.Count; i++)
                    {
                        bw.Write((int)line.Phenomes[i].EndTimeOffset);
                    }
                    for (int i = 0; i < line.Phenomes.Count; i++)
                    {
                        bw.Write((short)line.Phenomes[i].Frame);
                    }
                }

                bw.Close();
            }
        }
Esempio n. 42
0
        private void RunPreCompilationChecks(CompileMessages errors)
        {
            if ((_game.LipSync.Type == LipSyncType.PamelaVoiceFiles) &&
                (_game.Settings.SpeechStyle == SpeechStyle.Lucasarts))
            {
                errors.Add(new CompileError("Voice lip-sync cannot be used with Lucasarts-style speech"));
            }

            if ((_game.Settings.EnhancedSaveGames) &&
                (_game.Settings.SaveGameFileExtension == string.Empty))
            {
                errors.Add(new CompileError("Enhanced Save Games are enabled but no file extension is specified"));
            }

            if (_game.PlayerCharacter == null)
            {
                errors.Add(new CompileError("No character has been set as the player character"));
            }
            else if (_game.FindRoomByID(_game.PlayerCharacter.StartingRoom) == null)
            {
                errors.Add(new CompileError("The game is set to start in room " + _game.PlayerCharacter.StartingRoom + " which does not exist"));
            }

            if ((_game.Settings.GraphicsDriver == GraphicsDriver.D3D9) &&
                (_game.Settings.ColorDepth == GameColorDepth.Palette))
            {
                errors.Add(new CompileError("Direct3D graphics driver does not support 256-colour games"));
            }

            if ((_game.Settings.ColorDepth == GameColorDepth.Palette) &&
                (_game.Settings.RoomTransition == RoomTransitionStyle.CrossFade))
            {
                errors.Add(new CompileError("You cannot use the CrossFade room transition with 256-colour games"));
            }

            if ((_game.Settings.DialogOptionsGUI < 0) ||
                (_game.Settings.DialogOptionsGUI >= _game.GUIs.Count))
            {
                if (_game.Settings.DialogOptionsGUI != 0)
                {
                    errors.Add(new CompileError("Invalid GUI number set for Dialog Options GUI"));
                }
            }

            foreach (Character character in _game.Characters)
            {
                AGS.Types.View view = _game.FindViewByID(character.NormalView);
                if (view == null)
                {
                    errors.Add(new CompileError("Character " + character.ID + " (" + character.RealName + ") has invalid normal view."));
                }
                else
                {
                    EnsureViewHasAtLeast4LoopsAndAFrameInLeftRightLoops(view);
                }
            }

            foreach (GUI gui in _game.GUIs)
            {
                if (gui is NormalGUI)
                {
                    if ((((NormalGUI)gui).Width > _game.MinRoomWidth) ||
                        (((NormalGUI)gui).Height > _game.MinRoomHeight))
                    {
                        errors.Add(new CompileWarning("GUI " + gui.Name + " is larger than the screen size and may cause errors in the game."));
                    }
                }
            }

            Dictionary<string, AGS.Types.View> viewNames = new Dictionary<string, AGS.Types.View>();
            EnsureViewNamesAreUnique(_game.RootViewFolder, viewNames, errors);

            foreach (AudioClip clip in _game.RootAudioClipFolder.GetAllAudioClipsFromAllSubFolders())
            {
                if (!File.Exists(clip.CacheFileName))
                {
                    errors.Add(new CompileError("Audio file missing for " + clip.ScriptName + ": " + clip.CacheFileName));
                }
            }

            if (!IsEnoughSpaceFreeOnDisk(MINIMUM_BYTES_FREE_TO_COMPILE))
            {
                errors.Add(new CompileError("There is not enough space on the disk."));
            }
        }
Esempio n. 43
0
        public override bool Build(CompileMessages errors, bool forceRebuild)
        {
            if (!base.Build(errors, forceRebuild))
            {
                return(false);
            }

            UseGradleDaemon = Factory.AGSEditor.Settings.AndroidBuildGradleDaemon;
            string andProjDir = GetAndroidProjectInCompiledDir();

            if (!IsProjectSane(errors))
            {
                return(false);
            }

            InstallSdkToolsIfNeeded();

            AndroidBuildFormat buildFormat = Factory.AGSEditor.CurrentGame.Settings.AndroidBuildFormat;
            string             appName     = GetFinalAppName();

            string assetsDir = GetAssetsDir();

            if (!Directory.Exists(assetsDir))
            {
                Directory.CreateDirectory(assetsDir);
            }
            ClearInvalidAssetDirIfNeeded();

            foreach (string fileName in Directory.GetFiles(Path.Combine(AGSEditor.OUTPUT_DIRECTORY, AGSEditor.DATA_OUTPUT_DIRECTORY)))
            {
                if ((File.GetAttributes(fileName) & (FileAttributes.Hidden | FileAttributes.System | FileAttributes.Temporary)) != 0)
                {
                    continue;
                }
                if ((!fileName.EndsWith(".dll", StringComparison.OrdinalIgnoreCase)) &&
                    (!Path.GetFileName(fileName).Equals("winsetup.exe", StringComparison.OrdinalIgnoreCase)) &&
                    (!Path.GetFileName(fileName).Equals(AGSEditor.CONFIG_FILE_NAME, StringComparison.OrdinalIgnoreCase)))
                {
                    string dest_filename = Path.Combine(assetsDir, Path.GetFileName(fileName));
                    Utilities.HardlinkOrCopy(dest_filename, fileName, true);
                }
            }

            // Update config file with current game parameters
            Factory.AGSEditor.WriteConfigFile(assetsDir);
            WriteAndroidCfg(assetsDir);

            foreach (KeyValuePair <string, string> pair in GetRequiredLibraryPaths())
            {
                string fileName  = pair.Key;
                string originDir = pair.Value;

                string dest = GetCompiledPath(ANDROID_DIR, Path.GetDirectoryName(fileName));

                if (!Directory.Exists(dest))
                {
                    // doesn't exist, let's create it
                    Directory.CreateDirectory(dest);
                }

                string destFile       = GetCompiledPath(ANDROID_DIR, fileName);
                string originFile     = Path.Combine(originDir, fileName);
                string destFileName   = Utilities.ResolveSourcePath(destFile);
                string sourceFileName = Utilities.ResolveSourcePath(originFile);

                if (fileName.EndsWith(".so"))
                {
                    Utilities.HardlinkOrCopy(destFile, originFile, true);
                }
                else
                {
                    File.Copy(sourceFileName, destFileName, true);
                }
            }

            string destDir = GetCompiledPath(ANDROID_DIR, "mygame");

            WriteProjectProperties(destDir);
            WriteLocalStaticProperties(destDir);
            WriteProjectXml(destDir);
            IconAssetType iconType = GetGameIconType();

            if (iconType != IconAssetType.NoIconFiles)
            {
                SetGameIcons(iconType, destDir);
            }

            GradleTasks gradleTask = GradleTasks.bundleRelease;

            if (buildFormat == AndroidBuildFormat.ApkEmbedded)
            {
                gradleTask = GradleTasks.assembleRelease;
            }

            if (!AndroidUtilities.RunGradlewTask(gradleTask, andProjDir, use_daemon: UseGradleDaemon))
            {
                errors.Add(new CompileError("There was an error running gradle to build the Android App."));
                return(false);
            }

            string appFinalFile     = GetFinalAppName();
            string appSrcDir        = GetOutputDir();
            string generatedAppFile = Path.Combine(appSrcDir, appFinalFile);

            if (File.Exists(generatedAppFile))
            {
                try
                {
                    Utilities.HardlinkOrCopy(GetCompiledPath(ANDROID_DIR, appFinalFile), generatedAppFile, true);
                }
                catch { }

                return(true);
            }

            errors.Add(new CompileError("Failed to generate Android App."));

            return(false);
        }
Esempio n. 44
0
        public override void CommandClick(string controlID)
        {
            if (controlID == COMMAND_NEW_ITEM)
            {
                IList <Translation> items   = _agsEditor.CurrentGame.Translations;
                Translation         newItem = new Translation(GetFreeNameForTranslation());
                newItem.Name = newItem.Name;
                items.Add(newItem);

                // Create a dummy placeholder file
                StreamWriter sw = new StreamWriter(newItem.FileName);
                sw.Close();
                newItem.LoadData();

                string newNodeID = "Trl" + (items.Count - 1);
                _guiController.ProjectTree.StartFromNode(this, TOP_LEVEL_COMMAND_ID);
                AddTreeLeafForTranslation(newNodeID, newItem);
                _guiController.ProjectTree.SelectNode(this, newNodeID);
                _agsEditor.CurrentGame.FilesAddedOrRemoved = true;

                StartRename(newItem, newNodeID);
            }
            else if (controlID == COMMAND_RENAME_ITEM)
            {
                StartRename(_itemRightClicked, _commandIDRightClicked);
            }
            else if (controlID == COMMAND_MAKE_DEFAULT)
            {
                if (_guiController.ShowQuestion("This command will replace all the text in your game with the translations in this file. This means that your current default language will be lost in the process.\n\nAdditionally, all your translations will be updated to contain this translation as the source text.\n\nAre you really sure you want to continue?", MessageBoxIcon.Warning) == DialogResult.Yes)
                {
                    ReplaceGameTextWithTranslation(_itemRightClicked);
                }
            }
            else if (controlID == COMMAND_UPDATE_SOURCE)
            {
                List <Translation> translations = new List <Translation>();
                translations.Add(_itemRightClicked);
                UpdateTranslations(translations);
            }
            else if (controlID == COMMAND_UPDATE_ALL)
            {
                UpdateTranslations(_agsEditor.CurrentGame.Translations);
            }
            else if (controlID == COMMAND_COMPILE)
            {
                CompileMessages errors = new CompileMessages();
                CompileTranslation(_itemRightClicked, errors);
                if (errors.Count > 0)
                {
                    _guiController.ShowMessage(errors[0].Message, MessageBoxIcon.Warning);
                }
                else
                {
                    _guiController.ShowMessage("Translation compiled successfully.", MessageBoxIcon.Information);
                }
            }
            else if (controlID == COMMAND_DELETE_ITEM)
            {
                if (_guiController.ShowQuestion("Are you sure you want to delete this translation?") == DialogResult.Yes)
                {
                    string removing = _itemRightClicked.FileName;

                    /*                    if (_documents.ContainsKey(_itemRightClicked))
                     *                  {
                     *                      _guiController.RemovePaneIfExists(_documents[_itemRightClicked]);
                     *                      _documents.Remove(_itemRightClicked);
                     *                  }*/
                    _agsEditor.CurrentGame.Translations.Remove(_itemRightClicked);
                    _agsEditor.CurrentGame.FilesAddedOrRemoved = true;

                    if (File.Exists(_itemRightClicked.FileName))
                    {
                        _agsEditor.DeleteFileOnDiskAndSourceControl(_itemRightClicked.FileName);
                    }
                    RePopulateTreeView();
                    TranslationListTypeConverter.SetTranslationsList(_agsEditor.CurrentGame.Translations);
                }
            }
            else
            {
                if (controlID != TOP_LEVEL_COMMAND_ID)
                {
                    Translation translation = _agsEditor.CurrentGame.Translations[Convert.ToInt32(controlID.Substring(3))];
                    _guiController.ShowMessage("Currently you cannot edit translations within the editor. Load the file " + translation.FileName + " into your favourite text editor to do your translation work.", MessageBoxIcon.Information);

                    /*                    if (!_documents.ContainsKey(chosenFont))
                     *                  {
                     *                      Dictionary<string, object> list = new Dictionary<string, object>();
                     *                      list.Add(chosenFont.Name + " (Font " + chosenFont.ID + ")", chosenFont);
                     *
                     *                      _documents.Add(chosenFont, new ContentDocument(new FontEditor(chosenFont), chosenFont.WindowTitle, this, list));
                     *                      _documents[chosenFont].SelectedPropertyGridObject = chosenFont;
                     *                  }
                     *                  _guiController.AddOrShowPane(_documents[chosenFont]);*/
                }
            }
        }