示例#1
0
 private void button1_Click(object sender, EventArgs e)
 {
     try
     {
         System.Threading.ThreadStart ts = delegate
         {
             ParrotLibs.Streams.Reader OR = Original.Reader();
             ParrotLibs.Streams.Writer D  = Destination.Writer();
             OR.BaseStream.Position = 0;
             D.BaseStream.Position  = 0;
             for (long i = 0; i < Original.Length; i += 0x6000)
             {
                 D.Write(OR.ReadBytes(0x6000));
                 progressBar1.Invoke((MethodInvoker) delegate
                 {
                     try
                     {
                         progressBar1.Maximum = (int)(Original.Length >> 4);
                         progressBar1.Value   = (int)(((i >> 8) < 0) ? 0 : i >> 4);
                     }
                     catch { }
                 });
             }
             OR.Close();
             D.Close();
         };
         System.Threading.Thread t = new System.Threading.Thread(ts);
         t.Start();
     }
     catch (Exception x) { MessageBox.Show(x.Message); }
 }
        void AfterSelect()
        {
            listView1.Items.Clear();

            System.IO.DirectoryInfo clicked = new System.IO.DirectoryInfo((string)treeView1.SelectedNode.Tag);
            foreach (System.IO.DirectoryInfo di in clicked.GetDirectories())
            {
                ListViewItem li = new ListViewItem(di.Name);
                li.SubItems.Add("File Folder");
                li.SubItems.Add("");
                li.SubItems.Add(di.LastWriteTime.ToString());
                li.SubItems.Add((VariousFunctions.IsTitleIDFolder(di.Name)) ? Party_Buffalo.Cache.CheckCache(di.Name) : "");
                li.Tag        = new object[] { di.FullName, true };
                li.ImageIndex = 0;
                listView1.Items.Add(li);
            }

            foreach (System.IO.FileInfo fi in clicked.GetFiles())
            {
                ListViewItem li = new ListViewItem(fi.Name);
                li.SubItems.Add("File");
                li.SubItems.Add(VariousFunctions.ByteConversion(fi.Length));
                li.SubItems.Add(fi.LastWriteTime.ToString());
                // Get the file name
                ParrotLibs.Streams.Reader br = new ParrotLibs.Streams.Reader(new System.IO.FileStream(fi.FullName, System.IO.FileMode.Open));
                if (br.BaseStream.Length > 4)
                {
                    uint header = br.ReadUInt32(true);
                    if (header == 0x434F4E20 || header == 0x4C495645 || header == 0x50495253)
                    {
                        br.BaseStream.Position = (long)ParrotLibs.Geometry.STFSOffsets.DisplayName;
                        li.SubItems.Add(br.ReadUnicodeString(0x80));
                    }
                }
                br.Close();
                li.Tag        = new object[] { fi.FullName, true };
                li.ImageIndex = 1;
                listView1.Items.Add(li);
            }
        }
示例#3
0
        public uint[] GetBlocksOccupied()
        {
            List <uint> Blocks = new List <uint>();

            Streams.Reader r = Parent.Drive.Reader();
            Blocks.Add(Parent.StartingCluster);
            byte[] Buffer     = new byte[0x1000];
            int    buffersize = 0x1000;
            long   lastoffset = 0;

            for (int i = 0; i < Blocks.Count; i++)
            {
                r.BaseStream.Position = VariousFunctions.BlockToFATOffset(Blocks[i], Parent).DownToNearestCluster(0x1000);
                // We use this so that we aren't reading the same buffer
                // a zillion times
                if (r.BaseStream.Position != lastoffset)
                {
                    lastoffset = r.BaseStream.Position;
                    Buffer     = r.ReadBytes(buffersize);
                }

                Streams.Reader r1             = new ParrotLibs.Streams.Reader(new System.IO.MemoryStream(Buffer));
                int            OffsetInBuffer = (int)(VariousFunctions.BlockToFATOffset(Blocks[i], Parent) - VariousFunctions.BlockToFATOffset(Blocks[i], Parent).DownToNearestCluster(0x1000));
                r1.BaseStream.Position = OffsetInBuffer;
                switch (Parent.PartitionInfo.EntrySize)
                {
                case 2:
                    ushort Value = r1.ReadUInt16();
                    if (Value != 0xFFFF && Value != 0xFFF8)
                    {
                        if (Value == 0)
                        {
                            EntryData ed = Parent.EntryData;
                            ed.NameSize = 0xE5;
                            CreateNewEntry(ed);
                            if (Blocks.Count > 0)
                            {
                                ClearFATChain(Blocks.ToArray());
                            }
                            throw new Exception(string.Format("Bad FAT chain in file or folder {0}\r\nEntry Offset: 0x{1}\r\nLast block in FAT: 0x{2}\r\nEntry marked as deleted to avoid further errors!  Please reload this device", Parent.FullPath, Parent.EntryOffset.ToString("X"), Blocks.Last().ToString("X")));
                        }
                        Blocks.Add(Value);
                    }
                    break;

                case 4:
                    uint Value2 = r1.ReadUInt32();
                    if (Value2 != 0xFFFFFFFF && Value2 != 0xFFFFFFF8)
                    {
                        if (Value2 == 0)
                        {
                            EntryData ed = Parent.EntryData;
                            ed.NameSize = 0xE5;
                            CreateNewEntry(ed);
                            if (Blocks.Count > 0)
                            {
                                ClearFATChain(Blocks.ToArray());
                            }
                            throw new Exception(string.Format("Bad FAT chain in file or folder {0}\r\nEntry Offset: 0x{1}\r\nLast block in FAT: 0x{2}\r\nEntry marked as deleted to avoid further errors!  Please reload this device", Parent.FullPath, Parent.EntryOffset.ToString("X"), Blocks.Last().ToString("X")));
                        }
                        Blocks.Add(Value2);
                    }
                    break;
                }
                r1.Close();
            }
            return(Blocks.ToArray());
        }
示例#4
0
        public EntryData[] EntryDataFromBlock(uint Block)
        {
            bool             Break = false;
            List <EntryData> eList = new List <EntryData>();

            // Get our binary reader
            Streams.Reader r1 = Parent.Drive.Reader();
            r1.BaseStream.Position = VariousFunctions.GetBlockOffset(Block, Parent);

            /* Parent.PartitionInfo.Clusters / 0x40 / 0x8 because if each
             * entry is 0x40 in length and the cluster is filled to the
             * max with cluster entries, then we can do division to get
             * the number of entries that would be in that cluster
             * the 0x8 part is because on drives we have to read in intervals
             * of 0x200 right?  So if Parent.PartitionInfo.Clusters / 0x40 = 0x100,
             * then that means that there are 0x100 entries per cluster...
             * divide that by 8 (the number of clusters within a 0x200 interval) and
             * that's how many shits we have to go forward */
            for (int j = 0; j < Parent.PartitionInfo.ClusterSize / 0x1000; j++)
            {
                // Increment our position
                // Open another reader using a memory stream
                long           r1Position = r1.BaseStream.Position;
                Streams.Reader r          = new ParrotLibs.Streams.Reader(new System.IO.MemoryStream(r1.ReadBytes(0x1000)));
                for (int k = 0; k < (0x1000 / 0x40); k++)
                {
                    // Check to see if we've passed the last entry...
                    uint val = r.ReadUInt32();
                    if (val == 0x0 || val == 0xFFFFFFFF)
                    {
                        Break = true;
                        break;
                    }
                    // Go back four bytes because we just checked the next four...
                    r.BaseStream.Position -= 4;
                    long      StartOffset = r.BaseStream.Position;
                    EntryData e           = new EntryData();
                    e.EntryOffset = r.BaseStream.Position + r1Position;
                    e.NameSize    = r.ReadByte();
                    e.Flags       = r.ReadByte();

                    /* Because some f*****g smart guy decided to put the
                     * deleted flag in the name size field, we have to check
                     * if it's deleted or not...*/
                    if (e.NameSize == 0xE5)
                    {
                        // Fuckers
                        e.Name = Encoding.ASCII.GetString(r.ReadBytes(0x2A));
                    }
                    else
                    {
                        e.Name = Encoding.ASCII.GetString(r.ReadBytes(e.NameSize));
                    }
                    r.BaseStream.Position = StartOffset + 0x2C;
                    e.StartingCluster     = r.ReadUInt32();
                    e.Size         = r.ReadUInt32();
                    e.CreationDate = r.ReadUInt16();
                    e.CreationTime = r.ReadUInt16();
                    e.AccessDate   = r.ReadUInt16();
                    e.AccessTime   = r.ReadUInt16();
                    e.ModifiedDate = r.ReadUInt16();
                    e.ModifiedTime = r.ReadUInt16();
                    eList.Add(e);
                }
                r.Close();
                if (Break)
                {
                    break;
                }
            }
            return(eList.ToArray());
        }
示例#5
0
        void EntryAction_HandleCreated(object sender, EventArgs e)
        {
            if (Aero)
            {
                mTaskDialog = new TaskDialog();
            }
            System.Threading.ThreadStart ts = delegate
            {
#if TRACE
                try
                {
#endif
                //while (true)//(!this.IsHandleCreated || !progressBar1.IsHandleCreated || !label1.IsHandleCreated || !lPercent.IsHandleCreated || !button1.IsHandleCreated)
                //{
                //    try
                //    {
                //        this.Invoke((MethodInvoker)delegate { });
                //        progressBar1.Invoke((MethodInvoker)delegate { });
                //        label1.Invoke((MethodInvoker)delegate { });
                //        lPercent.Invoke((MethodInvoker)delegate { });
                //        button1.Invoke((MethodInvoker)delegate { });
                //        break;
                //    }
                //    catch(Exception E) { Application.DoEvents(); }
                //}
                if (xDrive != null && mMethod == Method.Backup || mMethod == Method.ExtractJ || mMethod == Method.ExtractSS || mMethod == Method.Restore)
                {
                    switch (mMethod)
                    {
                    case Method.Backup:
                        this.Invoke((MethodInvoker) delegate
                        {
                            this.Icon = Properties.Resources.Add;
                        });
                        ParrotLibs.Streams.Reader r = xDrive.Reader();
                        ParrotLibs.Streams.Writer w = new ParrotLibs.Streams.Writer(new System.IO.FileStream(OutPath, System.IO.FileMode.Create));
                        int ReadLength = 0x200;
                        if (xDrive.Length % 0x100000 == 0)
                        {
                            ReadLength = 0x100000;
                        }
                        else if (xDrive.Length % 0x40000 == 0)
                        {
                            ReadLength = 0x40000;
                        }
                        else if (xDrive.Length % 0x10000 == 0)
                        {
                            ReadLength = 0x10000;
                        }
                        else if (xDrive.Length % 0x5000 == 0)
                        {
                            ReadLength = 0x5000;
                        }
                        for (int i = 0; i < xDrive.Length / ReadLength; i++)
                        {
                            if (Cancel)
                            {
                                break;
                            }
                            w.Write(r.ReadBytes(ReadLength));
                            p_ProgressBar.Invoke((MethodInvoker) delegate
                            {
                                try
                                {
                                    p_ProgressBar.Maximum = (int)(xDrive.Length / ReadLength);
                                    p_ProgressBar.Value   = (i + 1);
                                    if (Windows7)
                                    {
                                        tm.SetProgressValue(p_ProgressBar.Value, p_ProgressBar.Maximum);
                                    }
                                }
                                catch { }
                            });
                            this.Invoke((MethodInvoker) delegate
                            {
                                this.Text = "Backing Up Drive";
                            });
                            l_Percent.Invoke((MethodInvoker) delegate
                            {
                                l_Percent.Text = (((decimal)(i + 1) / (decimal)(xDrive.Length / ReadLength)) * 100).ToString("#") + "%";
                            });
                        }
                        w.Close();
                        break;

                    case Method.ExtractSS:
                        this.Invoke((MethodInvoker) delegate
                        {
                            this.Icon = Properties.Resources.Add;
                        });
                        //Create our io for the drive
                        ParrotLibs.Streams.Reader io = xDrive.Reader();
                        //Go to the location of the security sector
                        io.BaseStream.Position = 0x2000;
                        //Create our ref io for the file
                        ParrotLibs.Streams.Writer bw = new ParrotLibs.Streams.Writer(new System.IO.FileStream(OutPath, System.IO.FileMode.Create));
                        //Read the sector.  The size is an estimation, since I have no idea how big it really is
                        bw.Write(io.ReadBytes(0xE00));
                        //Close our io
                        bw.Close();
                        break;

                    case Method.ExtractJ:
                        this.Invoke((MethodInvoker) delegate
                        {
                            this.Icon = Properties.Resources.Add;
                        });
                        //Create our io for the drive
                        ParrotLibs.Streams.Reader io2 = xDrive.Reader();
                        //Go to the location of the security sector
                        io2.BaseStream.Position = 0x800;
                        //Create our ref io for the file
                        ParrotLibs.Streams.Writer bw2 = new ParrotLibs.Streams.Writer(new System.IO.FileStream(OutPath, System.IO.FileMode.Create));
                        //Read the sector.  The size is an estimation, since I have no idea how big it really is
                        bw2.Write(io2.ReadBytes(0x400));
                        //Close our io
                        bw2.Close();
                        break;

                    case Method.Restore:
                        this.Invoke((MethodInvoker) delegate
                        {
                            this.Icon = Properties.Resources.Remove;
                        });
                        if (MessageBox.Show("WARNING: Restoring a drive that does not match your current one can cause for data to not be read correctly by the Xbox 360, or for other unforseen problems!  Please make sure you know what you're doing before continuing.  Are you sure you want to continue?", "WARNING AND STUFF", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                        {
                            if (MessageBox.Show("This is your last chance to stop!  Are you POSITIVE you want to continue?", "Last Chance!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                            {
                                ParrotLibs.Streams.Reader r2 = new ParrotLibs.Streams.Reader(new System.IO.FileStream(OutPath, System.IO.FileMode.Open));
                                ParrotLibs.Streams.Writer w2 = xDrive.Writer();
                                int ReadLength2 = 0x200;
                                if (xDrive.Length % 0x4000 != 0)
                                {
                                    ReadLength2 = 0x4000;
                                }
                                else
                                {
                                    for (int i = 0x300000; i > 0x200; i -= 0x1000)
                                    {
                                        if (xDrive.Length % i == 0)
                                        {
                                            ReadLength2 = i;
                                            break;
                                        }
                                    }
                                }
                                for (int i = 0; i < xDrive.Length / ReadLength2; i++)
                                {
                                    if (Cancel)
                                    {
                                        break;
                                    }
                                    w2.Write(r2.ReadBytes(ReadLength2));
                                    p_ProgressBar.Invoke((MethodInvoker) delegate
                                    {
                                        try
                                        {
                                            p_ProgressBar.Maximum = (int)(xDrive.Length / ReadLength2);
                                            p_ProgressBar.Value   = (i + 1);
                                            if (Windows7)
                                            {
                                                tm.SetProgressValue(p_ProgressBar.Value, p_ProgressBar.Maximum);
                                            }
                                        }
                                        catch { }
                                    });
                                    this.Invoke((MethodInvoker) delegate
                                    {
                                        this.Text = "Restoring Drive";
                                    });
                                    l_Percent.Invoke((MethodInvoker) delegate
                                    {
                                        l_Percent.Text = (((decimal)(i + 1) / (decimal)(xDrive.Length / ReadLength2)) * 100).ToString("#") + "%";
                                    });
                                }
                                r2.Close();
                            }
                        }
                        break;
                    }
                }
                else
                {
                    Folder ParentFolder = null;
                    this.Invoke((MethodInvoker) delegate
                    {
                        ParentFolder = Parent;
                    });

                    switch (mMethod)
                    {
                    // 提取游戏文件
                    case Method.Extract:
                    {
#if DEBUG
                        System.Diagnostics.Stopwatch sStopwatch = new System.Diagnostics.Stopwatch();
                        if (Timer)
                        {
                            sStopwatch.Start();
                        }
#endif
                        this.Invoke((MethodInvoker) delegate
                            {
                                this.Icon = Properties.Resources.Add;
                            });
                        foreach (Entry sEntry in Entries)
                        {
                            // 提取的元素不是文件夹
                            if (sEntry.IsFolder == false)
                            {
                                ((File)sEntry).FileAction += new ParrotLibs.Structs.FileActionChanged(EntryAction_FileAction);
                                this.Invoke((MethodInvoker) delegate
                                    {
                                        this.Text = sEntry.FullPath;
                                    });

                                l_Percent.Invoke((MethodInvoker) delegate
                                    {
                                        l_Percent.Text = sEntry.Name;
                                    });

                                // Check to see if we're batch-extracting...
                                if (Entries.Length == 1)
                                {
                                    ((File)sEntry).Extract(OutPath);
                                }
                                else
                                {
                                    ((File)sEntry).Extract(OutPath + "\\" + sEntry.Name);
                                }
                            }
                            else
                            {
                                ((Folder)sEntry).FolderAction += new ParrotLibs.Structs.FolderActionChanged(EntryAction_FolderAction);
                                ((Folder)sEntry).Extract(OutPath, EntriesToSkip);
                            }
                            if (Cancel)
                            {
                                break;
                            }
                        }
#if DEBUG
                        if (Timer)
                        {
                            sStopwatch.Stop();
                            MessageBox.Show(string.Format("{0}:{1}:{2}", sStopwatch.Elapsed.Minutes, sStopwatch.Elapsed.Seconds, sStopwatch.Elapsed.Milliseconds));
                        }
#endif
                        break;
                    }

                    // 删除游戏文件
                    case Method.Delete:
                    {
                        this.Invoke((MethodInvoker) delegate
                            {
                                this.Icon = Properties.Resources.Remove;
                            });

                        foreach (Entry sEntry in Entries)
                        {
                            if (Cancel == true)
                            {
                                break;
                            }
                            else
                            {
                                // 要删除的是文件夹
                                if (sEntry.IsFolder == true)
                                {
                                    Folder sCurrent = ((Folder)sEntry);
                                    sCurrent.ResetFolderAction();
                                    sCurrent.FolderAction += new ParrotLibs.Structs.FolderActionChanged(EntryAction_FolderAction);
                                    sCurrent.Delete();
                                }
                                // 要删除的是文件
                                else
                                {
                                    this.Invoke((MethodInvoker) delegate
                                        {
                                            this.Text = sEntry.FullPath;
                                        });

                                    l_Percent.Invoke((MethodInvoker) delegate
                                        {
                                            l_Percent.Text = sEntry.Name;
                                        });

                                    File sCurrent = ((File)sEntry);
                                    sCurrent.FileAction += new ParrotLibs.Structs.FileActionChanged(EntryAction_FileAction);
                                    sCurrent.Delete();
                                }
                            }
                        }

                        break;
                    }

                    // 添加新游戏
                    case Method.Inject:
                    {
                                #if DEBUG
                        System.Diagnostics.Stopwatch sw2 = new System.Diagnostics.Stopwatch();
                        if (Timer)
                        {
                            sw2.Start();
                        }
                                #endif
                        this.Invoke((MethodInvoker) delegate
                            {
                                this.Icon = Properties.Resources.Add;
                            });

                        if (ParentFolder != null)
                        {
                            ParentFolder.ResetFolderAction();
                            ParentFolder.FolderAction += new ParrotLibs.Structs.FolderActionChanged(EntryAction_FolderAction);
                            List <ParrotLibs.Structs.ExistingEntry> Existing = new List <ParrotLibs.Structs.ExistingEntry>();
                            foreach (string sPath in Paths)
                            {
                                if (Cancel == true)
                                {
                                    break;
                                }
                                else
                                {
                                    // 导入的是文件夹
                                    if (VariousFunctions.IsFolder(sPath) == true)
                                    {
                                        // 不合并,不覆盖
                                        Existing.AddRange(ParentFolder.InjectFolder(sPath, false, false));
                                    }
                                    // 导入的是文件
                                    else
                                    {
                                        ParentFolder.FolderAction += new ParrotLibs.Structs.FolderActionChanged(EntryAction_FolderAction);
                                        ParrotLibs.Structs.WriteResult sWriteResult = ParentFolder.CreateNewFile(sPath);

                                        // 如果不能写入,则检查是否存在
                                        if (sWriteResult.CouldNotWrite == true)
                                        {
                                            ParrotLibs.Structs.ExistingEntry sExistEntry = new ParrotLibs.Structs.ExistingEntry();
                                            sExistEntry.Existing = sWriteResult.Entry;
                                            sExistEntry.NewPath  = sPath;
                                            Existing.Add(sExistEntry);
                                        }
                                    }
                                }
                            }

                            DoExisting(Existing);
                        }
                        else
                        {
                            List <ParrotLibs.Structs.ExistingEntry> Existing = new List <ParrotLibs.Structs.ExistingEntry>();
                            foreach (string s in Paths)
                            {
                                string Path = "";
                                try
                                {
                                    // XBOX360 1代磁盘类型
                                    Path = VariousFunctions.GetFATXPath(s);
                                }
                                catch (Exception x)
                                {
                                    ExceptionHandler(x);
                                    continue;
                                }
                                Folder thisFolder = xDrive.CreateDirectory("Data\\" + Path);
                                thisFolder.ResetFolderAction();
                                thisFolder.FolderAction += new ParrotLibs.Structs.FolderActionChanged(EntryAction_FolderAction);
                                if (Cancel)
                                {
                                    break;
                                }
                                if (VariousFunctions.IsFolder(s))
                                {
                                    ExceptionHandler(new Exception("Can not write folder as STFS package (silly error wording)"));
                                    continue;
                                }
                                else
                                {
                                    thisFolder.FolderAction += new ParrotLibs.Structs.FolderActionChanged(EntryAction_FolderAction);
                                    ParrotLibs.Structs.WriteResult wr = thisFolder.CreateNewFile(s);
                                    if (wr.CouldNotWrite)
                                    {
                                        ParrotLibs.Structs.ExistingEntry ex = new ParrotLibs.Structs.ExistingEntry();
                                        ex.Existing = wr.Entry;
                                        ex.NewPath  = s;
                                        Existing.Add(ex);
                                    }
                                }
                            }

                            DoExisting(Existing);
                        }
#if DEBUG
                        if (Timer)
                        {
                            sw2.Stop();
                            MessageBox.Show(string.Format("{0}:{1}:{2}", sw2.Elapsed.Minutes, sw2.Elapsed.Seconds, sw2.Elapsed.Milliseconds));
                        }
#endif
                        break;
                    }

                    case Method.Move:
                    {
                        List <ParrotLibs.Structs.WriteResult> Results = new List <ParrotLibs.Structs.WriteResult>();
                        foreach (Entry sEntry in Entries)
                        {
                            ParrotLibs.Structs.WriteResult sWriteResult = sEntry.Move(OutPath);
                            if (sWriteResult.CouldNotWrite == true)
                            {
                                Results.Add(sWriteResult);
                            }
                            else
                            {
                                // DO NOTHING
                            }
                        }

                        break;
                    }
                    }
                }
                this.Invoke((MethodInvoker) delegate { this.Close(); });
#if TRACE
            }
            catch (Exception x)
            {
                ExceptionHandler(x);
                this.Invoke((MethodInvoker) delegate { this.Close(); });
            }
#endif
            };
            t = new System.Threading.Thread(ts);
            t.Start();
        }