protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.activity_work); CheckAppPermissions(); Toolbar toolbar = this.FindViewById <Toolbar>(Resource.Id.toolbar); SetActionBar(toolbar); ActionBar.Title = "EStorage"; List <CustomFragment> fragments = new List <CustomFragment>(); StorageFragment storgeFragment = new StorageFragment(); AccountFragment accountFragment = new AccountFragment(); FileFragment fileFragment = new FileFragment(); storgeFragment.Subscribe(accountFragment); storgeFragment.Subscribe(fileFragment); fragments.Add(storgeFragment); fragments.Add(accountFragment); fragments.Add(fileFragment); fragments.Add(new ProfileFragment()); StorageFragmentAdapter storageAdapter = new StorageFragmentAdapter(SupportFragmentManager, fragments); ViewPager pager = FindViewById <ViewPager>(Resource.Id.pager); pager.Adapter = storageAdapter; }
public void UpdateValidity(IList <FileFragment> list, int index) { //Switch based on box type switch ((list[index] as ISOFileFragment).BoxType) { //TODO length is super complicated with these, so I'll have to spend a good chunk of time to fix them case (BoxTypes.Length): //length (uint) string lengthPath = list[index].Path; long lengthLength = new FileInfo(lengthPath).Length; if (lengthLength != 4) { list[index].Validity = (lengthLength < 4) ? Validity.HardInvalid : Validity.Unknown; } else { //TODO why did I have to rename these?!?!?!?!?!?!?!?!?!?!?! uint lengthData1 = BinaryFileInterpreter.ReadFileAs <uint>(lengthPath, true); if ((list[index + 2] as ISOFileFragment).BoxType == BoxTypes.ExtendedLength) { list[index].Validity = (lengthData1 == 1) ? Validity.Valid : Validity.HardInvalid; list[index].Description = $"Box {(list[index] as ISOFileFragment).BoxNumber} Length = <unknown>"; } else { ulong correctLength1 = 4; //Starts at the length of "Length" int i1 = 0; FileFragment ff1; do { i1++; ff1 = list[index + i1]; correctLength1 += (ulong)new FileInfo(ff1.Path).Length; } while ((ff1 as ISOFileFragment).BoxType != BoxTypes.Data); //Assuming it did work, we can go as usual list[index].Validity = (lengthData1 == correctLength1) ? Validity.Valid : Validity.HardInvalid; } list[index].Description = $"Box {(list[index] as ISOFileFragment).BoxNumber} Length = {lengthData1}"; } break; case (BoxTypes.Type): //type string typeData = File.ReadAllText(list[index].Path); list[index].Validity = IsValidBoxType(typeData) ? Validity.Valid : Validity.HardInvalid; list[index].Description = $"Box {(list[index] as ISOFileFragment).BoxNumber} Type = {typeData}"; break; case (BoxTypes.ExtendedLength): //Extended Length (ulong) //TODO implement extended length validation break; case (BoxTypes.ExtendedType): //Extended Type (GUID) Guid extTypeData = new Guid(File.ReadAllBytes(list[index].Path)); list[index].Validity = IsValidExtendedBoxType(extTypeData) ? Validity.Valid : Validity.HardInvalid; list[index].Description = $"Box {(list[index] as ISOFileFragment).BoxNumber} GUID = {extTypeData.ToString()}"; break; case (BoxTypes.Data): //data //HACK this entire code is probably messy but hopefully actually works string dataPath = list[index].Path; ulong correctLength, dataLength; correctLength = dataLength = (ulong)new FileInfo(dataPath).Length; int i = 0; FileFragment ff, lengthToEdit = null; do { i++; ff = list[index - i]; correctLength += (ulong)new FileInfo(ff.Path).Length; //Save the first length or extended length box we find if (lengthToEdit == null && ((ff as ISOFileFragment).BoxType == BoxTypes.Length || (ff as ISOFileFragment).BoxType == BoxTypes.ExtendedLength)) { lengthToEdit = ff; } } while ((ff as ISOFileFragment).BoxType != BoxTypes.Length); bool isExtended = ((lengthToEdit as ISOFileFragment).BoxType == BoxTypes.ExtendedLength); //Storing this since it's used twice /* * ulong lengthData = isExtended * ? BitConverter.ToUInt64(File.ReadAllBytes(lengthToEdit.Path).Reverse().ToArray(), 0) * : BitConverter.ToUInt32(File.ReadAllBytes(lengthToEdit.Path).Reverse().ToArray(), 0); */ ulong lengthData = BinaryFileInterpreter.ReadFileAs(lengthToEdit.Path, isExtended ? typeof(ulong) : typeof(uint), true); if (FixLength && lengthData != correctLength) { //TODO this is so dumb that this conditional operator doesn't work :angery: //BitConverter.GetBytes(isExtended ? correctLength : (uint)correctLength).Reverse().ToArray(); byte[] bytesToWrite = isExtended ? BitConverter.GetBytes(correctLength) : BitConverter.GetBytes((uint)correctLength); File.WriteAllBytes(lengthToEdit.Path, bytesToWrite.Reverse().ToArray()); lengthData = correctLength; lengthToEdit.Validity = Validity.Valid; lengthToEdit.Description = $"Box {(lengthToEdit as ISOFileFragment).BoxNumber} Length = {correctLength}"; } list[index].Validity = (lengthData == correctLength) ? Validity.Valid : Validity.HardInvalid; list[index].Description = $"Box {(list[index] as ISOFileFragment).BoxNumber} Data length = {dataLength}"; break; } return; }