// Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved // Please see LICENSE.md in repository root for license information // https://github.com/AtomicGameEngine/AtomicGameEngine #include #include "AtomicEditor.h" #include #include "../AEEditor.h" #include "../AEPreferences.h" #include "BuildSystem.h" #include "AndroidProjectGenerator.h" namespace AtomicEditor { AndroidProjectGenerator::AndroidProjectGenerator(Context* context) : Object(context) { BuildSystem* buildSystem = GetSubsystem(); buildSettings_ = buildSystem->GetBuildSettings()->GetAndroidSettings(); } AndroidProjectGenerator::~AndroidProjectGenerator() { } bool AndroidProjectGenerator::Generate() { if (!GenerateAndroidManifest()) return false; if (!GenerateStringXML()) return false; if (!GenerateLocalProperties()) return false; if (!GenerateProjectProperties()) return false; if (!GenerateActivitySource()) return false; return true; } bool AndroidProjectGenerator::GenerateActivitySource() { if (!buildSettings_.package.Length()) { errorText_ = "Invalid Package Name"; return false; } Vector elements = buildSettings_.package.Split('.'); String path; path.Join(elements, "/"); path = buildPath_ + "/src/" + path; Poco::File dirs(path.CString()); dirs.createDirectories(); if (!dirs.exists()) { errorText_ = "Unable to create "; return false; } String source; source.AppendWithFormat("package %s;\n", buildSettings_.package.CString()); source += "import org.libsdl.app.SDLActivity;\n"; source += "public class AtomicGameEngine extends SDLActivity {\n"; source += "}\n"; File file(context_, path + "/AtomicGameEngine.java", FILE_WRITE); if (!file.IsOpen()) return false; file.Write(source.CString(), source.Length()); return true; } bool AndroidProjectGenerator::GenerateLocalProperties() { Editor* editor = GetSubsystem(); String sdkPath = editor->GetPreferences()->GetAndroidSDKPath(); if (!sdkPath.Length()) { errorText_ = "Invalid Android SDK Path"; return false; } String props; props.AppendWithFormat("sdk.dir=%s", sdkPath.CString()); File file(context_, buildPath_ + "/local.properties", FILE_WRITE); if (!file.IsOpen()) return false; file.Write(props.CString(), props.Length()); return true; } bool AndroidProjectGenerator::GenerateProjectProperties() { String apiString = buildSettings_.targetSDKVersion; if (!apiString.Length()) { errorText_ = "Invalid Android API"; return false; } String props; props.AppendWithFormat("target=%s", apiString.CString()); File file(context_, buildPath_ + "/project.properties", FILE_WRITE); if (!file.IsOpen()) return false; file.Write(props.CString(), props.Length()); return true; } bool AndroidProjectGenerator::GenerateStringXML() { if (!buildSettings_.appName.Length()) { errorText_ = "Invalid App Name"; return false; } String strings = "\n"; strings += "\n"; strings.AppendWithFormat("%s\n", buildSettings_.appName.CString()); strings += "\n"; File file(context_, buildPath_ + "/res/values/strings.xml", FILE_WRITE); if (!file.IsOpen()) return false; file.Write(strings.CString(), strings.Length()); return true; } bool AndroidProjectGenerator::GenerateAndroidManifest() { if (!buildSettings_.package.Length()) { errorText_ = "Invalid Package Name"; return false; } buildSettings_.activityName = "AtomicGameEngine"; if (!buildSettings_.activityName.Length()) { errorText_ = "Invalid Activity Name"; return false; } String manifest = "\n"; manifest += "\n"; manifest += "\n"; manifest += "\n"; manifest += "\n"; manifest += "\n"; manifest.AppendWithFormat("\n"; manifest += "\n"; manifest += "\n"; manifest += "\n"; manifest += "\n"; manifest += "\n"; manifest += "\n"; manifest += "\n"; File file(context_, buildPath_ + "/AndroidManifest.xml", FILE_WRITE); if (!file.IsOpen()) return false; file.Write(manifest.CString(), manifest.Length()); return true; } } /* */