Esempio n. 1
0
        /// <summary>
        /// 根据游戏核心id来启动游戏
        /// </summary>
        /// <param name="id"></param>
        public virtual void Launch(string id)
        {
            if (this.ProcessContainer?.ProcessState == Model.ProcessState.Running)
            {
                throw new GameHasRanException()
                      {
                          ProcessContainer = this.ProcessContainer
                      }
            }
            ;
            else
            {
                this.ProcessContainer?.Dispose();
            }

            var core = this.CoreLocator.GetGameCoreFromId(id);

            if (core == null)
            {
                throw new GameCoreNotFoundException()
                      {
                          Id = id
                      }
            }
            ;

            this.ArgumentsBuilder = new ArgumentsBuilder(core, this.LaunchConfig);

            if (string.IsNullOrEmpty(this.LaunchConfig.NativesFolder))
            {
                this.LaunchConfig.NativesFolder = $"{PathHelper.GetVersionFolder(core.Root, id)}{PathHelper.X}natives";
            }

            var nativesDecompressor = new NativesDecompressor(core.Root, id);

            nativesDecompressor.Decompress(core.Natives, this.LaunchConfig.NativesFolder);

            this.ProcessContainer = new ProcessContainer(
                new ProcessStartInfo
            {
                WorkingDirectory = Directory.Exists(LaunchConfig.WorkingFolder) ? LaunchConfig.WorkingFolder : core.Root,
                Arguments        = ArgumentsBuilder.BulidArguments(),
                FileName         = this.LaunchConfig.JavaPath,
            });

            ProcessContainer.Start();
        }