示例#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 bool DeleteFile(int Sid, FileSourceType type)
        {
            this.ClearBrokenRuleMessages();
            bool result = mgr.Delete(Sid, type);

            this.AddBrokenRuleMessages(mgr.BrokenRuleMessages);
            return(result);
        }
示例#4
0
        private void HandleAddedFile(PatchDefinition definition, PatchDefinitionEntry entry)
        {
            var sourcePath      = PathsManager.Combine(_context.Settings.GetUncompressedPatchArchivePath(definition.From, definition.To), entry.RelativePath);
            var destinationPath = PathsManager.Combine(_context.Settings.GetGamePath(), entry.RelativePath);

            FilesManager.Delete(destinationPath);
            FilesManager.Move(sourcePath, destinationPath);

            EnsureDefinition(destinationPath, entry);
        }
示例#5
0
        private bool HandleInvalidLastWriting(BuildDefinitionEntry entry)
        {
            var filePath = PathsManager.Combine(_context.Settings.GetGamePath(), entry.RelativePath);
            var hash     = Hashing.GetFileHash(filePath);

            if (entry.Hash != hash)
            {
                FilesManager.Delete(filePath);
                return(false);
            }
            return(true);
        }
        private void HandleDeletedFile(UpdaterDefinitionEntry entry)
        {
            var filePath = PathsManager.Combine(_context.Settings.RootPath, entry.RelativePath);

            if (FilesManager.IsFileLocked(filePath))
            {
                var newFilePath = FilesManager.GetTemporaryDeletingFileName(filePath);
                FilesManager.Rename(filePath, newFilePath);
            }
            else
            {
                FilesManager.Delete(filePath);
            }
        }
        private void HandleAddedFile(UpdaterDefinitionEntry entry)
        {
            var filePath = PathsManager.Combine(_context.Settings.RootPath, entry.RelativePath);

            var difference      = FileValidityDifference.None;
            var alreadyExisting = FilesManager.Exists(filePath);

            if (alreadyExisting && IsValid(entry, out difference))
            {
                return;
            }

            if (difference.HasFlag(FileValidityDifference.Size))
            {
                if (FilesManager.IsFileLocked(filePath))
                {
                    var newFilePath = FilesManager.GetTemporaryDeletingFileName(filePath);
                    FilesManager.Rename(filePath, newFilePath);
                }
                else
                {
                    FilesManager.Delete(filePath);
                }

                Downloader.Download(_context.Settings.GetRemoteUpdaterFileUrl(entry.RelativePath),
                                    PathsManager.GetDirectoryPath(filePath));

                EnsureDefinition(entry);

                _context.SetDirtyFlag(entry.RelativePath);
            }
            else
            {
                if (!alreadyExisting)
                {
                    Downloader.Download(_context.Settings.GetRemoteUpdaterFileUrl(entry.RelativePath),
                                        PathsManager.GetDirectoryPath(filePath));
                }

                if (FilesManager.IsFileLocked(filePath))
                {
                    var newFilePath = FilesManager.GetTemporaryDeletingFileName(filePath);
                    FilesManager.Rename(filePath, newFilePath);
                    FilesManager.Copy(newFilePath, filePath);
                }

                EnsureDefinition(entry);
            }
        }
示例#8
0
        private void DeleteFile(ListViewItem item)
        {
            FileVO file = item.Tag as FileVO;

            item.Tag = null;
            PagesLV.Items.Remove(item);
            currentDocument.Files.Remove(file);

            if (file.Id >= 0)
            {
                if (!filesManager.Delete(file))
                {
                    Error("حصل خطأ أثناء حذف الملف");
                }
            }
        }
示例#9
0
        public void TestDelete()
        {
            var p = new MediaFile()
            {
                Name    = "ToBeDeleted" + DateTime.Now.ToString("yyyyMMddHHmmsszzz"),
                Content = ReadDing(),
            };

            var helper = new FilesManager();
            var id     = helper.Create(p);

            Assert.NotNull(id);

            var ok = helper.Delete(id);

            Assert.True(ok);
        }
示例#10
0
        private void HandleUpdatedFile(PatchDefinition definition, PatchDefinitionEntry entry)
        {
            var filePath       = PathsManager.Combine(_context.Settings.GetGamePath(), entry.RelativePath);
            var fileBackupPath = filePath + ".bak";
            var patchPath      = PathsManager.Combine(_context.Settings.GetUncompressedPatchArchivePath(definition.From, definition.To), entry.RelativePath + ".patch");

            try
            {
                FilesManager.Rename(filePath, fileBackupPath);

                DeltaFileApplier.Apply(fileBackupPath, patchPath, filePath);

                EnsureDefinition(filePath, entry);
            }
            catch
            {
            }
            finally
            {
                FilesManager.Delete(fileBackupPath);
            }
        }
        private void removeSelectedFile_Click(object sender, EventArgs e)
        {
            OperationsManager opMan    = new OperationsManager();
            DocumentVO        document = documentsBindingSource.Current as DocumentVO;
            FileVO            file     = filesBindingSource.Current as FileVO;

            if (document != null && file != null)
            {
                if (!opMan.HasPermission(OperationsManager.EDIT_DOCS, Library.ConfigurationManager.currUser))
                {
                    Error("أنت لا تمتلك السماحية للقيام بهذه العملية");
                    return;
                }
            }
            else
            {
                return;
            }

            DialogResult result = Question("هل أنت متأكد من أنك تريد حذف الملف المحدد؟ لا يمكنك التراجع عن هذه العملية لاحقاً");

            if (result == System.Windows.Forms.DialogResult.Yes)
            {
                FilesManager manager = new FilesManager();

                if (manager.Delete(file))
                {
                    WriteToLogFileDleted(document, file);
                    Message("تمت عملية الحذف بنجاح", "عملية ناجحة");
                    filesBindingSource.Remove(file);
                }
                else
                {
                    Error("فشل عملية الحذف", "عملية فاشلة");
                }
            }
        }
示例#12
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);
        }
示例#13
0
        private void HandleDeletedFile(PatchDefinition definition, PatchDefinitionEntry entry)
        {
            var path = PathsManager.Combine(_context.Settings.GetGamePath(), entry.RelativePath);

            FilesManager.Delete(path);
        }
示例#14
0
        public override void Download(List <DownloadEntry> entries, Action <DownloadEntry> onEntryCompleted)
        {
            entries.Sort((entry1, entry2) =>
            {
                return(entry1.Definition.Size.CompareTo(entry2.Definition.Size));
            });

            var queue = new ConcurrentQueue <DownloadEntry>(entries);

            var tasksAmount = Environment.ProcessorCount - 1;
            var tasks       = new Task[tasksAmount];

            for (var i = 0; i < tasksAmount; i++)
            {
                tasks[i] = Task.Run(() =>
                {
                    using (var client = new DropboxClient(Credentials.Password))
                    {
                        while (queue.TryDequeue(out var entry))
                        {
                            int retriesCount = 0;

                            while (retriesCount < MaxDownloadRetries)
                            {
                                try
                                {
                                    var url = entry.PartialRemoteUrl;
                                    if (!url.StartsWith("/"))
                                    {
                                        url = "/" + url;
                                    }

                                    using (var response = client.Files.DownloadAsync(url).Result)
                                    {
                                        FilesManager.Delete(entry.DestinationFile);
                                        File.WriteAllBytes(entry.DestinationFile, response.GetContentAsByteArrayAsync().Result);
                                    }

                                    retriesCount = MaxDownloadRetries;
                                }
                                catch
                                {
                                    retriesCount++;

                                    if (retriesCount >= MaxDownloadRetries)
                                    {
                                        throw new WebException($"All retries have been tried for {entry.RemoteUrl}.");
                                    }

                                    Thread.Sleep(DelayForRetryMilliseconds + (DelayForRetryMilliseconds * retriesCount));
                                }
                            }

                            onEntryCompleted?.Invoke(entry);
                        }
                    }
                });
            }

            Task.WaitAll(tasks);
        }