public bool TryGetPayloadFromCache(string packageId, string packageVersion, out MsiPayload payload) { string packageCacheDirectory = GetPackageDirectory(packageId, packageVersion); string manifestPath = Path.Combine(packageCacheDirectory, "msi.json"); payload = default; // It's possible that the MSI is cached, but without the JSON manifest we cannot // trust that the MSI in the cache directory is the correct file. if (!File.Exists(manifestPath)) { Log?.LogMessage($"Manifest file does not exist, '{manifestPath}'"); return(false); } // The msi.json manifest contains the name of the actual MSI. The filename does not necessarily match the package // ID as it may have been shortened to support VS caching. MsiManifest msiManifest = JsonConvert.DeserializeObject <MsiManifest>(File.ReadAllText(manifestPath)); string msiPath = Path.Combine(Path.GetDirectoryName(manifestPath), msiManifest.Payload); if (!File.Exists(msiPath)) { Log?.LogMessage($"MSI package is not cached, '{msiPath}'"); return(false); } payload = new MsiPayload(manifestPath, msiPath); return(true); }
/// <summary> /// Creates the log filename to use when executing an MSI. The name is based on the primary log, payload name and <see cref="InstallAction"/>. /// </summary> /// <param name="packInfo">The workload pack to use when generating the log name.</param> /// <param name="action">The install action that will be performed.</param> /// <returns>The full path of the log file.</returns> protected string GetMsiLogName(MsiPayload msi, InstallAction action) { return(Path.Combine(Path.GetDirectoryName(Log.LogPath), Path.GetFileNameWithoutExtension(Log.LogPath) + $"_{msi.Manifest.Payload}_{action}.log")); }