public async Task <Dictionary <string, UpdataItem> > ReadresourcepacksInfo(string path) { path += @"\resourcepacks\"; if (!Directory.Exists(path)) { return(new Dictionary <string, UpdataItem>()); } Dictionary <string, UpdataItem> list = new(); await Task.Run(() => { string[] files = Directory.GetFiles(path, "*.zip"); IChecker checker = new MD5Checker(); foreach (string FilePath in files) { checker.FilePath = FilePath; UpdataItem mod = new() { local = FilePath, check = checker.GetFileChecksum() }; mod.name = mod.filename = FilePath.Replace(path, ""); if (list.ContainsKey(mod.name) == false) { list.Add(mod.name, mod); } } }); return(list); }
public async Task <Dictionary <string, UpdataItem> > ReadLaunchrInfo(string path) { if (!Directory.Exists(path)) { return(new()); } Dictionary <string, UpdataItem> list = new(); IChecker checker = new MD5Checker(); await Task.Factory.StartNew(() => { var GetFiles = new GetFiles(); foreach (string FilePath in GetFiles.GetDirectory(path)) { checker.FilePath = FilePath; UpdataItem mod = new() { local = FilePath, check = checker.GetFileChecksum() }; mod.name = mod.filename = FilePath.Replace(path, ""); if (list.ContainsKey(mod.name) == false) { list.Add(mod.name, mod); } } }); return(list); }
//生成MD5值 public static string MD5File(string file) { try { return(MD5Checker.Check(file)); } catch (System.Exception ex) { Debug.LogError(ex.Message); return(string.Empty); } }
public StartGameViewModel() { checker = new MD5Checker(LauncherSettings.Default.GamePath, "ftp://5.188.158.148"); checker.Notify += (message, progress) => { DownloadStatus = ""; TaskStatus = message; IsIndeterminate = progress; }; checker.DownloadStatus += (current, maximum, progress) => { IsIndeterminate = progress; ProgressBarMaximum = maximum; ProgressBarValue = current; DownloadStatus = $"{current}/{maximum} KB"; }; TaskStatus = "Начать подключение к серверу?"; StartButtonVisibility = Visibility.Visible; ProgressBarVisibility = Visibility.Collapsed; }
public UpdataItem GetModsInfo(string path, string fileName) { try { JToken modinfo = null; UpdataItem mod = new(); mod.filename = fileName.Replace(path, ""); using ZipFile zip = new(fileName); ZipEntry zp = zip.GetEntry("mcmod.info"); if (zp == null) { foreach (string name in TranList) { if (mod.filename.Contains(name)) { mod.name = name; } } } else { using Stream stream = zip.GetInputStream(zp); TextReader reader = new StreamReader(stream); string jsonString = reader.ReadToEnd(); try { if (jsonString.StartsWith("{")) { modinfo = JArray.Parse(jsonString)[0]; } else if (jsonString.StartsWith("[")) { var a = JObject.Parse(jsonString).ToObject <ModObjList.Root>().modList[0]; modinfo = JObject.FromObject(a); } } catch { modinfo = null; } if (modinfo != null) { var c = modinfo.ToObject <ModObj>(); if (c.name != null) { mod.name = c.name; } } } if (string.IsNullOrWhiteSpace(mod.name)) { mod.name = fileName.Replace(path + "\\", ""); } IChecker checker = new MD5Checker { FilePath = fileName }; mod.check = checker.GetFileChecksum(); mod.local = fileName; return(mod); } catch { return(null); } }