Ejemplo n.º 1
0
        public void Update()
        {
            if (_context.CurrentUpdaterDefinition == null)
            {
                _context.Logger.Warning("No updater definition found. The Launcher cannot be validated or updated.");
                return;
            }

            _context.Logger.Info("Launcher update started. The update contains {UpdateOperations} operations.", _context.CurrentUpdaterDefinition.Entries.Length);

            FilesManager.DeleteTemporaryDeletingFiles(_context.Settings.RootPath);

            foreach (var updaterDefinitionEntry in _context.CurrentUpdaterDefinition.Entries)
            {
                switch (updaterDefinitionEntry.Operation)
                {
                case PatchOperation.Added:
                    _context.LogProgress(string.Format(_context.LocalizedMessages.UpdateProcessingNewFile, updaterDefinitionEntry.RelativePath));
                    HandleAddedFile(updaterDefinitionEntry);
                    _context.ReportProgress(string.Format(_context.LocalizedMessages.UpdateProcessedNewFile, updaterDefinitionEntry.RelativePath));
                    continue;

                case PatchOperation.Deleted:
                    _context.LogProgress(string.Format(_context.LocalizedMessages.UpdateProcessingDeletedFile, updaterDefinitionEntry.RelativePath));
                    HandleDeletedFile(updaterDefinitionEntry);
                    _context.ReportProgress(string.Format(_context.LocalizedMessages.UpdateProcessedDeletedFile, updaterDefinitionEntry.RelativePath));
                    continue;

                case PatchOperation.ChangedAttributes:
                    _context.LogProgress(string.Format(_context.LocalizedMessages.UpdateProcessingChangedAttributesFile, updaterDefinitionEntry.RelativePath));
                    HandleChangedAttributesFile(updaterDefinitionEntry);
                    _context.ReportProgress(string.Format(_context.LocalizedMessages.UpdateProcessedChangedAttributesFile, updaterDefinitionEntry.RelativePath));
                    continue;

                case PatchOperation.Updated:
                    _context.LogProgress(string.Format(_context.LocalizedMessages.UpdateProcessingUpdatedFile, updaterDefinitionEntry.RelativePath));
                    HandleUpdatedFile(updaterDefinitionEntry);
                    _context.ReportProgress(string.Format(_context.LocalizedMessages.UpdateProcessedUpdatedFile, updaterDefinitionEntry.RelativePath));
                    continue;

                case PatchOperation.Unchanged:
                    HandleUnchangedFile(updaterDefinitionEntry);
                    _context.ReportProgress(string.Format(_context.LocalizedMessages.UpdateUnchangedFile, updaterDefinitionEntry.RelativePath));
                    continue;
                }
            }

            _context.Logger.Info("Launcher update completed.");
        }
Ejemplo n.º 2
0
        private void PerformUpdate(PatchDefinition definition)
        {
            _context.LogProgress(string.Format(_context.LocalizedMessages.UpdateDownloadingArchive, definition.From, definition.To));
            DownloadPatch(definition);
            _context.ReportProgress(string.Format(_context.LocalizedMessages.UpdateDownloadedArchive, definition.From, definition.To));

            _context.LogProgress(string.Format(_context.LocalizedMessages.UpdateDecompressingArchive, definition.From, definition.To));
            DecompressPatch(definition);
            _context.ReportProgress(string.Format(_context.LocalizedMessages.UpdateDecompressedArchive, definition.From, definition.To));

            foreach (var definitionEntry in definition.Entries)
            {
                ProcessFile(definition, definitionEntry);
            }

            DirectoriesManager.Delete(_context.Settings.GetTempPath());
        }
Ejemplo n.º 3
0
        public void Update()
        {
            _context.Logger.Info("Repairing process started.");
            var repairedFiles   = 0;
            var downloadEntries = new List <DownloadEntry>();

            foreach (var currentEntry in _context.CurrentBuildDefinition.Entries)
            {
                var canSkip   = false;
                var integrity = GetFileIntegrity(currentEntry);
                var filePath  = PathsManager.Combine(_context.Settings.GetGamePath(), currentEntry.RelativePath);

                if (integrity == FileIntegrity.Valid)
                {
                    canSkip = true;
                }
                else if (integrity == FileIntegrity.InvalidAttributes)
                {
                    HandleInvalidAttributes(currentEntry);
                    canSkip = true;
                }
                else if (integrity == FileIntegrity.InvalidLastWriting || integrity == (FileIntegrity.InvalidLastWriting | FileIntegrity.InvalidAttributes))
                {
                    var isNowValid = HandleInvalidLastWriting(currentEntry);
                    if (isNowValid)
                    {
                        SetDefinition(filePath, currentEntry);
                        canSkip = true;
                    }
                }
                else if (integrity.HasFlag(FileIntegrity.InvalidSize))
                {
                    FilesManager.Delete(currentEntry.RelativePath);
                }

                if (!canSkip)
                {
                    // If I am here, the file cannot be fixed and it does not exist anymore (or never existed)
                    DirectoriesManager.Create(PathsManager.GetDirectoryPath(filePath));

                    var remoteFile = PathsManager.UriCombine(
                        _context.Settings.GetRemoteBuildUrl(_context.CurrentVersion),
                        _context.Settings.GameFolderName,
                        currentEntry.RelativePath
                        );
                    var partialRemoteFile = PathsManager.UriCombine(
                        _context.Settings.GetPartialRemoteBuildUrl(_context.CurrentVersion),
                        _context.Settings.GameFolderName,
                        currentEntry.RelativePath
                        );
                    downloadEntries.Add(new DownloadEntry(
                                            remoteFile,
                                            partialRemoteFile,
                                            PathsManager.GetDirectoryPath(filePath),
                                            filePath,
                                            currentEntry)
                                        );

                    repairedFiles++;
                }
            }

            Downloader.Download(downloadEntries, (entry) =>
            {
                SetDefinition(entry.DestinationFile, entry.Definition);
                _context.ReportProgress($"Repaired {entry.Definition.RelativePath}");
            });

            _context.Logger.Info("Repairing process completed. Checked {CheckedFiles} files, repaired {RepairedFiles} files, skipped {SkippedFiles} files.",
                                 _context.CurrentBuildDefinition.Entries.Length,
                                 repairedFiles,
                                 _context.CurrentBuildDefinition.Entries.Length - repairedFiles);
        }