コード例 #1
0
ファイル: TADFile.cs プロジェクト: derplayer/ShenmueHDTools
        public void Write(BinaryWriter writer, bool includeMeta = false)
        {
            Header.Write(writer);

            for (int i = 0; i < FileEntries.Count; i++)
            {
                TADFileEntry entry = FileEntries[i];
                entry.Write(writer, includeMeta);
            }
        }
コード例 #2
0
ファイル: CacheFile.cs プロジェクト: derplayer/ShenmueHDTools
        public void CalculateHashes()
        {
            DescriptionChanged(this, new DescriptionChangedArgs("Calculating hashes..."));
            string outputFolder = Path.GetDirectoryName(Filename) + Header.RelativeOutputFolder;

            for (int i = 0; i < TADFile.FileEntries.Count; i++)
            {
                ProgressChanged(this, new ProgressChangedArgs(i, TADFile.FileEntries.Count));
                TADFileEntry entry = TADFile.FileEntries[i];
                entry.CheckMD5(outputFolder + "\\" + entry.RelativePath);
            }
            Finished(this, new FinishedArgs(true));
        }
コード例 #3
0
ファイル: TADFile.cs プロジェクト: derplayer/ShenmueHDTools
        public void Read(BinaryReader reader, bool includeMeta = false)
        {
            FileEntries.Clear();

            int dataOffset = 56 + 4; //including the useless filecount

            byte[] headerBuffer = new byte[dataOffset];
            reader.Read(headerBuffer, 0, headerBuffer.Length);
            Header.Read(headerBuffer);

            for (int i = 0; i < Header.FileCount; i++)
            {
                TADFileEntry entry = new TADFileEntry();
                entry.Read(reader, includeMeta);
                entry.Index = i;
                FileEntries.Add(entry);
            }
        }
コード例 #4
0
ファイル: CacheFile.cs プロジェクト: derplayer/ShenmueHDTools
        public void ConvertLegacy(string filename)
        {
            DataCollection dataCollection;

            using (FileStream reader = new FileStream(filename, FileMode.Open))
            {
                BinaryFormatter binaryFormatter = new BinaryFormatter();
                dataCollection = (DataCollection)binaryFormatter.Deserialize(reader);
            }
            if (dataCollection == null)
            {
                return;
            }

            Filename = filename.Replace(".shdcache", ".cache");

            TADFile                       = new TADFile();
            TADFile.Filename              = filename.Replace(".shdcache", ".tad");
            TADFile.Header.FileCount      = BitConverter.ToUInt32(dataCollection.Header.FileCount1, 0);
            TADFile.Header.HeaderChecksum = BitConverter.ToUInt32(dataCollection.Header.HeaderChecksum, 0);
            TADFile.Header.TacSize        = BitConverter.ToUInt32(dataCollection.Header.TacSize, 0);
            TADFile.Header.UnixTimestamp  = new DateTime(1970, 1, 1).AddSeconds(BitConverter.ToInt32(dataCollection.Header.UnixTimestamp, 0));

            string fileDir = Path.GetDirectoryName(Filename);
            string dir     = fileDir;

            if (dataCollection.Files.Count > 0)
            {
                dir = Path.GetDirectoryName(dataCollection.Files[0].Meta.FilePath);
            }

            Header.RelativeOutputFolder = "\\" + Helper.GetRelativePath(dir, fileDir);
            Header.RelativeTADPath      = "\\" + Helper.GetRelativePath(TADFile.Filename, fileDir);
            Header.RelativeTACPath      = "\\" + Helper.GetRelativePath(TADFile.Filename.Replace(".tad", ".tac"), fileDir);

            foreach (FileStructure file in dataCollection.Files)
            {
                TADFileEntry entry = new TADFileEntry();
                entry.FileOffset   = BitConverter.ToUInt32(file.FileStart, 0);
                entry.FileSize     = BitConverter.ToUInt32(file.FileSize, 0);
                entry.RelativePath = Helper.GetRelativePath(file.Meta.FilePath, dir);
                entry.Index        = file.Meta.Index;

                byte[] firstHash = new byte[4];
                Array.Copy(file.Hash1, firstHash, 4);
                entry.FirstHash = BitConverter.ToUInt32(firstHash, 0);

                byte[] secondHash = new byte[4];
                Array.Copy(file.Hash1, 4, secondHash, 0, 4);
                entry.SecondHash = BitConverter.ToUInt32(secondHash, 0);

                byte[] unknown = new byte[4];
                Array.Copy(file.Hash2, 0, unknown, 0, 4);
                entry.Unknown = BitConverter.ToUInt32(unknown, 0);

                entry.MD5Checksum = file.Meta.MD5Hash;

                TADFile.FileEntries.Add(entry);
            }

            FilenameDatabase filenameDB    = new FilenameDatabase();
            LoadingDialog    loadingDialog = new LoadingDialog();

            loadingDialog.SetData(filenameDB);
            Thread thread = new Thread(delegate() {
                filenameDB.MapFilenamesToTADInstance(this);
            });

            loadingDialog.ShowDialog(thread);

            DescriptionDatabase descDB = new DescriptionDatabase();

            loadingDialog = new LoadingDialog();
            loadingDialog.SetData(descDB);
            thread = new Thread(delegate() {
                descDB.MapDescriptionToTADInstance(TADFile);
            });
            loadingDialog.ShowDialog(thread);

            Write(Filename);
            if (File.Exists(filename))
            {
                File.Delete(filename);
            }
        }