2 * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 using System.Reflection;
20 using System.Runtime.Loader;
22 namespace Tizen.Runtime
24 public class Preloader
26 const string preloadPath = "/usr/share/dotnet.tizen/preload/";
27 public static void Preload()
29 string[] paths = Directory.GetFiles(preloadPath, "*.preload");
31 foreach (string path in paths)
33 // ex) Tizen.preload / 0A.Tizen.preload / A0.Tizen.preload / .0.Tizen.preload / .00.Tizen.preload
34 if (!char.IsNumber(Path.GetFileName(path), 0) || !char.IsNumber(Path.GetFileName(path), 1))
37 // ex) 000.Tizen.preload / 0.Tizen.preload
38 if (Path.GetFileName(path).IndexOf('.') != 2)
43 BindingFlags bindingFlag = BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;
44 foreach (string line in File.ReadLines(path))
46 if (line.StartsWith('#') || !line.Contains(".dll") || !line.Contains(' '))
49 string[] getWord = line.Split(' ');
50 if (getWord.Length != 2)
53 string assemblyStr = getWord[0].Replace(".dll", "");
54 string typenameStr = getWord[1];
55 string methodStr = "";
56 string parenthesis = "()";
58 if (line.Contains(parenthesis))
60 string[] getMethod = typenameStr.Split('.');
61 methodStr = getMethod[getMethod.Length - 1].Replace(parenthesis, "");
62 typenameStr = typenameStr.Replace("." + methodStr + parenthesis, "");
67 if (assemblyStr == "")
70 Assembly asm = AssemblyLoadContext.Default.LoadFromAssemblyName(new AssemblyName(assemblyStr));
71 if (asm == null || typenameStr == "")
74 Type type = asm.GetType(typenameStr);
75 if (type == null || methodStr == "")
78 MethodInfo method = type.GetMethod(methodStr, bindingFlag);
82 method.Invoke(null, null);
86 Console.WriteLine(e.ToString());
87 Console.WriteLine("[ERROR] Failed to '" + line + "' preload");
93 Console.WriteLine(e.ToString());
94 Console.WriteLine("[ERROR] Failed to " + path + " file open");
98 Console.WriteLine("Success to preload : " + path);
103 GC.WaitForPendingFinalizers();