/// <summary> /// Compose multiple PAK files into a solution /// </summary> public int Compose() { try { AppletManifest mfst = null; using (FileStream fs = File.OpenRead(this.m_parms.Source)) mfst = AppletManifest.Load(fs); var slnPak = mfst.CreatePackage(); AppletSolution sln = new AppletSolution(); sln.Meta = slnPak.Meta; sln.PublicKey = slnPak.PublicKey; sln.Manifest = slnPak.Manifest; if (sln.Meta.Uuid == Guid.Empty) { Emit.Message("WARN", "The package does not carry a UUID! You should add a UUID to your solution manifest"); } sln.Include = new List <AppletPackage>(); foreach (var pfile in sln.Meta.Dependencies.ToArray()) { AppletPackage pkg = null; if (!String.IsNullOrEmpty(pfile.Version)) // specific version { pkg = PackageRepositoryUtil.GetFromAny(pfile.Id, new Version(pfile.Version)); } else if (!String.IsNullOrEmpty(m_parms.Version)) { pkg = PackageRepositoryUtil.GetFromAny(pfile.Id, new Version(m_parms.Version)) ?? PackageRepositoryUtil.GetFromAny(pfile.Id, null); } else { pkg = PackageRepositoryUtil.GetFromAny(pfile.Id, null); } if (pkg == null) { throw new KeyNotFoundException($"Package {pfile.Id} ({pfile.Version ?? m_parms.Version ?? "latest"}) not found"); } else { Emit.Message("INFO", "Including {0} version {1}..", pkg.Meta.Id, pkg.Meta.Version); sln.Meta.Dependencies.RemoveAll(o => o.Id == pkg.Meta.Id); if (this.m_parms.Sign && pkg.Meta.Signature == null) { Emit.Message("WARN", "Package {0} is not signed, but you're signing your package. We'll sign it using your key", pkg.Meta.Id); pkg = new Signer(this.m_parms).CreateSignedPackage(pkg.Unpack()); } sln.Include.Add(pkg); } } // Emit i18n file? if (!String.IsNullOrEmpty(this.m_parms.InternationalizationFile)) { Emit.Message("INFO", $"Writing string manifest to {this.m_parms.InternationalizationFile}"); using (var fs = File.Create(this.m_parms.InternationalizationFile)) using (var tw = new StreamWriter(fs, System.Text.Encoding.UTF8)) { // tx translations var mfsts = sln.Include.Select(o => o.Unpack()).ToList(); var appletStrings = mfsts.SelectMany(o => o.Strings).ToArray(); var stringKeys = appletStrings.SelectMany(o => o.String).Select(o => o.Key).Distinct(); var langs = appletStrings.Select(o => o.Language).Distinct().ToArray(); tw.Write("key,"); tw.WriteLine(String.Join(",", langs)); foreach (var str in stringKeys) { tw.Write($"{str},"); foreach (var lang in langs) { tw.Write($"\"{appletStrings.Where(o => o.Language == lang).SelectMany(s => s.String).FirstOrDefault(o => o.Key == str)?.Value}\","); } tw.WriteLine(); } } } sln.Meta.Hash = SHA256.Create().ComputeHash(sln.Include.SelectMany(o => o.Manifest).ToArray()); // Sign the signature package if (this.m_parms.Sign) { new Signer(this.m_parms).CreateSignedSolution(sln); } // Now save using (FileStream fs = File.Create(this.m_parms.Output ?? Path.ChangeExtension(sln.Meta.Id, ".sln.pak"))) sln.Save(fs); return(0); } catch (System.Exception e) { Emit.Message("ERROR", e.Message); //Console.Error.WriteLine("Cannot compose solution {0}: {1}", this.m_parms.Source, e); return(-1); } }
/// <summary> /// Compile /// </summary> public int Compile() { int retVal = 0; // First is there a Manifest.xml? if (!Path.IsPathRooted(this.m_parms.Source)) { this.m_parms.Source = Path.Combine(Environment.CurrentDirectory, this.m_parms.Source); } Console.WriteLine("Processing {0}...", this.m_parms.Source); String manifestFile = this.m_parms.Source; if (!File.Exists(manifestFile) && Directory.Exists(manifestFile)) { manifestFile = Path.Combine(this.m_parms.Source, "manifest.xml"); } if (!File.Exists(manifestFile)) { throw new InvalidOperationException($"Directory {this.m_parms.Source} must have manifest.xml"); } else { Console.WriteLine("\t Reading Manifest...", manifestFile); using (var fs = File.OpenRead(manifestFile)) { AppletManifest mfst = AppletManifest.Load(fs); mfst.Assets.AddRange(this.ProcessDirectory(Path.GetDirectoryName(manifestFile), Path.GetDirectoryName(manifestFile))); foreach (var i in mfst.Assets) { if (i.Name.StartsWith("/")) { i.Name = i.Name.Substring(1); } } if (!string.IsNullOrEmpty(this.m_parms.Version)) { mfst.Info.Version = this.m_parms.Version; } mfst.Info.Version = PakManTool.ApplyVersion(mfst.Info.Version); if (!Directory.Exists(Path.GetDirectoryName(this.m_parms.Output)) && !String.IsNullOrEmpty(Path.GetDirectoryName(this.m_parms.Output))) { Directory.CreateDirectory(Path.GetDirectoryName(this.m_parms.Output)); } AppletPackage pkg = null; // Is there a signature? if (this.m_parms.Sign) { pkg = new Signer(this.m_parms).CreateSignedPackage(mfst); if (pkg == null) { return(-102); } } else { Emit.Message("WARN", "THIS PACKAGE IS NOT SIGNED - MOST OPEN IZ TOOLS WILL NOT LOAD IT"); mfst.Info.PublicKeyToken = null; pkg = mfst.CreatePackage(); //pkg.Meta.PublicKeyToken = null; } pkg.Meta.Hash = SHA256.Create().ComputeHash(pkg.Manifest); var outFile = this.m_parms.Output ?? mfst.Info.Id + ".pak"; using (var ofs = File.Create(outFile)) pkg.Save(ofs); if (this.m_parms.Install) { Emit.Message("INFO", "INSTALLING PACKAGE {0}", pkg.Meta.Id); PackageRepositoryUtil.InstallCache(pkg); } if (this.m_parms.Publish) { try { Emit.Message("INFO", "PUBLISHING PACKAGE TO {0}", this.m_parms.PublishServer); PackageRepositoryUtil.Publish(this.m_parms.PublishServer, pkg); } catch (Exception e) { Emit.Message("ERROR", "ERROR PUBLISHING PACKAGE - {0}", e.Message); } } } } return(retVal); }