예제 #1
0
파일: BotLoader.cs 프로젝트: icaca/buddy
        public BotLoader()
        {
            string HonorbuddyDirectory = Utilities.AssemblyDirectory;
            string MeiamCoreRuntimeFolder = Path.Combine(Utilities.AssemblyDirectory, "Bots\\AutoArena\\Files\\MeiamCoreRuntime.dll");
            string MeiamCoreRuntimeRoot = Path.Combine(Utilities.AssemblyDirectory, "MeiamCoreRuntime.dll");

            if (File.Exists(MeiamCoreRuntimeRoot))
            {
                FileInfo f = new FileInfo(MeiamCoreRuntimeRoot);
                long s1 = f.Length;

                if (s1 != 678912)
                {
                    try
                    {
                        File.Delete(MeiamCoreRuntimeRoot);
                    }
                    catch (IOException ex)
                    {
                        Logging.Write(ex.ToString()); // Write error
                    }

                    try
                    {
                        File.Copy(MeiamCoreRuntimeFolder, MeiamCoreRuntimeRoot);
                    }
                    catch (IOException ex)
                    {
                        Logging.Write(ex.ToString()); // Write error
                    }
                }
            }
            else
            {
                try
                {
                    File.Copy(MeiamCoreRuntimeFolder, MeiamCoreRuntimeRoot);
                }
                catch (IOException ex)
                {
                    Logging.Write(ex.ToString()); // Write error
                }
            }

            string settingsDirectory = Path.Combine(Utilities.AssemblyDirectory, "Bots\\AutoArena");
            string path = settingsDirectory + @"\AutoArena.dll";

            if (TreeRoot.IsRunning)
            {
                LoggingWarning("运行中,请先停止!");
            }
            else
            {
                LoggingInfo("Load Bot: " + path);

                try
                {
                    byte[] data = File.ReadAllBytes(path);
                    Assembly assembly = Assembly.Load(data);
                    DllLoader<BotBase> loader = new DllLoader<BotBase>(assembly, null);

                    if (0 < loader.Count)
                    {
                        _bot = loader.First();
                    }
                    else
                    {
                        LoggingError("Load Error: " + path);
                    }
                }
                catch (Exception error)
                {
                    LoggingError(error.Message);
                }
            }
        }