예제 #1
0
        public void Build()
        {
            if (DirectoriesManager.IsEmpty(_context.Settings.GetUpdaterFolderPath()))
            {
                throw new UpdaterFolderIsEmptyException();
            }

            _context.LogProgress(string.Format(_context.LocalizedMessages.UpdaterCollectingOldDefinition));
            var oldDefinition = GetCurrentDefinition();

            _context.LogProgress(string.Format(_context.LocalizedMessages.UpdaterCollectingFiles));
            var files = GetFiles();

            var definition = BuildDefinition(files, oldDefinition);

            FilesManager.Delete(_context.Settings.GetUpdaterIndexPath());

            FilesManager.Delete(_context.Settings.GetUpdaterDeployPath(_context.LauncherArchiveName));

            _context.LogProgress(string.Format(_context.LocalizedMessages.UpdaterCompressingArchive));
            Compressor.Compress(_context.Settings.GetUpdaterFolderPath(), _context.Settings.GetUpdaterDeployPath(_context.LauncherArchiveName), null, _context.CompressionLevel);
            _context.ReportProgress(string.Format(_context.LocalizedMessages.UpdaterCompressedArchive));

            File.WriteAllText(_context.Settings.GetUpdaterIndexPath(), _context.Serializer.Serialize(definition));
            _context.ReportProgress(string.Format(_context.LocalizedMessages.UpdaterSavedDefinition));
        }
예제 #2
0
        private void DownloadPatch(PatchDefinition definition)
        {
            DirectoriesManager.Create(_context.Settings.GetTempPath());

            var archivePath  = _context.Settings.GetDownloadedPatchArchivePath(definition.From, definition.To);
            var leftAttempts = _context.Settings.PatchDownloadAttempts;
            var success      = false;

            do
            {
                try
                {
                    Downloader.Download(_context.Settings.GetRemotePatchArchiveUrl(definition.From, definition.To), _context.Settings.GetTempPath());
                    var downloadedArchiveHash = Hashing.GetFileHash(archivePath);
                    if (downloadedArchiveHash == definition.Hash)
                    {
                        success = true;
                        break;
                    }
                }
                catch
                {
                    // ignored
                }

                FilesManager.Delete(archivePath);
                leftAttempts--;
            } while (leftAttempts > 0);

            if (!success)
            {
                throw new PatchCannotBeDownloadedException();
            }
        }
예제 #3
0
 public void SetDirectoriesManager()
 {
     if (DirectoriesManager == null)
     {
         DirectoriesManager = DirectoriesManager.GetInstance(Session);
     }
 }
예제 #4
0
        public void Build()
        {
            if (_context.VersionFrom == _context.VersionTo)
            {
                throw new SameVersionsException();
            }

            _context.LogProgress(string.Format(_context.LocalizedMessages.PatchCollectingDefinitions));
            var fromDefinition = GetBuildDefinition(_context.VersionFrom);
            var toDefinition   = GetBuildDefinition(_context.VersionTo);

            _context.LogProgress(string.Format(_context.LocalizedMessages.PatchCollectingPatchData));
            var patchDefinition = BuildPatchDefinition(fromDefinition, toDefinition);

            _context.LogProgress(string.Format(_context.LocalizedMessages.PatchBuildingPatch, _context.VersionFrom, _context.VersionTo));
            BuildPatch(patchDefinition, fromDefinition, toDefinition);
            FilesManager.DeleteMultiple(_context.Settings.GetPatchesTempFolderPath(), "*.signature");

            _context.LogProgress(string.Format(_context.LocalizedMessages.PatchCompressing, _context.VersionFrom, _context.VersionTo));
            CompressPatch();
            _context.ReportProgress(string.Format(_context.LocalizedMessages.PatchCompressed, _context.VersionFrom, _context.VersionTo));

            _context.LogProgress(string.Format(_context.LocalizedMessages.PatchCleaningWorkspace));
            DirectoriesManager.Delete(_context.Settings.GetPatchesTempFolderPath());
            _context.ReportProgress(string.Format(_context.LocalizedMessages.PatchCleanedWorkspace));

            _context.LogProgress(string.Format(_context.LocalizedMessages.PatchBuildingDefinition));
            BuildPatchDefinition(patchDefinition);
            _context.ReportProgress(string.Format(_context.LocalizedMessages.PatchBuiltDefinition));

            _context.LogProgress(string.Format(_context.LocalizedMessages.PatchBuildingIndex));
            BuildPatchIndex();
            _context.ReportProgress(string.Format(_context.LocalizedMessages.PatchBuiltIndex));
        }
예제 #5
0
        private void DecompressPatch(PatchDefinition definition)
        {
            var path = _context.Settings.GetUncompressedPatchArchivePath(definition.From, definition.To);

            DirectoriesManager.Create(path);

            Compressor.Decompress(path, _context.Settings.GetDownloadedPatchArchivePath(definition.From, definition.To), null);
        }
예제 #6
0
        private void BuilderOnCompleted()
        {
            _isCompleted = true;

            if (_cleaningFlag)
            {
                DirectoriesManager.Clean(CurrentWindow.AdminSettings.GetApplicationFolderPath());
            }
        }
예제 #7
0
        private void HandleUpdatedFile(PatchDefinitionEntry entry)
        {
            var fromFile      = PathsManager.Combine(_context.Settings.GetGameFolderPath(_context.VersionFrom), entry.RelativePath);
            var toFile        = PathsManager.Combine(_context.Settings.GetGameFolderPath(_context.VersionTo), entry.RelativePath);
            var patchFile     = PathsManager.Combine(_context.Settings.GetPatchesTempFolderPath(), entry.RelativePath + ".patch");
            var signatureFile = PathsManager.Combine(_context.Settings.GetPatchesTempFolderPath(), entry.RelativePath + ".signature");

            DirectoriesManager.Create(PathsManager.GetDirectoryPath(patchFile));

            DeltaFileBuilder.Build(fromFile, toFile, patchFile, signatureFile);

            var path = PathsManager.Combine(_context.Settings.GetGameFolderPath(_context.VersionTo), entry.RelativePath);
            var info = FilesManager.GetFileInfo(path);

            entry.Attributes  = info.Attributes;
            entry.LastWriting = info.LastWriting;
        }
예제 #8
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());
        }
예제 #9
0
        public virtual void Download(string url, string destFolder)
        {
            this.canceled = false;

            string destFileName = Path.GetFileName(url);

            destFolder         = destFolder.Replace("file:///", "").Replace("file://", "");
            this.downloadingTo = Path.Combine(destFolder, destFileName);

            DirectoriesManager.Create(destFolder);

            if (!File.Exists(downloadingTo))
            {
                using (FileStream fs = File.Create(downloadingTo))
                {
                    fs.Dispose();
                    fs.Close();
                }
            }

            byte[] buffer = new byte[DownloadBlockSize];

            var gotCanceled = false;

            using (FileStream fs = File.Open(downloadingTo, FileMode.Append, FileAccess.Write,
                                             FileShare.Write | FileShare.Delete))
            {
                var currentRetries = 0;

                while (currentRetries < MaxDownloadRetries)
                {
                    DownloadData data = null;

                    try
                    {
                        data = DownloadData.Create(url, destFolder, this.proxy, Credentials);
                        var totalDownloaded = data.StartPoint;
                        int readCount;

                        try
                        {
                            while ((int)(readCount = data.DownloadStream.Read(buffer, 0, DownloadBlockSize)) > 0)
                            {
                                if (canceled)
                                {
                                    gotCanceled = true;
                                    data.Close();
                                    break;
                                }

                                totalDownloaded += readCount;

                                SaveToFile(buffer, readCount, fs);

                                if (data.IsProgressKnown)
                                {
                                    RaiseProgressChanged(totalDownloaded, data.FileSize);
                                }

                                if (canceled)
                                {
                                    gotCanceled = true;
                                    data.Close();
                                    break;
                                }
                            }

                            currentRetries = MaxDownloadRetries;
                        }
                        catch
                        {
                            currentRetries++;

                            if (currentRetries >= MaxDownloadRetries)
                            {
                                fs.Dispose();
                                fs.Close();

                                throw new WebException($"All retries have been tried for {url}.");
                            }

                            Thread.Sleep(DelayForRetryMilliseconds + (DelayForRetryMilliseconds * currentRetries));
                        }
                    }
                    catch (WebException webException)
                    {
                        throw new WebException($"The URL {url} generated an exception.", webException);
                    }
                    catch (UriFormatException e)
                    {
                        throw new ArgumentException(
                                  string.Format(
                                      "Could not parse the URL \"{0}\" - it's either malformed or is an unknown protocol.",
                                      url), e);
                    }
                    finally
                    {
                        if (data != null)
                        {
                            data.Close();
                        }
                    }
                }

                fs.Dispose();
                fs.Close();
            }

            if (!gotCanceled)
            {
                OnDownloadComplete();
            }
        }
예제 #10
0
 protected override async Task LoadAsync()
 {
     // Load local sheet music (*.xml) files.
     await Task.Run(() => Sheets = xmlParser.LoadDirectory(DirectoriesManager.GetFullDirectoryPath("musician")));
 }
예제 #11
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);
        }
예제 #12
0
 private bool ApplicationFolderIsEmpty()
 {
     return(DirectoriesManager.IsEmpty(_context.Settings.GetApplicationFolderPath()));
 }
 private void InitializeDirectories()
 {
     DirectoriesManager.Create(Settings.GetUpdaterFolderPath());
 }
예제 #14
0
 private void InitializeDirectories()
 {
     DirectoriesManager.Create(Settings.GetApplicationFolderPath());
     DirectoriesManager.Create(Settings.GetBuildsFolderPath());
     DirectoriesManager.Create(Settings.GetPatchesFolderPath());
 }