internal static List <string> GetTypesFromCacheOrManifest(VersionManifest manifest, string path) { if (typeCache.ContainsKey(path)) { return(typeCache[path]); } // get the type from the manifest var matchingEntries = manifest.FindAll(x => Path.GetFullPath(x.FilePath) == path); if (matchingEntries == null || matchingEntries.Count == 0) { return(null); } var types = new List <string>(); foreach (var existingEntry in matchingEntries) { types.Add(existingEntry.Type); } typeCache[path] = types; return(typeCache[path]); }
public bool UpdateApp( string appName, string displayAppName, string appPath, string[] executePaths, string[] lockProcesses, string defaultUpdateUri) { try { VersionManifest currentManifest = GetCurrentVersionManifest(appPath); return(UpdateApp( currentManifest, appName, displayAppName, appPath, executePaths, lockProcesses, defaultUpdateUri )); } catch (Exception exc) { ErrorBox.Show(UpdStr.UPDATER, exc); } return(false); }
private static void AddOrUpdateJSONToManifest() { try { string filePath = "mods/CommanderPortraitLoader/Portraits/"; VersionManifest manifest = VersionManifestUtilities.ManifestFromCSV("mods/CommanderPortraitLoader/VersionManifest.csv"); DirectoryInfo d1 = new DirectoryInfo(filePath); FileInfo[] f1 = d1.GetFiles("*.png"); foreach (VersionManifestEntry entry in manifest.Entries) { if (!File.Exists(entry.FilePath.Replace(".json", ".png"))) { if (File.Exists(entry.FilePath)) { File.Delete(entry.FilePath); } manifest.Remove(entry.Id, entry.Type, DateTime.Now); manifest.ClearRemoved(); } } f1 = d1.GetFiles("*.json"); CustomPreset preset = new CustomPreset(); foreach (FileInfo info in f1) { using (StreamReader r = new StreamReader(info.FullName)) { string json = r.ReadToEnd(); preset = JsonConvert.DeserializeObject <CustomPreset>(json); } manifest.AddOrUpdate(preset.Description.Id, info.FullName, "PortraitSettings", DateTime.Now, null, false); } VersionManifestUtilities.ManifestToCSV(manifest, "mods/CommanderPortraitLoader/VersionManifest.csv"); } catch (Exception e) { Logger.LogError(e); } }
//Is it possible for this to ever return more than 1 type for a entry in the manifest? // Based on the output file the answer is yes. Prefab+Assetbundle | Texture2D+Sprite are examples //Can a manifest entry even have more than one type? // Multiple entries with the same ID could have different types in their entry public List <string> GetTypes(string id, VersionManifest manifest = null) { if (entries.ContainsKey(id)) { return(entries[id]); } if (manifest != null) { // get the types from the manifest var matchingEntries = manifest.FindAll(x => x.Id == id); if (matchingEntries == null || matchingEntries.Count == 0) { return(null); } var types = new List <string>(); foreach (var existingEntry in matchingEntries) { types.Add(existingEntry.Type); } entries[id] = types; return(entries[id]); } return(null); }
public OlderVersionsForm(VersionManifest versions) { InitializeComponent(); Versions = versions; SelectedVersion = null; SetupVersionDropdown(Versions); }
public void Test_SampleSerialize() { string json = UpdateChecker.GenerateSampleJson(); VersionManifest manifest = JsonConvert.DeserializeObject <VersionManifest>(json); Console.WriteLine(manifest); }
static void Postfix(VersionManifest __result) { ModTek.LogWithDate("VersionManifestUtilities_LoadDefaultManifest_Patch"); // add to the manifest here // TODO: these freaking kvp look so bad foreach (var entryKVP in ModTek.NewManifestEntries) { var id = entryKVP.Key; var newEntry = entryKVP.Value; if (newEntry.ShouldMergeJSON && __result.Contains(id, newEntry.Type)) { // read the manifest pointed entry and hash the contents DoJSONMerge.JSONHashes.Add(File.ReadAllText(__result.Get(id, newEntry.Type).FilePath).GetHashCode()); // The manifest already contains this information, so we need to queue it to be merged var partialJSON = File.ReadAllText(newEntry.Path); if (!DoJSONMerge.JSONMerges.ContainsKey(id)) { DoJSONMerge.JSONMerges.Add(id, new List <string>()); } ModTek.Log("\tAdding id {0} to JSONMerges", id); DoJSONMerge.JSONMerges[id].Add(partialJSON); } else { // This is a new definition or a replacement that doesn't get merged, so add or update the manifest ModTek.Log("\tAddOrUpdate({0}, {1}, {2}, {3}, {4}, {5})", id, newEntry.Path, newEntry.Type, DateTime.Now, newEntry.AssetBundleName, newEntry.AssetBundlePersistent); __result.AddOrUpdate(id, newEntry.Path, newEntry.Type, DateTime.Now, newEntry.AssetBundleName, newEntry.AssetBundlePersistent); } } }
public RealManifestTests(string version, string platform) { Platform = platform; VersionId = version; VersionManifest = VersionManifest.Parse(File.ReadAllText(TestContext.CurrentContext.TestDirectory + $@"\Versioning\Data\Versions\{VersionId}.json")); }
internal static List <string> GetTypesFromCacheOrManifest(VersionManifest manifest, string id) { var types = GetTypesFromCache(id); if (types != null) { return(types); } // get the types from the manifest var matchingEntries = manifest.FindAll(x => x.Id == id); if (matchingEntries == null || matchingEntries.Count == 0) { return(null); } types = new List <string>(); foreach (var existingEntry in matchingEntries) { types.Add(existingEntry.Type); } typeCache[id] = types; return(typeCache[id]); }
public async Task Refresh() { var json = await Downloader.DownloadStringTaskAsync( new Uri(Url)); VersionManifest = new JSON <VersionManifest>().Parse(json); }
private void SetupVersionDropdown(VersionManifest versions) { foreach (VersionPackage version in versions.Versions) { cmbVersions.Items.Add(version.DisplayID); } cmbVersions.SelectedIndex = 0; }
public void UpdateVersionListView() { jsinit.ClearVersions(); GetVersions(); //MessageBox.Show("herre"); foreach ( VersionManifest version in Directory.GetDirectories(_configuration.McVersions) .Select(versionDir => new DirectoryInfo(versionDir)) .Where(VersionManifest.IsValid) .Select(info => VersionManifest.ParseVersion(info, false))) { jsinit.AddVersions(version.ReleaseType, version.VersionId, true); //versionsListView.Items.Add(version.VersionId, version.ReleaseType, version.ReleaseTime, version.LastUpdateTime, // version.AssetsIndex ?? "null", version.InheritsFrom ?? _configuration.Localization.Independent); } string path = Path.Combine(_configuration.McVersions, _selectedProfile.SelectedVersion ?? GetLatestVersion(_selectedProfile) + @"\"); string state = _configuration.Localization.ReadyToLaunch; // LaunchButton.Enabled = true; if (!File.Exists(string.Format(@"{0}\{1}.json", path, _selectedProfile.SelectedVersion ?? GetLatestVersion(_selectedProfile)))) { state = _configuration.Localization.ReadyToDownload; if (_configuration.Arguments.OfflineMode) { // LaunchButton.Enabled = false; } if (jsinit.VersionList.Where(x => x.VersionData == _selectedProfile.SelectedVersion).Count() >= 1 && jsinit.VersionList.Where(x => x.Instaled == true).Count() >= 1) { jsinit.SelectVersion(jsinit.VersionList.Where(x => x.VersionData == _selectedProfile.SelectedVersion).First().VersionName + "," + jsinit.VersionList.Where(x => x.VersionData == _selectedProfile.SelectedVersion).First().VersionData); } // SelectedVersion.Text = string.Format(state, _selectedProfile.SelectedVersion ?? // GetLatestVersion(_selectedProfile)); return; } if (!File.Exists(string.Format(@"{0}\{1}.jar", path, _selectedProfile.SelectedVersion ?? GetLatestVersion(_selectedProfile))) && VersionManifest.ParseVersion(new DirectoryInfo(path)).InheritsFrom == null) { state = _configuration.Localization.ReadyToDownload; if (_configuration.Arguments.OfflineMode) { // LaunchButton.Enabled = false; } } if (jsinit.VersionList.Where(x => x.VersionData == _selectedProfile.SelectedVersion).Count() >= 1 && jsinit.VersionList.Where(x => x.Instaled == true).Count() >= 1) { jsinit.SelectVersion(jsinit.VersionList.Where(x => x.VersionData == _selectedProfile.SelectedVersion).First().VersionName + "," + jsinit.VersionList.Where(x => x.VersionData == _selectedProfile.SelectedVersion).First().VersionData); } }
private void DownloadVersionManifestCompleted(object sender, AsyncCompletedEventArgs e) { Thread.Sleep(1000); MasterVersionManifest = JsonConvert.DeserializeObject <VersionManifest>(File.ReadAllText(Path.Combine(Library.UpdaterDirectory, "versions"))); if (LatestVersion != null) { // Enable Menus EnableForm(); } }
public static void Prefix(BattleTechResourceLocator __instance) { RLog.M.TWL(0, "BattleTechResourceLocator.RefreshTypedEntries"); VersionManifest versionManifest = __instance.manifest(); if (versionManifest != ModTek.CachedVersionManifest) { RLog.M.TWL(0, "WARNING! STRANGE BEHAVIOR cachedManifest does not much locator manifest. Resolving"); __instance.manifest(ModTek.CachedVersionManifest); } }
protected string DownloadVersion( VersionManifest downloadManifest, string appName, Version latestVersion, string updateUri ) { var tempApplicationPath = String.Empty; if (UIDownloadProgress != null) { DispatcherHelper.Invoke(new SimpleMethod(UIDownloadProgress.Show)); DispatcherHelper.Invoke(new SetDownloadProgressInfo(UIDownloadProgress.SetDownloadInfo), downloadManifest); } try { var fileDownloader = FileDownloaderFactory.GetFileDownloader(new Uri(updateUri).Scheme); fileDownloader.DownloadFileStarted += (s, e) => DispatcherHelper.Invoke(new UpdateDownloadProgress( UIDownloadProgress.SetDownloadProgress), e.FilePath, e.ToltalSize, e.DownloadedSize); var downloadItems = new List <LocationHash>(downloadManifest.VersionItems.Count); foreach (var item in downloadManifest.VersionItems) { if (item.InstallAction != InstallAction.Delete) { downloadItems.Add(item.GetLocationHash()); } } tempApplicationPath = CreateTempDir(appName, latestVersion); fileDownloader.DownloadFileSet( downloadItems, tempApplicationPath); var tempInstallerPath = CreateInstallerDir(tempApplicationPath, appName, latestVersion); fileDownloader.DownloadFileSet( downloadManifest.BootStrapper, tempInstallerPath); } finally { if (UIDownloadProgress != null) { DispatcherHelper.Invoke( new SimpleMethod(UIDownloadProgress.Close)); } } return(tempApplicationPath); }
private static bool AddModEntryToVersionManifest(VersionManifest manifest, ModDef.ManifestEntry modEntry, bool addToDB = false) { if (modEntry.Path == null) { return(false); } VersionManifestAddendum addendum = null; if (!string.IsNullOrEmpty(modEntry.AddToAddendum)) { addendum = manifest.GetAddendumByName(modEntry.AddToAddendum); // create the addendum if it doesn't exist if (addendum == null) { Log($"\t\tCreated addendum: {modEntry.AddToAddendum}"); addendum = new VersionManifestAddendum(modEntry.AddToAddendum); manifest.ApplyAddendum(addendum); } } // add to DB if (addToDB && Path.GetExtension(modEntry.Path).ToLower() == ".json") { var type = (BattleTechResourceType)Enum.Parse(typeof(BattleTechResourceType), modEntry.Type); using (var metadataDatabase = new MetadataDatabase()) { VersionManifestHotReload.InstantiateResourceAndUpdateMDDB(type, modEntry.Path, metadataDatabase); Log($"\t\tAdding to MDDB! {type} {modEntry.Path}"); } } // add assetbundle path so it can be changed when the assetbundle path is requested if (modEntry.Type == "AssetBundle") { ModAssetBundlePaths[modEntry.Id] = modEntry.Path; } // add to addendum instead of adding to manifest if (addendum != null) { Log($"\t\tAddOrUpdate => {modEntry.Id} ({modEntry.Type}) to addendum {addendum.Name}"); addendum.AddOrUpdate(modEntry.Id, modEntry.Path, modEntry.Type, DateTime.Now, modEntry.AssetBundleName, modEntry.AssetBundlePersistent); return(true); } // not added to addendum, not added to jsonmerges Log($"\t\tAddOrUpdate => {modEntry.Id} ({modEntry.Type})"); manifest.AddOrUpdate(modEntry.Id, modEntry.Path, modEntry.Type, DateTime.Now, modEntry.AssetBundleName, modEntry.AssetBundlePersistent); return(true); }
public static bool Prefix(ref VersionManifest __result) { // Return the cached manifest if it exists -- otherwise call the method as normal if (ModTek.CachedVersionManifest != null) { __result = ModTek.CachedVersionManifest; return(false); } else { return(true); } }
private async Task Update(VersionManifest versionManifest) { var latest = versionManifest.Versions.FirstOrDefault(v => v.Id == versionManifest.Latest.Release); await Announce(latest.Id); Shutdown(); await new Url(await GetServerJarUrl(latest.Url)).DownloadFileAsync( Path.GetDirectoryName(Configuration.MinecraftJar), Path.GetFileName(Configuration.MinecraftJar)); WriteManifest(latest); Startup(); }
public static void Postfix(ref VersionManifest __result) { try { var addendum = VersionManifestUtilities.ManifestFromCSV($"{ CommanderPortraitLoader.ModDirectory}/VersionManifest.csv"); foreach (var entry in addendum.Entries) { __result.AddOrUpdate(entry.Id, entry.FilePath, entry.Type, entry.AddedOn, entry.AssetBundleName, entry.IsAssetBundlePersistent); } } catch (Exception e) { Logger.LogError(e); } }
static string Classpath(VersionManifest vm) { List <string> entr = vm.Libraries.Where(x => x.IsNeeded).SelectMany(x => x.NeededDownloads).Select(x => "../../libraries/" + x.Value.LibraryPath).ToList(); string jarId = vm.JarFrom?.ID ?? vm.ID; entr.Add("../../versions/" + jarId + "/" + jarId + ".jar"); entr.Add("../../MCAuthHelper.jar"); if (Environment.OSVersion.Platform == PlatformID.Win32NT) { return(string.Join(";", entr)); } else { return(string.Join(":", entr)); } }
private static VersionManifest ReadVersionManifest(XmlReader reader) { VersionManifest result = new VersionManifest(); reader.ReadStartElement("VersionManifest"); reader.ReadStartElement("VersionNumberString"); result.VersionNumberString = reader.ReadContentAsString(); reader.ReadEndElement(); reader.ReadStartElement("VersionItems"); //reader.Read(); if (reader.Name == "VersionItem") { while (reader.IsStartElement()) { result.VersionItems.Add(ReadVersionItem(reader)); } } if (reader.NodeType == XmlNodeType.EndElement) { reader.ReadEndElement(); } reader.ReadStartElement("UpdateUri"); result.UpdateUri = reader.ReadContentAsString(); reader.ReadEndElement(); reader.ReadStartElement("UpdateUriAlt"); result.UpdateUriAlt = reader.ReadContentAsString(); reader.ReadEndElement(); reader.ReadStartElement("BootStrapper"); if (reader.Name == "LocationHash") { while (reader.IsStartElement()) { result.BootStrapper.Add(ReadBootStrapperItem(reader)); } } return(result); }
// ADDING TO VERSION MANIFEST private static bool AddModEntry(VersionManifest manifest, ModDef.ManifestEntry modEntry) { if (modEntry.Path == null) { return(false); } VersionManifestAddendum addendum = null; if (!string.IsNullOrEmpty(modEntry.AddToAddendum)) { addendum = manifest.GetAddendumByName(modEntry.AddToAddendum); // create the addendum if it doesn't exist if (addendum == null) { Log($"\t\tCreated addendum: {modEntry.AddToAddendum}"); addendum = new VersionManifestAddendum(modEntry.AddToAddendum); manifest.ApplyAddendum(addendum); } } // add special handling for particular types switch (modEntry.Type) { case "AssetBundle": ModAssetBundlePaths[modEntry.Id] = modEntry.Path; break; case "Texture2D": ModTexture2Ds.Add(modEntry.Id); break; } // add to addendum instead of adding to manifest if (addendum != null) { Log($"\t\tAddOrUpdate => {modEntry.Id} ({modEntry.Type}) to addendum {addendum.Name}"); addendum.AddOrUpdate(modEntry.Id, modEntry.Path, modEntry.Type, DateTime.Now, modEntry.AssetBundleName, modEntry.AssetBundlePersistent); return(true); } // not added to addendum, not added to jsonmerges Log($"\t\tAddOrUpdate => {modEntry.Id} ({modEntry.Type})"); manifest.AddOrUpdate(modEntry.Id, modEntry.Path, modEntry.Type, DateTime.Now, modEntry.AssetBundleName, modEntry.AssetBundlePersistent); return(true); }
// ADDING MOD CONTENT TO THE GAME private static void AddModEntry(VersionManifest manifest, ModDef.ManifestEntry modEntry) { if (modEntry.Path == null) { return; } VersionManifestAddendum addendum = null; if (!string.IsNullOrEmpty(modEntry.AddToAddendum)) { addendum = manifest.GetAddendumByName(modEntry.AddToAddendum); if (addendum == null) { Log($"\tCannot add {modEntry.Id} to {modEntry.AddToAddendum} because addendum doesn't exist in the manifest."); return; } } // add special handling for particular types switch (modEntry.Type) { case "AssetBundle": ModAssetBundlePaths[modEntry.Id] = modEntry.Path; break; case "Texture2D": ModTexture2Ds.Add(modEntry.Id); break; } // add to addendum instead of adding to manifest if (addendum != null) { Log($"\tAdd/Replace: \"{GetRelativePath(modEntry.Path, ModsDirectory)}\" ({modEntry.Type}) [{addendum.Name}]"); } else { Log($"\tAdd/Replace: \"{GetRelativePath(modEntry.Path, ModsDirectory)}\" ({modEntry.Type})"); } // not added to addendum, not added to jsonmerges BTRLEntries.Add(modEntry); return; }
internal static void BuildCachedManifest() { // First load the default battletech manifest, then it'll get appended to VersionManifest vanillaManifest = VersionManifestUtilities.LoadDefaultManifest(); // Wrapper to be able to submit a parameterless work function IEnumerator <ProgressReport> NestedFunc() { IEnumerator <ProgressReport> reports = BuildCachedManifestLoop(vanillaManifest); while (reports.MoveNext()) { yield return(reports.Current); } } ProgressPanel.SubmitWork(NestedFunc); }
public static VersionManifest Read(string path) { if (!File.Exists(path)) { return(new VersionManifest()); } string jsonStr = File.ReadAllText(path); JSONObject resultPrase = JSON.Parse(jsonStr).AsObject; VersionManifest result = new VersionManifest(); foreach (var kvp in resultPrase) { result.Add(kvp.Key, (kvp.Value as JSONString).Value); } return(result); }
protected void CleanUp(string appName, VersionManifest manifest) { if (manifest == null) { return; } try { var tempPath = GetTempVersionDir(appName, manifest.VersionNumber); var instDir = GetInstallerDir(tempPath, appName, manifest.VersionNumber); if (Directory.Exists(tempPath)) { Directory.Delete(tempPath, true); } if (Directory.Exists(instDir)) { Directory.Delete(instDir, true); } //Delete old trash //probably it was unseccesfull installations var tmpDir = GetTempDir(appName); if (Directory.Exists(tmpDir)) { var tmp = new DirectoryInfo(tmpDir); var dirs = tmp.GetDirectories(); foreach (var dir in dirs) { if ((DateTime.Now - dir.LastAccessTime).TotalHours > 24) { dir.Delete(true); } } } } catch {; } }
private void DownloadVersion(string version) { string path = Path.Combine(_mcVersions, version + @"\"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } AppendLog($"Validating files for Minecraft {version}..."); SetStatusLabel(FindResource("r_LabelStatusValidatingVersion").ToString()); if (!File.Exists($@"{path}\{version}.json")) { RawVersionListManifest versionList = RawVersionListManifest.ParseList(_webClient.DownloadString(@"https://launchermeta.mojang.com/mc/game/version_manifest.json")); AppendLog(" Downloading JSON..."); _webClient.DownloadFile( new Uri(versionList.GetVersion(version)?.ManifestUrl ?? string.Format( "https://s3.amazonaws.com/Minecraft.Download/versions/{0}/{0}.json", version)), string.Format(@"{0}\{1}\{1}.json", _mcVersions, version)); } VersionManifest selectedVersionManifest = VersionManifest.ParseVersion( new DirectoryInfo(_mcVersions + @"\" + version), false); if ((!File.Exists($"{path}/{version}.jar")) && selectedVersionManifest.InheritsFrom == null) { AppendLog(" Downloading JAR..."); _webClient.DownloadFile(new Uri(selectedVersionManifest.DownloadInfo?.Client.Url ?? string.Format( "https://s3.amazonaws.com/Minecraft.Download/versions/{0}/{0}.jar", version)), string.Format("{0}/{1}/{1}.jar", _mcVersions, version)); } if (selectedVersionManifest.InheritsFrom != null) { DownloadVersion(selectedVersionManifest.InheritsFrom); } }
public VersionManifest ReadManifest() { if (_manifestOffset < 0) { long start = -8 - 256/8; _stream.Seek(start, SeekOrigin.End); var temp = new byte[8]; var bytesRead = _stream.Read(temp, 0, 8); if (bytesRead != temp.Length) throw new InvalidDataException(); _manifestSize = BitConverter.ToInt64(temp, 0); start -= _manifestSize; _manifestOffset = _stream.Seek(start, SeekOrigin.End); } else _stream.Seek(_manifestOffset, SeekOrigin.Begin); using (var boundedStream = new BoundedStream(_stream, _manifestSize)) using (var filteredStream = DoInputFiltering(boundedStream, false)) VersionManifest = Serializer.Deserialize<VersionManifest>(filteredStream); VersionManifest.ArchiveMetadata.EnsureNonNull(); _baseObjectsOffset = _manifestOffset - VersionManifest.ArchiveMetadata.EntriesSizeInArchive; _streamIds = new List<ulong>(VersionManifest.ArchiveMetadata.StreamIds); _streamSizes = new List<long>(VersionManifest.ArchiveMetadata.StreamSizes); return VersionManifest; }
public void AddVersionManifest(VersionManifest versionManifest) { EnsureMinimumState(ArchiveState.PushingFsos); EnsureMaximumState(ArchiveState.PushingFsos); _outputFilter.Flush(); _outputFilter.Dispose(); _outputFilter = null; versionManifest.ArchiveMetadata = new ArchiveMetadata { EntrySizes = new List<long>(_baseObjectEntrySizes), StreamIds = new List<ulong>(_streamIds), StreamSizes = new List<long>(_streamSizes), //CompressionMethod = CompressionMethod, EntriesSizeInArchive = _hashedStream.BytesWritten - _initialFsoOffset, }; long manifestLength; using (var filter = DoOutputFiltering(_hashedStream, false)) { var x0 = _hashedStream.BytesWritten; Serializer.SerializeToStream(filter, versionManifest); filter.Flush(); var x1 = _hashedStream.BytesWritten; manifestLength = x1 - x0; } var bytes = BitConverter.GetBytes(manifestLength); _hashedStream.Write(bytes, 0, bytes.Length); _hashedStream.Dispose(); _hashedStream = null; _hash.FinishHashing(); bytes = _hash.Hash; _fileStream.Write(bytes, 0, bytes.Length); _fileStream.Flush(); _fileStream.Dispose(); _transaction.Commit(); _fileStream = null; _transaction.Dispose(); _transaction = null; _state = ArchiveState.Final; }