예제 #1
0
        public void Dispose()
        {
            autoCompleteSource.Clear();

            List <uint> assetList = new List <uint>();

            assetList.AddRange(assetDictionary.Keys);

            if (assetList.Count == 0)
            {
                return;
            }

            ProgressBar progressBar = new ProgressBar("Closing Archive");

            progressBar.Show();
            progressBar.SetProgressBar(0, assetList.Count, 1);

            foreach (uint assetID in assetList)
            {
                DisposeOfAsset(assetID, true);
                progressBar.PerformStep();
            }

            HIPA = null;
            PACK = null;
            DICT = null;
            STRM = null;
            currentlyOpenFilePath = null;

            progressBar.Close();
        }
예제 #2
0
        public void OpenFile(string fileName)
        {
            allowRender = false;

            Dispose();
            ProgressBar progressBar = new ProgressBar("Opening Archive");

            progressBar.Show();

            assetDictionary = new Dictionary <uint, Asset>();

            currentlySelectedAssets = new List <Asset>();
            currentlyOpenFilePath   = fileName;

            foreach (HipSection i in HipFileToHipArray(fileName))
            {
                if (i is Section_HIPA hipa)
                {
                    HIPA = hipa;
                }
                else if (i is Section_PACK pack)
                {
                    PACK = pack;
                }
                else if (i is Section_DICT dict)
                {
                    DICT = dict;
                }
                else if (i is Section_STRM strm)
                {
                    STRM = strm;
                }
                else
                {
                    progressBar.Close();
                    throw new Exception();
                }
            }

            progressBar.SetProgressBar(0, DICT.ATOC.AHDRList.Count, 1);

            if (currentPlatform == Platform.Unknown)
            {
                new ChoosePlatformDialog().ShowDialog();
            }

            List <string> autoComplete = new List <string>();

            foreach (Section_AHDR AHDR in DICT.ATOC.AHDRList)
            {
                AddAssetToDictionary(AHDR, true);

                autoComplete.Add(AHDR.ADBG.assetName);

                progressBar.PerformStep();
            }

            autoCompleteSource.AddRange(autoComplete.ToArray());

            if (GetAssetsOfType(AssetType.RWTX).Any())
            {
                SetupTextureDisplay();
            }

            RecalculateAllMatrices();

            progressBar.Close();

            allowRender = true;
        }
예제 #3
0
        public Patch Commit(string root)
        {
            Patch uninstall = new Patch();

            uninstall.isUninstall = true;

            Console.WriteLine();
            Console.WriteLine("Patching...");
            Console.WriteLine();

            foreach (AddedFile file in addedFiles)
            {
                string path = root + file.path;

                DeletedFile backup = new DeletedFile(file.path);
                uninstall.deletedFiles.Add(backup);

                File.WriteAllBytes(path, file.data);

                PrintFile(PatchType.ADD, file.path);
            }

            foreach (ModifiedFile file in modifiedFiles)
            {
                string path = root + file.path;

                if (File.Exists(path))
                {
                    byte[]       data   = File.ReadAllBytes(path);
                    ModifiedFile backup = new ModifiedFile(file.path, data);
                    uninstall.modifiedFiles.Add(backup);
                }

                File.WriteAllBytes(path, file.data);

                PrintFile(PatchType.MODIFY, file.path);
            }

            foreach (DeletedFile file in deletedFiles)
            {
                string path = root + file.path;

                if (File.Exists(path))
                {
                    byte[]    data   = File.ReadAllBytes(path);
                    AddedFile backup = new AddedFile(file.path, data);
                    uninstall.addedFiles.Add(backup);
                }

                File.Delete(path);

                PrintFile(PatchType.DELETE, file.path);
            }

            foreach (HipFile file in hipFiles)
            {
                string path = root + file.path;

                HipFile      backup = new HipFile(file.path);
                HipSection[] hip    = HipFileToHipArray(path);

                Section_HIPA hipa = (Section_HIPA)hip[0];
                Section_PACK pack = (Section_PACK)hip[1];
                Section_DICT dict = (Section_DICT)hip[2];
                Section_STRM strm = (Section_STRM)hip[3];

                List <Section_AHDR> ahdrList = dict.ATOC.AHDRList;
                List <Section_LHDR> lhdrList = dict.LTOC.LHDRList;

                Dictionary <uint, Section_AHDR> ahdrDict = ahdrList.ToDictionary(s => s.assetID);

                PrintFile(PatchType.MODIFY, file.path);

                foreach (AddedAsset asset in file.addedAssets)
                {
                    Section_ADBG adbg = new Section_ADBG(asset.alignment, asset.name, asset.filename, asset.checksum);
                    Section_AHDR ahdr = new Section_AHDR(asset.id, new string(asset.type), (AHDRFlags)asset.flags, adbg);

                    ahdr.data = asset.data;

                    DeletedAsset backupAsset = new DeletedAsset(asset);
                    backup.deletedAssets.Add(backupAsset);

                    ahdrList.Add(ahdr);

                    Section_LHDR lhdr = lhdrList[asset.layer];
                    lhdr.assetIDlist.Add(asset.id);

                    PrintAsset(PatchType.ADD, asset.name);
                }

                foreach (ModifiedAsset asset in file.modifiedAssets)
                {
                    if (!ahdrDict.ContainsKey(asset.id))
                    {
                        break;
                    }

                    Section_ADBG adbg = new Section_ADBG(asset.alignment, asset.name, asset.filename, asset.checksum);
                    Section_AHDR ahdr = new Section_AHDR(asset.id, new string(asset.type), (AHDRFlags)asset.flags, adbg);

                    ahdr.data = asset.data;

                    Section_AHDR oldAHDR = ahdrDict[asset.id];
                    ahdrList.Remove(oldAHDR);
                    ahdrList.Add(ahdr);

                    ModifiedAsset backupAsset = new ModifiedAsset(oldAHDR, hip);
                    backup.modifiedAssets.Add(backupAsset);

                    PrintAsset(PatchType.MODIFY, asset.name);
                }

                foreach (DeletedAsset asset in file.deletedAssets)
                {
                    if (!ahdrDict.ContainsKey(asset.id))
                    {
                        break;
                    }

                    Section_AHDR ahdr = ahdrDict[asset.id];

                    ahdrList.Remove(ahdr);

                    AddedAsset backupAsset = new AddedAsset(ahdr, hip);
                    backup.addedAssets.Add(backupAsset);

                    Section_LHDR lhdr = lhdrList[asset.layer];
                    lhdr.assetIDlist.Remove(asset.id);

                    PrintAsset(PatchType.DELETE, asset.name);
                }

                pack.PCNT.AHDRCount = ahdrList.Count;

                hip = SetupStream(ref hipa, ref pack, ref dict, ref strm);
                File.WriteAllBytes(path, HipArrayToFile(hip));

                uninstall.hipFiles.Add(backup);
            }

            Console.WriteLine("Done patching.");
            Console.WriteLine();

            return(uninstall);
        }