Esempio n. 1
0
 private static async Task DeleteFileAsync(FileUpdateInfo fileUpdate, FactorioVersion versionToUpdate)
 {
     await Task.Run(() =>
     {
         var file = new FileInfo(versionToUpdate.ExpandPathVariables(fileUpdate.Path));
         if (file.Exists)
         {
             file.Delete();
         }
     });
 }
Esempio n. 2
0
        private static async Task UpdateFileAsync(FileUpdateInfo fileUpdate, FactorioVersion versionToUpdate, ZipArchive archive, string packageDirectory)
        {
            await Task.Run(() =>
            {
                var file = new FileInfo(versionToUpdate.ExpandPathVariables(fileUpdate.Path));
                if (!file.Exists)
                {
                    throw new CriticalUpdaterException(UpdaterErrorType.FileNotFound);
                }

                uint oldCrc = file.CalculateCrc();
                if (oldCrc != fileUpdate.OldCrc)
                {
                    throw new CriticalUpdaterException(UpdaterErrorType.ChecksumMismatch);
                }

                string entryPath = fileUpdate.Path;
                if (!string.IsNullOrEmpty(packageDirectory))
                {
                    entryPath = string.Join("/", packageDirectory, entryPath);
                }
                entryPath = ResolveArchivePath(entryPath);
                var entry = archive.GetEntry(entryPath);

                using (var output = new MemoryStream())
                {
                    using (var input = file.OpenRead())
                    {
                        using (var patch = new MemoryStream())
                        {
                            using (var source = entry.Open())
                                source.CopyTo(patch);
                            patch.Position = 0;

                            var decoder = new Decoder(input, patch, output);
                            decoder.Run();
                        }
                    }

                    output.Position = 0;
                    using (var destination = file.Open(FileMode.Truncate, FileAccess.Write))
                        output.CopyTo(destination);
                }

                uint newCrc = file.CalculateCrc();
                if (newCrc != fileUpdate.NewCrc)
                {
                    throw new CriticalUpdaterException(UpdaterErrorType.ChecksumMismatch);
                }
            });
        }
Esempio n. 3
0
        private static async Task AddFileAsync(FileUpdateInfo fileUpdate, FactorioVersion versionToUpdate, ZipArchive archive, string packageDirectory)
        {
            await Task.Run(() =>
            {
                var file = new FileInfo(versionToUpdate.ExpandPathVariables(fileUpdate.Path));

                string entryPath = fileUpdate.Path;
                if (!string.IsNullOrEmpty(packageDirectory))
                {
                    entryPath = string.Join("/", packageDirectory, entryPath);
                }
                entryPath = ResolveArchivePath(entryPath);
                var entry = archive.GetEntry(entryPath);

                var dir = file.Directory;
                if (!dir.Exists)
                {
                    dir.Create();
                }
                entry.ExtractToFile(file.FullName, true);
            });
        }