Ejemplo n.º 1
0
        /// <summary>
        /// 获取版本丢失的资源文件
        /// </summary>
        /// <param name="core">所使用的核心</param>
        /// <param name="version">要检查的版本</param>
        /// <returns>返回Key为路径,value为资源文件信息实例的集合</returns>
        public static Dictionary <string, JAssetsInfo> GetLostAssets(LaunchHandler core, JAssets assets)
        {
            Dictionary <string, JAssetsInfo> lostAssets = new Dictionary <string, JAssetsInfo>();

            try
            {
                if (assets == null)
                {
                    return(lostAssets);
                }
                foreach (var item in assets.Objects)
                {
                    string path = core.GetAssetsPath(item.Value);
                    if (lostAssets.ContainsKey(path))
                    {
                        continue;
                    }
                    else if (!File.Exists(path))
                    {
                        lostAssets.Add(item.Key, item.Value);
                    }
                }

                return(lostAssets);
            }
            catch
            {
                return(lostAssets);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 获取版本丢失的natives文件
        /// </summary>
        /// <param name="core">所使用的核心</param>
        /// <param name="version">要检查的版本</param>
        /// <returns>返回Key为路径,value为native实例的集合</returns>
        public static Dictionary <string, Native> GetLostNatives(LaunchHandler core, Modules.Version version)
        {
            Dictionary <string, Native> lostNatives = new Dictionary <string, Native>();

            try
            {
                foreach (var item in version.Natives)
                {
                    string path = core.GetNativePath(item);
                    if (lostNatives.ContainsKey(path))
                    {
                        continue;
                    }
                    else if (!File.Exists(path))
                    {
                        lostNatives.Add(path, item);
                    }
                }

                return(lostNatives);
            }
            catch
            {
                return(lostNatives);
            }
        }
Ejemplo n.º 3
0
        public static int Run(string[] args)
        {
            if (args.Length == 0 || args.Length == 1)
            {
                return(ErrorHandler.printHelpInfo());
            }
            else
            {
                switch (args[1])
                {
                case "new":
                    return(NewHandler.PrintHelpMenu());

                case "list":
                    return(ListHandler.PrintHelpMenu());

                case "update":
                    return(UpdateHandler.PrintHelpMenu());

                case "delete":
                    return(DeleteHandler.PrintHelpMenu());

                case "launch":
                    return(LaunchHandler.PrintHelpMenu());

                default:
                    return(ErrorHandler.printHelpInfo());
                }
            }
        }
 public static bool IsLostJarCore(LaunchHandler core, Version version)
 {
     if (version.InheritsVersion == null)
     {
         string jarPath = core.GetJarPath(version);
         return(!File.Exists(jarPath));
     }
     else
     {
         return(false);
     }
 }
 /// <summary>
 /// 获取版本是否丢失任何库文件
 /// </summary>
 /// <param name="core">启动核心</param>
 /// <param name="version">检查的版本</param>
 /// <returns>是否丢失任何库文件</returns>
 public static bool IsLostAnyLibs(LaunchHandler core, Version version)
 {
     foreach (var item in version.Libraries)
     {
         string path = core.GetLibraryPath(item);
         if (!File.Exists(path))
         {
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 6
0
 /// <summary>
 /// 获取版本是否丢失任何natives文件
 /// </summary>
 /// <param name="core"></param>
 /// <param name="version"></param>
 /// <returns></returns>
 public static bool IsLostAnyNatives(LaunchHandler core, MCVersion version)
 {
     foreach (var item in version.Natives)
     {
         string path = core.GetNativePath(item);
         if (!File.Exists(path))
         {
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 7
0
        /// <summary>
        /// 返回全部丢失的文件路径
        /// </summary>
        /// <param name="core">所使用的核心</param>
        /// <param name="version">要检查的版本</param>
        /// <returns>丢失文件的路径列表</returns>
        public static List <string> GetAllLostDepend(LaunchHandler core, Modules.Version version)
        {
            List <string> lost    = new List <string>();
            string        jarPath = core.GetJarPath(version);

            if (!File.Exists(jarPath))
            {
                lost.Add(jarPath);
            }
            lost.AddRange(GetLostLibs(core, version).Keys);
            lost.AddRange(GetLostNatives(core, version).Keys);
            return(lost);
        }
 private static bool IsLostAnyAssetsFromJassets(LaunchHandler core, JAssets assets)
 {
     if (assets == null)
     {
         return(false);
     }
     foreach (var item in assets.Objects)
     {
         string path = core.GetAssetsPath(item.Value);
         if (!File.Exists(path))
         {
             return(true);
         }
     }
     return(false);
 }
        /// <summary>
        /// 获取版本丢失的库文件
        /// </summary>
        /// <param name="core">所使用的启动核心</param>
        /// <param name="version">要检查的版本</param>
        /// <returns>返回Key为路径,value为库实例的集合</returns>
        public static Dictionary <string, Modules.Library> GetLostLibs(LaunchHandler core, Version version)
        {
            Dictionary <string, Modules.Library> lostLibs = new Dictionary <string, Modules.Library>();

            foreach (var item in version.Libraries)
            {
                string path = core.GetLibraryPath(item);
                if (lostLibs.ContainsKey(path))
                {
                    continue;
                }
                else if (!File.Exists(path))
                {
                    lostLibs.Add(path, item);
                }
            }
            return(lostLibs);
        }
        public static async Task <bool> IsLostAssetsAsync(DownloadSource source, LaunchHandler core, Version ver)
        {
            string assetsPath = core.GetAssetsIndexPath(ver.Assets);

            if (!File.Exists(assetsPath))
            {
                return(ver.AssetIndex != null);
            }
            else
            {
                var assets = await core.GetAssetsAsync(ver);

                return(await Task.Factory.StartNew(() =>
                {
                    return IsLostAnyAssetsFromJassets(core, assets);
                }));
            }
        }
Ejemplo n.º 11
0
 public async static Task SaveOptionsAsync(List <VersionOption> opts, LaunchHandler core, Modules.Version version)
 {
     await Task.Factory.StartNew(() =>
     {
         try
         {
             if (version != null && opts != null)
             {
                 List <string> optLines = new List <string>();
                 foreach (var item in opts)
                 {
                     optLines.Add(item.ToString());
                 }
                 File.WriteAllLines(core.GetVersionOptionsPath(version), optLines.ToArray());
             }
         }
         catch (Exception) {}
     });
 }
Ejemplo n.º 12
0
 public async static Task <List <VersionOption> > GetOptionsAsync(LaunchHandler core, Modules.Version version)
 {
     return(await Task.Factory.StartNew(() =>
     {
         if (version != null)
         {
             try
             {
                 string optionsPath = core.GetVersionOptionsPath(version);
                 if (!File.Exists(optionsPath))
                 {
                     return null;
                 }
                 string[] lines = File.ReadAllLines(optionsPath);
                 List <VersionOption> options = new List <VersionOption>();
                 foreach (var item in lines)
                 {
                     string[] kv = item.Split(':');
                     if (kv.Length != 2)
                     {
                         return null;
                     }
                     options.Add(new VersionOption()
                     {
                         Key = kv[0], Value = kv[1]
                     });
                 }
                 return options;
             }
             catch (Exception)
             {
                 return null;
             }
         }
         else
         {
             return null;
         }
     }));
 }
Ejemplo n.º 13
0
        public static async Task <bool> IsLostAssetsAsync(DownloadSource source, LaunchHandler core, Version ver)
        {
            string assetsPath = core.GetAssetsIndexPath(ver.Assets);

            if (!File.Exists(assetsPath))
            {
                if (ver.AssetIndex == null)
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
            else
            {
                var assets = await core.GetAssetsAsync(ver);

                return(await Task.Factory.StartNew(() =>
                {
                    foreach (var item in assets.Objects)
                    {
                        if (File.Exists(core.GetAssetsPath(item.Value)))
                        {
                            continue;
                        }
                        else
                        {
                            return true;
                        }
                    }
                    return false;
                }));
            }
        }
        //作者觉得使用这个方法判断是否丢失文件不如直接根据GetLostDependDownloadTask方法返回的列表的Count数来判断
        //毕竟这种方法大部分用在启动前判断是否丢失文件,但是如果丢失还是要获取一次列表,效率并没怎样优化
        //public static bool IsLostAnyDependent(LaunchHandler core, Version version)
        //{
        //    return IsLostJarCore(core, version) || IsLostAnyLibs(core, version) || IsLostAnyNatives(core, version);
        //}

        /// <summary>
        /// 获取全部丢失的文件下载任务
        /// </summary>
        /// <param name="source">下载源</param>
        /// <param name="core">使用的核心</param>
        /// <param name="version">检查的版本</param>
        /// <returns></returns>
        public async static Task <List <DownloadTask> > GetLostDependDownloadTaskAsync(DownloadSource source, LaunchHandler core, Version version)
        {
            var lostLibs              = GetLostLibs(core, version);
            var lostNatives           = GetLostNatives(core, version);
            List <DownloadTask> tasks = new List <DownloadTask>();

            if (IsLostJarCore(core, version))
            {
                if (version.Jar == null)
                {
                    tasks.Add(GetDownloadUrl.GetCoreJarDownloadTask(source, version, core));
                }
            }

            if (version.InheritsVersion != null)
            {
                string innerJsonPath = core.GetJsonPath(version.InheritsVersion);
                string innerJsonStr;
                if (!File.Exists(innerJsonPath))
                {
                    innerJsonStr = await APIRequester.HttpGetStringAsync(GetDownloadUrl.GetCoreJsonDownloadURL(source, version.InheritsVersion));

                    string jsonFolder = Path.GetDirectoryName(innerJsonPath);
                    if (!Directory.Exists(jsonFolder))
                    {
                        Directory.CreateDirectory(jsonFolder);
                    }
                    File.WriteAllText(innerJsonPath, innerJsonStr);
                }
                else
                {
                    innerJsonStr = File.ReadAllText(innerJsonPath);
                }
                Version innerVer = core.JsonToVersion(innerJsonStr);
                if (innerVer != null)
                {
                    tasks.AddRange(await GetLostDependDownloadTaskAsync(source, core, innerVer));
                }
            }
            foreach (var item in lostLibs)
            {
                tasks.Add(GetDownloadUrl.GetLibDownloadTask(source, item));
            }
            foreach (var item in lostNatives)
            {
                tasks.Add(GetDownloadUrl.GetNativeDownloadTask(source, item));
            }
            return(tasks);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// 获取全部丢失的文件下载任务
        /// </summary>
        /// <param name="source">下载源</param>
        /// <param name="core">使用的核心</param>
        /// <param name="version">检查的版本</param>
        /// <returns></returns>
        public static List <DownloadTask> GetLostDependDownloadTask(DownloadSource source, LaunchHandler core, Version version)
        {
            var lostLibs              = GetLostLibs(core, version);
            var lostNatives           = GetLostNatives(core, version);
            List <DownloadTask> tasks = new List <DownloadTask>();
            string jarPath            = core.GetJarPath(version);

            if (!File.Exists(jarPath))
            {
                if (version.InheritsVersion != null)
                {
                    Version inner = core.GetVersionByID(version.InheritsVersion);
                    tasks.Add(GetDownloadUrl.GetCoreDownloadTask(source, inner, core));
                }
                else
                {
                    tasks.Add(GetDownloadUrl.GetCoreDownloadTask(source, version, core));
                }
            }
            foreach (var item in lostLibs)
            {
                tasks.Add(GetDownloadUrl.GetLibDownloadTask(source, item.Value, core));
            }
            foreach (var item in lostNatives)
            {
                tasks.Add(GetDownloadUrl.GetNativeDownloadTask(source, item.Value, core));
            }
            return(tasks);
        }
Ejemplo n.º 16
0
        public static DownloadTask GetCoreDownloadTask(DownloadSource downloadSource, Modules.Version version, LaunchHandler core)
        {
            string from = GetCoreDownloadURL(downloadSource, version);
            string to   = core.GetJarPath(version);

            return(new DownloadTask("游戏版本核心", from, to));
        }
Ejemplo n.º 17
0
        /// <summary>
        /// 获取assets下载任务
        /// </summary>
        /// <param name="source">下载源</param>
        /// <param name="assets">assets实例</param>
        /// <param name="core">所使用的核心</param>
        /// <returns>下载任务</returns>
        public static DownloadTask GetAssetsDownloadTask(DownloadSource source, JAssetsInfo assets, LaunchHandler core)
        {
            string from = GetAssetsDownloadURL(source, assets);
            string to   = core.GetAssetsPath(assets);

            return(new DownloadTask("游戏资源文件" + assets.Hash, from, to));
        }
Ejemplo n.º 18
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            #region DEBUG初始化
            //debug
            logHandler = new LogHandler(true);
            AggregateExceptionCatched += (a, b) => logHandler.AppendFatal(b.AggregateException);
            if (e.Args.Contains("-debug"))
            {
                Windows.DebugWindow debugWindow = new Windows.DebugWindow();
                debugWindow.Show();
                logHandler.OnLog += (s, log) => debugWindow?.AppendLog(s, log);
            }
            #endregion

            config = new ConfigHandler();

            #region DEBUG初始化(基于配置文件)
            if (config.MainConfig.Launcher.Debug && !e.Args.Contains("-debug"))
            {
                Windows.DebugWindow debugWindow = new Windows.DebugWindow();
                debugWindow.Show();
                logHandler.OnLog += (s, log) => debugWindow?.AppendLog(s, log);
            }
            #endregion

            #region MineRealms反馈API初始化

#if DEBUG
            MineRealmsAPIHandler = new MineRealmsLauncherCore.Net.PhalAPI.APIHandler(true);
#else
            MineRealmsAPIHandler = new MineRealmsLauncherCore.Net.PhalAPI.APIHandler(config.MainConfig.Launcher.NoTracking);
#endif

            #endregion

            #region 数据初始化
            Config.Environment env = config.MainConfig.Environment;

            javaList = Java.GetJavaList();

            //设置版本路径
            string gameroot = null;
            switch (env.GamePathType)
            {
            case GameDirEnum.ROOT:
                gameroot = Path.GetFullPath(".minecraft");
                break;

            case GameDirEnum.APPDATA:
                gameroot = System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData) + "\\.minecraft";
                break;

            case GameDirEnum.PROGRAMFILES:
                gameroot = System.Environment.GetFolderPath(System.Environment.SpecialFolder.ProgramFiles) + "\\.minecraft";
                break;

            case GameDirEnum.CUSTOM:
                gameroot = env.GamePath + "\\.minecraft";
                break;

            default:
                throw new ArgumentException("判断游戏目录类型时出现异常,请检查配置文件中GamePathType节点");
            }
            logHandler.AppendInfo("核心初始化->游戏根目录(默认则为空):" + gameroot);

            //设置JAVA
            Java java = null;
            if (env.AutoJava)
            {
                java = Java.GetSuitableJava(javaList);
            }
            else
            {
                java = javaList.Find(x => x.Path == env.JavaPath);
                if (java == null)
                {
                    java = Java.GetJavaInfo(env.JavaPath);
                }
            }
            if (java != null)
            {
                env.JavaPath = java.Path;
                logHandler.AppendInfo("核心初始化->Java路径:" + java.Path);
                logHandler.AppendInfo("核心初始化->Java版本:" + java.Version);
                logHandler.AppendInfo("核心初始化->Java位数:" + java.Arch);
            }
            else
            {
                logHandler.AppendWarn("核心初始化失败,当前电脑未匹配到JAVA");
            }

            //设置版本独立
            bool verIso = config.MainConfig.Environment.VersionIsolation;
            #endregion

            #region 启动核心初始化
            handler          = new LaunchHandler(gameroot, java, verIso);
            handler.GameLog += (s, log) => logHandler.AppendLog(s, new Log()
            {
                LogLevel = LogLevel.GAME, Message = log
            });
            handler.LaunchLog += (s, log) => logHandler.AppendLog(s, log);
            #endregion

            #region  载核心初始化
            ServicePointManager.DefaultConnectionLimit = 10;

            Download downloadCfg = config.MainConfig.Download;
            downloader = new MultiThreadDownloader();
            if (!string.IsNullOrWhiteSpace(downloadCfg.DownloadProxyAddress))
            {
                WebProxy proxy = new WebProxy(downloadCfg.DownloadProxyAddress, downloadCfg.DownloadProxyPort);
                if (!string.IsNullOrWhiteSpace(downloadCfg.ProxyUserName))
                {
                    NetworkCredential credential = new NetworkCredential(downloadCfg.ProxyUserName, downloadCfg.ProxyUserPassword);
                    proxy.Credentials = credential;
                }
                downloader.Proxy = proxy;
            }
            downloader.ProcessorSize = App.config.MainConfig.Download.DownloadThreadsSize;
            downloader.CheckFileHash = App.config.MainConfig.Download.CheckDownloadFileHash;
            downloader.DownloadLog  += (s, log) => logHandler?.AppendLog(s, log);
            #endregion

            #region 自定义主题初始化
            var custom = config.MainConfig.Customize;
            if (!string.IsNullOrWhiteSpace(custom.AccentColor) && !string.IsNullOrWhiteSpace(custom.AppThme))
            {
                logHandler.AppendInfo("自定义->更改主题颜色:" + custom.AccentColor);
                logHandler.AppendInfo("自定义->更改主题:" + custom.AppThme);
                ThemeManager.ChangeAppStyle(Current, ThemeManager.GetAccent(custom.AccentColor), ThemeManager.GetAppTheme(custom.AppThme));
            }
            #endregion
        }
Ejemplo n.º 19
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11;
            Process[] myProcesses = Process.GetProcessesByName("NsisoLauncher");//获取指定的进程名
            bool      self        = false;

            foreach (var item in myProcesses)
            {
                if (item.MainModule.FileName == AppDomain.CurrentDomain.BaseDirectory + AppDomain.CurrentDomain.FriendlyName)
                {
                    if (self == false)
                    {
                        self = true;
                    }
                    else
                    {
                        SetForegroundWindow(item.MainWindowHandle);
                        Shutdown();
                    }
                }
            }

            LogHandler = new LogHandler(true);
            Config     = new ConfigHandler();
            EnvironmentObj env = Config.MainConfig.Environment;

            JavaList = Java.GetJavaList();

            AggregateExceptionCatched += (a, b) => LogHandler.AppendFatal(b.AggregateException);

            if (Config.MainConfig.Launcher.Debug || e.Args.Contains("-debug"))
            {
                DebugWindow debugWindow = new DebugWindow();
                debugWindow.Show();
                LogHandler.OnLog += (s, log) => debugWindow?.AppendLog(s, log);
            }

            nsisoAPIHandler = new APIHandler(Config.MainConfig.Launcher.NoTracking);

            //设置版本路径
            string gameroot = null;

            switch (env.GamePathType)
            {
            case GameDirEnum.ROOT:
                gameroot = Path.GetFullPath(".minecraft");
                break;

            case GameDirEnum.APPDATA:
                gameroot = System.Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\.minecraft";
                break;

            case GameDirEnum.PROGRAMFILES:
                gameroot = System.Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) + "\\.minecraft";
                break;

            case GameDirEnum.CUSTOM:
                gameroot = env.GamePath + "\\.minecraft";
                break;

            default:
                throw new ArgumentException("判断游戏目录类型时出现异常,请检查配置文件中GamePathType节点");
            }
            LogHandler.AppendInfo("核心初始化->游戏根目录(默认则为空):" + gameroot);

            //设置JAVA
            Java java;

            if (env.AutoJava)
            {
                java = Java.GetSuitableJava(JavaList);
            }
            else
            {
                java = JavaList.Find(x => x.Path == env.JavaPath);
                if (java == null)
                {
                    java = Java.GetJavaInfo(env.JavaPath);
                }
            }
            if (java != null)
            {
                env.JavaPath = java.Path;
                LogHandler.AppendInfo("核心初始化->Java路径:" + java.Path);
                LogHandler.AppendInfo("核心初始化->Java版本:" + java.Version);
                LogHandler.AppendInfo("核心初始化->Java位数:" + java.Arch);
            }
            else
            {
                LogHandler.AppendWarn("核心初始化失败,当前电脑未匹配到JAVA");
            }

            bool verIso = Config.MainConfig.Environment.VersionIsolation;

            Handler          = new LaunchHandler(gameroot, java, verIso);
            Handler.GameLog += (s, log) => LogHandler.AppendLog(s, new Log()
            {
                LogLevel = LogLevel.GAME, Message = log
            });
            Handler.LaunchLog += (s, log) => LogHandler.AppendLog(s, log);

            ServicePointManager.DefaultConnectionLimit = 10;

            Downloader = new MultiThreadDownloader();

            ProxyRe();

            Downloader.ProcessorSize = Config.MainConfig.Download.DownloadThreadsSize;
            Downloader.CheckFileHash = Config.MainConfig.Download.CheckDownloadFileHash;
            Downloader.DownloadLog  += (s, log) => LogHandler?.AppendLog(s, log);

            var custom = Config.MainConfig.Customize;

            if (!string.IsNullOrWhiteSpace(custom.AppThme))
            {
                LogHandler.AppendInfo("自定义->更改主题:" + custom.AppThme);
                ThemeManager.Current.ChangeTheme(Current, custom.AppThme);
            }

            Lauguage();
        }
Ejemplo n.º 20
0
        public string GetCrashInfo(LaunchHandler handler, GameExitArg exitArg)
        {
            if (!exitArg.Process.HasExited)
            {
                throw new Exception("The game is running.");
            }
            if (exitArg.IsNormalExit())
            {
                throw new ArgumentException("It seems that the game is safe exit.Exit code equal zero");
            }
            Process  process        = exitArg.Process;
            DateTime launchTime     = process.StartTime;
            DateTime exitTime       = process.ExitTime;
            string   verRootDir     = handler.GetGameVersionRootDir(exitArg.Version);
            string   crashreportDir = verRootDir + "\\crash-reports";
            string   latestlogPath  = verRootDir + "\\logs\\latest.log";

            if (Directory.Exists(crashreportDir))
            {
                var files = Directory.EnumerateFiles(crashreportDir);
                var logs  = files.Where((x) =>
                {
                    string time = Path.GetFileName(x).Substring(6, 19).Replace('-', '/').Replace('_', ' ').Replace('.', ':');
                    if (DateTime.TryParse(time, out DateTime logtime))
                    {
                        return((launchTime < logtime) && (logtime < exitTime));
                    }
                    else
                    {
                        return(false);
                    }
                });
                if (logs.Count() != 0)
                {
                    return(File.ReadAllText(logs.FirstOrDefault()));
                }
                else
                {
                    return(null);
                }
            }

            //没有崩溃日志直接查找log
            else if (File.Exists(latestlogPath))
            {
                DateTime lastWrtTime = File.GetLastWriteTime(latestlogPath);
                if ((launchTime < lastWrtTime) && (lastWrtTime < exitTime))
                {
                    string[]      allLogArr = File.ReadAllLines(latestlogPath);
                    List <int>    valiLogNo = new List <int>();
                    bool          keepRead  = false;
                    StringBuilder builder   = new StringBuilder();
                    for (int i = 0; i < allLogArr.Length; i++)
                    {
                        string current = allLogArr[i];

                        if (keepRead)
                        {
                            builder.AppendLine(allLogArr[i - 1]);
                        }

                        //最简单的检查
                        if (!current.StartsWith("["))
                        {
                            continue;
                        }

                        //寻找第一个固定要素区块
                        var firstLBrac = current.IndexOf('[');
                        if (firstLBrac == -1)
                        {
                            continue;
                        }
                        var firstRBrac = current.IndexOf(']');
                        if (firstRBrac == -1)
                        {
                            continue;
                        }
                        var firstBlock = current.Substring(firstLBrac + 1, firstRBrac - firstLBrac - 1);

                        //寻找第二个固定要素区块
                        var secondLBrac = current.IndexOf('[', firstRBrac);
                        if (secondLBrac == -1)
                        {
                            continue;
                        }
                        var secondRBrac = current.IndexOf(']', secondLBrac);
                        if (secondRBrac == -1)
                        {
                            continue;
                        }
                        var secondBlock = current.Substring(secondLBrac + 1, secondRBrac - secondLBrac - 1);

                        if (DateTime.TryParse(firstBlock, out DateTime time))
                        {
                            if (secondBlock.Contains("ERROR"))
                            {
                                keepRead = true;
                            }
                            else
                            {
                                keepRead = false;
                            }
                        }
                    }
                    return(builder.ToString());
                }
                else
                {
                    return(null);
                }
            }

            else
            {
                return(null);
            }
        }
Ejemplo n.º 21
0
 public AssetsReader(LaunchHandler handler)
 {
     this.handler = handler;
 }
Ejemplo n.º 22
0
        public static DownloadTask GetCoreJsonDownloadTask(DownloadSource downloadSource, string verID, LaunchHandler core)
        {
            string to   = core.GetJsonPath(verID);
            string from = GetCoreJsonDownloadURL(downloadSource, verID);

            return(new DownloadTask("游戏版本核心Json文件", from, to));
        }
Ejemplo n.º 23
0
        public static DownloadTask GetCoreJarDownloadTask(DownloadSource downloadSource, Modules.Version version, LaunchHandler core)
        {
            string       to           = core.GetJarPath(version);
            string       from         = GetCoreJarDownloadURL(downloadSource, version);
            DownloadTask downloadTask = new DownloadTask("游戏版本核心Jar文件", from, to);

            if (!string.IsNullOrWhiteSpace(version.Downloads?.Client?.SHA1))
            {
                downloadTask.Checker = new SHA1Checker()
                {
                    CheckSum = version.Downloads.Client.SHA1, FilePath = to
                };
            }
            return(downloadTask);
        }
        /// <summary>
        /// 获取丢失的资源文件下载任务
        /// </summary>
        /// <param name="source"></param>
        /// <param name="core"></param>
        /// <param name="version"></param>
        /// <returns></returns>
        public async static Task <List <DownloadTask> > GetLostAssetsDownloadTaskAsync(DownloadSource source, LaunchHandler core, Version ver)
        {
            List <DownloadTask> tasks  = new List <DownloadTask>();
            JAssets             assets = null;

            string assetsPath = core.GetAssetsIndexPath(ver.Assets);

            if (!File.Exists(assetsPath))
            {
                if (ver.AssetIndex != null)
                {
                    string jsonUrl    = GetDownloadUrl.DoURLReplace(source, ver.AssetIndex.URL);
                    string assetsJson = await APIRequester.HttpGetStringAsync(jsonUrl);

                    assets = core.GetAssetsByJson(assetsJson);
                    tasks.Add(new DownloadTask("资源文件引导", jsonUrl, assetsPath));
                }
                else
                {
                    return(tasks);
                }
            }
            else
            {
                assets = core.GetAssets(ver);
            }
            var lostAssets = GetLostAssets(core, assets);

            foreach (var item in lostAssets)
            {
                DownloadTask task = GetDownloadUrl.GetAssetsDownloadTask(source, item.Value, core);
                if (!tasks.Contains(task))
                {
                    tasks.Add(task);
                }
            }
            return(tasks);
        }
Ejemplo n.º 25
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            #region DEBUG初始化
            //debug
            LogHandler = new LogHandler(true);
            AggregateExceptionCatched += (a, b) => LogHandler.AppendFatal(b.AggregateException);
            if (e.Args.Contains("-debug"))
            {
                DebugWindow debugWindow = new DebugWindow();
                debugWindow.Show();
                LogHandler.OnLog += (s, log) => debugWindow?.AppendLog(s, log);
            }
            #endregion

            #region 从旧版本跳转
            String[] args = System.Environment.GetCommandLineArgs();
            if (args.Length == 2)
            {
                //关闭并删除旧版本
                Task.Run(() =>
                {
                    Process oldLauncher    = Process.GetProcessById(Convert.ToInt32(args[1]));
                    string oldLauncherPath = oldLauncher.MainModule.FileName;
                    oldLauncher.Kill();
                    oldLauncher.WaitForExit();
                    File.Delete(oldLauncherPath);
                });
            }
            #endregion

            Config = new ConfigHandler();

            #region DEBUG初始化(基于配置文件)
            if (Config.MainConfig.Launcher.Debug && !e.Args.Contains("-debug"))
            {
                DebugWindow debugWindow = new DebugWindow();
                debugWindow.Show();
                LogHandler.OnLog += (s, log) => debugWindow?.AppendLog(s, log);
            }
            #endregion

            #region Nsiso反馈API初始化

#if DEBUG
            NsisoAPIHandler = new NsisoLauncherCore.Net.PhalAPI.APIHandler(true);
#else
            NsisoAPIHandler = new NsisoLauncherCore.Net.PhalAPI.APIHandler(Config.MainConfig.Launcher.NoTracking);
#endif

            #endregion

            #region 数据初始化
            Config.Environment env = Config.MainConfig.Environment;

            JavaList = Java.GetJavaList();

            //设置版本路径
            string gameroot = null;
            switch (env.GamePathType)
            {
            case GameDirEnum.ROOT:
                gameroot = Path.GetFullPath(".minecraft");
                break;

            case GameDirEnum.APPDATA:
                gameroot = System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData) + "\\.minecraft";
                break;

            case GameDirEnum.PROGRAMFILES:
                gameroot = System.Environment.GetFolderPath(System.Environment.SpecialFolder.ProgramFiles) + "\\.minecraft";
                break;

            case GameDirEnum.CUSTOM:
                gameroot = env.GamePath + "\\.minecraft";
                break;

            default:
                throw new ArgumentException("判断游戏目录类型时出现异常,请检查配置文件中GamePathType节点");
            }
            LogHandler.AppendInfo("核心初始化->游戏根目录(默认则为空):" + gameroot);

            //设置JAVA
            Java java = null;
            if (env.AutoJava)
            {
                java = Java.GetSuitableJava(JavaList);
            }
            else
            {
                java = JavaList.Find(x => x.Path == env.JavaPath);
                if (java == null)
                {
                    java = Java.GetJavaInfo(env.JavaPath);
                }
            }
            if (java != null)
            {
                env.JavaPath = java.Path;
                LogHandler.AppendInfo("核心初始化->Java路径:" + java.Path);
                LogHandler.AppendInfo("核心初始化->Java版本:" + java.Version);
                LogHandler.AppendInfo("核心初始化->Java位数:" + java.Arch);
            }
            else
            {
                LogHandler.AppendWarn("核心初始化失败,当前电脑未匹配到JAVA");
            }

            //设置版本独立
            bool verIso = Config.MainConfig.Environment.VersionIsolation;
            #endregion

            #region 启动核心初始化
            Handler          = new LaunchHandler(gameroot, java, verIso);
            Handler.GameLog += (s, log) => LogHandler.AppendLog(s, new Log()
            {
                LogLevel = LogLevel.GAME, Message = log
            });
            Handler.LaunchLog += (s, log) => LogHandler.AppendLog(s, log);
            #endregion

            #region  载核心初始化
            ServicePointManager.DefaultConnectionLimit = 10;

            Download downloadCfg = Config.MainConfig.Download;
            Downloader = new MultiThreadDownloader();
            if (!string.IsNullOrWhiteSpace(downloadCfg.DownloadProxyAddress))
            {
                WebProxy proxy = new WebProxy(downloadCfg.DownloadProxyAddress, downloadCfg.DownloadProxyPort);
                if (!string.IsNullOrWhiteSpace(downloadCfg.ProxyUserName))
                {
                    NetworkCredential credential = new NetworkCredential(downloadCfg.ProxyUserName, downloadCfg.ProxyUserPassword);
                    proxy.Credentials = credential;
                }
                Downloader.Proxy = proxy;
            }
            Downloader.ProcessorSize = App.Config.MainConfig.Download.DownloadThreadsSize;
            Downloader.CheckFileHash = App.Config.MainConfig.Download.CheckDownloadFileHash;
            Downloader.DownloadLog  += (s, log) => LogHandler?.AppendLog(s, log);
            #endregion

            #region 自定义主题初始化
            var custom = Config.MainConfig.Customize;
            if (!string.IsNullOrWhiteSpace(custom.AccentColor) && !string.IsNullOrWhiteSpace(custom.AppThme))
            {
                LogHandler.AppendInfo("自定义->更改主题颜色:" + custom.AccentColor);
                LogHandler.AppendInfo("自定义->更改主题:" + custom.AppThme);
                ThemeManager.ChangeAppStyle(Current, ThemeManager.GetAccent(custom.AccentColor), ThemeManager.GetAppTheme(custom.AppThme));
            }
            #endregion

            #region 读取版本
            VersionList = new ObservableCollection <Version>();
            RefreshVersionList();
            #endregion
        }
Ejemplo n.º 26
0
        /// <summary>
        /// 获取Lib下载任务
        /// </summary>
        /// <param name="source">下载源</param>
        /// <param name="lib">lib实例</param>
        /// <param name="core">所使用的核心</param>
        /// <returns>下载任务</returns>
        public static DownloadTask GetLibDownloadTask(DownloadSource source, Modules.Library lib, LaunchHandler core)
        {
            string from = GetLibDownloadURL(source, lib);
            string to   = core.GetLibraryPath(lib);

            return(new DownloadTask("版本依赖库文件" + lib.Name, from, to));
        }
Ejemplo n.º 27
0
        /// <summary>
        /// 获取Native下载任务
        /// </summary>
        /// <param name="source">下载源</param>
        /// <param name="native">native实例</param>
        /// <param name="core">所使用的核心</param>
        /// <returns>下载任务</returns>
        public static DownloadTask GetNativeDownloadTask(DownloadSource source, Native native, LaunchHandler core)
        {
            string from = GetNativeDownloadURL(source, native);
            string to   = core.GetNativePath(native);

            return(new DownloadTask("版本系统依赖库文件" + native.Name, from, to));
        }
Ejemplo n.º 28
0
 public static Task <List <DownloadTask> > GetLostAssetsDownloadTaskAsync(DownloadSource source, LaunchHandler core, Version ver)
 {
     return(Task.Factory.StartNew(() =>
     {
         return GetLostAssetsDownloadTask(source, core, ver);
     }));
 }
Ejemplo n.º 29
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            #region 检查环境
            if ((System.Environment.Version.Major == 4) && (System.Environment.Version.Minor == 0))
            {
                if ((!SystemTools.IsSetupFrameworkUpdate("KB2468871v2")) && (!SystemTools.IsSetupFrameworkUpdate("KB2468871")))
                {
                    var result = MessageBox.Show(GetResourceString("String.Message.NoFrameworkUpdate2"),
                                                 GetResourceString("String.Message.NoFrameworkUpdate"),
                                                 MessageBoxButton.YesNo);
                    if (result == MessageBoxResult.Yes)
                    {
                        System.Diagnostics.Process.Start("https://github.com/Nsiso/NsisoLauncher/wiki/%E5%90%AF%E5%8A%A8%E5%99%A8%E6%8A%A5%E9%94%99%EF%BC%9A%E5%BD%93%E5%89%8D%E7%94%B5%E8%84%91%E7%8E%AF%E5%A2%83%E7%BC%BA%E5%B0%91KB2468871v2%E8%A1%A5%E4%B8%81");
                        System.Environment.Exit(0);
                    }
                }
            }
            #endregion

            #region DEBUG初始化
            //debug
            logHandler = new LogHandler(true);
            AggregateExceptionCatched += (a, b) => logHandler.AppendFatal(b.AggregateException);
            if (e.Args.Contains("-debug"))
            {
                Windows.DebugWindow debugWindow = new Windows.DebugWindow();
                debugWindow.Show();
                logHandler.OnLog += (s, log) => debugWindow?.AppendLog(s, log);
            }
            #endregion

            config = new ConfigHandler();

            #region DEBUG初始化(基于配置文件)
            if (config.MainConfig.Launcher.Debug && !e.Args.Contains("-debug"))
            {
                Windows.DebugWindow debugWindow = new Windows.DebugWindow();
                debugWindow.Show();
                logHandler.OnLog += (s, log) => debugWindow?.AppendLog(s, log);
            }
            #endregion

            #region 数据初始化
            Config.Environment env = config.MainConfig.Environment;

            javaList = Java.GetJavaList();

            //设置版本路径
            string gameroot = null;
            switch (env.GamePathType)
            {
            case GameDirEnum.ROOT:
                gameroot = Path.GetFullPath(".minecraft");
                break;

            case GameDirEnum.APPDATA:
                gameroot = System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData) + "\\.minecraft";
                break;

            case GameDirEnum.PROGRAMFILES:
                gameroot = System.Environment.GetFolderPath(System.Environment.SpecialFolder.ProgramFiles) + "\\.minecraft";
                break;

            case GameDirEnum.CUSTOM:
                gameroot = env.GamePath + "\\.minecraft";
                break;

            default:
                throw new ArgumentException("判断游戏目录类型时出现异常,请检查配置文件中GamePathType节点");
            }
            logHandler.AppendInfo("核心初始化->游戏根目录(默认则为空):" + gameroot);

            //设置JAVA
            Java java = null;
            if (env.AutoJava)
            {
                java = Java.GetSuitableJava(javaList);
            }
            else
            {
                java = javaList.Find(x => x.Path == env.JavaPath);
                if (java == null)
                {
                    java = Java.GetJavaInfo(env.JavaPath);
                }
            }
            if (java != null)
            {
                env.JavaPath = java.Path;
                logHandler.AppendInfo("核心初始化->Java路径:" + java.Path);
                logHandler.AppendInfo("核心初始化->Java版本:" + java.Version);
                logHandler.AppendInfo("核心初始化->Java位数:" + java.Arch);
            }
            else
            {
                logHandler.AppendWarn("核心初始化失败,当前电脑未匹配到JAVA");
            }

            //设置版本独立
            bool verIso = config.MainConfig.Environment.VersionIsolation;
            #endregion

            #region 启动核心初始化
            handler          = new LaunchHandler(gameroot, java, verIso);
            handler.GameLog += (s, log) => logHandler.AppendLog(s, new Log()
            {
                LogLevel = LogLevel.GAME, Message = log
            });
            #endregion

            #region  载核心初始化
            ServicePointManager.DefaultConnectionLimit = 10;
            Download downloadCfg = config.MainConfig.Download;
            downloader = new MultiThreadDownloader();
            if (!string.IsNullOrWhiteSpace(downloadCfg.DownloadProxyAddress))
            {
                WebProxy proxy = new WebProxy(downloadCfg.DownloadProxyAddress, downloadCfg.DownloadProxyPort);
                if (!string.IsNullOrWhiteSpace(downloadCfg.ProxyUserName))
                {
                    NetworkCredential credential = new NetworkCredential(downloadCfg.ProxyUserName, downloadCfg.ProxyUserPassword);
                    proxy.Credentials = credential;
                }
                downloader.Proxy = proxy;
            }
            downloader.ProcessorSize = App.config.MainConfig.Download.DownloadThreadsSize;
            downloader.DownloadLog  += (s, log) => logHandler?.AppendLog(s, log);
            #endregion

            #region NIDE8核心初始化
            if (!string.IsNullOrWhiteSpace(config.MainConfig.User.Nide8ServerID))
            {
                nide8Handler = new Core.Net.Nide8API.APIHandler(config.MainConfig.User.Nide8ServerID);
                nide8Handler.UpdateBaseURL();
            }
            #endregion

            #region 自定义主题初始化
            var custom = config.MainConfig.Customize;
            if (!string.IsNullOrWhiteSpace(custom.AccentColor) && !string.IsNullOrWhiteSpace(custom.AppThme))
            {
                logHandler.AppendInfo("自定义->更改主题颜色:" + custom.AccentColor);
                logHandler.AppendInfo("自定义->更改主题:" + custom.AppThme);
                ThemeManager.ChangeAppStyle(Current, ThemeManager.GetAccent(custom.AccentColor), ThemeManager.GetAppTheme(custom.AppThme));
            }
            #endregion
        }
Ejemplo n.º 30
0
 public VersionReader(LaunchHandler launchHandler)
 {
     dirInfo = new DirectoryInfo(launchHandler.GameRootPath + @"\versions");
     handler = launchHandler;
 }