public byte[] xExtractBytes() { byte[] ret = null; var xIO = new DJsIO(true); try { if (xExtract(ref xIO)) { xIO.Position = 0; ret = xIO.GetBytes(); } } catch { ret = null; } xIO.Close(); return ret; }
/// <summary> /// Create an STFS Package /// </summary> /// <param name="xSession"></param> /// <param name="xSigning"></param> /// <param name="xOutPath"></param> /// <param name="LogIn"></param> public STFSPackage(CreateSTFS xSession, RSAParams xSigning, out byte[] ret, LogRecord LogIn) { ret = null; xActive = true; if (!xSigning.Valid) throw CryptoExcepts.ParamError; if (xSession.xFileDirectory.Count == 0) throw new Exception(); ////try { //AddToLog("Setting Package variables"); xroot = new FolderEntry("", 0, 0xFFFF, 0xFFFF, this); if (xSession.HeaderData.ThisType == PackageType.GamesOnDemand || xSession.HeaderData.ThisType == PackageType.HDDInstalledGame || xSession.HeaderData.ThisType == PackageType.OriginalXboxGame || xSession.HeaderData.ThisType == PackageType.SocialTitle) throw STFSExcepts.Game; xLog = LogIn; xHeader = xSession.HeaderData; xSTFSStruct = new STFSDescriptor(xSession.STFSType, 0); xIO = new DJsIO(); var DirectoryBlockz = new List<BlockRecord>(); // switched2 = true; uint xcurblock = 0; for (ushort i = 0; i < xSession.GetDirectoryCount; i++) { DirectoryBlockz.Add(new BlockRecord()); DirectoryBlockz[DirectoryBlockz.Count - 1].ThisBlock = xcurblock++; } xFileBlocks = DirectoryBlockz.ToArray(); xWriteChain(xFileBlocks); xSTFSStruct.xDirectoryBlockCount = (ushort)xFileBlocks.Length; ushort xCurID = 0; xSession.xFolderDirectory.Sort(new Comparison<CFolderEntry>(sortpathct)); foreach (var x in xSession.xFolderDirectory) { ushort pointer = 0xFFFF; if (x.xthispath.xPathCount() > 1) pointer = xGetParentFolder(x.Path).EntryID; xFolderDirectory.Add(new FolderEntry(x.Name, 0, xCurID++, pointer, this)); xFolderDirectory[xFolderDirectory.Count - 1].xFixOffset(); } foreach (CFileEntry x in xSession.xFileDirectory) { ushort pointer = 0xFFFF; if (x.xthispath.xPathCount() > 1) pointer = xGetParentFolder(x.Path).EntryID; xFileDirectory.Add(new FileEntry(x.Name, (int)x.GetLength(), false, xCurID++, pointer, this)); var xAlloc = new List<BlockRecord>(); for (uint i = 0; i < x.BlockCount(); i++) { xAlloc.Add(new BlockRecord()); xAlloc[xAlloc.Count - 1].ThisBlock = xcurblock++; } xFileDirectory[xFileDirectory.Count - 1].xBlockCount = (uint)xAlloc.Count; xFileDirectory[xFileDirectory.Count - 1].xStartBlock = xAlloc[0].ThisBlock; xFileDirectory[xFileDirectory.Count - 1].xPackage = this; xFileDirectory[xFileDirectory.Count - 1].xFixOffset(); xWriteChain(xAlloc.ToArray()); } //AddToLog("Writing Entry Table"); DJsIO xent; if (!xEntriesToFile(out xent)) throw new Exception(); xWriteTo(ref xent, xFileBlocks); xent.Close(); //VariousFunctions.DeleteFile(xent.FileNameLong); //AddToLog("Writing Files"); uint curblck = xSession.GetDirectoryCount; foreach (var z in xSession.xFileDirectory) { var w = new List<BlockRecord>(); uint ct = z.BlockCount(); for (uint y = 0; y < ct; y++) { w.Add(new BlockRecord()); w[w.Count - 1].ThisBlock = curblck++; } DJsIO x = null; //try { x = new DJsIO(z.FileData, true); xWriteTo(ref x, w.ToArray()); } //catch { } if (x != null) x.Dispose(); } xWriteTables(); xWriteHeader(xSigning); ret = xIO.GetBytes(); xIO.Close(); //VariousFunctions.MoveFile(xIO.FileNameLong, xOutPath); xActive = false; } ////catch (Exception x) { xFileDirectory = null; xFolderDirectory = null; xIO.Dispose(); throw x; } }