public PropertiesForm(Folder f)
        {
            InitializeComponent();
            xFolder = f;
            this.Text = "Properties -- " + f.Name;
            groupBox4.Enabled = false;
            groupBox1.Enabled = false;
            LoadGeneral(f);
            tabPage1.Click += new EventHandler(tabPage1_Click);
            #if DEBUG
            TabPage tabPage2 = new TabPage();
            propertyGrid1.Dock = DockStyle.Fill;
            tabPage2.Controls.Add(this.propertyGrid1);
            tabPage2.Location = new System.Drawing.Point(4, 22);
            tabPage2.Name = "tabPage2";
            tabPage2.Padding = new System.Windows.Forms.Padding(3);
            tabPage2.Size = new System.Drawing.Size(509, 320);
            tabPage2.TabIndex = 1;
            tabPage2.Text = "Entry";
            tabPage2.UseVisualStyleBackColor = true;

            tabControl1.TabPages.Add(tabPage2);
            #endif
            this.Load +=new EventHandler(PropertiesForm_Load);
        }
Example #2
0
 public SearchForm(Folder[] Partitions)
 {
     InitializeComponent();
     listView1.SetExplorerTheme();
     this.Partitions = Partitions;
     listView1.ListViewItemSorter = lvwColumnSorter;
     listView1.DoubleClick +=new EventHandler(listView1_DoubleClick);
     this.FormClosing += new FormClosingEventHandler(SearchForm_FormClosing);
     listView1.ColumnClick +=new ColumnClickEventHandler(listView1_ColumnClick);
 }
Example #3
0
 void AddFolder(Folder Parent)
 {
     listView1.Invoke((MethodInvoker)delegate
     {
         ListViewItem li = new ListViewItem(Parent.Name);
         li.Tag = Parent;
         ListViewItem.ListViewSubItem l1 = new ListViewItem.ListViewSubItem(li, Parent.EntryType);
         ListViewItem.ListViewSubItem l2 = new ListViewItem.ListViewSubItem(li, "");
         ListViewItem.ListViewSubItem l3 = new ListViewItem.ListViewSubItem(li, Parent.ModifiedDate.ToString());
         li.SubItems.Add(l1);
         li.SubItems.Add(l2);
         li.SubItems.Add(l3);
         if (stfsInfo.Checked && Parent.IsTitleIDFolder)
         {
             if (Parent.IsKnownFolder)
             {
                 for (int i = 0; i < CLKsFATXLib.VariousFunctions.Known.Length; i++)
                 {
                     if (Parent.Name.ToLower() == CLKsFATXLib.VariousFunctions.Known[i].ToLower())
                     {
                         ListViewItem.ListViewSubItem lsi = new ListViewItem.ListViewSubItem(li, CLKsFATXLib.VariousFunctions.KnownEquivilent[i]);
                         li.SubItems.Add(lsi);
                         break;
                     }
                 }
             }
             else
             {
                 ListViewItem.ListViewSubItem lsi = new ListViewItem.ListViewSubItem(li, Parent.GameName());
                 li.SubItems.Add(lsi);
             }
         }
         else
         {
             ListViewItem.ListViewSubItem lsi = new ListViewItem.ListViewSubItem(li, "");
             li.SubItems.Add(lsi);
         }
         ListViewItem.ListViewSubItem l4 = new ListViewItem.ListViewSubItem(li, Parent.FullPath);
         li.SubItems.Add(l4);
         listView1.Invoke((MethodInvoker)delegate { listView1.Items.Add(li); });
     });
 }
Example #4
0
        void AddNodes(TreeNode current, Folder parent, bool AllTheWay, bool AddListviewItem)
        {
            List<ListViewItem> lvi = new List<ListViewItem>();
            Folder[] Folders = parent.Folders();
            for (int i = 0; i < Folders.Length; i++)
            {
                ListViewItem li = new ListViewItem(Folders[i].Name);
                li.Tag = Folders[i];
                li.SubItems.Add(Folders[i].EntryType);
                li.SubItems.Add("");
                li.SubItems.Add(Folders[i].ModifiedDate.ToString());
                li.ImageIndex = 0;
                li.Name = Folders[i].Name;
                TreeNode tn = new TreeNode(Folders[i].Name);
                tn.Name = Folders[i].Name;
                string Label = Cache.CheckCache(Folders[i].FullPath);
                if (Label != null)
                {
                    tn.Text += " | " + Label;
                    li.SubItems.Add(Label);
                }

                if (Folders[i].IsTitleIDFolder)
                {
                    if (Properties.Settings.Default.loadTIDNames)
                    {
                        if (Cache.CheckCache(Folders[i].Name) != null)
                        {
                            tn.Text += " | " + Cache.CheckCache(Folders[i].Name);
                            li.SubItems.Add(Cache.CheckCache(Folders[i].Name));
                        }
                        // Didn't find it, need to grab that shit
                        else if (!Folders[i].IsKnownFolder)
                        {
                            if (Folders[i].GameName() != null && Folders[i].GameName() != "")
                            {
                                if (!Folders[i].IsKnownFolder)
                                {
                                    Cache.AddID(Folders[i].Name, Folders[i].GameName());
                                }
                                tn.Text += " | " + Folders[i].GameName();
                                li.SubItems.Add(Folders[i].GameName());
                            }
                        }
                    }

                    if (Properties.Settings.Default.SaveIcons && (!Folders[i].IsKnownFolder || Folders[i].Name.ToLower() == "fffe07d1"))
                    {
                        // Getting the icon
                        if (!Folders[i].IsKnownFolder || Folders[i].Name.ToLower() == "FFFE07D1".ToLower())
                        {
                            if (!siL.Images.Keys.Contains(Folders[i].Name.ToUpper()))
                            {
                                // Check the cache for the icon
                                if (Cache.GetIcon(Folders[i].Name) != null)
                                {
                                    siL.Images.Add(Folders[i].Name.ToUpper(), Cache.GetIcon(Folders[i].Name));
                                    liL.Images.Add(Folders[i].Name.ToUpper(), Cache.GetIcon(Folders[i].Name));
                                    tn.ImageKey = Folders[i].Name.ToUpper();
                                    tn.SelectedImageKey = tn.ImageKey;
                                    li.ImageKey = Folders[i].Name.ToUpper();
                                }
                                else
                                {
                                    if ( Folders[i].GameName() != null && Folders[i].GameIcon() != null)
                                    {
                                        Cache.AddIcon(Folders[i].GameIcon(), Folders[i].Name);
                                        siL.Images.Add(Folders[i].Name.ToUpper(), Folders[i].GameIcon());
                                        liL.Images.Add(Folders[i].Name.ToUpper(), Folders[i].GameIcon());
                                        //treeView1.ImageList = SmallListForFATX;
                                        //listView1.SmallImageList = SmallListForFATX;
                                        //listView1.LargeImageList = LargeListForFATX;
                                        tn.ImageKey = Folders[i].Name.ToUpper();
                                        tn.SelectedImageKey = tn.ImageKey;
                                        li.ImageKey = Folders[i].Name.ToUpper();
                                    }
                                }
                            }
                            else
                            {
                                tn.ImageKey = Folders[i].Name.ToUpper();
                                tn.SelectedImageKey = tn.ImageKey;
                                li.ImageKey = Folders[i].Name.ToUpper();
                            }
                        }
                    }
                }
                // For profile folders
                else if (Properties.Settings.Default.SaveIcons)
                {
                    Image I = Cache.GetIcon(Folders[i].Name);
                    if (I != null)
                    {
                        treeView1.Invoke((MethodInvoker)delegate
                        {
                            if (!siL.Images.ContainsKey(Folders[i].Name.ToUpper()))
                            {
                                siL.Images.Add(Folders[i].Name.ToUpper(), I);
                                liL.Images.Add(Folders[i].Name.ToUpper(), I);
                            }
                            tn.ImageKey = Folders[i].Name.ToUpper();
                            tn.SelectedImageKey = tn.ImageKey;
                            li.ImageKey = Folders[i].Name.ToUpper();
                        });
                    }
                    else
                    {
                        File FILE = Folders[i].IsProfileFolder();
                        if (FILE != null)
                        {
                            I = FILE.ContentIcon();
                            if (I != null)
                            {
                                Cache.AddIcon(I, Folders[i].Name);
                                if (!siL.Images.ContainsKey(Folders[i].Name.ToUpper()))
                                {
                                    siL.Images.Add(Folders[i].Name.ToUpper(), I);
                                    liL.Images.Add(Folders[i].Name.ToUpper(), I);
                                }
                                tn.ImageKey = Folders[i].Name.ToUpper();
                                tn.SelectedImageKey = tn.ImageKey;
                                li.ImageKey = Folders[i].Name.ToUpper();
                            }
                        }
                    }
                }
                tn.ToolTipText = tn.Text;
                tn.Tag = Folders[i];

                // If we already have a treenode under the current node with
                // the same name...
                if (current.Nodes.Find(tn.Name, false).Length != 0)
                {

                }
                else
                {
                    AddNodes(tn, Folders[i], AllTheWay, false);
                    current.Nodes.Add(tn);
                }

                if (!AllTheWay && AddListviewItem)
                {
                    if (listView1.Items.Find(li.Name, false).Length == 0)
                    {
                        lvi.Add(li);
                    }
                }
            }
            listView1.Items.AddRange(lvi.ToArray());
        }
Example #5
0
        void AddNode(Folder f, TreeNode n, ListViewCreateItem CreateListViewItem)
        {
            ListViewItem li = new ListViewItem(f.Name);
            li.Tag = f;
            li.SubItems.Add(f.EntryType);
            li.SubItems.Add("");
            li.SubItems.Add(f.ModifiedDate.ToString());
            li.ImageIndex = 0;
            li.Name = f.Name;
            TreeNode tn = new TreeNode(f.Name);
            tn.Name = f.Name;
            // Check our cache to see if we have cached this title ID

            string Label = Cache.CheckCache(f.FullPath);
            if (Label != null)
            {
                tn.Text += " | " + Label;
                li.SubItems.Add(Label);
            }

            if (f.IsTitleIDFolder)
            {
                if (Properties.Settings.Default.loadTIDNames)
                {
                    if (Cache.CheckCache(f.Name) != null)
                    {
                        tn.Text += " | " + Cache.CheckCache(f.Name);
                        li.SubItems.Add(Cache.CheckCache(f.Name));
                    }
                    // Didn't find it, need to grab that shit
                    else if (!f.IsKnownFolder )
                    {
                        if (f.GameName() != null && f.GameName() != "")
                        {
                            if (!f.IsKnownFolder)
                            {
                                Cache.AddID(f.Name, f.GameName());
                            }
                            tn.Text += " | " + f.GameName();
                            li.SubItems.Add(f.GameName());
                        }
                    }
                }

                if (Properties.Settings.Default.SaveIcons)
                {
                    // Getting the icon
                    if (!f.IsKnownFolder || f.Name.ToLower() == "FFFE07D1".ToLower())
                    {
                        if (!siL.Images.Keys.Contains(f.Name.ToUpper()))
                        {
                            // Check the cache for the icon
                            if (Cache.GetIcon(f.Name) != null)
                            {
                                treeView1.Invoke((MethodInvoker)delegate
                                {
                                    if (!siL.Images.ContainsKey(f.Name.ToUpper()))
                                    {
                                        siL.Images.Add(f.Name.ToUpper(), Cache.GetIcon(f.Name));
                                        liL.Images.Add(f.Name.ToUpper(), Cache.GetIcon(f.Name));
                                    }
                                    tn.ImageKey = f.Name.ToUpper();
                                    tn.SelectedImageKey = tn.ImageKey;
                                    li.ImageKey = f.Name.ToUpper();
                                });
                            }
                            else
                            {
                                if (f.GameIcon() != null)
                                {
                                    Cache.AddIcon(f.GameIcon(), f.Name);
                                    treeView1.Invoke((MethodInvoker)delegate
                                    {
                                        if (!siL.Images.ContainsKey(f.Name.ToUpper()))
                                        {
                                            siL.Images.Add(f.Name.ToUpper(), f.GameIcon());
                                            liL.Images.Add(f.Name.ToUpper(), f.GameIcon());
                                        }
                                        tn.ImageKey = f.Name.ToUpper();
                                        tn.SelectedImageKey = tn.ImageKey;
                                        li.ImageKey = f.Name.ToUpper();
                                    }
                                    );
                                }
                            }
                        }
                        else
                        {
                            tn.ImageKey = f.Name.ToUpper();
                            tn.SelectedImageKey = tn.ImageKey;
                            li.ImageKey = f.Name.ToUpper();
                        }
                    }
                        // For profile folders
                    else
                    {
                        Image I = Cache.GetIcon(f.Name);
                        if (I != null)
                        {
                            treeView1.Invoke((MethodInvoker)delegate
                            {
                                if (!siL.Images.ContainsKey(f.Name.ToUpper()))
                                {
                                    siL.Images.Add(f.Name.ToUpper(), I);
                                    liL.Images.Add(f.Name.ToUpper(), I);
                                }
                                tn.ImageKey = f.Name.ToUpper();
                                tn.SelectedImageKey = tn.ImageKey;
                                li.ImageKey = f.Name.ToUpper();
                            });
                        }
                        else
                        {
                            File FILE = f.IsProfileFolder();
                            if (FILE != null)
                            {
                                I = FILE.ContentIcon();
                                if (I != null)
                                {
                                    Cache.AddIcon(I, f.Name);
                                    if (!siL.Images.ContainsKey(f.Name.ToUpper()))
                                    {
                                        siL.Images.Add(f.Name.ToUpper(), I);
                                        liL.Images.Add(f.Name.ToUpper(), I);
                                    }
                                    tn.ImageKey = f.Name.ToUpper();
                                    tn.SelectedImageKey = tn.ImageKey;
                                    li.ImageKey = f.Name.ToUpper();
                                }
                            }
                        }
                    }
                }
            }
            tn.ToolTipText = tn.Text;
            tn.Tag = (Folder)f;
            treeView1.Invoke((MethodInvoker)delegate
            {
                n.Nodes.Add(tn);
                if (CreateListViewItem == ListViewCreateItem.DecideForMeNigga)
                {
                    if (((Folder)n.Tag).FullPath == treeView1.SelectedNode.RealPath())
                    {
                        listView1.Invoke((MethodInvoker)delegate { listView1.Items.Add(li); });
                    }
                }
                else if (CreateListViewItem == ListViewCreateItem.FuckYes)
                {
                    listView1.Invoke((MethodInvoker)delegate { listView1.Items.Add(li); });
                }
            });
        }
Example #6
0
 private string GetNewFolderName(Folder f)
 {
     int FoldersFound = 0;
     string NewName = "New Folder";
     foreach (Folder g in f.Folders())
     {
         if (g.Name == NewName)
         {
             FoldersFound++;
             NewName = "New Folder (" + FoldersFound.ToString() + ")";
         }
     }
     return NewName;
 }
 /// <summary>
 /// Provides partition/FAT information
 /// </summary>
 public PartitionFunctions(Drive Drive, Folder partition)
 {
     FATXDrive = Drive;
     Partition = partition.PartitionInfo;
     ProcessBootSector();
 }
 public long GetNewEntryOffset(Folder Destination)
 {
     // Go to the last block since we want to speed things up and not have to go
     // through all of them
     EntryData[] Entries = EntryDataFromBlock(Destination.BlocksOccupied[Destination.BlocksOccupied.Length - 1]);
     if (Entries.Length == 0)
     {
         return Destination.StartingOffset;
     }
     // If there isn't the maximum amount of entries for a cluster...
     if (Entries.Length < Destination.PartitionInfo.ClusterSize / 0x40)
     {
         foreach (EntryData e in Entries)
         {
             if (e.NameSize == 0xE5)
             {
                 return e.EntryOffset;
             }
         }
         return Entries[Entries.Length - 1].EntryOffset + 0x40;
     }
     // Max amount of entries, let's add another cluster to our parent...
     else
     {
         uint[] NewBlocks = new uint[Destination.BlocksOccupied.Length + 1];
         Array.Copy(Destination.BlocksOccupied, NewBlocks, Destination.BlocksOccupied.Length);
         NewBlocks[NewBlocks.Length - 1] = Destination.Drive.GetFreeBlocks((Folder)Destination, 1, 0, 0, false)[0];
         byte[] FF = new byte[Destination.PartitionInfo.ClusterSize];
         for (int i = 0; i < FF.Length; i++)
         {
             FF[i] = 0xFF;
         }
         Streams.Writer w = Destination.Drive.Writer();
         w.BaseStream.Position = VariousFunctions.BlockToFATOffset(NewBlocks[NewBlocks.Length - 1], Destination);
         w.Write(FF);
         Destination.BlocksOccupied = NewBlocks;
         return VariousFunctions.BlockToFATOffset(NewBlocks[NewBlocks.Length - 1], Destination);
     }
 }
Example #9
0
 public Folder[] Folders()
 {
     // If all of those guys are null, that means we have to re-load them.
     if (cachedFolders == null && cachedFiles == null && cachedDeletedFiles == null && cachedDeletedFolders == null)
     {
         object[] entries = new EntryFunctions(this).GetEntries(this);
         cachedFiles = (List<File>)entries[0];
         cachedFolders = (List<Folder>)entries[1];
         cachedDeletedFiles = (List<File>)entries[2];
         cachedDeletedFolders = (List<Folder>)entries[3];
     }
     if (ReturnDeletedEntries)
     {
         foreach (Folder f in cachedDeletedFolders)
         {
             f.ReturnDeletedEntries = this.ReturnDeletedEntries;
         }
     }
     if (ReturnDeletedEntries)
     {
         Folder[] list = new Folder[cachedFolders.Count + cachedDeletedFolders.Count];
         Array.Copy(cachedFolders.ToArray(), 0, list, 0, cachedFolders.Count);
         Array.Copy(cachedDeletedFolders.ToArray(), 0, list, cachedFolders.Count, cachedDeletedFolders.Count);
         return list;
     }
     return cachedFolders.ToArray();
 }
 public EntryData[] GetEntryData(Folder Parent)
 {
     List<EntryData> eList = new List<EntryData>();
     for (int i = 0; i < Parent.BlocksOccupied.Length; i++)
     {
         eList.AddRange(EntryDataFromBlock(Parent.BlocksOccupied[i]));
     }
     return eList.ToArray();
 }
        public object[] GetEntries(Folder Parent)
        {
            List<Folder> cachedFolders = new List<Folder>();
            List<Folder> cachedDeletedFolders = new List<Folder>();
            List<File> cachedFiles = new List<File>();
            List<File> cachedDeletedFiles = new List<File>();
            EntryData[] Entries = GetEntryData(Parent);

            for (int i = 0; i < Entries.Length; i++)
            {
                EntryData newEdata = Entries[i];
                bool Deleted = false;
                if (newEdata.NameSize == 0xE5)
                {
                    // Remove the question marks and shit
                    try
                    {
                        newEdata.Name = newEdata.Name.Remove(newEdata.Name.IndexOf('?'));
                        newEdata.NameSize = (byte)newEdata.Name.Length;
                    }
                    catch
                    {
                        try
                        {
                            if (newEdata.Name.Contains("\0"))
                            {
                                newEdata.Name = newEdata.Name.Remove(newEdata.Name.IndexOf("\0"));
                                newEdata.NameSize = (byte)newEdata.Name.Length;
                            }
                            else
                            {
                                newEdata.NameSize = 0x2A;
                            }
                        }
                        catch
                        {
                            newEdata.NameSize = 0x2A;
                        }
                    }
                    Deleted = true;
                }
                List<Geometry.Flags> FL = new List<Geometry.Flags>();
                // Read bit zero, mask the rest of that shit
                for (short s = 1, j = 0; s <= 80; s <<= 1, j++)
                {
                    if (((newEdata.Flags & s) >> j) == 1)
                    {
                        FL.Add((Geometry.Flags)Enum.Parse(typeof(Geometry.Flags), Enum.GetName(typeof(Geometry.Flags), j)));
                    }
                }
                // Folder
                if (newEdata.StartingCluster != 0 && newEdata.Size == 0 && FL.Contains(Geometry.Flags.Directory))
                {
                    Folder f = new Folder(Parent.PartitionInfo, newEdata, Parent.Drive);
                    f.FullPath = Parent.FullPath + "\\" + f.Name;
                    f.Parent = Parent;
                    if (Deleted)
                    {
                        f.IsDeleted = true;
                        cachedDeletedFolders.Add(f);
                    }
                    else
                    {
                        cachedFolders.Add(f);
                    }
                }
                    // File
                else
                {
                    File f = new File(Parent.PartitionInfo, newEdata, Parent.Drive);
                    f.FullPath = Parent.FullPath + "\\" + f.Name;
                    f.Parent = Parent;
                    if (Deleted)
                    {
                        f.IsDeleted = true;
                        cachedDeletedFiles.Add(f);
                    }
                    else
                    {
                        cachedFiles.Add(f);
                    }
                }
            }
            return new object[] { cachedFiles, cachedFolders, cachedDeletedFiles, cachedDeletedFolders };
        }
Example #12
0
 void Search(Folder f, string SearchTerm, bool STFS, bool Deleted, bool Files, bool Folders)
 {
     if (stop)
     {
         return;
     }
     this.Invoke((MethodInvoker)delegate { this.Text = "Searching for \"" + SearchTerm + "\"" + " in " + f.FullPath; });
     foreach (File file in f.Files())
     {
         if (stop)
         {
             return;
         }
         if (Files)
         {
             if (file.Name.ToLower().Contains(SearchTerm.ToLower()) || file.SizeFriendly.ToLower().Contains(SearchTerm.ToLower()))
             {
                 AddFile(file);
             }
             else if (STFS && file.IsSTFSPackage())
             {
                 if (file.TitleName().ToLower().Contains(SearchTerm.ToLower()) || file.TitleID().ToString("X").ToLower().Contains(SearchTerm.ToLower()) || file.ContentName().ToLower().Contains(SearchTerm.ToLower()) || file.DeviceID().ToHexString().ToLower().Contains(SearchTerm.ToLower()) || file.ProfileID().ToHexString().ToLower().Contains(SearchTerm.ToLower()) || file.ConsoleID().ToHexString().ToLower().Contains(SearchTerm.ToLower()))
                 {
                     AddFile(file);
                 }
             }
         }
     }
     foreach (Folder ff in f.Folders())
     {
         if (stop)
         {
             return;
         }
         if (Folders)
         {
             if (ff.Name.ToLower().Contains(SearchTerm.ToLower()))
             {
                 AddFolder(ff);
             }
             else if(STFS)
             {
                 if (ff.GameName() != null)
                 {
                     if (ff.GameName().ToLower().Contains(SearchTerm.ToLower()))
                     {
                         AddFolder(ff);
                     }
                 }
             }
         }
         ff.ReturnDeletedEntries = Deleted;
         Search(ff, SearchTerm, STFS, Deleted, Files, Folders);
     }
 }
Example #13
0
 void ResetFolderActions(Folder folder)
 {
     folder.ResetFolderAction();
     foreach (Folder f in folder.Folders())
     {
         ResetFolderActions(f);
     }
 }
Example #14
0
 public EntryAction(string[] Paths, Folder Parent, Method method)
 {
     InitializeComponent();
     if (Environment.OSVersion.Version.Build >= 7600)
     {
         Windows7 = true;
     }
     if (Environment.OSVersion.Version.Build >= 6000)
     {
         Aero = true;
     }
     if (Windows7)
     {
         tm = TaskbarManager.Instance;
     }
     this.HandleCreated += new EventHandler(EntryAction_HandleCreated);
     this.FormClosing +=new FormClosingEventHandler(EntryAction_FormClosing);
     m = method;
     this.Paths = Paths;
     this.Parent = Parent;
 }
Example #15
0
 /// <summary>
 /// Returns an array of free blocks based off of the number of blocks needed
 /// </summary>
 public uint[] GetFreeBlocks(Folder Partition, int blocksNeeded, uint StartBlock, long end, bool SecondLoop)
 {
     int Clustersize = 0x10000;
     uint Block = StartBlock;
     if (end == 0)
     {
         end = Partition.PartitionInfo.FATOffset + Partition.PartitionInfo.FATSize;
     }
     List<uint> BlockList = new List<uint>();
     // Create our reader for the drive
     Streams.Reader br = Reader();
     // Create our reader for the memory stream
     Streams.Reader mr = null;
     for (long i = VariousFunctions.DownToNearest200(VariousFunctions.BlockToFATOffset(StartBlock, Partition)); i < end; i += Clustersize)
     {
         //Set our position to i
         br.BaseStream.Position = i;
         byte[] buffer = new byte[0];
         if ((end - i) < Clustersize)
         {
             buffer = VariousFunctions.ReadBytes(ref br, end - i);
         }
         else
         {
             //Read our buffer
             buffer = br.ReadBytes(Clustersize);
         }
         try
         {
             mr.Close();
         }
         catch { }
         mr = new Streams.Reader(new System.IO.MemoryStream(buffer));
         //Re-open our binary reader using the buffer/memory stream
         for (int j = 0; j < buffer.Length; j += (int)Partition.PartitionInfo.EntrySize, Block += (uint)Partition.PartitionInfo.EntrySize)
         {
             mr.BaseStream.Position = j;
             //If we've gotten all of our requested blocks...
             if (BlockList.Count == blocksNeeded)
             {
                 //Close our reader -> break the loop
                 mr.Close();
                 break;
             }
             //Read the next block entry
             byte[] reading = mr.ReadBytes((int)Partition.PartitionInfo.EntrySize);
             //For each byte in our reading
             for (int k = 0; k < reading.Length; k++)
             {
                 //If the byte isn't null (if the block isn't open)
                 if (reading[k] != 0x00)
                 {
                     //Break
                     break;
                 }
                 //If we've reached the end of the array, and the last byte
                 //is 0x00, then the block is free
                 if (k == reading.Length - 1 && reading[k] == 0x00)
                 {
                     //Do some maths to get the block numbah
                     long fOff = Partition.PartitionInfo.FATOffset;
                     long blockPosition = (long)i + j;
                     uint block = (uint)(blockPosition - fOff) / (uint)Partition.PartitionInfo.EntrySize;
                     BlockList.Add(block);
                 }
             }
         }
         //We're putting in one last check so that we don't loop more than we need to
         if (BlockList.Count == blocksNeeded)
         {
             break;
         }
     }
     //If we found the required amount of free blocks - return our list
     if (BlockList.Count == blocksNeeded)
     {
         return BlockList.ToArray();
     }
     //If we didn't find the amount of blocks required, but we started from a
     //block other than the first one...
     if (BlockList.Count < blocksNeeded && SecondLoop == false)
     {
         BlockList.AddRange(GetFreeBlocks(Partition, blocksNeeded - BlockList.Count, 1, VariousFunctions.DownToNearest200(VariousFunctions.BlockToFATOffset(StartBlock, Partition)), true));
         return BlockList.ToArray();
     }
     //We didn't find the amount of free blocks required, meaning we're ref of
     //disk space
     if (BlockList.Count != blocksNeeded)
     {
         throw new Exception("Out of Xbox 360 hard disk space");
     }
     return BlockList.ToArray();
 }
        /* AUTOMATICALLY CREATES SHIT */
        public EntryData GetNewEntry(Folder Destination, uint Size, Geometry.Flags[] Flags, string EntryName)
        {
            if (!VariousFunctions.CheckFileName(EntryName))
            {
                throw new ArgumentException("Invalid name: \"" + EntryName + "\"", "EntryName");
            }

            EntryData newEntryData = new EntryData();
            newEntryData.EntryOffset = GetNewEntryOffset(Destination);

            ushort Date = VariousFunctions.DateTimeToFATShort(DateTime.Now, true);
            ushort Time = VariousFunctions.DateTimeToFATShort(DateTime.Now, false);
            newEntryData.CreationDate = Date;
            newEntryData.CreationTime = Time;
            newEntryData.ModifiedDate = Date;
            newEntryData.ModifiedTime = Time;
            newEntryData.AccessDate = Date;
            newEntryData.AccessTime = Time;
            if (Flags.Length != 0)
            {
                newEntryData.Flags = VariousFunctions.FlagsToByte(Flags);
            }
            else
            {
                newEntryData.Flags = 0;
            }
            newEntryData.Size = Size;
            newEntryData.Name = EntryName;
            newEntryData.NameSize = (byte)EntryName.Length;
            if ((Size == 0 && Flags.Contains(Geometry.Flags.Directory)) || (Size != 0 && Flags.Length == 0))
            {
                newEntryData.StartingCluster = Destination.Drive.GetFreeBlocks(Destination, 1, 0, 0, false)[0];
            }
            else
            {
                newEntryData.StartingCluster = 0;
            }
            WriteFATChain(new uint[] { newEntryData.StartingCluster });
            CreateNewEntry(newEntryData);
            return newEntryData;
        }
Example #17
0
 public long GetPartitionRemainingStorage(Folder Partition)
 {
     return new PartitionFunctions(Partition).GetFreeSpace();
 }
Example #18
0
        /// <summary>
        /// Creates a new folder
        /// </summary>
        /// <param name="Name">New folder name</param>
        /// <returns>The existing file or folder will be returned if applicable, otherwise returns null (no problems encountered)</returns>
        public Structs.WriteResult CreateNewFolder(string Name)
        {
            WriteResult Result = new WriteResult();
            Folders();
            Console.WriteLine("Getting folders... comparing names");
            for (int i = 0; i < cachedFolders.Count; i++)
            {
                if (cachedFolders[i].Name.ToLower() == Name.ToLower())
                {
                    Result.CouldNotWrite = true;
                    Result.Entry = cachedFolders[i];
                    Result.ConflictingEntryPath = Result.Entry.FullPath;
                    return Result;
                }
            }

            Console.WriteLine("Getting files... comparing names");
            for (int i = 0; i < cachedFiles.Count; i++)
            {
                if (cachedFiles[i].Name.ToLower() == Name.ToLower())
                {
                    Result.CouldNotWrite = true;
                    Result.Entry = cachedFiles[i];
                    Result.ConflictingEntryPath = Result.Entry.FullPath;
                    return Result;
                }
            }

            EntryFunctions ef = new EntryFunctions(this);
            Console.WriteLine("Creating new folder");
            Folder f = new Folder(this.PartitionInfo,
                ef.GetNewEntry(this, 0, new Geometry.Flags[] { Geometry.Flags.Directory }, Name),
                this.Drive);
            // Check if the new folder was created on a new cluster
            if (f.EntryOffset >= VariousFunctions.GetBlockOffset(this.BlocksOccupied[BlocksOccupied.Length - 1], this) + this.PartitionInfo.ClusterSize)
            {
                List<uint> blocks = this.BlocksOccupied.ToList();
                blocks.Add(VariousFunctions.GetBlockFromOffset(f.EntryOffset, this.PartitionInfo));
                this.BlocksOccupied = blocks.ToArray();
            }
            Console.WriteLine("Writing FAT chain");
            ef.WriteFATChain(new uint[] { f.EntryData.StartingCluster });
            f.FullPath = this.FullPath + "\\" + f.Name;
            f.Parent = this;
            Streams.Writer w = this.Drive.Writer();
            w.BaseStream.Position = f.StartingOffset;
            byte[] FF = new byte[PartitionInfo.ClusterSize];
            for (int i = 0; i < FF.Length; i++)
            {
                FF[i] = 0xFF;
            }
            Console.WriteLine("Writing FF");
            w.Write(FF);
            //Console.WriteLine("Closing stream");
            //w.Close();
            this.cachedFolders.Add(f);

            EntryEventArgs eea = new EntryEventArgs();
            eea.FullParentPath = FullPath;
            eea.ModifiedEntry = f;
            eea.ParentFolder = this;
            OnEntryEvent(ref eea);

            Console.WriteLine("Updating entry modified time");
            UpdateModifiedTime();

            Result.Entry = f;
            return Result;
        }