public static async Task <GameFileInfo> GenerateGameFileInfo(string file, string fileName,
                                                                     string outputFolder, string baseHttpLink, CancellationToken ct = default)
        {
            if (!Directory.Exists(outputFolder))
            {
                Directory.CreateDirectory(outputFolder);
            }

            if (!baseHttpLink.EndsWith("/"))
            {
                baseHttpLink += "/";
            }

            var binFileName = $"{fileName.ToLower().GetHashCode():X4}.bin";
            var outFileName = Path.Combine(outputFolder, binFileName);

            await L33TZipUtils.CompressFileAsL33TZipAsync(file, outFileName, ct);

            var fileCrc = await Crc32Utils.DoGetCrc32FromFile(file, ct);

            var fileLength = new FileInfo(file).Length;

            var externalLocation = Path.Combine(baseHttpLink, binFileName).Replace("\\", "/");
            var outFileCrc       = await Crc32Utils.DoGetCrc32FromFile(outFileName, ct);

            var outFileLength = new FileInfo(outFileName).Length;

            return(new GameFileInfo(fileName, fileCrc, fileLength, externalLocation,
                                    outFileCrc, outFileLength));
        }
Ejemplo n.º 2
0
        public static async Task <bool> RunFileCheck(string filePath, long fileSize, uint fileCrc32,
#pragma warning disable IDE0034 // Simplifier l'expression 'default'
                                                     CancellationToken ct = default(CancellationToken),
#pragma warning restore IDE0034 // Simplifier l'expression 'default'
                                                     IProgress <double> progress = null)
        {
            return(RunFileQuickCheck(filePath, fileSize) &&
                   fileCrc32 == await Crc32Utils.DoGetCrc32FromFile(filePath, ct, progress));
        }
Ejemplo n.º 3
0
        private static async Task <GameFileInfo> GenerateGameFileInfo(string file, string fileName,
                                                                      string outputFolder,
#pragma warning disable IDE0034 // Simplifier l'expression 'default'
                                                                      string baseHttpLink, CancellationToken ct = default(CancellationToken))
#pragma warning restore IDE0034 // Simplifier l'expression 'default'
        {
            if (!baseHttpLink.EndsWith("/"))
            {
                baseHttpLink += "/";
            }

            var binFileName = $"{fileName.ToLower().GetHashCode():X4}.bin";
            var outFileName = Path.Combine(outputFolder, binFileName);

            await L33TZipUtils.DoCreateL33TZipFile(file, outFileName, ct);

            var fileInfo = new GameFileInfo(fileName, await Crc32Utils.DoGetCrc32FromFile(file, ct),
                                            new FileInfo(file).Length, Path.Combine(baseHttpLink, binFileName).Replace("\\", "/"),
                                            await Crc32Utils.DoGetCrc32FromFile(outFileName, ct), new FileInfo(outFileName).Length);

            return(fileInfo);
        }
        public static async Task EnsureValidGameFile(string gameFilePath, long expectedFileSize, uint expectedCrc32,
                                                     CancellationToken ct = default, IProgress <double> progress = null)
        {
            var gameFileInfo = new FileInfo(gameFilePath);

            if (!gameFileInfo.Exists)
            {
                throw new Exception($"The game file {gameFilePath} does not exist");
            }

            if (gameFileInfo.Length != expectedFileSize)
            {
                throw new Exception(
                          $"The game file {gameFilePath} was expected to have a size of {expectedFileSize} but was {gameFileInfo.Length}");
            }

            var gameFileCrc32 = await Crc32Utils.DoGetCrc32FromFile(gameFilePath, ct, progress);

            if (gameFileCrc32 != expectedCrc32)
            {
                throw new Exception(
                          $"The game file {gameFilePath} was expected to have a crc32 {expectedCrc32} but was {gameFileCrc32}");
            }
        }
 public static async Task <bool> RunFileCheck(string gameFilePath, long expectedFileSize, uint expectedCrc32,
                                              CancellationToken ct = default, IProgress <double> progress = null)
 {
     return(RunFileQuickCheck(gameFilePath, expectedFileSize) &&
            expectedCrc32 == await Crc32Utils.DoGetCrc32FromFile(gameFilePath, ct, progress));
 }