// Get installes packages public void LoadInstalledPacks() { List <string> dirs = new List <string>(Directory.EnumerateDirectories(_sPacksDir)); PacksInstalled = new MCPacksInstalled(); foreach (string dir in dirs) { if (File.Exists(dir + @"\version") && File.Exists(dir + @"\pack.json")) { MCPacksInstalledPack pack = new MCPacksInstalledPack { Name = dir.Substring(dir.LastIndexOf("\\") + 1), // Get versions files CurrentVersion = File.ReadAllText(dir + @"\version").Trim() }; if (File.Exists(dir + @"\selected")) { pack.SelectedVersion = File.ReadAllText(dir + @"\selected").Trim(); } else { pack.SelectedVersion = "recommended"; } PacksInstalled.packs.Add(pack); } } }
// Check if Pack is Installed (and the right version) public bool IsPackInstalled(string sPackName, string sPackVersion = null) { // get pack MCPacksInstalledPack Pack = GetInstalledPack(sPackName); // return false if pack not found if (Pack == null) { return(false); } // return true if no version is given if (sPackVersion == null) { return(true); } // check version of installed Pack // if recommended version, getting the version from available packs if (sPackVersion == "recommended") { sPackVersion = GetRecommendedVersion(sPackName); } // check if version is installed if (Pack.CurrentVersion != sPackVersion) { return(false); } // Pack is fine :) return(true); }
public string GetRecommendedVersion(string sPackName) { if (Offline == false) { MCAvailablePack Pack = GetAvailablePack(sPackName); return(Pack.RecommendedVersion); } else { MCPacksInstalledPack Pack = GetInstalledPack(sPackName); return(Pack.CurrentVersion); } }
// get pack icon public Image GetPackIconOffline(MCPacksInstalledPack Pack) { if (!File.Exists(_sPacksDir + @"\" + Pack.Name + @"\" + Pack.Name + ".png")) { return(null); } MemoryStream ms = new MemoryStream(); using (FileStream fileStream = File.OpenRead(_sPacksDir + @"\" + Pack.Name + @"\" + Pack.Name + ".png")) { ms.SetLength(fileStream.Length); //read file to MemoryStream fileStream.Read(ms.GetBuffer(), 0, (int)fileStream.Length); } return(Image.FromStream(ms)); }
public string GetInstalledPackVersion(string sPackName) { MCPacksInstalledPack Pack = GetInstalledPack(sPackName); return(Pack.CurrentVersion); }