コード例 #1
0
        public bool extractFile(Sims3PackFileInfo file, string destinationFolder, bool cleanNames)
        {
            FileStream   s3pfile  = new FileStream(this.filename, FileMode.Open, FileAccess.Read, FileShare.Read);
            BinaryReader readFile = new BinaryReader(s3pfile);

            uint   version = readFile.ReadUInt32();
            string s3pack  = Encoding.ASCII.GetString(readFile.ReadBytes(7));

            if (s3pack != "TS3Pack")
            {
                errorMessage = "Not a Sims3Pack file";
                readFile.Close();
                s3pfile.Close();
                return(false);
            }

            uint unknown = readFile.ReadUInt16();

            int xmlLength = readFile.ReadInt32();

            s3pfile.Seek(xmlLength + file.offset, SeekOrigin.Current);

            string outputName = "";

            if (cleanNames && this.packagedFiles.Count == 1)
            {
                outputName = this.cleanName + ".package";
            }
            else
            {
                outputName = file.name;
            }

            FileStream   destFile  = new FileStream(destinationFolder + "\\" + outputName, FileMode.Create, FileAccess.Write, FileShare.Write);
            BinaryWriter writeFile = new BinaryWriter(destFile);

            writeFile.Write(readFile.ReadBytes(file.length));

            writeFile.Close();
            destFile.Close();

            readFile.Close();
            s3pfile.Close();

            return(true);
        }
コード例 #2
0
        public bool extractFile(Sims3PackFileInfo file, string destinationFolder, bool cleanNames )
        {
            FileStream s3pfile = new FileStream(this.filename, FileMode.Open, FileAccess.Read, FileShare.Read);
            BinaryReader readFile = new BinaryReader(s3pfile);

            uint version = readFile.ReadUInt32();
            string s3pack = Encoding.ASCII.GetString(readFile.ReadBytes(7));
            if (s3pack != "TS3Pack")
            {
                errorMessage = "Not a Sims3Pack file";
                readFile.Close();
                s3pfile.Close();
                return false;
            }

            uint unknown = readFile.ReadUInt16();

            int xmlLength = readFile.ReadInt32();
            s3pfile.Seek(xmlLength + file.offset, SeekOrigin.Current);

            string outputName = "";
            if (cleanNames && this.packagedFiles.Count == 1)
            {
                outputName = this.cleanName + ".package";
            }
            else
            {
                outputName = file.name;
            }

            FileStream destFile = new FileStream(destinationFolder + "\\" + outputName, FileMode.Create, FileAccess.Write, FileShare.Write);
            BinaryWriter writeFile = new BinaryWriter(destFile);

            writeFile.Write(readFile.ReadBytes(file.length));

            writeFile.Close();
            destFile.Close();

            readFile.Close();
            s3pfile.Close();

            return true;
        }
コード例 #3
0
 public bool extractFile(Sims3PackFileInfo file, string destinationFolder)
 {
     return extractFile(file, destinationFolder, true);
 }
コード例 #4
0
        public bool load(string filename)
        {
            FileStream s3pfile = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read);
            BinaryReader readFile = new BinaryReader(s3pfile);

            FileInfo f = new FileInfo(filename);
            this.cleanName = f.Name.Replace(f.Extension, "");

            uint version = readFile.ReadUInt32();
            string s3pack = Encoding.ASCII.GetString(readFile.ReadBytes(7));
            if (s3pack != "TS3Pack")
            {
                errorMessage = "Not a Sims3Pack file";
                readFile.Close();
                s3pfile.Close();
                return false;
            }
            this.filename = filename;

            uint unknown = readFile.ReadUInt16();

            int xmlLength = readFile.ReadInt32();

            byte[] xmlBytes = readFile.ReadBytes(xmlLength);

            MemoryStream mem = new MemoryStream(xmlBytes);
            XPathDocument doc = new XPathDocument(mem);

            Stack nameStack = getXmlFields(doc, "//PackagedFile/Name");
            Stack offsetStack = getXmlFields(doc, "//PackagedFile/Offset");
            Stack lengthStack = getXmlFields(doc, "//PackagedFile/Length");

            int sCount = nameStack.Count;
            for (int i = 0; i < sCount; i++)
            {
                string tempName = nameStack.Pop().ToString();
                int tempOffset = Convert.ToInt32(offsetStack.Pop().ToString());
                int length = Convert.ToInt32(lengthStack.Pop().ToString());

                string extension = tempName.Substring(tempName.LastIndexOf("."));
                if (extension == ".package")
                {
                    Sims3PackFileInfo s3fileInfo = new Sims3PackFileInfo();
                    s3fileInfo.name = tempName;
                    //s3fileInfo.cleanName = sanitiseString(tempName.Replace(".package", "")) + ".package";
                    s3fileInfo.offset = tempOffset;
                    s3fileInfo.length = length;

                    packagedFiles.Add(s3fileInfo);
                    s3fileInfo = null;
                }
            }

            //string xmlStuff = Encoding.ASCII.GetString(xmlBytes);

            // Close the files since we'll be working purely with the XML here.
            readFile.Close();
            s3pfile.Close();

            //rawXML = xmlStuff;

            return true;
        }
コード例 #5
0
        public bool load(string filename)
        {
            FileStream   s3pfile  = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read);
            BinaryReader readFile = new BinaryReader(s3pfile);

            FileInfo f = new FileInfo(filename);

            this.cleanName = f.Name.Replace(f.Extension, "");

            uint   version = readFile.ReadUInt32();
            string s3pack  = Encoding.ASCII.GetString(readFile.ReadBytes(7));

            if (s3pack != "TS3Pack")
            {
                errorMessage = "Not a Sims3Pack file";
                readFile.Close();
                s3pfile.Close();
                return(false);
            }
            this.filename = filename;

            uint unknown = readFile.ReadUInt16();

            int xmlLength = readFile.ReadInt32();

            byte[] xmlBytes = readFile.ReadBytes(xmlLength);

            MemoryStream  mem = new MemoryStream(xmlBytes);
            XPathDocument doc = new XPathDocument(mem);

            Stack nameStack   = getXmlFields(doc, "//PackagedFile/Name");
            Stack offsetStack = getXmlFields(doc, "//PackagedFile/Offset");
            Stack lengthStack = getXmlFields(doc, "//PackagedFile/Length");

            int sCount = nameStack.Count;

            for (int i = 0; i < sCount; i++)
            {
                string tempName   = nameStack.Pop().ToString();
                int    tempOffset = Convert.ToInt32(offsetStack.Pop().ToString());
                int    length     = Convert.ToInt32(lengthStack.Pop().ToString());

                string extension = tempName.Substring(tempName.LastIndexOf("."));
                if (extension == ".package")
                {
                    Sims3PackFileInfo s3fileInfo = new Sims3PackFileInfo();
                    s3fileInfo.name = tempName;
                    //s3fileInfo.cleanName = sanitiseString(tempName.Replace(".package", "")) + ".package";
                    s3fileInfo.offset = tempOffset;
                    s3fileInfo.length = length;

                    packagedFiles.Add(s3fileInfo);
                    s3fileInfo = null;
                }
            }


            //string xmlStuff = Encoding.ASCII.GetString(xmlBytes);

            // Close the files since we'll be working purely with the XML here.
            readFile.Close();
            s3pfile.Close();

            //rawXML = xmlStuff;

            return(true);
        }
コード例 #6
0
 public bool extractFile(Sims3PackFileInfo file, string destinationFolder)
 {
     return(extractFile(file, destinationFolder, true));
 }
コード例 #7
0
        public void ProcessFiles()
        {
            ProgressBar1.Minimum = 0;

            DateTime start = new DateTime();

            start = DateTime.Now;

            int    numFiles = this.fileList.Count;
            string filename = "";

            ProgressBar1.Maximum = numFiles + 1;

            for (int i = 0; i < numFiles; i++)
            {
                try
                {
                    filename = this.fileList.Pop().ToString();

                    Sims3Pack s3pack = new Sims3Pack();
                    if (s3pack.load(filename) == true)
                    {
                        // Okay so now we should have a list of Sims3PackFileInfo stuff in the packagedFiles Array
                        //Sims3PackFileInfo s3fileinfo = new Sims3PackFileInfo();

                        FileInfo f = new FileInfo(filename);

                        toolStripStatusLabel1.Text = "Extracting " + f.Name;
                        statusStrip1.Refresh();

                        for (int j = 0; j < s3pack.packagedFiles.Count; j++)
                        {
                            Sims3PackFileInfo s3fileinfo = (Sims3PackFileInfo)s3pack.packagedFiles[j];
                            // Only install .package files
                            string extension = s3fileinfo.name.Substring(s3fileinfo.name.LastIndexOf("."));
                            //Console.WriteLine(s3fileinfo.name + " " + extension);
                            if (extension.ToLower() == ".package")
                            {
                                if (s3pack.extractFile(s3fileinfo, txtDestinationFolder.Text, checkBox1.Checked) == true)
                                {
                                }
                            }
                        }

                        ProgressBar1.Value++;
                    }
                    s3pack = null;
                }
                catch (System.Exception excpt)
                {
                    MessageBox.Show(excpt.Message + " " + excpt.StackTrace);
                }
            }

            DateTime stop = new DateTime();

            stop = DateTime.Now;
            int timeTaken = (stop.Second - start.Second);

            if (timeTaken == 0)
            {
                timeTaken++;
            }

            double filesPerSecond = Math.Round((double)(numFiles / timeTaken), 2);

            toolStripStatusLabel1.Text = "Done " + numFiles + " files in " + timeTaken + " seconds with " + filesPerSecond + " files per second.";
            ProgressBar1.Value         = 0;
        }