Esempio n. 1
0
        private static void ResolveInternalLibs(AN_AndroidBuildRequirements requirements)
        {
            List <string> libsToAdd    = new List <string>();
            List <string> libsToRemove = new List <string>();


            List <string> internalLibs = SA_AssetDatabase.FindAssetsWithExtentions(AN_Settings.ANDROID_INTERNAL_FOLDER);

            foreach (var lib in internalLibs)
            {
                string libName = SA_AssetDatabase.GetFileName(lib);
                if (!requirements.HasInternalLib(libName))
                {
                    libsToRemove.Add(libName);
                }
            }

            foreach (var lib in requirements.InternalLibs)
            {
                string libPath = AN_Settings.ANDROID_INTERNAL_FOLDER + lib;
                if (!SA_AssetDatabase.IsFileExists(libPath))
                {
                    libsToAdd.Add(lib);
                }
            }

            SA_PluginsEditor.UninstallLibs(AN_Settings.ANDROID_INTERNAL_FOLDER, libsToRemove);
            SA_PluginsEditor.InstallLibs(AN_Settings.ANDROID_INTERNAL_FOLDER_DISABLED, AN_Settings.ANDROID_INTERNAL_FOLDER, libsToAdd);
        }
Esempio n. 2
0
        public static void EnableLibsAtPath(string path)
        {
            List <string> files = SA_AssetDatabase.FindAssetsWithExtentions(path);

            for (int i = 0; i < files.Count; i++)
            {
                var file = files[i];
                //Make sure this is not a folder
                if (SA_AssetDatabase.IsValidFolder(file))
                {
                    continue;
                }


                if (SA_AssetDatabase.GetExtension(file).Equals(DISABLED_LIB_EXTENSION))
                {
                    string newFileName = file.Replace(DISABLED_LIB_EXTENSION, string.Empty);

                    string fileName = SA_AssetDatabase.GetFileName(newFileName);

                    float progress = (float)(i + 1) / (float)files.Count;
                    EditorUtility.DisplayProgressBar("Stan's Assets.", "Installing: " + fileName, progress);


                    SA_AssetDatabase.MoveAsset(file, newFileName);
                    SA_AssetDatabase.ImportAsset(newFileName);
                }
            }

            EditorUtility.ClearProgressBar();
        }
Esempio n. 3
0
        private ISN_CNContactsResult CreateFakeResult()
        {
            TextAsset            editorData = SA_AssetDatabase.LoadAssetAtPath <TextAsset>(ISN_Settings.CONTACTS_API_LOCATION + "ISN_CNContactsEditorResponce.txt");
            ISN_CNContactsResult result     = JsonUtility.FromJson <ISN_CNContactsResult>(editorData.text);

            return(result);
        }
Esempio n. 4
0
        private static List <string> ReadDependencies()
        {
            var result = new List <string>();

            try {
                if (SA_AssetDatabase.IsFileExists(AN_Settings.DEPENDENCIES_FILE_PATH))
                {
                    var doc = new XmlDocument();
                    doc.Load(SA_PathUtil.ConvertRelativeToAbsolutePath(AN_Settings.DEPENDENCIES_FILE_PATH));
                    var xnList = doc.SelectNodes("dependencies/androidPackages/androidPackage");

                    foreach (XmlNode xn in xnList)
                    {
                        var spec = xn.Attributes["spec"].Value;
                        result.Add(spec);
                    }
                }
            } catch (Exception ex) {
                AN_Logger.LogError("Error reading AN_Dependencies");
                AN_Logger.LogError(AN_Settings.DEPENDENCIES_FILE_PATH + " filed: " + ex.Message);
            }



            return(result);
        }
Esempio n. 5
0
        public static void DisableLibstAtPath(string path)
        {
            List <string> files = SA_AssetDatabase.FindAssetsWithExtentions(path);

            for (int i = 0; i < files.Count; i++)
            {
                var filePath = files[i];

                //Make sure this is not a folder
                if (SA_AssetDatabase.IsValidFolder(filePath))
                {
                    continue;
                }

                //Already disabled
                if (SA_AssetDatabase.GetExtension(filePath).Equals(DISABLED_LIB_EXTENSION))
                {
                    continue;
                }

                string newFilePath;
                newFilePath = filePath + DISABLED_LIB_EXTENSION;


                float  progress = (float)(i + 1) / (float)files.Count;
                string fileName = SA_AssetDatabase.GetFileName(newFilePath);
                EditorUtility.DisplayProgressBar("Stan's Assets.", "Packing: " + fileName, progress);
                SA_AssetDatabase.MoveAsset(filePath, newFilePath);
                SA_AssetDatabase.ImportAsset(newFilePath);
            }

            EditorUtility.ClearProgressBar();
        }
Esempio n. 6
0
 public static void UninstallLibFolder(string path)
 {
     if (SA_AssetDatabase.IsDirectoryExists(path))
     {
         EditorUtility.DisplayProgressBar("Stan's Assets.", "Uninstalling: " + path, 1);
         SA_AssetDatabase.DeleteAsset(path);
         EditorUtility.ClearProgressBar();
     }
 }
        //--------------------------------------
        //  Public Methods
        //--------------------------------------

        public static void ProcessAssets()
        {
            List <string> projectLibs = SA_AssetDatabase.FindAssetsWithExtentions("Assets", ".dll");

            foreach (var lib in projectLibs)
            {
                ProcessAssetImport(lib);
            }
        }
        private void ValidateAssets <T>(List <T> assets, string requiredLocation, string requiredExtension) where T : Object
        {
            //Let's make sure we aren't missing assets under requiredLocation
            var assetPaths = SA_AssetDatabase.FindAssetsWithExtentions(requiredLocation, requiredExtension);

            foreach (var assetPath in assetPaths)
            {
                var assetExtension = SA_PathUtil.GetExtension(assetPath);
                if (assetExtension.Equals(requiredExtension))
                {
                    var file = (T)AssetDatabase.LoadAssetAtPath(assetPath, typeof(T));
                    if (!assets.Contains(file))
                    {
                        assets.Add(file);
                        return;
                    }
                }
            }

            for (var i = 0; i < assets.Count; i++)
            {
                var asset = assets[i];
                if (asset == null)
                {
                    //We do not allow null element's unless this is a last element
                    if (i != assets.Count - 1)
                    {
                        assets.Remove(asset);
                        return;
                    }
                    continue;
                }

                if (!HasValidExtension(asset, requiredExtension))
                {
                    EditorGUILayout.HelpBox(asset.name + " need to be in *" + requiredExtension + " format.", MessageType.Error);
                    continue;
                }

                if (!SA_AssetDatabase.IsAssetInsideFolder(asset, requiredLocation))
                {
                    EditorGUILayout.HelpBox(asset.name + " has to be inside: \n" + requiredLocation, MessageType.Error);
                    using (new SA_GuiBeginHorizontal()) {
                        GUILayout.FlexibleSpace();
                        var move = GUILayout.Button("Move", EditorStyles.miniButton);
                        if (move)
                        {
                            var currentPath = AssetDatabase.GetAssetPath(asset);
                            var assetName   = SA_AssetDatabase.GetFileName(currentPath);
                            var newPath     = requiredLocation + assetName;
                            SA_AssetDatabase.MoveAsset(currentPath, newPath);
                        }
                    }
                }
            }
        }
Esempio n. 9
0
        private static void ResolveBinaryLibs(AN_AndroidBuildRequirements requirements)
        {
            if (AN_Settings.Instance.UseUnityJarResolver)
            {
                AN_Dependencies.Resolve(requirements.BinaryDependencies);
                SA_AssetDatabase.DeleteAsset(AN_Settings.ANDROID_MAVEN_FOLDER);
            }
            else
            {
                AN_Dependencies.Resolve(new List <AN_BinaryDependency>());


                List <string> repositorysToAdd    = new List <string>();
                List <string> repositorysToRemove = new List <string>();

                List <string> mavenLibs = SA_AssetDatabase.FindAssetsWithExtentions(AN_Settings.ANDROID_MAVEN_FOLDER);
                foreach (var lib in mavenLibs)
                {
                    //we are only interested in folder, we also assume all folders are located inside a root folder
                    if (!SA_AssetDatabase.IsValidFolder(lib))
                    {
                        continue;
                    }

                    string libName = SA_AssetDatabase.GetFileName(lib);
                    if (!requirements.HasBinaryDependency(libName))
                    {
                        repositorysToRemove.Add(libName);
                    }
                }

                foreach (var dep in requirements.BinaryDependencies)
                {
                    string libPath = AN_Settings.ANDROID_MAVEN_FOLDER + dep.GetLocalRepositoryName();
                    if (!SA_AssetDatabase.IsDirectoryExists(libPath))
                    {
                        string localRepositoryName = dep.GetLocalRepositoryName();
                        if (!repositorysToAdd.Contains(localRepositoryName))
                        {
                            repositorysToAdd.Add(localRepositoryName);
                        }
                    }
                }

                SA_PluginsEditor.UninstallLibs(AN_Settings.ANDROID_MAVEN_FOLDER, repositorysToRemove);

                foreach (var lib in repositorysToAdd)
                {
                    string source      = AN_Settings.ANDROID_MAVEN_FOLDER_DISABLED + lib;
                    string destination = AN_Settings.ANDROID_MAVEN_FOLDER + lib;
                    SA_PluginsEditor.InstallLibFolder(source, destination);
                }
            }
        }
Esempio n. 10
0
        //--------------------------------------
        // Search and reset state for Jar Resolver
        //--------------------------------------

        internal static void ProcessAssets()
        {
            var projectLibs = SA_AssetDatabase.FindAssetsWithExtentions("Assets", ".dll");

            foreach (var lib in projectLibs)
            {
                if (ProcessAssetImport(lib))
                {
                    return;
                }
            }
            UpdateJarResolverState(false, null);
        }
Esempio n. 11
0
        protected override void AddNotificationRequestInternal(UM_NotificationRequest request, Action <SA_Result> callback)
        {
            try
            {
                var builder = new AN_NotificationCompat.Builder();
                builder.SetContentTitle(request.Content.Title);
                builder.SetContentText(request.Content.Body);
                if (request.Content.BadgeNumber != -1)
                {
                    builder.SetNumber(request.Content.BadgeNumber);
                }

                if (string.IsNullOrEmpty(request.Content.SoundName))
                {
                    builder.SetDefaults(AN_Notification.DEFAULT_LIGHTS | AN_Notification.DEFAULT_SOUND);
                }
                else
                {
                    string soundName = SA_AssetDatabase.GetAssetNameWithoutExtension(request.Content.SoundName);
                    builder.SetSound(soundName);
                }


                if (!string.IsNullOrEmpty(request.Content.IconName))
                {
                    string iconName = SA_AssetDatabase.GetAssetNameWithoutExtension(request.Content.IconName);
                    builder.SetSmallIcon(iconName);
                }

                if (request.Content.LargeIcon != null)
                {
                    builder.SetLargeIcon(request.Content.LargeIcon);
                }


                UM_TimeIntervalNotificationTrigger timeIntervalTrigger = (UM_TimeIntervalNotificationTrigger)request.Trigger;

                var trigger = new AN_AlarmNotificationTrigger();
                trigger.SetDate(TimeSpan.FromSeconds(timeIntervalTrigger.Interval));
                trigger.SerRepeating(timeIntervalTrigger.Repeating);

                var android_request = new AN_NotificationRequest(request.Identifier, builder, trigger);

                AN_NotificationManager.Schedule(android_request);

                callback.Invoke(new SA_Result());
            } catch (Exception ex) {
                var error = new SA_Error(100, ex.Message);
                callback.Invoke(new SA_Result(error));
            }
        }
        private bool HasValidExtension(Object asset, string requiredExtension)
        {
            var assetPath      = SA_AssetDatabase.GetAssetPath(asset);
            var assetExtension = SA_PathUtil.GetExtension(assetPath);

            if (assetExtension.Equals(requiredExtension))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 13
0
        public void SaveManifest()
        {
#if !(UNITY_WP8 || UNITY_METRO)
            if (!SA_AssetDatabase.IsFileExists(m_path))
            {
                string m_folderPath = SA_PathUtil.GetDirectoryPath(m_path);
                if (!SA_AssetDatabase.IsValidFolder(m_folderPath))
                {
                    SA_AssetDatabase.CreateFolder(m_folderPath);
                }
            }

            XmlDocument newDoc = new XmlDocument();
            //Create XML header
            XmlNode docNode = newDoc.CreateXmlDeclaration("1.0", "UTF-8", null);
            newDoc.AppendChild(docNode);

            XmlElement child = newDoc.CreateElement("manifest");
            child.SetAttribute("xmlns:android", "http://schemas.android.com/apk/res/android");
            child.SetAttribute("xmlns:tools", "http://schemas.android.com/tools");
            child.SetAttribute("package", "com.stansassets.androidnative");

            m_template.ToXmlElement(newDoc, child);
            newDoc.AppendChild(child);


            newDoc.Save(SA_PathUtil.ConvertRelativeToAbsolutePath(m_path));

            //Replace 'android___' pattern with 'android:'
            TextReader reader      = new StreamReader(SA_PathUtil.ConvertRelativeToAbsolutePath(m_path));
            string     src         = reader.ReadToEnd();
            string     pattern     = @"android___";
            string     replacement = "android:";
            Regex      regex       = new Regex(pattern);
            src = regex.Replace(src, replacement);

            pattern     = @"tools___";
            replacement = "tools:";
            regex       = new Regex(pattern);
            src         = regex.Replace(src, replacement);
            reader.Close();

            TextWriter writer = new StreamWriter(SA_PathUtil.ConvertRelativeToAbsolutePath(m_path));
            writer.Write(src);
            writer.Close();

            AssetDatabase.Refresh();
#endif
        }
        //--------------------------------------
        // Static
        //--------------------------------------

        public static void Resolve()
        {
            var versionUpdated = AN_Settings.UpdateVersion(AN_Settings.FormattedVersion) && !SA_PluginTools.IsDevelopmentMode;
            var requirements   = new AN_AndroidBuildRequirements();

            if (versionUpdated)
            {
                SA_AssetDatabase.DeleteAsset(AN_Settings.ANDROID_INTERNAL_FOLDER);
                SA_AssetDatabase.DeleteAsset(AN_Settings.ANDROID_MAVEN_FOLDER);
            }

            foreach (var resolver in Resolvers)
            {
                resolver.Run(requirements);
            }
            Resolve(requirements);
        }
Esempio n. 15
0
        private static void ResolveXMLConfig(List <string> dependencies)
        {
            //Clean up file if we have no Dependencies
            if (dependencies.Count == 0)
            {
                if (SA_AssetDatabase.IsDirectoryExists(AN_Settings.DEPENDENCIES_FOLDER))
                {
                    SA_AssetDatabase.DeleteAsset(AN_Settings.DEPENDENCIES_FOLDER);
                }
                s_activeDependencies = new List <string>();
                return;
            }

            if (IsEqualsToActiveDependencies(dependencies))
            {
                return;
            }

            if (!SA_AssetDatabase.IsValidFolder(AN_Settings.DEPENDENCIES_FOLDER))
            {
                SA_AssetDatabase.CreateFolder(AN_Settings.DEPENDENCIES_FOLDER);
            }


            var doc = new XmlDocument();
            var dependenciesElement    = doc.CreateElement("dependencies");
            var androidPackagesElement = doc.CreateElement("androidPackages");


            foreach (var dependency in dependencies)
            {
                var androidPackage = doc.CreateElement("androidPackage");

                var spec = doc.CreateAttribute("spec");
                spec.Value = dependency;
                androidPackage.Attributes.Append(spec);

                androidPackagesElement.AppendChild(androidPackage);
            }

            dependenciesElement.AppendChild(androidPackagesElement);
            doc.AppendChild(dependenciesElement);
            doc.Save(SA_PathUtil.ConvertRelativeToAbsolutePath(AN_Settings.DEPENDENCIES_FILE_PATH));
            SA_AssetDatabase.ImportAsset(AN_Settings.DEPENDENCIES_FILE_PATH);
            s_activeDependencies = ReadDependencies();
        }
Esempio n. 16
0
        public static void SaveManifest()
        {
#if !(UNITY_WP8 || UNITY_METRO)
            if (!SA_AssetDatabase.IsFileExists(AMM_Settings.MANIFEST_FILE_PATH))
            {
                //Make sure we have a folder
                if (!SA_AssetDatabase.IsValidFolder(AMM_Settings.MANIFEST_FOLDER_PATH))
                {
                    SA_AssetDatabase.CreateFolder(AMM_Settings.MANIFEST_FOLDER_PATH);
                }
            }

            XmlDocument newDoc = new XmlDocument();
            //Create XML header
            XmlNode docNode = newDoc.CreateXmlDeclaration("1.0", "UTF-8", null);
            newDoc.AppendChild(docNode);

            XmlElement child = newDoc.CreateElement("manifest");
            s_template.ToXmlElement(newDoc, child);
            newDoc.AppendChild(child);


            newDoc.Save(SA_PathUtil.ConvertRelativeToAbsolutePath(AMM_Settings.MANIFEST_FILE_PATH));

            //Replace 'android___' pattern with 'android:'
            TextReader reader      = new StreamReader(SA_PathUtil.ConvertRelativeToAbsolutePath(AMM_Settings.MANIFEST_FILE_PATH));
            string     src         = reader.ReadToEnd();
            string     pattern     = @"android___";
            string     replacement = "android:";
            Regex      regex       = new Regex(pattern);
            src = regex.Replace(src, replacement);

            pattern     = @"tools___";
            replacement = "tools:";
            regex       = new Regex(pattern);
            src         = regex.Replace(src, replacement);
            reader.Close();

            TextWriter writer = new StreamWriter(SA_PathUtil.ConvertRelativeToAbsolutePath(AMM_Settings.MANIFEST_FILE_PATH));
            writer.Write(src);
            writer.Close();

            AssetDatabase.Refresh();
    #endif
        }
Esempio n. 17
0
        //--------------------------------------
        //  Public Methods
        //--------------------------------------

        public static void ProcessAssets()
        {
            //We are loocking for folder
            List <string> projectFolders = SA_AssetDatabase.FindAssetsWithExtentions("Assets", "");

            foreach (var lib in projectFolders)
            {
                ProcessAssetImport(lib);
            }

            //We are loocking for dll libs
            List <string> projectLibs = SA_AssetDatabase.FindAssetsWithExtentions("Assets", ".dll");

            foreach (var lib in projectLibs)
            {
                ProcessAssetImport(lib);
            }
        }
Esempio n. 18
0
        public static void InstallLibFolder(string source, string destination)
        {
            if (!SA_AssetDatabase.IsDirectoryExists(source))
            {
                Debug.LogError("Can't find the source lib folder at path: " + source);
                return;
            }


            //Clean before install
            if (SA_AssetDatabase.IsDirectoryExists(destination))
            {
                SA_AssetDatabase.DeleteAsset(destination);
            }

            SA_AssetDatabase.CopyAsset(source, destination);
            EnableLibsAtPath(destination);
        }
Esempio n. 19
0
        public static void UninstallLibs(string path, List <string> libs)
        {
            for (int i = 0; i < libs.Count; i++)
            {
                var   lib      = libs[i];
                float progress = (float)(i + 1) / (float)libs.Count;
                EditorUtility.DisplayProgressBar("Stan's Assets.", "Uninstalling: " + lib, progress);

                string libPath = path + lib;
                if (SA_AssetDatabase.IsFileExists(libPath) || SA_AssetDatabase.IsDirectoryExists(libPath))
                {
                    SA_AssetDatabase.DeleteAsset(path + lib);
                }
                else
                {
                    Debug.LogWarning("There is no file to deleted at: " + libPath);
                }
            }

            EditorUtility.ClearProgressBar();
        }
        private Object DrawSoundField(Rect position, Object asset)
        {
            var color = GUI.color;

            if (asset != null)
            {
                if (!HasValidExtension(asset, k_RequiredSoundExtension))
                {
                    GUI.color = Color.red;
                }

                if (!SA_AssetDatabase.IsAssetInsideFolder(asset, AN_Settings.ANDROID_RAW_PATH))
                {
                    GUI.color = Color.red;
                }
            }

            var result = DrawObjectField(position, asset);

            GUI.color = color;
            return(result);
        }
Esempio n. 21
0
        public static void InstallLibs(string source, string destination, List <string> libs)
        {
            for (int i = 0; i < libs.Count; i++)
            {
                var    lib             = libs[i];
                string disabledLib     = lib + DISABLED_LIB_EXTENSION;
                string sourcePath      = source + disabledLib;
                string destinationPath = destination + lib;


                if (!SA_AssetDatabase.IsFileExists(sourcePath))
                {
                    Debug.LogError("Can't find the source lib folder at path: " + sourcePath);
                    continue;
                }

                float progress = (float)(i + 1) / (float)libs.Count;
                EditorUtility.DisplayProgressBar("Stan's Assets.", "Installing: " + lib, progress);

                SA_AssetDatabase.CopyAsset(sourcePath, destinationPath);
            }

            EditorUtility.ClearProgressBar();
        }
        public static void OnPostprocessBuild(BuildTarget target, string projectPath)
        {
            var pbxProjPath = PBXProject.GetPBXProjectPath(projectPath);


            PBXProject proj = new PBXProject();

            proj.ReadFromFile(pbxProjPath);
            string targetGuid = proj.TargetGuidByName("Unity-iPhone");


            RegisterAppLanguages();

            AddFlags(proj, targetGuid);
            AddLibraries(proj, targetGuid);
            AddFrameworks(proj, targetGuid, target);
            AddEmbededFrameworks(proj, targetGuid);
            AddPlistVariables(projectPath);
            ApplyBuildSettings(proj, targetGuid);
            CopyAssetFiles(proj, projectPath, targetGuid);
            AddShellScriptBuildPhase(proj, targetGuid);

            proj.WriteToFile(pbxProjPath);


            var capManager = new ProjectCapabilityManager(pbxProjPath, ISD_Settings.ENTITLEMENTS_FILE_NAME, "Unity-iPhone");

            AddCapabilities(proj, targetGuid, capManager);
            capManager.WriteToFile();



            //Some API simply does not work so on this block we are applying a workaround
            //after Unity deploy scrips has stopped working

            //Addons EmbededFrameworks
            foreach (var framework in ISD_Settings.Instance.EmbededFrameworks)
            {
                string contents    = File.ReadAllText(pbxProjPath);
                string pattern     = "(?<=Embed Frameworks)(?:.*)(\\/\\* " + framework.FileName + "\\ \\*\\/)(?=; };)";
                string oldText     = "/* " + framework.FileName + " */";
                string updatedText = "/* " + framework.FileName + " */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }";
                contents = Regex.Replace(contents, pattern, m => m.Value.Replace(oldText, updatedText));
                File.WriteAllText(pbxProjPath, contents);
            }


            var entitlementsPath = projectPath + "/" + ISD_Settings.ENTITLEMENTS_FILE_NAME;

            if (ISD_Settings.Instance.EntitlementsMode == ISD_EntitlementsGenerationMode.Automatic)
            {
                if (ISD_Settings.Instance.Capability.iCloud.Enabled)
                {
                    if (ISD_Settings.Instance.Capability.iCloud.keyValueStorage && !ISD_Settings.Instance.Capability.iCloud.iCloudDocument)
                    {
                        var entitlements = new PlistDocument();
                        entitlements.ReadFromFile(entitlementsPath);

                        var plistVariable = new PlistElementArray();
                        entitlements.root["com.apple.developer.icloud-container-identifiers"] = plistVariable;

                        entitlements.WriteToFile(entitlementsPath);
                    }
                }
            }
            else
            {
                if (ISD_Settings.Instance.EntitlementsFile != null)
                {
                    var    entitlementsContentPath = SA_AssetDatabase.GetAbsoluteAssetPath(ISD_Settings.Instance.EntitlementsFile);
                    string contents = File.ReadAllText(entitlementsContentPath);
                    File.WriteAllText(entitlementsPath, contents);
                }
                else
                {
                    Debug.LogWarning("ISD: EntitlementsMode set to Manual but no file provided");
                }
            }
        }
 public static void OverrideGamesIds(string data)
 {
     SA_FilesUtil.Write(AN_Settings.ANDROID_GAMES_IDS_FILE_PATH, data);
     SA_AssetDatabase.ImportAsset(AN_Settings.ANDROID_GAMES_IDS_FILE_PATH);
 }
Esempio n. 24
0
        /// <summary>
        /// Delete's asset instance
        /// </summary>
        public static void Delete()
        {
            string path = SA_AssetDatabase.GetAssetPath(Instance);

            SA_AssetDatabase.DeleteAsset(path);
        }
Esempio n. 25
0
 private static void SaveToAssetDatabase(T asset)
 {
     SA_AssetDatabase.CreateAsset(asset, SA_Config.STANS_ASSETS_SETTINGS_PATH + asset.GetType().Name + ".asset");
 }
Esempio n. 26
0
        private void ReadManifest(string manifestPath)
        {
            m_template = new AMM_Template();


            if (!SA_AssetDatabase.IsFileExists(manifestPath))
            {
                return;
            }

#if !(UNITY_WP8 || UNITY_METRO)
            //Read XML file
            XmlDocument doc = new XmlDocument();
            doc.Load(SA_PathUtil.ConvertRelativeToAbsolutePath(manifestPath));
            XmlNode rootNode = doc.DocumentElement;

            foreach (XmlAttribute attr in rootNode.Attributes)
            {
                m_template.SetValue(attr.Name, attr.Value);
            }

            foreach (XmlNode childNode in rootNode.ChildNodes)
            {
                if (!childNode.Name.Equals("application") &&
                    !childNode.Name.Equals("uses-permission") &&
                    !childNode.Name.Equals("#comment"))
                {
                    m_template.AddProperty(childNode.Name, AMM_Manager.ParseProperty(childNode));
                }
            }

            XmlNode applicationNode = null;
            foreach (XmlNode childNode in rootNode.ChildNodes)
            {
                if (childNode.Name.Equals("application"))
                {
                    applicationNode = childNode;
                    break;
                }
            }

            foreach (XmlAttribute attr in applicationNode.Attributes)
            {
                m_template.ApplicationTemplate.SetValue(attr.Name, attr.Value);
            }
            foreach (XmlNode childNode in applicationNode.ChildNodes)
            {
                if (!childNode.Name.Equals("#comment") &&
                    !childNode.Name.Equals("activity"))
                {
                    m_template.ApplicationTemplate.AddProperty(childNode.Name, AMM_Manager.ParseProperty(childNode));
                }
            }

            foreach (XmlNode childNode in applicationNode.ChildNodes)
            {
                if (childNode.Name.Equals("activity") &&
                    !childNode.Name.Equals("#comment"))
                {
                    string activityName = "";
                    if (childNode.Attributes["android:name"] != null)
                    {
                        activityName = childNode.Attributes["android:name"].Value;
                    }
                    else
                    {
                        Debug.LogWarning("Android Manifest contains activity tag without android:name attribute.");
                    }

                    XmlNode launcher   = null;
                    bool    isLauncher = false;
                    foreach (XmlNode actNode in childNode.ChildNodes)
                    {
                        if (actNode.Name.Equals("intent-filter"))
                        {
                            foreach (XmlNode intentNode in actNode.ChildNodes)
                            {
                                if (intentNode.Name.Equals("category"))
                                {
                                    if (intentNode.Attributes["android:name"].Value.Equals("android.intent.category.LAUNCHER"))
                                    {
                                        isLauncher = true;
                                        launcher   = actNode;
                                    }
                                }
                            }
                        }
                    }

                    AMM_ActivityTemplate activity = new AMM_ActivityTemplate(isLauncher, activityName);
                    foreach (XmlAttribute attr in childNode.Attributes)
                    {
                        activity.SetValue(attr.Name, attr.Value);
                    }

                    foreach (XmlNode actNode in childNode.ChildNodes)
                    {
                        if (!actNode.Name.Equals("#comment"))
                        {
                            if (actNode != launcher)
                            {
                                activity.AddProperty(actNode.Name, AMM_Manager.ParseProperty(actNode));
                            }
                        }
                    }

                    m_template.ApplicationTemplate.AddActivity(activity);
                }
            }

            //Load Manifest Permissions
            foreach (XmlNode node in rootNode.ChildNodes)
            {
                if (node.Name.Equals("uses-permission"))
                {
                    AMM_PropertyTemplate permission = new AMM_PropertyTemplate("uses-permission");
                    permission.SetValue("android:name", node.Attributes["android:name"].Value);
                    m_template.AddPermission(permission);
                }
            }
#endif
        }