private void btnOK_Click(object sender, EventArgs e) { S3Pack.Sims3Pack.Pack(tbSource.Text, tbTarget.Text, xv); CopyableMessageBox.Show("Done!", "Sims3Pack created", CopyableMessageBoxButtons.OK, CopyableMessageBoxIcon.Information); ResetSource(); ResetTarget(); xv = null; OKforOK(); }
void setSource(string source) { tbSource.Text = source; try { xv = new XmlValues(tbSource.Text); UpdatePackagedFiles(Path.GetDirectoryName(tbSource.Text)); } catch (System.Xml.XmlException xe) { CopyableMessageBox.IssueException(xe, "There is a problem with the XML.", "s3su repack"); ResetSource(); return; } haveSource = true; OKforOK(); }
public static void Pack(string Package, string Target, XmlValues v) { v.SetInnerText("Date", DateTime.UtcNow.ToString("MM/dd/yyyy HH:mm:ss")); long Offset = 0; // Update the XML foreach (PackagedFile pf in v.PackagedFiles) { string filename = GetFilename(pf.Name, v.PackageId, Package); using (Stream sr = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read)) { try { pf.SetInnerText("Length", sr.Length + ""); pf.SetInnerText("Offset", Offset + ""); UInt64 Crc = System.Security.Cryptography.Sims3PackCRC.CalculateCRC(sr); pf.SetInnerText("Crc", Crc.ToString("x")); Offset += sr.Length; } finally { sr.Close(); } } } using (Stream sw = new FileStream(Target, FileMode.Create, FileAccess.Write, FileShare.None)) { BinaryWriter bw = new BinaryWriter(sw); try { // Write the header bw.Write((int)magic.Length); bw.Write(magic.ToCharArray()); bw.Write(unknown1); // Write the XML using (MemoryStream ms = new MemoryStream()) using (XmlWriter xw = XmlWriter.Create(ms, new XmlWriterSettings() { CloseOutput = false, Indent = true, IndentChars = " ", })) { v.Sims3PackType.OwnerDocument.WriteContentTo(xw); xw.Flush(); xw.Close(); byte[] xml = ms.ToArray(); bw.Write((int)xml.Length); bw.Write(xml); ms.Close(); } // Write all the packaged files foreach (PackagedFile pf in v.PackagedFiles) { string filename = GetFilename(pf.Name, v.PackageId, Package); using (Stream sr = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read)) { try { sw.Write(new BinaryReader(sr).ReadBytes((int)sr.Length), 0, (int)sr.Length); } catch (Exception e) { throw e; } finally { sr.Close(); } } } } catch (Exception e) { throw e; } finally { sw.Close(); } } }
private void btnOK_Click(object sender, EventArgs e) { string source = tbSource.Text; bool deleteSource = false; try { XmlValues xv = new XmlValues(); xv.SetAttributeValue("Type", tbType.Text); xv.SetAttributeValue("SubType", tbSubType.Text); xv.SetInnerText("ArchiveVersion", tbArchiveVersion.Text); xv.SetInnerText("CodeVersion", tbCodeVersion.Text); xv.SetInnerText("GameVersion", tbGameVersion.Text); xv.SetInnerText("DisplayName", tbDisplayName.Text); xv.SetInnerText("Description", tbDescription.Text); xv.SetInnerText("PackageId", tbPackageId.Text); //Date gets set by packer xv.SetInnerText("AssetVersion", tbAssetVersion.Text); xv.SetInnerText("MinReqVersion", tbMinReqVersion.Text); if (ckbCreateManifest.Checked) { source = CopyToTemp(source, tbPackageId.Text); deleteSource = true; try { Manifest.UpdatePackage(source, tbPackageId.Text, tbType.Text, tbSubType.Text, tbDisplayName.Text, tbDescription.Text, ckbCreateMissingIcon.Checked); } catch (ApplicationException aex) { CopyableMessageBox.Show(aex.Message, "s3su", CopyableMessageBoxButtons.OK, CopyableMessageBoxIcon.Warning); return; } } //Ensure a minimal entry for the package exists but don't override existing values PackagedFile pf = xv.PackagedFiles.Find(p => p.Guid.InnerText.ToLower().Equals(tbPackageId.Text.ToLower())); if (pf == null) { pf = xv.CreatePackagedFile(tbPackageId.Text + ".package"); pf.GetInnerText(pf.Guid, "Guid", tbPackageId.Text); pf.GetInnerText(pf.ContentType, "ContentType", tbType.Text); pf.GetInnerText(pf.EPFlags, "EPFlags", "0x00000000"); } S3Pack.Sims3Pack.Pack(source, tbTarget.Text, xv); CopyableMessageBox.Show("Done!", "Sims3Pack created", CopyableMessageBoxButtons.OK, CopyableMessageBoxIcon.Information); } finally { if (deleteSource) { File.Delete(source); } ResetSource(); ResetTarget(); ResetPackageId(); tbDisplayName.Text = tbDescription.Text = ""; tbSubType.Text = "0x00000000"; ckbCreateManifest.Enabled = false; ckbCreateManifest.Checked = ckbCreateManifest.Enabled; OKforOK(); } }
private void btnOK_Click(object sender, EventArgs e) { string source = tbSource.Text; bool deleteSource = false; try { XmlValues xv = new XmlValues(); xv.SetAttributeValue("Type", tbType.Text); xv.SetAttributeValue("SubType", tbSubType.Text); xv.SetInnerText("ArchiveVersion", tbArchiveVersion.Text); xv.SetInnerText("CodeVersion", tbCodeVersion.Text); xv.SetInnerText("GameVersion", tbGameVersion.Text); xv.SetInnerText("DisplayName", tbDisplayName.Text); xv.SetInnerText("Description", tbDescription.Text); xv.SetInnerText("PackageId", tbPackageId.Text); //Date gets set by packer xv.SetInnerText("AssetVersion", tbAssetVersion.Text); xv.SetInnerText("MinReqVersion", tbMinReqVersion.Text); if (ckbCreateManifest.Checked) { source = CopyToTemp(source, tbPackageId.Text); deleteSource = true; try { Manifest.UpdatePackage(source, tbPackageId.Text, tbType.Text, tbSubType.Text, tbDisplayName.Text, tbDescription.Text, ckbCreateMissingIcon.Checked); } catch (ApplicationException aex) { CopyableMessageBox.Show(aex.Message, "s3su", CopyableMessageBoxButtons.OK, CopyableMessageBoxIcon.Warning); return; } } //Ensure a minimal entry for the package exists but don't override existing values PackagedFile pf = xv.PackagedFiles.Find(p => p.Guid.InnerText.ToLower().Equals(tbPackageId.Text.ToLower())); if (pf == null) { pf = xv.CreatePackagedFile(tbPackageId.Text + ".package"); pf.GetInnerText(pf.Guid, "Guid", tbPackageId.Text); pf.GetInnerText(pf.ContentType, "ContentType", tbType.Text); pf.GetInnerText(pf.EPFlags, "EPFlags", "0x00000000"); } S3Pack.Sims3Pack.Pack(source, tbTarget.Text, xv); CopyableMessageBox.Show("Done!", "Sims3Pack created", CopyableMessageBoxButtons.OK, CopyableMessageBoxIcon.Information); } finally { if (deleteSource) File.Delete(source); ResetSource(); ResetTarget(); ResetPackageId(); tbDisplayName.Text = tbDescription.Text = ""; tbSubType.Text = "0x00000000"; ckbCreateManifest.Enabled = false; ckbCreateManifest.Checked = ckbCreateManifest.Enabled; OKforOK(); } }