public override void LoadDataAsync(LoadCommand cmd, LoadDataAsyncParameters cmdParam, Action <PaneViewModelBase> success = null, Action <PaneViewModelBase, Exception> error = null)
 {
     base.LoadDataAsync(cmd, cmdParam, success, error);
     switch (cmd)
     {
     case LoadCommand.Load:
         WorkHandler.Run(
             () =>
         {
             _packageContent = (BinaryContent)cmdParam.Payload;
             _stfs           = ModelFactory.GetModel <StfsPackage>(_packageContent.Content);
             return(true);
         },
             result =>
         {
             IsLoaded = true;
             Tabs.Add(new ProfileRebuilderTabItemViewModel(Resx.FileStructure, ParseStfs(_stfs)));
             SelectedTab = Tabs.First();
             if (success != null)
             {
                 success.Invoke(this);
             }
         },
             exception =>
         {
             if (error != null)
             {
                 error.Invoke(this, exception);
             }
         });
         break;
     }
 }
        private static ObservableCollection <FileEntryViewModel> ParseStfs(StfsPackage package)
        {
            var collection      = new ObservableCollection <FileEntryViewModel>();
            var allocatedBlocks = new HashSet <int>();
            var blockCollisions = new HashSet <int>();

            foreach (var fileEntry in package.FlatFileList.Where(f => !f.IsDirectory).OrderBy(f => f.Name))
            {
                var blockList = package.GetFileEntryBlockList(fileEntry);
                foreach (var block in blockList.Where(b => b.Key.HasValue))
                {
                    if (!allocatedBlocks.Contains(block.Key.Value))
                    {
                        allocatedBlocks.Add(block.Key.Value);
                    }
                    else
                    {
                        blockCollisions.Add(block.Key.Value);
                    }
                }
                collection.Add(new FileEntryViewModel(fileEntry, blockList, package));
            }

            foreach (var block in blockCollisions.SelectMany(blockCollision => collection.SelectMany(vm => vm.Blocks.Where(b => b.BlockNumber == blockCollision))))
            {
                block.Health = FileBlockHealthStatus.Collision;
            }

            return(collection);
        }
Exemplo n.º 3
0
 public FileEntryViewModel(FileEntry model, IEnumerable<KeyValuePair<int?, BlockStatus>> blockList, StfsPackage parent)
 {
     Parent = parent;
     _model = model;
     _blocks = new ObservableCollection<FileBlockViewModel>();
     foreach (var block in blockList)
     {
         FileBlockHealthStatus status;
         if (!block.Key.HasValue) status = FileBlockHealthStatus.Missing;
         else
         {
             switch (block.Value)
             {
                 case BlockStatus.Allocated:
                 case BlockStatus.NewlyAllocated:
                     status = FileBlockHealthStatus.Ok;
                     break;
                 default:
                     status = FileBlockHealthStatus.Unallocated;
                     break;
             }
         }
         var vm = new FileBlockViewModel(block.Key, status);
         _blocks.Add(vm);
     }
 }
Exemplo n.º 4
0
        private string FindFile(StfsPackage p, int b)
        {
            var       hes = p.TopTable.Tables.SelectMany(t => t.Entries).ToArray();
            var       bb  = b;
            HashEntry he;

            do
            {
                he =
                    hes.FirstOrDefault(
                        h =>
                        h.NextBlock == bb &&
                        (h.Status == BlockStatus.Allocated || h.Status == BlockStatus.NewlyAllocated));
                if (he != null)
                {
                    bb = he.Block.Value;
                }
            } while (he != null);
            var fno = p.FileStructure.Files.FirstOrDefault(f => f.StartingBlockNum == bb);

            if (fno != null)
            {
                return(fno.Name);
            }

            if (p.VolumeDescriptor.FileTableBlockNum == bb)
            {
                return("<FileTable>");
            }

            return("-");
        }
Exemplo n.º 5
0
        private void LoadPackage(string path)
        {
            packagePath.Text = path;

            package = new StfsPackage(path);
            ShowListing(package.GetFileListing());
        }
Exemplo n.º 6
0
        public FileEntryViewModel(FileEntry model, IEnumerable <KeyValuePair <int?, BlockStatus> > blockList, StfsPackage parent)
        {
            Parent  = parent;
            _model  = model;
            _blocks = new ObservableCollection <FileBlockViewModel>();
            foreach (var block in blockList)
            {
                FileBlockHealthStatus status;
                if (!block.Key.HasValue)
                {
                    status = FileBlockHealthStatus.Missing;
                }
                else
                {
                    switch (block.Value)
                    {
                    case BlockStatus.Allocated:
                    case BlockStatus.NewlyAllocated:
                        status = FileBlockHealthStatus.Ok;
                        break;

                    default:
                        status = FileBlockHealthStatus.Unallocated;
                        break;
                    }
                }
                var vm = new FileBlockViewModel(block.Key, status);
                _blocks.Add(vm);
            }
        }
        //private void LogHelperStatusBarChange(object sender, ValueChangedEventArgs e)
        //{
        //    UIThread.BeginRun(() => LoadingProgress = e.NewValue);
        //}

        //private void LogHelperStatusBarMax(object sender, ValueChangedEventArgs e)
        //{
        //    UIThread.BeginRun(() =>
        //                          {
        //                              LoadingQueueLength = e.NewValue;
        //                              LoadingProgress = 0;
        //                          });
        //}

        //private void LogHelperStatusBarText(object sender, TextChangedEventArgs e)
        //{
        //    UIThread.BeginRun(() => LoadingInfo = e.Text);
        //}

        private StfsPackage LoadFile()
        {
            var         file    = File.ReadAllBytes(_path);
            StfsPackage profile = null;

            profile = ModelFactory.GetModel <StfsPackage>(file);
            profile.ExtractContent();
            return(profile);
        }
 private void LoadFileCallback(StfsPackage profile)
 {
     _profile = profile;
     Initialize();
     IsInProgress = false;
     //LogHelper.StatusBarChange -= LogHelperStatusBarChange;
     //LogHelper.StatusBarMax -= LogHelperStatusBarMax;
     //LogHelper.StatusBarText -= LogHelperStatusBarText;
     LoadingInfo = "Done.";
 }
Exemplo n.º 9
0
        private void btnCreateAndDeploy_Click(object sender, EventArgs e)
        {
            var tempStfsFile = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\\gfaiutzayvy545555iuug2vmslaqbaaaaaaaaaaaa";

            File.Copy(_inputStfsPackage, tempStfsFile, true);

            // Get Base Shit
            Stream templateStfs = new FileStream(tempStfsFile, FileMode.OpenOrCreate, FileAccess.ReadWrite);
            var    stfs         = new StfsPackage(templateStfs)
            {
                Name = string.Format("{0}/{1} - Yrs2013", _cityA, _cityB)
            };

            stfs.SaveMetadata();

            // Extract shit
            var tempFile = Path.GetTempFileName();

            stfs.ExtractFile("variant", tempFile);

            // Load Shit
            var gametype = GameType.Load(tempFile);

            gametype = CreateMegaloGametype(gametype, Convert.ToUInt32(txtGametypeLength.Text));

            // Save Shit
            gametype.Save(tempFile);
            if (File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\\variant"))
            {
                File.Delete(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\\variant");
            }
            File.Copy(tempFile, Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\\variant");

            // Inject Shit
            stfs.ReplaceFile(tempFile, "variant");

            // Fix Shit
            stfs.Rehash();
            stfs.SaveChanges(@"Stfs/KV_D.bin");
            templateStfs.Close();

            // Transfer Stuff
            XboxCommunication.XboxCopy(tempStfsFile, @"hdd:\Content\E00006B45A52FF20\4D530919\00000001");

            // Tell Shit
            MessageBox.Show("Gametype deployed to console");
        }
Exemplo n.º 10
0
        private void MapPackage(StfsPackage p)
        {
            foreach (var f in p.FileStructure.Files)
            {
                var block = f.StartingBlockNum;
                for (var i = 0; i < f.BlocksForFile; i++)
                {
                    var adr = p.GetRealAddressOfBlock(block);
                    //if (f.Name == "58410A6F.gpd")
                    //{
                    //    Debug.WriteLine("{0,2} {1,4}", i, block);
                    //}
                    p.BinMap.Add(adr, 0x1000, f.Name, i.ToString(CultureInfo.InvariantCulture), block);
                    var he = p.GetHashEntry(block);
                    block = he.NextBlock;
                }
            }
            foreach (var f in p.FileStructure.Folders[0].Files)
            {
                var block = f.StartingBlockNum;
                for (var i = 0; i < f.BlocksForFile; i++)
                {
                    var adr = p.GetRealAddressOfBlock(block);
                    p.BinMap.Add(adr, 0x1000, f.Name, i.ToString(CultureInfo.InvariantCulture), block);
                    var he = p.GetHashEntry(block);
                    block = he.NextBlock;
                }
            }

            {
                var block = p.VolumeDescriptor.FileTableBlockNum;
                for (var i = 0; i < p.VolumeDescriptor.FileTableBlockCount; i++)
                {
                    var adr = p.GetRealAddressOfBlock(block);
                    p.BinMap.Add(adr, 0x1000, "FileTable", i.ToString(CultureInfo.InvariantCulture), block);
                    var he = p.GetHashEntry(block);
                    block = he.NextBlock;
                }
            }

            p.BinMap.Add(p.TopTable.StartOffset, 0x1000, "TopTable", String.Empty);
            for (var i = 0; i < p.TopTable.EntryCount; i++)
            {
                p.BinMap.Add(p.TopTable.Tables[i].StartOffset, 0x1000, "Table", i.ToString(CultureInfo.InvariantCulture));
            }
        }
Exemplo n.º 11
0
        private void btnCreateAndDeploy_Click(object sender, EventArgs e)
        {
            var tempStfsFile = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\\gfaiutzayvy545555iuug2vmslaqbaaaaaaaaaaaa";
            File.Copy(_inputStfsPackage, tempStfsFile, true);

            // Get Base Shit
            Stream templateStfs = new FileStream(tempStfsFile, FileMode.OpenOrCreate, FileAccess.ReadWrite);
            var stfs = new StfsPackage(templateStfs)
            {
                Name = string.Format("{0}/{1} - Yrs2013", _cityA, _cityB)
            };
            stfs.SaveMetadata();

            // Extract shit
            var tempFile = Path.GetTempFileName();
            stfs.ExtractFile("variant", tempFile);

            // Load Shit
            var gametype = GameType.Load(tempFile);
            gametype = CreateMegaloGametype(gametype, Convert.ToUInt32(txtGametypeLength.Text));

            // Save Shit
            gametype.Save(tempFile);
            if (File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\\variant"))
                File.Delete(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\\variant");
            File.Copy(tempFile, Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\\variant");

            // Inject Shit
            stfs.ReplaceFile(tempFile, "variant");

            // Fix Shit
            stfs.Rehash();
            stfs.SaveChanges(@"Stfs/KV_D.bin");
            templateStfs.Close();

            // Transfer Stuff
            XboxCommunication.XboxCopy(tempStfsFile, @"hdd:\Content\E00006B45A52FF20\4D530919\00000001");

            // Tell Shit
            MessageBox.Show("Gametype deployed to console");
        }
Exemplo n.º 12
0
 public override void Dispose()
 {
     _stfs = null;
     GC.Collect();
 }
Exemplo n.º 13
0
 public static BitmapImage GetTitleThumbnailImage(this StfsPackage package)
 {
     return(GetBitmapFromByteArray(package.TitleThumbnailImage));
 }
Exemplo n.º 14
0
 public static ObservableCollection <TreeItemViewModel> BuildTreeFromFileListing(this StfsPackage package)
 {
     return(new ObservableCollection <TreeItemViewModel> {
         BuildTree(package.FileStructure)
     });
 }
Exemplo n.º 15
0
 private void LoadFileCallback(StfsPackage profile)
 {
     _profile = profile;
     Initialize();
     IsInProgress = false;
     //LogHelper.StatusBarChange -= LogHelperStatusBarChange;
     //LogHelper.StatusBarMax -= LogHelperStatusBarMax;
     //LogHelper.StatusBarText -= LogHelperStatusBarText;
     LoadingInfo = "Done.";
 }
Exemplo n.º 16
0
 private void MergeCallback(StfsPackage profile)
 {
     LoadFileCallback(_profile);
     Gamerscore = _profile.ProfileInfo.GamercardCred;
     CalculatedGamerscore = _profile.ProfileInfo.TitlesPlayed.Sum(t => t.GamerscoreUnlocked);
 }
        private static ObservableCollection<FileEntryViewModel> ParseStfs(StfsPackage package)
        {
            var collection = new ObservableCollection<FileEntryViewModel>();
            var allocatedBlocks = new HashSet<int>();
            var blockCollisions = new HashSet<int>();
            foreach (var fileEntry in package.FlatFileList.Where(f => !f.IsDirectory).OrderBy(f => f.Name))
            {
                var blockList = package.GetFileEntryBlockList(fileEntry);
                foreach (var block in blockList.Where(b => b.Key.HasValue))
                {
                    if (!allocatedBlocks.Contains(block.Key.Value))
                        allocatedBlocks.Add(block.Key.Value);
                    else
                        blockCollisions.Add(block.Key.Value);
                }
                collection.Add(new FileEntryViewModel(fileEntry, blockList, package));
            }

            foreach (var block in blockCollisions.SelectMany(blockCollision => collection.SelectMany(vm => vm.Blocks.Where(b => b.BlockNumber == blockCollision))))
            {
                block.Health = FileBlockHealthStatus.Collision;
            }

            return collection;
        }
 public override void LoadDataAsync(LoadCommand cmd, LoadDataAsyncParameters cmdParam, Action<PaneViewModelBase> success = null, Action<PaneViewModelBase, Exception> error = null)
 {
     base.LoadDataAsync(cmd, cmdParam, success, error);
     switch (cmd)
     {
         case LoadCommand.Load:
             WorkHandler.Run(
                 () =>
                 {
                     _packageContent = (BinaryContent)cmdParam.Payload;
                     _stfs = ModelFactory.GetModel<StfsPackage>(_packageContent.Content);
                     return true;
                 },
                 result =>
                     {
                         IsLoaded = true;
                         Tabs.Add(new ProfileRebuilderTabItemViewModel(Resx.FileStructure, ParseStfs(_stfs)));
                         SelectedTab = Tabs.First();
                         if (success != null) success.Invoke(this);
                     },
                 exception =>
                 {
                     if (error != null) error.Invoke(this, exception);
                 });
             break;
     }
 }
Exemplo n.º 19
0
        public ActionResult Index(CreateProject createProject, HttpPostedFileBase stfsUpload)
        {
            if (!ModelState.IsValid)
                return View();

            // Get the User
            var user = Helpers.GetAuthenticatedUser();
            if (user == null)
                return View();

            // Check Name is Unique
            if (_dbContext.Projects.Count(p =>
                !p.IsDeleted && p.Name.ToLower().Equals(createProject.ProjectName.ToLower())) > 0)
            {
                ModelState.AddModelError("ProjectName", "You can't have 2 Projects with the same name.");
                return View();
            }

            // Do file validation stuff
            if (stfsUpload == null)
            {
                ModelState.AddModelError("File", "You must select a Halo 4 Gametype to create a project.");
                return View();
            }
            else
            {
                var outputPath = Path.GetTempFileName();
                var variantExtrated = Path.GetTempFileName();
                System.IO.File.WriteAllBytes(outputPath, VariousFunctions.StreamToByteArray(stfsUpload.InputStream));
                try
                {
                    var stfsParsed = new StfsPackage(outputPath);

                    // Validate contains variant
                    if (!stfsParsed.FileExists("variant"))
                        throw new Exception();

                    // Extract variant
                    stfsParsed.ExtractFile("variant", variantExtrated);

                    var gametype = GameType.Load(variantExtrated);

                    // TODO: seralize gametype data
                    var seralizedData = "";

                    // Write data to Database
                    var project = new Project
                    {
                        Name = createProject.ProjectName,
                        Description = createProject.ProjectDescription,
                        UserId = user.Id
                    };

                    // Write data to the S3 Bucket
                    try
                    {
                        var s3 = new S3Storage();
                        s3.WriteObject(VariousFunctions.StreamToByteArray(stfsUpload.InputStream),
                            S3Storage.StorageLocations.Stfs, project.StfsId);
                        s3.WriteObject(seralizedData,
                            S3Storage.StorageLocations.Solution, project.SolutionId);
                    }
                    catch
                    {
                        return RedirectToAction("Index").Error("There was an unknown error trying to create the project.");
                    }

                    // Save project to database
                    _dbContext.Projects.Add(project);
                    _dbContext.SaveChanges();

                    // Delete files now we done, yo
                    System.IO.File.Delete(outputPath);
                    System.IO.File.Delete(variantExtrated);

                    // Redirect outa here
                    return RedirectToAction("Edit", new { id = project.Id });
                }
                catch
                {
                    // Uh Oh, NSA - get the f**k out of here, and delete all the evidence.
                    System.IO.File.Delete(outputPath);
                    System.IO.File.Delete(variantExtrated);

                    ModelState.AddModelError("File", "Invalid Halo 4 Gametype.");
                    return View();
                }
            }
        }
Exemplo n.º 20
0
 private void MergeCallback(StfsPackage profile)
 {
     LoadFileCallback(_profile);
     Gamerscore           = _profile.ProfileInfo.GamercardCred;
     CalculatedGamerscore = _profile.ProfileInfo.TitlesPlayed.Sum(t => t.GamerscoreUnlocked);
 }
Exemplo n.º 21
0
 public void LoadPackage(BinaryContent content)
 {
     _contentType = content.ContentType;
     _stfs = ModelFactory.GetModel<StfsPackage>(content.Content);
 }
Exemplo n.º 22
0
 public void LoadPackage(BinaryContent content)
 {
     _contentType = content.ContentType;
     _stfs        = ModelFactory.GetModel <StfsPackage>(content.Content);
 }
Exemplo n.º 23
0
 public override void Dispose()
 {
     _stfs = null;
     GC.Collect();
 }
Exemplo n.º 24
0
        public ActionResult Index(CreateProject createProject, HttpPostedFileBase stfsUpload)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            // Get the User
            var user = Helpers.GetAuthenticatedUser();

            if (user == null)
            {
                return(View());
            }

            // Check Name is Unique
            if (_dbContext.Projects.Count(p =>
                                          !p.IsDeleted && p.Name.ToLower().Equals(createProject.ProjectName.ToLower())) > 0)
            {
                ModelState.AddModelError("ProjectName", "You can't have 2 Projects with the same name.");
                return(View());
            }

            // Do file validation stuff
            if (stfsUpload == null)
            {
                ModelState.AddModelError("File", "You must select a Halo 4 Gametype to create a project.");
                return(View());
            }
            else
            {
                var outputPath      = Path.GetTempFileName();
                var variantExtrated = Path.GetTempFileName();
                System.IO.File.WriteAllBytes(outputPath, VariousFunctions.StreamToByteArray(stfsUpload.InputStream));
                try
                {
                    var stfsParsed = new StfsPackage(outputPath);

                    // Validate contains variant
                    if (!stfsParsed.FileExists("variant"))
                    {
                        throw new Exception();
                    }

                    // Extract variant
                    stfsParsed.ExtractFile("variant", variantExtrated);

                    var gametype = GameType.Load(variantExtrated);

                    // TODO: seralize gametype data
                    var seralizedData = "";

                    // Write data to Database
                    var project = new Project
                    {
                        Name        = createProject.ProjectName,
                        Description = createProject.ProjectDescription,
                        UserId      = user.Id
                    };

                    // Write data to the S3 Bucket
                    try
                    {
                        var s3 = new S3Storage();
                        s3.WriteObject(VariousFunctions.StreamToByteArray(stfsUpload.InputStream),
                                       S3Storage.StorageLocations.Stfs, project.StfsId);
                        s3.WriteObject(seralizedData,
                                       S3Storage.StorageLocations.Solution, project.SolutionId);
                    }
                    catch
                    {
                        return(RedirectToAction("Index").Error("There was an unknown error trying to create the project."));
                    }

                    // Save project to database
                    _dbContext.Projects.Add(project);
                    _dbContext.SaveChanges();

                    // Delete files now we done, yo
                    System.IO.File.Delete(outputPath);
                    System.IO.File.Delete(variantExtrated);

                    // Redirect outa here
                    return(RedirectToAction("Edit", new { id = project.Id }));
                }
                catch
                {
                    // Uh Oh, NSA - get the f**k out of here, and delete all the evidence.
                    System.IO.File.Delete(outputPath);
                    System.IO.File.Delete(variantExtrated);

                    ModelState.AddModelError("File", "Invalid Halo 4 Gametype.");
                    return(View());
                }
            }
        }