public string VerifyArchive()
        {
            string result = "";
            char   endl   = '\n';

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

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

            foreach (Section_LHDR LHDR in DICT.LTOC.LHDRList)
            {
                foreach (uint assetID in LHDR.assetIDlist)
                {
                    if (!ContainsAsset(assetID))
                    {
                        result += $"Archive: Asset 0x{assetID.ToString("X8")} appears to be present in a layer, but it's not in the AHDR dictionary. This archive is likely unusable." + endl;
                    }
                }
            }

            List <Asset> ordered = assetDictionary.Values.OrderBy(f => f.AHDR.ADBG.assetName).ToList();

            ordered = ordered.OrderBy(f => f.AHDR.assetType).ToList();

            if (!ContainsAssetWithType(AssetType.JSP))
            {
                result += $"Archive: Does not contain any JSP asset." + endl;
            }

            foreach (Asset asset in ordered)
            {
                bool found = false;

                foreach (Section_LHDR LHDR in DICT.LTOC.LHDRList)
                {
                    foreach (uint assetID in LHDR.assetIDlist)
                    {
                        if (assetID == asset.AHDR.assetID)
                        {
                            if (found == false)
                            {
                                found = true;
                            }
                            else
                            {
                                result += $"Archive: Asset {asset.ToString()} is present in more than one layer. This is unexpected." + endl;
                            }
                        }
                    }
                }

                if (found == false)
                {
                    result += $"Archive: Asset {asset.ToString()} appears to not be present in the AHDR dictionary, but it's not in any layer. This archive is likely unusable." + endl;
                }

                List <string> resultParam = new List <string>();
                try
                {
                    asset.Verify(ref resultParam);

                    foreach (string s in resultParam)
                    {
                        result += $"[{asset.AHDR.assetType.ToString()}] {asset.AHDR.ADBG.assetName}: " + s + endl;
                    }
                }
                catch (Exception e)
                {
                    result += $"Failed verification on [{asset.AHDR.assetType.ToString()}] {asset.AHDR.ADBG.assetName}: " + e.Message + endl;
                }

                progressBar.PerformStep();
            }

            progressBar.Close();

            return(result);
        }
Пример #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;
        }
        public void OpenFile(string fileName, bool displayProgressBar, Platform platform, bool skipTexturesAndModels = false)
        {
            allowRender = false;

            Dispose();

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

            if (displayProgressBar)
            {
                progressBar.Show();
            }

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

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

            try
            {
                hipFile = new HipFile(fileName);
            }
            catch (Exception e)
            {
                progressBar.Close();
                throw e;
            }

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

            if (this.platform == Platform.Unknown)
            {
                hipFile.platform = platform;
            }
            while (this.platform == Platform.Unknown)
            {
                hipFile.platform = ChoosePlatformDialog.GetPlatform();
            }

            string assetsWithError = "";

            List <string> autoComplete = new List <string>(DICT.ATOC.AHDRList.Count);

            foreach (Section_AHDR AHDR in DICT.ATOC.AHDRList)
            {
                string error = AddAssetToDictionary(AHDR, true, skipTexturesAndModels || standalone, false);

                if (error != null)
                {
                    assetsWithError += error + "\n";
                }

                autoComplete.Add(AHDR.ADBG.assetName);

                progressBar.PerformStep();
            }

            if (assetsWithError != "")
            {
                MessageBox.Show("There was an error loading the following assets and editing has been disabled for them:\n" + assetsWithError);
            }

            autoCompleteSource.AddRange(autoComplete.ToArray());

            if (!(skipTexturesAndModels || standalone) && ContainsAssetWithType(AssetType.RWTX))
            {
                SetupTextureDisplay();
            }

            RecalculateAllMatrices();

            if (!skipTexturesAndModels && ContainsAssetWithType(AssetType.PIPT) && ContainsAssetWithType(AssetType.MODL))
            {
                foreach (var asset in assetDictionary.Values)
                {
                    if (asset is AssetPIPT PIPT)
                    {
                        PIPT.UpdateDictionary();
                    }
                }
            }

            progressBar.Close();

            allowRender = true;
        }